Skip to contentSkip to conversation

block/raw-posix: Fix error_report of mounting message

PATCH In review Wei Jiangang 3 participants 8 messages Jun 1, 2016 – Jun 3, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block/raw-posix: Fix error_report of mounting message

Use a single error_printf to replace triple error_report.

---
 block/raw-posix.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/raw-posix.c +5 -5
index a4f5a1b..141b01a 100644
@@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error **errp)
 /* Prints directions on mounting and unmounting a device */
 static void print_unmounting_directions(const char *file_name)
 {
-    error_report("If device %s is mounted on the desktop, unmount"
-                 " it first before using it in QEMU", file_name);
-    error_report("Command to unmount device: diskutil unmountDisk %s",
-                 file_name);
-    error_report("Command to mount device: diskutil mountDisk %s", file_name);
+    error_printf("If device %s is mounted on the desktop, unmount"
+        " it first before using it in QEMU\n"
+        "Command to unmount device: diskutil unmountDisk %s\n"
+        "Command to mount device: diskutil mountDisk %s\n",
+        file_name, file_name, file_name);
 }
 
 #endif /* defined(__APPLE__) && defined(__MACH__) */
Signature · 1 line
1.9.3
#1 lore raw
Quoted 15 lines · Wei Jiangang

Use a single error_printf to replace triple error_report.

---
 block/raw-posix.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/raw-posix.c +0 -0
index a4f5a1b..141b01a 100644
@@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error **errp)
 /* Prints directions on mounting and unmounting a device */
 static void print_unmounting_directions(const char *file_name)
 {

block/raw-posix.c static bool setup_cdrom(char *bsd_path, Error **errp) · line 2068

Quoted 10 lines
block/raw-posix.c +5 -5
-    error_report("If device %s is mounted on the desktop, unmount"
-                 " it first before using it in QEMU", file_name);
-    error_report("Command to unmount device: diskutil unmountDisk %s",
-                 file_name);
-    error_report("Command to mount device: diskutil mountDisk %s", file_name);
+    error_printf("If device %s is mounted on the desktop, unmount"
+        " it first before using it in QEMU\n"
+        "Command to unmount device: diskutil unmountDisk %s\n"
+        "Command to mount device: diskutil mountDisk %s\n",
+        file_name, file_name, file_name);

I'd say it's less readable with a worse alignment to the parameters.

Fam

#2 lore raw
Quoted 20 lines · Fam Zheng
Quoted 19 lines · Wei Jiangang

Use a single error_printf to replace triple error_report.

---
 block/raw-posix.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/raw-posix.c +0 -4
index a4f5a1b..141b01a 100644
@@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error **errp)
 /* Prints directions on mounting and unmounting a device */
 static void print_unmounting_directions(const char *file_name)
 {
-    error_report("If device %s is mounted on the desktop, unmount"
-                 " it first before using it in QEMU", file_name);
-    error_report("Command to unmount device: diskutil unmountDisk %s",
-                 file_name);
Quoted 8 lines

block/raw-posix.c static bool setup_cdrom(char *bsd_path, Error **errp) · line 2068

Quoted 6 lines
block/raw-posix.c +5 -1
-    error_report("Command to mount device: diskutil mountDisk %s", file_name);
+    error_printf("If device %s is mounted on the desktop, unmount"
+        " it first before using it in QEMU\n"
+        "Command to unmount device: diskutil unmountDisk %s\n"
+        "Command to mount device: diskutil mountDisk %s\n",
+        file_name, file_name, file_name);

I'd say it's less readable with a worse alignment to the parameters.

Hi, Fam

Thanks for your comment.
You mean every error_report() followed by file_name is more readable ? or my codes dosen't follow a good alignment format?

Wei

Quoted 4 lines

Fam

#3 lore raw
Quoted 29 lines · Jiangang
Quoted 20 lines · Fam Zheng
Quoted 19 lines · Wei Jiangang

Use a single error_printf to replace triple error_report.

---
 block/raw-posix.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/raw-posix.c +0 -4
index a4f5a1b..141b01a 100644
@@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error **errp)
 /* Prints directions on mounting and unmounting a device */
 static void print_unmounting_directions(const char *file_name)
 {
-    error_report("If device %s is mounted on the desktop, unmount"
-                 " it first before using it in QEMU", file_name);
-    error_report("Command to unmount device: diskutil unmountDisk %s",
-                 file_name);
Quoted 8 lines

block/raw-posix.c static bool setup_cdrom(char *bsd_path, Error **errp) · line 2068

Quoted 6 lines
block/raw-posix.c +5 -1
-    error_report("Command to mount device: diskutil mountDisk %s", file_name);
+    error_printf("If device %s is mounted on the desktop, unmount"
+        " it first before using it in QEMU\n"
+        "Command to unmount device: diskutil unmountDisk %s\n"
+        "Command to mount device: diskutil mountDisk %s\n",
+        file_name, file_name, file_name);

I'd say it's less readable with a worse alignment to the parameters.

Quoted 6 lines

Hi, Fam

Thanks for your comment.
You mean every error_report() followed by file_name is more readable ? or my codes dosen't follow a good alignment format?

I'm happy with either way. :)

Fam

#4 lore raw
In reply to Wei Jiangang
Quoted 18 lines · Wei Jiangang

Use a single error_printf to replace triple error_report.

---
 block/raw-posix.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/raw-posix.c +0 -3
index a4f5a1b..141b01a 100644
@@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error **errp)
 /* Prints directions on mounting and unmounting a device */
 static void print_unmounting_directions(const char *file_name)
 {
-    error_report("If device %s is mounted on the desktop, unmount"
-                 " it first before using it in QEMU", file_name);
-    error_report("Command to unmount device: diskutil unmountDisk %s",

block/raw-posix.c static bool setup_cdrom(char *bsd_path, Error **errp) · line 2071

Quoted 10 lines
block/raw-posix.c +5 -2
-                 file_name);
-    error_report("Command to mount device: diskutil mountDisk %s", file_name);
+    error_printf("If device %s is mounted on the desktop, unmount"
+        " it first before using it in QEMU\n"
+        "Command to unmount device: diskutil unmountDisk %s\n"
+        "Command to mount device: diskutil mountDisk %s\n",
+        file_name, file_name, file_name);
 }
 
 #endif /* defined(__APPLE__) && defined(__MACH__) */

