Blame SOURCES/libvirt-qemu_hotplug-separate-Chr-Lease-from-other-devices-in-DetachDevice-switch.patch

99cbc7
From ff7bc70a5e5d7aaf354ce501653beb82429030fe Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <ff7bc70a5e5d7aaf354ce501653beb82429030fe@dist-git>
99cbc7
From: Laine Stump <laine@laine.org>
99cbc7
Date: Thu, 11 Apr 2019 15:14:46 -0400
99cbc7
Subject: [PATCH] qemu_hotplug: separate Chr|Lease from other devices in
99cbc7
 DetachDevice switch
99cbc7
99cbc7
The Chr and Lease devices have detach code that is too different from
99cbc7
the other device types to handle with common functionality (which will
99cbc7
soon be added at the end of qemuDomainDetachDeviceLive(). In order to
99cbc7
make this difference obvious, move the cases for those two device
99cbc7
types to the top of the switch statement in
99cbc7
qemuDomainDetachDeviceLive(), have the cases return immediately so the
99cbc7
future common code at the end of the function will be skipped, and
99cbc7
also include some hopefully helpful comments to remind future
99cbc7
maintainers why these two device types are treated differently.
99cbc7
99cbc7
Any attempt to detach an unsupported device type should also skip the
99cbc7
future common code at the end of the function, so the case for
99cbc7
unsupported types is similarly changed from a simple break to a return
99cbc7
-1.
99cbc7
99cbc7
Signed-off-by: Laine Stump <laine@laine.org>
99cbc7
ACKed-by: Peter Krempa <pkrempa@redhat.com>
99cbc7
(cherry picked from commit 2ec6faea798b2a7d8986b7a958e781b54d8a8070)
99cbc7
99cbc7
Partially-Resolves: https://bugzilla.redhat.com/1658198
99cbc7
Signed-off-by: Laine Stump <laine@redhat.com>
99cbc7
Signed-off-by: Laine Stump <laine@laine.org>
99cbc7
Message-Id: <20190411191453.24055-35-laine@redhat.com>
99cbc7
Acked-by: Michal Privoznik <mprivozn@redhat.com>
99cbc7
---
99cbc7
 src/qemu/qemu_hotplug.c | 26 +++++++++++++++++++-------
99cbc7
 1 file changed, 19 insertions(+), 7 deletions(-)
99cbc7
99cbc7
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
99cbc7
index a655fc391f..9c0ee1c6a5 100644
99cbc7
--- a/src/qemu/qemu_hotplug.c
99cbc7
+++ b/src/qemu/qemu_hotplug.c
99cbc7
@@ -5657,24 +5657,36 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
99cbc7
     int ret = -1;
99cbc7
 
99cbc7
     switch ((virDomainDeviceType)match->type) {
99cbc7
+        /*
99cbc7
+         * lease and chr devices don't follow the standard pattern of
99cbc7
+         * the others, so they must have their own self-contained
99cbc7
+         * Detach functions.
99cbc7
+         */
99cbc7
+    case VIR_DOMAIN_DEVICE_LEASE:
99cbc7
+        return qemuDomainDetachLease(driver, vm, match->data.lease);
99cbc7
+
99cbc7
+    case VIR_DOMAIN_DEVICE_CHR:
99cbc7
+        return qemuDomainDetachChrDevice(driver, vm, match->data.chr, async);
99cbc7
+
99cbc7
+        /*
99cbc7
+         * All the other device types follow a very similar pattern -
99cbc7
+         * First we call type-specific functions to 1) locate the
99cbc7
+         * device we want to detach (based on the prototype device in
99cbc7
+         * match) and 2) do any device-type-specific validation to
99cbc7
+         * assure it is okay to detach the device.
99cbc7
+         */
99cbc7
     case VIR_DOMAIN_DEVICE_DISK:
99cbc7
         ret = qemuDomainDetachDeviceDiskLive(driver, vm, match, async);
99cbc7
         break;
99cbc7
     case VIR_DOMAIN_DEVICE_CONTROLLER:
99cbc7
         ret = qemuDomainDetachControllerDevice(driver, vm, match, async);
99cbc7
         break;
99cbc7
-    case VIR_DOMAIN_DEVICE_LEASE:
99cbc7
-        ret = qemuDomainDetachLease(driver, vm, match->data.lease);
99cbc7
-        break;
99cbc7
     case VIR_DOMAIN_DEVICE_NET:
99cbc7
         ret = qemuDomainDetachNetDevice(driver, vm, match, async);
99cbc7
         break;
99cbc7
     case VIR_DOMAIN_DEVICE_HOSTDEV:
99cbc7
         ret = qemuDomainDetachHostDevice(driver, vm, match, async);
99cbc7
         break;
99cbc7
-    case VIR_DOMAIN_DEVICE_CHR:
99cbc7
-        ret = qemuDomainDetachChrDevice(driver, vm, match->data.chr, async);
99cbc7
-        break;
99cbc7
     case VIR_DOMAIN_DEVICE_RNG:
99cbc7
         ret = qemuDomainDetachRNGDevice(driver, vm, match->data.rng, async);
99cbc7
         break;
99cbc7
@@ -5714,7 +5726,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
99cbc7
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
99cbc7
                        _("live detach of device '%s' is not supported"),
99cbc7
                        virDomainDeviceTypeToString(match->type));
99cbc7
-        break;
99cbc7
+        return -1;
99cbc7
     }
99cbc7
 
99cbc7
     return ret;
99cbc7
-- 
99cbc7
2.21.0
99cbc7