Skip to contentSkip to conversation

safe_mount: safe_umount: print debug info about the operation

PATCH Superseded Murphy Zhou 3 participants 3 messages Jun 7, 2023 – Jun 8, 2023 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 safe_mount: safe_umount: print debug info about the operation

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

---
 lib/safe_macros.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
lib/safe_macros.c +15 -0
index af6dd0716..6add92f06 100644
@@ -898,7 +898,15 @@ 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_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"realpath(%s, s) failed", target);
+
+	tst_resm_(file, lineno, TINFO,
+		"Mounting %s to %s fstyp=%s flags=%lx",
+		source, mpath, filesystemtype, mountflags);
 	/*
 	 * 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 +956,13 @@ 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_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"realpath(%s, s) failed", target);
+
+	tst_resm_(file, lineno, TINFO, "Umounting %s", mpath);
 
 	rval = tst_umount(target);
 
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/1
#1 lore raw
Quoted 13 lines · Murphy Zhou

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

---
 lib/safe_macros.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
lib/safe_macros.c +0 -0
index af6dd0716..6add92f06 100644

lib/safe_macros.c int safe_mount(const char *file, const int lineno, · line 907

Quoted 10 lines
lib/safe_macros.c +4 -0
@@ -898,7 +898,15 @@ 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_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+                       "realpath(%s, s) failed", target);
 

Shouldn't this be like:

     "realpath(%s, %s) failed", target, mpath);

Otherwise, LGTM.

Quoted 9 lines
lib/safe_macros.c +4 -0
+
+       tst_resm_(file, lineno, TINFO,
+               "Mounting %s to %s fstyp=%s flags=%lx",
+               source, mpath, filesystemtype, mountflags);
        /*

* Don't try using the kernel's NTFS driver when mounting NTFS,
since
* the kernel's NTFS driver doesn't have proper write support.

lib/safe_macros.c int safe_umount(const char *file, const int lineno, · line 965

Quoted 10 lines
lib/safe_macros.c +5 -0
@@ -948,6 +956,13 @@ 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_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+                       "realpath(%s, s) failed", target);
 

and here ^

Quoted 13 lines
lib/safe_macros.c +2 -0
+
+       tst_resm_(file, lineno, TINFO, "Umounting %s", mpath);
 
        rval = tst_umount(target);

--
2.31.1

--
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
In reply to Murphy Zhou

Hi,

Quoted 15 lines · Murphy Zhou

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

---
  lib/safe_macros.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
lib/safe_macros.c +0 -0
index af6dd0716..6add92f06 100644
@@ -898,7 +898,15 @@ int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void),
  	       const void *data)
  {

lib/safe_macros.c int safe_mount(const char *file, const int lineno, void (*cleanup_fn)(void), · line 909

Quoted 10 lines
lib/safe_macros.c +8 -0
  	int rval = -1;
+	char mpath[PATH_MAX];
 
+	if (!realpath(target, mpath))
+		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"realpath(%s, s) failed", target);
+
+	tst_resm_(file, lineno, TINFO,
+		"Mounting %s to %s fstyp=%s flags=%lx",
+		source, mpath, filesystemtype, mountflags);

This is much better, but realpath() failure is not a fatal error here, just a minor inconvenience. So it'd be better to do this:

if (realpath(...)) {
	tst_resm_(... TINFO, "Mounting %s to %s...", ...);
} else {
	tst_resm_(... TINFO | TERRNO, "Cannot resolve absolute path to %s", ...);
}
Quoted 4 lines
lib/safe_macros.c +0 -0
  	/*
  	 * Don't try using the kernel's NTFS driver when mounting NTFS, since
  	 * the kernel's NTFS driver doesn't have proper write support.

lib/safe_macros.c int safe_umount(const char *file, const int lineno, void (*cleanup_fn)(void), · line 965

Quoted 10 lines
lib/safe_macros.c +7 -0
@@ -948,6 +956,13 @@ 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_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+			"realpath(%s, s) failed", target);
+
+	tst_resm_(file, lineno, TINFO, "Umounting %s", mpath);

Same here.

Quoted 3 lines
lib/safe_macros.c +0 -0
  	rval = tst_umount(target);
 
Signature · 11 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic


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