render / rpms / libvirt

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