<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 FIBMAP ioctl is supported on the filesystem we are<br>
testing on. It also can check the support status of specific<br>
files, but that may not needed for now.<br>
<br>
Signed-off-by: Murphy Zhou <<a href="mailto:xzhou@redhat.com" target="_blank">xzhou@redhat.com</a>><br>
---<br>
v6:<br>
Modify make_swapfile() to check mkswap support status safely<br>
Remove whitelist<br>
Remove BTRFS EINVAL check<br>
Check mkswap status before testing swapon in helper<br>
If swapon pass, following swapoff failure will fail the whole test and break<br>
Also modify swapoff02 to remove whitelist completely<br>
v5:<br>
Split to 4 patches<br>
Only take one filename parameter in tst_fibmap<br>
Add helper is_swap_supported to check swap operation support status<br>
Test fibmap/swapon and swapoff operation in the helper<br>
Keep NFS/TMPFS whitelist<br>
Keep BTRFS EINVAL handling logic, except above 2 situation:<br>
if swapon fails and fibmap is not supported, tst_brk with TCONF<br>
if swapon fails and fibmap is supported, tst_brk with TFAIL<br>
If swapon test pass in the helper, test swapoff similarly<br>
Put is_swap_supported helper in libswapon, link swapoff binaries to it<br>
Mute a sprintf filaname wanrning by the way<br>
v4:<br>
Fail softly if FIBMAP nit supported, instead of skip entire testcase<br>
v3:<br>
Fix fs_type undeclared in swapoff01.c<br>
v2:<br>
Test FIBMAP instead of fstype whitelist<br>
<br>
include/tst_fs.h | 5 +++++<br>
lib/tst_ioctl.c | 37 +++++++++++++++++++++++++++++++++++++<br>
2 files changed, 42 insertions(+)<br>
create mode 100644 lib/tst_ioctl.c<br>
<br>
diff --git a/include/tst_fs.h b/include/tst_fs.h<br>
index ebca065c6..6d03371ec 100644<br>
--- a/include/tst_fs.h<br>
+++ b/include/tst_fs.h<br>
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);<br>
*/<br>
void tst_fill_fs(const char *path, int verbose);<br>
<br>
+/*<br>
+ * test if FIBMAP ioctl is supported<br>
+ */<br>
+int tst_fibmap(const char *filename);<br>
+<br>
#ifdef TST_TEST_H__<br>
static inline long tst_fs_type(const char *path)<br>
{<br>
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c<br>
new file mode 100644<br>
index 000000000..38aa937db<br>
--- /dev/null<br>
+++ b/lib/tst_ioctl.c<br>
@@ -0,0 +1,37 @@<br>
+// SPDX-License-Identifier: GPL-2.0-or-later<br>
+<br>
+#include <errno.h><br>
+#include <stdio.h><br>
+#include <stdlib.h><br>
+#include <sys/ioctl.h><br>
+#include <linux/fs.h><br>
+<br>
+#define TST_NO_DEFAULT_MAIN<br>
+<br>
+#include "tst_test.h"<br>
+<br>
+int tst_fibmap(const char *filename)<br>
+{<br>
+ /* test if FIBMAP ioctl is supported */<br>
+ int fd, block = 0;<br>
+<br>
+ fd = open(filename, O_RDWR | O_CREAT, 0666);<br>
+ if (fd < 0) {<br>
+ tst_res(TWARN | TERRNO,<br>
+ "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);<br>
+ return 1;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">what about return -1 here? Calling this tst_fibmap() in otherplace, we don't know that</div><div class="gmail_default" style="font-size:small">the reruened 1 means a open/close() fail or FIBMAP ioctl is NOT supported.</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">
+ }<br>
+<br>
+ if (ioctl(fd, FIBMAP, &block)) {<br>
+ tst_res(TINFO, "FIBMAP ioctl is NOT supported");<br>
+ close(fd);<br>
+ return 1;<br>
+ }<br>
+ tst_res(TINFO, "FIBMAP ioctl is supported");<br>
+<br>
+ if (close(fd)) {<br>
+ tst_res(TWARN | TERRNO, "close(fd) failed");<br>
+ return 1;<br></blockquote><div><br></div><div class="gmail_default" style="font-size:small">return -1;</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">
+ }<br>
+ return 0;<br>
+}<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>