From f60135d37a9f5bb3a06761da5ff097d2f6a16a56 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 18 May 2021 15:10:22 +0200 Subject: [PATCH] qemuDomainAttachDeviceDiskLiveInternal: Absorb qemuDomainAttachVirtioDiskDevice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Move the specific device setup and address reservation code into the main hotplug helper as it's just one extra function call. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko Reviewed-by: Pavel Hrdina --- src/qemu/qemu_hotplug.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 93f0bd55e5..0f5f3fbb86 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -798,29 +798,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriver *driver, } -static int -qemuDomainAttachVirtioDiskDevice(virQEMUDriver *driver, - virDomainObj *vm, - virDomainDiskDef *disk) -{ - virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_DISK, { .disk = disk } }; - bool releaseaddr = false; - int rv; - - if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev, disk->dst) < 0) - return -1; - - if ((rv = qemuDomainAttachDiskGeneric(driver, vm, disk)) < 0) { - if (rv == -1 && releaseaddr) - qemuDomainReleaseDeviceAddress(vm, &disk->info); - - return -1; - } - - return 0; -} - - int qemuDomainAttachControllerDevice(virQEMUDriver *driver, virDomainObj *vm, virDomainControllerDef *controller) @@ -1005,6 +982,7 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, size_t i; virDomainDiskDef *disk = dev->data.disk; bool releaseUSB = false; + bool releaseVirtio = false; int ret = -1; if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM || @@ -1054,7 +1032,10 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, break; case VIR_DOMAIN_DISK_BUS_VIRTIO: - ret = qemuDomainAttachVirtioDiskDevice(driver, vm, disk); + if (qemuDomainEnsureVirtioAddress(&releaseVirtio, vm, dev, disk->dst) < 0) + goto cleanup; + + ret = qemuDomainAttachDiskGeneric(driver, vm, disk); break; case VIR_DOMAIN_DISK_BUS_SCSI: @@ -1083,6 +1064,9 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver, if (releaseUSB) virDomainUSBAddressRelease(priv->usbaddrs, &disk->info); + + if (releaseVirtio && ret == -1) + qemuDomainReleaseDeviceAddress(vm, &disk->info); } return ret;