|
|
6ae9ed |
From 9d97987c6cd5a7bf0dbd251d48b72b506bf0abe9 Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <9d97987c6cd5a7bf0dbd251d48b72b506bf0abe9@dist-git>
|
|
|
6ae9ed |
From: John Ferlan <jferlan@redhat.com>
|
|
|
6ae9ed |
Date: Mon, 25 Jul 2016 12:42:53 -0400
|
|
|
6ae9ed |
Subject: [PATCH] qemu: Alter error path cleanup for
|
|
|
6ae9ed |
qemuDomainAttachHostSCSIDevice
|
|
|
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 6fe2eb2458b5e4b84f5aede6d3fdf3ae47c0cd02)
|
|
|
6ae9ed |
Signed-off-by: John Ferlan <jferlan@redhat.com>
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
src/qemu/qemu_hotplug.c | 17 ++++++++---------
|
|
|
6ae9ed |
1 file changed, 8 insertions(+), 9 deletions(-)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
|
|
|
6ae9ed |
index 7a71333..3f63b0e 100644
|
|
|
6ae9ed |
--- a/src/qemu/qemu_hotplug.c
|
|
|
6ae9ed |
+++ b/src/qemu/qemu_hotplug.c
|
|
|
6ae9ed |
@@ -1899,6 +1899,7 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
|
|
|
6ae9ed |
char *drvstr = NULL;
|
|
|
6ae9ed |
bool teardowncgroup = false;
|
|
|
6ae9ed |
bool teardownlabel = false;
|
|
|
6ae9ed |
+ bool driveAdded = false;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_SCSI_GENERIC)) {
|
|
|
6ae9ed |
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
6ae9ed |
@@ -1960,17 +1961,17 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
|
|
|
6ae9ed |
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- /* Attach the device - 2 step process */
|
|
|
6ae9ed |
qemuDomainObjEnterMonitor(driver, vm);
|
|
|
6ae9ed |
|
|
|
6ae9ed |
if (qemuMonitorAddDrive(priv->mon, drvstr) < 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 cleanup;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
virDomainAuditHostdev(vm, hostdev, "attach", true);
|
|
|
6ae9ed |
|
|
|
6ae9ed |
@@ -1993,21 +1994,19 @@ qemuDomainAttachHostSCSIDevice(virConnectPtr conn,
|
|
|
6ae9ed |
VIR_FREE(devstr);
|
|
|
6ae9ed |
return ret;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- failadddevice:
|
|
|
6ae9ed |
+ exit_monitor:
|
|
|
6ae9ed |
orig_err = virSaveLastError();
|
|
|
6ae9ed |
- if (qemuMonitorDriveDel(priv->mon, drvstr) < 0)
|
|
|
6ae9ed |
+ if (driveAdded && qemuMonitorDriveDel(priv->mon, drvstr) < 0) {
|
|
|
6ae9ed |
VIR_WARN("Unable to remove drive %s (%s) after failed "
|
|
|
6ae9ed |
"qemuMonitorAddDevice",
|
|
|
6ae9ed |
drvstr, devstr);
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
if (orig_err) {
|
|
|
6ae9ed |
virSetError(orig_err);
|
|
|
6ae9ed |
virFreeError(orig_err);
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
|
|
|
6ae9ed |
- failadddrive:
|
|
|
6ae9ed |
ignore_value(qemuDomainObjExitMonitor(driver, vm));
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- failexitmonitor:
|
|
|
6ae9ed |
virDomainAuditHostdev(vm, hostdev, "attach", false);
|
|
|
6ae9ed |
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|