]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuDomainDiskControllerIsBusy: Fix logic of matching disk bus to controller type
authorPeter Krempa <pkrempa@redhat.com>
Fri, 13 Nov 2020 13:07:40 +0000 (14:07 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 Nov 2020 13:05:06 +0000 (14:05 +0100)
The tests which match the disk bus to the controller type were backwards
in this function. This meant that any disk bus type (such as
VIR_DOMAIN_DISK_BUS_SATA) would not skip the controller index comparison
even if the removed controller was of a different type.

Switch the internals to a switch statement with selects the controller
type in the first place and a proper type so that new controller types
are added in the future.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1870072
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_hotplug.c

index 00d908912f182d9a96b6463483f9dd0ec4e13e21..90ed59a0ee15d72bfc97a424cbc683de82150d65 100644 (file)
@@ -5327,16 +5327,48 @@ qemuDomainDiskControllerIsBusy(virDomainObjPtr vm,
             continue;
 
         /* check whether the disk uses this type controller */
-        if (disk->bus == VIR_DOMAIN_DISK_BUS_IDE &&
-            detach->type != VIR_DOMAIN_CONTROLLER_TYPE_IDE)
+        switch ((virDomainControllerType) detach->type) {
+        case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
+            if (disk->bus != VIR_DOMAIN_DISK_BUS_IDE)
+                continue;
+            break;
+
+        case VIR_DOMAIN_CONTROLLER_TYPE_FDC:
+            if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC)
+                continue;
+            break;
+
+        case VIR_DOMAIN_CONTROLLER_TYPE_SCSI:
+            if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI)
+                continue;
+            break;
+
+        case VIR_DOMAIN_CONTROLLER_TYPE_SATA:
+            if (disk->bus != VIR_DOMAIN_DISK_BUS_SATA)
+                continue;
+            break;
+
+        case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS:
+            /* xenbus is not supported by the qemu driver */
             continue;
-        if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC &&
-            detach->type != VIR_DOMAIN_CONTROLLER_TYPE_FDC)
+
+        case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
+            /* virtio-serial does not host any disks */
             continue;
-        if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI &&
-            detach->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI)
+
+        case VIR_DOMAIN_CONTROLLER_TYPE_CCID:
+        case VIR_DOMAIN_CONTROLLER_TYPE_USB:
+        case VIR_DOMAIN_CONTROLLER_TYPE_PCI:
+        case VIR_DOMAIN_CONTROLLER_TYPE_ISA:
+            /* These buses have (also) other device types too so they need to
+             * be checked elsewhere */
             continue;
 
+        case VIR_DOMAIN_CONTROLLER_TYPE_LAST:
+        default:
+            continue;
+        }
+
         if (disk->info.addr.drive.controller == detach->idx)
             return true;
     }