Skip to contentSkip to conversation

fspick01.c: Check mount point was really remounted read only

PATCH Superseded Wei Gao via ltp 1 participant 15 messages Aug 20, 2025 – Aug 22, 2025 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fspick01.c: Check mount point was really remounted read only

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.

---
 testcases/kernel/syscalls/fspick/fspick01.c | 43 ++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/fspick/fspick01.c +42 -1
index d03cacd3d..c2ad369d4 100644
@@ -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);
 }
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wei,

Quoted 24 lines · Wei Gao via ltp

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.

---
 testcases/kernel/syscalls/fspick/fspick01.c | 43 ++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/fspick/fspick01.c +1 -0
index d03cacd3d..c2ad369d4 100644
@@ -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}

testcases/kernel/syscalls/fspick/fspick01.c static struct tcase { · line 25

Quoted 5 lines
testcases/kernel/syscalls/fspick/fspick01.c +1 -0
@@ -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.

Quoted 12 lines
testcases/kernel/syscalls/fspick/fspick01.c +7 -0
+{
+       char line[PATH_MAX];
+       FILE *file;
+       int ret = 0;
+
+       file = SAFE_FOPEN("/proc/mounts", "r");
+
 
 
 
 

testcases/kernel/syscalls/fspick/fspick01.c static struct tcase { · line 46

Quoted 10 lines
testcases/kernel/syscalls/fspick/fspick01.c +7 -0
+       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;

Quoted 56 lines
testcases/kernel/syscalls/fspick/fspick01.c +25 -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

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

v2 cover fspick01.c: Check mount point was really remounted read only

In reply to Wei Gao via ltp

Wei Gao (2):
tst_device.c: Add tst_is_mounted_ro/w check mount option fspick01.c: Check mount point was really remounted read only

 include/tst_device.h                        |   2 +
 lib/tst_device.c                            |  42 +++++
 testcases/kernel/syscalls/fspick/fspick01.c |  23 ++-
 ver_linux                                   | 191 --------------------
 4 files changed, 66 insertions(+), 192 deletions(-)
 delete mode 100755 ver_linux
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v2 1/2 tst_device.c: Add tst_is_mounted_ro/w check mount option

---
 include/tst_device.h |  2 ++
 lib/tst_device.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
include/tst_device.h +2 -0
index 2597fb4e2..3ea7b5500 100644
@@ -34,6 +34,8 @@ int tst_umount(const char *path);
  */
 int tst_is_mounted(const char *path);
 int tst_is_mounted_at_tmpdir(const char *path);
+int tst_is_mounted_ro(const char *path);
+int tst_is_mounted_rw(const char *path);
 
 /*
  * Clears a first few blocks of the device. This is needed when device has
lib/tst_device.c +42 -0

48 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

PATCH v2 2/2 fspick01.c: Check mount point was really remounted read only

In reply to Wei Gao via ltp

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.

---
 testcases/kernel/syscalls/fspick/fspick01.c |  23 ++-
 ver_linux                                   | 191 --------------------
 2 files changed, 22 insertions(+), 192 deletions(-)
 delete mode 100755 ver_linux
testcases/kernel/syscalls/fspick/fspick01.c +22 -1
index d03cacd3d..8cb2d3669 100644
@@ -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);
+
+	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);
 }
ver_linux deleted +0 -191

191 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
Quoted 10 lines · Wei Gao

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.

---
 testcases/kernel/syscalls/fspick/fspick01.c |  23 ++-
 ver_linux                                   | 191 --------------------

I guess the deletion of ver_linux was a careless mistake?

Otherwise looks good.

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

v2 cover fspick01.c: Check mount point was really remounted read only

In reply to Wei Gao via ltp

Wei Gao (2):
tst_device.c: Add tst_is_mounted_ro/w check mount option fspick01.c: Check mount point was really remounted read only

 include/tst_device.h                        |  2 +
 lib/tst_device.c                            | 42 +++++++++++++++++++++
 testcases/kernel/syscalls/fspick/fspick01.c | 23 ++++++++++-
 3 files changed, 66 insertions(+), 1 deletion(-)
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v3 1/2 tst_device.c: Add tst_is_mounted_ro/w check mount option

---
 include/tst_device.h |  2 ++
 lib/tst_device.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
include/tst_device.h +2 -0
index 2597fb4e2..3ea7b5500 100644
@@ -34,6 +34,8 @@ int tst_umount(const char *path);
  */
 int tst_is_mounted(const char *path);
 int tst_is_mounted_at_tmpdir(const char *path);
+int tst_is_mounted_ro(const char *path);
+int tst_is_mounted_rw(const char *path);
 
 /*
  * Clears a first few blocks of the device. This is needed when device has
lib/tst_device.c +42 -0

48 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option

Once we created the more generic function tst_mount_has_opt(), the tst_is_mounted() could be simply rewritten in:

(We/I can do this in a separate patch)

int tst_is_mounted(const char *path)

{
        int ret = tst_mount_has_opt(path, NULL);
        if (!ret)
                tst_resm(TINFO, "No device is mounted at %s", path);

        return ret;

}

Quoted 77 lines · Wei Gao
---
 include/tst_device.h |  2 ++
 lib/tst_device.c     | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
include/tst_device.h +2 -0
index 2597fb4e2..3ea7b5500 100644
@@ -34,6 +34,8 @@ int tst_umount(const char *path);
  */
 int tst_is_mounted(const char *path);
 int tst_is_mounted_at_tmpdir(const char *path);
+int tst_is_mounted_ro(const char *path);
+int tst_is_mounted_rw(const char *path);
 
 /*
  * Clears a first few blocks of the device. This is needed when device has
lib/tst_device.c +42 -0
index 6d1abf065..34f24be7d 100644
@@ -473,6 +473,48 @@ int tst_is_mounted_at_tmpdir(const char *path)
        return tst_is_mounted(mpath);
 }
 
+static int tst_mount_has_opt(const char *path, const char *opt)
+{
+       char line[PATH_MAX];
+       FILE *file;
+       int ret = 0;
+
+       file = SAFE_FOPEN(NULL, "/proc/mounts", "r");
+
+       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;
+       }
+
+       return ret;
+}
+
+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");
+}
+
 static int find_stat_file(const char *dev, char *path, size_t path_len)
 {
        const char *devname = strrchr(dev, '/') + 1;

--
2.43.0

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

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

In reply to Wei Gao via ltp

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.

---
 testcases/kernel/syscalls/fspick/fspick01.c | 23 ++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/fspick/fspick01.c +22 -1
index d03cacd3d..8cb2d3669 100644
@@ -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);
+
+	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);
 }
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw
Quoted 26 lines · Wei Gao

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.

---
 testcases/kernel/syscalls/fspick/fspick01.c | 23 ++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/fspick/fspick01.c +1 -0
index d03cacd3d..8cb2d3669 100644
@@ -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)
 {

testcases/kernel/syscalls/fspick/fspick01.c static void run(unsigned int n)

Quoted 10 lines
testcases/kernel/syscalls/fspick/fspick01.c +4 -0
        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:

lib/tst_device.c +0 -0
@@ -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) {
Quoted 35 lines
testcases/kernel/syscalls/fspick/fspick01.c +17 -1
+
+       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

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

v4 cover fspick01.c: Check mount point was really remounted read only

In reply to Wei Gao via ltp

Wei Gao (2):
tst_device.c: Add tst_is_mounted_ro/w check mount option fspick01.c: Check mount point was really remounted read only

 include/tst_device.h                        |  2 +
 lib/tst_device.c                            | 48 +++++++++++++++++++++
 testcases/kernel/syscalls/fspick/fspick01.c | 19 +++++++-
 3 files changed, 68 insertions(+), 1 deletion(-)
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

PATCH v4 1/2 tst_device.c: Add tst_is_mounted_ro/w check mount option

---
 include/tst_device.h |  2 ++
 lib/tst_device.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
include/tst_device.h +2 -0
index 2597fb4e2..3ea7b5500 100644
@@ -34,6 +34,8 @@ int tst_umount(const char *path);
  */
 int tst_is_mounted(const char *path);
 int tst_is_mounted_at_tmpdir(const char *path);
+int tst_is_mounted_ro(const char *path);
+int tst_is_mounted_rw(const char *path);
 
 /*
  * Clears a first few blocks of the device. This is needed when device has
lib/tst_device.c +48 -0

54 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

Re: [LTP] [PATCH v4 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option

Quoted 54 lines · Wei Gao
---
 include/tst_device.h |  2 ++
 lib/tst_device.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)
include/tst_device.h +2 -0
index 2597fb4e2..3ea7b5500 100644
@@ -34,6 +34,8 @@ int tst_umount(const char *path);
  */
 int tst_is_mounted(const char *path);
 int tst_is_mounted_at_tmpdir(const char *path);
+int tst_is_mounted_ro(const char *path);
+int tst_is_mounted_rw(const char *path);
 
 /*
  * Clears a first few blocks of the device. This is needed when device has
lib/tst_device.c +26 -0
index 6d1abf065..7f9a2b2f6 100644
@@ -473,6 +473,54 @@ int tst_is_mounted_at_tmpdir(const char *path)
        return tst_is_mounted(mpath);
 }
 
+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");
+
+       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, abspath) != 0)
+                       continue;
+
+               char *tok = strtok(options, ",");
+               while (tok) {
+                       if (strcmp(tok, opt) == 0) {

lib/tst_device.c int tst_is_mounted_at_tmpdir(const char *path) · line 512

Quoted 10 lines
lib/tst_device.c +9 -0
+                               ret = 1;
+                               break;
+                       }
+                       tok = strtok(NULL, ",");
+               }
+               if (ret)
+                       break;
+       }
+
 

Patch set pushed with minor adjustments, thank you.

+ SAFE_FCLOSE(NULL, file);

+ return ret;

Quoted 19 lines
lib/tst_device.c +12 -1
+}
+
+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");
+}
+
 static int find_stat_file(const char *dev, char *path, size_t path_len)
 {
        const char *devname = strrchr(dev, '/') + 1;
--

2.43.0

Signature · 5 lines
Regards,
Li Wang

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH v4 2/2 fspick01.c: Check mount point was really remounted read only

In reply to Wei Gao via ltp

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.

---
 testcases/kernel/syscalls/fspick/fspick01.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/fspick/fspick01.c +18 -1
index d03cacd3d..dab2bd75e 100644
@@ -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}
@@ -25,6 +26,8 @@ static void run(unsigned int n)
 	struct tcase *tc = &tcases[n];
 	int fspick_fd;
 
+	TST_EXP_VAL(tst_is_mounted_rw(MNTPOINT), 1);
+
 	TEST(fspick_fd = fspick(AT_FDCWD, MNTPOINT, tc->flags));
 	if (fspick_fd == -1) {
 		tst_res(TFAIL | TTERRNO, "fspick() failed");
@@ -49,8 +52,22 @@ static void run(unsigned int n)
 		goto out;
 	}
 
-	tst_res(TPASS, "%s: fspick() passed", tc->name);
+	TST_EXP_VAL(tst_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_EXP_VAL(tst_is_mounted_rw(MNTPOINT), 1);
+	tst_res(TPASS, "%s: fspick() passed", tc->name);
 out:
 	SAFE_CLOSE(fspick_fd);
 }
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp