All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
@ 2019-04-30  7:14 Murphy Zhou
  2019-04-30  8:14 ` Li Wang
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-04-30  7:14 UTC (permalink / raw)
  To: ltp

Currently swapfiles on Overlayfs are not supported.

So if we are on overlayfs and we get EINVAL from swapon() we return TCONF.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..211cdfc4e 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)
 			return;
 	}
 
+	if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
+		tst_resm(TCONF, "Swapfile on overlayfs not implemeted");
+			return;
+	}
+
 	tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
 	         " %d, errno: %s and got %d.", test->exp_errno,
 	         test->exp_errval, TEST_ERRNO);
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  7:14 [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs Murphy Zhou
@ 2019-04-30  8:14 ` Li Wang
  2019-04-30  8:30   ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Li Wang @ 2019-04-30  8:14 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 3:21 PM Murphy Zhou <xzhou@redhat.com> wrote:

> Currently swapfiles on Overlayfs are not supported.
>
> So if we are on overlayfs and we get EINVAL from swapon() we return TCONF.
>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> ---
>  testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/swapon/swapon02.c
> b/testcases/kernel/syscalls/swapon/swapon02.c
> index 4af5105c6..211cdfc4e 100644
> --- a/testcases/kernel/syscalls/swapon/swapon02.c
> +++ b/testcases/kernel/syscalls/swapon/swapon02.c
> @@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)
>                         return;
>         }
>
> +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
> +               tst_resm(TCONF, "Swapfile on overlayfs not implemeted");
> +                       return;
> +       }
>

The code looks correct.

But it already has a test skipping for BTRFS, is there any possibility to
combine these filesystems check together?


> +
>         tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
>                  " %d, errno: %s and got %d.", test->exp_errno,
>                  test->exp_errval, TEST_ERRNO);
> --
> 2.21.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190430/37366418/attachment.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  8:14 ` Li Wang
@ 2019-04-30  8:30   ` Murphy Zhou
  2019-04-30  8:54     ` Li Wang
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-04-30  8:30 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 04:14:23PM +0800, Li Wang wrote:
> On Tue, Apr 30, 2019 at 3:21 PM Murphy Zhou <xzhou@redhat.com> wrote:
> 
> > Currently swapfiles on Overlayfs are not supported.
> >
> > So if we are on overlayfs and we get EINVAL from swapon() we return TCONF.
> >
> > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > ---
> >  testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/testcases/kernel/syscalls/swapon/swapon02.c
> > b/testcases/kernel/syscalls/swapon/swapon02.c
> > index 4af5105c6..211cdfc4e 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon02.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon02.c
> > @@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)
> >                         return;
> >         }
> >
> > +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
> > +               tst_resm(TCONF, "Swapfile on overlayfs not implemeted");
> > +                       return;
> > +       }
> >
> 
> The code looks correct.
> 
> But it already has a test skipping for BTRFS, is there any possibility to
> combine these filesystems check together?

Good idea~  Sending V2.

Thansk!
M

> 
> 
> > +
> >         tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
> >                  " %d, errno: %s and got %d.", test->exp_errno,
> >                  test->exp_errval, TEST_ERRNO);
> > --
> > 2.21.0
> >
> >
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
> >
> 
> 
> -- 
> Regards,
> Li Wang

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  8:30   ` Murphy Zhou
@ 2019-04-30  8:54     ` Li Wang
  2019-04-30  9:08       ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Li Wang @ 2019-04-30  8:54 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 4:31 PM Murphy Zhou <xzhou@redhat.com> wrote:

> On Tue, Apr 30, 2019 at 04:14:23PM +0800, Li Wang wrote:
> > On Tue, Apr 30, 2019 at 3:21 PM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > > Currently swapfiles on Overlayfs are not supported.
> > >
> > > So if we are on overlayfs and we get EINVAL from swapon() we return
> TCONF.
> > >
> > > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > ---
> > >  testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > >
> > > diff --git a/testcases/kernel/syscalls/swapon/swapon02.c
> > > b/testcases/kernel/syscalls/swapon/swapon02.c
> > > index 4af5105c6..211cdfc4e 100644
> > > --- a/testcases/kernel/syscalls/swapon/swapon02.c
> > > +++ b/testcases/kernel/syscalls/swapon/swapon02.c
> > > @@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)
> > >                         return;
> > >         }
> > >
> > > +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
> > > +               tst_resm(TCONF, "Swapfile on overlayfs not
> implemeted");
> > > +                       return;
> > > +       }
> > >
> >
> > The code looks correct.
> >
> > But it already has a test skipping for BTRFS, is there any possibility to
> > combine these filesystems check together?
>
> Good idea~  Sending V2.
>

One more comment.

I just noticed that it also has an FS skipping list in setup(), do u think
can we move BTRFS and OVERLAYFS to there?

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190430/40504742/attachment.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  8:54     ` Li Wang
@ 2019-04-30  9:08       ` Murphy Zhou
  2019-04-30  9:21         ` Li Wang
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-04-30  9:08 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 04:54:23PM +0800, Li Wang wrote:
> On Tue, Apr 30, 2019 at 4:31 PM Murphy Zhou <xzhou@redhat.com> wrote:
> 
> > On Tue, Apr 30, 2019 at 04:14:23PM +0800, Li Wang wrote:
> > > On Tue, Apr 30, 2019 at 3:21 PM Murphy Zhou <xzhou@redhat.com> wrote:
> > >
> > > > Currently swapfiles on Overlayfs are not supported.
> > > >
> > > > So if we are on overlayfs and we get EINVAL from swapon() we return
> > TCONF.
> > > >
> > > > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > > ---
> > > >  testcases/kernel/syscalls/swapon/swapon02.c | 5 +++++
> > > >  1 file changed, 5 insertions(+)
> > > >
> > > > diff --git a/testcases/kernel/syscalls/swapon/swapon02.c
> > > > b/testcases/kernel/syscalls/swapon/swapon02.c
> > > > index 4af5105c6..211cdfc4e 100644
> > > > --- a/testcases/kernel/syscalls/swapon/swapon02.c
> > > > +++ b/testcases/kernel/syscalls/swapon/swapon02.c
> > > > @@ -86,6 +86,11 @@ static void verify_swapon(struct test_case_t *test)
> > > >                         return;
> > > >         }
> > > >
> > > > +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
> > > > +               tst_resm(TCONF, "Swapfile on overlayfs not
> > implemeted");
> > > > +                       return;
> > > > +       }
> > > >
> > >
> > > The code looks correct.
> > >
> > > But it already has a test skipping for BTRFS, is there any possibility to
> > > combine these filesystems check together?
> >
> > Good idea~  Sending V2.
> >
> 
> One more comment.
> 
> I just noticed that it also has an FS skipping list in setup(), do u think
> can we move BTRFS and OVERLAYFS to there?

Great! That makes perfect sense. Also I'm thinking a few other tweaks
needed:

  NFS now actually support swapfiles. Let's remove it from skip list;
  Skip all swapon/swapoff tests on TMPFS BTRFS OVERLAYFS;
  Add CIFS_MAGIC, then skip on it too;
  Remove existing BTRFS return value tweaks.

Thanks,
M

> 
> -- 
> Regards,
> Li Wang

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  9:08       ` Murphy Zhou
@ 2019-04-30  9:21         ` Li Wang
  2019-04-30  9:29           ` Murphy Zhou
  2019-04-30  9:37           ` Amir Goldstein
  0 siblings, 2 replies; 55+ messages in thread
From: Li Wang @ 2019-04-30  9:21 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 5:08 PM Murphy Zhou <xzhou@redhat.com> wrote:

> ...
> > > > > +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
> > > > > +               tst_resm(TCONF, "Swapfile on overlayfs not
> > > implemeted");
> > > > > +                       return;
> > > > > +       }
> > > > >
> > > >
> > > > The code looks correct.
> > > >
> > > > But it already has a test skipping for BTRFS, is there any
> possibility to
> > > > combine these filesystems check together?
> > >
> > > Good idea~  Sending V2.
> > >
> >
> > One more comment.
> >
> > I just noticed that it also has an FS skipping list in setup(), do u
> think
> > can we move BTRFS and OVERLAYFS to there?
>
> Great! That makes perfect sense. Also I'm thinking a few other tweaks
> needed:
>
>   NFS now actually support swapfiles. Let's remove it from skip list;
>

But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee
the test works fine in that situation. So, my opinion is to reserve the
NFS, or do you have a better way to make test more flexible?


>   Skip all swapon/swapoff tests on TMPFS BTRFS OVERLAYFS;
>   Add CIFS_MAGIC, then skip on it too;
>   Remove existing BTRFS return value tweaks.
>

Agree.

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190430/1dbfc940/attachment.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  9:21         ` Li Wang
@ 2019-04-30  9:29           ` Murphy Zhou
  2019-04-30  9:37           ` Amir Goldstein
  1 sibling, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-04-30  9:29 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 05:21:34PM +0800, Li Wang wrote:
> On Tue, Apr 30, 2019 at 5:08 PM Murphy Zhou <xzhou@redhat.com> wrote:
> 
> > ...
> > > > > > +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
> > > > > > +               tst_resm(TCONF, "Swapfile on overlayfs not
> > > > implemeted");
> > > > > > +                       return;
> > > > > > +       }
> > > > > >
> > > > >
> > > > > The code looks correct.
> > > > >
> > > > > But it already has a test skipping for BTRFS, is there any
> > possibility to
> > > > > combine these filesystems check together?
> > > >
> > > > Good idea~  Sending V2.
> > > >
> > >
> > > One more comment.
> > >
> > > I just noticed that it also has an FS skipping list in setup(), do u
> > think
> > > can we move BTRFS and OVERLAYFS to there?
> >
> > Great! That makes perfect sense. Also I'm thinking a few other tweaks
> > needed:
> >
> >   NFS now actually support swapfiles. Let's remove it from skip list;
> >
> 
> But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee
> the test works fine in that situation. So, my opinion is to reserve the
> NFS, or do you have a better way to make test more flexible?

Fair enough. We can reserve NFS on the skip list to avoid much false alarms.
> 
> 
> >   Skip all swapon/swapoff tests on TMPFS BTRFS OVERLAYFS;
> >   Add CIFS_MAGIC, then skip on it too;
> >   Remove existing BTRFS return value tweaks.
> >
> 
> Agree.

Thanks!

M
> 
> -- 
> Regards,
> Li Wang

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  9:21         ` Li Wang
  2019-04-30  9:29           ` Murphy Zhou
@ 2019-04-30  9:37           ` Amir Goldstein
  2019-04-30  9:54             ` Murphy Zhou
  1 sibling, 1 reply; 55+ messages in thread
From: Amir Goldstein @ 2019-04-30  9:37 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 5:21 AM Li Wang <liwang@redhat.com> wrote:
>
>
>
> On Tue, Apr 30, 2019 at 5:08 PM Murphy Zhou <xzhou@redhat.com> wrote:
>>
>> ...
>> > > > > +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
>> > > > > +               tst_resm(TCONF, "Swapfile on overlayfs not
>> > > implemeted");
>> > > > > +                       return;
>> > > > > +       }
>> > > > >
>> > > >
>> > > > The code looks correct.
>> > > >
>> > > > But it already has a test skipping for BTRFS, is there any possibility to
>> > > > combine these filesystems check together?
>> > >
>> > > Good idea~  Sending V2.
>> > >
>> >
>> > One more comment.
>> >
>> > I just noticed that it also has an FS skipping list in setup(), do u think
>> > can we move BTRFS and OVERLAYFS to there?
>>
>> Great! That makes perfect sense. Also I'm thinking a few other tweaks
>> needed:
>>
>>   NFS now actually support swapfiles. Let's remove it from skip list;
>
>
> But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee the test works fine in that situation. So, my opinion is to reserve the NFS, or do you have a better way to make test more flexible?

Avoid whitelist.
Test for FIBMAP ioctl support.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs
  2019-04-30  9:37           ` Amir Goldstein
@ 2019-04-30  9:54             ` Murphy Zhou
  2019-04-30 15:29               ` [LTP] [PATCH v2] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-04-30  9:54 UTC (permalink / raw)
  To: ltp

On Tue, Apr 30, 2019 at 05:37:36AM -0400, Amir Goldstein wrote:
> On Tue, Apr 30, 2019 at 5:21 AM Li Wang <liwang@redhat.com> wrote:
> >
> >
> >
> > On Tue, Apr 30, 2019 at 5:08 PM Murphy Zhou <xzhou@redhat.com> wrote:
> >>
> >> ...
> >> > > > > +       if (fs_type == TST_OVERLAYFS_MAGIC && errno == EINVAL) {
> >> > > > > +               tst_resm(TCONF, "Swapfile on overlayfs not
> >> > > implemeted");
> >> > > > > +                       return;
> >> > > > > +       }
> >> > > > >
> >> > > >
> >> > > > The code looks correct.
> >> > > >
> >> > > > But it already has a test skipping for BTRFS, is there any possibility to
> >> > > > combine these filesystems check together?
> >> > >
> >> > > Good idea~  Sending V2.
> >> > >
> >> >
> >> > One more comment.
> >> >
> >> > I just noticed that it also has an FS skipping list in setup(), do u think
> >> > can we move BTRFS and OVERLAYFS to there?
> >>
> >> Great! That makes perfect sense. Also I'm thinking a few other tweaks
> >> needed:
> >>
> >>   NFS now actually support swapfiles. Let's remove it from skip list;
> >
> >
> > But AFAIK someone still run LTP on old distro/kernel, so we can't guarantee the test works fine in that situation. So, my opinion is to reserve the NFS, or do you have a better way to make test more flexible?
> 
> Avoid whitelist.
> Test for FIBMAP ioctl support.

Hmm.. This is better. I'll try.

Thanks!
M

> 
> Thanks,
> Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v2] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
  2019-04-30  9:54             ` Murphy Zhou
@ 2019-04-30 15:29               ` Murphy Zhou
  2019-04-30 23:59                 ` [LTP] [PATCH v3] " Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-04-30 15:29 UTC (permalink / raw)
  To: ltp

That means swapfile in the test filesystem is not supported.
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 include/tst_fs.h                              |  5 +++
 lib/tst_ioctl.c                               | 41 +++++++++++++++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++----
 testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ++---
 testcases/kernel/syscalls/swapon/swapon01.c   | 13 ++----
 testcases/kernel/syscalls/swapon/swapon02.c   | 16 ++------
 testcases/kernel/syscalls/swapon/swapon03.c   | 20 ++-------
 7 files changed, 64 insertions(+), 54 deletions(-)
 create mode 100644 lib/tst_ioctl.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index b2b19ada6..cc38b3547 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
  */
 void tst_fill_fs(const char *path, int verbose);
 
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(void);
+
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
 {
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
new file mode 100644
index 000000000..d468d5898
--- /dev/null
+++ b/lib/tst_ioctl.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(void)
+{
+	/* test if FIBMAP ioctl is supported */
+	int fd, block = 0;
+	const char *tmpdir = getenv("TMPDIR");
+	char buf[128];
+
+	tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s", tmpdir);
+
+	sprintf(buf, "%s/tst_fibmap", tmpdir);
+
+	fd = open(buf, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		tst_res(TWARN | TERRNO,
+			 "open(%s, O_RDWR | O_CREAT, 0666) failed", buf);
+		return 1;
+	}
+
+	if (ioctl(fd, FIBMAP, &block)) {
+		close(fd);
+		return 1;
+	}
+
+	if (close(fd)) {
+		tst_res(TWARN | TERRNO, "close(fd) failed");
+		return 1;
+	}
+	return 0;
+}
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index a63e661a5..a37cd9be1 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -55,11 +55,6 @@ int main(int ac, char **av)
 static void verify_swapoff(void)
 {
 	if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
-		if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-			tst_brkm(TCONF, cleanup,
-			         "Swapfiles on BTRFS are not implemented");
-		}
-
 		tst_resm(TBROK, "Failed to turn on the swap file"
 			 ", skipping test iteration");
 		return;
@@ -86,13 +81,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index b5c6312a1..d14b1c7ab 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -138,13 +138,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(type));
-	break;
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
+			 tst_fs_type_name(fs_type));
 	}
 
 	if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index 32538f82b..0a5a3de86 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -39,11 +39,6 @@ static void verify_swapon(void)
 	TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
 
 	if (TEST_RETURN == -1) {
-		if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-			tst_brkm(TCONF, cleanup,
-			         "Swapfile on BTRFS not implemeted");
-			return;
-		}
 		tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
 	} else {
 		tst_resm(TPASS, "Succeeded to turn on swapfile");
@@ -84,13 +79,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	make_swapfile(cleanup, "swapfile01");
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..31f0c66ac 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -81,11 +81,6 @@ static void verify_swapon(struct test_case_t *test)
 		return;
 	}
 
-	if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-		tst_resm(TCONF, "Swapfile on BTRFS not implemeted");
-			return;
-	}
-
 	tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
 	         " %d, errno: %s and got %d.", test->exp_errno,
 	         test->exp_errval, TEST_ERRNO);
@@ -132,13 +127,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
@@ -146,8 +139,7 @@ static void setup(void)
 	make_swapfile(cleanup, "alreadyused");
 
 	if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
-		if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
-			tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
+		tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
 	} else {
 		do_swapoff = 1;
 	}
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 955ac247b..391391fbf 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -215,9 +215,6 @@ static int setup_swap(void)
 			/* turn on the swap file */
 			res = ltp_syscall(__NR_swapon, filename, 0);
 			if (res != 0) {
-				if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL)
-					exit(2);
-
 				if (errno == EPERM) {
 					printf("Successfully created %d "
 					       "swapfiles\n", j);
@@ -233,15 +230,8 @@ static int setup_swap(void)
 	} else
 		waitpid(pid, &status, 0);
 
-	switch (WEXITSTATUS(status)) {
-	case 0:
-	break;
-	case 2:
-		tst_brkm(TCONF, cleanup, "Swapfile on BTRFS not implemeted");
-	break;
-	default:
+	if (WEXITSTATUS(status)) {
 		tst_brkm(TFAIL, cleanup, "Failed to setup swaps");
-	break;
 	}
 
 	/* Create all needed extra swapfiles for testing */
@@ -333,13 +323,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	TEST_PAUSE;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
  2019-04-30 15:29               ` [LTP] [PATCH v2] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails Murphy Zhou
@ 2019-04-30 23:59                 ` Murphy Zhou
  2019-05-07  8:52                   ` Li Wang
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-04-30 23:59 UTC (permalink / raw)
  To: ltp

That means swapfile in the test filesystem is not supported.
Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
v2:
   Test FIBMAP instead of fstype whitelist.
v3:
   Fix fs_type undeclared in swapoff01.c.

 include/tst_fs.h                              |  5 +++
 lib/tst_ioctl.c                               | 41 +++++++++++++++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++----
 testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++--
 testcases/kernel/syscalls/swapon/swapon01.c   | 13 ++----
 testcases/kernel/syscalls/swapon/swapon02.c   | 16 ++------
 testcases/kernel/syscalls/swapon/swapon03.c   | 20 ++-------
 7 files changed, 65 insertions(+), 54 deletions(-)
 create mode 100644 lib/tst_ioctl.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index b2b19ada6..cc38b3547 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
  */
 void tst_fill_fs(const char *path, int verbose);
 
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(void);
+
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
 {
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
new file mode 100644
index 000000000..d468d5898
--- /dev/null
+++ b/lib/tst_ioctl.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(void)
+{
+	/* test if FIBMAP ioctl is supported */
+	int fd, block = 0;
+	const char *tmpdir = getenv("TMPDIR");
+	char buf[128];
+
+	tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s", tmpdir);
+
+	sprintf(buf, "%s/tst_fibmap", tmpdir);
+
+	fd = open(buf, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		tst_res(TWARN | TERRNO,
+			 "open(%s, O_RDWR | O_CREAT, 0666) failed", buf);
+		return 1;
+	}
+
+	if (ioctl(fd, FIBMAP, &block)) {
+		close(fd);
+		return 1;
+	}
+
+	if (close(fd)) {
+		tst_res(TWARN | TERRNO, "close(fd) failed");
+		return 1;
+	}
+	return 0;
+}
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index a63e661a5..a37cd9be1 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -55,11 +55,6 @@ int main(int ac, char **av)
 static void verify_swapoff(void)
 {
 	if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
-		if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-			tst_brkm(TCONF, cleanup,
-			         "Swapfiles on BTRFS are not implemented");
-		}
-
 		tst_resm(TBROK, "Failed to turn on the swap file"
 			 ", skipping test iteration");
 		return;
@@ -86,13 +81,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index b5c6312a1..889f3c800 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -43,6 +43,7 @@ char *TCID = "swapoff02";
 int TST_TOTAL = 3;
 
 static uid_t nobody_uid;
+static long fs_type;
 
 static struct test_case_t {
 	char *err_desc;
@@ -138,13 +139,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(type));
-	break;
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
+			 tst_fs_type_name(fs_type));
 	}
 
 	if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index 32538f82b..0a5a3de86 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -39,11 +39,6 @@ static void verify_swapon(void)
 	TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
 
 	if (TEST_RETURN == -1) {
-		if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-			tst_brkm(TCONF, cleanup,
-			         "Swapfile on BTRFS not implemeted");
-			return;
-		}
 		tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
 	} else {
 		tst_resm(TPASS, "Succeeded to turn on swapfile");
@@ -84,13 +79,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	make_swapfile(cleanup, "swapfile01");
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..31f0c66ac 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -81,11 +81,6 @@ static void verify_swapon(struct test_case_t *test)
 		return;
 	}
 
-	if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-		tst_resm(TCONF, "Swapfile on BTRFS not implemeted");
-			return;
-	}
-
 	tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
 	         " %d, errno: %s and got %d.", test->exp_errno,
 	         test->exp_errval, TEST_ERRNO);
@@ -132,13 +127,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
@@ -146,8 +139,7 @@ static void setup(void)
 	make_swapfile(cleanup, "alreadyused");
 
 	if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
-		if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
-			tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
+		tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
 	} else {
 		do_swapoff = 1;
 	}
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 955ac247b..391391fbf 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -215,9 +215,6 @@ static int setup_swap(void)
 			/* turn on the swap file */
 			res = ltp_syscall(__NR_swapon, filename, 0);
 			if (res != 0) {
-				if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL)
-					exit(2);
-
 				if (errno == EPERM) {
 					printf("Successfully created %d "
 					       "swapfiles\n", j);
@@ -233,15 +230,8 @@ static int setup_swap(void)
 	} else
 		waitpid(pid, &status, 0);
 
-	switch (WEXITSTATUS(status)) {
-	case 0:
-	break;
-	case 2:
-		tst_brkm(TCONF, cleanup, "Swapfile on BTRFS not implemeted");
-	break;
-	default:
+	if (WEXITSTATUS(status)) {
 		tst_brkm(TFAIL, cleanup, "Failed to setup swaps");
-	break;
 	}
 
 	/* Create all needed extra swapfiles for testing */
@@ -333,13 +323,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap()) {
 		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
+			 "Cannot do FIBMAP ioctl on a file on %s filesystem",
 			 tst_fs_type_name(fs_type));
-	break;
 	}
 
 	TEST_PAUSE;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
  2019-04-30 23:59                 ` [LTP] [PATCH v3] " Murphy Zhou
@ 2019-05-07  8:52                   ` Li Wang
  2019-05-08  3:43                     ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Li Wang @ 2019-05-07  8:52 UTC (permalink / raw)
  To: ltp

Hi Murphy,

On Wed, May 1, 2019 at 7:59 AM Murphy Zhou <xzhou@redhat.com> wrote:

