]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Misc error handling fixes in text mode monitor commands
authorDaniel P. Berrange <berrange@redhat.com>
Mon, 1 Nov 2010 17:09:31 +0000 (13:09 -0400)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 2 Nov 2010 14:38:23 +0000 (14:38 +0000)
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

index d7e128c2cecdff385c83e5997b1efa023428e0f9..7f15008977537f9ff5ffea7b7d23db40a8c1c27a 100644 (file)
@@ -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;
     }