Blob Blame History Raw
From fb4e8466ec0adc6e0aee55ab34e60e88d365d5de Mon Sep 17 00:00:00 2001
Message-Id: <fb4e8466ec0adc6e0aee55ab34e60e88d365d5de@dist-git>
From: Andrea Bolognani <abologna@redhat.com>
Date: Wed, 15 Aug 2018 14:04:43 +0200
Subject: [PATCH] utils: Remove arbitrary limit on socket_id/core_id

While in most cases the values are going to be much
smaller than our arbitrary 4096 limit, there is really
no guarantee that would be the case: in fact, a few
aarch64 servers have been spotted in the wild with
core_id as high as 6216.

Take advantage of virBitmap's ability to automatically
alter its size at runtime to accomodate such values.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
(cherry picked from commit ba35ac2ebbc7f94abc50ffbf1d681458e2406444)

https://bugzilla.redhat.com/show_bug.cgi?id=1608479

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/util/virhostcpu.c | 23 ++++-------------------
 1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index b644398e00..1e31be5900 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -294,9 +294,6 @@ virHostCPUParseNode(const char *node,
                     int *threads,
                     int *offline)
 {
-    /* Biggest value we can expect to be used as either socket id
-     * or core id. Bitmaps will need to be sized accordingly */
-    const int ID_MAX = 4095;
     int ret = -1;
     int processors = 0;
     DIR *cpudir = NULL;
@@ -325,7 +322,7 @@ virHostCPUParseNode(const char *node,
         goto cleanup;
 
     /* enumerate sockets in the node */
-    if (!(sockets_map = virBitmapNew(ID_MAX + 1)))
+    if (!(sockets_map = virBitmapNewEmpty()))
         goto cleanup;
 
     while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) {
@@ -344,14 +341,8 @@ virHostCPUParseNode(const char *node,
 
         if (virHostCPUGetSocket(cpu, &sock) < 0)
             goto cleanup;
-        if (sock > ID_MAX) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Socket %d can't be handled (max socket is %d)"),
-                           sock, ID_MAX);
-            goto cleanup;
-        }
 
-        if (virBitmapSetBit(sockets_map, sock) < 0)
+        if (virBitmapSetBitExpand(sockets_map, sock) < 0)
             goto cleanup;
 
         if (sock > sock_max)
@@ -368,7 +359,7 @@ virHostCPUParseNode(const char *node,
         goto cleanup;
 
     for (i = 0; i < sock_max; i++)
-        if (!(cores_maps[i] = virBitmapNew(ID_MAX + 1)))
+        if (!(cores_maps[i] = virBitmapNewEmpty()))
             goto cleanup;
 
     /* Iterate over all CPUs in the node, in ascending order */
@@ -412,14 +403,8 @@ virHostCPUParseNode(const char *node,
             if (virHostCPUGetCore(cpu, &core) < 0)
                 goto cleanup;
         }
-        if (core > ID_MAX) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Core %d can't be handled (max core is %d)"),
-                           core, ID_MAX);
-            goto cleanup;
-        }
 
-        if (virBitmapSetBit(cores_maps[sock], core) < 0)
+        if (virBitmapSetBitExpand(cores_maps[sock], core) < 0)
             goto cleanup;
 
         if (!(siblings = virHostCPUCountThreadSiblings(cpu)))
-- 
2.18.0