> That means swapfile in the test filesystem is not supported.
> Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist
> code.
>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> ---
> v2:
>    Test FIBMAP instead of fstype whitelist.
> v3:
>    Fix fs_type undeclared in swapoff01.c.
>
>  include/tst_fs.h                              |  5 +++
>  lib/tst_ioctl.c                               | 41 +++++++++++++++++++
>  testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++----
>  testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++--
>  testcases/kernel/syscalls/swapon/swapon01.c   | 13 ++----
>  testcases/kernel/syscalls/swapon/swapon02.c   | 16 ++------
>  testcases/kernel/syscalls/swapon/swapon03.c   | 20 ++-------
>  7 files changed, 65 insertions(+), 54 deletions(-)
>  create mode 100644 lib/tst_ioctl.c
>
> diff --git a/include/tst_fs.h b/include/tst_fs.h
> index b2b19ada6..cc38b3547 100644
> --- a/include/tst_fs.h
> +++ b/include/tst_fs.h
> @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
>   */
>  void tst_fill_fs(const char *path, int verbose);
>
> +/*
> + * test if FIBMAP ioctl is supported
> + */
> +int tst_fibmap(void);
> +
>  #ifdef TST_TEST_H__
>  static inline long tst_fs_type(const char *path)
>  {
> diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> new file mode 100644
> index 000000000..d468d5898
> --- /dev/null
> +++ b/lib/tst_ioctl.c
> @@ -0,0 +1,41 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +
> +#include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <linux/fs.h>
> +
> +#define TST_NO_DEFAULT_MAIN
> +
> +#include "tst_test.h"
> +
> +int tst_fibmap(void)
> +{
> +       /* test if FIBMAP ioctl is supported */
> +       int fd, block = 0;
> +       const char *tmpdir = getenv("TMPDIR");
> +       char buf[128];
> +
> +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",
> tmpdir);
> +
> +       sprintf(buf, "%s/tst_fibmap", tmpdir);
> +
> +       fd = open(buf, O_RDWR | O_CREAT, 0666);
> +       if (fd < 0) {
> +               tst_res(TWARN | TERRNO,
> +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", buf);
> +               return 1;
> +       }
> +
> +       if (ioctl(fd, FIBMAP, &block)) {
> +               close(fd);
> +               return 1;
> +       }
> +
> +       if (close(fd)) {
> +               tst_res(TWARN | TERRNO, "close(fd) failed");
> +               return 1;
> +       }
> +       return 0;
> +}
> diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c
> b/testcases/kernel/syscalls/swapoff/swapoff01.c
> index a63e661a5..a37cd9be1 100644
> --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> @@ -55,11 +55,6 @@ int main(int ac, char **av)
>  static void verify_swapoff(void)
>  {
>         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> -                       tst_brkm(TCONF, cleanup,
> -                                "Swapfiles on BTRFS are not implemented");
> -               }
> -
>                 tst_resm(TBROK, "Failed to turn on the swap file"
>                          ", skipping test iteration");
>                 return;
> @@ -86,13 +81,11 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> +       fs_type = tst_fs_type(cleanup, ".");
> +       if (tst_fibmap()) {
>                 tst_brkm(TCONF, cleanup,
> -                        "Cannot do swapoff on a file on %s filesystem",
> +                        "Cannot do FIBMAP ioctl on a file on %s
> filesystem",
>                          tst_fs_type_name(fs_type));
> -       break;
>         }
>
>         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c
> b/testcases/kernel/syscalls/swapoff/swapoff02.c
> index b5c6312a1..889f3c800 100644
> --- a/testcases/kernel/syscalls/swapoff/swapoff02.c
> +++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
> @@ -43,6 +43,7 @@ char *TCID = "swapoff02";
>  int TST_TOTAL = 3;
>
>  static uid_t nobody_uid;
> +static long fs_type;
>
>  static struct test_case_t {
>         char *err_desc;
> @@ -138,13 +139,11 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> +       fs_type = tst_fs_type(cleanup, ".");
> +       if (tst_fibmap()) {
>                 tst_brkm(TCONF, cleanup,
> -                        "Cannot do swapoff on a file on %s filesystem",
> -                        tst_fs_type_name(type));
> -       break;
> +                        "Cannot do FIBMAP ioctl on a file on %s
> filesystem",
> +                        tst_fs_type_name(fs_type));
>         }
>
>         if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
> diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> b/testcases/kernel/syscalls/swapon/swapon01.c
> index 32538f82b..0a5a3de86 100644
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -39,11 +39,6 @@ static void verify_swapon(void)
>         TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
>
>         if (TEST_RETURN == -1) {
> -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> -                       tst_brkm(TCONF, cleanup,
> -                                "Swapfile on BTRFS not implemeted");
> -                       return;
> -               }
>                 tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
>         } else {
>                 tst_resm(TPASS, "Succeeded to turn on swapfile");
> @@ -84,13 +79,11 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> +       fs_type = tst_fs_type(cleanup, ".");
> +       if (tst_fibmap()) {
>

I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted
on a filesystem.
If that's true, shouldn't we verify FIBMAP ioctl on the swapfile?  Here you
just test that in a tmp file, it probably not a correct way I guess.

IMO, maybe we can define the function API as:
    tst_fibmap(const char *filename);
And calling it in behind of make_swapfile(cleanup, "swapfile01");

Beside that, there is another issue in this patch, since the
getenv("TMPDIR"); depend on runltp script, so we cann't run the test
independently.

# ./swapon01
tst_ioctl.c:20: INFO: Testing if FIBMAP ioctl is supported in (null)
tst_ioctl.c:27: WARN: open((null)/tst_fibmap, O_RDWR | O_CREAT, 0666)
failed: ENOENT
swapon01    1  TCONF  :  swapon01.c:86: Cannot do FIBMAP ioctl on a file on
XFS filesystem
swapon01    2  TCONF  :  swapon01.c:86: Remaining cases not appropriate for
configuration

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190507/9bdefaa0/attachment-0001.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
  2019-05-07  8:52                   ` Li Wang
@ 2019-05-08  3:43                     ` Murphy Zhou
  2019-05-08 10:22                       ` Amir Goldstein
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-05-08  3:43 UTC (permalink / raw)
  To: ltp

Hi,

Thanks for reviewing!

On Tue, May 07, 2019 at 04:52:01PM +0800, Li Wang wrote:
> Hi Murphy,
> 
> On Wed, May 1, 2019 at 7:59 AM Murphy Zhou <xzhou@redhat.com> wrote:
> 
> > That means swapfile in the test filesystem is not supported.
> > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist
> > code.
> >
> > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > ---
> > v2:
> >    Test FIBMAP instead of fstype whitelist.
> > v3:
> >    Fix fs_type undeclared in swapoff01.c.
> >
> >  include/tst_fs.h                              |  5 +++
> >  lib/tst_ioctl.c                               | 41 +++++++++++++++++++
> >  testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++----
> >  testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++--
> >  testcases/kernel/syscalls/swapon/swapon01.c   | 13 ++----
> >  testcases/kernel/syscalls/swapon/swapon02.c   | 16 ++------
> >  testcases/kernel/syscalls/swapon/swapon03.c   | 20 ++-------
> >  7 files changed, 65 insertions(+), 54 deletions(-)
> >  create mode 100644 lib/tst_ioctl.c
> >
> > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > index b2b19ada6..cc38b3547 100644
> > --- a/include/tst_fs.h
> > +++ b/include/tst_fs.h
> > @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
> >   */
> >  void tst_fill_fs(const char *path, int verbose);
> >
> > +/*
> > + * test if FIBMAP ioctl is supported
> > + */
> > +int tst_fibmap(void);
> > +
> >  #ifdef TST_TEST_H__
> >  static inline long tst_fs_type(const char *path)
> >  {
> > diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> > new file mode 100644
> > index 000000000..d468d5898
> > --- /dev/null
> > +++ b/lib/tst_ioctl.c
> > @@ -0,0 +1,41 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +
> > +#include <errno.h>
> > +#include <stdio.h>
> > +#include <stdlib.h>
> > +#include <sys/ioctl.h>
> > +#include <linux/fs.h>
> > +
> > +#define TST_NO_DEFAULT_MAIN
> > +
> > +#include "tst_test.h"
> > +
> > +int tst_fibmap(void)
> > +{
> > +       /* test if FIBMAP ioctl is supported */
> > +       int fd, block = 0;
> > +       const char *tmpdir = getenv("TMPDIR");
> > +       char buf[128];
> > +
> > +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",
> > tmpdir);
> > +
> > +       sprintf(buf, "%s/tst_fibmap", tmpdir);
> > +
> > +       fd = open(buf, O_RDWR | O_CREAT, 0666);
> > +       if (fd < 0) {
> > +               tst_res(TWARN | TERRNO,
> > +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", buf);
> > +               return 1;
> > +       }
> > +
> > +       if (ioctl(fd, FIBMAP, &block)) {
> > +               close(fd);
> > +               return 1;
> > +       }
> > +
> > +       if (close(fd)) {
> > +               tst_res(TWARN | TERRNO, "close(fd) failed");
> > +               return 1;
> > +       }
> > +       return 0;
> > +}
> > diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > index a63e661a5..a37cd9be1 100644
> > --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > @@ -55,11 +55,6 @@ int main(int ac, char **av)
> >  static void verify_swapoff(void)
> >  {
> >         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > -                       tst_brkm(TCONF, cleanup,
> > -                                "Swapfiles on BTRFS are not implemented");
> > -               }
> > -
> >                 tst_resm(TBROK, "Failed to turn on the swap file"
> >                          ", skipping test iteration");
> >                 return;
> > @@ -86,13 +81,11 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > +       fs_type = tst_fs_type(cleanup, ".");
> > +       if (tst_fibmap()) {
> >                 tst_brkm(TCONF, cleanup,
> > -                        "Cannot do swapoff on a file on %s filesystem",
> > +                        "Cannot do FIBMAP ioctl on a file on %s
> > filesystem",
> >                          tst_fs_type_name(fs_type));
> > -       break;
> >         }
> >
> >         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> > diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c
> > b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > index b5c6312a1..889f3c800 100644
> > --- a/testcases/kernel/syscalls/swapoff/swapoff02.c
> > +++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > @@ -43,6 +43,7 @@ char *TCID = "swapoff02";
> >  int TST_TOTAL = 3;
> >
> >  static uid_t nobody_uid;
> > +static long fs_type;
> >
> >  static struct test_case_t {
> >         char *err_desc;
> > @@ -138,13 +139,11 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > +       fs_type = tst_fs_type(cleanup, ".");
> > +       if (tst_fibmap()) {
> >                 tst_brkm(TCONF, cleanup,
> > -                        "Cannot do swapoff on a file on %s filesystem",
> > -                        tst_fs_type_name(type));
> > -       break;
> > +                        "Cannot do FIBMAP ioctl on a file on %s
> > filesystem",
> > +                        tst_fs_type_name(fs_type));
> >         }
> >
> >         if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
> > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> > b/testcases/kernel/syscalls/swapon/swapon01.c
> > index 32538f82b..0a5a3de86 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > @@ -39,11 +39,6 @@ static void verify_swapon(void)
> >         TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
> >
> >         if (TEST_RETURN == -1) {
> > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > -                       tst_brkm(TCONF, cleanup,
> > -                                "Swapfile on BTRFS not implemeted");
> > -                       return;
> > -               }
> >                 tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
> >         } else {
> >                 tst_resm(TPASS, "Succeeded to turn on swapfile");
> > @@ -84,13 +79,11 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > +       fs_type = tst_fs_type(cleanup, ".");
> > +       if (tst_fibmap()) {
> >
> 
> I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted
> on a filesystem.
> If that's true, shouldn't we verify FIBMAP ioctl on the swapfile?  Here you
> just test that in a tmp file, it probably not a correct way I guess.

We don't need to test on a swapfile. If the filesystem we are testing
supports FIBMAP iotcl, we can make a file in this filesystem a swapfile.

> 
> IMO, maybe we can define the function API as:
>     tst_fibmap(const char *filename);
> And calling it in behind of make_swapfile(cleanup, "swapfile01");
> 
> Beside that, there is another issue in this patch, since the
> getenv("TMPDIR"); depend on runltp script, so we cann't run the test
> independently.

Good catch. I guess we can check the string returned by getenv("TMPDIR"),
if it's null, set the test directory to "./".

Thanks,
M

> 
> # ./swapon01
> tst_ioctl.c:20: INFO: Testing if FIBMAP ioctl is supported in (null)
> tst_ioctl.c:27: WARN: open((null)/tst_fibmap, O_RDWR | O_CREAT, 0666)
> failed: ENOENT
> swapon01    1  TCONF  :  swapon01.c:86: Cannot do FIBMAP ioctl on a file on
> XFS filesystem
> swapon01    2  TCONF  :  swapon01.c:86: Remaining cases not appropriate for
> configuration
> 
> -- 
> Regards,
> Li Wang

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
  2019-05-08  3:43                     ` Murphy Zhou
@ 2019-05-08 10:22                       ` Amir Goldstein
  2019-05-08 14:38                         ` Murphy Zhou
  2019-05-10  4:42                         ` [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly " Murphy Zhou
  0 siblings, 2 replies; 55+ messages in thread
From: Amir Goldstein @ 2019-05-08 10:22 UTC (permalink / raw)
  To: ltp

On Wed, May 8, 2019 at 6:43 AM Murphy Zhou <xzhou@redhat.com> wrote:
>
> Hi,
>
> Thanks for reviewing!
>
> On Tue, May 07, 2019 at 04:52:01PM +0800, Li Wang wrote:
> > Hi Murphy,
> >
> > On Wed, May 1, 2019 at 7:59 AM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > > That means swapfile in the test filesystem is not supported.
> > > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist
> > > code.
> > >
> > > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > ---
> > > v2:
> > >    Test FIBMAP instead of fstype whitelist.
> > > v3:
> > >    Fix fs_type undeclared in swapoff01.c.
> > >
> > >  include/tst_fs.h                              |  5 +++
> > >  lib/tst_ioctl.c                               | 41 +++++++++++++++++++
> > >  testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++----
> > >  testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++--
> > >  testcases/kernel/syscalls/swapon/swapon01.c   | 13 ++----
> > >  testcases/kernel/syscalls/swapon/swapon02.c   | 16 ++------
> > >  testcases/kernel/syscalls/swapon/swapon03.c   | 20 ++-------
> > >  7 files changed, 65 insertions(+), 54 deletions(-)
> > >  create mode 100644 lib/tst_ioctl.c
> > >
> > > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > > index b2b19ada6..cc38b3547 100644
> > > --- a/include/tst_fs.h
> > > +++ b/include/tst_fs.h
> > > @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
> > >   */
> > >  void tst_fill_fs(const char *path, int verbose);
> > >
> > > +/*
> > > + * test if FIBMAP ioctl is supported
> > > + */
> > > +int tst_fibmap(void);
> > > +
> > >  #ifdef TST_TEST_H__
> > >  static inline long tst_fs_type(const char *path)
> > >  {
> > > diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> > > new file mode 100644
> > > index 000000000..d468d5898
> > > --- /dev/null
> > > +++ b/lib/tst_ioctl.c
> > > @@ -0,0 +1,41 @@
> > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > +
> > > +#include <errno.h>
> > > +#include <stdio.h>
> > > +#include <stdlib.h>
> > > +#include <sys/ioctl.h>
> > > +#include <linux/fs.h>
> > > +
> > > +#define TST_NO_DEFAULT_MAIN
> > > +
> > > +#include "tst_test.h"
> > > +
> > > +int tst_fibmap(void)
> > > +{
> > > +       /* test if FIBMAP ioctl is supported */
> > > +       int fd, block = 0;
> > > +       const char *tmpdir = getenv("TMPDIR");
> > > +       char buf[128];
> > > +
> > > +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",
> > > tmpdir);
> > > +
> > > +       sprintf(buf, "%s/tst_fibmap", tmpdir);
> > > +
> > > +       fd = open(buf, O_RDWR | O_CREAT, 0666);
> > > +       if (fd < 0) {
> > > +               tst_res(TWARN | TERRNO,
> > > +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", buf);
> > > +               return 1;
> > > +       }
> > > +
> > > +       if (ioctl(fd, FIBMAP, &block)) {
> > > +               close(fd);
> > > +               return 1;
> > > +       }
> > > +
> > > +       if (close(fd)) {
> > > +               tst_res(TWARN | TERRNO, "close(fd) failed");
> > > +               return 1;
> > > +       }
> > > +       return 0;
> > > +}
> > > diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > index a63e661a5..a37cd9be1 100644
> > > --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > @@ -55,11 +55,6 @@ int main(int ac, char **av)
> > >  static void verify_swapoff(void)
> > >  {
> > >         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> > > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > > -                       tst_brkm(TCONF, cleanup,
> > > -                                "Swapfiles on BTRFS are not implemented");
> > > -               }
> > > -
> > >                 tst_resm(TBROK, "Failed to turn on the swap file"
> > >                          ", skipping test iteration");
> > >                 return;
> > > @@ -86,13 +81,11 @@ static void setup(void)
> > >
> > >         tst_tmpdir();
> > >
> > > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > > -       case TST_NFS_MAGIC:
> > > -       case TST_TMPFS_MAGIC:
> > > +       fs_type = tst_fs_type(cleanup, ".");
> > > +       if (tst_fibmap()) {
> > >                 tst_brkm(TCONF, cleanup,
> > > -                        "Cannot do swapoff on a file on %s filesystem",
> > > +                        "Cannot do FIBMAP ioctl on a file on %s
> > > filesystem",
> > >                          tst_fs_type_name(fs_type));
> > > -       break;
> > >         }
> > >
> > >         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> > > diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > index b5c6312a1..889f3c800 100644
> > > --- a/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > +++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > @@ -43,6 +43,7 @@ char *TCID = "swapoff02";
> > >  int TST_TOTAL = 3;
> > >
> > >  static uid_t nobody_uid;
> > > +static long fs_type;
> > >
> > >  static struct test_case_t {
> > >         char *err_desc;
> > > @@ -138,13 +139,11 @@ static void setup(void)
> > >
> > >         tst_tmpdir();
> > >
> > > -       switch ((type = tst_fs_type(cleanup, "."))) {
> > > -       case TST_NFS_MAGIC:
> > > -       case TST_TMPFS_MAGIC:
> > > +       fs_type = tst_fs_type(cleanup, ".");
> > > +       if (tst_fibmap()) {
> > >                 tst_brkm(TCONF, cleanup,
> > > -                        "Cannot do swapoff on a file on %s filesystem",
> > > -                        tst_fs_type_name(type));
> > > -       break;
> > > +                        "Cannot do FIBMAP ioctl on a file on %s
> > > filesystem",
> > > +                        tst_fs_type_name(fs_type));
> > >         }
> > >
> > >         if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
> > > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> > > b/testcases/kernel/syscalls/swapon/swapon01.c
> > > index 32538f82b..0a5a3de86 100644
> > > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > > @@ -39,11 +39,6 @@ static void verify_swapon(void)
> > >         TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
> > >
> > >         if (TEST_RETURN == -1) {
> > > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > > -                       tst_brkm(TCONF, cleanup,
> > > -                                "Swapfile on BTRFS not implemeted");
> > > -                       return;
> > > -               }
> > >                 tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
> > >         } else {
> > >                 tst_resm(TPASS, "Succeeded to turn on swapfile");
> > > @@ -84,13 +79,11 @@ static void setup(void)
> > >
> > >         tst_tmpdir();
> > >
> > > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > > -       case TST_NFS_MAGIC:
> > > -       case TST_TMPFS_MAGIC:
> > > +       fs_type = tst_fs_type(cleanup, ".");
> > > +       if (tst_fibmap()) {
> > >
> >
> > I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted
> > on a filesystem.

Li is correct here. BTRFS and NFS on recent kernel support swapfile but not
support FIBMAP ioctl, so if you want to add test coverage for NFS and
BTRFS, I'm afraid they would have to be whitelisted after all, but not
is setup()
because depending on kernel, they may support swapfile and may not.
Worse even, BTRFS had FIBMAP support for a while and then removed, see:
ed46ff3d4237 Btrfs: support swap files
35054394c4b3 Btrfs: stop providing a bmap operation to avoid swapfile
corruptions

Sorry I missed this before.

> > If that's true, shouldn't we verify FIBMAP ioctl on the swapfile?  Here you
> > just test that in a tmp file, it probably not a correct way I guess.
>
> We don't need to test on a swapfile. If the filesystem we are testing
> supports FIBMAP iotcl, we can make a file in this filesystem a swapfile.
>

In theory, FIBMAP can work on certain files and fail on certain files
(e.g. reflinked xfs/ocfs2 file), but that is unlikely the case in this test
and not related to file being a swap file.

In conclusion
1. If filesystem supports FIBMAP its a very strong indication that
    filesystem supports swapfile, but in theory a future  filesystem
    could fail this test (don't see a reason for that to happen).
2. If filesystem does not support FIBMAP it can support swapfile
    btrfs and nfs are examples in current upstream, but in future could
    be other filesystems as well

Suggestion: test in setup FIBMAP. If not supported don't fail immediately
but do the try and fail softly with TCONF that is currently implemented
for TST_BTRFS_MAGIC.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v3] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
  2019-05-08 10:22                       ` Amir Goldstein
@ 2019-05-08 14:38                         ` Murphy Zhou
  2019-05-10  4:42                         ` [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly " Murphy Zhou
  1 sibling, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-08 14:38 UTC (permalink / raw)
  To: ltp

Hi,

On Wed, May 08, 2019 at 01:22:15PM +0300, Amir Goldstein wrote:
> On Wed, May 8, 2019 at 6:43 AM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > Hi,
> >
> > Thanks for reviewing!
> >
> > On Tue, May 07, 2019 at 04:52:01PM +0800, Li Wang wrote:
> > > Hi Murphy,
> > >
> > > On Wed, May 1, 2019 at 7:59 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > >
> > > > That means swapfile in the test filesystem is not supported.
> > > > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist
> > > > code.
> > > >
> > > > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > > ---
> > > > v2:
> > > >    Test FIBMAP instead of fstype whitelist.
> > > > v3:
> > > >    Fix fs_type undeclared in swapoff01.c.
> > > >
> > > >  include/tst_fs.h                              |  5 +++
> > > >  lib/tst_ioctl.c                               | 41 +++++++++++++++++++
> > > >  testcases/kernel/syscalls/swapoff/swapoff01.c | 13 ++----
> > > >  testcases/kernel/syscalls/swapoff/swapoff02.c | 11 +++--
> > > >  testcases/kernel/syscalls/swapon/swapon01.c   | 13 ++----
> > > >  testcases/kernel/syscalls/swapon/swapon02.c   | 16 ++------
> > > >  testcases/kernel/syscalls/swapon/swapon03.c   | 20 ++-------
> > > >  7 files changed, 65 insertions(+), 54 deletions(-)
> > > >  create mode 100644 lib/tst_ioctl.c
> > > >
> > > > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > > > index b2b19ada6..cc38b3547 100644
> > > > --- a/include/tst_fs.h
> > > > +++ b/include/tst_fs.h
> > > > @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
> > > >   */
> > > >  void tst_fill_fs(const char *path, int verbose);
> > > >
> > > > +/*
> > > > + * test if FIBMAP ioctl is supported
> > > > + */
> > > > +int tst_fibmap(void);
> > > > +
> > > >  #ifdef TST_TEST_H__
> > > >  static inline long tst_fs_type(const char *path)
> > > >  {
> > > > diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> > > > new file mode 100644
> > > > index 000000000..d468d5898
> > > > --- /dev/null
> > > > +++ b/lib/tst_ioctl.c
> > > > @@ -0,0 +1,41 @@
> > > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > > +
> > > > +#include <errno.h>
> > > > +#include <stdio.h>
> > > > +#include <stdlib.h>
> > > > +#include <sys/ioctl.h>
> > > > +#include <linux/fs.h>
> > > > +
> > > > +#define TST_NO_DEFAULT_MAIN
> > > > +
> > > > +#include "tst_test.h"
> > > > +
> > > > +int tst_fibmap(void)
> > > > +{
> > > > +       /* test if FIBMAP ioctl is supported */
> > > > +       int fd, block = 0;
> > > > +       const char *tmpdir = getenv("TMPDIR");
> > > > +       char buf[128];
> > > > +
> > > > +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported in %s",
> > > > tmpdir);
> > > > +
> > > > +       sprintf(buf, "%s/tst_fibmap", tmpdir);
> > > > +
> > > > +       fd = open(buf, O_RDWR | O_CREAT, 0666);
> > > > +       if (fd < 0) {
> > > > +               tst_res(TWARN | TERRNO,
> > > > +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", buf);
> > > > +               return 1;
> > > > +       }
> > > > +
> > > > +       if (ioctl(fd, FIBMAP, &block)) {
> > > > +               close(fd);
> > > > +               return 1;
> > > > +       }
> > > > +
> > > > +       if (close(fd)) {
> > > > +               tst_res(TWARN | TERRNO, "close(fd) failed");
> > > > +               return 1;
> > > > +       }
> > > > +       return 0;
> > > > +}
> > > > diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > > b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > > index a63e661a5..a37cd9be1 100644
> > > > --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > > +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > > @@ -55,11 +55,6 @@ int main(int ac, char **av)
> > > >  static void verify_swapoff(void)
> > > >  {
> > > >         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> > > > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > > > -                       tst_brkm(TCONF, cleanup,
> > > > -                                "Swapfiles on BTRFS are not implemented");
> > > > -               }
> > > > -
> > > >                 tst_resm(TBROK, "Failed to turn on the swap file"
> > > >                          ", skipping test iteration");
> > > >                 return;
> > > > @@ -86,13 +81,11 @@ static void setup(void)
> > > >
> > > >         tst_tmpdir();
> > > >
> > > > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > > > -       case TST_NFS_MAGIC:
> > > > -       case TST_TMPFS_MAGIC:
> > > > +       fs_type = tst_fs_type(cleanup, ".");
> > > > +       if (tst_fibmap()) {
> > > >                 tst_brkm(TCONF, cleanup,
> > > > -                        "Cannot do swapoff on a file on %s filesystem",
> > > > +                        "Cannot do FIBMAP ioctl on a file on %s
> > > > filesystem",
> > > >                          tst_fs_type_name(fs_type));
> > > > -       break;
> > > >         }
> > > >
> > > >         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> > > > diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > > b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > > index b5c6312a1..889f3c800 100644
> > > > --- a/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > > +++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > > > @@ -43,6 +43,7 @@ char *TCID = "swapoff02";
> > > >  int TST_TOTAL = 3;
> > > >
> > > >  static uid_t nobody_uid;
> > > > +static long fs_type;
> > > >
> > > >  static struct test_case_t {
> > > >         char *err_desc;
> > > > @@ -138,13 +139,11 @@ static void setup(void)
> > > >
> > > >         tst_tmpdir();
> > > >
> > > > -       switch ((type = tst_fs_type(cleanup, "."))) {
> > > > -       case TST_NFS_MAGIC:
> > > > -       case TST_TMPFS_MAGIC:
> > > > +       fs_type = tst_fs_type(cleanup, ".");
> > > > +       if (tst_fibmap()) {
> > > >                 tst_brkm(TCONF, cleanup,
> > > > -                        "Cannot do swapoff on a file on %s filesystem",
> > > > -                        tst_fs_type_name(type));
> > > > -       break;
> > > > +                        "Cannot do FIBMAP ioctl on a file on %s
> > > > filesystem",
> > > > +                        tst_fs_type_name(fs_type));
> > > >         }
> > > >
> > > >         if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
> > > > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c
> > > > b/testcases/kernel/syscalls/swapon/swapon01.c
> > > > index 32538f82b..0a5a3de86 100644
> > > > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > > > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > > > @@ -39,11 +39,6 @@ static void verify_swapon(void)
> > > >         TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
> > > >
> > > >         if (TEST_RETURN == -1) {
> > > > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > > > -                       tst_brkm(TCONF, cleanup,
> > > > -                                "Swapfile on BTRFS not implemeted");
> > > > -                       return;
> > > > -               }
> > > >                 tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
> > > >         } else {
> > > >                 tst_resm(TPASS, "Succeeded to turn on swapfile");
> > > > @@ -84,13 +79,11 @@ static void setup(void)
> > > >
> > > >         tst_tmpdir();
> > > >
> > > > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > > > -       case TST_NFS_MAGIC:
> > > > -       case TST_TMPFS_MAGIC:
> > > > +       fs_type = tst_fs_type(cleanup, ".");
> > > > +       if (tst_fibmap()) {
> > > >
> > >
> > > I'm not sure whether FIBMAP ioctl FAIL means that swapfile is unsupportted
> > > on a filesystem.
> 
> Li is correct here. BTRFS and NFS on recent kernel support swapfile but not
> support FIBMAP ioctl, so if you want to add test coverage for NFS and
> BTRFS, I'm afraid they would have to be whitelisted after all, but not
> is setup()
> because depending on kernel, they may support swapfile and may not.
> Worse even, BTRFS had FIBMAP support for a while and then removed, see:
> ed46ff3d4237 Btrfs: support swap files
> 35054394c4b3 Btrfs: stop providing a bmap operation to avoid swapfile
> corruptions

Great to know! Thanks for pointing that out. Much learned. :)

> 
> Sorry I missed this before.

It's my bad not checking carefully.
> 
> > > If that's true, shouldn't we verify FIBMAP ioctl on the swapfile?  Here you
> > > just test that in a tmp file, it probably not a correct way I guess.
> >
> > We don't need to test on a swapfile. If the filesystem we are testing
> > supports FIBMAP iotcl, we can make a file in this filesystem a swapfile.
> >
> 
> In theory, FIBMAP can work on certain files and fail on certain files
> (e.g. reflinked xfs/ocfs2 file), but that is unlikely the case in this test
> and not related to file being a swap file.

Agreed. Sounds like a corner case in these corner swap rests to me :)
> 
> In conclusion
> 1. If filesystem supports FIBMAP its a very strong indication that
>     filesystem supports swapfile, but in theory a future  filesystem
>     could fail this test (don't see a reason for that to happen).

I mainly thought about ths situation. We can let the following swap* test
go to see what's happening.

> 2. If filesystem does not support FIBMAP it can support swapfile
>     btrfs and nfs are examples in current upstream, but in future could
>     be other filesystems as well
> 
> Suggestion: test in setup FIBMAP. If not supported don't fail immediately
> but do the try and fail softly with TCONF that is currently implemented
> for TST_BTRFS_MAGIC.

Reasonable to me. Thanks for the suggestion. We can go wo/ whitelist.

Thanks,
M
> 
> Thanks,
> Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-08 10:22                       ` Amir Goldstein
  2019-05-08 14:38                         ` Murphy Zhou
@ 2019-05-10  4:42                         ` Murphy Zhou
  2019-05-10  5:27                           ` Amir Goldstein
  1 sibling, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-05-10  4:42 UTC (permalink / raw)
  To: ltp

Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
Leave swapoff02 alone because it's permission checking only in it.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
v2:
  Test FIBMAP instead of fstype whitelist.
v3:
  Fix fs_type undeclared in swapoff01.c.
v4:
  Fail softly if FIBMAP nit supported, instead of skip entire testcase.

 include/tst_fs.h                              |  5 ++
 lib/tst_ioctl.c                               | 39 ++++++++++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++-------
 testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ----
 testcases/kernel/syscalls/swapon/swapon01.c   | 23 ++++----
 testcases/kernel/syscalls/swapon/swapon02.c   | 31 ++++++-----
 testcases/kernel/syscalls/swapon/swapon03.c   | 52 +++++++++----------
 7 files changed, 121 insertions(+), 85 deletions(-)
 create mode 100644 lib/tst_ioctl.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index b2b19ada6..423ca82ec 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
  */
 void tst_fill_fs(const char *path, int verbose);
 
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(const char *filename, const char *fstype);
+
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
 {
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
new file mode 100644
index 000000000..f63eb5565
--- /dev/null
+++ b/lib/tst_ioctl.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(const char *filename, const char *fstype)
+{
+	/* test if FIBMAP ioctl is supported */
+	int fd, block = 0;
+
+	tst_res(TINFO, "Testing if FIBMAP ioctl is supported on %s", fstype);
+
+	fd = open(filename, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		tst_res(TWARN | TERRNO,
+			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
+		return 1;
+	}
+
+	if (ioctl(fd, FIBMAP, &block)) {
+		tst_res(TINFO, "FIBMAP ioctl is NOT supported");
+		close(fd);
+		return 1;
+	}
+	tst_res(TINFO, "FIBMAP ioctl is supported");
+
+	if (close(fd)) {
+		tst_res(TWARN | TERRNO, "close(fd) failed");
+		return 1;
+	}
+	return 0;
+}
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index a63e661a5..fbce66fc8 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -32,6 +32,7 @@ static void verify_swapoff(void);
 
 char *TCID = "swapoff01";
 int TST_TOTAL = 1;
+int fibmap = 1;
 
 static long fs_type;
 
@@ -55,22 +56,26 @@ int main(int ac, char **av)
 static void verify_swapoff(void)
 {
 	if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
-		if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-			tst_brkm(TCONF, cleanup,
-			         "Swapfiles on BTRFS are not implemented");
+		if (fibmap == 1) {
+			tst_resm(TBROK, "Failed to turn on the swap file"
+				 ", skipping test iteration");
+			return;
+		} else {
+			tst_resm(TCONF, "Failed to turn on the swap file"
+				 ", keep going for sanity check");
 		}
-
-		tst_resm(TBROK, "Failed to turn on the swap file"
-			 ", skipping test iteration");
-		return;
 	}
 
 	TEST(ltp_syscall(__NR_swapoff, "./swapfile01"));
 
 	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
-		         " system reboot after execution of LTP "
-			 "test suite is recommended.");
+		if (fibmap == 1) {
+			tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
+				 " system reboot after execution of LTP "
+				 "test suite is recommended.");
+		} else {
+			tst_resm(TCONF, "Failed to turn off swapfile");
+		}
 	} else {
 		tst_resm(TPASS, "Succeeded to turn off swapfile");
 	}
@@ -86,13 +91,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
+		tst_resm(TCONF,
+			 "Will not report FAIL as FIBMAP ioctl not supported");
+		fibmap = 0;
 	}
 
 	if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
@@ -103,8 +106,13 @@ static void setup(void)
 	if (tst_fill_file("swapfile01", 0x00, 1024, 65536))
 		tst_brkm(TBROK, cleanup, "Failed to create file for swap");
 
-	if (system("mkswap swapfile01 > tmpfile 2>&1") != 0)
-		tst_brkm(TBROK, cleanup, "Failed to make swapfile");
+	if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) {
+		if (fibmap == 1) {
+			tst_brkm(TBROK, cleanup, "Failed to make swapfile");
+		} else {
+			tst_resm(TCONF, "Failed to make swapfile");
+		}
+	}
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index b5c6312a1..2267449eb 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -124,7 +124,6 @@ static void cleanup01(void)
 
 static void setup(void)
 {
-	long type;
 	struct passwd *nobody;
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -138,15 +137,6 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(type));
-	break;
-	}
-
 	if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
 		tst_brkm(TBROK, cleanup,
 			 "Insufficient disk space to create swap file");
diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index 32538f82b..0419cae28 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -31,6 +31,7 @@ static void cleanup(void);
 
 char *TCID = "swapon01";
 int TST_TOTAL = 1;
+int fibmap = 1;
 
 static long fs_type;
 
@@ -39,12 +40,11 @@ static void verify_swapon(void)
 	TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
 
 	if (TEST_RETURN == -1) {
-		if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-			tst_brkm(TCONF, cleanup,
-			         "Swapfile on BTRFS not implemeted");
-			return;
+		if (fibmap == 0) {
+			tst_resm(TCONF, "Failed to turn on swapfile");
+		} else {
+			tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
 		}
-		tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
 	} else {
 		tst_resm(TPASS, "Succeeded to turn on swapfile");
 		/*we need to turn this swap file off for -i option */
@@ -58,7 +58,6 @@ static void verify_swapon(void)
 
 int main(int ac, char **av)
 {
-
 	int lc;
 
 	tst_parse_opts(ac, av, NULL, NULL);
@@ -84,13 +83,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
+		tst_resm(TCONF,
+			 "Will not report FAIL as FIBMAP ioctl not supported");
+		fibmap = 0;
 	}
 
 	make_swapfile(cleanup, "swapfile01");
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..8120be987 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -44,6 +44,7 @@ static void cleanup01(void);
 
 char *TCID = "swapon02";
 int TST_TOTAL = 4;
+int fibmap = 1;
 
 static uid_t nobody_uid;
 static int do_swapoff;
@@ -81,14 +82,15 @@ static void verify_swapon(struct test_case_t *test)
 		return;
 	}
 
-	if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
-		tst_resm(TCONF, "Swapfile on BTRFS not implemeted");
-			return;
+	if (fibmap == 1) {
+		tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
+			 " %d, errno: %s and got %d.", test->exp_errno,
+			 test->exp_errval, TEST_ERRNO);
+	} else {
+		tst_resm(TCONF, "swapon(2) failed to produce expected error:"
+			 " %d, errno: %s and got %d.", test->exp_errno,
+			 test->exp_errval, TEST_ERRNO);
 	}
