qemuDomainDetachDiskDevice() is only called from one place. Moving the contents of the function to that place makes qemuDomainDetachDiskLive() more similar to the other Detach functions called by the toplevel qemuDomainDetachDevice(). The goal is to make each of the device-type-specific functions do this: 1) find the exact device 2) do any device-specific validation 3) do general validation 4) do device-specific shutdown (only needed for net devices) 5) do the common block of code to send device_del to qemu, then optionally wait for a corresponding DEVICE_DELETED event from qemu. with the final aim being that only items 1 & 2 will remain in each device-type-specific function, while 3 & 5 (which are the same for almost every type) will be de-duplicated and moved to the toplevel function that calls all of these (qemuDomainDetachDeviceLive(), which will also contain a callout to the one instance of (4) (netdev). Signed-off-by: Laine Stump <laine@xxxxxxxxx> --- src/qemu/qemu_hotplug.c | 96 ++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index af99f3bf4c..820929b109 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5273,47 +5273,6 @@ qemuDomainSignalDeviceRemoval(virDomainObjPtr vm, } -static int -qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr detach, - bool async) -{ - int ret = -1; - - if (qemuDomainDiskBlockJobIsActive(detach)) - return -1; - - if (detach->bus == VIR_DOMAIN_DISK_BUS_VIRTIO && - qemuIsMultiFunctionDevice(vm->def, &detach->info)) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("cannot hot unplug multifunction PCI device: %s"), - detach->dst); - return -1; - } - - if (!async) - qemuDomainMarkDeviceForRemoval(vm, &detach->info); - - if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) { - if (virDomainObjIsActive(vm)) - virDomainAuditDisk(vm, detach->src, NULL, "detach", false); - goto cleanup; - } - - if (async) { - ret = 0; - } else { - if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) - ret = qemuDomainRemoveDiskDevice(driver, vm, detach); - } - - cleanup: - if (!async) - qemuDomainResetDeviceRemoval(vm); - return ret; -} - static int qemuFindDisk(virDomainDefPtr def, const char *dst) { @@ -5333,25 +5292,26 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, virDomainDeviceDefPtr dev, bool async) { - virDomainDiskDefPtr disk; + virDomainDiskDefPtr detach; int idx; + int ret = -1; if ((idx = qemuFindDisk(vm->def, dev->data.disk->dst)) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, _("disk %s not found"), dev->data.disk->dst); return -1; } - disk = vm->def->disks[idx]; + detach = vm->def->disks[idx]; - switch ((virDomainDiskDevice) disk->device) { + switch ((virDomainDiskDevice) detach->device) { case VIR_DOMAIN_DISK_DEVICE_DISK: case VIR_DOMAIN_DISK_DEVICE_LUN: - switch ((virDomainDiskBus) disk->bus) { + switch ((virDomainDiskBus) detach->bus) { case VIR_DOMAIN_DISK_BUS_VIRTIO: case VIR_DOMAIN_DISK_BUS_USB: case VIR_DOMAIN_DISK_BUS_SCSI: - return qemuDomainDetachDiskDevice(driver, vm, disk, async); + break; case VIR_DOMAIN_DISK_BUS_IDE: case VIR_DOMAIN_DISK_BUS_FDC: @@ -5361,12 +5321,12 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, case VIR_DOMAIN_DISK_BUS_SD: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("This type of disk cannot be hot unplugged")); - break; + return -1; case VIR_DOMAIN_DISK_BUS_LAST: default: - virReportEnumRangeError(virDomainDiskBus, disk->bus); - break; + virReportEnumRangeError(virDomainDiskBus, detach->bus); + return -1; } break; @@ -5374,16 +5334,46 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, case VIR_DOMAIN_DISK_DEVICE_FLOPPY: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("disk device type '%s' cannot be detached"), - virDomainDiskDeviceTypeToString(disk->device)); - break; + virDomainDiskDeviceTypeToString(detach->device)); + return -1; case VIR_DOMAIN_DISK_DEVICE_LAST: default: - virReportEnumRangeError(virDomainDiskDevice, disk->device); + virReportEnumRangeError(virDomainDiskDevice, detach->device); break; } - return -1; + if (qemuDomainDiskBlockJobIsActive(detach)) + return -1; + + if (detach->bus == VIR_DOMAIN_DISK_BUS_VIRTIO && + qemuIsMultiFunctionDevice(vm->def, &detach->info)) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("cannot hot unplug multifunction PCI device: %s"), + detach->dst); + return -1; + } + + if (!async) + qemuDomainMarkDeviceForRemoval(vm, &detach->info); + + if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) { + if (virDomainObjIsActive(vm)) + virDomainAuditDisk(vm, detach->src, NULL, "detach", false); + goto cleanup; + } + + if (async) { + ret = 0; + } else { + if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) + ret = qemuDomainRemoveDiskDevice(driver, vm, detach); + } + + cleanup: + if (!async) + qemuDomainResetDeviceRemoval(vm); + return ret; } -- 2.20.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list