[LTP] [PATCH v1] fspick01.c: Check mount point was really remounted read only
Wei Gao
wegao@suse.com
Wed Aug 20 02:25:51 CEST 2025
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)
+{
+ 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,"))) {
+ 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
More information about the ltp
mailing list