-
-	tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
-	         " %d, errno: %s and got %d.", test->exp_errno,
-	         test->exp_errval, TEST_ERRNO);
 }
 
 int main(int ac, char **av)
@@ -132,13 +134,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
+		tst_resm(TCONF,
+			 "Will not report FAIL as FIBMAP ioctl not supported");
+		fibmap = 0;
 	}
 
 	SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
@@ -146,8 +146,7 @@ static void setup(void)
 	make_swapfile(cleanup, "alreadyused");
 
 	if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
-		if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
-			tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
+		tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
 	} else {
 		do_swapoff = 1;
 	}
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 955ac247b..696d0a3dd 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -49,6 +49,7 @@ static int check_and_swapoff(const char *filename);
 
 char *TCID = "swapon03";
 int TST_TOTAL = 1;
+int fibmap = 1;
 
 static int swapfiles;
 
@@ -65,6 +66,14 @@ static struct swap_testfile_t {
 
 int expected_errno = EPERM;
 
+void record_failure_soft(int flag, char *s, int exp, char *err)
+{
+	if (fibmap != 1)
+		flag = TCONF;
+
+	tst_resm(flag, s, exp, err);
+}
+
 int main(int ac, char **av)
 {
 	int lc;
@@ -88,10 +97,10 @@ int main(int ac, char **av)
 			tst_resm(TPASS, "swapon(2) got expected failure (%d),",
 				 expected_errno);
 		} else if (TEST_RETURN < 0) {
-			tst_resm(TFAIL | TTERRNO,
+			record_failure_soft(TFAIL | TTERRNO,
 				 "swapon(2) failed to produce expected error "
-				 "(%d). System reboot recommended.",
-				 expected_errno);
+				 "(%d), got (%s). System reboot recommended.",
+				 expected_errno, strerror(TEST_ERRNO));
 		} else {
 			/* Probably the system supports MAX_SWAPFILES > 30,
 			 * let's try with MAX_SWAPFILES == 32 */
@@ -103,8 +112,10 @@ int main(int ac, char **av)
 
 			/* Check return code (now we're expecting success) */
 			if (TEST_RETURN < 0) {
-				tst_resm(TFAIL | TTERRNO,
-					 "swapon(2) got an unexpected failure");
+				record_failure_soft(TFAIL | TTERRNO,
+					 "swapon(2) got an unexpected failure"
+					 "(%d: %s).",
+					 TEST_RETURN, strerror(TEST_ERRNO));
 			} else {
 				/* Call swapon sys call once again for 33
 				 * now we have to receive an error */
@@ -121,7 +132,7 @@ int main(int ac, char **av)
 						 " MAX_SWAPFILES is 32",
 						 expected_errno);
 				} else {
-					tst_resm(TFAIL,
+					record_failure_soft(TFAIL,
 						 "swapon(2) failed to produce"
 						 " expected error: %d, got %s."
 						 " System reboot after execution of LTP"
@@ -141,7 +152,6 @@ int main(int ac, char **av)
 
 	cleanup();
 	tst_exit();
-
 }
 
 /*
@@ -215,9 +225,6 @@ static int setup_swap(void)
 			/* turn on the swap file */
 			res = ltp_syscall(__NR_swapon, filename, 0);
 			if (res != 0) {
-				if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL)
-					exit(2);
-
 				if (errno == EPERM) {
 					printf("Successfully created %d "
 					       "swapfiles\n", j);
@@ -225,7 +232,8 @@ static int setup_swap(void)
 				} else {
 					printf("Failed to create "
 					       "swapfile: %s\n", filename);
-					exit(1);
+					if (fibmap == 1)
+						exit(1);
 				}
 			}
 		}
@@ -233,15 +241,8 @@ static int setup_swap(void)
 	} else
 		waitpid(pid, &status, 0);
 
-	switch (WEXITSTATUS(status)) {
-	case 0:
-	break;
-	case 2:
-		tst_brkm(TCONF, cleanup, "Swapfile on BTRFS not implemeted");
-	break;
-	default:
+	if (WEXITSTATUS(status)) {
 		tst_brkm(TFAIL, cleanup, "Failed to setup swaps");
-	break;
 	}
 
 	/* Create all needed extra swapfiles for testing */
@@ -249,7 +250,6 @@ static int setup_swap(void)
 		make_swapfile(cleanup, swap_testfiles[j].filename);
 
 	return 0;
-
 }
 
 /*
@@ -333,13 +333,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
+	fs_type = tst_fs_type(cleanup, ".");
+	if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
+		tst_resm(TCONF,
+			 "Will not report FAIL as FIBMAP ioctl not supported");
+		fibmap = 0;
 	}
 
 	TEST_PAUSE;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-10  4:42                         ` [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly " Murphy Zhou
@ 2019-05-10  5:27                           ` Amir Goldstein
  2019-05-10  8:15                             ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Amir Goldstein @ 2019-05-10  5:27 UTC (permalink / raw)
  To: ltp

On Fri, May 10, 2019 at 7:42 AM Murphy Zhou <xzhou@redhat.com> wrote:
>
> Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.

If you wouldn't have just done that it would have been good.
But your patch also changes a lot of the logic and output messages,
which is less good.
For BTRFS, with a kernel that does not support swapon/off, test logic
should have stayed the same and produce more or less the same output.
This would have made review much easier and less chance of breaking things.

> Leave swapoff02 alone because it's permission checking only in it.
>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> ---
> v2:
>   Test FIBMAP instead of fstype whitelist.
> v3:
>   Fix fs_type undeclared in swapoff01.c.
> v4:
>   Fail softly if FIBMAP nit supported, instead of skip entire testcase.
>
>  include/tst_fs.h                              |  5 ++
>  lib/tst_ioctl.c                               | 39 ++++++++++++++
>  testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++-------
>  testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ----
>  testcases/kernel/syscalls/swapon/swapon01.c   | 23 ++++----
>  testcases/kernel/syscalls/swapon/swapon02.c   | 31 ++++++-----
>  testcases/kernel/syscalls/swapon/swapon03.c   | 52 +++++++++----------
>  7 files changed, 121 insertions(+), 85 deletions(-)
>  create mode 100644 lib/tst_ioctl.c
>
> diff --git a/include/tst_fs.h b/include/tst_fs.h
> index b2b19ada6..423ca82ec 100644
> --- a/include/tst_fs.h
> +++ b/include/tst_fs.h
> @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
>   */
>  void tst_fill_fs(const char *path, int verbose);
>
> +/*
> + * test if FIBMAP ioctl is supported
> + */
> +int tst_fibmap(const char *filename, const char *fstype);
> +
>  #ifdef TST_TEST_H__
>  static inline long tst_fs_type(const char *path)
>  {
> diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> new file mode 100644
> index 000000000..f63eb5565
> --- /dev/null
> +++ b/lib/tst_ioctl.c
> @@ -0,0 +1,39 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +
> +#include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <linux/fs.h>
> +
> +#define TST_NO_DEFAULT_MAIN
> +
> +#include "tst_test.h"
> +
> +int tst_fibmap(const char *filename, const char *fstype)
> +{
> +       /* test if FIBMAP ioctl is supported */
> +       int fd, block = 0;
> +
> +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported on %s", fstype);

passing the fstype into this helper seems quite irrelevant to me.
the TINFO print doesn't justify it IMO
Its not even an important info IMO, so as long as you have the print
when FIBMAP not supported

> +
> +       fd = open(filename, O_RDWR | O_CREAT, 0666);
> +       if (fd < 0) {
> +               tst_res(TWARN | TERRNO,
> +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
> +               return 1;
> +       }
> +
> +       if (ioctl(fd, FIBMAP, &block)) {
> +               tst_res(TINFO, "FIBMAP ioctl is NOT supported");
> +               close(fd);
> +               return 1;
> +       }
> +       tst_res(TINFO, "FIBMAP ioctl is supported");
> +
> +       if (close(fd)) {
> +               tst_res(TWARN | TERRNO, "close(fd) failed");
> +               return 1;
> +       }
> +       return 0;
> +}
> diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
> index a63e661a5..fbce66fc8 100644
> --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> @@ -32,6 +32,7 @@ static void verify_swapoff(void);
>
>  char *TCID = "swapoff01";
>  int TST_TOTAL = 1;
> +int fibmap = 1;
>
>  static long fs_type;
>
> @@ -55,22 +56,26 @@ int main(int ac, char **av)
>  static void verify_swapoff(void)
>  {
>         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> -                       tst_brkm(TCONF, cleanup,
> -                                "Swapfiles on BTRFS are not implemented");
> +               if (fibmap == 1) {

This changes both logic and output message.
I don't see a good reason for you to do that.
Please keep the errno == EINVAL check and the message format for TCONF case
Same comment for all the other places it applies

> +                       tst_resm(TBROK, "Failed to turn on the swap file"
> +                                ", skipping test iteration");
> +                       return;
> +               } else {
> +                       tst_resm(TCONF, "Failed to turn on the swap file"
> +                                ", keep going for sanity check");
>                 }
> -
> -               tst_resm(TBROK, "Failed to turn on the swap file"
> -                        ", skipping test iteration");
> -               return;
>         }
>
>         TEST(ltp_syscall(__NR_swapoff, "./swapfile01"));
>
>         if (TEST_RETURN == -1) {
> -               tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> -                        " system reboot after execution of LTP "
> -                        "test suite is recommended.");
> +               if (fibmap == 1) {

No reason to do that.
If filesystem was already proven to support swpaon(), swapoff() must succeed.
If fs doesn't support swapon(), test should bail out and not try swapoff()

> +                       tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> +                                " system reboot after execution of LTP "
> +                                "test suite is recommended.");
> +               } else {
> +                       tst_resm(TCONF, "Failed to turn off swapfile");
> +               }
>         } else {
>                 tst_resm(TPASS, "Succeeded to turn off swapfile");
>         }
> @@ -86,13 +91,11 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> -               tst_brkm(TCONF, cleanup,
> -                        "Cannot do swapoff on a file on %s filesystem",
> -                        tst_fs_type_name(fs_type));
> -       break;
> +       fs_type = tst_fs_type(cleanup, ".");
> +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> +               tst_resm(TCONF,
> +                        "Will not report FAIL as FIBMAP ioctl not supported");

Here printing fs name would be useful IMO

> +               fibmap = 0;
>         }
>
>         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> @@ -103,8 +106,13 @@ static void setup(void)
>         if (tst_fill_file("swapfile01", 0x00, 1024, 65536))
>                 tst_brkm(TBROK, cleanup, "Failed to create file for swap");
>
> -       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0)
> -               tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> +       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) {
> +               if (fibmap == 1) {
> +                       tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> +               } else {
> +                       tst_resm(TCONF, "Failed to make swapfile");

You see, this message does not align with the outcome (skip).
Is this really needed? does mkswap fail on tmpfs?
If it does, then surely the entire test can be skipped

> +               }
> +       }
>  }
>
>  static void cleanup(void)
> diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
> index b5c6312a1..2267449eb 100644
> --- a/testcases/kernel/syscalls/swapoff/swapoff02.c
> +++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
> @@ -124,7 +124,6 @@ static void cleanup01(void)
>
>  static void setup(void)
>  {
> -       long type;
>         struct passwd *nobody;
>
>         tst_sig(FORK, DEF_HANDLER, cleanup);
> @@ -138,15 +137,6 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> -               tst_brkm(TCONF, cleanup,
> -                        "Cannot do swapoff on a file on %s filesystem",
> -                        tst_fs_type_name(type));
> -       break;
> -       }
> -
>         if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
>                 tst_brkm(TBROK, cleanup,
>                          "Insufficient disk space to create swap file");
> diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
> index 32538f82b..0419cae28 100644
> --- a/testcases/kernel/syscalls/swapon/swapon01.c
> +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> @@ -31,6 +31,7 @@ static void cleanup(void);
>
>  char *TCID = "swapon01";
>  int TST_TOTAL = 1;
> +int fibmap = 1;
>
>  static long fs_type;
>
> @@ -39,12 +40,11 @@ static void verify_swapon(void)
>         TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
>
>         if (TEST_RETURN == -1) {
> -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> -                       tst_brkm(TCONF, cleanup,
> -                                "Swapfile on BTRFS not implemeted");
> -                       return;
> +               if (fibmap == 0) {
> +                       tst_resm(TCONF, "Failed to turn on swapfile");

Please take care to not change logic.
You replcaed tst_brkm with tst_resm. Intentional?
You also change the meaning of the warning message to the worse IMO

> +               } else {
> +                       tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
>                 }
> -               tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
>         } else {
>                 tst_resm(TPASS, "Succeeded to turn on swapfile");
>                 /*we need to turn this swap file off for -i option */
> @@ -58,7 +58,6 @@ static void verify_swapon(void)
>
>  int main(int ac, char **av)
>  {
> -
>         int lc;
>
>         tst_parse_opts(ac, av, NULL, NULL);
> @@ -84,13 +83,11 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> -               tst_brkm(TCONF, cleanup,
> -                        "Cannot do swapon on a file on %s filesystem",
> -                        tst_fs_type_name(fs_type));
> -       break;
> +       fs_type = tst_fs_type(cleanup, ".");
> +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> +               tst_resm(TCONF,
> +                        "Will not report FAIL as FIBMAP ioctl not supported");
> +               fibmap = 0;
>         }
>
>         make_swapfile(cleanup, "swapfile01");
> diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
> index 4af5105c6..8120be987 100644
> --- a/testcases/kernel/syscalls/swapon/swapon02.c
> +++ b/testcases/kernel/syscalls/swapon/swapon02.c
> @@ -44,6 +44,7 @@ static void cleanup01(void);
>
>  char *TCID = "swapon02";
>  int TST_TOTAL = 4;
> +int fibmap = 1;
>
>  static uid_t nobody_uid;
>  static int do_swapoff;
> @@ -81,14 +82,15 @@ static void verify_swapon(struct test_case_t *test)
>                 return;
>         }
>
> -       if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> -               tst_resm(TCONF, "Swapfile on BTRFS not implemeted");
> -                       return;
> +       if (fibmap == 1) {
> +               tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
> +                        " %d, errno: %s and got %d.", test->exp_errno,
> +                        test->exp_errval, TEST_ERRNO);

Changes message

> +       } else {
> +               tst_resm(TCONF, "swapon(2) failed to produce expected error:"
> +                        " %d, errno: %s and got %d.", test->exp_errno,
> +                        test->exp_errval, TEST_ERRNO);
>         }
> -
> -       tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
> -                " %d, errno: %s and got %d.", test->exp_errno,
> -                test->exp_errval, TEST_ERRNO);
>  }
>
>  int main(int ac, char **av)
> @@ -132,13 +134,11 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> -               tst_brkm(TCONF, cleanup,
> -                        "Cannot do swapon on a file on %s filesystem",
> -                        tst_fs_type_name(fs_type));
> -       break;
> +       fs_type = tst_fs_type(cleanup, ".");
> +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> +               tst_resm(TCONF,
> +                        "Will not report FAIL as FIBMAP ioctl not supported");
> +               fibmap = 0;
>         }
>
>         SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
> @@ -146,8 +146,7 @@ static void setup(void)
>         make_swapfile(cleanup, "alreadyused");
>
>         if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
> -               if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
> -                       tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
> +               tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");

Change of logic for fibmap == 0 case

>         } else {
>                 do_swapoff = 1;
>         }
> diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
> index 955ac247b..696d0a3dd 100644
> --- a/testcases/kernel/syscalls/swapon/swapon03.c
> +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> @@ -49,6 +49,7 @@ static int check_and_swapoff(const char *filename);
>
>  char *TCID = "swapon03";
>  int TST_TOTAL = 1;
> +int fibmap = 1;
>
>  static int swapfiles;
>
> @@ -65,6 +66,14 @@ static struct swap_testfile_t {
>
>  int expected_errno = EPERM;
>
> +void record_failure_soft(int flag, char *s, int exp, char *err)
> +{
> +       if (fibmap != 1)
> +               flag = TCONF;
> +
> +       tst_resm(flag, s, exp, err);
> +}
> +
>  int main(int ac, char **av)
>  {
>         int lc;
> @@ -88,10 +97,10 @@ int main(int ac, char **av)
>                         tst_resm(TPASS, "swapon(2) got expected failure (%d),",
>                                  expected_errno);
>                 } else if (TEST_RETURN < 0) {
> -                       tst_resm(TFAIL | TTERRNO,
> +                       record_failure_soft(TFAIL | TTERRNO,
>                                  "swapon(2) failed to produce expected error "
> -                                "(%d). System reboot recommended.",
> -                                expected_errno);
> +                                "(%d), got (%s). System reboot recommended.",
> +                                expected_errno, strerror(TEST_ERRNO));
>                 } else {
>                         /* Probably the system supports MAX_SWAPFILES > 30,
>                          * let's try with MAX_SWAPFILES == 32 */
> @@ -103,8 +112,10 @@ int main(int ac, char **av)
>
>                         /* Check return code (now we're expecting success) */
>                         if (TEST_RETURN < 0) {
> -                               tst_resm(TFAIL | TTERRNO,
> -                                        "swapon(2) got an unexpected failure");
> +                               record_failure_soft(TFAIL | TTERRNO,
> +                                        "swapon(2) got an unexpected failure"
> +                                        "(%d: %s).",
> +                                        TEST_RETURN, strerror(TEST_ERRNO));
>                         } else {
>                                 /* Call swapon sys call once again for 33
>                                  * now we have to receive an error */
> @@ -121,7 +132,7 @@ int main(int ac, char **av)
>                                                  " MAX_SWAPFILES is 32",
>                                                  expected_errno);
>                                 } else {
> -                                       tst_resm(TFAIL,
> +                                       record_failure_soft(TFAIL,
>                                                  "swapon(2) failed to produce"
>                                                  " expected error: %d, got %s."
>                                                  " System reboot after execution of LTP"
> @@ -141,7 +152,6 @@ int main(int ac, char **av)
>
>         cleanup();
>         tst_exit();
> -
>  }
>
>  /*
> @@ -215,9 +225,6 @@ static int setup_swap(void)
>                         /* turn on the swap file */
>                         res = ltp_syscall(__NR_swapon, filename, 0);
>                         if (res != 0) {
> -                               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL)
> -                                       exit(2);
> -
>                                 if (errno == EPERM) {
>                                         printf("Successfully created %d "
>                                                "swapfiles\n", j);
> @@ -225,7 +232,8 @@ static int setup_swap(void)
>                                 } else {
>                                         printf("Failed to create "
>                                                "swapfile: %s\n", filename);
> -                                       exit(1);
> +                                       if (fibmap == 1)
> +                                               exit(1);
>                                 }
>                         }
>                 }
> @@ -233,15 +241,8 @@ static int setup_swap(void)
>         } else
>                 waitpid(pid, &status, 0);
>
> -       switch (WEXITSTATUS(status)) {
> -       case 0:
> -       break;
> -       case 2:
> -               tst_brkm(TCONF, cleanup, "Swapfile on BTRFS not implemeted");
> -       break;
> -       default:
> +       if (WEXITSTATUS(status)) {
>                 tst_brkm(TFAIL, cleanup, "Failed to setup swaps");
> -       break;
>         }
>
>         /* Create all needed extra swapfiles for testing */
> @@ -249,7 +250,6 @@ static int setup_swap(void)
>                 make_swapfile(cleanup, swap_testfiles[j].filename);
>
>         return 0;
> -
>  }
>
>  /*
> @@ -333,13 +333,11 @@ static void setup(void)
>
>         tst_tmpdir();
>
> -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> -       case TST_NFS_MAGIC:
> -       case TST_TMPFS_MAGIC:
> -               tst_brkm(TCONF, cleanup,
> -                        "Cannot do swapon on a file on %s filesystem",
> -                        tst_fs_type_name(fs_type));
> -       break;
> +       fs_type = tst_fs_type(cleanup, ".");
> +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> +               tst_resm(TCONF,
> +                        "Will not report FAIL as FIBMAP ioctl not supported");
> +               fibmap = 0;
>         }
>
>         TEST_PAUSE;
> --
> 2.21.0
>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-10  5:27                           ` Amir Goldstein
@ 2019-05-10  8:15                             ` Murphy Zhou
  2019-05-10  8:48                               ` Amir Goldstein
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-05-10  8:15 UTC (permalink / raw)
  To: ltp

On Fri, May 10, 2019 at 08:27:35AM +0300, Amir Goldstein wrote:
> On Fri, May 10, 2019 at 7:42 AM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
> 
> If you wouldn't have just done that it would have been good.
> But your patch also changes a lot of the logic and output messages,
> which is less good.

First of all, don't be mad if you think I'm changing too much. :)
I should have written more info here in commit message like in the changelog.

If FIBMAP trial fails, don't bail out immediately, go on to the rest
of tests. Than don't report fail if swap* syscall fails, just record
the failure info, acting like a sanity check test.

If FIBMAP trial pass, follow the original logic.

The whitelist code removal is kinda independent. But combining with the
fibmap code it looks like a lot of logic changing.

> For BTRFS, with a kernel that does not support swapon/off, test logic
> should have stayed the same and produce more or less the same output.
> This would have made review much easier and less chance of breaking things.

I can understand the test logic part, but why the same output matters?
Since we are not using golden output like fstests :)

Back to the logic, checking specific return value is precise, but it i
 hard to maintain them IMO. If kernel logic changes, it's easy to forget
updating testing logic. That's why I am fan of your whitelist avoiding
idea. Now if I understand correctly, you want to keep the filesystems
whitelist, fibmap test is just for the info. Am I right?

For better communication, I'd like to remove whitelist code. Can we have
an alter opinion here?

> 
> > Leave swapoff02 alone because it's permission checking only in it.
> >
> > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > ---
> > v2:
> >   Test FIBMAP instead of fstype whitelist.
> > v3:
> >   Fix fs_type undeclared in swapoff01.c.
> > v4:
> >   Fail softly if FIBMAP nit supported, instead of skip entire testcase.
> >
> >  include/tst_fs.h                              |  5 ++
> >  lib/tst_ioctl.c                               | 39 ++++++++++++++
> >  testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++-------
> >  testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ----
> >  testcases/kernel/syscalls/swapon/swapon01.c   | 23 ++++----
> >  testcases/kernel/syscalls/swapon/swapon02.c   | 31 ++++++-----
> >  testcases/kernel/syscalls/swapon/swapon03.c   | 52 +++++++++----------
> >  7 files changed, 121 insertions(+), 85 deletions(-)
> >  create mode 100644 lib/tst_ioctl.c
> >
> > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > index b2b19ada6..423ca82ec 100644
> > --- a/include/tst_fs.h
> > +++ b/include/tst_fs.h
> > @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
> >   */
> >  void tst_fill_fs(const char *path, int verbose);
> >
> > +/*
> > + * test if FIBMAP ioctl is supported
> > + */
> > +int tst_fibmap(const char *filename, const char *fstype);
> > +
> >  #ifdef TST_TEST_H__
> >  static inline long tst_fs_type(const char *path)
> >  {
> > diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> > new file mode 100644
> > index 000000000..f63eb5565
> > --- /dev/null
> > +++ b/lib/tst_ioctl.c
> > @@ -0,0 +1,39 @@
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > +
> > +#include <errno.h>
> > +#include <stdio.h>
> > +#include <stdlib.h>
> > +#include <sys/ioctl.h>
> > +#include <linux/fs.h>
> > +
> > +#define TST_NO_DEFAULT_MAIN
> > +
> > +#include "tst_test.h"
> > +
> > +int tst_fibmap(const char *filename, const char *fstype)
> > +{
> > +       /* test if FIBMAP ioctl is supported */
> > +       int fd, block = 0;
> > +
> > +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported on %s", fstype);
> 
> passing the fstype into this helper seems quite irrelevant to me.
> the TINFO print doesn't justify it IMO
> Its not even an important info IMO, so as long as you have the print
> when FIBMAP not supported

That's for ensure the test taking place in the right dir. We can remove this.

> 
> > +
> > +       fd = open(filename, O_RDWR | O_CREAT, 0666);
> > +       if (fd < 0) {
> > +               tst_res(TWARN | TERRNO,
> > +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
> > +               return 1;
> > +       }
> > +
> > +       if (ioctl(fd, FIBMAP, &block)) {
> > +               tst_res(TINFO, "FIBMAP ioctl is NOT supported");
> > +               close(fd);
> > +               return 1;
> > +       }
> > +       tst_res(TINFO, "FIBMAP ioctl is supported");
> > +
> > +       if (close(fd)) {
> > +               tst_res(TWARN | TERRNO, "close(fd) failed");
> > +               return 1;
> > +       }
> > +       return 0;
> > +}
> > diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > index a63e661a5..fbce66fc8 100644
> > --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > @@ -32,6 +32,7 @@ static void verify_swapoff(void);
> >
> >  char *TCID = "swapoff01";
> >  int TST_TOTAL = 1;
> > +int fibmap = 1;
> >
> >  static long fs_type;
> >
> > @@ -55,22 +56,26 @@ int main(int ac, char **av)
> >  static void verify_swapoff(void)
> >  {
> >         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > -                       tst_brkm(TCONF, cleanup,
> > -                                "Swapfiles on BTRFS are not implemented");
> > +               if (fibmap == 1) {
> 
> This changes both logic and output message.
> I don't see a good reason for you to do that.
> Please keep the errno == EINVAL check and the message format for TCONF case
> Same comment for all the other places it applies

Explained at the beginning.

> 
> > +                       tst_resm(TBROK, "Failed to turn on the swap file"
> > +                                ", skipping test iteration");
> > +                       return;
> > +               } else {
> > +                       tst_resm(TCONF, "Failed to turn on the swap file"
> > +                                ", keep going for sanity check");
> >                 }
> > -
> > -               tst_resm(TBROK, "Failed to turn on the swap file"
> > -                        ", skipping test iteration");
> > -               return;
> >         }
> >
> >         TEST(ltp_syscall(__NR_swapoff, "./swapfile01"));
> >
> >         if (TEST_RETURN == -1) {
> > -               tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> > -                        " system reboot after execution of LTP "
> > -                        "test suite is recommended.");
> > +               if (fibmap == 1) {
> 
> No reason to do that.
> If filesystem was already proven to support swpaon(), swapoff() must succeed.
> If fs doesn't support swapon(), test should bail out and not try swapoff()

If swapon() fails an fibmap == 0, we could be here for a sanity check. Big
chance it will fail, but hey, don't panic.

> 
> > +                       tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> > +                                " system reboot after execution of LTP "
> > +                                "test suite is recommended.");
> > +               } else {
> > +                       tst_resm(TCONF, "Failed to turn off swapfile");
> > +               }
> >         } else {
> >                 tst_resm(TPASS, "Succeeded to turn off swapfile");
> >         }
> > @@ -86,13 +91,11 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > -               tst_brkm(TCONF, cleanup,
> > -                        "Cannot do swapoff on a file on %s filesystem",
> > -                        tst_fs_type_name(fs_type));
> > -       break;
> > +       fs_type = tst_fs_type(cleanup, ".");
> > +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> > +               tst_resm(TCONF,
> > +                        "Will not report FAIL as FIBMAP ioctl not supported");
> 
> Here printing fs name would be useful IMO

Ya, I did it here firstly.

> 
> > +               fibmap = 0;
> >         }
> >
> >         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> > @@ -103,8 +106,13 @@ static void setup(void)
> >         if (tst_fill_file("swapfile01", 0x00, 1024, 65536))
> >                 tst_brkm(TBROK, cleanup, "Failed to create file for swap");
> >
> > -       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0)
> > -               tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> > +       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) {
> > +               if (fibmap == 1) {
> > +                       tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> > +               } else {
> > +                       tst_resm(TCONF, "Failed to make swapfile");
> 
> You see, this message does not align with the outcome (skip).

Sorry, you lost me here.

> Is this really needed? does mkswap fail on tmpfs?
> If it does, then surely the entire test can be skipped

Or fail silently with out reporting FAIL.

> 
> > +               }
> > +       }
> >  }
> >
> >  static void cleanup(void)
> > diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > index b5c6312a1..2267449eb 100644
> > --- a/testcases/kernel/syscalls/swapoff/swapoff02.c
> > +++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
> > @@ -124,7 +124,6 @@ static void cleanup01(void)
> >
> >  static void setup(void)
> >  {
> > -       long type;
> >         struct passwd *nobody;
> >
> >         tst_sig(FORK, DEF_HANDLER, cleanup);
> > @@ -138,15 +137,6 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > -               tst_brkm(TCONF, cleanup,
> > -                        "Cannot do swapoff on a file on %s filesystem",
> > -                        tst_fs_type_name(type));
> > -       break;
> > -       }
> > -
> >         if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
> >                 tst_brkm(TBROK, cleanup,
> >                          "Insufficient disk space to create swap file");
> > diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
> > index 32538f82b..0419cae28 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon01.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon01.c
> > @@ -31,6 +31,7 @@ static void cleanup(void);
> >
> >  char *TCID = "swapon01";
> >  int TST_TOTAL = 1;
> > +int fibmap = 1;
> >
> >  static long fs_type;
> >
> > @@ -39,12 +40,11 @@ static void verify_swapon(void)
> >         TEST(ltp_syscall(__NR_swapon, "./swapfile01", 0));
> >
> >         if (TEST_RETURN == -1) {
> > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > -                       tst_brkm(TCONF, cleanup,
> > -                                "Swapfile on BTRFS not implemeted");
> > -                       return;
> > +               if (fibmap == 0) {
> > +                       tst_resm(TCONF, "Failed to turn on swapfile");
> 
> Please take care to not change logic.
> You replcaed tst_brkm with tst_resm. Intentional?
> You also change the meaning of the warning message to the worse IMO

No no no, :) Removal of BTRFS case is one part, and the change of TFAIL
report is another part.

> 
> > +               } else {
> > +                       tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
> >                 }
> > -               tst_resm(TFAIL | TTERRNO, "Failed to turn on swapfile");
	^^
	   tst_resm and msg come from this line.

