]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Alter error path cleanup for qemuDomainAttachSCSIDisk
authorJohn Ferlan <jferlan@redhat.com>
Thu, 14 Jul 2016 21:47:13 +0000 (17:47 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 19 Jul 2016 11:13:09 +0000 (07:13 -0400)
Based on recent review comment - rather than have a spate of goto failxxxx,
change to a boolean based model. Ensures that the original error can be
preserved and cleanup is a bit more orderly if more objects are added.

src/qemu/qemu_hotplug.c

index b38b5452ceec099e267a5648783e1cb0d3448d92..2079231b56e01f51005af020c96fdf650874abf1 100644 (file)
@@ -546,6 +546,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     char *drivestr = NULL;
     char *devstr = NULL;
+    bool driveAdded = false;
     int ret = -1;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
 
@@ -587,17 +588,17 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
     if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
         goto error;
 
-    /* Attach the device - 2 step process */
     qemuDomainObjEnterMonitor(driver, vm);
 
     if (qemuMonitorAddDrive(priv->mon, drivestr) < 0)
-        goto failadddrive;
+        goto exit_monitor;
+    driveAdded = true;
 
     if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
-        goto failadddevice;
+        goto exit_monitor;
 
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
-        goto failexitmonitor;
+        goto error;
 
     virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
 
@@ -611,14 +612,13 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
     virObjectUnref(cfg);
     return ret;
 
failadddevice:
exit_monitor:
     /* XXX should call 'drive_del' on error but this does not exist yet */
-    VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
+    if (driveAdded)
+        VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
 
- failadddrive:
     ignore_value(qemuDomainObjExitMonitor(driver, vm));
 
- failexitmonitor:
     virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
 
  error: