Validate that users don't try to disable vcpu 0 and reject attempt to
modify a vcpu to the state it is currently in.
---
src/qemu/qemu_hotplug.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 5488b1dd4..18a8df33a 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -5875,6 +5875,37 @@ qemuDomainFilterHotplugVcpuEntities(virDomainDefPtr def,
}
+static int
+qemuDomainVcpuValidateConfig(virDomainDefPtr def,
+ virBitmapPtr map,
+ bool state)
+{
+ virDomainVcpuDefPtr vcpu;
+ ssize_t next = -1;
+
+ /* vcpu 0 can't be disabled */
+ if (!state && virBitmapIsBitSet(map, 0)) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("vCPU '0' must be enabled"));
+ return -1;
+ }
+
+ /* make sure that all selected vcpus are in the correct state */
+ while ((next = virBitmapNextSetBit(map, next)) >= 0) {
+ if (!(vcpu = virDomainDefGetVcpu(def, next)))
+ continue;
+
+ if (vcpu->online == state) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("vcpu '%zd' is already in requested
state"), next);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+
int
qemuDomainSetVcpuInternal(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -5909,6 +5940,11 @@ qemuDomainSetVcpuInternal(virQEMUDriverPtr driver,
}
}
+ if (persistentDef) {
+ if (qemuDomainVcpuValidateConfig(persistentDef, map, state) < 0)
+ goto cleanup;
+ }
+
if (livevcpus &&
qemuDomainSetVcpusLive(driver, cfg, vm, livevcpus, state) < 0)
goto cleanup;
--
2.12.2