diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 4e99efe770..ed29373025 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6362,58 +6362,6 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, return ret; } -static int -qemuFindDisk(virDomainDefPtr def, const char *dst) -{ - size_t i; - - for (i = 0; i < def->ndisks; i++) { - if (STREQ(def->disks[i]->dst, dst)) { - return i; - } - } - - return -1; -} - -static int -qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDeviceDefPtr dev) -{ - virDomainDiskDefPtr disk; - int ret = -1; - int idx; - - 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]; - - switch (disk->device) { - case VIR_DOMAIN_DISK_DEVICE_DISK: - case VIR_DOMAIN_DISK_DEVICE_LUN: - if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) - ret = qemuDomainDetachVirtioDiskDevice(driver, vm, disk); - else if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI || - disk->bus == VIR_DOMAIN_DISK_BUS_USB) - ret = qemuDomainDetachDiskDevice(driver, vm, disk); - else - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("This type of disk cannot be hot unplugged")); - break; - default: - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("disk device type '%s' cannot be detached"), - virDomainDiskDeviceTypeToString(disk->device)); - break; - } - - return ret; -} - static int qemuDomainDetachDeviceControllerLive(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f221faefb3..0cc4977693 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2752,9 +2752,10 @@ qemuDomainSignalDeviceRemoval(virDomainObjPtr vm, } -int qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr detach) +static int +qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr detach) { int ret = -1; qemuDomainObjPrivatePtr priv = vm->privateData; @@ -2823,9 +2824,10 @@ cleanup: return ret; } -int qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr detach) +static int +qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDiskDefPtr detach) { int ret = -1; qemuDomainObjPrivatePtr priv = vm->privateData; @@ -2875,6 +2877,59 @@ cleanup: return ret; } +static int +qemuFindDisk(virDomainDefPtr def, const char *dst) +{ + size_t i; + + for (i = 0; i < def->ndisks; i++) { + if (STREQ(def->disks[i]->dst, dst)) { + return i; + } + } + + return -1; +} + +int +qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev) +{ + virDomainDiskDefPtr disk; + int ret = -1; + int idx; + + 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]; + + switch (disk->device) { + case VIR_DOMAIN_DISK_DEVICE_DISK: + case VIR_DOMAIN_DISK_DEVICE_LUN: + if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) + ret = qemuDomainDetachVirtioDiskDevice(driver, vm, disk); + else if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI || + disk->bus == VIR_DOMAIN_DISK_BUS_USB) + ret = qemuDomainDetachDiskDevice(driver, vm, disk); + else + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("This type of disk cannot be hot unplugged")); + break; + default: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("disk device type '%s' cannot be detached"), + virDomainDiskDeviceTypeToString(disk->device)); + break; + } + + return ret; +} + + static bool qemuDomainDiskControllerIsBusy(virDomainObjPtr vm, virDomainControllerDefPtr detach) { diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 80f6e4b473..355d809c26 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -75,12 +75,9 @@ int qemuDomainChangeNetLinkState(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainNetDefPtr dev, int linkstate); -int qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr disk); -int qemuDomainDetachDiskDevice(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr disk); +int qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDeviceDefPtr dev); int qemuDomainDetachPciControllerDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev);