[LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup

Li Wang liwang@redhat.com
Fri Aug 22 10:12:20 CEST 2025


On Fri, Aug 22, 2025 at 4:03 PM Wei Gao <wegao@suse.com> wrote:

> On Fri, Aug 22, 2025 at 03:48:11PM +0800, Li Wang via ltp wrote:
> > tst_is_mounted() now internally resolves the mount path via realpath(),
> > which will fail if the path does not exist. In sometest (e.g. mount05),
> > MNTPOINT2 may not exist yet during cleanup, calling tst_is_mounted()
> > directly could produce misleading warnings or errors.
> >
> > Add an explicit access(PATH, F_OK) check before calling tst_is_mounted()
> > in the cleanup, ensuring we only query mounts for existing paths.
> >
> > Signed-off-by: Li Wang <liwang@redhat.com>
> > ---
> >
> > Notes:
> >     v1 --> v2:
> >             patch 1/2, keep no change, do not send v2.
> >             patch 2/2, adding two more files for path exist check
> >
> >  testcases/kernel/containers/mqns/mqns_03.c | 2 +-
> >  testcases/kernel/containers/mqns/mqns_04.c | 2 +-
> >  testcases/kernel/syscalls/mount/mount05.c  | 2 +-
> >  3 files changed, 3 insertions(+), 3 deletions(-)
> Still more test case need update such as following?
>   13    111  testcases/kernel/syscalls/mount/mount02.c <<cleanup>>
>              if (tst_is_mounted(MNTPOINT))
>   14    202  testcases/kernel/syscalls/mount/mount03.c <<cleanup>>
>              if (tst_is_mounted(MNTPOINT))
>   15     21  testcases/kernel/syscalls/mount/mount04.c <<cleanup>>
>              if (tst_is_mounted(MNTPOINT))
>

I wasn't encountering these test failures on that, the problem
only appears when the mounted path is deleted by test.

Did you test and get anything abnormal on your side?


>
> Maybe we can just report warning instead of error?
>

It is Warning but not an error, the 'TERRNO' is only use to
show the errno for better debugging.

  tst_device.c:440: TWARN: realpath(mntpoint2) failed: ENOENT (2)



>
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -481,7 +481,7 @@ static int tst_mount_has_opt(const char *path, const
> char *opt)
>         char abspath[PATH_MAX];
>
>         if (!realpath(path, abspath)) {
> -               tst_resm(TWARN | TERRNO, "realpath(%s) failed", path);
> +               tst_resm(TWARN, "realpath(%s) failed", path);
>                 return 0;
>         }
>
> >
> > diff --git a/testcases/kernel/containers/mqns/mqns_03.c
> b/testcases/kernel/containers/mqns/mqns_03.c
> > index 4d3bfc52f..ac8311559 100644
> > --- a/testcases/kernel/containers/mqns/mqns_03.c
> > +++ b/testcases/kernel/containers/mqns/mqns_03.c
> > @@ -130,7 +130,7 @@ static void cleanup(void)
> >       if (!access(MQUEUE2, F_OK))
> >               SAFE_MQ_UNLINK(MQNAME2);
> >
> > -     if (tst_is_mounted(DEVDIR))
> > +     if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
> >               SAFE_UMOUNT(DEVDIR);
> >  }
> >
> > diff --git a/testcases/kernel/containers/mqns/mqns_04.c
> b/testcases/kernel/containers/mqns/mqns_04.c
> > index d28c330c4..790607ecd 100644
> > --- a/testcases/kernel/containers/mqns/mqns_04.c
> > +++ b/testcases/kernel/containers/mqns/mqns_04.c
> > @@ -123,7 +123,7 @@ static void cleanup(void)
> >       if (!access(MQUEUE2, F_OK))
> >               SAFE_MQ_UNLINK(MQNAME2);
> >
> > -     if (tst_is_mounted(DEVDIR))
> > +     if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
> >               SAFE_UMOUNT(DEVDIR);
> >  }
> >
> > diff --git a/testcases/kernel/syscalls/mount/mount05.c
> b/testcases/kernel/syscalls/mount/mount05.c
> > index 66e102a32..5585e230e 100644
> > --- a/testcases/kernel/syscalls/mount/mount05.c
> > +++ b/testcases/kernel/syscalls/mount/mount05.c
> > @@ -35,7 +35,7 @@ static void cleanup(void)
> >       if (tst_is_mounted(MNTPOINT1))
> >               SAFE_UMOUNT(MNTPOINT1);
> >
> > -     if (tst_is_mounted(MNTPOINT2))
> > +     if (!access(MNTPOINT2, F_OK) && tst_is_mounted(MNTPOINT2))
> >               SAFE_UMOUNT(MNTPOINT2);
> >  }
> >
> > --
> > 2.49.0
> >
> >
> > --
> > Mailing list info: https://lists.linux.it/listinfo/ltp
>
>

-- 
Regards,
Li Wang


More information about the ltp mailing list