From: John Ferlan Date: Thu, 14 Jul 2016 21:28:53 +0000 (-0400) Subject: qemu: Alter error path cleanup for qemuDomainAttachVirtioDiskDevice X-Git-Tag: v2.1.0-rc1~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7f84cb1ee037c2ea6c803450eb692d8030b4227;p=thirdparty%2Flibvirt.git qemu: Alter error path cleanup for qemuDomainAttachVirtioDiskDevice 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. --- diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 406fec93a4..b38b5452ce 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 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: