Re: [PATCH 3/7] qemu: Alter error path cleanup for qemuDomainAttachSCSIDisk

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
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@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]