提交 c3b5f22d 编写于 作者: J John Ferlan

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.
上级 a7f84cb1
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册