On Fri, Jul 15, 2016 at 07:50:21AM -0400, John Ferlan wrote:
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 04e11b4..10120aa 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1874,6 +1874,7 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn, char *drvstr = NULL; bool teardowncgroup = false; bool teardownlabel = false; + bool cleanupAddDrive = false;
driveAdded is shorter
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -1935,17 +1936,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 monitor_error; + cleanupAddDrive = true; if (qemuMonitorAddDevice(priv->mon, devstr) < 0) - goto failadddevice; + goto monitor_error; if (qemuDomainObjExitMonitor(driver, vm) < 0) - goto failexitmonitor; + goto cleanup; virDomainAuditHostdev(vm, hostdev, "attach", true); @@ -1968,21 +1969,18 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn, VIR_FREE(devstr); return ret; - failadddevice: + monitor_error:
can be 'exit_monitor' to match what we already use.
orig_err = virSaveLastError(); - if (qemuMonitorDriveDel(priv->mon, drvstr) < 0) + if (cleanupAddDrive && qemuMonitorDriveDel(priv->mon, drvstr) < 0) { VIR_WARN("Unable to remove drive %s (%s) after failed " "qemuMonitorAddDevice", drvstr, devstr); + } + ignore_value(qemuDomainObjExitMonitor(driver, vm));
The error reported by qemuDomainObjExitMonitor ('domain is no longer running') could be more important than the original error. I would leave it where it was. Also, it's possible that ExitMonitor can no longer fail now that we take a job for cleaning up after EOF. ACK either way. Jan
if (orig_err) { virSetError(orig_err); virFreeError(orig_err); } - - failadddrive: - ignore_value(qemuDomainObjExitMonitor(driver, vm)); - - failexitmonitor: virDomainAuditHostdev(vm, hostdev, "attach", false); goto cleanup; -- 2.5.5 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list