Blob Blame History Raw
From f87f0fc731dcb28cfcbe65bb7a69628f431030aa Mon Sep 17 00:00:00 2001
Message-Id: <f87f0fc731dcb28cfcbe65bb7a69628f431030aa@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Thu, 15 Dec 2016 18:17:45 +0100
Subject: [PATCH] qemuDomainAttachNetDevice: Don't overwrite error on rollback

RHEL-7.4: https://bugzilla.redhat.com/show_bug.cgi?id=1386976
RHEL-7.3.z: https://bugzilla.redhat.com/show_bug.cgi?id=1404186

If there is an error hotpluging a net device (for whatever
reason) a rollback operation is performed. However, whilst doing
so various helper functions that are called report errors on
their own. This results in the original error to be overwritten
and thus misleading the user.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
(cherry picked from commit 0e82fa4c345acb7ad52e0da0e54f7375eda57657)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_hotplug.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 8acbf370b..573cb8c93 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -885,6 +885,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
                           virDomainNetDefPtr net)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    virErrorPtr originalError = NULL;
     char **tapfdName = NULL;
     int *tapfd = NULL;
     size_t tapfdSize = 0;
@@ -1266,6 +1267,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
     if (!virDomainObjIsActive(vm))
         goto cleanup;
 
+    originalError = virSaveLastError();
     if (vlan < 0) {
         if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NETDEV)) {
             char *netdev_name;
@@ -1296,6 +1298,8 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
         ignore_value(qemuDomainObjExitMonitor(driver, vm));
         VIR_FREE(hostnet_name);
     }
+    virSetError(originalError);
+    virFreeError(originalError);
     goto cleanup;
 }
 
-- 
2.11.0