> >         } else {
> >                 tst_resm(TPASS, "Succeeded to turn on swapfile");
> >                 /*we need to turn this swap file off for -i option */
> > @@ -58,7 +58,6 @@ static void verify_swapon(void)
> >
> >  int main(int ac, char **av)
> >  {
> > -
> >         int lc;
> >
> >         tst_parse_opts(ac, av, NULL, NULL);
> > @@ -84,13 +83,11 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > -               tst_brkm(TCONF, cleanup,
> > -                        "Cannot do swapon on a file on %s filesystem",
> > -                        tst_fs_type_name(fs_type));
> > -       break;
> > +       fs_type = tst_fs_type(cleanup, ".");
> > +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> > +               tst_resm(TCONF,
> > +                        "Will not report FAIL as FIBMAP ioctl not supported");
> > +               fibmap = 0;
> >         }
> >
> >         make_swapfile(cleanup, "swapfile01");
> > diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
> > index 4af5105c6..8120be987 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon02.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon02.c
> > @@ -44,6 +44,7 @@ static void cleanup01(void);
> >
> >  char *TCID = "swapon02";
> >  int TST_TOTAL = 4;
> > +int fibmap = 1;
> >
> >  static uid_t nobody_uid;
> >  static int do_swapoff;
> > @@ -81,14 +82,15 @@ static void verify_swapon(struct test_case_t *test)
> >                 return;
> >         }
> >
> > -       if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > -               tst_resm(TCONF, "Swapfile on BTRFS not implemeted");
> > -                       return;
> > +       if (fibmap == 1) {
> > +               tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
> > +                        " %d, errno: %s and got %d.", test->exp_errno,
> > +                        test->exp_errval, TEST_ERRNO);
> 
> Changes message


Ditto.

> 
> > +       } else {
> > +               tst_resm(TCONF, "swapon(2) failed to produce expected error:"
> > +                        " %d, errno: %s and got %d.", test->exp_errno,
> > +                        test->exp_errval, TEST_ERRNO);
> >         }
> > -
> > -       tst_resm(TFAIL, "swapon(2) failed to produce expected error:"
> > -                " %d, errno: %s and got %d.", test->exp_errno,
> > -                test->exp_errval, TEST_ERRNO);
> >  }
> >
> >  int main(int ac, char **av)
> > @@ -132,13 +134,11 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > -               tst_brkm(TCONF, cleanup,
> > -                        "Cannot do swapon on a file on %s filesystem",
> > -                        tst_fs_type_name(fs_type));
> > -       break;
> > +       fs_type = tst_fs_type(cleanup, ".");
> > +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> > +               tst_resm(TCONF,
> > +                        "Will not report FAIL as FIBMAP ioctl not supported");
> > +               fibmap = 0;
> >         }
> >
> >         SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
> > @@ -146,8 +146,7 @@ static void setup(void)
> >         make_swapfile(cleanup, "alreadyused");
> >
> >         if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
> > -               if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
> > -                       tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
> > +               tst_resm(TWARN | TERRNO, "swapon(alreadyused) failed");
> 
> Change of logic for fibmap == 0 case

It's a warning no matter what fs it is.

Thanks!
M

> 
> >         } else {
> >                 do_swapoff = 1;
> >         }
> > diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
> > index 955ac247b..696d0a3dd 100644
> > --- a/testcases/kernel/syscalls/swapon/swapon03.c
> > +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> > @@ -49,6 +49,7 @@ static int check_and_swapoff(const char *filename);
> >
> >  char *TCID = "swapon03";
> >  int TST_TOTAL = 1;
> > +int fibmap = 1;
> >
> >  static int swapfiles;
> >
> > @@ -65,6 +66,14 @@ static struct swap_testfile_t {
> >
> >  int expected_errno = EPERM;
> >
> > +void record_failure_soft(int flag, char *s, int exp, char *err)
> > +{
> > +       if (fibmap != 1)
> > +               flag = TCONF;
> > +
> > +       tst_resm(flag, s, exp, err);
> > +}
> > +
> >  int main(int ac, char **av)
> >  {
> >         int lc;
> > @@ -88,10 +97,10 @@ int main(int ac, char **av)
> >                         tst_resm(TPASS, "swapon(2) got expected failure (%d),",
> >                                  expected_errno);
> >                 } else if (TEST_RETURN < 0) {
> > -                       tst_resm(TFAIL | TTERRNO,
> > +                       record_failure_soft(TFAIL | TTERRNO,
> >                                  "swapon(2) failed to produce expected error "
> > -                                "(%d). System reboot recommended.",
> > -                                expected_errno);
> > +                                "(%d), got (%s). System reboot recommended.",
> > +                                expected_errno, strerror(TEST_ERRNO));
> >                 } else {
> >                         /* Probably the system supports MAX_SWAPFILES > 30,
> >                          * let's try with MAX_SWAPFILES == 32 */
> > @@ -103,8 +112,10 @@ int main(int ac, char **av)
> >
> >                         /* Check return code (now we're expecting success) */
> >                         if (TEST_RETURN < 0) {
> > -                               tst_resm(TFAIL | TTERRNO,
> > -                                        "swapon(2) got an unexpected failure");
> > +                               record_failure_soft(TFAIL | TTERRNO,
> > +                                        "swapon(2) got an unexpected failure"
> > +                                        "(%d: %s).",
> > +                                        TEST_RETURN, strerror(TEST_ERRNO));
> >                         } else {
> >                                 /* Call swapon sys call once again for 33
> >                                  * now we have to receive an error */
> > @@ -121,7 +132,7 @@ int main(int ac, char **av)
> >                                                  " MAX_SWAPFILES is 32",
> >                                                  expected_errno);
> >                                 } else {
> > -                                       tst_resm(TFAIL,
> > +                                       record_failure_soft(TFAIL,
> >                                                  "swapon(2) failed to produce"
> >                                                  " expected error: %d, got %s."
> >                                                  " System reboot after execution of LTP"
> > @@ -141,7 +152,6 @@ int main(int ac, char **av)
> >
> >         cleanup();
> >         tst_exit();
> > -
> >  }
> >
> >  /*
> > @@ -215,9 +225,6 @@ static int setup_swap(void)
> >                         /* turn on the swap file */
> >                         res = ltp_syscall(__NR_swapon, filename, 0);
> >                         if (res != 0) {
> > -                               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL)
> > -                                       exit(2);
> > -
> >                                 if (errno == EPERM) {
> >                                         printf("Successfully created %d "
> >                                                "swapfiles\n", j);
> > @@ -225,7 +232,8 @@ static int setup_swap(void)
> >                                 } else {
> >                                         printf("Failed to create "
> >                                                "swapfile: %s\n", filename);
> > -                                       exit(1);
> > +                                       if (fibmap == 1)
> > +                                               exit(1);
> >                                 }
> >                         }
> >                 }
> > @@ -233,15 +241,8 @@ static int setup_swap(void)
> >         } else
> >                 waitpid(pid, &status, 0);
> >
> > -       switch (WEXITSTATUS(status)) {
> > -       case 0:
> > -       break;
> > -       case 2:
> > -               tst_brkm(TCONF, cleanup, "Swapfile on BTRFS not implemeted");
> > -       break;
> > -       default:
> > +       if (WEXITSTATUS(status)) {
> >                 tst_brkm(TFAIL, cleanup, "Failed to setup swaps");
> > -       break;
> >         }
> >
> >         /* Create all needed extra swapfiles for testing */
> > @@ -249,7 +250,6 @@ static int setup_swap(void)
> >                 make_swapfile(cleanup, swap_testfiles[j].filename);
> >
> >         return 0;
> > -
> >  }
> >
> >  /*
> > @@ -333,13 +333,11 @@ static void setup(void)
> >
> >         tst_tmpdir();
> >
> > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > -       case TST_NFS_MAGIC:
> > -       case TST_TMPFS_MAGIC:
> > -               tst_brkm(TCONF, cleanup,
> > -                        "Cannot do swapon on a file on %s filesystem",
> > -                        tst_fs_type_name(fs_type));
> > -       break;
> > +       fs_type = tst_fs_type(cleanup, ".");
> > +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> > +               tst_resm(TCONF,
> > +                        "Will not report FAIL as FIBMAP ioctl not supported");
> > +               fibmap = 0;
> >         }
> >
> >         TEST_PAUSE;
> > --
> > 2.21.0
> >

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-10  8:15                             ` Murphy Zhou
@ 2019-05-10  8:48                               ` Amir Goldstein
  2019-05-11  4:20                                 ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Amir Goldstein @ 2019-05-10  8:48 UTC (permalink / raw)
  To: ltp

On Fri, May 10, 2019 at 11:15 AM Murphy Zhou <xzhou@redhat.com> wrote:
>
> On Fri, May 10, 2019 at 08:27:35AM +0300, Amir Goldstein wrote:
> > On Fri, May 10, 2019 at 7:42 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > >
> > > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
> >
> > If you wouldn't have just done that it would have been good.
> > But your patch also changes a lot of the logic and output messages,
> > which is less good.
>
> First of all, don't be mad if you think I'm changing too much. :)

Not mad. Sorry if came off this way..
Just trying to explain why too much changes can be counter productive.
And I am writing my opinion, you are not obliged to agree with it ;-)

> I should have written more info here in commit message like in the changelog.
>
> If FIBMAP trial fails, don't bail out immediately, go on to the rest
> of tests. Than don't report fail if swap* syscall fails, just record
> the failure info, acting like a sanity check test.

In retrospect, I think the best approach is to do all the feature support
testing in setup(). As someone else wrote, testing mkswap/swapon in setup()
and keeping logic simpler in tests would be better.
Testing FIBMAP and then mkwap/swpaon/swapoff will make sure that
test will detect regression in swpaon with filesystems that support
FIBMAP. It will not guaranty that for BTRFS/NFS, but that is the tradeoff
of not whitelisting.

>
> If FIBMAP trial pass, follow the original logic.
>
> The whitelist code removal is kinda independent. But combining with the
> fibmap code it looks like a lot of logic changing.
>
> > For BTRFS, with a kernel that does not support swapon/off, test logic
> > should have stayed the same and produce more or less the same output.
> > This would have made review much easier and less chance of breaking things.
>
> I can understand the test logic part, but why the same output matters?
> Since we are not using golden output like fstests :)

Same output doesn't matter, but output was good and you have not
made it better you have made it worse - I will explain below.

>
> Back to the logic, checking specific return value is precise, but it i
>  hard to maintain them IMO. If kernel logic changes, it's easy to forget
> updating testing logic. That's why I am fan of your whitelist avoiding
> idea. Now if I understand correctly, you want to keep the filesystems
> whitelist, fibmap test is just for the info. Am I right?

I meant you stopped checking errno == EINVAL, which is the only
expected return value for fs that do not support swapon.
If for some reason btrfs has a regression and swapon returns ENOSPC
test MUST fail.

>
> For better communication, I'd like to remove whitelist code. Can we have
> an alter opinion here?
>
> >
> > > Leave swapoff02 alone because it's permission checking only in it.
> > >
> > > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > ---
> > > v2:
> > >   Test FIBMAP instead of fstype whitelist.
> > > v3:
> > >   Fix fs_type undeclared in swapoff01.c.
> > > v4:
> > >   Fail softly if FIBMAP nit supported, instead of skip entire testcase.
> > >
> > >  include/tst_fs.h                              |  5 ++
> > >  lib/tst_ioctl.c                               | 39 ++++++++++++++
> > >  testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++-------
> > >  testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ----
> > >  testcases/kernel/syscalls/swapon/swapon01.c   | 23 ++++----
> > >  testcases/kernel/syscalls/swapon/swapon02.c   | 31 ++++++-----
> > >  testcases/kernel/syscalls/swapon/swapon03.c   | 52 +++++++++----------
> > >  7 files changed, 121 insertions(+), 85 deletions(-)
> > >  create mode 100644 lib/tst_ioctl.c
> > >
> > > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > > index b2b19ada6..423ca82ec 100644
> > > --- a/include/tst_fs.h
> > > +++ b/include/tst_fs.h
> > > @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
> > >   */
> > >  void tst_fill_fs(const char *path, int verbose);
> > >
> > > +/*
> > > + * test if FIBMAP ioctl is supported
> > > + */
> > > +int tst_fibmap(const char *filename, const char *fstype);
> > > +
> > >  #ifdef TST_TEST_H__
> > >  static inline long tst_fs_type(const char *path)
> > >  {
> > > diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> > > new file mode 100644
> > > index 000000000..f63eb5565
> > > --- /dev/null
> > > +++ b/lib/tst_ioctl.c
> > > @@ -0,0 +1,39 @@
> > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > +
> > > +#include <errno.h>
> > > +#include <stdio.h>
> > > +#include <stdlib.h>
> > > +#include <sys/ioctl.h>
> > > +#include <linux/fs.h>
> > > +
> > > +#define TST_NO_DEFAULT_MAIN
> > > +
> > > +#include "tst_test.h"
> > > +
> > > +int tst_fibmap(const char *filename, const char *fstype)
> > > +{
> > > +       /* test if FIBMAP ioctl is supported */
> > > +       int fd, block = 0;
> > > +
> > > +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported on %s", fstype);
> >
> > passing the fstype into this helper seems quite irrelevant to me.
> > the TINFO print doesn't justify it IMO
> > Its not even an important info IMO, so as long as you have the print
> > when FIBMAP not supported
>
> That's for ensure the test taking place in the right dir. We can remove this.
>
> >
> > > +
> > > +       fd = open(filename, O_RDWR | O_CREAT, 0666);
> > > +       if (fd < 0) {
> > > +               tst_res(TWARN | TERRNO,
> > > +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
> > > +               return 1;
> > > +       }
> > > +
> > > +       if (ioctl(fd, FIBMAP, &block)) {
> > > +               tst_res(TINFO, "FIBMAP ioctl is NOT supported");
> > > +               close(fd);
> > > +               return 1;
> > > +       }
> > > +       tst_res(TINFO, "FIBMAP ioctl is supported");
> > > +
> > > +       if (close(fd)) {
> > > +               tst_res(TWARN | TERRNO, "close(fd) failed");
> > > +               return 1;
> > > +       }
> > > +       return 0;
> > > +}
> > > diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > index a63e661a5..fbce66fc8 100644
> > > --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > @@ -32,6 +32,7 @@ static void verify_swapoff(void);
> > >
> > >  char *TCID = "swapoff01";
> > >  int TST_TOTAL = 1;
> > > +int fibmap = 1;
> > >
> > >  static long fs_type;
> > >
> > > @@ -55,22 +56,26 @@ int main(int ac, char **av)
> > >  static void verify_swapoff(void)
> > >  {
> > >         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> > > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > > -                       tst_brkm(TCONF, cleanup,
> > > -                                "Swapfiles on BTRFS are not implemented");
> > > +               if (fibmap == 1) {
> >
> > This changes both logic and output message.
> > I don't see a good reason for you to do that.
> > Please keep the errno == EINVAL check and the message format for TCONF case
> > Same comment for all the other places it applies
>
> Explained at the beginning.
>
> >
> > > +                       tst_resm(TBROK, "Failed to turn on the swap file"
> > > +                                ", skipping test iteration");
> > > +                       return;
> > > +               } else {
> > > +                       tst_resm(TCONF, "Failed to turn on the swap file"
> > > +                                ", keep going for sanity check");
> > >                 }
> > > -
> > > -               tst_resm(TBROK, "Failed to turn on the swap file"
> > > -                        ", skipping test iteration");
> > > -               return;
> > >         }
> > >
> > >         TEST(ltp_syscall(__NR_swapoff, "./swapfile01"));
> > >
> > >         if (TEST_RETURN == -1) {
> > > -               tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> > > -                        " system reboot after execution of LTP "
> > > -                        "test suite is recommended.");
> > > +               if (fibmap == 1) {
> >
> > No reason to do that.
> > If filesystem was already proven to support swpaon(), swapoff() must succeed.
> > If fs doesn't support swapon(), test should bail out and not try swapoff()
>
> If swapon() fails an fibmap == 0, we could be here for a sanity check. Big
> chance it will fail, but hey, don't panic.

Of course swapoff will fail if swpaon failed.
Should abort when swapon fails.

>
> >
> > > +                       tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> > > +                                " system reboot after execution of LTP "
> > > +                                "test suite is recommended.");
> > > +               } else {
> > > +                       tst_resm(TCONF, "Failed to turn off swapfile");
> > > +               }
> > >         } else {
> > >                 tst_resm(TPASS, "Succeeded to turn off swapfile");
> > >         }
> > > @@ -86,13 +91,11 @@ static void setup(void)
> > >
> > >         tst_tmpdir();
> > >
> > > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > > -       case TST_NFS_MAGIC:
> > > -       case TST_TMPFS_MAGIC:
> > > -               tst_brkm(TCONF, cleanup,
> > > -                        "Cannot do swapoff on a file on %s filesystem",
> > > -                        tst_fs_type_name(fs_type));
> > > -       break;
> > > +       fs_type = tst_fs_type(cleanup, ".");
> > > +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> > > +               tst_resm(TCONF,
> > > +                        "Will not report FAIL as FIBMAP ioctl not supported");
> >
> > Here printing fs name would be useful IMO
>
> Ya, I did it here firstly.
>
> >
> > > +               fibmap = 0;
> > >         }
> > >
> > >         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> > > @@ -103,8 +106,13 @@ static void setup(void)
> > >         if (tst_fill_file("swapfile01", 0x00, 1024, 65536))
> > >                 tst_brkm(TBROK, cleanup, "Failed to create file for swap");
> > >
> > > -       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0)
> > > -               tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> > > +       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) {
> > > +               if (fibmap == 1) {
> > > +                       tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> > > +               } else {
> > > +                       tst_resm(TCONF, "Failed to make swapfile");
> >
> > You see, this message does not align with the outcome (skip).
>
> Sorry, you lost me here.
>

Put your tester hat on. Imagine you do not know what swapfile is nor
that filesystems may support it or not.
Which is the following messages convey the test result better:

TCONF: Failed to make swapfile

OR

TCONF: mkswap not supported on btrfs filesystem

If test setup arrives to a conclusion that filesystem doesn't support test
and test should be skipped, that is what should be communicated to user.

The BTRFS_MAGIC code that your patch removes does that correctly.
Your patch does not.

Even the message:
TCONF: "Will not report FAIL as FIBMAP ioctl not supported"
is "too much information" IMO.
Users without proper background won't know what it means.
This would have been better IMO:
TCONF: "FIBMAP ioctl not supported on XXX filesystem"

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-10  8:48                               ` Amir Goldstein
@ 2019-05-11  4:20                                 ` Murphy Zhou
  2019-05-11  9:30                                   ` Amir Goldstein
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-05-11  4:20 UTC (permalink / raw)
  To: ltp

On Fri, May 10, 2019 at 11:48:42AM +0300, Amir Goldstein wrote:
> On Fri, May 10, 2019 at 11:15 AM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > On Fri, May 10, 2019 at 08:27:35AM +0300, Amir Goldstein wrote:
> > > On Fri, May 10, 2019 at 7:42 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > > >
> > > > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
> > >
> > > If you wouldn't have just done that it would have been good.
> > > But your patch also changes a lot of the logic and output messages,
> > > which is less good.
> >
> > First of all, don't be mad if you think I'm changing too much. :)
> 
> Not mad. Sorry if came off this way..
> Just trying to explain why too much changes can be counter productive.
> And I am writing my opinion, you are not obliged to agree with it ;-)

Start your developer engine. Actually _think_ about what your're writing.
Your opinion varies every single post in this thread.

> 
> > I should have written more info here in commit message like in the changelog.
> >
> > If FIBMAP trial fails, don't bail out immediately, go on to the rest
> > of tests. Than don't report fail if swap* syscall fails, just record
> > the failure info, acting like a sanity check test.
> 
> In retrospect, I think the best approach is to do all the feature support
> testing in setup(). As someone else wrote, testing mkswap/swapon in setup()
> and keeping logic simpler in tests would be better.
> Testing FIBMAP and then mkwap/swpaon/swapoff will make sure that
> test will detect regression in swpaon with filesystems that support
> FIBMAP. It will not guaranty that for BTRFS/NFS, but that is the tradeoff
> of not whitelisting.
> 
> >
> > If FIBMAP trial pass, follow the original logic.
> >
> > The whitelist code removal is kinda independent. But combining with the
> > fibmap code it looks like a lot of logic changing.
> >
> > > For BTRFS, with a kernel that does not support swapon/off, test logic
> > > should have stayed the same and produce more or less the same output.
> > > This would have made review much easier and less chance of breaking things.
> >
> > I can understand the test logic part, but why the same output matters?
> > Since we are not using golden output like fstests :)
> 
> Same output doesn't matter, but output was good and you have not
> made it better you have made it worse - I will explain below.
> 
> >
> > Back to the logic, checking specific return value is precise, but it i
> >  hard to maintain them IMO. If kernel logic changes, it's easy to forget
> > updating testing logic. That's why I am fan of your whitelist avoiding
> > idea. Now if I understand correctly, you want to keep the filesystems
> > whitelist, fibmap test is just for the info. Am I right?
> 
> I meant you stopped checking errno == EINVAL, which is the only
> expected return value for fs that do not support swapon.
> If for some reason btrfs has a regression and swapon returns ENOSPC
> test MUST fail.

Ah, this is new to me.

> 
> >
> > For better communication, I'd like to remove whitelist code. Can we have
> > an alter opinion here?
> >
> > >
> > > > Leave swapoff02 alone because it's permission checking only in it.
> > > >
> > > > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > > ---
> > > > v2:
> > > >   Test FIBMAP instead of fstype whitelist.
> > > > v3:
> > > >   Fix fs_type undeclared in swapoff01.c.
> > > > v4:
> > > >   Fail softly if FIBMAP nit supported, instead of skip entire testcase.
> > > >
> > > >  include/tst_fs.h                              |  5 ++
> > > >  lib/tst_ioctl.c                               | 39 ++++++++++++++
> > > >  testcases/kernel/syscalls/swapoff/swapoff01.c | 46 +++++++++-------
> > > >  testcases/kernel/syscalls/swapoff/swapoff02.c | 10 ----
> > > >  testcases/kernel/syscalls/swapon/swapon01.c   | 23 ++++----
> > > >  testcases/kernel/syscalls/swapon/swapon02.c   | 31 ++++++-----
> > > >  testcases/kernel/syscalls/swapon/swapon03.c   | 52 +++++++++----------
> > > >  7 files changed, 121 insertions(+), 85 deletions(-)
> > > >  create mode 100644 lib/tst_ioctl.c
> > > >
> > > > diff --git a/include/tst_fs.h b/include/tst_fs.h
> > > > index b2b19ada6..423ca82ec 100644
> > > > --- a/include/tst_fs.h
> > > > +++ b/include/tst_fs.h
> > > > @@ -172,6 +172,11 @@ const char **tst_get_supported_fs_types(void);
> > > >   */
> > > >  void tst_fill_fs(const char *path, int verbose);
> > > >
> > > > +/*
> > > > + * test if FIBMAP ioctl is supported
> > > > + */
> > > > +int tst_fibmap(const char *filename, const char *fstype);
> > > > +
> > > >  #ifdef TST_TEST_H__
> > > >  static inline long tst_fs_type(const char *path)
> > > >  {
> > > > diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> > > > new file mode 100644
> > > > index 000000000..f63eb5565
> > > > --- /dev/null
> > > > +++ b/lib/tst_ioctl.c
> > > > @@ -0,0 +1,39 @@
> > > > +// SPDX-License-Identifier: GPL-2.0-or-later
> > > > +
> > > > +#include <errno.h>
> > > > +#include <stdio.h>
> > > > +#include <stdlib.h>
> > > > +#include <sys/ioctl.h>
> > > > +#include <linux/fs.h>
> > > > +
> > > > +#define TST_NO_DEFAULT_MAIN
> > > > +
> > > > +#include "tst_test.h"
> > > > +
> > > > +int tst_fibmap(const char *filename, const char *fstype)
> > > > +{
> > > > +       /* test if FIBMAP ioctl is supported */
> > > > +       int fd, block = 0;
> > > > +
> > > > +       tst_res(TINFO, "Testing if FIBMAP ioctl is supported on %s", fstype);
> > >
> > > passing the fstype into this helper seems quite irrelevant to me.
> > > the TINFO print doesn't justify it IMO
> > > Its not even an important info IMO, so as long as you have the print
> > > when FIBMAP not supported
> >
> > That's for ensure the test taking place in the right dir. We can remove this.
> >
> > >
> > > > +
> > > > +       fd = open(filename, O_RDWR | O_CREAT, 0666);
> > > > +       if (fd < 0) {
> > > > +               tst_res(TWARN | TERRNO,
> > > > +                        "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
> > > > +               return 1;
> > > > +       }
> > > > +
> > > > +       if (ioctl(fd, FIBMAP, &block)) {
> > > > +               tst_res(TINFO, "FIBMAP ioctl is NOT supported");
> > > > +               close(fd);
> > > > +               return 1;
> > > > +       }
> > > > +       tst_res(TINFO, "FIBMAP ioctl is supported");
> > > > +
> > > > +       if (close(fd)) {
> > > > +               tst_res(TWARN | TERRNO, "close(fd) failed");
> > > > +               return 1;
> > > > +       }
> > > > +       return 0;
> > > > +}
> > > > diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > > index a63e661a5..fbce66fc8 100644
> > > > --- a/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > > +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
> > > > @@ -32,6 +32,7 @@ static void verify_swapoff(void);
> > > >
> > > >  char *TCID = "swapoff01";
> > > >  int TST_TOTAL = 1;
> > > > +int fibmap = 1;
> > > >
> > > >  static long fs_type;
> > > >
> > > > @@ -55,22 +56,26 @@ int main(int ac, char **av)
> > > >  static void verify_swapoff(void)
> > > >  {
> > > >         if (ltp_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
> > > > -               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> > > > -                       tst_brkm(TCONF, cleanup,
> > > > -                                "Swapfiles on BTRFS are not implemented");
> > > > +               if (fibmap == 1) {
> > >
> > > This changes both logic and output message.
> > > I don't see a good reason for you to do that.
> > > Please keep the errno == EINVAL check and the message format for TCONF case
> > > Same comment for all the other places it applies
> >
> > Explained at the beginning.
> >
> > >
> > > > +                       tst_resm(TBROK, "Failed to turn on the swap file"
> > > > +                                ", skipping test iteration");
> > > > +                       return;
> > > > +               } else {
> > > > +                       tst_resm(TCONF, "Failed to turn on the swap file"
> > > > +                                ", keep going for sanity check");
> > > >                 }
> > > > -
> > > > -               tst_resm(TBROK, "Failed to turn on the swap file"
> > > > -                        ", skipping test iteration");
> > > > -               return;
> > > >         }
> > > >
> > > >         TEST(ltp_syscall(__NR_swapoff, "./swapfile01"));
> > > >
> > > >         if (TEST_RETURN == -1) {
> > > > -               tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> > > > -                        " system reboot after execution of LTP "
> > > > -                        "test suite is recommended.");
> > > > +               if (fibmap == 1) {
> > >
> > > No reason to do that.
> > > If filesystem was already proven to support swpaon(), swapoff() must succeed.
> > > If fs doesn't support swapon(), test should bail out and not try swapoff()
> >
> > If swapon() fails an fibmap == 0, we could be here for a sanity check. Big
> > chance it will fail, but hey, don't panic.
> 
> Of course swapoff will fail if swpaon failed.
> Should abort when swapon fails.
> 
> >
> > >
> > > > +                       tst_resm(TFAIL | TTERRNO, "Failed to turn off swapfile,"
> > > > +                                " system reboot after execution of LTP "
> > > > +                                "test suite is recommended.");
> > > > +               } else {
> > > > +                       tst_resm(TCONF, "Failed to turn off swapfile");
> > > > +               }
> > > >         } else {
> > > >                 tst_resm(TPASS, "Succeeded to turn off swapfile");
> > > >         }
> > > > @@ -86,13 +91,11 @@ static void setup(void)
> > > >
> > > >         tst_tmpdir();
> > > >
> > > > -       switch ((fs_type = tst_fs_type(cleanup, "."))) {
> > > > -       case TST_NFS_MAGIC:
> > > > -       case TST_TMPFS_MAGIC:
> > > > -               tst_brkm(TCONF, cleanup,
> > > > -                        "Cannot do swapoff on a file on %s filesystem",
> > > > -                        tst_fs_type_name(fs_type));
> > > > -       break;
> > > > +       fs_type = tst_fs_type(cleanup, ".");
> > > > +       if (tst_fibmap("./tst_fibmap", tst_fs_type_name(fs_type))) {
> > > > +               tst_resm(TCONF,
> > > > +                        "Will not report FAIL as FIBMAP ioctl not supported");
> > >
> > > Here printing fs name would be useful IMO
> >
> > Ya, I did it here firstly.
> >
> > >
> > > > +               fibmap = 0;
> > > >         }
> > > >
> > > >         if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
> > > > @@ -103,8 +106,13 @@ static void setup(void)
> > > >         if (tst_fill_file("swapfile01", 0x00, 1024, 65536))
> > > >                 tst_brkm(TBROK, cleanup, "Failed to create file for swap");
> > > >
> > > > -       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0)
> > > > -               tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> > > > +       if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) {
> > > > +               if (fibmap == 1) {
> > > > +                       tst_brkm(TBROK, cleanup, "Failed to make swapfile");
> > > > +               } else {
> > > > +                       tst_resm(TCONF, "Failed to make swapfile");
> > >
> > > You see, this message does not align with the outcome (skip).
> >
> > Sorry, you lost me here.
> >
> 
> Put your tester hat on. Imagine you do not know what swapfile is nor
> that filesystems may support it or not.
> Which is the following messages convey the test result better:
> 
> TCONF: Failed to make swapfile
> 
> OR
> 
> TCONF: mkswap not supported on btrfs filesystem

You are ranting at wrong guy. It was not me writing this message.

> 
> If test setup arrives to a conclusion that filesystem doesn't support test
> and test should be skipped, that is what should be communicated to user.
> 
> The BTRFS_MAGIC code that your patch removes does that correctly.
> Your patch does not.
> 
> Even the message:
> TCONF: "Will not report FAIL as FIBMAP ioctl not supported"
> is "too much information" IMO.
> Users without proper background won't know what it means.
> This would have been better IMO:
> TCONF: "FIBMAP ioctl not supported on XXX filesystem"

I guess LTP is not a desktop app :), but yes these messages need improvement.

Thanks,
M

> 
> Thanks,
> Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-11  4:20                                 ` Murphy Zhou
@ 2019-05-11  9:30                                   ` Amir Goldstein
  2019-05-13  7:39                                     ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Amir Goldstein @ 2019-05-11  9:30 UTC (permalink / raw)
  To: ltp

On Sat, May 11, 2019 at 7:20 AM Murphy Zhou <xzhou@redhat.com> wrote:
>
> On Fri, May 10, 2019 at 11:48:42AM +0300, Amir Goldstein wrote:
> > On Fri, May 10, 2019 at 11:15 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > >
> > > On Fri, May 10, 2019 at 08:27:35AM +0300, Amir Goldstein wrote:
> > > > On Fri, May 10, 2019 at 7:42 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > > > >
> > > > > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
> > > >
> > > > If you wouldn't have just done that it would have been good.
> > > > But your patch also changes a lot of the logic and output messages,
> > > > which is less good.
> > >
> > > First of all, don't be mad if you think I'm changing too much. :)
> >
> > Not mad. Sorry if came off this way..
> > Just trying to explain why too much changes can be counter productive.
> > And I am writing my opinion, you are not obliged to agree with it ;-)
>
> Start your developer engine. Actually _think_ about what your're writing.
> Your opinion varies every single post in this thread.
>

I sense that I offended you. I did not mean to. I apologize.
There might have been some miscommunication.
My option varied after incorporating feedback from Li Wang and looking
closer at recent kernel changes to btrfs, which I was not aware of.

To be clear, my current opinion is:
- As Li suggested, it is best to check filesystem support in setup()
using swapon()
  and the rest of the test should not relax any failure
- By checking FIBMAP before swapon() in setup() you can differentiate between
  failing the test (for legacy fs) or TCONF (BTRFS, NFS)
- TCONF result should be accompanied with "not supported" language
- Take care not to change test logic in a way that will regress test on older
  kernels or some filesystem

[...]
> > Put your tester hat on. Imagine you do not know what swapfile is nor
> > that filesystems may support it or not.
> > Which is the following messages convey the test result better:
> >
> > TCONF: Failed to make swapfile
> >
> > OR
> >
> > TCONF: mkswap not supported on btrfs filesystem
>
> You are ranting at wrong guy. It was not me writing this message.
>

Certainly. It wasn't my intention to blame you for anything.
The developer that wrote this message did not expect tmpfs to reach this
point, because blacklist was in place.
By changing from TBROK to TCONF, the message may need to change
from a language of "Failed" to a language of "not supported".

> >
> > If test setup arrives to a conclusion that filesystem doesn't support test
> > and test should be skipped, that is what should be communicated to user.
> >
> > The BTRFS_MAGIC code that your patch removes does that correctly.
> > Your patch does not.
> >
> > Even the message:
> > TCONF: "Will not report FAIL as FIBMAP ioctl not supported"
> > is "too much information" IMO.
> > Users without proper background won't know what it means.
> > This would have been better IMO:
> > TCONF: "FIBMAP ioctl not supported on XXX filesystem"
>
> I guess LTP is not a desktop app :), but yes these messages need improvement.
>

Test engineers can spend a lot of time figuring out why a certain test
(of a feature they
are not intimately familiar with) has started failing on a certain
kernel version or after
getting latest LTP.
We should be sympathetic to our end users and try to make their lives
easier if it is
in our power.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-11  9:30                                   ` Amir Goldstein
@ 2019-05-13  7:39                                     ` Murphy Zhou
  2019-05-23 13:55                                       ` Cyril Hrubis
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-05-13  7:39 UTC (permalink / raw)
  To: ltp

On Sat, May 11, 2019 at 12:30:51PM +0300, Amir Goldstein wrote:
> On Sat, May 11, 2019 at 7:20 AM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > On Fri, May 10, 2019 at 11:48:42AM +0300, Amir Goldstein wrote:
> > > On Fri, May 10, 2019 at 11:15 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > > >
> > > > On Fri, May 10, 2019 at 08:27:35AM +0300, Amir Goldstein wrote:
> > > > > On Fri, May 10, 2019 at 7:42 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > > > > >
> > > > > > Add a test helper to do a FIBMAP ioctl test. Remove old fs type whitelist code.
> > > > >
> > > > > If you wouldn't have just done that it would have been good.
> > > > > But your patch also changes a lot of the logic and output messages,
> > > > > which is less good.
> > > >
> > > > First of all, don't be mad if you think I'm changing too much. :)
> > >
> > > Not mad. Sorry if came off this way..
> > > Just trying to explain why too much changes can be counter productive.
> > > And I am writing my opinion, you are not obliged to agree with it ;-)
> >
> > Start your developer engine. Actually _think_ about what your're writing.
> > Your opinion varies every single post in this thread.
> >
> 
> I sense that I offended you. I did not mean to. I apologize.
> There might have been some miscommunication.

