[PATCH 2/2] qemu: Reuse virDomainDeGetVcpusTopology to calculate total vcpu count

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rather than multiplying sockets, cores, and threads use the new helper
for getting the vcpu count resulting from the topology.
---
 src/qemu/qemu_domain.c | 18 ++++++++----------
 src/qemu/qemu_driver.c | 14 ++++++--------
 2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2b24c01..83ac389 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2401,7 +2401,7 @@ qemuDomainDefValidate(const virDomainDef *def,
 {
     virQEMUDriverPtr driver = opaque;
     virQEMUCapsPtr qemuCaps = NULL;
-    size_t topologycpus;
+    unsigned int topologycpus;
     int ret = -1;

     if (!(qemuCaps = virQEMUCapsCacheLookup(caps,
@@ -2443,15 +2443,13 @@ qemuDomainDefValidate(const virDomainDef *def,
     }

     /* qemu as of 2.5.0 rejects SMP topologies that don't match the cpu count */
-    if (def->cpu && def->cpu->sockets) {
-        topologycpus = def->cpu->sockets * def->cpu->cores * def->cpu->threads;
-        if (topologycpus != virDomainDefGetVcpusMax(def)) {
-            /* presence of query-hotpluggable-cpus should be a good enough witness */
-            if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("CPU topology doesn't match maximum vcpu count"));
-                goto cleanup;
-            }
+    if (virDomainDefGetVcpusTopology(def, &topologycpus) == 0 &&
+        topologycpus != virDomainDefGetVcpusMax(def)) {
+        /* presence of query-hotpluggable-cpus should be a good enough witness */
+        if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_HOTPLUGGABLE_CPUS)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("CPU topology doesn't match maximum vcpu count"));
+            goto cleanup;
         }
     }

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 29a7e3f..e6f845d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4718,6 +4718,7 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
                       unsigned int nvcpus)
 {
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    unsigned int topologycpus;
     int ret = -1;

     if (def) {
@@ -4733,16 +4734,13 @@ qemuDomainSetVcpusMax(virQEMUDriverPtr driver,
         goto cleanup;
     }

-    if (persistentDef->cpu && persistentDef->cpu->sockets) {
+    if (virDomainDefGetVcpusTopology(persistentDef, &topologycpus) == 0 &&
+        nvcpus != topologycpus) {
         /* 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;
-        }
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("CPU topology doesn't match the desired vcpu count"));
+        goto cleanup;
     }

     /* ordering information may become invalid, thus clear it */
-- 
2.10.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]