This patch implements live hotunplug of a cpu device. Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx> --- src/qemu/qemu_driver.c | 2 ++ src/qemu/qemu_hotplug.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.h | 4 +++ 3 files changed, 81 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 00a36e7..bf33d7a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7090,6 +7090,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret = qemuDomainDetachChrDevice(driver, vm, dev->data.chr); break; case VIR_DOMAIN_DEVICE_CPU: + ret = qemuDomainDetachCPUDevice(driver, vm, dev->data.cpu); + break; case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: case VIR_DOMAIN_DEVICE_SOUND: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f51555d..975ed1d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2918,6 +2918,27 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver, } +static int +qemuDomainRemoveCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ + virObjectEventPtr event; + + VIR_DEBUG("Removing cpu device %s from domain %p %s", + cpu->info.alias, vm, vm->def->name); + + event = virDomainEventDeviceRemovedNewFromObj(vm, cpu->info.alias); + if (event) + qemuDomainEventQueue(driver, event); + + virDomainCPURemove(vm->def, cpu); + virDomainCPUDefFree(cpu); + + return 0; +} + + int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -3843,3 +3864,57 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, VIR_FREE(devstr); return ret; } + +int qemuDomainDetachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ + int ret = -1; + qemuDomainObjPrivatePtr priv = vm->privateData; + virDomainDefPtr vmdef = vm->def; + virDomainCPUDefPtr tmpCPU; + int rc = 0; + + if (!(tmpCPU = virDomainCPUFind(vmdef, cpu))) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("device not present in domain configration")); + return ret; + } + + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("qemu does not support -device")); + } + + if (!tmpCPU->info.alias) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("detaching cpu device without id is not supported")); + return ret; + } + + qemuDomainMarkDeviceForRemoval(vm, &tmpCPU->info); + + qemuDomainObjEnterMonitor(driver, vm); + if (qemuMonitorDelDevice(priv->mon, tmpCPU->info.alias) < 0) { + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret = -1; + + goto cleanup; + } + if (qemuDomainObjExitMonitor(driver, vm) < 0) { + ret = -1; + goto cleanup; + } + + ignore_value(virBitmapClearBit(vm->def->apic_id_map, tmpCPU->apic_id)); + + rc = qemuDomainWaitForDeviceRemoval(vm); + if (rc == 0 || rc == 1) + ret = qemuDomainRemoveCPUDevice(driver, vm, tmpCPU); + else + goto cleanup; + + cleanup: + qemuDomainResetDeviceRemoval(vm); + return ret; +} diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index c583fb7..c168ac5 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -113,6 +113,10 @@ qemuDomainAttachCPUDevice(virQEMUDriverPtr driver, int qemuDomainCPUInsert(virDomainDefPtr vmdef, virDomainCPUDefPtr cpu); +int +qemuDomainDetachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu); int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, -- 1.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list