[PATCH] virnuma: Report error when NUMA -> CPUs translation fails

Michal Privoznik posted 1 patch 3 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/c6b09d182696a520836f2d8fbcc864c658685768.1599491503.git.mprivozn@redhat.com
src/util/virnuma.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
[PATCH] virnuma: Report error when NUMA -> CPUs translation fails
Posted by Michal Privoznik 3 years, 7 months ago
When starting a domain with <numatune/> set libvirt translates
given NUMA nodes into a set of host CPUs which is then used to
QEMU process affinity. But, if the numatune contains a
non-existent NUMA node then the translation fails with no error
reported. This is because virNumaNodesetToCPUset() calls
virNumaGetNodeCPUs() and expects it to report an error on
failure. Well, it does except for non-existent NUMA nodes. While
this behaviour might look strange it is actually desired because
of how we construct host capabilities. The virNumaGetNodeCPUs()
is called from virCapabilitiesHostNUMAInitReal() where we do not
want any error reported for non-existent NUMA nodes.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1724866
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/util/virnuma.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/util/virnuma.c b/src/util/virnuma.c
index ba1e4363d6..2872ce3c5e 100644
--- a/src/util/virnuma.c
+++ b/src/util/virnuma.c
@@ -316,12 +316,21 @@ virNumaNodesetToCPUset(virBitmapPtr nodeset,
 
     for (i = 0; i < nodesetSize; i++) {
         g_autoptr(virBitmap) nodeCPUs = NULL;
+        int rc;
 
         if (!virBitmapIsBitSet(nodeset, i))
             continue;
 
-        if (virNumaGetNodeCPUs(i, &nodeCPUs) < 0)
+        rc = virNumaGetNodeCPUs(i, &nodeCPUs);
+        if (rc < 0) {
+            /* Error is reported for cases other than non-existent NUMA node. */
+            if (rc == -2) {
+                virReportError(VIR_ERR_OPERATION_FAILED,
+                               _("NUMA node %zu is not available"),
+                               i);
+            }
             return -1;
+        }
 
         if (virBitmapUnion(allNodesCPUs, nodeCPUs) < 0)
             return -1;
-- 
2.26.2

Re: [PATCH] virnuma: Report error when NUMA -> CPUs translation fails
Posted by Martin Kletzander 3 years, 7 months ago
On Mon, Sep 07, 2020 at 05:11:50PM +0200, Michal Privoznik wrote:
>When starting a domain with <numatune/> set libvirt translates
>given NUMA nodes into a set of host CPUs which is then used to
>QEMU process affinity. But, if the numatune contains a
>non-existent NUMA node then the translation fails with no error
>reported. This is because virNumaNodesetToCPUset() calls
>virNumaGetNodeCPUs() and expects it to report an error on
>failure. Well, it does except for non-existent NUMA nodes. While
>this behaviour might look strange it is actually desired because
>of how we construct host capabilities. The virNumaGetNodeCPUs()
>is called from virCapabilitiesHostNUMAInitReal() where we do not
>want any error reported for non-existent NUMA nodes.
>
>Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1724866
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>