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