[LTP] [PATCH v3] safe_mount: safe_umount: print debug info about the operation

Murphy Zhou jencce.kernel@gmail.com
Thu Jun 15 03:24:45 CEST 2023


Make the source and the target to mount/umount visible. It's
good for debugging.

Signed-off-by: Murphy Zhou <jencce.kernel@gmail.com>
---
v3:
  Apply suggestions from Li and Martin. Thanks very much!

 lib/safe_macros.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index af6dd0716..26f9136af 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -898,7 +898,16 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
 	       const void *data)
 {
 	int rval = -1;
+	char mpath[PATH_MAX];
 
+	if (realpath(target, mpath)) {
+		tst_resm_(file, lineno, TINFO,
+			"Mounting %s to %s fstyp=%s flags=%lx",
+			source, mpath, filesystemtype, mountflags);
+	} else {
+		tst_resm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"Cannot resolve the absolute path of %s", target);
+	}
 	/*
 	 * Don't try using the kernel's NTFS driver when mounting NTFS, since
 	 * the kernel's NTFS driver doesn't have proper write support.
@@ -948,6 +957,14 @@ int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void),
 		const char *target)
 {
 	int rval;
+	char mpath[PATH_MAX];
+
+	if (realpath(target, mpath)) {
+		tst_resm_(file, lineno, TINFO, "Umounting %s", mpath);
+	} else {
+		tst_resm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"Cannot resolve the absolute path of %s", target);
+	}
 
 	rval = tst_umount(target);
 
-- 
2.31.1



More information about the ltp mailing list