render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
6ae9ed
From bf72946b78df7a69566eb9e25df8210f926aa513 Mon Sep 17 00:00:00 2001
6ae9ed
Message-Id: <bf72946b78df7a69566eb9e25df8210f926aa513@dist-git>
6ae9ed
From: John Ferlan <jferlan@redhat.com>
6ae9ed
Date: Mon, 25 Jul 2016 12:42:54 -0400
6ae9ed
Subject: [PATCH] qemu: Alter error path cleanup for
6ae9ed
 qemuDomainAttachVirtioDiskDevice
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 a7f84cb1ee037c2ea6c803450eb692d8030b4227)
6ae9ed
Signed-off-by: John Ferlan <jferlan@redhat.com>
6ae9ed
---
6ae9ed
 src/qemu/qemu_hotplug.c | 16 +++++++---------
6ae9ed
 1 file changed, 7 insertions(+), 9 deletions(-)
6ae9ed
6ae9ed
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
6ae9ed
index 3f63b0e..e21720b 100644
6ae9ed
--- a/src/qemu/qemu_hotplug.c
6ae9ed
+++ b/src/qemu/qemu_hotplug.c
6ae9ed
@@ -309,6 +309,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
6ae9ed
     char *drivestr = NULL;
6ae9ed
     char *drivealias = NULL;
6ae9ed
     bool releaseaddr = false;
6ae9ed
+    bool driveAdded = false;
6ae9ed
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
6ae9ed
     const char *src = virDomainDiskGetSource(disk);
6ae9ed
 
6ae9ed
@@ -355,18 +356,18 @@ qemuDomainAttachVirtioDiskDevice(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
         releaseaddr = false;
6ae9ed
-        goto failexitmonitor;
6ae9ed
+        goto error;
6ae9ed
     }
6ae9ed
 
6ae9ed
     virDomainAuditDisk(vm, NULL, disk->src, "attach", true);
6ae9ed
@@ -382,9 +383,9 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
6ae9ed
     virObjectUnref(cfg);
6ae9ed
     return ret;
6ae9ed
 
6ae9ed
- failadddevice:
6ae9ed
+ exit_monitor:
6ae9ed
     orig_err = virSaveLastError();
6ae9ed
-    if (qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
6ae9ed
+    if (driveAdded && qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
6ae9ed
         VIR_WARN("Unable to remove drive %s (%s) after failed "
6ae9ed
                  "qemuMonitorAddDevice", drivealias, drivestr);
6ae9ed
     }
6ae9ed
@@ -392,12 +393,9 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
6ae9ed
         virSetError(orig_err);
6ae9ed
         virFreeError(orig_err);
6ae9ed
     }
6ae9ed
-
6ae9ed
- failadddrive:
6ae9ed
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
6ae9ed
         releaseaddr = false;
6ae9ed
 
6ae9ed
- failexitmonitor:
6ae9ed
     virDomainAuditDisk(vm, NULL, disk->src, "attach", false);
6ae9ed
 
6ae9ed
  error:
6ae9ed
-- 
6ae9ed
2.9.2
6ae9ed