ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted()
@ 2025-08-22  7:22 Li Wang via ltp
  2025-08-22  7:22 ` [LTP] [PATCH 2/2] mount05: check if mount path exist before tst_is_mounted Li Wang via ltp
  2025-08-22  7:45 ` [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted() Wei Gao via ltp
  0 siblings, 2 replies; 9+ messages in thread
From: Li Wang via ltp @ 2025-08-22  7:22 UTC (permalink / raw)
  To: ltp

Refactor tst_is_mounted() to reuse tst_mount_has_opt() instead of
parsing /proc/mounts with strstr(). This makes the check more
accurate and consistent with tst_is_mounted_ro()/rw().

Also moved tst_is_mounted_at_tmpdir() below for consistency.

Signed-off-by: Li Wang <liwang@redhat.com>
Cc: Wei Gao <wegao@suse.com>
---
 lib/tst_device.c | 79 +++++++++++++++++++++---------------------------
 1 file changed, 35 insertions(+), 44 deletions(-)

diff --git a/lib/tst_device.c b/lib/tst_device.c
index b610cf14b..5b0498c03 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -429,50 +429,6 @@ int tst_umount(const char *path)
 	return -1;
 }
 
-int tst_is_mounted(const char *path)
-{
-	char line[PATH_MAX];
-	FILE *file;
-	int ret = 0;
-
-	file = SAFE_FOPEN(NULL, "/proc/mounts", "r");
-
-	while (fgets(line, sizeof(line), file)) {
-		if (strstr(line, path) != NULL) {
-			ret = 1;
-			break;
-		}
-	}
-
-	SAFE_FCLOSE(NULL, file);
-
-	if (!ret)
-		tst_resm(TINFO, "No device is mounted at %s", path);
-
-	return ret;
-}
-
-int tst_is_mounted_at_tmpdir(const char *path)
-{
-	char cdir[PATH_MAX], mpath[PATH_MAX];
-	int ret;
-
-	if (!getcwd(cdir, PATH_MAX)) {
-		tst_resm(TWARN | TERRNO, "Failed to find current directory");
-		return 0;
-	}
-
-	ret = snprintf(mpath, PATH_MAX, "%s/%s", cdir, path);
-	if (ret < 0 || ret >= PATH_MAX) {
-		tst_resm(TWARN | TERRNO,
-			 "snprintf() should have returned %d instead of %d",
-			 PATH_MAX, ret);
-		return 0;
-	}
-
-	return tst_is_mounted(mpath);
-}
-
 static int tst_mount_has_opt(const char *path, const char *opt)
 {
 	char line[PATH_MAX];
@@ -496,6 +452,11 @@ static int tst_mount_has_opt(const char *path, const char *opt)
 		if (strcmp(mount_point, abspath) != 0)
 			continue;
 
+		if (!opt) {
+			ret = 1;
+			break;
+		}
+
 		char *tok = strtok(options, ",");
 		while (tok) {
 			if (strcmp(tok, opt) == 0) {
@@ -512,6 +473,15 @@ static int tst_mount_has_opt(const char *path, const char *opt)
 	return ret;
 }
 
+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;
+}
+
 int tst_is_mounted_ro(const char *path)
 {
 	return tst_mount_has_opt(path, "ro");
@@ -522,6 +492,27 @@ int tst_is_mounted_rw(const char *path)
 	return tst_mount_has_opt(path, "rw");
 }
 
+int tst_is_mounted_at_tmpdir(const char *path)
+{
+	char cdir[PATH_MAX], mpath[PATH_MAX];
+	int ret;
+
+	if (!getcwd(cdir, PATH_MAX)) {
+		tst_resm(TWARN | TERRNO, "Failed to find current directory");
+		return 0;
+	}
+
+	ret = snprintf(mpath, PATH_MAX, "%s/%s", cdir, path);
+	if (ret < 0 || ret >= PATH_MAX) {
+		tst_resm(TWARN | TERRNO,
+			 "snprintf() should have returned %d instead of %d",
+			 PATH_MAX, ret);
+		return 0;
+	}
+
+	return tst_is_mounted(mpath);
+}
+
 static int find_stat_file(const char *dev, char *path, size_t path_len)
 {
 	const char *devname = strrchr(dev, '/') + 1;
-- 
2.49.0


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [LTP] [PATCH 2/2] mount05: check if mount path exist before tst_is_mounted
  2025-08-22  7:22 [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted() Li Wang via ltp
@ 2025-08-22  7:22 ` Li Wang via ltp
  2025-08-22  7:28   ` Li Wang via ltp
  2025-08-22  7:45 ` [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted() Wei Gao via ltp
  1 sibling, 1 reply; 9+ messages in thread
From: Li Wang via ltp @ 2025-08-22  7:22 UTC (permalink / raw)
  To: ltp

tst_is_mounted() now internally resolves the mount path via realpath(),
which will fail if the path does not exist. In mount05, MNTPOINT2 may
not always be created during the test flow, so calling tst_is_mounted()
directly could produce misleading warnings or errors.

Add an explicit access(MNTPOINT2, F_OK) check before calling
tst_is_mounted(), ensuring we only query mounts for existing paths.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/syscalls/mount/mount05.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/mount/mount05.c b/testcases/kernel/syscalls/mount/mount05.c
index 66e102a32..5585e230e 100644
--- a/testcases/kernel/syscalls/mount/mount05.c
+++ b/testcases/kernel/syscalls/mount/mount05.c
@@ -35,7 +35,7 @@ static void cleanup(void)
 	if (tst_is_mounted(MNTPOINT1))
 		SAFE_UMOUNT(MNTPOINT1);
 
-	if (tst_is_mounted(MNTPOINT2))
+	if (!access(MNTPOINT2, F_OK) && tst_is_mounted(MNTPOINT2))
 		SAFE_UMOUNT(MNTPOINT2);
 }
 
-- 
2.49.0


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH 2/2] mount05: check if mount path exist before tst_is_mounted
  2025-08-22  7:22 ` [LTP] [PATCH 2/2] mount05: check if mount path exist before tst_is_mounted Li Wang via ltp
@ 2025-08-22  7:28   ` Li Wang via ltp
  2025-08-22  7:48     ` [LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup Li Wang via ltp
  0 siblings, 1 reply; 9+ messages in thread
From: Li Wang via ltp @ 2025-08-22  7:28 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

On Fri, Aug 22, 2025 at 3:24 PM Li Wang via ltp <ltp@lists.linux.it> wrote:

> tst_is_mounted() now internally resolves the mount path via realpath(),
>


> which will fail if the path does not exist. In mount05, MNTPOINT2 may
> not always be created during the test flow, so calling tst_is_mounted()
>

This line was forgotten to amend in my git log:

"In mount05, MNTPOINT2 may not exist yet during cleanup. "

directly could produce misleading warnings or errors.
>
> Add an explicit access(MNTPOINT2, F_OK) check before calling
> tst_is_mounted(), ensuring we only query mounts for existing paths.
>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
>  testcases/kernel/syscalls/mount/mount05.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/syscalls/mount/mount05.c
> b/testcases/kernel/syscalls/mount/mount05.c
> index 66e102a32..5585e230e 100644
> --- a/testcases/kernel/syscalls/mount/mount05.c
> +++ b/testcases/kernel/syscalls/mount/mount05.c
> @@ -35,7 +35,7 @@ static void cleanup(void)
>         if (tst_is_mounted(MNTPOINT1))
>                 SAFE_UMOUNT(MNTPOINT1);
>
> -       if (tst_is_mounted(MNTPOINT2))
> +       if (!access(MNTPOINT2, F_OK) && tst_is_mounted(MNTPOINT2))
>                 SAFE_UMOUNT(MNTPOINT2);
>  }
>
> --
> 2.49.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] 9+ messages in thread

* Re: [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted()
  2025-08-22  7:22 [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted() Li Wang via ltp
  2025-08-22  7:22 ` [LTP] [PATCH 2/2] mount05: check if mount path exist before tst_is_mounted Li Wang via ltp
@ 2025-08-22  7:45 ` Wei Gao via ltp
  2025-08-26  1:16   ` Li Wang via ltp
  1 sibling, 1 reply; 9+ messages in thread
From: Wei Gao via ltp @ 2025-08-22  7:45 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

On Fri, Aug 22, 2025 at 03:22:03PM +0800, Li Wang wrote:
> Refactor tst_is_mounted() to reuse tst_mount_has_opt() instead of
> parsing /proc/mounts with strstr(). This makes the check more
> accurate and consistent with tst_is_mounted_ro()/rw().
> 
> Also moved tst_is_mounted_at_tmpdir() below for consistency.
> 
> Signed-off-by: Li Wang <liwang@redhat.com>
> Cc: Wei Gao <wegao@suse.com>
> ---
>  lib/tst_device.c | 79 +++++++++++++++++++++---------------------------
>  1 file changed, 35 insertions(+), 44 deletions(-)
> 
> diff --git a/lib/tst_device.c b/lib/tst_device.c
> index b610cf14b..5b0498c03 100644
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -429,50 +429,6 @@ int tst_umount(const char *path)
>  	return -1;
>  }
>  
> -int tst_is_mounted(const char *path)
> -{
> -	char line[PATH_MAX];
> -	FILE *file;
> -	int ret = 0;
> -
> -	file = SAFE_FOPEN(NULL, "/proc/mounts", "r");
> -
> -	while (fgets(line, sizeof(line), file)) {
> -		if (strstr(line, path) != NULL) {
> -			ret = 1;
> -			break;
> -		}
> -	}
> -
> -	SAFE_FCLOSE(NULL, file);
> -
> -	if (!ret)
> -		tst_resm(TINFO, "No device is mounted at %s", path);
> -
> -	return ret;
> -}
> -
> -int tst_is_mounted_at_tmpdir(const char *path)
> -{
> -	char cdir[PATH_MAX], mpath[PATH_MAX];
> -	int ret;
> -
> -	if (!getcwd(cdir, PATH_MAX)) {
> -		tst_resm(TWARN | TERRNO, "Failed to find current directory");
> -		return 0;
> -	}
> -
> -	ret = snprintf(mpath, PATH_MAX, "%s/%s", cdir, path);
> -	if (ret < 0 || ret >= PATH_MAX) {
> -		tst_resm(TWARN | TERRNO,
> -			 "snprintf() should have returned %d instead of %d",
> -			 PATH_MAX, ret);
> -		return 0;
> -	}
> -
> -	return tst_is_mounted(mpath);
> -}
> -
>  static int tst_mount_has_opt(const char *path, const char *opt)
>  {
>  	char line[PATH_MAX];
> @@ -496,6 +452,11 @@ static int tst_mount_has_opt(const char *path, const char *opt)
>  		if (strcmp(mount_point, abspath) != 0)
>  			continue;
>  
> +		if (!opt) {
> +			ret = 1;
> +			break;
> +		}
> +
>  		char *tok = strtok(options, ",");
>  		while (tok) {
>  			if (strcmp(tok, opt) == 0) {
> @@ -512,6 +473,15 @@ static int tst_mount_has_opt(const char *path, const char *opt)
>  	return ret;
>  }
>  
> +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;
> +}
> +
>  int tst_is_mounted_ro(const char *path)
>  {
>  	return tst_mount_has_opt(path, "ro");
> @@ -522,6 +492,27 @@ int tst_is_mounted_rw(const char *path)
>  	return tst_mount_has_opt(path, "rw");
>  }
>  
> +int tst_is_mounted_at_tmpdir(const char *path)
> +{
> +	char cdir[PATH_MAX], mpath[PATH_MAX];
> +	int ret;
> +
> +	if (!getcwd(cdir, PATH_MAX)) {
> +		tst_resm(TWARN | TERRNO, "Failed to find current directory");
> +		return 0;
> +	}
> +
> +	ret = snprintf(mpath, PATH_MAX, "%s/%s", cdir, path);
> +	if (ret < 0 || ret >= PATH_MAX) {
> +		tst_resm(TWARN | TERRNO,
> +			 "snprintf() should have returned %d instead of %d",
> +			 PATH_MAX, ret);
> +		return 0;
> +	}
> +
> +	return tst_is_mounted(mpath);
> +}
> +
>  static int find_stat_file(const char *dev, char *path, size_t path_len)
>  {
>  	const char *devname = strrchr(dev, '/') + 1;
> -- 
> 2.49.0
> 
Thanks for your patch!
Reviewed-by: Wei Gao <wegao@suse.com>



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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup
  2025-08-22  7:28   ` Li Wang via ltp
@ 2025-08-22  7:48     ` Li Wang via ltp
  2025-08-22  8:02       ` Wei Gao via ltp
  0 siblings, 1 reply; 9+ messages in thread
From: Li Wang via ltp @ 2025-08-22  7:48 UTC (permalink / raw)
  To: ltp

tst_is_mounted() now internally resolves the mount path via realpath(),
which will fail if the path does not exist. In sometest (e.g. mount05),
MNTPOINT2 may not exist yet during cleanup, calling tst_is_mounted()
directly could produce misleading warnings or errors.

Add an explicit access(PATH, F_OK) check before calling tst_is_mounted()
in the cleanup, ensuring we only query mounts for existing paths.

Signed-off-by: Li Wang <liwang@redhat.com>
---

Notes:
    v1 --> v2:
            patch 1/2, keep no change, do not send v2.
            patch 2/2, adding two more files for path exist check

 testcases/kernel/containers/mqns/mqns_03.c | 2 +-
 testcases/kernel/containers/mqns/mqns_04.c | 2 +-
 testcases/kernel/syscalls/mount/mount05.c  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/containers/mqns/mqns_03.c b/testcases/kernel/containers/mqns/mqns_03.c
index 4d3bfc52f..ac8311559 100644
--- a/testcases/kernel/containers/mqns/mqns_03.c
+++ b/testcases/kernel/containers/mqns/mqns_03.c
@@ -130,7 +130,7 @@ static void cleanup(void)
 	if (!access(MQUEUE2, F_OK))
 		SAFE_MQ_UNLINK(MQNAME2);
 
-	if (tst_is_mounted(DEVDIR))
+	if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
 		SAFE_UMOUNT(DEVDIR);
 }
 
diff --git a/testcases/kernel/containers/mqns/mqns_04.c b/testcases/kernel/containers/mqns/mqns_04.c
index d28c330c4..790607ecd 100644
--- a/testcases/kernel/containers/mqns/mqns_04.c
+++ b/testcases/kernel/containers/mqns/mqns_04.c
@@ -123,7 +123,7 @@ static void cleanup(void)
 	if (!access(MQUEUE2, F_OK))
 		SAFE_MQ_UNLINK(MQNAME2);
 
-	if (tst_is_mounted(DEVDIR))
+	if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
 		SAFE_UMOUNT(DEVDIR);
 }
 
diff --git a/testcases/kernel/syscalls/mount/mount05.c b/testcases/kernel/syscalls/mount/mount05.c
index 66e102a32..5585e230e 100644
--- a/testcases/kernel/syscalls/mount/mount05.c
+++ b/testcases/kernel/syscalls/mount/mount05.c
@@ -35,7 +35,7 @@ static void cleanup(void)
 	if (tst_is_mounted(MNTPOINT1))
 		SAFE_UMOUNT(MNTPOINT1);
 
-	if (tst_is_mounted(MNTPOINT2))
+	if (!access(MNTPOINT2, F_OK) && tst_is_mounted(MNTPOINT2))
 		SAFE_UMOUNT(MNTPOINT2);
 }
 
-- 
2.49.0


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

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup
  2025-08-22  7:48     ` [LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup Li Wang via ltp
@ 2025-08-22  8:02       ` Wei Gao via ltp
  2025-08-22  8:12         ` Li Wang via ltp
  0 siblings, 1 reply; 9+ messages in thread
From: Wei Gao via ltp @ 2025-08-22  8:02 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

On Fri, Aug 22, 2025 at 03:48:11PM +0800, Li Wang via ltp wrote:
> tst_is_mounted() now internally resolves the mount path via realpath(),
> which will fail if the path does not exist. In sometest (e.g. mount05),
> MNTPOINT2 may not exist yet during cleanup, calling tst_is_mounted()
> directly could produce misleading warnings or errors.
> 
> Add an explicit access(PATH, F_OK) check before calling tst_is_mounted()
> in the cleanup, ensuring we only query mounts for existing paths.
> 
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
> 
> Notes:
>     v1 --> v2:
>             patch 1/2, keep no change, do not send v2.
>             patch 2/2, adding two more files for path exist check
> 
>  testcases/kernel/containers/mqns/mqns_03.c | 2 +-
>  testcases/kernel/containers/mqns/mqns_04.c | 2 +-
>  testcases/kernel/syscalls/mount/mount05.c  | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
Still more test case need update such as following?
  13    111  testcases/kernel/syscalls/mount/mount02.c <<cleanup>>
             if (tst_is_mounted(MNTPOINT))
  14    202  testcases/kernel/syscalls/mount/mount03.c <<cleanup>>
             if (tst_is_mounted(MNTPOINT))
  15     21  testcases/kernel/syscalls/mount/mount04.c <<cleanup>>
             if (tst_is_mounted(MNTPOINT))

Maybe we can just report warning instead of error?

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

> 
> diff --git a/testcases/kernel/containers/mqns/mqns_03.c b/testcases/kernel/containers/mqns/mqns_03.c
> index 4d3bfc52f..ac8311559 100644
> --- a/testcases/kernel/containers/mqns/mqns_03.c
> +++ b/testcases/kernel/containers/mqns/mqns_03.c
> @@ -130,7 +130,7 @@ static void cleanup(void)
>  	if (!access(MQUEUE2, F_OK))
>  		SAFE_MQ_UNLINK(MQNAME2);
>  
> -	if (tst_is_mounted(DEVDIR))
> +	if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
>  		SAFE_UMOUNT(DEVDIR);
>  }
>  
> diff --git a/testcases/kernel/containers/mqns/mqns_04.c b/testcases/kernel/containers/mqns/mqns_04.c
> index d28c330c4..790607ecd 100644
> --- a/testcases/kernel/containers/mqns/mqns_04.c
> +++ b/testcases/kernel/containers/mqns/mqns_04.c
> @@ -123,7 +123,7 @@ static void cleanup(void)
>  	if (!access(MQUEUE2, F_OK))
>  		SAFE_MQ_UNLINK(MQNAME2);
>  
> -	if (tst_is_mounted(DEVDIR))
> +	if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
>  		SAFE_UMOUNT(DEVDIR);
>  }
>  
> diff --git a/testcases/kernel/syscalls/mount/mount05.c b/testcases/kernel/syscalls/mount/mount05.c
> index 66e102a32..5585e230e 100644
> --- a/testcases/kernel/syscalls/mount/mount05.c
> +++ b/testcases/kernel/syscalls/mount/mount05.c
> @@ -35,7 +35,7 @@ static void cleanup(void)
>  	if (tst_is_mounted(MNTPOINT1))
>  		SAFE_UMOUNT(MNTPOINT1);
>  
> -	if (tst_is_mounted(MNTPOINT2))
> +	if (!access(MNTPOINT2, F_OK) && tst_is_mounted(MNTPOINT2))
>  		SAFE_UMOUNT(MNTPOINT2);
>  }
>  
> -- 
> 2.49.0
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup
  2025-08-22  8:02       ` Wei Gao via ltp
@ 2025-08-22  8:12         ` Li Wang via ltp
  2025-08-22  8:32           ` Wei Gao via ltp
  0 siblings, 1 reply; 9+ messages in thread
From: Li Wang via ltp @ 2025-08-22  8:12 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

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

> On Fri, Aug 22, 2025 at 03:48:11PM +0800, Li Wang via ltp wrote:
> > tst_is_mounted() now internally resolves the mount path via realpath(),
> > which will fail if the path does not exist. In sometest (e.g. mount05),
> > MNTPOINT2 may not exist yet during cleanup, calling tst_is_mounted()
> > directly could produce misleading warnings or errors.
> >
> > Add an explicit access(PATH, F_OK) check before calling tst_is_mounted()
> > in the cleanup, ensuring we only query mounts for existing paths.
> >
> > Signed-off-by: Li Wang <liwang@redhat.com>
> > ---
> >
> > Notes:
> >     v1 --> v2:
> >             patch 1/2, keep no change, do not send v2.
> >             patch 2/2, adding two more files for path exist check
> >
> >  testcases/kernel/containers/mqns/mqns_03.c | 2 +-
> >  testcases/kernel/containers/mqns/mqns_04.c | 2 +-
> >  testcases/kernel/syscalls/mount/mount05.c  | 2 +-
> >  3 files changed, 3 insertions(+), 3 deletions(-)
> Still more test case need update such as following?
>   13    111  testcases/kernel/syscalls/mount/mount02.c <<cleanup>>
>              if (tst_is_mounted(MNTPOINT))
>   14    202  testcases/kernel/syscalls/mount/mount03.c <<cleanup>>
>              if (tst_is_mounted(MNTPOINT))
>   15     21  testcases/kernel/syscalls/mount/mount04.c <<cleanup>>
>              if (tst_is_mounted(MNTPOINT))
>

I wasn't encountering these test failures on that, the problem
only appears when the mounted path is deleted by test.

Did you test and get anything abnormal on your side?


>
> Maybe we can just report warning instead of error?
>

It is Warning but not an error, the 'TERRNO' is only use to
show the errno for better debugging.

  tst_device.c:440: TWARN: realpath(mntpoint2) failed: ENOENT (2)



>
> --- a/lib/tst_device.c
> +++ b/lib/tst_device.c
> @@ -481,7 +481,7 @@ static int tst_mount_has_opt(const char *path, const
> char *opt)
>         char abspath[PATH_MAX];
>
>         if (!realpath(path, abspath)) {
> -               tst_resm(TWARN | TERRNO, "realpath(%s) failed", path);
> +               tst_resm(TWARN, "realpath(%s) failed", path);
>                 return 0;
>         }
>
> >
> > diff --git a/testcases/kernel/containers/mqns/mqns_03.c
> b/testcases/kernel/containers/mqns/mqns_03.c
> > index 4d3bfc52f..ac8311559 100644
> > --- a/testcases/kernel/containers/mqns/mqns_03.c
> > +++ b/testcases/kernel/containers/mqns/mqns_03.c
> > @@ -130,7 +130,7 @@ static void cleanup(void)
> >       if (!access(MQUEUE2, F_OK))
> >               SAFE_MQ_UNLINK(MQNAME2);
> >
> > -     if (tst_is_mounted(DEVDIR))
> > +     if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
> >               SAFE_UMOUNT(DEVDIR);
> >  }
> >
> > diff --git a/testcases/kernel/containers/mqns/mqns_04.c
> b/testcases/kernel/containers/mqns/mqns_04.c
> > index d28c330c4..790607ecd 100644
> > --- a/testcases/kernel/containers/mqns/mqns_04.c
> > +++ b/testcases/kernel/containers/mqns/mqns_04.c
> > @@ -123,7 +123,7 @@ static void cleanup(void)
> >       if (!access(MQUEUE2, F_OK))
> >               SAFE_MQ_UNLINK(MQNAME2);
> >
> > -     if (tst_is_mounted(DEVDIR))
> > +     if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
> >               SAFE_UMOUNT(DEVDIR);
> >  }
> >
> > diff --git a/testcases/kernel/syscalls/mount/mount05.c
> b/testcases/kernel/syscalls/mount/mount05.c
> > index 66e102a32..5585e230e 100644
> > --- a/testcases/kernel/syscalls/mount/mount05.c
> > +++ b/testcases/kernel/syscalls/mount/mount05.c
> > @@ -35,7 +35,7 @@ static void cleanup(void)
> >       if (tst_is_mounted(MNTPOINT1))
> >               SAFE_UMOUNT(MNTPOINT1);
> >
> > -     if (tst_is_mounted(MNTPOINT2))
> > +     if (!access(MNTPOINT2, F_OK) && tst_is_mounted(MNTPOINT2))
> >               SAFE_UMOUNT(MNTPOINT2);
> >  }
> >
> > --
> > 2.49.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] 9+ messages in thread

