[libvirt] [PATCH 3/7] qemu: Alter error path cleanup for qemuDomainAttachSCSIDisk
Ján Tomko
jtomko at redhat.com
Tue Jul 19 10:34:47 UTC 2016
On Fri, Jul 15, 2016 at 07:50:23AM -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 at 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);
>+ }
I don't think we need to save the error just for ExitMonitor
Jan
>
>- failexitmonitor:
> virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
>
> error:
>--
>2.5.5
>
>--
>libvir-list mailing list
>libvir-list at redhat.com
>https://www.redhat.com/mailman/listinfo/libvir-list
More information about the libvir-list
mailing list