This patch implements live hotplug of a cpu device. Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx> --- src/qemu/qemu_driver.c | 6 ++++++ src/qemu/qemu_hotplug.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.h | 8 +++++++ 3 files changed, 71 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c6318bc..00a36e7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7008,6 +7008,12 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm, break; case VIR_DOMAIN_DEVICE_CPU: + ret = qemuDomainAttachCPUDevice(driver, vm, + dev->data.cpu); + if (!ret) + dev->data.cpu = NULL; + break; + case VIR_DOMAIN_DEVICE_NONE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index cf8362c..f51555d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1543,6 +1543,63 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, return ret; } +int +qemuDomainCPUInsert(virDomainDefPtr vmdef, + virDomainCPUDefPtr cpu) +{ + if (virDomainCPUInsert(vmdef, cpu) < 0) + return -1; + + return 0; +} + +int qemuDomainAttachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu) +{ + int ret = -1; + char *devstr = NULL; + qemuDomainObjPrivatePtr priv = vm->privateData; + virDomainDefPtr vmdef = vm->def; + + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("qemu does not support -device")); + goto cleanup; + } + + if (qemuAssignDeviceCPUAlias(vmdef, cpu, -1) < 0) + goto cleanup; + + cpu->apic_id = virDomainCPUGetFreeApicID(vmdef); + + if (qemuBuildCPUDeviceStr(&devstr, driver, vmdef, cpu, priv->qemuCaps) < 0) + goto cleanup; + + if (qemuDomainCPUInsert(vmdef, cpu) < 0) + goto cleanup; + + qemuDomainObjEnterMonitor(driver, vm); + if (devstr && qemuMonitorAddDevice(priv->mon, devstr) < 0) { + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret = -1; + + goto cleanup; + } + + if (qemuDomainObjExitMonitor(driver, vm) < 0) { + ret = -1; + goto cleanup; + } + + ignore_value(virBitmapSetBit(vm->def->apic_id_map, cpu->apic_id)); + ret = 0; + + cleanup: + VIR_FREE(devstr); + return ret; +} + static int qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index a30788d..c583fb7 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -106,6 +106,14 @@ virDomainChrDefPtr qemuDomainChrRemove(virDomainDefPtr vmdef, virDomainChrDefPtr chr); +int +qemuDomainAttachCPUDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainCPUDefPtr cpu); +int +qemuDomainCPUInsert(virDomainDefPtr vmdef, + virDomainCPUDefPtr cpu); + int qemuDomainRemoveDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDeviceDefPtr dev); -- 1.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list