Nevermind.

> My option varied after incorporating feedback from Li Wang and looking
> closer at recent kernel changes to btrfs, which I was not aware of.
> 
> To be clear, my current opinion is:
> - As Li suggested, it is best to check filesystem support in setup()
> using swapon()
>   and the rest of the test should not relax any failure
> - By checking FIBMAP before swapon() in setup() you can differentiate between
>   failing the test (for legacy fs) or TCONF (BTRFS, NFS)
> - TCONF result should be accompanied with "not supported" language
> - Take care not to change test logic in a way that will regress test on older
>   kernels or some filesystem

Crystal clear now and I agree.

> 
> [...]
> > > Put your tester hat on. Imagine you do not know what swapfile is nor
> > > that filesystems may support it or not.
> > > Which is the following messages convey the test result better:
> > >
> > > TCONF: Failed to make swapfile
> > >
> > > OR
> > >
> > > TCONF: mkswap not supported on btrfs filesystem
> >
> > You are ranting at wrong guy. It was not me writing this message.
> >
> 
> Certainly. It wasn't my intention to blame you for anything.
> The developer that wrote this message did not expect tmpfs to reach this
> point, because blacklist was in place.
> By changing from TBROK to TCONF, the message may need to change
> from a language of "Failed" to a language of "not supported".

Fare enough.

> 
> > >
> > > If test setup arrives to a conclusion that filesystem doesn't support test
> > > and test should be skipped, that is what should be communicated to user.
> > >
> > > The BTRFS_MAGIC code that your patch removes does that correctly.
> > > Your patch does not.
> > >
> > > Even the message:
> > > TCONF: "Will not report FAIL as FIBMAP ioctl not supported"
> > > is "too much information" IMO.
> > > Users without proper background won't know what it means.
> > > This would have been better IMO:
> > > TCONF: "FIBMAP ioctl not supported on XXX filesystem"
> >
> > I guess LTP is not a desktop app :), but yes these messages need improvement.
> >
> 
> Test engineers can spend a lot of time figuring out why a certain test
> (of a feature they
> are not intimately familiar with) has started failing on a certain
> kernel version or after
> getting latest LTP.
> We should be sympathetic to our end users and try to make their lives
> easier if it is
> in our power.

Can't agree more. :)

Thanks,
M

> 
> Thanks,
> Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-13  7:39                                     ` Murphy Zhou
@ 2019-05-23 13:55                                       ` Cyril Hrubis
  2019-05-23 14:06                                         ` Murphy Zhou
  2019-05-28  4:39                                         ` [LTP] [PATCH v5 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  0 siblings, 2 replies; 55+ messages in thread
From: Cyril Hrubis @ 2019-05-23 13:55 UTC (permalink / raw)
  To: ltp

Hi!
Guys what should I merge in the end?

Looking at the conversation v4 was not final patch, or was it?

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly if FIBMAP ioctl trial fails
  2019-05-23 13:55                                       ` Cyril Hrubis
@ 2019-05-23 14:06                                         ` Murphy Zhou
  2019-05-28  4:39                                         ` [LTP] [PATCH v5 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  1 sibling, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-23 14:06 UTC (permalink / raw)
  To: ltp

Hi,

I'm working on a new version based on Amir's comments. Will post later. Sorry for the confusion :)

Murphy

On Thu, May 23, 2019 at 03:55:18PM +0200, Cyril Hrubis wrote:
> Hi!
> Guys what should I merge in the end?
> 
> Looking at the conversation v4 was not final patch, or was it?
> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 1/4] lib/tst_ioctl.c: add helper tst_fibmap
  2019-05-23 13:55                                       ` Cyril Hrubis
  2019-05-23 14:06                                         ` Murphy Zhou
@ 2019-05-28  4:39                                         ` Murphy Zhou
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
                                                             ` (2 more replies)
  1 sibling, 3 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28  4:39 UTC (permalink / raw)
  To: ltp

To check if FIBMAP ioctl is supported on the filesystem we are
testing on. It also can check the support status of specific
files, but that may not needed for now.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
v5:
  Split to 4 patches
  Only take one filename parameter in tst_fibmap
  Add helper is_swap_supported to check swap operation support status
  Test fibmap/swapon and swapoff operation in the helper
  Keep NFS/TMPFS whitelist
  Keep BTRFS EINVAL handling logic, except above 2 situation:
    if swapon fails and fibmap is not supported, tst_brk with TCONF
    if swapon fails and fibmap is supported, tst_brk with TFAIL
  If swapon test pass in the helper, test swapoff similarly
  Put is_swap_supported helper in libswapon, link swapoff binaries to it
  Mute a sprintf filaname wanrning by the way
v4:
  Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
  Fix fs_type undeclared in swapoff01.c
v2:
  Test FIBMAP instead of fstype whitelist

 include/tst_fs.h |  5 +++++
 lib/tst_ioctl.c  | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 lib/tst_ioctl.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index ebca065c6..6d03371ec 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);
  */
 void tst_fill_fs(const char *path, int verbose);
 
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(const char *filename);
+
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
 {
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
new file mode 100644
index 000000000..38aa937db
--- /dev/null
+++ b/lib/tst_ioctl.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(const char *filename)
+{
+	/* test if FIBMAP ioctl is supported */
+	int fd, block = 0;
+
+	fd = open(filename, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		tst_res(TWARN | TERRNO,
+			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
+		return 1;
+	}
+
+	if (ioctl(fd, FIBMAP, &block)) {
+		tst_res(TINFO, "FIBMAP ioctl is NOT supported");
+		close(fd);
+		return 1;
+	}
+	tst_res(TINFO, "FIBMAP ioctl is supported");
+
+	if (close(fd)) {
+		tst_res(TWARN | TERRNO, "close(fd) failed");
+		return 1;
+	}
+	return 0;
+}
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28  4:39                                         ` [LTP] [PATCH v5 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
@ 2019-05-28  4:39                                           ` Murphy Zhou
  2019-05-28  5:56                                             ` Amir Goldstein
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status Murphy Zhou
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 4/4] syscalls/swapoff/swapoff01: " Murphy Zhou
  2 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28  4:39 UTC (permalink / raw)
  To: ltp

To check if the filesystem we are testing on supports swapon/swapoff
operations. Keep NFS and TMPFS on the white list. Don't report fail
if BTRFS fails with EINVAL.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++
 testcases/kernel/syscalls/swapon/libswapon.h |  6 +++
 2 files changed, 62 insertions(+)

diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
index cf6a98891..e02fdd4ad 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.c
+++ b/testcases/kernel/syscalls/swapon/libswapon.c
@@ -19,6 +19,8 @@
  *
  */
 
+#include <errno.h>
+#include "lapi/syscalls.h"
 #include "test.h"
 #include "libswapon.h"
 
@@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
 
 	tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
 }
+
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *ops,
+				const char *filename)
+{
+	int fibmap = tst_fibmap(filename);
+	long fs_type = tst_fs_type(cleanup, filename);
+	const char *fstype = tst_fs_type_name(fs_type);
+
+	/* whitelist legacy fs */
+	switch (fs_type) {
+	case TST_NFS_MAGIC:
+	case TST_TMPFS_MAGIC:
+		tst_brkm(TCONF, cleanup,
+			 "Cannot do %s on a file on %s filesystem",
+			 ops, fstype);
+	break;
+	}
+
+	make_swapfile(NULL, filename);
+
+	TEST(ltp_syscall(__NR_swapon, filename, 0));
+
+	if (TEST_RETURN == -1) {
+		if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
+			tst_brkm(TCONF, cleanup,
+				"Swapfile on BTRFS not implemented");
+		} else {
+			if (fibmap == 0) {
+				tst_brkm(TFAIL | TERRNO, cleanup,
+					 "swapon on %s failed", fstype);
+			} else {
+				tst_brkm(TCONF, cleanup,
+					 "swapon on %s is not supported",
+						fstype);
+			}
+		}
+	}
+
+	TEST(ltp_syscall(__NR_swapoff, filename, 0));
+
+	if (TEST_RETURN == -1) {
+		if (fibmap == 0) {
+			tst_brkm(TFAIL | TERRNO, cleanup,
+				"swapoff on %s failed", fstype);
+		} else {
+			tst_brkm(TCONF, cleanup,
+				 "swapoff on %s is not supported", fstype);
+		}
+	}
+}
diff --git a/testcases/kernel/syscalls/swapon/libswapon.h b/testcases/kernel/syscalls/swapon/libswapon.h
index 7f7211eb4..4f2c83614 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.h
+++ b/testcases/kernel/syscalls/swapon/libswapon.h
@@ -31,4 +31,10 @@
  */
 void make_swapfile(void (cleanup)(void), const char *swapfile);
 
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *ops,
+				const char *filename);
 #endif /* __LIBSWAPON_H__ */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status
  2019-05-28  4:39                                         ` [LTP] [PATCH v5 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
@ 2019-05-28  4:39                                           ` Murphy Zhou
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 4/4] syscalls/swapoff/swapoff01: " Murphy Zhou
  2 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28  4:39 UTC (permalink / raw)
  To: ltp

Of swap operations.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/swapon01.c |  9 +--------
 testcases/kernel/syscalls/swapon/swapon02.c |  9 +--------
 testcases/kernel/syscalls/swapon/swapon03.c | 11 ++---------
 3 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index 32538f82b..082a21f72 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -84,14 +84,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "swapon", "./tstswap");
 
 	make_swapfile(cleanup, "swapfile01");
 }
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..14bf4905d 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -132,14 +132,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "swapon", "./tstswap");
 
 	SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
 	make_swapfile(cleanup, "swapfile01");
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 955ac247b..62e67d677 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -153,7 +153,7 @@ static int setup_swap(void)
 	int j, fd;
 	int status;
 	int res = 0;
-	char filename[15];
+	char filename[FILENAME_MAX];
 	char buf[BUFSIZ + 1];
 
 	/* Find out how many swapfiles (1 line per entry) already exist */
@@ -333,14 +333,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "swapon", "./tstswap");
 
 	TEST_PAUSE;
 }
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 4/4] syscalls/swapoff/swapoff01: use helper to check support status
  2019-05-28  4:39                                         ` [LTP] [PATCH v5 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status Murphy Zhou
@ 2019-05-28  4:39                                           ` Murphy Zhou
  2 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28  4:39 UTC (permalink / raw)
  To: ltp

Of swap operations. Change Makefile to use functions from
../swapon/libswapon.c

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapoff/Makefile     |  3 ++-
 testcases/kernel/syscalls/swapoff/Makefile.inc |  6 ++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c  | 10 ++--------
 3 files changed, 10 insertions(+), 9 deletions(-)
 create mode 100644 testcases/kernel/syscalls/swapoff/Makefile.inc

diff --git a/testcases/kernel/syscalls/swapoff/Makefile b/testcases/kernel/syscalls/swapoff/Makefile
index bd617d806..536b2dbac 100644
--- a/testcases/kernel/syscalls/swapoff/Makefile
+++ b/testcases/kernel/syscalls/swapoff/Makefile
@@ -19,5 +19,6 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-
+include $(abs_srcdir)/./Makefile.inc
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
+$(MAKE_TARGETS): %: %.o ../swapon/libswapon.o
diff --git a/testcases/kernel/syscalls/swapoff/Makefile.inc b/testcases/kernel/syscalls/swapoff/Makefile.inc
new file mode 100644
index 000000000..65350cbeb
--- /dev/null
+++ b/testcases/kernel/syscalls/swapoff/Makefile.inc
@@ -0,0 +1,6 @@
+LIBDIR			+= ../swapon/
+LIBSWAPON		:= $(LIBDIR)/libswapon.o
+$(LIBSWAPON):
+	$(MAKE) -C $(LIBDIR)
+CPPFLAGS		+= -I$(abs_srcdir)/$(LIBDIR)
+LDFLAGS			+= -L$(abs_builddir)/$(LIBDIR)
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index a63e661a5..79e48c6ac 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include "config.h"
 #include "lapi/syscalls.h"
+#include "../swapon/libswapon.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -86,14 +87,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "swapoff", "./tstswap");
 
 	if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
 		tst_brkm(TBROK, cleanup,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28  4:39                                           ` [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
@ 2019-05-28  5:56                                             ` Amir Goldstein
  2019-05-28  8:33                                               ` Murphy Zhou
  2019-05-28  9:56                                               ` Murphy Zhou
  0 siblings, 2 replies; 55+ messages in thread
From: Amir Goldstein @ 2019-05-28  5:56 UTC (permalink / raw)
  To: ltp

On Tue, May 28, 2019 at 7:40 AM Murphy Zhou <xzhou@redhat.com> wrote:
>
> To check if the filesystem we are testing on supports swapon/swapoff
> operations. Keep NFS and TMPFS on the white list. Don't report fail
> if BTRFS fails with EINVAL.

Changes look very good, but I don't think you need the whitelist anymore...

>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> ---
>  testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++
>  testcases/kernel/syscalls/swapon/libswapon.h |  6 +++
>  2 files changed, 62 insertions(+)
>
> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
> index cf6a98891..e02fdd4ad 100644
> --- a/testcases/kernel/syscalls/swapon/libswapon.c
> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> @@ -19,6 +19,8 @@
>   *
>   */
>
> +#include <errno.h>
> +#include "lapi/syscalls.h"
>  #include "test.h"
>  #include "libswapon.h"
>
> @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
>
>         tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
>  }
> +
> +/*
> + * Check swapon/swapoff support status of filesystems or files
> + * we are testing on.
> + */
> +void is_swap_supported(void (cleanup)(void), const char *ops,
> +                               const char *filename)
> +{
> +       int fibmap = tst_fibmap(filename);
> +       long fs_type = tst_fs_type(cleanup, filename);
> +       const char *fstype = tst_fs_type_name(fs_type);
> +
> +       /* whitelist legacy fs */
> +       switch (fs_type) {
> +       case TST_NFS_MAGIC:
> +       case TST_TMPFS_MAGIC:
> +               tst_brkm(TCONF, cleanup,
> +                        "Cannot do %s on a file on %s filesystem",
> +                        ops, fstype);
> +       break;
> +       }

If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case
and result in tst_brkm(TCONF anyway.

> +
> +       make_swapfile(NULL, filename);
> +
> +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> +
> +       if (TEST_RETURN == -1) {
> +               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {

If you replace (fs_type == TST_BTRFS_MAGIC) with (fibmap != 0)
then NFS swapfile support could be tested as well and you do not
special case any filesystem.


> +                       tst_brkm(TCONF, cleanup,
> +                               "Swapfile on BTRFS not implemented");
> +               } else {
> +                       if (fibmap == 0) {

and then you don't need this extra test.

> +                               tst_brkm(TFAIL | TERRNO, cleanup,
> +                                        "swapon on %s failed", fstype);
> +                       } else {
> +                               tst_brkm(TCONF, cleanup,
> +                                        "swapon on %s is not supported",
> +                                               fstype);
> +                       }
> +               }
> +       }
> +
> +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> +
> +       if (TEST_RETURN == -1) {
> +               if (fibmap == 0) {
> +                       tst_brkm(TFAIL | TERRNO, cleanup,
> +                               "swapoff on %s failed", fstype);
> +               } else {
> +                       tst_brkm(TCONF, cleanup,
> +                                "swapoff on %s is not supported", fstype);
> +               }

I don't think there should be any TCONF here.
If we reached here then swapon is supported - in that case
failure to swapoff is a real failure.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28  5:56                                             ` Amir Goldstein
@ 2019-05-28  8:33                                               ` Murphy Zhou
  2019-05-28  9:56                                               ` Murphy Zhou
  1 sibling, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28  8:33 UTC (permalink / raw)
  To: ltp

On Tue, May 28, 2019 at 08:56:06AM +0300, Amir Goldstein wrote:
> On Tue, May 28, 2019 at 7:40 AM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > To check if the filesystem we are testing on supports swapon/swapoff
> > operations. Keep NFS and TMPFS on the white list. Don't report fail
> > if BTRFS fails with EINVAL.
> 
> Changes look very good, but I don't think you need the whitelist anymore...
> 
> >
> > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > ---
> >  testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++
> >  testcases/kernel/syscalls/swapon/libswapon.h |  6 +++
> >  2 files changed, 62 insertions(+)
> >
> > diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
> > index cf6a98891..e02fdd4ad 100644
> > --- a/testcases/kernel/syscalls/swapon/libswapon.c
> > +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> > @@ -19,6 +19,8 @@
> >   *
> >   */
> >
> > +#include <errno.h>
> > +#include "lapi/syscalls.h"
> >  #include "test.h"
> >  #include "libswapon.h"
> >
> > @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
> >
> >         tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> >  }
> > +
> > +/*
> > + * Check swapon/swapoff support status of filesystems or files
> > + * we are testing on.
> > + */
> > +void is_swap_supported(void (cleanup)(void), const char *ops,
> > +                               const char *filename)
> > +{
> > +       int fibmap = tst_fibmap(filename);
> > +       long fs_type = tst_fs_type(cleanup, filename);
> > +       const char *fstype = tst_fs_type_name(fs_type);
> > +
> > +       /* whitelist legacy fs */
> > +       switch (fs_type) {
> > +       case TST_NFS_MAGIC:
> > +       case TST_TMPFS_MAGIC:
> > +               tst_brkm(TCONF, cleanup,
> > +                        "Cannot do %s on a file on %s filesystem",
> > +                        ops, fstype);
> > +       break;
> > +       }
> 
> If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case
> and result in tst_brkm(TCONF anyway.
> 
> > +
> > +       make_swapfile(NULL, filename);
> > +
> > +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> > +
> > +       if (TEST_RETURN == -1) {
> > +               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> 
> If you replace (fs_type == TST_BTRFS_MAGIC) with (fibmap != 0)
> then NFS swapfile support could be tested as well and you do not
> special case any filesystem.

Very good idea!

> 
> 
> > +                       tst_brkm(TCONF, cleanup,
> > +                               "Swapfile on BTRFS not implemented");
> > +               } else {
> > +                       if (fibmap == 0) {
> 
> and then you don't need this extra test.

Yes.

> 
> > +                               tst_brkm(TFAIL | TERRNO, cleanup,
> > +                                        "swapon on %s failed", fstype);
> > +                       } else {
> > +                               tst_brkm(TCONF, cleanup,
> > +                                        "swapon on %s is not supported",
> > +                                               fstype);
> > +                       }
> > +               }
> > +       }
> > +
> > +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> > +
> > +       if (TEST_RETURN == -1) {
> > +               if (fibmap == 0) {
> > +                       tst_brkm(TFAIL | TERRNO, cleanup,
> > +                               "swapoff on %s failed", fstype);
> > +               } else {
> > +                       tst_brkm(TCONF, cleanup,
> > +                                "swapoff on %s is not supported", fstype);
> > +               }
> 
> I don't think there should be any TCONF here.
> If we reached here then swapon is supported - in that case
> failure to swapoff is a real failure.

Hmm.. make perfect sense. I have felt this test here was a little odd..

Thanks!

I'll tests this more on different filesystems and then post again.

--
Murphy

> 
> Thanks,
> Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28  5:56                                             ` Amir Goldstein
  2019-05-28  8:33                                               ` Murphy Zhou
@ 2019-05-28  9:56                                               ` Murphy Zhou
  2019-05-28 11:59                                                 ` Amir Goldstein
  1 sibling, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28  9:56 UTC (permalink / raw)
  To: ltp

On Tue, May 28, 2019 at 08:56:06AM +0300, Amir Goldstein wrote:
> On Tue, May 28, 2019 at 7:40 AM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > To check if the filesystem we are testing on supports swapon/swapoff
> > operations. Keep NFS and TMPFS on the white list. Don't report fail
> > if BTRFS fails with EINVAL.
> 
> Changes look very good, but I don't think you need the whitelist anymore...
> 
> >
> > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > ---
> >  testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++
> >  testcases/kernel/syscalls/swapon/libswapon.h |  6 +++
> >  2 files changed, 62 insertions(+)
> >
> > diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
> > index cf6a98891..e02fdd4ad 100644
> > --- a/testcases/kernel/syscalls/swapon/libswapon.c
> > +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> > @@ -19,6 +19,8 @@
> >   *
> >   */
> >
> > +#include <errno.h>
> > +#include "lapi/syscalls.h"
> >  #include "test.h"
> >  #include "libswapon.h"
> >
> > @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
> >
> >         tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> >  }
> > +
> > +/*
> > + * Check swapon/swapoff support status of filesystems or files
> > + * we are testing on.
> > + */
> > +void is_swap_supported(void (cleanup)(void), const char *ops,
> > +                               const char *filename)
> > +{
> > +       int fibmap = tst_fibmap(filename);
> > +       long fs_type = tst_fs_type(cleanup, filename);
> > +       const char *fstype = tst_fs_type_name(fs_type);
> > +
> > +       /* whitelist legacy fs */
> > +       switch (fs_type) {
> > +       case TST_NFS_MAGIC:
> > +       case TST_TMPFS_MAGIC:
> > +               tst_brkm(TCONF, cleanup,
> > +                        "Cannot do %s on a file on %s filesystem",
> > +                        ops, fstype);
> > +       break;
> > +       }
> 
> If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case
> and result in tst_brkm(TCONF anyway.
> 
> > +
> > +       make_swapfile(NULL, filename);
> > +
> > +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> > +
> > +       if (TEST_RETURN == -1) {
> > +               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> 
> If you replace (fs_type == TST_BTRFS_MAGIC) with (fibmap != 0)
> then NFS swapfile support could be tested as well and you do not
> special case any filesystem.

There is a surprise that on old kernels, 2.6.32 based, this change
would TBROK whitelisted NFS TCONF while mkswap swapfiles.

TBROK on mkswap failure seems the right thing to do, but the whitelist
here intended to fix this false alarm.

I remember Li suggested that un-whitelist NFS would break old distros.
TMPFS is fine.

Maybe we should safely check if mkswap is doable before checking swapon?
mkswap fail, fibmap fail --> tst_brk TCONF
mkswap fail, fibmap pass --> tst_brk TFAIL

Thanks,
Murphy
> 
> 
> > +                       tst_brkm(TCONF, cleanup,
> > +                               "Swapfile on BTRFS not implemented");
> > +               } else {
> > +                       if (fibmap == 0) {
> 
> and then you don't need this extra test.
> 
> > +                               tst_brkm(TFAIL | TERRNO, cleanup,
> > +                                        "swapon on %s failed", fstype);
> > +                       } else {
> > +                               tst_brkm(TCONF, cleanup,
> > +                                        "swapon on %s is not supported",
> > +                                               fstype);
> > +                       }
> > +               }
> > +       }
> > +
> > +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> > +
> > +       if (TEST_RETURN == -1) {
> > +               if (fibmap == 0) {
> > +                       tst_brkm(TFAIL | TERRNO, cleanup,
> > +                               "swapoff on %s failed", fstype);
> > +               } else {
> > +                       tst_brkm(TCONF, cleanup,
> > +                                "swapoff on %s is not supported", fstype);
> > +               }
> 
> I don't think there should be any TCONF here.
> If we reached here then swapon is supported - in that case
> failure to swapoff is a real failure.
> 
> Thanks,
> Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28  9:56                                               ` Murphy Zhou
@ 2019-05-28 11:59                                                 ` Amir Goldstein
  2019-05-28 14:12                                                   ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Amir Goldstein @ 2019-05-28 11:59 UTC (permalink / raw)
  To: ltp

On Tue, May 28, 2019 at 12:56 PM Murphy Zhou <xzhou@redhat.com> wrote:
>
> On Tue, May 28, 2019 at 08:56:06AM +0300, Amir Goldstein wrote:
> > On Tue, May 28, 2019 at 7:40 AM Murphy Zhou <xzhou@redhat.com> wrote:
> > >
> > > To check if the filesystem we are testing on supports swapon/swapoff
> > > operations. Keep NFS and TMPFS on the white list. Don't report fail
> > > if BTRFS fails with EINVAL.
> >
> > Changes look very good, but I don't think you need the whitelist anymore...
> >
> > >
> > > Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > ---
> > >  testcases/kernel/syscalls/swapon/libswapon.c | 56 ++++++++++++++++++++
> > >  testcases/kernel/syscalls/swapon/libswapon.h |  6 +++
> > >  2 files changed, 62 insertions(+)
> > >
> > > diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
> > > index cf6a98891..e02fdd4ad 100644
> > > --- a/testcases/kernel/syscalls/swapon/libswapon.c
> > > +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> > > @@ -19,6 +19,8 @@
> > >   *
> > >   */
> > >
> > > +#include <errno.h>
> > > +#include "lapi/syscalls.h"
> > >  #include "test.h"
> > >  #include "libswapon.h"
> > >
> > > @@ -47,3 +49,57 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
> > >
> > >         tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> > >  }
> > > +
> > > +/*
> > > + * Check swapon/swapoff support status of filesystems or files
> > > + * we are testing on.
> > > + */
> > > +void is_swap_supported(void (cleanup)(void), const char *ops,
> > > +                               const char *filename)
> > > +{
> > > +       int fibmap = tst_fibmap(filename);
> > > +       long fs_type = tst_fs_type(cleanup, filename);
> > > +       const char *fstype = tst_fs_type_name(fs_type);
> > > +
> > > +       /* whitelist legacy fs */
> > > +       switch (fs_type) {
> > > +       case TST_NFS_MAGIC:
> > > +       case TST_TMPFS_MAGIC:
> > > +               tst_brkm(TCONF, cleanup,
> > > +                        "Cannot do %s on a file on %s filesystem",
> > > +                        ops, fstype);
> > > +       break;
> > > +       }
> >
> > If you remove this whitelist, then NFS,tmpfs will reach the fiemap != 0 case
> > and result in tst_brkm(TCONF anyway.
> >
> > > +
> > > +       make_swapfile(NULL, filename);
> > > +
> > > +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> > > +
> > > +       if (TEST_RETURN == -1) {
> > > +               if (fs_type == TST_BTRFS_MAGIC && errno == EINVAL) {
> >
> > If you replace (fs_type == TST_BTRFS_MAGIC) with (fibmap != 0)
> > then NFS swapfile support could be tested as well and you do not
> > special case any filesystem.
>
> There is a surprise that on old kernels, 2.6.32 based, this change
> would TBROK whitelisted NFS TCONF while mkswap swapfiles.
>
> TBROK on mkswap failure seems the right thing to do, but the whitelist
> here intended to fix this false alarm.
>
> I remember Li suggested that un-whitelist NFS would break old distros.
> TMPFS is fine.
>
> Maybe we should safely check if mkswap is doable before checking swapon?
> mkswap fail, fibmap fail --> tst_brk TCONF
> mkswap fail, fibmap pass --> tst_brk TFAIL
>

Makes sense to me.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap
  2019-05-28 11:59                                                 ` Amir Goldstein
@ 2019-05-28 14:12                                                   ` Murphy Zhou
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
                                                                       ` (4 more replies)
  0 siblings, 5 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28 14:12 UTC (permalink / raw)
  To: ltp

To check if FIBMAP ioctl is supported on the filesystem we are
testing on. It also can check the support status of specific
files, but that may not needed for now.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
v6:
  Modify make_swapfile() to check mkswap support status safely
  Remove whitelist
  Remove BTRFS EINVAL check
  Check mkswap status before testing swapon in helper
  If swapon pass, following swapoff failure will fail the whole test and break
  Also modify swapoff02 to remove whitelist completely
v5:
  Split to 4 patches
  Only take one filename parameter in tst_fibmap
  Add helper is_swap_supported to check swap operation support status
  Test fibmap/swapon and swapoff operation in the helper
  Keep NFS/TMPFS whitelist
  Keep BTRFS EINVAL handling logic, except above 2 situation:
    if swapon fails and fibmap is not supported, tst_brk with TCONF
    if swapon fails and fibmap is supported, tst_brk with TFAIL
  If swapon test pass in the helper, test swapoff similarly
  Put is_swap_supported helper in libswapon, link swapoff binaries to it
  Mute a sprintf filaname wanrning by the way
v4:
  Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
  Fix fs_type undeclared in swapoff01.c
v2:
  Test FIBMAP instead of fstype whitelist

 include/tst_fs.h |  5 +++++
 lib/tst_ioctl.c  | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 lib/tst_ioctl.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index ebca065c6..6d03371ec 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);
  */
 void tst_fill_fs(const char *path, int verbose);
 
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(const char *filename);
+
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
 {
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
new file mode 100644
index 000000000..38aa937db
--- /dev/null
+++ b/lib/tst_ioctl.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(const char *filename)
+{
+	/* test if FIBMAP ioctl is supported */
+	int fd, block = 0;
+
+	fd = open(filename, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		tst_res(TWARN | TERRNO,
+			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
+		return 1;
+	}
+
+	if (ioctl(fd, FIBMAP, &block)) {
+		tst_res(TINFO, "FIBMAP ioctl is NOT supported");
+		close(fd);
+		return 1;
+	}
+	tst_res(TINFO, "FIBMAP ioctl is supported");
+
+	if (close(fd)) {
+		tst_res(TWARN | TERRNO, "close(fd) failed");
+		return 1;
+	}
+	return 0;
+}
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28 14:12                                                   ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
@ 2019-05-28 14:12                                                     ` Murphy Zhou
  2019-05-28 14:52                                                       ` Amir Goldstein
  2019-06-05  5:51                                                       ` Li Wang
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status Murphy Zhou
                                                                       ` (3 subsequent siblings)
  4 siblings, 2 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28 14:12 UTC (permalink / raw)
  To: ltp

To check if the filesystem we are testing on supports FIBMAP, mkswap,
swapon and swapoff operations.
Modify make_swapfile function to test mkswap support status safely.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-
 testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
index cf6a98891..f66d19548 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.c
+++ b/testcases/kernel/syscalls/swapon/libswapon.c
@@ -19,13 +19,15 @@
  *
  */
 
+#include <errno.h>
+#include "lapi/syscalls.h"
 #include "test.h"
 #include "libswapon.h"
 
 /*
  * Make a swap file
  */
-void make_swapfile(void (cleanup)(void), const char *swapfile)
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)
 {
 	if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
 	    TST_BYTES)) {
@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
 	argv[1] = swapfile;
 	argv[2] = NULL;
 
-	tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
+	return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);
+}
+
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *filename)
+{
+	int fibmap = tst_fibmap(filename);
+	long fs_type = tst_fs_type(cleanup, filename);
+	const char *fstype = tst_fs_type_name(fs_type);
+
+	int ret = make_swapfile(NULL, filename, 1);
+	if (ret != 0) {
+		if (fibmap != 0) {
+			tst_brkm(TCONF, cleanup,
+				"mkswap on %s not supported", fstype);
+		} else {
+			tst_brkm(TFAIL, cleanup,
+				"mkswap on %s failed", fstype);
+		}
+	}
+
+	TEST(ltp_syscall(__NR_swapon, filename, 0));
+	if (TEST_RETURN == -1) {
+		if (fibmap != 0 && errno == EINVAL) {
+			tst_brkm(TCONF, cleanup,
+				"Swapfile on %s not implemented", fstype);
+		} else {
+			tst_brkm(TFAIL | TERRNO, cleanup,
+				 "swapon on %s failed", fstype);
+		}
+	}
+
+	TEST(ltp_syscall(__NR_swapoff, filename, 0));
+	if (TEST_RETURN == -1) {
+		tst_brkm(TFAIL | TERRNO, cleanup,
+			"swapoff on %s failed", fstype);
+	}
 }
