From b6f6759fcada504563b4c439975bee66fd611162 Mon Sep 17 00:00:00 2001 Message-Id: From: Peter Krempa Date: Tue, 4 Apr 2017 09:31:24 +0200 Subject: [PATCH] qemu: hotplug: Validate that vcpu-hotplug does not break config Make sure that non-hotpluggable vcpus stay clustered at the beginning after modifying persistent definition. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1437010 (cherry picked from commit 079832103c3b7883e36db90705631cc55cac9dcc) --- src/qemu/qemu_hotplug.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 999c8b804..a6dac6f09 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -5876,9 +5876,14 @@ qemuDomainFilterHotplugVcpuEntities(virDomainDefPtr def, static int -qemuDomainVcpuValidateConfig(virBitmapPtr map, +qemuDomainVcpuValidateConfig(virDomainDefPtr def, + virBitmapPtr map, bool state) { + virDomainVcpuDefPtr vcpu; + size_t maxvcpus = virDomainDefGetVcpusMax(def); + ssize_t next; + /* vcpu 0 can't be disabled */ if (!state && virBitmapIsBitSet(map, 0)) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -5886,6 +5891,23 @@ qemuDomainVcpuValidateConfig(virBitmapPtr map, return -1; } + /* non-hotpluggable vcpus need to stay clustered starting from vcpu 0 */ + for (next = virBitmapNextSetBit(map, -1) + 1; next < maxvcpus; next++) { + if (!(vcpu = virDomainDefGetVcpu(def, next))) + continue; + + /* skip vcpus being modified */ + if (virBitmapIsBitSet(map, next)) + continue; + + if (vcpu->online && vcpu->hotpluggable == VIR_TRISTATE_BOOL_NO) { + virReportError(VIR_ERR_INVALID_ARG, + _("vcpu '%zd' can't be modified as it is followed " + "by non-hotpluggable online vcpus"), next); + return -1; + } + } + return 0; } @@ -5925,7 +5947,7 @@ qemuDomainSetVcpuInternal(virQEMUDriverPtr driver, } if (persistentDef) { - if (qemuDomainVcpuValidateConfig(map, state) < 0) + if (qemuDomainVcpuValidateConfig(persistentDef, map, state) < 0) goto cleanup; } -- 2.12.2