* [LTP] [PATCH v1] fspick01.c: Check mount point was really remounted read only
@ 2025-08-20 0:25 Wei Gao via ltp
2025-08-22 0:05 ` Li Wang via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
0 siblings, 2 replies; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-20 0:25 UTC (permalink / raw)
To: 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.
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH v1] fspick01.c: Check mount point was really remounted read only
2025-08-20 0:25 [LTP] [PATCH v1] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
@ 2025-08-22 0:05 ` Li Wang via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
1 sibling, 0 replies; 15+ messages in thread
From: Li Wang via ltp @ 2025-08-22 0:05 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 0/2] fspick01.c: Check mount point was really remounted read only
2025-08-20 0:25 [LTP] [PATCH v1] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
2025-08-22 0:05 ` Li Wang via ltp
@ 2025-08-22 3:41 ` Wei Gao via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
` (2 more replies)
1 sibling, 3 replies; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 3:41 UTC (permalink / raw)
To: 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
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option
2025-08-22 3:41 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
@ 2025-08-22 3:41 ` Wei Gao via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
2025-08-22 4:03 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2 siblings, 0 replies; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 3:41 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_device.h | 2 ++
lib/tst_device.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/include/tst_device.h b/include/tst_device.h
index 2597fb4e2..3ea7b5500 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -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
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 6d1abf065..34f24be7d 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 2/2] fspick01.c: Check mount point was really remounted read only
2025-08-22 3:41 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
@ 2025-08-22 3:41 ` Wei Gao via ltp
2025-08-22 3:47 ` Li Wang via ltp
2025-08-22 4:03 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2 siblings, 1 reply; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 3:41 UTC (permalink / raw)
To: 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.
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/fspick/fspick01.c | 23 ++-
ver_linux | 191 --------------------
2 files changed, 22 insertions(+), 192 deletions(-)
delete mode 100755 ver_linux
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);
+
+ 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);
}
diff --git a/ver_linux b/ver_linux
deleted file mode 100755
index 4333575d3..000000000
--- a/ver_linux
+++ /dev/null
@@ -1,191 +0,0 @@
-#!/bin/sh
-# Before running this script please ensure that your PATH is
-# typical as you use for compilation/istallation. I use
-# /bin /sbin /usr/bin /usr/sbin /usr/local/bin, but it may
-# differ on your system.
-
-PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
-
-tst_cmd_available()
-{
- if type command > /dev/null 2>&1; then
- command -v $1 > /dev/null 2>&1 || return 1
- else
- which $1 > /dev/null 2>&1
- if [ $? -eq 0 ]; then
- return 0
- else
- return 1
- fi
- fi
-}
-
-tst_cmd_run()
-{
- local cmd="$1"
- shift
- tst_cmd_available $cmd && eval "$cmd $@"
-}
-
-is_enabled()
-{
- [ -f "$1" ] && [ "$(cat $1)" = "Y" -o "$(cat $1)" = "1" ]
-}
-
-echo 'If some fields are empty or look unusual you may have an old version.'
-echo 'Compare to the current minimal requirements in Documentation/Changes.'
-
-echo
-echo "`ls /etc/*release 2> /dev/null`"
-cat /etc/*release 2> /dev/null
-if [ $? = 1 ]; then
- echo "`ls /usr/lib/*release 2> /dev/null`"
- cat /usr/lib/*release 2> /dev/null
-fi
-if [ $? = 1 ]; then
- echo '/etc/issue:'
- cat /etc/issue 2> /dev/null
-fi
-if [ $? = 1 ]; then
- echo 'lsb_release -a'
- lsb_release -a 2> /dev/null
-fi
-
-echo
-echo 'uname:'
-uname -a
-
-echo
-echo '/proc/cmdline'
-cat /proc/cmdline
-
-echo
-
-echo "Gnu C " `gcc --version 2>/dev/null | head -n 1`
-echo "Clang " `clang --version 2>/dev/null | head -n 1`
-
-make --version 2>&1 | awk -F, '{print $1}' | awk \
- '/GNU Make/{print "Gnu make ",$NF}'
-
-ld -v 2>&1 | awk -F\) '{print $1}' | awk \
- '/BFD/{print "binutils ",$NF}'
-
-mkswap -V 2>&1 | awk '{print "util-linux ", $NF}'
-
-mount --version 2>&1 | awk '{$1=$2=""; print "mount ", $0}'
-
-insmod -V 2>&1 | awk 'NR==1 {print "modutils ",$NF}'
-
-bcachefs version 2>&1 | grep "^[0-9]" | awk \
-'NR==1 {print "bcachefs ", $1}'
-
-mkfs.btrfs -V 2>&1 | grep "^mkfs.btrfs" | sed 's/,//' | awk \
-'NR==1 {print "btrfs ", $5}'
-
-tune2fs 2>&1 | grep "^tune2fs" | sed 's/,//' | awk \
-'NR==1 {print "e2fsprogs ", $2}'
-
-mkfs.exfat -V 2>&1 | grep "^exfatprogs" | sed 's/,//' | awk \
-'NR==1 {print "exfat ", $4}'
-
-mkfs.ntfs -V 2>&1 | grep "^mkntfs" | sed 's/,//' | awk \
-'NR==1 {$1="";print "ntfs ", $0}'
-
-mkfs.vfat 2>&1 | grep "^mkfs\." | sed 's/,//' | awk \
-'NR==1 {print "vfat ", $2}'
-
-mkfs.xfs -V 2>&1 | grep "^mkfs.xfs" | sed 's/,//' | awk \
-'NR==1 {print "xfs ", $3}'
-
-cardmgr -V 2>&1| grep version | awk \
-'NR==1{print "pcmcia-cs ", $3}'
-
-isdnctrl 2>&1 | grep version | awk \
-'NR==1{print "isdn4k-utils ", $NF}'
-
-printf "Linux C Library $($(ldd /bin/sh | \
-awk '/libc/{print $3}') 2>&1 | \
-grep -i -e libc.*version -e musl.*libc -e ^version)\n"
-
-ldd -v > /dev/null 2>&1 && ldd -v || ldd --version |head -n 1 | awk \
-'NR==1{print "Dynamic linker (ldd) ", $NF}'
-
-ls -l /usr/lib/lib{g,stdc}++.so 2>/dev/null | awk -F. \
- '{print "Linux C++ Library " $4"."$5"."$6}'
-
-ps --version 2>&1 | awk 'NR==1{print "Procps ", $NF}'
-
-ifconfig --version 2>&1 | grep tools | awk \
-'NR==1{print "Net-tools ", $NF}'
-
-ip -V 2>&1 | awk \
-'NR==1{print "iproute2 ", $NF}'
-
-ping -V 2>&1 | awk \
-'NR==1{print "iputils ", $NF}'
-
-ethtool --version | grep version 2>&1 | awk \
-'NR==1{print "ethtool ", $NF}'
-
-# Kbd needs 'loadkeys -h',
-loadkeys -h 2>&1 | awk \
-'(NR==1 && ($3 !~ /option/)) {print "Kbd ", $3}'
-
-# while console-tools needs 'loadkeys -V'.
-loadkeys -V 2>&1 | awk \
-'(NR==1 && ($2 ~ /console-tools/)) {print "Console-tools ", $3}'
-
-expr --v 2>&1 | awk 'NR==1{print "Sh-utils ", $NF}'
-
-echo
-if [ -e /proc/modules ]; then
- X=`cat /proc/modules | sed -e "s/ .*$//"`
- echo "Modules Loaded "$X
-fi
-
-echo
-echo 'cpuinfo:'
-tst_cmd_run lscpu || cat /proc/cpuinfo
-
-echo
-echo 'free reports:'
-free
-
-echo
-echo 'memory (/proc/meminfo):'
-cat /proc/meminfo
-
-echo
-echo 'available filesystems:'
-echo $(cut -f2 /proc/filesystems | sort -u)
-
-echo
-echo 'mounted filesystems (/proc/mounts):'
-cat /proc/mounts
-
-echo
-echo 'mounted filesystems (df):'
-if `df -hT >/dev/null 2>/dev/null`; then
- df -hT
-else
- df
-fi
-
-echo
-echo 'tainted (/proc/sys/kernel/tainted):'
-cat /proc/sys/kernel/tainted
-
-echo
-if is_enabled /sys/module/apparmor/parameters/enabled; then
- echo 'AppArmor enabled'
- tst_cmd_run aa-status
-else
- echo 'AppArmor disabled'
-fi
-
-echo
-
-if ! tst_cmd_run sestatus; then
- printf 'SELinux mode: '
- tst_cmd_run getenforce || echo 'unknown'
-fi
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH v2 2/2] fspick01.c: Check mount point was really remounted read only
2025-08-22 3:41 ` [LTP] [PATCH v2 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
@ 2025-08-22 3:47 ` Li Wang via ltp
0 siblings, 0 replies; 15+ messages in thread
From: Li Wang via ltp @ 2025-08-22 3:47 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
On Fri, Aug 22, 2025 at 11:42 AM 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 ++-
> ver_linux | 191 --------------------
>
I guess the deletion of ver_linux was a careless mistake?
Otherwise looks good.
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v2 0/2] fspick01.c: Check mount point was really remounted read only
2025-08-22 3:41 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
@ 2025-08-22 4:03 ` Wei Gao via ltp
2025-08-22 4:03 ` [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
` (2 more replies)
2 siblings, 3 replies; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 4:03 UTC (permalink / raw)
To: 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(-)
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option
2025-08-22 4:03 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
@ 2025-08-22 4:03 ` Wei Gao via ltp
2025-08-22 5:42 ` Li Wang via ltp
2025-08-22 4:03 ` [LTP] [PATCH v3 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 0/2] " Wei Gao via ltp
2 siblings, 1 reply; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 4:03 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_device.h | 2 ++
lib/tst_device.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/include/tst_device.h b/include/tst_device.h
index 2597fb4e2..3ea7b5500 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -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
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 6d1abf065..34f24be7d 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v3 2/2] fspick01.c: Check mount point was really remounted read only
2025-08-22 4:03 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2025-08-22 4:03 ` [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
@ 2025-08-22 4:03 ` Wei Gao via ltp
2025-08-22 5:38 ` Li Wang via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 0/2] " Wei Gao via ltp
2 siblings, 1 reply; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 4:03 UTC (permalink / raw)
To: 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.
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);
+
+ 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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH v3 2/2] fspick01.c: Check mount point was really remounted read only
2025-08-22 4:03 ` [LTP] [PATCH v3 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
@ 2025-08-22 5:38 ` Li Wang via ltp
0 siblings, 0 replies; 15+ messages in thread
From: Li Wang via ltp @ 2025-08-22 5:38 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option
2025-08-22 4:03 ` [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
@ 2025-08-22 5:42 ` Li Wang via ltp
0 siblings, 0 replies; 15+ messages in thread
From: Li Wang via ltp @ 2025-08-22 5:42 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
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;
}
On Fri, Aug 22, 2025 at 12:05 PM Wei Gao <wegao@suse.com> wrote:
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> include/tst_device.h | 2 ++
> lib/tst_device.c | 42 ++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 44 insertions(+)
>
> diff --git a/include/tst_device.h b/include/tst_device.h
> index 2597fb4e2..3ea7b5500 100644
> --- a/include/tst_device.h
> +++ b/include/tst_device.h
> @@ -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
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index 6d1abf065..34f24be7d 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -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
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v4 0/2] fspick01.c: Check mount point was really remounted read only
2025-08-22 4:03 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2025-08-22 4:03 ` [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
2025-08-22 4:03 ` [LTP] [PATCH v3 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
@ 2025-08-22 6:33 ` Wei Gao via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
2 siblings, 2 replies; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 6:33 UTC (permalink / raw)
To: 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(-)
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
* [LTP] [PATCH v4 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option
2025-08-22 6:33 ` [LTP] [PATCH v4 0/2] " Wei Gao via ltp
@ 2025-08-22 6:33 ` Wei Gao via ltp
2025-08-22 7:01 ` Li Wang via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
1 sibling, 1 reply; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 6:33 UTC (permalink / raw)
To: ltp
Signed-off-by: Wei Gao <wegao@suse.com>
---
include/tst_device.h | 2 ++
lib/tst_device.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+)
diff --git a/include/tst_device.h b/include/tst_device.h
index 2597fb4e2..3ea7b5500 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -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
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 6d1abf065..7f9a2b2f6 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -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) {
+ 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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [LTP] [PATCH v4 2/2] fspick01.c: Check mount point was really remounted read only
2025-08-22 6:33 ` [LTP] [PATCH v4 0/2] " Wei Gao via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
@ 2025-08-22 6:33 ` Wei Gao via ltp
1 sibling, 0 replies; 15+ messages in thread
From: Wei Gao via ltp @ 2025-08-22 6:33 UTC (permalink / raw)
To: 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.
Signed-off-by: Wei Gao <wegao@suse.com>
---
testcases/kernel/syscalls/fspick/fspick01.c | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/testcases/kernel/syscalls/fspick/fspick01.c b/testcases/kernel/syscalls/fspick/fspick01.c
index d03cacd3d..dab2bd75e 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}
@@ -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);
}
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [LTP] [PATCH v4 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option
2025-08-22 6:33 ` [LTP] [PATCH v4 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
@ 2025-08-22 7:01 ` Li Wang via ltp
0 siblings, 0 replies; 15+ messages in thread
From: Li Wang via ltp @ 2025-08-22 7:01 UTC (permalink / raw)
To: Wei Gao; +Cc: ltp
On Fri, Aug 22, 2025 at 2:33 PM Wei Gao <wegao@suse.com> wrote:
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> include/tst_device.h | 2 ++
> lib/tst_device.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 50 insertions(+)
>
> diff --git a/include/tst_device.h b/include/tst_device.h
> index 2597fb4e2..3ea7b5500 100644
> --- a/include/tst_device.h
> +++ b/include/tst_device.h
> @@ -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
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index 6d1abf065..7f9a2b2f6 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -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) {
> + ret = 1;
> + break;
> + }
> + tok = strtok(NULL, ",");
> + }
> + if (ret)
> + break;
> + }
> +
>
Patch set pushed with minor adjustments, thank you.
+ SAFE_FCLOSE(NULL, file);
+ 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
>
>
--
Regards,
Li Wang
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-08-22 7:01 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-20 0:25 [LTP] [PATCH v1] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
2025-08-22 0:05 ` Li Wang via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
2025-08-22 3:41 ` [LTP] [PATCH v2 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
2025-08-22 3:47 ` Li Wang via ltp
2025-08-22 4:03 ` [LTP] [PATCH v2 0/2] " Wei Gao via ltp
2025-08-22 4:03 ` [LTP] [PATCH v3 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
2025-08-22 5:42 ` Li Wang via ltp
2025-08-22 4:03 ` [LTP] [PATCH v3 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
2025-08-22 5:38 ` Li Wang via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 0/2] " Wei Gao via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 1/2] tst_device.c: Add tst_is_mounted_ro/w check mount option Wei Gao via ltp
2025-08-22 7:01 ` Li Wang via ltp
2025-08-22 6:33 ` [LTP] [PATCH v4 2/2] fspick01.c: Check mount point was really remounted read only Wei Gao via ltp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).