Avoid using virDomainDefSetVcpus when we can set it directly in the
structure.
---
src/qemu/qemu_driver.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0fa7d13..9dce1b2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4761,6 +4761,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
unsigned int vcpu)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
+ virDomainVcpuInfoPtr vcpuinfo;
int ret = -1;
int rc;
int oldvcpus = virDomainDefGetVcpus(vm->def);
@@ -4770,6 +4771,15 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
char *mem_mask = NULL;
virDomainNumatuneMemMode mem_mode;
+ if (!(vcpuinfo = virDomainDefGetVcpu(vm->def, vcpu)))
+ return -1;
+
+ if (vcpuinfo->online) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("vCPU '%u' is already online"), vcpu);
+ return -1;
+ }
+
qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorSetCPU(priv->mon, vcpu, true);
@@ -4785,7 +4795,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
if (rc < 0)
goto cleanup;
- ignore_value(virDomainDefSetVcpus(vm->def, oldvcpus + 1));
+ vcpuinfo->online = true;
if (ncpupids < 0)
goto cleanup;
@@ -4861,12 +4871,22 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
unsigned int vcpu)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
+ virDomainVcpuInfoPtr vcpuinfo;
int ret = -1;
int rc;
int oldvcpus = virDomainDefGetVcpus(vm->def);
pid_t *cpupids = NULL;
int ncpupids = 0;
+ if (!(vcpuinfo = virDomainDefGetVcpu(vm->def, vcpu)))
+ return -1;
+
+ if (!vcpuinfo->online) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("vCPU '%u' is already offline"), vcpu);
+ return -1;
+ }
+
qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorSetCPU(priv->mon, vcpu, false);
@@ -4890,7 +4910,7 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
goto cleanup;
}
- ignore_value(virDomainDefSetVcpus(vm->def, oldvcpus - 1));
+ vcpuinfo->online = false;
if (qemuDomainDelCgroupForThread(priv->cgroup,
VIR_CGROUP_THREAD_VCPU, vcpu) < 0)
--
2.6.2