6ae9ed
From 48393066faa3d6af3791e6a0d0fcf79a71b8e9e4 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <48393066faa3d6af3791e6a0d0fcf79a71b8e9e4@dist-git>
6ae9ed
From: John Ferlan <jferlan@redhat.com>
6ae9ed
Date: Mon, 25 Jul 2016 12:42:55 -0400
6ae9ed
Subject: [PATCH] qemu: Alter error path cleanup for qemuDomainAttachSCSIDisk
6ae9ed
6ae9ed
https://bugzilla.redhat.com/show_bug.cgi?id=1301021
6ae9ed
6ae9ed
Based on recent review comment - rather than have a spate of goto failxxxx,
6ae9ed
change to a boolean based model. Ensures that the original error can be
6ae9ed
preserved and cleanup is a bit more orderly if more objects are added.
6ae9ed
6ae9ed
(cherry picked from commit c3b5f22dec05389a8a164761976d4aa64d4c399f)
6ae9ed
Signed-off-by: John Ferlan <jferlan@redhat.com>
6ae9ed
---
6ae9ed
 src/qemu/qemu_hotplug.c | 16 ++++++++--------
6ae9ed
 1 file changed, 8 insertions(+), 8 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
6ae9ed
index e21720b..b3fab6a 100644
6ae9ed
--- a/src/qemu/qemu_hotplug.c
6ae9ed
+++ b/src/qemu/qemu_hotplug.c
6ae9ed
@@ -547,6 +547,7 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
6ae9ed
     qemuDomainObjPrivatePtr priv = vm->privateData;
6ae9ed
     char *drivestr = NULL;
6ae9ed
     char *devstr = NULL;
6ae9ed
+    bool driveAdded = false;
6ae9ed
     int ret = -1;
6ae9ed
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
6ae9ed
 
6ae9ed
@@ -588,17 +589,17 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
6ae9ed
     if (VIR_REALLOC_N(vm->def->disks, vm->def->ndisks+1) < 0)
6ae9ed
         goto error;
6ae9ed
 
6ae9ed
-    /* Attach the device - 2 step process */
6ae9ed
     qemuDomainObjEnterMonitor(driver, vm);
6ae9ed
 
6ae9ed
     if (qemuMonitorAddDrive(priv->mon, drivestr) < 0)
6ae9ed
-        goto failadddrive;
6ae9ed
+        goto exit_monitor;
6ae9ed
+    driveAdded = true;
6ae9ed
 
6ae9ed
     if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
6ae9ed
-        goto failadddevice;
6ae9ed
+        goto exit_monitor;
6ae9ed
 
6ae9ed
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
6ae9ed
-        goto failexitmonitor;
6ae9ed
+        goto error;
6ae9ed
 
6ae9ed
     virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
6ae9ed
 
6ae9ed
@@ -612,14 +613,13 @@ qemuDomainAttachSCSIDisk(virConnectPtr conn,
6ae9ed
     virObjectUnref(cfg);
6ae9ed
     return ret;
6ae9ed
 
6ae9ed
- failadddevice:
6ae9ed
+ exit_monitor:
6ae9ed
     /* XXX should call 'drive_del' on error but this does not exist yet */
6ae9ed
-    VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
6ae9ed
+    if (driveAdded)
6ae9ed
+        VIR_WARN("qemuMonitorAddDevice failed on %s (%s)", drivestr, devstr);
6ae9ed
 
6ae9ed
- failadddrive:
6ae9ed
     ignore_value(qemuDomainObjExitMonitor(driver, vm));
6ae9ed
 
6ae9ed
- failexitmonitor:
6ae9ed
     virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
6ae9ed
 
6ae9ed
  error:
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed