mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-23 06:23:10 +00:00
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.
This commit is contained in:
parent
a7f84cb1ee
commit
c3b5f22dec
@ -546,6 +546,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
|
|||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
char *drivestr = NULL;
|
char *drivestr = NULL;
|
||||||
char *devstr = NULL;
|
char *devstr = NULL;
|
||||||
|
bool driveAdded = false;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
|
||||||
@ -587,17 +588,17 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
|
|||||||
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
|
if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* Attach the device - 2 step process */
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
|
|
||||||
if (qemuMonitorAddDrive(priv->mon, drivestr) < 0)
|
if (qemuMonitorAddDrive(priv->mon, drivestr) < 0)
|
||||||
goto failadddrive;
|
goto exit_monitor;
|
||||||
|
driveAdded = true;
|
||||||
|
|
||||||
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
|
if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
|
||||||
goto failadddevice;
|
goto exit_monitor;
|
||||||
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
goto failexitmonitor;
|
goto error;
|
||||||
|
|
||||||
virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
|
virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
|
||||||
|
|
||||||
@ -611,14 +612,13 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
|
|||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
failadddevice:
|
exit_monitor:
|
||||||
/* XXX should call 'drive_del' on error but this does not exist yet */
|
/* XXX should call 'drive_del' on error but this does not exist yet */
|
||||||
|
if (driveAdded)
|
||||||
VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
|
VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
|
||||||
|
|
||||||
failadddrive:
|
|
||||||
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
||||||
|
|
||||||
failexitmonitor:
|
|
||||||
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
Loading…
Reference in New Issue
Block a user