Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx> --- src/qemu/qemu_driver.c | 2 ++ src/qemu/qemu_hotplug.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_hotplug.h | 3 +++ 3 files changed, 59 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 76ff7b5..61a4ead 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7074,6 +7074,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm, ret = qemuDomainDetachChrDevice(driver, vm, dev->data.chr); break; case VIR_DOMAIN_DEVICE_DIMM: + ret = qemuDomainDetachDimmDevice(driver, vm, dev->data.dimm); + 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 8a0594f..4895f95 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3897,3 +3897,57 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, VIR_FREE(devstr); return ret; } + +int qemuDomainDetachDimmDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDimmDefPtr dimm) +{ + int ret = -1; + qemuDomainObjPrivatePtr priv = vm->privateData; + virDomainDefPtr vmdef = vm->def; + virDomainDimmDefPtr tmpDimm; + int rc; + + if (!(tmpDimm = virDomainDimmFind(vmdef, dimm))) { + 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")); + return ret; + } + + if (!tmpDimm->info.alias) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("detaching dimm device without alias name is not suported")); + return ret; + } + + qemuDomainMarkDeviceForRemoval(vm, &tmpDimm->info); + + qemuDomainObjEnterMonitor(driver, vm); + if (qemuMonitorDelDevice(priv->mon, tmpDimm->info.alias) < 0) { + qemuDomainObjExitMonitor(driver, vm); + goto cleanup; + } + qemuDomainObjExitMonitor(driver, vm); + + virDomainAuditMemory(vm, vm->def->mem.cur_balloon, + vm->def->mem.cur_balloon - tmpDimm->backend.size, + "update", true); + + ignore_value(virBitmapClearBit(vm->def->mem.dimm_slot_map, tmpDimm->slot)); + + rc = qemuDomainWaitForDeviceRemoval(vm); + if (rc == 0 || rc == 1) + ret = qemuDomainRemoveDimmDevice(driver, vm, tmpDimm); + else + goto cleanup; + + cleanup: + qemuDomainResetDeviceRemoval(vm); + return ret; +} diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h index 1e9f7b3..f47a849 100644 --- a/src/qemu/qemu_hotplug.h +++ b/src/qemu/qemu_hotplug.h @@ -98,6 +98,9 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver, int qemuDomainDetachChrDevice(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainChrDefPtr chr); +int qemuDomainDetachDimmDevice(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainDimmDefPtr dimm); int -- 1.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list