From: John Ferlan Date: Thu, 14 Jul 2016 21:47:13 +0000 (-0400) Subject: qemu: Alter error path cleanup for qemuDomainAttachSCSIDisk X-Git-Tag: v2.1.0-rc1~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c3b5f22dec05389a8a164761976d4aa64d4c399f;p=thirdparty%2Flibvirt.git qemu: Alter error path cleanup for qemuDomainAttachSCSIDisk 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 b38b5452ce..2079231b56 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -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: