]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Alter error path cleanup for qemuDomainAttachVirtioDiskDevice
authorJohn Ferlan <jferlan@redhat.com>
Thu, 14 Jul 2016 21:28:53 +0000 (17:28 -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 406fec93a4477cc6d145812d7ace4e3739055950..b38b5452ceec099e267a5648783e1cb0d3448d92 100644 (file)
@@ -308,6 +308,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     char *drivestr = NULL;
     char *drivealias = NULL;
     bool releaseaddr = false;
+    bool driveAdded = false;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
     const char *src = virDomainDiskGetSource(disk);
 
@@ -354,18 +355,18 @@ qemuDomainAttachVirtioDiskDevice(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) {
         releaseaddr = false;
-        goto failexitmonitor;
+        goto error;
     }
 
     virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
@@ -381,9 +382,9 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
     virObjectUnref(cfg);
     return ret;
 
failadddevice:
exit_monitor:
     orig_err = virSaveLastError();
-    if (qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
+    if (driveAdded && qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
         VIR_WARN("Unable to remove drive %s (%s) after failed "
                  "qemuMonitorAddDevice", drivealias, drivestr);
     }
@@ -391,12 +392,9 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
         virSetError(orig_err);
         virFreeError(orig_err);
     }
-
- failadddrive:
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
         releaseaddr = false;
 
- failexitmonitor:
     virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
 
  error: