[libvirt] [PATCH v2 07/14] qemu_hotplug: separate Chr|Lease from other devices in DetachDevice switch

Laine Stump laine at laine.org
Mon Mar 25 17:24:29 UTC 2019


The Chr and Lease devices have detach code that is too different from
the other device types to handle with common functionality (which will
soon be added at the end of qemuDomainDetachDeviceLive(). In order to
make this difference obvious, move the cases for those two device
types to the top of the switch statement in
qemuDomainDetachDeviceLive(), have the cases return immediately so the
future common code at the end of the function will be skipped, and
also include some hopefully helpful comments to remind future
maintainers why these two device types are treated differently.

Any attempt to detach an unsupported device type should also skip the
future common code at the end of the function, so the case for
unsupported types is similarly changed from a simple break to a return
-1.

Signed-off-by: Laine Stump <laine at laine.org>
---

NEW PATCH IN V2.

 src/qemu/qemu_hotplug.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 18bf2da264..c9b8868f9c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -6209,24 +6209,36 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
     int ret = -1;
 
     switch ((virDomainDeviceType)match->type) {
+        /*
+         * lease and chr devices don't follow the standard pattern of
+         * the others, so they must have their own self-contained
+         * Detach functions.
+         */
+    case VIR_DOMAIN_DEVICE_LEASE:
+        return qemuDomainDetachLease(driver, vm, match->data.lease);
+
+    case VIR_DOMAIN_DEVICE_CHR:
+        return qemuDomainDetachChrDevice(driver, vm, match->data.chr, async);
+
+        /*
+         * All the other device types follow a very similar pattern -
+         * First we call type-specific functions to 1) locate the
+         * device we want to detach (based on the prototype device in
+         * match) and 2) do any device-type-specific validation to
+         * assure it is okay to detach the device.
+         */
     case VIR_DOMAIN_DEVICE_DISK:
         ret = qemuDomainDetachDeviceDiskLive(driver, vm, match, async);
         break;
     case VIR_DOMAIN_DEVICE_CONTROLLER:
         ret = qemuDomainDetachControllerDevice(driver, vm, match, async);
         break;
-    case VIR_DOMAIN_DEVICE_LEASE:
-        ret = qemuDomainDetachLease(driver, vm, match->data.lease);
-        break;
     case VIR_DOMAIN_DEVICE_NET:
         ret = qemuDomainDetachNetDevice(driver, vm, match, async);
         break;
     case VIR_DOMAIN_DEVICE_HOSTDEV:
         ret = qemuDomainDetachHostDevice(driver, vm, match, async);
         break;
-    case VIR_DOMAIN_DEVICE_CHR:
-        ret = qemuDomainDetachChrDevice(driver, vm, match->data.chr, async);
-        break;
     case VIR_DOMAIN_DEVICE_RNG:
         ret = qemuDomainDetachRNGDevice(driver, vm, match->data.rng, async);
         break;
@@ -6266,7 +6278,7 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                        _("live detach of device '%s' is not supported"),
                        virDomainDeviceTypeToString(match->type));
-        break;
+        return -1;
     }
 
     return ret;
-- 
2.20.1




More information about the libvir-list mailing list