<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">[Cc Amir, Thomas if they have better advice on this]</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Sep 2, 2021 at 6:46 PM Li Wang <<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The st_mtime field is defined as st_mtim.tv_sec for backward<br>
compatibility in struct stat, which might not precise enough<br>
for timestamp comparing.<br>
<br>
Similar issue as:<br>
  <a href="https://lists.linux.it/pipermail/ltp/2020-November/019982.html" rel="noreferrer" target="_blank">https://lists.linux.it/pipermail/ltp/2020-November/019982.html</a><br>
<br>
Here switch to timespec diff (with compare nanosecond as well) to<br>
get rid of this kind of rare faliure:<br>
<br>
   7    tst_test.c:1345: TINFO: Timeout per run is 0h 05m 00s<br>
   8    copy_file_range.h:36: TINFO: Testing libc copy_file_range()<br>
   9    copy_file_range03.c:48: TPASS: copy_file_range sucessfully updated the timestamp<br>
   10   tst_test.c:1345: TINFO: Timeout per run is 0h 05m 00s<br>
   11   copy_file_range.h:39: TINFO: Testing __NR_copy_file_range syscall<br>
   12   copy_file_range03.c:46: TFAIL: copy_file_range did not update timestamp.<br></blockquote><div><br></div>After <span class="gmail_default" style="font-size:small">digging</span> into <span class="gmail_default" style="font-size:small">syscall</span> copy_file_range<span class="gmail_default" style="font-size:small"> </span>(<span class="gmail_default">which </span><span class="gmail_default">mainly call </span></div><div class="gmail_quote"><span class="gmail_default">the </span><span class="gmail_default"></span><span style="color:rgb(0,0,0);white-space:pre-wrap">splice_direct_to_actor</span>),<span class="gmail_default"> </span>I found it relies on <span class="gmail_default" style="font-size:small">the</span> specific </div><div class="gmail_quote">filesystem (my platform is XFS)<span class="gmail_default"> </span><span class="gmail_default">t</span>o<span class="gmail_default" style="font-size:small"> </span><span class="gmail_default"></span>complete the timestamps</div><div class="gmail_quote"><span class="gmail_default"> updating. </span></div><div class="gmail_quote"><span class="gmail_default" style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div class="gmail_quote"><span class="gmail_default" style="color:rgb(0,0,0);white-space:pre-wrap">For XFS, the “</span><span style="color:rgb(0,0,0)"><span class="gmail_default">file_modified“</span><span class="gmail_default"> code path </span></span><span style="color:rgb(0,0,0)"><span class="gmail_default">is via</span></span></div><div class="gmail_quote"><span style="color:rgb(0,0,0);white-space:pre-wrap"><span class="gmail_default" style="font-size:small">   </span>file_update_time() --> current_time() --> timestamp_truncate() </span></div><div class="gmail_quote"><span style="color:rgb(0,0,0);white-space:pre-wrap">to get <span class="gmail_default">a truncated </span></span><span style="color:rgb(0,0,0);white-space:pre-wrap">current time for <span class="gmail_default" style="font-size:small">use</span>.</span></div><div class="gmail_quote"><span style="color:rgb(0,0,0);white-space:pre-wrap"><br></span></div><div class="gmail_quote"><span class="gmail_default" style="font-size:small"><font color="#000000"><span style="white-space:pre-wrap">Then, I guess, </span></font> there is also potential to get a </span><span class="gmail_default">round-down value</span><span class="gmail_default"></span>,</div><div class="gmail_quote">then <span class="gmail_default">apply it to the dest_file as timestamp, reflect to the </span><span class="gmail_default">userland,</span></div><div class="gmail_quote"><span class="gmail_default">it </span>show<span class="gmail_default">s</span> <span class="gmail_default"></span>time no<span class="gmail_default"> </span>change in 1<span class="gmail_default"> </span>second<span class="gmail_default"> </span>elapsed<span class="gmail_default" style="font-size:small"></span><span class="gmail_default"></span><span class="gmail_default"></span>.</div><div class="gmail_quote"><br></div><div class="gmail_quote"><div class="gmail_default" style="font-size:small">So another improvement is to let it wait a bit more than 1 second</div><div class="gmail_default" style="font-size:small">to counteract the rounded-down nanosecond.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I'd add the below change in the patch V2 to make the test more robust.</div></div><div class="gmail_quote"><br></div><div class="gmail_quote"><div class="gmail_default" style="font-size:small">--- a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c</div>+++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c<br>@@ -32,7 +32,7 @@ static void verify_copy_file_range_timestamp(void)<br>        struct timespec timestamp1, timestamp2, diff;<br> <br>        timestamp1 = get_timestamp(fd_dest);<br>-       usleep(1000000);<br>+       usleep(1500000);<br> <br>        offset = 0;<br>        TEST(sys_copy_file_range(fd_src, &offset,<br><div class="gmail_default" style="font-size:small"></div></div><div><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Signed-off-by: Li Wang <<a href="mailto:liwang@redhat.com" target="_blank">liwang@redhat.com</a>><br>
---<br>
 .../syscalls/copy_file_range/copy_file_range03.c  | 15 +++++++++------<br>
 1 file changed, 9 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c<br>
index 253eb57ad..5d055e6ba 100644<br>
--- a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c<br>
+++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c<br>
@@ -12,25 +12,26 @@<br>
 #define _GNU_SOURCE<br>
<br>
 #include "tst_test.h"<br>
+#include "tst_timer.h"<br>
 #include "copy_file_range.h"<br>
<br>
 static int fd_src;<br>
 static int fd_dest;<br>
<br>
-unsigned long get_timestamp(int fd)<br>
+struct timespec get_timestamp(int fd)<br>
 {<br>
        struct stat filestat;<br>
<br>
        fstat(fd, &filestat);<br>
-       return filestat.st_mtime;<br>
+       return filestat.st_mtim;<br>
 }<br>
<br>
 static void verify_copy_file_range_timestamp(void)<br>
 {<br>
        loff_t offset;<br>
-       unsigned long timestamp, updated_timestamp;<br>
+       struct timespec timestamp1, timestamp2, diff;<br>
<br>
-       timestamp = get_timestamp(fd_dest);<br>
+       timestamp1 = get_timestamp(fd_dest);<br>
        usleep(1000000);<br>
<br>
        offset = 0;<br>
@@ -40,9 +41,11 @@ static void verify_copy_file_range_timestamp(void)<br>
                tst_brk(TBROK | TTERRNO,<br>
                                "copy_file_range unexpectedly failed");<br>
<br>
-       updated_timestamp = get_timestamp(fd_dest);<br>
+       timestamp2 = get_timestamp(fd_dest);<br>
<br>
-       if (timestamp == updated_timestamp)<br>
+       diff = tst_timespec_diff(timestamp1, timestamp2);<br>
+<br>
+       if (!diff.tv_sec && !diff.tv_nsec)<br>
                tst_brk(TFAIL, "copy_file_range did not update timestamp.");<br>
<br>
        tst_res(TPASS, "copy_file_range sucessfully updated the timestamp");<br>
-- <br>
2.31.1<br>
<br>
<br>
-- <br>
Mailing list info: <a href="https://lists.linux.it/listinfo/ltp" rel="noreferrer" target="_blank">https://lists.linux.it/listinfo/ltp</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div></div>