diff --git a/testcases/kernel/syscalls/swapon/libswapon.h b/testcases/kernel/syscalls/swapon/libswapon.h
index 7f7211eb4..a51833ec1 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.h
+++ b/testcases/kernel/syscalls/swapon/libswapon.h
@@ -29,6 +29,11 @@
 /*
  * Make a swap file
  */
-void make_swapfile(void (cleanup)(void), const char *swapfile);
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);
 
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *filename);
 #endif /* __LIBSWAPON_H__ */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status
  2019-05-28 14:12                                                   ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
@ 2019-05-28 14:12                                                     ` Murphy Zhou
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 4/4] syscalls/swapoff/swapoff0{1, 2}: " Murphy Zhou
                                                                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28 14:12 UTC (permalink / raw)
  To: ltp

Of swap operations.

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/swapon01.c | 11 ++---------
 testcases/kernel/syscalls/swapon/swapon02.c | 13 +++----------
 testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++-----------
 3 files changed, 9 insertions(+), 30 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index 32538f82b..f95ce0ab2 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -84,16 +84,9 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
-	make_swapfile(cleanup, "swapfile01");
+	make_swapfile(cleanup, "swapfile01", 0);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..3d49d0c6b 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -132,18 +132,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
-	make_swapfile(cleanup, "swapfile01");
-	make_swapfile(cleanup, "alreadyused");
+	make_swapfile(cleanup, "swapfile01", 0);
+	make_swapfile(cleanup, "alreadyused", 0);
 
 	if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
 		if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 955ac247b..cef57150c 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -153,7 +153,7 @@ static int setup_swap(void)
 	int j, fd;
 	int status;
 	int res = 0;
-	char filename[15];
+	char filename[FILENAME_MAX];
 	char buf[BUFSIZ + 1];
 
 	/* Find out how many swapfiles (1 line per entry) already exist */
@@ -210,7 +210,7 @@ static int setup_swap(void)
 			}
 
 			/* Create the swapfile */
-			make_swapfile(cleanup, filename);
+			make_swapfile(cleanup, filename, 0);
 
 			/* turn on the swap file */
 			res = ltp_syscall(__NR_swapon, filename, 0);
@@ -246,7 +246,7 @@ static int setup_swap(void)
 
 	/* Create all needed extra swapfiles for testing */
 	for (j = 0; j < testfiles; j++)
-		make_swapfile(cleanup, swap_testfiles[j].filename);
+		make_swapfile(cleanup, swap_testfiles[j].filename, 0);
 
 	return 0;
 
@@ -333,14 +333,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	TEST_PAUSE;
 }
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 4/4] syscalls/swapoff/swapoff0{1, 2}: use helper to check support status
  2019-05-28 14:12                                                   ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status Murphy Zhou
@ 2019-05-28 14:12                                                     ` Murphy Zhou
  2019-06-05  4:44                                                     ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
  2019-06-05  5:40                                                     ` Li Wang
  4 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-05-28 14:12 UTC (permalink / raw)
  To: ltp

Of swap operations. Change Makefile to use functions from
../swapon/libswapon.c

Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapoff/Makefile     |  3 ++-
 testcases/kernel/syscalls/swapoff/Makefile.inc |  6 ++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c  | 10 ++--------
 testcases/kernel/syscalls/swapoff/swapoff02.c  |  9 +--------
 4 files changed, 11 insertions(+), 17 deletions(-)
 create mode 100644 testcases/kernel/syscalls/swapoff/Makefile.inc

diff --git a/testcases/kernel/syscalls/swapoff/Makefile b/testcases/kernel/syscalls/swapoff/Makefile
index bd617d806..536b2dbac 100644
--- a/testcases/kernel/syscalls/swapoff/Makefile
+++ b/testcases/kernel/syscalls/swapoff/Makefile
@@ -19,5 +19,6 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-
+include $(abs_srcdir)/./Makefile.inc
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
+$(MAKE_TARGETS): %: %.o ../swapon/libswapon.o
diff --git a/testcases/kernel/syscalls/swapoff/Makefile.inc b/testcases/kernel/syscalls/swapoff/Makefile.inc
new file mode 100644
index 000000000..65350cbeb
--- /dev/null
+++ b/testcases/kernel/syscalls/swapoff/Makefile.inc
@@ -0,0 +1,6 @@
+LIBDIR			+= ../swapon/
+LIBSWAPON		:= $(LIBDIR)/libswapon.o
+$(LIBSWAPON):
+	$(MAKE) -C $(LIBDIR)
+CPPFLAGS		+= -I$(abs_srcdir)/$(LIBDIR)
+LDFLAGS			+= -L$(abs_builddir)/$(LIBDIR)
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index a63e661a5..e115269c0 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include "config.h"
 #include "lapi/syscalls.h"
+#include "../swapon/libswapon.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -86,14 +87,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
 		tst_brkm(TBROK, cleanup,
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index b5c6312a1..a59aaaa06 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -138,14 +138,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
 		tst_brkm(TBROK, cleanup,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
@ 2019-05-28 14:52                                                       ` Amir Goldstein
  2019-06-05  5:51                                                       ` Li Wang
  1 sibling, 0 replies; 55+ messages in thread
From: Amir Goldstein @ 2019-05-28 14:52 UTC (permalink / raw)
  To: ltp

On Tue, May 28, 2019 at 5:12 PM Murphy Zhou <xzhou@redhat.com> wrote:
>
> To check if the filesystem we are testing on supports FIBMAP, mkswap,
> swapon and swapoff operations.
> Modify make_swapfile function to test mkswap support status safely.
>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>

Looks ok to me

> ---
>  testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-
>  testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
>  2 files changed, 49 insertions(+), 3 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
> index cf6a98891..f66d19548 100644
> --- a/testcases/kernel/syscalls/swapon/libswapon.c
> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> @@ -19,13 +19,15 @@
>   *
>   */
>
> +#include <errno.h>
> +#include "lapi/syscalls.h"
>  #include "test.h"
>  #include "libswapon.h"
>
>  /*
>   * Make a swap file
>   */
> -void make_swapfile(void (cleanup)(void), const char *swapfile)
> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)
>  {
>         if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
>             TST_BYTES)) {
> @@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
>         argv[1] = swapfile;
>         argv[2] = NULL;
>
> -       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> +       return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);
> +}
> +
> +/*
> + * Check swapon/swapoff support status of filesystems or files
> + * we are testing on.
> + */
> +void is_swap_supported(void (cleanup)(void), const char *filename)
> +{
> +       int fibmap = tst_fibmap(filename);
> +       long fs_type = tst_fs_type(cleanup, filename);
> +       const char *fstype = tst_fs_type_name(fs_type);
> +
> +       int ret = make_swapfile(NULL, filename, 1);
> +       if (ret != 0) {
> +               if (fibmap != 0) {
> +                       tst_brkm(TCONF, cleanup,
> +                               "mkswap on %s not supported", fstype);
> +               } else {
> +                       tst_brkm(TFAIL, cleanup,
> +                               "mkswap on %s failed", fstype);
> +               }
> +       }
> +
> +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> +       if (TEST_RETURN == -1) {
> +               if (fibmap != 0 && errno == EINVAL) {
> +                       tst_brkm(TCONF, cleanup,
> +                               "Swapfile on %s not implemented", fstype);
> +               } else {
> +                       tst_brkm(TFAIL | TERRNO, cleanup,
> +                                "swapon on %s failed", fstype);
> +               }
> +       }
> +
> +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> +       if (TEST_RETURN == -1) {
> +               tst_brkm(TFAIL | TERRNO, cleanup,
> +                       "swapoff on %s failed", fstype);
> +       }
>  }
> diff --git a/testcases/kernel/syscalls/swapon/libswapon.h b/testcases/kernel/syscalls/swapon/libswapon.h
> index 7f7211eb4..a51833ec1 100644
> --- a/testcases/kernel/syscalls/swapon/libswapon.h
> +++ b/testcases/kernel/syscalls/swapon/libswapon.h
> @@ -29,6 +29,11 @@
>  /*
>   * Make a swap file
>   */
> -void make_swapfile(void (cleanup)(void), const char *swapfile);
> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);
>
> +/*
> + * Check swapon/swapoff support status of filesystems or files
> + * we are testing on.
> + */
> +void is_swap_supported(void (cleanup)(void), const char *filename);
>  #endif /* __LIBSWAPON_H__ */
> --
> 2.21.0
>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap
  2019-05-28 14:12                                                   ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
                                                                       ` (2 preceding siblings ...)
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 4/4] syscalls/swapoff/swapoff0{1, 2}: " Murphy Zhou
@ 2019-06-05  4:44                                                     ` Murphy Zhou
  2019-06-05  5:40                                                     ` Li Wang
  4 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-05  4:44 UTC (permalink / raw)
  To: ltp

Ping on this one.

Thanks~

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

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap
  2019-05-28 14:12                                                   ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
                                                                       ` (3 preceding siblings ...)
  2019-06-05  4:44                                                     ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
@ 2019-06-05  5:40                                                     ` Li Wang
  4 siblings, 0 replies; 55+ messages in thread
From: Li Wang @ 2019-06-05  5:40 UTC (permalink / raw)
  To: ltp

On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <xzhou@redhat.com> wrote:

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

what about return -1 here?  Calling this tst_fibmap() in otherplace, we
don't know that
the reruened 1 means a open/close() fail or FIBMAP ioctl is NOT supported.

> +       }
> +
> +       if (ioctl(fd, FIBMAP, &block)) {
> +               tst_res(TINFO, "FIBMAP ioctl is NOT supported");
> +               close(fd);
> +               return 1;
> +       }
> +       tst_res(TINFO, "FIBMAP ioctl is supported");
> +
> +       if (close(fd)) {
> +               tst_res(TWARN | TERRNO, "close(fd) failed");
> +               return 1;
>

return -1;

> +       }
> +       return 0;
> +}
> --
> 2.21.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/f14123bf/attachment.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-05-28 14:12                                                     ` [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
  2019-05-28 14:52                                                       ` Amir Goldstein
@ 2019-06-05  5:51                                                       ` Li Wang
  2019-06-05  6:55                                                         ` Li Wang
  1 sibling, 1 reply; 55+ messages in thread
From: Li Wang @ 2019-06-05  5:51 UTC (permalink / raw)
  To: ltp

On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <xzhou@redhat.com> wrote:

> To check if the filesystem we are testing on supports FIBMAP, mkswap,
> swapon and swapoff operations.
> Modify make_swapfile function to test mkswap support status safely.
>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> ---
>  testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-
>  testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
>  2 files changed, 49 insertions(+), 3 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c
> b/testcases/kernel/syscalls/swapon/libswapon.c
> index cf6a98891..f66d19548 100644
> --- a/testcases/kernel/syscalls/swapon/libswapon.c
> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> @@ -19,13 +19,15 @@
>   *
>   */
>
> +#include <errno.h>
> +#include "lapi/syscalls.h"
>  #include "test.h"
>  #include "libswapon.h"
>
>  /*
>   * Make a swap file
>   */
> -void make_swapfile(void (cleanup)(void), const char *swapfile)
> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)
>  {
>         if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
>             TST_BYTES)) {
> @@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char
> *swapfile)
>         argv[1] = swapfile;
>         argv[2] = NULL;
>
> -       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> +       return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);
> +}
> +
> +/*
> + * Check swapon/swapoff support status of filesystems or files
> + * we are testing on.
> + */
> +void is_swap_supported(void (cleanup)(void), const char *filename)
> +{
> +       int fibmap = tst_fibmap(filename);
> +       long fs_type = tst_fs_type(cleanup, filename);
> +       const char *fstype = tst_fs_type_name(fs_type);
> +
> +       int ret = make_swapfile(NULL, filename, 1);
> +       if (ret != 0) {
> +               if (fibmap != 0) {
>

As I replied in patch 1/4, how do we know that means FIBMAP not support if
just verify fibmap != 0?
So I would suggest to make the return value of tst_fibmap() is more precise
and do if (fibmap == 1) check here.

+                       tst_brkm(TCONF, cleanup,
> +                               "mkswap on %s not supported", fstype);
> +               } else {
> +                       tst_brkm(TFAIL, cleanup,
> +                               "mkswap on %s failed", fstype);
> +               }
> +       }
> +
> +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> +       if (TEST_RETURN == -1) {
> +               if (fibmap != 0 && errno == EINVAL) {
> +                       tst_brkm(TCONF, cleanup,
> +                               "Swapfile on %s not implemented", fstype);
>

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?



> +               } else {
> +                       tst_brkm(TFAIL | TERRNO, cleanup,
> +                                "swapon on %s failed", fstype);
> +               }
> +       }
> +
> +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> +       if (TEST_RETURN == -1) {
> +               tst_brkm(TFAIL | TERRNO, cleanup,
> +                       "swapoff on %s failed", fstype);
> +       }
>  }
> diff --git a/testcases/kernel/syscalls/swapon/libswapon.h
> b/testcases/kernel/syscalls/swapon/libswapon.h
> index 7f7211eb4..a51833ec1 100644
> --- a/testcases/kernel/syscalls/swapon/libswapon.h
> +++ b/testcases/kernel/syscalls/swapon/libswapon.h
> @@ -29,6 +29,11 @@
>  /*
>   * Make a swap file
>   */
> -void make_swapfile(void (cleanup)(void), const char *swapfile);
> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);
>
> +/*
> + * Check swapon/swapoff support status of filesystems or files
> + * we are testing on.
> + */
> +void is_swap_supported(void (cleanup)(void), const char *filename);
>  #endif /* __LIBSWAPON_H__ */
> --
> 2.21.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/a95a5d46/attachment.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-06-05  5:51                                                       ` Li Wang
@ 2019-06-05  6:55                                                         ` Li Wang
  2019-06-05  9:30                                                           ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Li Wang @ 2019-06-05  6:55 UTC (permalink / raw)
  To: ltp

On Wed, Jun 5, 2019 at 1:51 PM Li Wang <liwang@redhat.com> wrote:

>
>
> On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <xzhou@redhat.com> wrote:
>
>> To check if the filesystem we are testing on supports FIBMAP, mkswap,
>> swapon and swapoff operations.
>> Modify make_swapfile function to test mkswap support status safely.
>>
>> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
>> ---
>>  testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-
>>  testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
>>  2 files changed, 49 insertions(+), 3 deletions(-)
>>
>> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c
>> b/testcases/kernel/syscalls/swapon/libswapon.c
>> index cf6a98891..f66d19548 100644
>> --- a/testcases/kernel/syscalls/swapon/libswapon.c
>> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
>> @@ -19,13 +19,15 @@
>>   *
>>   */
>>
>> +#include <errno.h>
>> +#include "lapi/syscalls.h"
>>  #include "test.h"
>>  #include "libswapon.h"
>>
>>  /*
>>   * Make a swap file
>>   */
>> -void make_swapfile(void (cleanup)(void), const char *swapfile)
>> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)
>>  {
>>         if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
>>             TST_BYTES)) {
>> @@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char
>> *swapfile)
>>         argv[1] = swapfile;
>>         argv[2] = NULL;
>>
>> -       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
>> +       return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);
>> +}
>> +
>> +/*
>> + * Check swapon/swapoff support status of filesystems or files
>> + * we are testing on.
>> + */
>> +void is_swap_supported(void (cleanup)(void), const char *filename)
>> +{
>> +       int fibmap = tst_fibmap(filename);
>> +       long fs_type = tst_fs_type(cleanup, filename);
>> +       const char *fstype = tst_fs_type_name(fs_type);
>> +
>> +       int ret = make_swapfile(NULL, filename, 1);
>> +       if (ret != 0) {
>> +               if (fibmap != 0) {
>>
>
> As I replied in patch 1/4, how do we know that means FIBMAP not support if
> just verify fibmap != 0?
> So I would suggest to make the return value of tst_fibmap() is more
> precise and do if (fibmap == 1) check here.
>

And also, imagine that if swapon01 test failed on BRTFS or NFS(support
swapfile but not
support FIBMAP ioctl), then here will report the new bug as a TCONF to LTP.


> +                       tst_brkm(TCONF, cleanup,
>> +                               "mkswap on %s not supported", fstype);
>> +               } else {
>> +                       tst_brkm(TFAIL, cleanup,
>> +                               "mkswap on %s failed", fstype);
>> +               }
>> +       }
>> +
>> +       TEST(ltp_syscall(__NR_swapon, filename, 0));
>> +       if (TEST_RETURN == -1) {
>> +               if (fibmap != 0 && errno == EINVAL) {
>> +                       tst_brkm(TCONF, cleanup,
>> +                               "Swapfile on %s not implemented", fstype);
>>
>
> 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?
>
>
>
>> +               } else {
>> +                       tst_brkm(TFAIL | TERRNO, cleanup,
>> +                                "swapon on %s failed", fstype);
>> +               }
>> +       }
>> +
>> +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
>> +       if (TEST_RETURN == -1) {
>> +               tst_brkm(TFAIL | TERRNO, cleanup,
>> +                       "swapoff on %s failed", fstype);
>> +       }
>>  }
>> diff --git a/testcases/kernel/syscalls/swapon/libswapon.h
>> b/testcases/kernel/syscalls/swapon/libswapon.h
>> index 7f7211eb4..a51833ec1 100644
>> --- a/testcases/kernel/syscalls/swapon/libswapon.h
>> +++ b/testcases/kernel/syscalls/swapon/libswapon.h
>> @@ -29,6 +29,11 @@
>>  /*
>>   * Make a swap file
>>   */
>> -void make_swapfile(void (cleanup)(void), const char *swapfile);
>> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);
>>
>> +/*
>> + * Check swapon/swapoff support status of filesystems or files
>> + * we are testing on.
>> + */
>> +void is_swap_supported(void (cleanup)(void), const char *filename);
>>  #endif /* __LIBSWAPON_H__ */
>> --
>> 2.21.0
>>
>>
>> --
>> Mailing list info: https://lists.linux.it/listinfo/ltp
>>
>
>
> --
> Regards,
> Li Wang
>


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/0d333ce9/attachment.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-06-05  6:55                                                         ` Li Wang
@ 2019-06-05  9:30                                                           ` Murphy Zhou
  2019-06-05  9:53                                                             ` Li Wang
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-06-05  9:30 UTC (permalink / raw)
  To: ltp

On Wed, Jun 05, 2019 at 02:55:47PM +0800, Li Wang wrote:
> On Wed, Jun 5, 2019 at 1:51 PM Li Wang <liwang@redhat.com> wrote:
> 
> >
> >
> > On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> >> To check if the filesystem we are testing on supports FIBMAP, mkswap,
> >> swapon and swapoff operations.
> >> Modify make_swapfile function to test mkswap support status safely.
> >>
> >> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> >> ---
> >>  testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-
> >>  testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
> >>  2 files changed, 49 insertions(+), 3 deletions(-)
> >>
> >> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c
> >> b/testcases/kernel/syscalls/swapon/libswapon.c
> >> index cf6a98891..f66d19548 100644
> >> --- a/testcases/kernel/syscalls/swapon/libswapon.c
> >> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> >> @@ -19,13 +19,15 @@
> >>   *
> >>   */
> >>
> >> +#include <errno.h>
> >> +#include "lapi/syscalls.h"
> >>  #include "test.h"
> >>  #include "libswapon.h"
> >>
> >>  /*
> >>   * Make a swap file
> >>   */
> >> -void make_swapfile(void (cleanup)(void), const char *swapfile)
> >> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)
> >>  {
> >>         if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
> >>             TST_BYTES)) {
> >> @@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char
> >> *swapfile)
> >>         argv[1] = swapfile;
> >>         argv[2] = NULL;
> >>
> >> -       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> >> +       return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);
> >> +}
> >> +
> >> +/*
> >> + * Check swapon/swapoff support status of filesystems or files
> >> + * we are testing on.
> >> + */
> >> +void is_swap_supported(void (cleanup)(void), const char *filename)
> >> +{
> >> +       int fibmap = tst_fibmap(filename);
> >> +       long fs_type = tst_fs_type(cleanup, filename);
> >> +       const char *fstype = tst_fs_type_name(fs_type);
> >> +
> >> +       int ret = make_swapfile(NULL, filename, 1);
> >> +       if (ret != 0) {
> >> +               if (fibmap != 0) {
> >>
> >
> > As I replied in patch 1/4, how do we know that means FIBMAP not support if
> > just verify fibmap != 0?
> > So I would suggest to make the return value of tst_fibmap() is more
> > precise and do if (fibmap == 1) check here.

Very good catch. The return value should be more precise. Thanks!

> >
> 
> And also, imagine that if swapon01 test failed on BRTFS or NFS(support
> swapfile but not
> support FIBMAP ioctl), then here will report the new bug as a TCONF to LTP.

Here is testing mkswap for swapon test preparation. If mkswap fail, and
FIBMAP not supported, it's reasonable to me that we should not go on to
test swapon.

But yes, if a regression causes mkswap fail without FIBMAP supported, we
could miss the bug here like you described. This situation should be
covered by tcase for mkswap IMO.

I'm going to dig more on fibmap/mkswap/swapon/swapoff support status of
varies filesystems.

> 
> 
> > +                       tst_brkm(TCONF, cleanup,
> >> +                               "mkswap on %s not supported", fstype);
> >> +               } else {
> >> +                       tst_brkm(TFAIL, cleanup,
> >> +                               "mkswap on %s failed", fstype);
> >> +               }
> >> +       }
> >> +
> >> +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> >> +       if (TEST_RETURN == -1) {
> >> +               if (fibmap != 0 && errno == EINVAL) {
> >> +                       tst_brkm(TCONF, cleanup,
> >> +                               "Swapfile on %s not implemented", fstype);
> >>
> >
> > 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?

If mkswap succeeds, we are coming here.

Thanks for reviewing!
Murphy

> >
> >
> >
> >> +               } else {
> >> +                       tst_brkm(TFAIL | TERRNO, cleanup,
> >> +                                "swapon on %s failed", fstype);
> >> +               }
> >> +       }
> >> +
> >> +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> >> +       if (TEST_RETURN == -1) {
> >> +               tst_brkm(TFAIL | TERRNO, cleanup,
> >> +                       "swapoff on %s failed", fstype);
> >> +       }
> >>  }
> >> diff --git a/testcases/kernel/syscalls/swapon/libswapon.h
> >> b/testcases/kernel/syscalls/swapon/libswapon.h
> >> index 7f7211eb4..a51833ec1 100644
> >> --- a/testcases/kernel/syscalls/swapon/libswapon.h
> >> +++ b/testcases/kernel/syscalls/swapon/libswapon.h
> >> @@ -29,6 +29,11 @@
> >>  /*
> >>   * Make a swap file
> >>   */
> >> -void make_swapfile(void (cleanup)(void), const char *swapfile);
> >> +int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);
> >>
> >> +/*
> >> + * Check swapon/swapoff support status of filesystems or files
> >> + * we are testing on.
> >> + */
> >> +void is_swap_supported(void (cleanup)(void), const char *filename);
> >>  #endif /* __LIBSWAPON_H__ */
> >> --
> >> 2.21.0
> >>
> >>
> >> --
> >> Mailing list info: https://lists.linux.it/listinfo/ltp
> >>
> >
> >
> > --
> > Regards,
> > Li Wang
> >
> 
> 
> -- 
> Regards,
> Li Wang

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-06-05  9:30                                                           ` Murphy Zhou
@ 2019-06-05  9:53                                                             ` Li Wang
  2019-06-10  6:12                                                               ` Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Li Wang @ 2019-06-05  9:53 UTC (permalink / raw)
  To: ltp

On Wed, Jun 5, 2019 at 5:30 PM Murphy Zhou <xzhou@redhat.com> wrote:

