[LTP] [PATCH v1] fspick01.c: Check mount point was really remounted read only
Li Wang
liwang@redhat.com
Fri Aug 22 02:05:38 CEST 2025
Hi Wei,
On Wed, Aug 20, 2025 at 8:26 AM Wei Gao via ltp <ltp@lists.linux.it> 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 | 43 ++++++++++++++++++++-
> 1 file changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/fspick/fspick01.c
> b/testcases/kernel/syscalls/fspick/fspick01.c
> index d03cacd3d..c2ad369d4 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}
> @@ -20,11 +21,38 @@ static struct tcase {
> TCASE_ENTRY(FSPICK_EMPTY_PATH),
> };
>
> +static int is_mounted_ro(const char *path)
>
Maybe we can consider refactoring this function as a more generic,
e.g. tst_mount_has_opt(const char *path, const char *opt) and move
it into tst_device.c file?
static int tst_mount_has_opt(const char *path, const char *opt)
{
...
}
int tst_is_mounted_ro(const char *path)
{
return tst_mount_has_opt(path, "ro");
}
int tst_is_mounted_rw(const char *path)
{
return tst_mount_has_opt(path, "rw");
}
People can call tst_is_mounted_ro(path) or tst_is_mounted_rw(path) directly.
> +{
> + char line[PATH_MAX];
> + FILE *file;
> + int ret = 0;
> +
> + file = SAFE_FOPEN("/proc/mounts", "r");
> +
>
> + while (fgets(line, sizeof(line), file)) {
> + char dev[PATH_MAX], mount_point[PATH_MAX],
> fstype[PATH_MAX], options[PATH_MAX];
> +
> + if (sscanf(line, "%s %s %s %s", dev, mount_point, fstype,
> options) < 4)
> + continue;
> +
> + if (strstr(mount_point, path) && (strstr(options, "ro,")))
> {
>
strstr(mount_point, path) may give false positives (e.g. /mnt will match
/mnt2).
Better to use strcmp() or prefix matching with / boundaries.
How about this:
while (fgets(line, sizeof(line), file)) {
char mount_point[PATH_MAX], options[PATH_MAX];
if (sscanf(line, "%*s %s %*s %s", mount_point, options) < 2)
continue;
if (strcmp(mount_point, path) != 0)
continue;
char *tok = strtok(options, ",");
while (tok) {
if (strcmp(tok, opt) == 0) {
ret = 1;
break;
}
tok = strtok(NULL, ",");
}
if (ret)
break;
}
+ ret = 1;
> + break;
> + }
> + }
> +
>
> + SAFE_FCLOSE(file);
> +
> + return ret;
> +}
> +
> static void run(unsigned int n)
> {
> struct tcase *tc = &tcases[n];
> int fspick_fd;
>
> + TST_EXP_VAL(is_mounted_ro(MNTPOINT), 0);
> +
> TEST(fspick_fd = fspick(AT_FDCWD, MNTPOINT, tc->flags));
> if (fspick_fd == -1) {
> tst_res(TFAIL | TTERRNO, "fspick() failed");
> @@ -49,8 +77,21 @@ static void run(unsigned int n)
> goto out;
> }
>
> - tst_res(TPASS, "%s: fspick() passed", tc->name);
> + TST_EXP_VAL(is_mounted_ro(MNTPOINT), 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_res(TPASS, "%s: fspick() passed", tc->name);
> out:
> SAFE_CLOSE(fspick_fd);
> }
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
--
Regards,
Li Wang
More information about the ltp
mailing list