This is less wrong :)

Beware, I have no suitable machine to actually test this, so the following is based on code inspection.

print_unmounting_directions() is used by hdev_open(). hdev_open() is a BlockDriver method bdrv_file_open(), and as such returns errors to its caller via parameter Error **errp. The caller may or may not report errors it gets from hdev_open().

If it reports them, then print_unmounting_directions()'s output "overtakes" the error message, i.e. the "If device ... is mounted ..." hint is printed before the error message. Wrong, it should be printed after the error message.

If it doesn't report them, the hint gets printed anyway. More wrong.

In any case, printing each line of the hint with error_report() is also wrong, because that prefixes each line with program name and location information. Your patch fixes this part.

A more complete fix uses error_append_hint(errp, ...) instead of error_printf(). hdev_open() needs to pass errp to print_unmounting_directions() for that. errp must have an error set, or else error_append_hint() makes no sense.

#5 lore raw
Quoted 48 lines · Markus Armbruster
Quoted 18 lines · Wei Jiangang

Use a single error_printf to replace triple error_report.

---
 block/raw-posix.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/raw-posix.c +0 -3
index a4f5a1b..141b01a 100644
@@ -2061,11 +2061,11 @@ static bool setup_cdrom(char *bsd_path, Error **errp)
 /* Prints directions on mounting and unmounting a device */
 static void print_unmounting_directions(const char *file_name)
 {
-    error_report("If device %s is mounted on the desktop, unmount"
-                 " it first before using it in QEMU", file_name);
-    error_report("Command to unmount device: diskutil unmountDisk %s",

block/raw-posix.c static bool setup_cdrom(char *bsd_path, Error **errp) · line 2071

Quoted 10 lines
block/raw-posix.c +5 -2
-                 file_name);
-    error_report("Command to mount device: diskutil mountDisk %s", file_name);
+    error_printf("If device %s is mounted on the desktop, unmount"
+        " it first before using it in QEMU\n"
+        "Command to unmount device: diskutil unmountDisk %s\n"
+        "Command to mount device: diskutil mountDisk %s\n",
+        file_name, file_name, file_name);
 }
 
 #endif /* defined(__APPLE__) && defined(__MACH__) */

This is less wrong :)

Beware, I have no suitable machine to actually test this, so the following is based on code inspection.

print_unmounting_directions() is used by hdev_open(). hdev_open() is a BlockDriver method bdrv_file_open(), and as such returns errors to its caller via parameter Error **errp. The caller may or may not report errors it gets from hdev_open().

If it reports them, then print_unmounting_directions()'s output "overtakes" the error message, i.e. the "If device ... is mounted ..." hint is printed before the error message. Wrong, it should be printed after the error message.

If it doesn't report them, the hint gets printed anyway. More wrong.

Quoted 8 lines

In any case, printing each line of the hint with error_report() is also wrong, because that prefixes each line with program name and location information. Your patch fixes this part.

A more complete fix uses error_append_hint(errp, ...) instead of error_printf(). hdev_open() needs to pass errp to print_unmounting_directions() for that. errp must have an error set, or else error_append_hint() makes no sense.

I think you gave me a wonderful lesson about how to deal with error report.
Thank you very much.

My intention is only to avoid the output of multiple location information.

I'll check it again.

Thanks,
wei

Quoted 2 lines
#6 lore raw
Quoted 2 lines · Jiangang

My intention is only to avoid the output of multiple location information.

Then I think this should have gone into the commit message.

Fam

#7 lore raw
Quoted 5 lines · Fam Zheng
Quoted 2 lines · Jiangang

My intention is only to avoid the output of multiple location information.

Then I think this should have gone into the commit message.

OK, I'll make more detailed description in next version.

Quoted 4 lines

Fam