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. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/qemu/qemu_hotplug.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 10120aa..ce1db3c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -308,6 +308,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, char *drivestr = NULL; char *drivealias = NULL; bool releaseaddr = false; + bool cleanupAddDrive = 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 monitor_error; + cleanupAddDrive = true; if (qemuMonitorAddDevice(priv->mon, devstr) < 0) - goto failadddevice; + goto monitor_error; if (qemuDomainObjExitMonitor(driver, vm) < 0) { releaseaddr = false; - goto failexitmonitor; + goto error; } virDomainAuditDisk(vm, NULL, disk->src, "attach", true); @@ -381,22 +382,19 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, virObjectUnref(cfg); return ret; - failadddevice: + monitor_error: orig_err = virSaveLastError(); - if (qemuMonitorDriveDel(priv->mon, drivealias) < 0) { + if (cleanupAddDrive && qemuMonitorDriveDel(priv->mon, drivealias) < 0) { VIR_WARN("Unable to remove drive %s (%s) after failed " "qemuMonitorAddDevice", drivealias, drivestr); } + if (qemuDomainObjExitMonitor(driver, vm) < 0) + releaseaddr = false; if (orig_err) { virSetError(orig_err); virFreeError(orig_err); } - failadddrive: - if (qemuDomainObjExitMonitor(driver, vm) < 0) - releaseaddr = false; - - failexitmonitor: virDomainAuditDisk(vm, NULL, disk->src, "attach", false); error: -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list