<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <<a href="mailto:xzhou@redhat.com">xzhou@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">To check if the filesystem we are testing on supports FIBMAP, mkswap,<br>
swapon and swapoff operations.<br>
Modify make_swapfile function to test mkswap support status safely.<br>
<br>
Signed-off-by: Murphy Zhou <<a href="mailto:xzhou@redhat.com" target="_blank">xzhou@redhat.com</a>><br>
---<br>
 testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-<br>
 testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-<br>
 2 files changed, 49 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c<br>
index cf6a98891..f66d19548 100644<br>
--- a/testcases/kernel/syscalls/swapon/libswapon.c<br>
+++ b/testcases/kernel/syscalls/swapon/libswapon.c<br>
@@ -19,13 +19,15 @@<br>
  *<br>
  */<br>
<br>
+#include <errno.h><br>
+#include "lapi/syscalls.h"<br>
 #include "test.h"<br>
 #include "libswapon.h"<br>
<br>
 /*<br>
  * Make a swap file<br>
  */<br>
-void make_swapfile(void (cleanup)(void), const char *swapfile)<br>
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)<br>
 {<br>
        if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,<br>
            TST_BYTES)) {<br>
@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)<br>
        argv[1] = swapfile;<br>
        argv[2] = NULL;<br>
<br>
-       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);<br>
+       return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);<br>
+}<br>
+<br>
+/*<br>
+ * Check swapon/swapoff support status of filesystems or files<br>
+ * we are testing on.<br>
+ */<br>
+void is_swap_supported(void (cleanup)(void), const char *filename)<br>
+{<br>
+       int fibmap = tst_fibmap(filename);<br>
+       long fs_type = tst_fs_type(cleanup, filename);<br>
+       const char *fstype = tst_fs_type_name(fs_type);<br>
+<br>
+       int ret = make_swapfile(NULL, filename, 1);<br>
+       if (ret != 0) {<br>
+               if (fibmap != 0) {<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">As I replied in patch 1/4, how do we know that means FIBMAP not support if just verify fibmap != 0?</div><div class="gmail_default" style="font-size:small">So I would suggest to make the return value of tst_fibmap() is more precise and do if (fibmap == 1) check here.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+                       tst_brkm(TCONF, cleanup,<br>
+                               "mkswap on %s not supported", fstype);<br>
+               } else {<br>
+                       tst_brkm(TFAIL, cleanup,<br>
+                               "mkswap on %s failed", fstype);<br>
+               }<br>
+       }<br>
+<br>
+       TEST(ltp_syscall(__NR_swapon, filename, 0));<br>
+       if (TEST_RETURN == -1) {<br>
+               if (fibmap != 0 && errno == EINVAL) {<br>
+                       tst_brkm(TCONF, cleanup,<br>
+                               "Swapfile on %s not implemented", fstype);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Maybe there is unnecessary to check fibmap value again? Since if the fibmap is 1, it has already broken in make_swapfile() error handler and never coming here?</div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+               } else {<br>
+                       tst_brkm(TFAIL | TERRNO, cleanup,<br>
+                                "swapon on %s failed", fstype);<br>
+               }<br>
+       }<br>
+<br>
+       TEST(ltp_syscall(__NR_swapoff, filename, 0));<br>
+       if (TEST_RETURN == -1) {<br>
+               tst_brkm(TFAIL | TERRNO, cleanup,<br>
+                       "swapoff on %s failed", fstype);<br>
+       }<br>
 }<br>
diff --git a/testcases/kernel/syscalls/swapon/libswapon.h b/testcases/kernel/syscalls/swapon/libswapon.h<br>
index 7f7211eb4..a51833ec1 100644<br>
--- a/testcases/kernel/syscalls/swapon/libswapon.h<br>
+++ b/testcases/kernel/syscalls/swapon/libswapon.h<br>
@@ -29,6 +29,11 @@<br>
 /*<br>
  * Make a swap file<br>
  */<br>
-void make_swapfile(void (cleanup)(void), const char *swapfile);<br>
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);<br>
<br>
+/*<br>
+ * Check swapon/swapoff support status of filesystems or files<br>
+ * we are testing on.<br>
+ */<br>
+void is_swap_supported(void (cleanup)(void), const char *filename);<br>
 #endif /* __LIBSWAPON_H__ */<br>
-- <br>
2.21.0<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>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div></div>