From: Peter Krempa Date: Fri, 13 Nov 2020 13:07:40 +0000 (+0100) Subject: qemuDomainDiskControllerIsBusy: Fix logic of matching disk bus to controller type X-Git-Tag: v6.10.0-rc1~152 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=022f4d431b7fffc5caa28b9872a061360410e0b2;p=thirdparty%2Flibvirt.git qemuDomainDiskControllerIsBusy: Fix logic of matching disk bus to controller type 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 Reviewed-by: Ján Tomko --- diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 00d908912f..90ed59a0ee 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -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; }