[libvirt] [PATCH 4/4] Misc error handling fixes in text mode monitor commands

Daniel P. Berrange berrange at redhat.com
Mon Nov 1 17:48:34 UTC 2010


A couple of places in the text monitor were overwriting the
'ret' variable with a >= 0 value before success was actually
determined. So later error paths would not correctly return
the -1 value. The drive_add code was not checking for errors
like missing command

* src/qemu/qemu_monitor_text.c: Misc error handling fixes
---
 src/qemu/qemu_monitor_text.c |   28 +++++++++++++++++++---------
 1 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index d7e128c..7f15008 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -2094,11 +2094,10 @@ int qemuMonitorTextAttachDrive(qemuMonitorPtr mon,
     }
 
 try_command:
-    ret = virAsprintf(&cmd, "drive_add %s%.2x:%.2x:%.2x %s",
-                      (tryOldSyntax ? "" : "pci_addr="),
-                      controllerAddr->domain, controllerAddr->bus,
-                      controllerAddr->slot, safe_str);
-    if (ret == -1) {
+    if (virAsprintf(&cmd, "drive_add %s%.2x:%.2x:%.2x %s",
+                    (tryOldSyntax ? "" : "pci_addr="),
+                    controllerAddr->domain, controllerAddr->bus,
+                    controllerAddr->slot, safe_str) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -2109,6 +2108,12 @@ try_command:
         goto cleanup;
     }
 
+    if (strstr(reply, "unknown command:")) {
+        qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                        _("drive hotplug is not supported"));
+        goto cleanup;
+    }
+
     if (qemudParseDriveAddReply(reply, driveAddr) < 0) {
         if (!tryOldSyntax && strstr(reply, "invalid char in expression")) {
             VIR_FREE(reply);
@@ -2360,8 +2365,7 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon,
 
     /* 'dummy' here is just a placeholder since there is no PCI
      * address required when attaching drives to a controller */
-    ret = virAsprintf(&cmd, "drive_add dummy %s", safe_str);
-    if (ret == -1) {
+    if (virAsprintf(&cmd, "drive_add dummy %s", safe_str) < 0) {
         virReportOOMError();
         goto cleanup;
     }
@@ -2372,6 +2376,12 @@ int qemuMonitorTextAddDrive(qemuMonitorPtr mon,
         goto cleanup;
     }
 
+    if (strstr(reply, "unknown command:")) {
+        qemuReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                        _("drive hotplug is not supported"));
+        goto cleanup;
+    }
+
     ret = 0;
 
 cleanup:
@@ -2397,8 +2407,8 @@ int qemuMonitorTextSetDrivePassphrase(qemuMonitorPtr mon,
         return -1;
     }
 
-    ret = virAsprintf(&cmd, "block_passwd %s%s \"%s\"", QEMU_DRIVE_HOST_PREFIX, alias, safe_str);
-    if (ret == -1) {
+    if (virAsprintf(&cmd, "block_passwd %s%s \"%s\"",
+                    QEMU_DRIVE_HOST_PREFIX, alias, safe_str) < 0) {
         virReportOOMError();
         goto cleanup;
     }
-- 
1.7.2.3




More information about the libvir-list mailing list