[PATCH 2/2] qemuDomainGetNumaParameters: Don't report spurious info

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

 



This API does not work well on domains without <numatune/>. It blindly
reports misleading info on a shutoff domain:

  # virsh numatune rhel7
  numa_mode      : strict
  numa_nodeset   :

This is obviously wrong as long as there's no numatune for rhel7
domain, which isn't. What we should do, is report only those NUMA
parameters, that domain has defined.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e7f235b..9b3bc68 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -10522,13 +10522,14 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
                             unsigned int flags)
 {
     virQEMUDriverPtr driver = dom->conn->privateData;
-    size_t i;
+    size_t i, j;
     virDomainObjPtr vm = NULL;
     virDomainDefPtr persistentDef = NULL;
     char *nodeset = NULL;
     int ret = -1;
     virCapsPtr caps = NULL;
     virDomainDefPtr def = NULL;
+    bool hasNumatune;
 
     virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
                   VIR_DOMAIN_AFFECT_CONFIG |
@@ -10552,31 +10553,40 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
                                         &persistentDef) < 0)
         goto cleanup;
 
-    if ((*nparams) == 0) {
-        *nparams = QEMU_NB_NUMA_PARAM;
-        ret = 0;
-        goto cleanup;
-    }
-
     if (flags & VIR_DOMAIN_AFFECT_CONFIG)
         def = persistentDef;
     else
         def = vm->def;
 
-    for (i = 0; i < QEMU_NB_NUMA_PARAM && i < *nparams; i++) {
-        virMemoryParameterPtr param = &params[i];
+    hasNumatune = virDomainNumatuneGetMode(def->numa, -1, NULL) == 0;
+
+    if ((*nparams) == 0) {
+        *nparams = QEMU_NB_NUMA_PARAM - (hasNumatune ? 0 : 2);
+        ret = 0;
+        goto cleanup;
+    }
+
+    for (i = 0, j = 0; i < QEMU_NB_NUMA_PARAM && j < *nparams; i++) {
+        virMemoryParameterPtr param = &params[j];
 
         switch (i) {
         case 0: /* fill numa mode here */
+            if (!hasNumatune)
+                break;
+
             if (virTypedParameterAssign(param, VIR_DOMAIN_NUMA_MODE,
                                         VIR_TYPED_PARAM_INT, 0) < 0)
                 goto cleanup;
 
             virDomainNumatuneGetMode(def->numa, -1,
                                      (virDomainNumatuneMemMode *) &param->value.i);
+            j++;
             break;
 
         case 1: /* fill numa nodeset here */
+            if (!hasNumatune)
+                break;
+
             nodeset = virDomainNumatuneFormatNodeset(def->numa, NULL, -1);
             if (!nodeset ||
                 virTypedParameterAssign(param, VIR_DOMAIN_NUMA_NODESET,
@@ -10584,6 +10594,7 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
                 goto cleanup;
 
             nodeset = NULL;
+            j++;
             break;
 
         /* coverity[dead_error_begin] */
@@ -10593,8 +10604,7 @@ qemuDomainGetNumaParameters(virDomainPtr dom,
         }
     }
 
-    if (*nparams > QEMU_NB_NUMA_PARAM)
-        *nparams = QEMU_NB_NUMA_PARAM;
+    *nparams = j;
     ret = 0;
 
  cleanup:
-- 
2.3.6

--
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]