> On Wed, Jun 05, 2019 at 02:55:47PM +0800, Li Wang wrote:
> > On Wed, Jun 5, 2019 at 1:51 PM Li Wang <liwang@redhat.com> wrote:
> >
> > >
> > >
> > > On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <xzhou@redhat.com> wrote:
> > >
> > >> To check if the filesystem we are testing on supports FIBMAP, mkswap,
> > >> swapon and swapoff operations.
> > >> Modify make_swapfile function to test mkswap support status safely.
> > >>
> > >> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > >> ---
> > >>  testcases/kernel/syscalls/swapon/libswapon.c | 45
> +++++++++++++++++++-
> > >>  testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
> > >>  2 files changed, 49 insertions(+), 3 deletions(-)
> > >>
> > >> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c
> > >> b/testcases/kernel/syscalls/swapon/libswapon.c
> > >> index cf6a98891..f66d19548 100644
> > >> --- a/testcases/kernel/syscalls/swapon/libswapon.c
> > >> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> > >> @@ -19,13 +19,15 @@
> > >>   *
> > >>   */
> > >>
> > >> +#include <errno.h>
> > >> +#include "lapi/syscalls.h"
> > >>  #include "test.h"
> > >>  #include "libswapon.h"
> > >>
> > >>  /*
> > >>   * Make a swap file
> > >>   */
> > >> -void make_swapfile(void (cleanup)(void), const char *swapfile)
> > >> +int make_swapfile(void (cleanup)(void), const char *swapfile, int
> safe)
> > >>  {
> > >>         if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
> > >>             TST_BYTES)) {
> > >> @@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char
> > >> *swapfile)
> > >>         argv[1] = swapfile;
> > >>         argv[2] = NULL;
> > >>
> > >> -       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> > >> +       return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null",
> safe);
> > >> +}
> > >> +
> > >> +/*
> > >> + * Check swapon/swapoff support status of filesystems or files
> > >> + * we are testing on.
> > >> + */
> > >> +void is_swap_supported(void (cleanup)(void), const char *filename)
> > >> +{
> > >> +       int fibmap = tst_fibmap(filename);
> > >> +       long fs_type = tst_fs_type(cleanup, filename);
> > >> +       const char *fstype = tst_fs_type_name(fs_type);
> > >> +
> > >> +       int ret = make_swapfile(NULL, filename, 1);
> > >> +       if (ret != 0) {
> > >> +               if (fibmap != 0) {
> > >>
> > >
> > > As I replied in patch 1/4, how do we know that means FIBMAP not
> support if
> > > just verify fibmap != 0?
> > > So I would suggest to make the return value of tst_fibmap() is more
> > > precise and do if (fibmap == 1) check here.
>
> Very good catch. The return value should be more precise. Thanks!
>
> > >
> >
> > And also, imagine that if swapon01 test failed on BRTFS or NFS(support
> > swapfile but not
> > support FIBMAP ioctl), then here will report the new bug as a TCONF to
> LTP.
>
> Here is testing mkswap for swapon test preparation. If mkswap fail, and
> FIBMAP not supported, it's reasonable to me that we should not go on to
> test swapon.
>
> But yes, if a regression causes mkswap fail without FIBMAP supported, we
> could miss the bug here like you described. This situation should be
> covered by tcase for mkswap IMO.
>

I'm thinking maybe we cann't avoid adding a whilelist in the test, at least
for known filesystem without FIBMAP supported.

FYI: what do you think if change the is_swap_supported(...) like this?

void is_swap_supported(void (cleanup)(void), const char *filename)
{
        int fibmap = tst_fibmap(filename);

        if (fibmap == 1) {
                int ret;
                long fs_type = tst_fs_type(cleanup, filename);
                const char *fstype = tst_fs_type_name(fs_type);

                ret = make_swapfile(NULL, filename, 1);
                if (ret != 0) {
                        if (fs_type == TST_NFS_MAGIC ||
                                fs_type == TST_TMPFS_MAGIC ||
                                fs_type == TST_BRTFS_MAGIC) {
                                tst_brkm(TFAIL, cleanup,
                                        "mkswap on %s failed", fstype);
                        } else {
                                tst_brkm(TCONF, cleanup,
                                        "mkswap on %s not supported",
fstype);
                        }
                }

                TEST(ltp_syscall(__NR_swapon, filename, 0));
                if (TEST_RETURN == -1) {
                        if (errno == EINVAL) {
                                tst_brkm(TCONF, cleanup,
                                         "Swapfile on %s not implemented",
fstype);
                        } else {
                                tst_brkm(TFAIL | TERRNO, cleanup,
                                         "swapon on %s failed", fstype);
                        }
                }

                TEST(ltp_syscall(__NR_swapoff, filename, 0));
                if (TEST_RETURN == -1) {
                        tst_brkm(TFAIL | TERRNO, cleanup,
                                "swapoff on %s failed", fstype);
                }
        }
}

>
> I'm going to dig more on fibmap/mkswap/swapon/swapoff support status of
> varies filesystems.
>
> >
> >
> > > +                       tst_brkm(TCONF, cleanup,
> > >> +                               "mkswap on %s not supported", fstype);
> > >> +               } else {
> > >> +                       tst_brkm(TFAIL, cleanup,
> > >> +                               "mkswap on %s failed", fstype);
> > >> +               }
> > >> +       }
> > >> +
> > >> +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> > >> +       if (TEST_RETURN == -1) {
> > >> +               if (fibmap != 0 && errno == EINVAL) {
> > >> +                       tst_brkm(TCONF, cleanup,
> > >> +                               "Swapfile on %s not implemented",
> fstype);
> > >>
> > >
> > > 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?
>
> If mkswap succeeds, we are coming here.
>

Ah yes. I missed that situation.

>
> Thanks for reviewing!
> Murphy
>
> > >
> > >
> > >
> > >> +               } else {
> > >> +                       tst_brkm(TFAIL | TERRNO, cleanup,
> > >> +                                "swapon on %s failed", fstype);
> > >> +               }
> > >> +       }
> > >> +
> > >> +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> > >> +       if (TEST_RETURN == -1) {
> > >> +               tst_brkm(TFAIL | TERRNO, cleanup,
> > >> +                       "swapoff on %s failed", fstype);
> > >> +       }
> > >>  }
> > >> diff --git a/testcases/kernel/syscalls/swapon/libswapon.h
> > >> b/testcases/kernel/syscalls/swapon/libswapon.h
> > >> index 7f7211eb4..a51833ec1 100644
> > >> --- a/testcases/kernel/syscalls/swapon/libswapon.h
> > >> +++ b/testcases/kernel/syscalls/swapon/libswapon.h
> > >> @@ -29,6 +29,11 @@
> > >>  /*
> > >>   * Make a swap file
> > >>   */
> > >> -void make_swapfile(void (cleanup)(void), const char *swapfile);
> > >> +int make_swapfile(void (cleanup)(void), const char *swapfile, int
> safe);
> > >>
> > >> +/*
> > >> + * Check swapon/swapoff support status of filesystems or files
> > >> + * we are testing on.
> > >> + */
> > >> +void is_swap_supported(void (cleanup)(void), const char *filename);
> > >>  #endif /* __LIBSWAPON_H__ */
> > >> --
> > >> 2.21.0
> > >>
> > >>
> > >> --
> > >> Mailing list info: https://lists.linux.it/listinfo/ltp
> > >>
> > >
> > >
> > > --
> > > Regards,
> > > Li Wang
> > >
> >
> >
> > --
> > Regards,
> > Li Wang
>


-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190605/d5d20df0/attachment-0001.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-06-05  9:53                                                             ` Li Wang
@ 2019-06-10  6:12                                                               ` Murphy Zhou
  2019-06-10  9:28                                                                 ` Li Wang
  0 siblings, 1 reply; 55+ messages in thread
From: Murphy Zhou @ 2019-06-10  6:12 UTC (permalink / raw)
  To: ltp

On Wed, Jun 05, 2019 at 05:53:13PM +0800, Li Wang wrote:
> On Wed, Jun 5, 2019 at 5:30 PM Murphy Zhou <xzhou@redhat.com> wrote:
> 
> > On Wed, Jun 05, 2019 at 02:55:47PM +0800, Li Wang wrote:
> > > On Wed, Jun 5, 2019 at 1:51 PM Li Wang <liwang@redhat.com> wrote:
> > >
> > > >
> > > >
> > > > On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <xzhou@redhat.com> wrote:
> > > >
> > > >> To check if the filesystem we are testing on supports FIBMAP, mkswap,
> > > >> swapon and swapoff operations.
> > > >> Modify make_swapfile function to test mkswap support status safely.
> > > >>
> > > >> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > >> ---
> > > >>  testcases/kernel/syscalls/swapon/libswapon.c | 45
> > +++++++++++++++++++-
> > > >>  testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
> > > >>  2 files changed, 49 insertions(+), 3 deletions(-)
> > > >>
> > > >> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c
> > > >> b/testcases/kernel/syscalls/swapon/libswapon.c
> > > >> index cf6a98891..f66d19548 100644
> > > >> --- a/testcases/kernel/syscalls/swapon/libswapon.c
> > > >> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> > > >> @@ -19,13 +19,15 @@
> > > >>   *
> > > >>   */
> > > >>
> > > >> +#include <errno.h>
> > > >> +#include "lapi/syscalls.h"
> > > >>  #include "test.h"
> > > >>  #include "libswapon.h"
> > > >>
> > > >>  /*
> > > >>   * Make a swap file
> > > >>   */
> > > >> -void make_swapfile(void (cleanup)(void), const char *swapfile)
> > > >> +int make_swapfile(void (cleanup)(void), const char *swapfile, int
> > safe)
> > > >>  {
> > > >>         if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
> > > >>             TST_BYTES)) {
> > > >> @@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char
> > > >> *swapfile)
> > > >>         argv[1] = swapfile;
> > > >>         argv[2] = NULL;
> > > >>
> > > >> -       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> > > >> +       return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null",
> > safe);
> > > >> +}
> > > >> +
> > > >> +/*
> > > >> + * Check swapon/swapoff support status of filesystems or files
> > > >> + * we are testing on.
> > > >> + */
> > > >> +void is_swap_supported(void (cleanup)(void), const char *filename)
> > > >> +{
> > > >> +       int fibmap = tst_fibmap(filename);
> > > >> +       long fs_type = tst_fs_type(cleanup, filename);
> > > >> +       const char *fstype = tst_fs_type_name(fs_type);
> > > >> +
> > > >> +       int ret = make_swapfile(NULL, filename, 1);
> > > >> +       if (ret != 0) {
> > > >> +               if (fibmap != 0) {
> > > >>
> > > >
> > > > As I replied in patch 1/4, how do we know that means FIBMAP not
> > support if
> > > > just verify fibmap != 0?
> > > > So I would suggest to make the return value of tst_fibmap() is more
> > > > precise and do if (fibmap == 1) check here.
> >
> > Very good catch. The return value should be more precise. Thanks!
> >
> > > >
> > >
> > > And also, imagine that if swapon01 test failed on BRTFS or NFS(support
> > > swapfile but not
> > > support FIBMAP ioctl), then here will report the new bug as a TCONF to
> > LTP.
> >
> > Here is testing mkswap for swapon test preparation. If mkswap fail, and
> > FIBMAP not supported, it's reasonable to me that we should not go on to
> > test swapon.
> >
> > But yes, if a regression causes mkswap fail without FIBMAP supported, we
> > could miss the bug here like you described. This situation should be
> > covered by tcase for mkswap IMO.
> >
> 
> I'm thinking maybe we cann't avoid adding a whilelist in the test, at least
> for known filesystem without FIBMAP supported.

No, I think we don't need a whilelist here. Amir and I discussed long way
to here, you can check that. We are not using fibmap test as a verdict for
swapfile is supported or not. Doing a mkswap/swapon/swapoff test before
real tests to detect the support situation. tst_fibmap result helps us
to decide how to report. If the underneath filesystem can survive these
test, it should be supporting swapfiles and swapon/swapoff tests should
run.

The whitelisted nfs and tmpfs are well covered by these pre-tests. More, 
NFS should not be skipped as if we turn on kernle configs for NFS_SWAP,
these tests can run on NFS.

Whitelist could skip more tests and bugs.

I tested some fibmap/mkswap/swapon/swapoff tests for your reference:

1 means positive, 0 means negative.

-------- On 5.3-rc3+ kernel, NFS_SWAP=y SUNRPC_SWAP=y -------
	fibamp	mkswap	swapon swapoff
xfs	1	1	1	1
ext4	1	1	1	1

btrfs	0	1	0	0
tmpfs	0	1	0	0

ovl	1	1	1	1

cifs
v3.11	0	1	0	0
v1	0	1	0	0
v2	0	1	0	0

nfs
v4.2	0	1	1*	1
v4.1	0	1	1	1
v4.0	0	1	1* 	1
v3	0	1	1	1

* hang sometimes

--------- On 3.10.0 based kernel ----------------
	fibamp	mkswap	swapon swapoff
xfs	1	1	1	1
ext4	1	1	1	1

btrfs	0	1	0	0
tmpfs	0	1	0	0

ovl	1	1	1	1

cifs
v3.0	0	1	0	0

nfs
v4.2	0	1	0	0


---------- On 2.6.32 based kernel ---------------
	fibamp	mkswap	swapon swapoff
tmpfs	0	1	0	0
xfs	1	1	1	1
ext4	1	1	1	1
cifs	0	0	0	0
nfs	0	0	0	0

> 
> FYI: what do you think if change the is_swap_supported(...) like this?
> 
> void is_swap_supported(void (cleanup)(void), const char *filename)
> {
>         int fibmap = tst_fibmap(filename);
> 
>         if (fibmap == 1) {

fibmap == 0 does not mean swapfile is supported. We need to make sure that
survivors of this function are supporting swapfiles.

Thanks,
Murphy

>                 int ret;
>                 long fs_type = tst_fs_type(cleanup, filename);
>                 const char *fstype = tst_fs_type_name(fs_type);
> 
>                 ret = make_swapfile(NULL, filename, 1);
>                 if (ret != 0) {
>                         if (fs_type == TST_NFS_MAGIC ||
>                                 fs_type == TST_TMPFS_MAGIC ||
>                                 fs_type == TST_BRTFS_MAGIC) {
>                                 tst_brkm(TFAIL, cleanup,
>                                         "mkswap on %s failed", fstype);
>                         } else {
>                                 tst_brkm(TCONF, cleanup,
>                                         "mkswap on %s not supported",
> fstype);
>                         }
>                 }
> 
>                 TEST(ltp_syscall(__NR_swapon, filename, 0));
>                 if (TEST_RETURN == -1) {
>                         if (errno == EINVAL) {
>                                 tst_brkm(TCONF, cleanup,
>                                          "Swapfile on %s not implemented",
> fstype);
>                         } else {
>                                 tst_brkm(TFAIL | TERRNO, cleanup,
>                                          "swapon on %s failed", fstype);
>                         }
>                 }
> 
>                 TEST(ltp_syscall(__NR_swapoff, filename, 0));
>                 if (TEST_RETURN == -1) {
>                         tst_brkm(TFAIL | TERRNO, cleanup,
>                                 "swapoff on %s failed", fstype);
>                 }
>         }
> }
> 
> >
> > I'm going to dig more on fibmap/mkswap/swapon/swapoff support status of
> > varies filesystems.
> >
> > >
> > >
> > > > +                       tst_brkm(TCONF, cleanup,
> > > >> +                               "mkswap on %s not supported", fstype);
> > > >> +               } else {
> > > >> +                       tst_brkm(TFAIL, cleanup,
> > > >> +                               "mkswap on %s failed", fstype);
> > > >> +               }
> > > >> +       }
> > > >> +
> > > >> +       TEST(ltp_syscall(__NR_swapon, filename, 0));
> > > >> +       if (TEST_RETURN == -1) {
> > > >> +               if (fibmap != 0 && errno == EINVAL) {
> > > >> +                       tst_brkm(TCONF, cleanup,
> > > >> +                               "Swapfile on %s not implemented",
> > fstype);
> > > >>
> > > >
> > > > 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?
> >
> > If mkswap succeeds, we are coming here.
> >
> 
> Ah yes. I missed that situation.
> 
> >
> > Thanks for reviewing!
> > Murphy
> >
> > > >
> > > >
> > > >
> > > >> +               } else {
> > > >> +                       tst_brkm(TFAIL | TERRNO, cleanup,
> > > >> +                                "swapon on %s failed", fstype);
> > > >> +               }
> > > >> +       }
> > > >> +
> > > >> +       TEST(ltp_syscall(__NR_swapoff, filename, 0));
> > > >> +       if (TEST_RETURN == -1) {
> > > >> +               tst_brkm(TFAIL | TERRNO, cleanup,
> > > >> +                       "swapoff on %s failed", fstype);
> > > >> +       }
> > > >>  }
> > > >> diff --git a/testcases/kernel/syscalls/swapon/libswapon.h
> > > >> b/testcases/kernel/syscalls/swapon/libswapon.h
> > > >> index 7f7211eb4..a51833ec1 100644
> > > >> --- a/testcases/kernel/syscalls/swapon/libswapon.h
> > > >> +++ b/testcases/kernel/syscalls/swapon/libswapon.h
> > > >> @@ -29,6 +29,11 @@
> > > >>  /*
> > > >>   * Make a swap file
> > > >>   */
> > > >> -void make_swapfile(void (cleanup)(void), const char *swapfile);
> > > >> +int make_swapfile(void (cleanup)(void), const char *swapfile, int
> > safe);
> > > >>
> > > >> +/*
> > > >> + * Check swapon/swapoff support status of filesystems or files
> > > >> + * we are testing on.
> > > >> + */
> > > >> +void is_swap_supported(void (cleanup)(void), const char *filename);
> > > >>  #endif /* __LIBSWAPON_H__ */
> > > >> --
> > > >> 2.21.0
> > > >>
> > > >>
> > > >> --
> > > >> Mailing list info: https://lists.linux.it/listinfo/ltp
> > > >>
> > > >
> > > >
> > > > --
> > > > Regards,
> > > > Li Wang
> > > >
> > >
> > >
> > > --
> > > Regards,
> > > Li Wang
> >
> 
> 
> -- 
> Regards,
> Li Wang

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported
  2019-06-10  6:12                                                               ` Murphy Zhou
@ 2019-06-10  9:28                                                                 ` Li Wang
  2019-06-11  7:47                                                                     ` [LTP] " Murphy Zhou
  0 siblings, 1 reply; 55+ messages in thread
From: Li Wang @ 2019-06-10  9:28 UTC (permalink / raw)
  To: ltp

On Mon, Jun 10, 2019 at 2:12 PM Murphy Zhou <xzhou@redhat.com> wrote:

> On Wed, Jun 05, 2019 at 05:53:13PM +0800, Li Wang wrote:
> > On Wed, Jun 5, 2019 at 5:30 PM Murphy Zhou <xzhou@redhat.com> wrote:
> >
> > > On Wed, Jun 05, 2019 at 02:55:47PM +0800, Li Wang wrote:
> > > > On Wed, Jun 5, 2019 at 1:51 PM Li Wang <liwang@redhat.com> wrote:
> > > >
> > > > >
> > > > >
> > > > > On Tue, May 28, 2019 at 10:13 PM Murphy Zhou <xzhou@redhat.com>
> wrote:
> > > > >
> > > > >> To check if the filesystem we are testing on supports FIBMAP,
> mkswap,
> > > > >> swapon and swapoff operations.
> > > > >> Modify make_swapfile function to test mkswap support status
> safely.
> > > > >>
> > > > >> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> > > > >> ---
> > > > >>  testcases/kernel/syscalls/swapon/libswapon.c | 45
> > > +++++++++++++++++++-
> > > > >>  testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
> > > > >>  2 files changed, 49 insertions(+), 3 deletions(-)
> > > > >>
> > > > >> diff --git a/testcases/kernel/syscalls/swapon/libswapon.c
> > > > >> b/testcases/kernel/syscalls/swapon/libswapon.c
> > > > >> index cf6a98891..f66d19548 100644
> > > > >> --- a/testcases/kernel/syscalls/swapon/libswapon.c
> > > > >> +++ b/testcases/kernel/syscalls/swapon/libswapon.c
> > > > >> @@ -19,13 +19,15 @@
> > > > >>   *
> > > > >>   */
> > > > >>
> > > > >> +#include <errno.h>
> > > > >> +#include "lapi/syscalls.h"
> > > > >>  #include "test.h"
> > > > >>  #include "libswapon.h"
> > > > >>
> > > > >>  /*
> > > > >>   * Make a swap file
> > > > >>   */
> > > > >> -void make_swapfile(void (cleanup)(void), const char *swapfile)
> > > > >> +int make_swapfile(void (cleanup)(void), const char *swapfile, int
> > > safe)
> > > > >>  {
> > > > >>         if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) *
> 10,
> > > > >>             TST_BYTES)) {
> > > > >> @@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const
> char
> > > > >> *swapfile)
> > > > >>         argv[1] = swapfile;
> > > > >>         argv[2] = NULL;
> > > > >>
> > > > >> -       tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
> > > > >> +       return tst_run_cmd(cleanup, argv, "/dev/null",
> "/dev/null",
> > > safe);
> > > > >> +}
> > > > >> +
> > > > >> +/*
> > > > >> + * Check swapon/swapoff support status of filesystems or files
> > > > >> + * we are testing on.
> > > > >> + */
> > > > >> +void is_swap_supported(void (cleanup)(void), const char
> *filename)
> > > > >> +{
> > > > >> +       int fibmap = tst_fibmap(filename);
> > > > >> +       long fs_type = tst_fs_type(cleanup, filename);
> > > > >> +       const char *fstype = tst_fs_type_name(fs_type);
> > > > >> +
> > > > >> +       int ret = make_swapfile(NULL, filename, 1);
> > > > >> +       if (ret != 0) {
> > > > >> +               if (fibmap != 0) {
> > > > >>
> > > > >
> > > > > As I replied in patch 1/4, how do we know that means FIBMAP not
> > > support if
> > > > > just verify fibmap != 0?
> > > > > So I would suggest to make the return value of tst_fibmap() is more
> > > > > precise and do if (fibmap == 1) check here.
> > >
> > > Very good catch. The return value should be more precise. Thanks!
> > >
> > > > >
> > > >
> > > > And also, imagine that if swapon01 test failed on BRTFS or
> NFS(support
> > > > swapfile but not
> > > > support FIBMAP ioctl), then here will report the new bug as a TCONF
> to
> > > LTP.
> > >
> > > Here is testing mkswap for swapon test preparation. If mkswap fail, and
> > > FIBMAP not supported, it's reasonable to me that we should not go on to
> > > test swapon.
> > >
> > > But yes, if a regression causes mkswap fail without FIBMAP supported,
> we
> > > could miss the bug here like you described. This situation should be
> > > covered by tcase for mkswap IMO.
> > >
> >
> > I'm thinking maybe we cann't avoid adding a whilelist in the test, at
> least
> > for known filesystem without FIBMAP supported.
>
> No, I think we don't need a whilelist here. Amir and I discussed long way
> to here, you can check that. We are not using fibmap test as a verdict for
> swapfile is supported or not. Doing a mkswap/swapon/swapoff test before
> real tests to detect the support situation. tst_fibmap result helps us
> to decide how to report. If the underneath filesystem can survive these
> test, it should be supporting swapfiles and swapon/swapoff tests should
> run.


> The whitelisted nfs and tmpfs are well covered by these pre-tests. More,
> NFS should not be skipped as if we turn on kernle configs for NFS_SWAP,
> these tests can run on NFS.
>
> Whitelist could skip more tests and bugs.
>
> I tested some fibmap/mkswap/swapon/swapoff tests for your reference:
>

Thanks a lot for the test report, good to know these details.


>
> 1 means positive, 0 means negative.
>
> -------- On 5.3-rc3+ kernel, NFS_SWAP=y SUNRPC_SWAP=y -------
>         fibamp  mkswap  swapon swapoff
> xfs     1       1       1       1
> ext4    1       1       1       1
>
> btrfs   0       1       0       0
> tmpfs   0       1       0       0
>
> ovl     1       1       1       1
>
> cifs
> v3.11   0       1       0       0
> v1      0       1       0       0
> v2      0       1       0       0
>
> nfs
> v4.2    0       1       1*      1
> v4.1    0       1       1       1
> v4.0    0       1       1*      1
> v3      0       1       1       1
>
> * hang sometimes
>
> --------- On 3.10.0 based kernel ----------------
>         fibamp  mkswap  swapon swapoff
> xfs     1       1       1       1
> ext4    1       1       1       1
>
> btrfs   0       1       0       0
> tmpfs   0       1       0       0
>
> ovl     1       1       1       1
>
> cifs
> v3.0    0       1       0       0
>
> nfs
> v4.2    0       1       0       0
>
>
> ---------- On 2.6.32 based kernel ---------------
>         fibamp  mkswap  swapon swapoff
> tmpfs   0       1       0       0
> xfs     1       1       1       1
> ext4    1       1       1       1
> cifs    0       0       0       0
> nfs     0       0       0       0
>
> >
> > FYI: what do you think if change the is_swap_supported(...) like this?
> >
> > void is_swap_supported(void (cleanup)(void), const char *filename)
> > {
> >         int fibmap = tst_fibmap(filename);
> >
> >         if (fibmap == 1) {
>
> fibmap == 0 does not mean swapfile is supported. We need to make sure that
> survivors of this function are supporting swapfiles.
>

Yes, it sounds quite reasonable. So besides that return value of
tst_fibmap() is not precise, patch V6 LGTM. Feel free to add my review in
patch v7:

Reviewed-by: Li Wang <liwang@redhat.com>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190610/9d6e1b32/attachment.html>

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [PATCH v7 1/4] lib/tst_ioctl.c: add helper tst_fibmap
  2019-06-10  9:28                                                                 ` Li Wang
@ 2019-06-11  7:47                                                                     ` Murphy Zhou
  0 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: liwang; +Cc: ltp, amir73il, chrubis, linux-fsdevel, Murphy Zhou

To check if FIBMAP ioctl is supported by the filesystem we are
testing on. It also can check the support status of specific
files, but that may not needed for now.

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
v7:
  Make tst_fibmap return value more accurate
  Print errno if fibmap ioctl does not succeed
  Make swapoff02 use new helper
  Mute some build warnnings
  cc linux-fsdevel list
  Overall diff stat:

 include/tst_fs.h                               |  5 +++++
 lib/tst_ioctl.c                                | 37 +++++++++++++++++++++++++++++++++++++
 testcases/kernel/syscalls/swapoff/Makefile     |  3 ++-
 testcases/kernel/syscalls/swapoff/Makefile.inc |  6 ++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c  | 10 ++--------
 testcases/kernel/syscalls/swapoff/swapoff02.c  | 11 ++---------
 testcases/kernel/syscalls/swapon/libswapon.c   | 45 +++++++++++++++++++++++++++++++++++++++++++--
 testcases/kernel/syscalls/swapon/libswapon.h   |  7 ++++++-
 testcases/kernel/syscalls/swapon/swapon01.c    | 11 ++---------
 testcases/kernel/syscalls/swapon/swapon02.c    | 13 +++----------
 testcases/kernel/syscalls/swapon/swapon03.c    | 15 ++++-----------
 11 files changed, 112 insertions(+), 51 deletions(-)

v6:
  Modify make_swapfile() to check mkswap support status safely
  Remove whitelist
  Remove BTRFS EINVAL check
  Check mkswap status before testing swapon in helper
  If swapon pass, following swapoff failure will fail the whole test and break
  Also modify swapoff02 to remove whitelist completely
v5:
  Split to 4 patches
  Only take one filename parameter in tst_fibmap
  Add helper is_swap_supported to check swap operation support status
  Test fibmap/swapon and swapoff operation in the helper
  Keep NFS/TMPFS whitelist
  Keep BTRFS EINVAL handling logic, except above 2 situation:
    if swapon fails and fibmap is not supported, tst_brk with TCONF
    if swapon fails and fibmap is supported, tst_brk with TFAIL
  If swapon test pass in the helper, test swapoff similarly
  Put is_swap_supported helper in libswapon, link swapoff binaries to it
  Mute a sprintf filaname wanrning by the way
v4:
  Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
  Fix fs_type undeclared in swapoff01.c
v2:
  Test FIBMAP instead of fstype whitelist

 include/tst_fs.h |  5 +++++
 lib/tst_ioctl.c  | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 lib/tst_ioctl.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index ebca065c6..6d03371ec 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);
  */
 void tst_fill_fs(const char *path, int verbose);
 
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(const char *filename);
+
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
 {
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
new file mode 100644
index 000000000..364220bcd
--- /dev/null
+++ b/lib/tst_ioctl.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(const char *filename)
+{
+	/* test if FIBMAP ioctl is supported */
+	int fd, block = 0;
+
+	fd = open(filename, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		tst_res(TWARN | TERRNO,
+			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
+		return -1;
+	}
+
+	if (ioctl(fd, FIBMAP, &block)) {
+		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
+		close(fd);
+		return 1;
+	}
+	tst_res(TINFO, "FIBMAP ioctl is supported");
+
+	if (close(fd)) {
+		tst_res(TWARN | TERRNO, "close(fd) failed");
+		return -1;
+	}
+	return 0;
+}
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v7 1/4] lib/tst_ioctl.c: add helper tst_fibmap
@ 2019-06-11  7:47                                                                     ` Murphy Zhou
  0 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: ltp

To check if FIBMAP ioctl is supported by the filesystem we are
testing on. It also can check the support status of specific
files, but that may not needed for now.

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
v7:
  Make tst_fibmap return value more accurate
  Print errno if fibmap ioctl does not succeed
  Make swapoff02 use new helper
  Mute some build warnnings
  cc linux-fsdevel list
  Overall diff stat:

 include/tst_fs.h                               |  5 +++++
 lib/tst_ioctl.c                                | 37 +++++++++++++++++++++++++++++++++++++
 testcases/kernel/syscalls/swapoff/Makefile     |  3 ++-
 testcases/kernel/syscalls/swapoff/Makefile.inc |  6 ++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c  | 10 ++--------
 testcases/kernel/syscalls/swapoff/swapoff02.c  | 11 ++---------
 testcases/kernel/syscalls/swapon/libswapon.c   | 45 +++++++++++++++++++++++++++++++++++++++++++--
 testcases/kernel/syscalls/swapon/libswapon.h   |  7 ++++++-
 testcases/kernel/syscalls/swapon/swapon01.c    | 11 ++---------
 testcases/kernel/syscalls/swapon/swapon02.c    | 13 +++----------
 testcases/kernel/syscalls/swapon/swapon03.c    | 15 ++++-----------
 11 files changed, 112 insertions(+), 51 deletions(-)

v6:
  Modify make_swapfile() to check mkswap support status safely
  Remove whitelist
  Remove BTRFS EINVAL check
  Check mkswap status before testing swapon in helper
  If swapon pass, following swapoff failure will fail the whole test and break
  Also modify swapoff02 to remove whitelist completely
v5:
  Split to 4 patches
  Only take one filename parameter in tst_fibmap
  Add helper is_swap_supported to check swap operation support status
  Test fibmap/swapon and swapoff operation in the helper
  Keep NFS/TMPFS whitelist
  Keep BTRFS EINVAL handling logic, except above 2 situation:
    if swapon fails and fibmap is not supported, tst_brk with TCONF
    if swapon fails and fibmap is supported, tst_brk with TFAIL
  If swapon test pass in the helper, test swapoff similarly
  Put is_swap_supported helper in libswapon, link swapoff binaries to it
  Mute a sprintf filaname wanrning by the way
v4:
  Fail softly if FIBMAP nit supported, instead of skip entire testcase
v3:
  Fix fs_type undeclared in swapoff01.c
v2:
  Test FIBMAP instead of fstype whitelist

 include/tst_fs.h |  5 +++++
 lib/tst_ioctl.c  | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+)
 create mode 100644 lib/tst_ioctl.c

diff --git a/include/tst_fs.h b/include/tst_fs.h
index ebca065c6..6d03371ec 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);
  */
 void tst_fill_fs(const char *path, int verbose);
 
+/*
+ * test if FIBMAP ioctl is supported
+ */
+int tst_fibmap(const char *filename);
+
 #ifdef TST_TEST_H__
 static inline long tst_fs_type(const char *path)
 {
diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
new file mode 100644
index 000000000..364220bcd
--- /dev/null
+++ b/lib/tst_ioctl.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
+#define TST_NO_DEFAULT_MAIN
+
+#include "tst_test.h"
+
+int tst_fibmap(const char *filename)
+{
+	/* test if FIBMAP ioctl is supported */
+	int fd, block = 0;
+
+	fd = open(filename, O_RDWR | O_CREAT, 0666);
+	if (fd < 0) {
+		tst_res(TWARN | TERRNO,
+			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
+		return -1;
+	}
+
+	if (ioctl(fd, FIBMAP, &block)) {
+		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
+		close(fd);
+		return 1;
+	}
+	tst_res(TINFO, "FIBMAP ioctl is supported");
+
+	if (close(fd)) {
+		tst_res(TWARN | TERRNO, "close(fd) failed");
+		return -1;
+	}
+	return 0;
+}
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH v7 2/4] swapon/libswapon: add helper is_swap_supported
  2019-06-11  7:47                                                                     ` [LTP] " Murphy Zhou
@ 2019-06-11  7:47                                                                       ` Murphy Zhou
  -1 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: liwang; +Cc: ltp, amir73il, chrubis, linux-fsdevel, Murphy Zhou

To check if the filesystem we are testing on supports FIBMAP, mkswap,
swapon and swapoff operations. Survivor of this function should support
swapfile function well, like swapon and swapoff.
Modify make_swapfile function to test mkswap support status safely.

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-
 testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
index cf6a98891..0a4501bdd 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.c
+++ b/testcases/kernel/syscalls/swapon/libswapon.c
@@ -19,13 +19,15 @@
  *
  */
 
+#include <errno.h>
+#include "lapi/syscalls.h"
 #include "test.h"
 #include "libswapon.h"
 
 /*
  * Make a swap file
  */
-void make_swapfile(void (cleanup)(void), const char *swapfile)
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)
 {
 	if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
 	    TST_BYTES)) {
@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
 	argv[1] = swapfile;
 	argv[2] = NULL;
 
-	tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
+	return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);
+}
+
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *filename)
+{
+	int fibmap = tst_fibmap(filename);
+	long fs_type = tst_fs_type(cleanup, filename);
+	const char *fstype = tst_fs_type_name(fs_type);
+
+	int ret = make_swapfile(NULL, filename, 1);
+	if (ret != 0) {
+		if (fibmap == 1) {
+			tst_brkm(TCONF, cleanup,
+				"mkswap on %s not supported", fstype);
+		} else {
+			tst_brkm(TFAIL, cleanup,
+				"mkswap on %s failed", fstype);
+		}
+	}
+
+	TEST(ltp_syscall(__NR_swapon, filename, 0));
+	if (TEST_RETURN == -1) {
+		if (fibmap == 1 && errno == EINVAL) {
+			tst_brkm(TCONF, cleanup,
+				"Swapfile on %s not implemented", fstype);
+		} else {
+			tst_brkm(TFAIL | TERRNO, cleanup,
+				 "swapon on %s failed", fstype);
+		}
+	}
+
+	TEST(ltp_syscall(__NR_swapoff, filename, 0));
+	if (TEST_RETURN == -1) {
+		tst_brkm(TFAIL | TERRNO, cleanup,
+			"swapoff on %s failed", fstype);
+	}
 }
diff --git a/testcases/kernel/syscalls/swapon/libswapon.h b/testcases/kernel/syscalls/swapon/libswapon.h
index 7f7211eb4..a51833ec1 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.h
+++ b/testcases/kernel/syscalls/swapon/libswapon.h
@@ -29,6 +29,11 @@
 /*
  * Make a swap file
  */
-void make_swapfile(void (cleanup)(void), const char *swapfile);
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);
 
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *filename);
 #endif /* __LIBSWAPON_H__ */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v7 2/4] swapon/libswapon: add helper is_swap_supported
@ 2019-06-11  7:47                                                                       ` Murphy Zhou
  0 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: ltp

To check if the filesystem we are testing on supports FIBMAP, mkswap,
swapon and swapoff operations. Survivor of this function should support
swapfile function well, like swapon and swapoff.
Modify make_swapfile function to test mkswap support status safely.

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/libswapon.c | 45 +++++++++++++++++++-
 testcases/kernel/syscalls/swapon/libswapon.h |  7 ++-
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/libswapon.c b/testcases/kernel/syscalls/swapon/libswapon.c
index cf6a98891..0a4501bdd 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.c
+++ b/testcases/kernel/syscalls/swapon/libswapon.c
@@ -19,13 +19,15 @@
  *
  */
 
+#include <errno.h>
+#include "lapi/syscalls.h"
 #include "test.h"
 #include "libswapon.h"
 
 /*
  * Make a swap file
  */
-void make_swapfile(void (cleanup)(void), const char *swapfile)
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe)
 {
 	if (!tst_fs_has_free(NULL, ".", sysconf(_SC_PAGESIZE) * 10,
 	    TST_BYTES)) {
@@ -45,5 +47,44 @@ void make_swapfile(void (cleanup)(void), const char *swapfile)
 	argv[1] = swapfile;
 	argv[2] = NULL;
 
-	tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", 0);
+	return tst_run_cmd(cleanup, argv, "/dev/null", "/dev/null", safe);
+}
+
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *filename)
+{
+	int fibmap = tst_fibmap(filename);
+	long fs_type = tst_fs_type(cleanup, filename);
+	const char *fstype = tst_fs_type_name(fs_type);
+
+	int ret = make_swapfile(NULL, filename, 1);
+	if (ret != 0) {
+		if (fibmap == 1) {
+			tst_brkm(TCONF, cleanup,
+				"mkswap on %s not supported", fstype);
+		} else {
+			tst_brkm(TFAIL, cleanup,
+				"mkswap on %s failed", fstype);
+		}
+	}
+
+	TEST(ltp_syscall(__NR_swapon, filename, 0));
+	if (TEST_RETURN == -1) {
+		if (fibmap == 1 && errno == EINVAL) {
+			tst_brkm(TCONF, cleanup,
+				"Swapfile on %s not implemented", fstype);
+		} else {
+			tst_brkm(TFAIL | TERRNO, cleanup,
+				 "swapon on %s failed", fstype);
+		}
+	}
+
+	TEST(ltp_syscall(__NR_swapoff, filename, 0));
+	if (TEST_RETURN == -1) {
+		tst_brkm(TFAIL | TERRNO, cleanup,
+			"swapoff on %s failed", fstype);
+	}
 }
diff --git a/testcases/kernel/syscalls/swapon/libswapon.h b/testcases/kernel/syscalls/swapon/libswapon.h
index 7f7211eb4..a51833ec1 100644
--- a/testcases/kernel/syscalls/swapon/libswapon.h
+++ b/testcases/kernel/syscalls/swapon/libswapon.h
@@ -29,6 +29,11 @@
 /*
  * Make a swap file
  */
-void make_swapfile(void (cleanup)(void), const char *swapfile);
+int make_swapfile(void (cleanup)(void), const char *swapfile, int safe);
 
+/*
+ * Check swapon/swapoff support status of filesystems or files
+ * we are testing on.
+ */
+void is_swap_supported(void (cleanup)(void), const char *filename);
 #endif /* __LIBSWAPON_H__ */
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH v7 3/4] syscalls/swapon/swapon0{1..3}: use helpers to check support status
  2019-06-11  7:47                                                                     ` [LTP] " Murphy Zhou
@ 2019-06-11  7:47                                                                       ` Murphy Zhou
  -1 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: liwang; +Cc: ltp, amir73il, chrubis, linux-fsdevel, Murphy Zhou

Of swap operations.

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/swapon01.c | 11 ++---------
 testcases/kernel/syscalls/swapon/swapon02.c | 13 +++----------
 testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++-----------
 3 files changed, 9 insertions(+), 30 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index 32538f82b..f95ce0ab2 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -84,16 +84,9 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
-	make_swapfile(cleanup, "swapfile01");
+	make_swapfile(cleanup, "swapfile01", 0);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..3d49d0c6b 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -132,18 +132,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
-	make_swapfile(cleanup, "swapfile01");
-	make_swapfile(cleanup, "alreadyused");
+	make_swapfile(cleanup, "swapfile01", 0);
+	make_swapfile(cleanup, "alreadyused", 0);
 
 	if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
 		if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 955ac247b..cef57150c 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -153,7 +153,7 @@ static int setup_swap(void)
 	int j, fd;
 	int status;
 	int res = 0;
-	char filename[15];
+	char filename[FILENAME_MAX];
 	char buf[BUFSIZ + 1];
 
 	/* Find out how many swapfiles (1 line per entry) already exist */
@@ -210,7 +210,7 @@ static int setup_swap(void)
 			}
 
 			/* Create the swapfile */
-			make_swapfile(cleanup, filename);
+			make_swapfile(cleanup, filename, 0);
 
 			/* turn on the swap file */
 			res = ltp_syscall(__NR_swapon, filename, 0);
@@ -246,7 +246,7 @@ static int setup_swap(void)
 
 	/* Create all needed extra swapfiles for testing */
 	for (j = 0; j < testfiles; j++)
-		make_swapfile(cleanup, swap_testfiles[j].filename);
+		make_swapfile(cleanup, swap_testfiles[j].filename, 0);
 
 	return 0;
 
@@ -333,14 +333,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	TEST_PAUSE;
 }
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v7 3/4] syscalls/swapon/swapon0{1..3}: use helpers to check support status
@ 2019-06-11  7:47                                                                       ` Murphy Zhou
  0 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: ltp

Of swap operations.

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapon/swapon01.c | 11 ++---------
 testcases/kernel/syscalls/swapon/swapon02.c | 13 +++----------
 testcases/kernel/syscalls/swapon/swapon03.c | 15 ++++-----------
 3 files changed, 9 insertions(+), 30 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c
index 32538f82b..f95ce0ab2 100644
--- a/testcases/kernel/syscalls/swapon/swapon01.c
+++ b/testcases/kernel/syscalls/swapon/swapon01.c
@@ -84,16 +84,9 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
-	make_swapfile(cleanup, "swapfile01");
+	make_swapfile(cleanup, "swapfile01", 0);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index 4af5105c6..3d49d0c6b 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -132,18 +132,11 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	SAFE_TOUCH(cleanup, "notswap", 0777, NULL);
-	make_swapfile(cleanup, "swapfile01");
-	make_swapfile(cleanup, "alreadyused");
+	make_swapfile(cleanup, "swapfile01", 0);
+	make_swapfile(cleanup, "alreadyused", 0);
 
 	if (ltp_syscall(__NR_swapon, "alreadyused", 0)) {
 		if (fs_type != TST_BTRFS_MAGIC || errno != EINVAL)
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 955ac247b..cef57150c 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -153,7 +153,7 @@ static int setup_swap(void)
 	int j, fd;
 	int status;
 	int res = 0;
-	char filename[15];
+	char filename[FILENAME_MAX];
 	char buf[BUFSIZ + 1];
 
 	/* Find out how many swapfiles (1 line per entry) already exist */
@@ -210,7 +210,7 @@ static int setup_swap(void)
 			}
 
 			/* Create the swapfile */
-			make_swapfile(cleanup, filename);
+			make_swapfile(cleanup, filename, 0);
 
 			/* turn on the swap file */
 			res = ltp_syscall(__NR_swapon, filename, 0);
@@ -246,7 +246,7 @@ static int setup_swap(void)
 
 	/* Create all needed extra swapfiles for testing */
 	for (j = 0; j < testfiles; j++)
-		make_swapfile(cleanup, swap_testfiles[j].filename);
+		make_swapfile(cleanup, swap_testfiles[j].filename, 0);
 
 	return 0;
 
@@ -333,14 +333,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapon on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	TEST_PAUSE;
 }
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [PATCH v7 4/4] syscalls/swapoff/swapoff0{1,2}: use helpers to check support status
  2019-06-11  7:47                                                                     ` [LTP] " Murphy Zhou
@ 2019-06-11  7:47                                                                       ` Murphy Zhou
  -1 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: liwang; +Cc: ltp, amir73il, chrubis, linux-fsdevel, Murphy Zhou

Of swap operations. Change Makefile to use functions from
../swapon/libswapon.c

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapoff/Makefile     |  3 ++-
 testcases/kernel/syscalls/swapoff/Makefile.inc |  6 ++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c  | 10 ++--------
 testcases/kernel/syscalls/swapoff/swapoff02.c  | 11 ++---------
 4 files changed, 12 insertions(+), 18 deletions(-)
 create mode 100644 testcases/kernel/syscalls/swapoff/Makefile.inc

diff --git a/testcases/kernel/syscalls/swapoff/Makefile b/testcases/kernel/syscalls/swapoff/Makefile
index bd617d806..536b2dbac 100644
--- a/testcases/kernel/syscalls/swapoff/Makefile
+++ b/testcases/kernel/syscalls/swapoff/Makefile
@@ -19,5 +19,6 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-
+include $(abs_srcdir)/./Makefile.inc
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
+$(MAKE_TARGETS): %: %.o ../swapon/libswapon.o
diff --git a/testcases/kernel/syscalls/swapoff/Makefile.inc b/testcases/kernel/syscalls/swapoff/Makefile.inc
new file mode 100644
index 000000000..65350cbeb
--- /dev/null
+++ b/testcases/kernel/syscalls/swapoff/Makefile.inc
@@ -0,0 +1,6 @@
+LIBDIR			+= ../swapon/
+LIBSWAPON		:= $(LIBDIR)/libswapon.o
+$(LIBSWAPON):
+	$(MAKE) -C $(LIBDIR)
+CPPFLAGS		+= -I$(abs_srcdir)/$(LIBDIR)
+LDFLAGS			+= -L$(abs_builddir)/$(LIBDIR)
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index a63e661a5..e115269c0 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include "config.h"
 #include "lapi/syscalls.h"
+#include "../swapon/libswapon.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -86,14 +87,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
 		tst_brkm(TBROK, cleanup,
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index b5c6312a1..8954f975f 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -33,6 +33,7 @@
 #include "test.h"
 #include "lapi/syscalls.h"
 #include "safe_macros.h"
+#include "../swapon/libswapon.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -124,7 +125,6 @@ static void cleanup01(void)
 
 static void setup(void)
 {
-	long type;
 	struct passwd *nobody;
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -138,14 +138,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
 		tst_brkm(TBROK, cleanup,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v7 4/4] syscalls/swapoff/swapoff0{1, 2}: use helpers to check support status
@ 2019-06-11  7:47                                                                       ` Murphy Zhou
  0 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-11  7:47 UTC (permalink / raw)
  To: ltp

Of swap operations. Change Makefile to use functions from
../swapon/libswapon.c

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
 testcases/kernel/syscalls/swapoff/Makefile     |  3 ++-
 testcases/kernel/syscalls/swapoff/Makefile.inc |  6 ++++++
 testcases/kernel/syscalls/swapoff/swapoff01.c  | 10 ++--------
 testcases/kernel/syscalls/swapoff/swapoff02.c  | 11 ++---------
 4 files changed, 12 insertions(+), 18 deletions(-)
 create mode 100644 testcases/kernel/syscalls/swapoff/Makefile.inc

diff --git a/testcases/kernel/syscalls/swapoff/Makefile b/testcases/kernel/syscalls/swapoff/Makefile
index bd617d806..536b2dbac 100644
--- a/testcases/kernel/syscalls/swapoff/Makefile
+++ b/testcases/kernel/syscalls/swapoff/Makefile
@@ -19,5 +19,6 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-
+include $(abs_srcdir)/./Makefile.inc
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
+$(MAKE_TARGETS): %: %.o ../swapon/libswapon.o
diff --git a/testcases/kernel/syscalls/swapoff/Makefile.inc b/testcases/kernel/syscalls/swapoff/Makefile.inc
new file mode 100644
index 000000000..65350cbeb
--- /dev/null
+++ b/testcases/kernel/syscalls/swapoff/Makefile.inc
@@ -0,0 +1,6 @@
+LIBDIR			+= ../swapon/
+LIBSWAPON		:= $(LIBDIR)/libswapon.o
+$(LIBSWAPON):
+	$(MAKE) -C $(LIBDIR)
+CPPFLAGS		+= -I$(abs_srcdir)/$(LIBDIR)
+LDFLAGS			+= -L$(abs_builddir)/$(LIBDIR)
diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index a63e661a5..e115269c0 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -25,6 +25,7 @@
 #include <stdlib.h>
 #include "config.h"
 #include "lapi/syscalls.h"
+#include "../swapon/libswapon.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -86,14 +87,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((fs_type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(fs_type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	if (!tst_fs_has_free(NULL, ".", 64, TST_MB)) {
 		tst_brkm(TBROK, cleanup,
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index b5c6312a1..8954f975f 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -33,6 +33,7 @@
 #include "test.h"
 #include "lapi/syscalls.h"
 #include "safe_macros.h"
+#include "../swapon/libswapon.h"
 
 static void setup(void);
 static void cleanup(void);
@@ -124,7 +125,6 @@ static void cleanup01(void)
 
 static void setup(void)
 {
-	long type;
 	struct passwd *nobody;
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -138,14 +138,7 @@ static void setup(void)
 
 	tst_tmpdir();
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do swapoff on a file on %s filesystem",
-			 tst_fs_type_name(type));
-	break;
-	}
+	is_swap_supported(cleanup, "./tstswap");
 
 	if (!tst_fs_has_free(NULL, ".", 1, TST_KB)) {
 		tst_brkm(TBROK, cleanup,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v7 1/4] lib/tst_ioctl.c: add helper tst_fibmap
  2019-06-11  7:47                                                                     ` [LTP] " Murphy Zhou
                                                                                       ` (3 preceding siblings ...)
  (?)
@ 2019-06-30  1:51                                                                     ` Murphy Zhou
  -1 siblings, 0 replies; 55+ messages in thread
From: Murphy Zhou @ 2019-06-30  1:51 UTC (permalink / raw)
  To: ltp

Ping ?

On Tue, Jun 11, 2019 at 03:47:38PM +0800, Murphy Zhou wrote:
> To check if FIBMAP ioctl is supported by the filesystem we are
> testing on. It also can check the support status of specific
> files, but that may not needed for now.
> 
> Reviewed-by: Li Wang <liwang@redhat.com>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
> ---
> v7:
>   Make tst_fibmap return value more accurate
>   Print errno if fibmap ioctl does not succeed
>   Make swapoff02 use new helper
>   Mute some build warnnings
>   cc linux-fsdevel list
>   Overall diff stat:
> 
>  include/tst_fs.h                               |  5 +++++
>  lib/tst_ioctl.c                                | 37 +++++++++++++++++++++++++++++++++++++
>  testcases/kernel/syscalls/swapoff/Makefile     |  3 ++-
>  testcases/kernel/syscalls/swapoff/Makefile.inc |  6 ++++++
>  testcases/kernel/syscalls/swapoff/swapoff01.c  | 10 ++--------
>  testcases/kernel/syscalls/swapoff/swapoff02.c  | 11 ++---------
>  testcases/kernel/syscalls/swapon/libswapon.c   | 45 +++++++++++++++++++++++++++++++++++++++++++--
>  testcases/kernel/syscalls/swapon/libswapon.h   |  7 ++++++-
>  testcases/kernel/syscalls/swapon/swapon01.c    | 11 ++---------
>  testcases/kernel/syscalls/swapon/swapon02.c    | 13 +++----------
>  testcases/kernel/syscalls/swapon/swapon03.c    | 15 ++++-----------
>  11 files changed, 112 insertions(+), 51 deletions(-)
> 
> v6:
>   Modify make_swapfile() to check mkswap support status safely
>   Remove whitelist
>   Remove BTRFS EINVAL check
>   Check mkswap status before testing swapon in helper
>   If swapon pass, following swapoff failure will fail the whole test and break
>   Also modify swapoff02 to remove whitelist completely
> v5:
>   Split to 4 patches
>   Only take one filename parameter in tst_fibmap
>   Add helper is_swap_supported to check swap operation support status
>   Test fibmap/swapon and swapoff operation in the helper
>   Keep NFS/TMPFS whitelist
>   Keep BTRFS EINVAL handling logic, except above 2 situation:
>     if swapon fails and fibmap is not supported, tst_brk with TCONF
>     if swapon fails and fibmap is supported, tst_brk with TFAIL
>   If swapon test pass in the helper, test swapoff similarly
>   Put is_swap_supported helper in libswapon, link swapoff binaries to it
>   Mute a sprintf filaname wanrning by the way
> v4:
>   Fail softly if FIBMAP nit supported, instead of skip entire testcase
> v3:
>   Fix fs_type undeclared in swapoff01.c
> v2:
>   Test FIBMAP instead of fstype whitelist
> 
>  include/tst_fs.h |  5 +++++
>  lib/tst_ioctl.c  | 37 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+)
>  create mode 100644 lib/tst_ioctl.c
> 
> diff --git a/include/tst_fs.h b/include/tst_fs.h
> index ebca065c6..6d03371ec 100644
> --- a/include/tst_fs.h
> +++ b/include/tst_fs.h
> @@ -178,6 +178,11 @@ const char **tst_get_supported_fs_types(void);
>   */
>  void tst_fill_fs(const char *path, int verbose);
>  
> +/*
> + * test if FIBMAP ioctl is supported
> + */
> +int tst_fibmap(const char *filename);
> +
>  #ifdef TST_TEST_H__
>  static inline long tst_fs_type(const char *path)
>  {
> diff --git a/lib/tst_ioctl.c b/lib/tst_ioctl.c
> new file mode 100644
> index 000000000..364220bcd
> --- /dev/null
> +++ b/lib/tst_ioctl.c
> @@ -0,0 +1,37 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +
> +#include <errno.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/ioctl.h>
> +#include <linux/fs.h>
> +
> +#define TST_NO_DEFAULT_MAIN
> +
> +#include "tst_test.h"
> +
> +int tst_fibmap(const char *filename)
> +{
> +	/* test if FIBMAP ioctl is supported */
> +	int fd, block = 0;
> +
> +	fd = open(filename, O_RDWR | O_CREAT, 0666);
> +	if (fd < 0) {
> +		tst_res(TWARN | TERRNO,
> +			 "open(%s, O_RDWR | O_CREAT, 0666) failed", filename);
> +		return -1;
> +	}
> +
> +	if (ioctl(fd, FIBMAP, &block)) {
> +		tst_res(TINFO | TERRNO, "FIBMAP ioctl is NOT supported");
> +		close(fd);
> +		return 1;
> +	}
> +	tst_res(TINFO, "FIBMAP ioctl is supported");
> +
> +	if (close(fd)) {
> +		tst_res(TWARN | TERRNO, "close(fd) failed");
> +		return -1;
> +	}
> +	return 0;
> +}
> -- 
> 2.21.0
> 

^ permalink raw reply	[flat|nested] 55+ messages in thread

* [LTP] [PATCH v7 1/4] lib/tst_ioctl.c: add helper tst_fibmap
  2019-06-11  7:47                                                                     ` [LTP] " Murphy Zhou
                                                                                       ` (4 preceding siblings ...)
  (?)
@ 2019-07-16  5:19                                                                     ` Li Wang
  -1 siblings, 0 replies; 55+ messages in thread
From: Li Wang @ 2019-07-16  5:19 UTC (permalink / raw)
  To: ltp

On Tue, Jun 11, 2019 at 3:48 PM Murphy Zhou <xzhou@redhat.com> wrote:

> To check if FIBMAP ioctl is supported by the filesystem we are
> testing on. It also can check the support status of specific
> files, but that may not needed for now.
>
> Reviewed-by: Li Wang <liwang@redhat.com>
> Signed-off-by: Murphy Zhou <xzhou@redhat.com>
>

Patch set pushed, thanks.

I also added Amir's reviewed by.
    Reviewed-by: Amir Goldstein <amir73il@gmail.com>

-- 
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190716/f00a03c3/attachment.htm>

^ permalink raw reply	[flat|nested] 55+ messages in thread

end of thread, other threads:[~2019-07-16  5:19 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-30  7:14 [LTP] [PATCH] syscalls/swapon02: Do not fail on overlayfs Murphy Zhou
2019-04-30  8:14 ` Li Wang
2019-04-30  8:30   ` Murphy Zhou
2019-04-30  8:54     ` Li Wang
2019-04-30  9:08       ` Murphy Zhou
2019-04-30  9:21         ` Li Wang
2019-04-30  9:29           ` Murphy Zhou
2019-04-30  9:37           ` Amir Goldstein
2019-04-30  9:54             ` Murphy Zhou
2019-04-30 15:29               ` [LTP] [PATCH v2] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails Murphy Zhou
2019-04-30 23:59                 ` [LTP] [PATCH v3] " Murphy Zhou
2019-05-07  8:52                   ` Li Wang
2019-05-08  3:43                     ` Murphy Zhou
2019-05-08 10:22                       ` Amir Goldstein
2019-05-08 14:38                         ` Murphy Zhou
2019-05-10  4:42                         ` [LTP] [PATCH v4] syscalls/swap{on, off}: fail softly " Murphy Zhou
2019-05-10  5:27                           ` Amir Goldstein
2019-05-10  8:15                             ` Murphy Zhou
2019-05-10  8:48                               ` Amir Goldstein
2019-05-11  4:20                                 ` Murphy Zhou
2019-05-11  9:30                                   ` Amir Goldstein
2019-05-13  7:39                                     ` Murphy Zhou
2019-05-23 13:55                                       ` Cyril Hrubis
2019-05-23 14:06                                         ` Murphy Zhou
2019-05-28  4:39                                         ` [LTP] [PATCH v5 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
2019-05-28  4:39                                           ` [LTP] [PATCH v5 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
2019-05-28  5:56                                             ` Amir Goldstein
2019-05-28  8:33                                               ` Murphy Zhou
2019-05-28  9:56                                               ` Murphy Zhou
2019-05-28 11:59                                                 ` Amir Goldstein
2019-05-28 14:12                                                   ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
2019-05-28 14:12                                                     ` [LTP] [PATCH v6 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
2019-05-28 14:52                                                       ` Amir Goldstein
2019-06-05  5:51                                                       ` Li Wang
2019-06-05  6:55                                                         ` Li Wang
2019-06-05  9:30                                                           ` Murphy Zhou
2019-06-05  9:53                                                             ` Li Wang
2019-06-10  6:12                                                               ` Murphy Zhou
2019-06-10  9:28                                                                 ` Li Wang
2019-06-11  7:47                                                                   ` [PATCH v7 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
2019-06-11  7:47                                                                     ` [LTP] " Murphy Zhou
2019-06-11  7:47                                                                     ` [PATCH v7 2/4] swapon/libswapon: add helper is_swap_supported Murphy Zhou
2019-06-11  7:47                                                                       ` [LTP] " Murphy Zhou
2019-06-11  7:47                                                                     ` [PATCH v7 3/4] syscalls/swapon/swapon0{1..3}: use helpers to check support status Murphy Zhou
2019-06-11  7:47                                                                       ` [LTP] " Murphy Zhou
2019-06-11  7:47                                                                     ` [PATCH v7 4/4] syscalls/swapoff/swapoff0{1,2}: " Murphy Zhou
2019-06-11  7:47                                                                       ` [LTP] [PATCH v7 4/4] syscalls/swapoff/swapoff0{1, 2}: " Murphy Zhou
2019-06-30  1:51                                                                     ` [LTP] [PATCH v7 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
2019-07-16  5:19                                                                     ` Li Wang
2019-05-28 14:12                                                     ` [LTP] [PATCH v6 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status Murphy Zhou
2019-05-28 14:12                                                     ` [LTP] [PATCH v6 4/4] syscalls/swapoff/swapoff0{1, 2}: " Murphy Zhou
2019-06-05  4:44                                                     ` [LTP] [PATCH v6 1/4] lib/tst_ioctl.c: add helper tst_fibmap Murphy Zhou
2019-06-05  5:40                                                     ` Li Wang
2019-05-28  4:39                                           ` [LTP] [PATCH v5 3/4] syscalls/swapon/swapon0{1..3}: use helper to check support status Murphy Zhou
2019-05-28  4:39                                           ` [LTP] [PATCH v5 4/4] syscalls/swapoff/swapoff01: " Murphy Zhou

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.