render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From 0cf2ad925d4c4258d08e85e80700d6b1163fff2c Mon Sep 17 00:00:00 2001
Message-Id: <0cf2ad925d4c4258d08e85e80700d6b1163fff2c@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Fri, 26 Aug 2016 15:45:27 -0400
Subject: [PATCH] qemu: driver: Validate configuration when setting maximum
 vcpu count

Partially fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1370066
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
https://bugzilla.redhat.com/show_bug.cgi?id=1224341

Setting vcpu count when cpu topology is specified may result into an
invalid configuration. Since the topology can't be modified, reject the
setting if it doesn't match the requested topology. This will allow
fixing the topology in case it was broken.

(cherry picked from commit 802fac97ec8c8bd5438ec5bcd4d13edb03b00fc2)
---
 src/qemu/qemu_driver.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c8c7aee..8081417 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4736,6 +4736,18 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
         goto cleanup;
     }
 
+    if (persistentDef && persistentDef->cpu && persistentDef->cpu->sockets) {
+        /* allow setting a valid vcpu count for the topology so an invalid
+         * setting may be corrected via this API */
+        if (nvcpus != persistentDef->cpu->sockets *
+                      persistentDef->cpu->cores *
+                      persistentDef->cpu->threads) {
+            virReportError(VIR_ERR_INVALID_ARG, "%s",
+                           _("CPU topology doesn't match the desired vcpu count"));
+            goto cleanup;
+        }
+    }
+
     if (virDomainDefSetVcpusMax(persistentDef, nvcpus, driver->xmlopt) < 0)
         goto cleanup;
 
-- 
2.10.0