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(a)redhat.com>
---
src/qemu/qemu_hotplug.c | 22 ++++++++++++++--------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ce1db3c..0fc0084 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -544,8 +544,10 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
{
size_t i;
qemuDomainObjPrivatePtr priv = vm->privateData;
+ virErrorPtr orig_err;
char *drivestr = NULL;
char *devstr = NULL;
+ bool cleanupAddDrive = false;
int ret = -1;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
@@ -587,17 +589,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 monitor_error;
+ cleanupAddDrive = true;
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
- goto failadddevice;
+ goto monitor_error;
if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto failexitmonitor;
+ goto error;
virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
@@ -611,14 +613,18 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
virObjectUnref(cfg);
return ret;
- failadddevice:
+ monitor_error:
+ orig_err = virSaveLastError();
/* XXX should call 'drive_del' on error but this does not exist yet */
- VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
+ if (cleanupAddDrive)
+ VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
- failadddrive:
ignore_value(qemuDomainObjExitMonitor(driver, vm));
+ if (orig_err) {
+ virSetError(orig_err);
+ virFreeError(orig_err);
+ }
- failexitmonitor:
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
error:
--
2.5.5