* Re: [LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup
  2025-08-22  8:12         ` Li Wang via ltp
@ 2025-08-22  8:32           ` Wei Gao via ltp
  0 siblings, 0 replies; 9+ messages in thread
From: Wei Gao via ltp @ 2025-08-22  8:32 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp

On Fri, Aug 22, 2025 at 04:12:20PM +0800, Li Wang wrote:
> On Fri, Aug 22, 2025 at 4:03 PM Wei Gao <wegao@suse.com> wrote:
> 
> > On Fri, Aug 22, 2025 at 03:48:11PM +0800, Li Wang via ltp wrote:
> > > tst_is_mounted() now internally resolves the mount path via realpath(),
> > > which will fail if the path does not exist. In sometest (e.g. mount05),
> > > MNTPOINT2 may not exist yet during cleanup, calling tst_is_mounted()
> > > directly could produce misleading warnings or errors.
> > >
> > > Add an explicit access(PATH, F_OK) check before calling tst_is_mounted()
> > > in the cleanup, ensuring we only query mounts for existing paths.
> > >
> > > Signed-off-by: Li Wang <liwang@redhat.com>
> > > ---
> > >
> > > Notes:
> > >     v1 --> v2:
> > >             patch 1/2, keep no change, do not send v2.
> > >             patch 2/2, adding two more files for path exist check
> > >
> > >  testcases/kernel/containers/mqns/mqns_03.c | 2 +-
> > >  testcases/kernel/containers/mqns/mqns_04.c | 2 +-
> > >  testcases/kernel/syscalls/mount/mount05.c  | 2 +-
> > >  3 files changed, 3 insertions(+), 3 deletions(-)
> > Still more test case need update such as following?
> >   13    111  testcases/kernel/syscalls/mount/mount02.c <<cleanup>>
> >              if (tst_is_mounted(MNTPOINT))
> >   14    202  testcases/kernel/syscalls/mount/mount03.c <<cleanup>>
> >              if (tst_is_mounted(MNTPOINT))
> >   15     21  testcases/kernel/syscalls/mount/mount04.c <<cleanup>>
> >              if (tst_is_mounted(MNTPOINT))
> >
> 
> I wasn't encountering these test failures on that, the problem
> only appears when the mounted path is deleted by test.
> 
> Did you test and get anything abnormal on your side?
Quick use your patch check mount02/3/4 no issue happen.
> 
> 
> >
> > Maybe we can just report warning instead of error?
> >
> 
> It is Warning but not an error, the 'TERRNO' is only use to
> show the errno for better debugging.
> 
>   tst_device.c:440: TWARN: realpath(mntpoint2) failed: ENOENT (2)
Sorry i thought this will give an error :)
> 
> 
> 
> >
> > --- a/lib/tst_device.c
> > +++ b/lib/tst_device.c
> > @@ -481,7 +481,7 @@ static int tst_mount_has_opt(const char *path, const
> > char *opt)
> >         char abspath[PATH_MAX];
> >
> >         if (!realpath(path, abspath)) {
> > -               tst_resm(TWARN | TERRNO, "realpath(%s) failed", path);
> > +               tst_resm(TWARN, "realpath(%s) failed", path);
> >                 return 0;
> >         }
> >
> > >
> > > diff --git a/testcases/kernel/containers/mqns/mqns_03.c
> > b/testcases/kernel/containers/mqns/mqns_03.c
> > > index 4d3bfc52f..ac8311559 100644
> > > --- a/testcases/kernel/containers/mqns/mqns_03.c
> > > +++ b/testcases/kernel/containers/mqns/mqns_03.c
> > > @@ -130,7 +130,7 @@ static void cleanup(void)
> > >       if (!access(MQUEUE2, F_OK))
> > >               SAFE_MQ_UNLINK(MQNAME2);
> > >
> > > -     if (tst_is_mounted(DEVDIR))
> > > +     if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
> > >               SAFE_UMOUNT(DEVDIR);
> > >  }
> > >
> > > diff --git a/testcases/kernel/containers/mqns/mqns_04.c
> > b/testcases/kernel/containers/mqns/mqns_04.c
> > > index d28c330c4..790607ecd 100644
> > > --- a/testcases/kernel/containers/mqns/mqns_04.c
> > > +++ b/testcases/kernel/containers/mqns/mqns_04.c
> > > @@ -123,7 +123,7 @@ static void cleanup(void)
> > >       if (!access(MQUEUE2, F_OK))
> > >               SAFE_MQ_UNLINK(MQNAME2);
> > >
> > > -     if (tst_is_mounted(DEVDIR))
> > > +     if (!access(DEVDIR, F_OK) && tst_is_mounted(DEVDIR))
> > >               SAFE_UMOUNT(DEVDIR);
> > >  }
> > >
> > > diff --git a/testcases/kernel/syscalls/mount/mount05.c
> > b/testcases/kernel/syscalls/mount/mount05.c
> > > index 66e102a32..5585e230e 100644
> > > --- a/testcases/kernel/syscalls/mount/mount05.c
> > > +++ b/testcases/kernel/syscalls/mount/mount05.c
> > > @@ -35,7 +35,7 @@ static void cleanup(void)
> > >       if (tst_is_mounted(MNTPOINT1))
> > >               SAFE_UMOUNT(MNTPOINT1);
> > >
> > > -     if (tst_is_mounted(MNTPOINT2))
> > > +     if (!access(MNTPOINT2, F_OK) && tst_is_mounted(MNTPOINT2))
> > >               SAFE_UMOUNT(MNTPOINT2);
> > >  }
> > >
> > > --
> > > 2.49.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] 9+ messages in thread

