[LTP] [PATCH v3 2/2] fspick01.c: Check mount point was really remounted read only

Li Wang liwang@redhat.com
Fri Aug 22 07:38:01 CEST 2025


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

> Fixes: #1171
> The fspick01 test does not test if FSCONFIG_CMD_RECONFIGURE really
> reconfigures the mount point, e.g. if the mount point was really
> remounted read only.
>
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
>  testcases/kernel/syscalls/fspick/fspick01.c | 23 ++++++++++++++++++++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/fspick/fspick01.c
> b/testcases/kernel/syscalls/fspick/fspick01.c
> index d03cacd3d..8cb2d3669 100644
> --- a/testcases/kernel/syscalls/fspick/fspick01.c
> +++ b/testcases/kernel/syscalls/fspick/fspick01.c
> @@ -6,6 +6,7 @@
>   */
>  #include "tst_test.h"
>  #include "lapi/fsmount.h"
> +#include "tst_safe_stdio.h"
>
>  #define MNTPOINT               "mntpoint"
>  #define TCASE_ENTRY(_flags)    {.name = "Flag " #_flags, .flags = _flags}
> @@ -24,6 +25,12 @@ static void run(unsigned int n)
>  {
>         struct tcase *tc = &tcases[n];
>         int fspick_fd;
> +       char abspath[PATH_MAX];
> +       char *tmpdir = tst_tmpdir_path();
> +
>



> +       snprintf(abspath, sizeof(abspath), "%s/%s", tmpdir, MNTPOINT);
>

I just found here that you resolve the realpath to abspath manually,
that's not our expectation, since the tst_is_mounted_ro/w() should
be able to handle that automatically.

So, I suppose we could do this in the lib function, can you try:

--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -434,6 +434,12 @@ static int tst_mount_has_opt(const char *path, const
char *opt)
        char line[PATH_MAX];
        FILE *file;
        int ret = 0;
+       char abspath[PATH_MAX];
+
+       if (!realpath(path, abspath)) {
+               tst_resm(TWARN | TERRNO, "realpath(%s) failed", path);
+               return 0;
+       }

        file = SAFE_FOPEN(NULL, "/proc/mounts", "r");

@@ -443,7 +449,7 @@ static int tst_mount_has_opt(const char *path, const
char *opt)
                if (sscanf(line, "%*s %s %*s %s", mount_point, options) < 2)
                        continue;

-               if (strcmp(mount_point, path) != 0)
+               if (strcmp(mount_point, abspath) != 0)
                        continue;

                if (!opt) {



> +
> +       TST_EXP_VAL(tst_is_mounted_rw(abspath), 1);
>
>         TEST(fspick_fd = fspick(AT_FDCWD, MNTPOINT, tc->flags));
>         if (fspick_fd == -1) {
> @@ -49,8 +56,22 @@ static void run(unsigned int n)
>                 goto out;
>         }
>
> -       tst_res(TPASS, "%s: fspick() passed", tc->name);
> +       TST_EXP_VAL(tst_is_mounted_ro(abspath), 1);
> +
> +       TEST(fsconfig(fspick_fd, FSCONFIG_SET_FLAG, "rw", NULL, 0));
> +       if (TST_RET == -1) {
> +               tst_res(TFAIL | TTERRNO, "fsconfig(FSCONFIG_SET_FLAG)
> failed");
> +               goto out;
> +       }
>
> +       TEST(fsconfig(fspick_fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0));
> +       if (TST_RET == -1) {
> +               tst_res(TFAIL | TTERRNO,
> "fsconfig(FSCONFIG_CMD_RECONFIGURE) failed");
> +               goto out;
> +       }
> +
> +       TST_EXP_VAL(tst_is_mounted_rw(abspath), 1);
> +       tst_res(TPASS, "%s: fspick() passed", tc->name);
>  out:
>         SAFE_CLOSE(fspick_fd);
>  }
> --
> 2.43.0
>
>

-- 
Regards,
Li Wang


More information about the ltp mailing list