On 01/14/2016 11:27 AM, Peter Krempa wrote:
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 f3844d6..3aa49f2 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4680,6 +4680,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
unsigned int vcpu)
{
qemuDomainObjPrivatePtr priv = vm->privateData;
+ virDomainVcpuInfoPtr vcpuinfo;
int ret = -1;
int rc;
int oldvcpus = virDomainDefGetVcpus(vm->def);
@@ -4689,6 +4690,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;
+ }
+
Yet another construct that could benefit from an OnlineVcpuMap and
virBitmapCountBits would tell us how many bits are set (oldvcpus in this
instance).
qemuDomainObjEnterMonitor(driver, vm);
rc = qemuMonitorSetCPU(priv->mon, vcpu, true);
@@ -4704,7 +4714,7 @@ qemuDomainHotplugAddVcpu(virQEMUDriverPtr driver,
if (rc < 0)
goto cleanup;
- ignore_value(virDomainDefSetVcpus(vm->def, oldvcpus + 1));
+ vcpuinfo->online = true;
Setting online bit directly...
[and repeat for DelVcpu]
John
if (ncpupids < 0)
goto cleanup;
@@ -4780,12 +4790,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);
@@ -4809,7 +4829,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)