Skip to contentSkip to conversation

vhost-scsi: Improve error reporting for invalid vhostfd

PATCH In review Markus Armbruster 2 participants 2 messages Feb 9, 2015 – Feb 10, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost-scsi: Improve error reporting for invalid vhostfd

We get two error messages: one from monitor_handle_fd_param2(), and another one from vhost_scsi_realize(). The second one gets suppressed in QMP context.

That's because monitor_handle_fd_param() calls qerror_report_err(). Calling qerror_report_err() is always inappropriate in realize methods, because it doesn't return the Error object. It either reports the error to stderr or the human monitor, or it stores it in the QMP monitor, where it makes the QMP command fail even when the realize method ignores the error and succeeds. Fortunately, vhost_scsi_realize() doesn't do that.

Fix by switching to monitor_handle_fd_param2().

---
 hw/scsi/vhost-scsi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/scsi/vhost-scsi.c +4 -2
index dcb2bc5..567f350 100644
@@ -214,9 +214,11 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
     }
 
     if (vs->conf.vhostfd) {
-        vhostfd = monitor_handle_fd_param(cur_mon, vs->conf.vhostfd);
+        vhostfd = monitor_handle_fd_param2(cur_mon, vs->conf.vhostfd, &err);
         if (vhostfd == -1) {
-            error_setg(errp, "vhost-scsi: unable to parse vhostfd");
+            error_setg(errp, "vhost-scsi: unable to parse vhostfd: %s",
+                       error_get_pretty(err));
+            error_free(err);
             return;
         }
     } else {
Signature · 1 line
1.9.3
Acked-by on v1 1/1
#1 lore raw
Quoted 28 lines · Markus Armbruster

We get two error messages: one from monitor_handle_fd_param2(), and another one from vhost_scsi_realize(). The second one gets suppressed in QMP context.

That's because monitor_handle_fd_param() calls qerror_report_err(). Calling qerror_report_err() is always inappropriate in realize methods, because it doesn't return the Error object. It either reports the error to stderr or the human monitor, or it stores it in the QMP monitor, where it makes the QMP command fail even when the realize method ignores the error and succeeds. Fortunately, vhost_scsi_realize() doesn't do that.

Fix by switching to monitor_handle_fd_param2().

---
 hw/scsi/vhost-scsi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/scsi/vhost-scsi.c +0 -0
index dcb2bc5..567f350 100644
@@ -214,9 +214,11 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
     }
 
     if (vs->conf.vhostfd) {

hw/scsi/vhost-scsi.c static void vhost_scsi_realize(DeviceState *dev, Error **errp) · line 224

Quoted 10 lines
hw/scsi/vhost-scsi.c +4 -2
-        vhostfd = monitor_handle_fd_param(cur_mon, vs->conf.vhostfd);
+        vhostfd = monitor_handle_fd_param2(cur_mon, vs->conf.vhostfd, &err);
         if (vhostfd == -1) {
-            error_setg(errp, "vhost-scsi: unable to parse vhostfd");
+            error_setg(errp, "vhost-scsi: unable to parse vhostfd: %s",
+                       error_get_pretty(err));
+            error_free(err);
             return;
         }
     } else {