* Re: [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted()
  2025-08-22  7:45 ` [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted() Wei Gao via ltp
@ 2025-08-26  1:16   ` Li Wang via ltp
  0 siblings, 0 replies; 9+ messages in thread
From: Li Wang via ltp @ 2025-08-26  1:16 UTC (permalink / raw)
  To: Wei Gao; +Cc: ltp

Wei Gao <wegao@suse.com> wrote:


> Thanks for your patch!
> Reviewed-by: Wei Gao <wegao@suse.com>
>

Patchset merged, thanks for the review.

-- 
Regards,
Li Wang

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-08-26  1:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22  7:22 [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted() Li Wang via ltp
2025-08-22  7:22 ` [LTP] [PATCH 2/2] mount05: check if mount path exist before tst_is_mounted Li Wang via ltp
2025-08-22  7:28   ` Li Wang via ltp
2025-08-22  7:48     ` [LTP] [PATCH v2 2/2] mount: check path exists before tst_is_mounted in cleanup Li Wang via ltp
2025-08-22  8:02       ` Wei Gao via ltp
2025-08-22  8:12         ` Li Wang via ltp
2025-08-22  8:32           ` Wei Gao via ltp
2025-08-22  7:45 ` [LTP] [PATCH 1/2] tst_device: refine tst_is_mounted() Wei Gao via ltp
2025-08-26  1:16   ` Li Wang 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).