This patch implements live hotunplug of a cpu device.
Signed-off-by: Zhu Guihua <zhugh.fnst(a)cn.fujitsu.com>
---
src/qemu/qemu_driver.c | 2 ++
src/qemu/qemu_hotplug.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_hotplug.h | 4 +++
3 files changed, 72 insertions(+)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ddc7eeb..004bc35 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7077,6 +7077,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 bff0d14..41013d9 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2876,6 +2876,20 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
static int
+qemuDomainRemoveCPUDevice(virDomainObjPtr vm,
+ virDomainCPUDefPtr cpu)
+{
+ VIR_DEBUG("Removing cpu device %s from domain %p %s",
+ cpu->info.alias, vm, vm->def->name);
+
+ virDomainCPURemove(vm->def, cpu);
+ virDomainCPUDefFree(cpu);
+
+ return 0;
+}
+
+
+static int
qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainChrDefPtr chr)
@@ -2941,6 +2955,9 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
break;
case VIR_DOMAIN_DEVICE_CPU:
+ qemuDomainRemoveCPUDevice(vm, dev->data.cpu);
+ break;
+
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
@@ -3841,3 +3858,52 @@ 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) {
+ qemuDomainObjExitMonitor(driver, vm);
+ goto cleanup;
+ }
+ qemuDomainObjExitMonitor(driver, vm);
+
+ ignore_value(virBitmapClearBit(vm->def->apic_id_map, tmpCPU->apic_id));
+
+ rc = qemuDomainWaitForDeviceRemoval(vm);
+ if (rc == 0 || rc == 1)
+ ret = qemuDomainRemoveCPUDevice(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 6cdead3..5ec7b23 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