From 9d97987c6cd5a7bf0dbd251d48b72b506bf0abe9 Mon Sep 17 00:00:00 2001 Message-Id: <9d97987c6cd5a7bf0dbd251d48b72b506bf0abe9@dist-git> From: John Ferlan Date: Mon, 25 Jul 2016 12:42:53 -0400 Subject: [PATCH] qemu: Alter error path cleanup for qemuDomainAttachHostSCSIDevice https://bugzilla.redhat.com/show_bug.cgi?id=1301021 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. (cherry picked from commit 6fe2eb2458b5e4b84f5aede6d3fdf3ae47c0cd02) Signed-off-by: John Ferlan --- src/qemu/qemu_hotplug.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 7a71333..3f63b0e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1899,6 +1899,7 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn, char *drvstr = NULL; bool teardowncgroup = false; bool teardownlabel = false; + bool driveAdded = false; if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -1960,17 +1961,17 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn, if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) goto cleanup; - /* Attach the device - 2 step process */ qemuDomainObjEnterMonitor(driver, vm); if (qemuMonitorAddDrive(priv->mon, drvstr) < 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 cleanup; virDomainAuditHostdev(vm, hostdev, "attach", true); @@ -1993,21 +1994,19 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn, VIR_FREE(devstr); return ret; - failadddevice: + exit_monitor: orig_err = virSaveLastError(); - if (qemuMonitorDriveDel(priv->mon, drvstr) < 0) + if (driveAdded && qemuMonitorDriveDel(priv->mon, drvstr) < 0) { VIR_WARN("Unable to remove drive %s (%s) after failed " "qemuMonitorAddDevice", drvstr, devstr); + } if (orig_err) { virSetError(orig_err); virFreeError(orig_err); } - failadddrive: ignore_value(qemuDomainObjExitMonitor(driver, vm)); - - failexitmonitor: virDomainAuditHostdev(vm, hostdev, "attach", false); goto cleanup; -- 2.9.2