All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3] syscalls/swap{on, off}: skip if FIBMAP ioctl trial fails
Date: Wed, 8 May 2019 13:22:15 +0300	[thread overview]
Message-ID: <CAOQ4uxjDyx7JFBSmkDe-rHNe=NriT710Ldsva=s+HasaDL0CTw@mail.gmail.com> (raw)
In-Reply-To: <20190508034331.hc6rssg4mc66k5xc@XZHOUW.usersys.redhat.com>

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.

  reply	other threads:[~2019-05-08 10:22 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOQ4uxjDyx7JFBSmkDe-rHNe=NriT710Ldsva=s+HasaDL0CTw@mail.gmail.com' \
    --to=amir73il@gmail.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.