From 279ba2d1cceceb70fa2463da7075bfe7cb6e43a3 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 13 Nov 2020 14:15:19 +0100 Subject: [PATCH] qemuDomainDiskControllerIsBusy: Optimize checking for SCSI hostdevs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Iterate through hostdevs only when the controller type is VIR_DOMAIN_CONTROLLER_TYPE_SCSI. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_hotplug.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 90ed59a0ee..124f60912f 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5373,13 +5373,15 @@ qemuDomainDiskControllerIsBusy(virDomainObjPtr vm, return true; } - for (i = 0; i < vm->def->nhostdevs; i++) { - hostdev = vm->def->hostdevs[i]; - if (!virHostdevIsSCSIDevice(hostdev) || - detach->type != VIR_DOMAIN_CONTROLLER_TYPE_SCSI) - continue; - if (hostdev->info->addr.drive.controller == detach->idx) - return true; + if (detach->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI) { + for (i = 0; i < vm->def->nhostdevs; i++) { + hostdev = vm->def->hostdevs[i]; + if (!virHostdevIsSCSIDevice(hostdev)) + continue; + + if (hostdev->info->addr.drive.controller == detach->idx) + return true; + } } return false;