c401cc
From 1fe7516d6ee1b8e1f0ee039777db7484deed8bee Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <1fe7516d6ee1b8e1f0ee039777db7484deed8bee.1391001809.git.jdenemar@redhat.com>
c401cc
From: Osier Yang <jyang@redhat.com>
c401cc
Date: Thu, 23 Jan 2014 13:36:41 +0800
c401cc
Subject: [PATCH] util: Correct the NUMA node range checking
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1045958
c401cc
c401cc
There are 2 issues here: First we shouldn't add "1" to the return
c401cc
value of numa_max_node(), since the semanteme of the error message
c401cc
was changed, it's not saying about the number of total NUMA nodes
c401cc
anymore.  Second, the value of "bit" is the position of the first
c401cc
bit which exceeds either numa_max_node() or NUMA_NUM_NODES, it can
c401cc
be any number in the range, so saying "bigger than $bit" is quite
c401cc
confused now. For example, assuming there is a NUMA machine which
c401cc
has 10 NUMA nodes, and one specifies the "nodeset" as "0,5,88",
c401cc
the error message will be like:
c401cc
c401cc
Nodeset is out of range, host cannot support NUMA node bigger than 88
c401cc
c401cc
It sounds like all NUMA node number less than 88 is fine, but
c401cc
actually the maximum NUMA node number the machine supports is 9.
c401cc
c401cc
This patch fixes the issues by removing the addition with "1" and
c401cc
simplifies the error message as "NUMA node $bit is out of range".
c401cc
Also simplifies the comparision in the while loop by getting the
c401cc
smaller one of numa_max_node() and NUMA_NUM_NODES up front.
c401cc
(cherry picked from commit ae2860b4c66b7bdfffb1dfa9ead4aa1b2d9aa2da)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/util/virnuma.c | 8 ++++----
c401cc
 1 file changed, 4 insertions(+), 4 deletions(-)
c401cc
c401cc
diff --git a/src/util/virnuma.c b/src/util/virnuma.c
c401cc
index ecf7ede..b911f29 100644
c401cc
--- a/src/util/virnuma.c
c401cc
+++ b/src/util/virnuma.c
c401cc
@@ -112,16 +112,16 @@ virNumaSetupMemoryPolicy(virNumaTuneDef numatune,
c401cc
         return -1;
c401cc
     }
c401cc
 
c401cc
-    maxnode = numa_max_node() + 1;
c401cc
+    maxnode = numa_max_node();
c401cc
+    maxnode = maxnode < NUMA_NUM_NODES ? maxnode : NUMA_NUM_NODES;
c401cc
 
c401cc
     /* Convert nodemask to NUMA bitmask. */
c401cc
     nodemask_zero(&mask);
c401cc
     bit = -1;
c401cc
     while ((bit = virBitmapNextSetBit(tmp_nodemask, bit)) >= 0) {
c401cc
-        if (bit > maxnode || bit > NUMA_NUM_NODES) {
c401cc
+        if (bit > maxnode) {
c401cc
             virReportError(VIR_ERR_INTERNAL_ERROR,
c401cc
-                           _("Nodeset is out of range, host cannot support "
c401cc
-                             "NUMA node bigger than %d"), bit);
c401cc
+                           _("NUMA node %d is out of range"), bit);
c401cc
             return -1;
c401cc
         }
c401cc
         nodemask_set(&mask, bit);
c401cc
-- 
c401cc
1.8.5.3
c401cc