9c6c51
From fb4e8466ec0adc6e0aee55ab34e60e88d365d5de Mon Sep 17 00:00:00 2001
9c6c51
Message-Id: <fb4e8466ec0adc6e0aee55ab34e60e88d365d5de@dist-git>
9c6c51
From: Andrea Bolognani <abologna@redhat.com>
9c6c51
Date: Wed, 15 Aug 2018 14:04:43 +0200
9c6c51
Subject: [PATCH] utils: Remove arbitrary limit on socket_id/core_id
9c6c51
9c6c51
While in most cases the values are going to be much
9c6c51
smaller than our arbitrary 4096 limit, there is really
9c6c51
no guarantee that would be the case: in fact, a few
9c6c51
aarch64 servers have been spotted in the wild with
9c6c51
core_id as high as 6216.
9c6c51
9c6c51
Take advantage of virBitmap's ability to automatically
9c6c51
alter its size at runtime to accomodate such values.
9c6c51
9c6c51
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
9c6c51
(cherry picked from commit ba35ac2ebbc7f94abc50ffbf1d681458e2406444)
9c6c51
9c6c51
https://bugzilla.redhat.com/show_bug.cgi?id=1608479
9c6c51
9c6c51
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
9c6c51
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
9c6c51
---
9c6c51
 src/util/virhostcpu.c | 23 ++++-------------------
9c6c51
 1 file changed, 4 insertions(+), 19 deletions(-)
9c6c51
9c6c51
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
9c6c51
index b644398e00..1e31be5900 100644
9c6c51
--- a/src/util/virhostcpu.c
9c6c51
+++ b/src/util/virhostcpu.c
9c6c51
@@ -294,9 +294,6 @@ virHostCPUParseNode(const char *node,
9c6c51
                     int *threads,
9c6c51
                     int *offline)
9c6c51
 {
9c6c51
-    /* Biggest value we can expect to be used as either socket id
9c6c51
-     * or core id. Bitmaps will need to be sized accordingly */
9c6c51
-    const int ID_MAX = 4095;
9c6c51
     int ret = -1;
9c6c51
     int processors = 0;
9c6c51
     DIR *cpudir = NULL;
9c6c51
@@ -325,7 +322,7 @@ virHostCPUParseNode(const char *node,
9c6c51
         goto cleanup;
9c6c51
 
9c6c51
     /* enumerate sockets in the node */
9c6c51
-    if (!(sockets_map = virBitmapNew(ID_MAX + 1)))
9c6c51
+    if (!(sockets_map = virBitmapNewEmpty()))
9c6c51
         goto cleanup;
9c6c51
 
9c6c51
     while ((direrr = virDirRead(cpudir, &cpudirent, node)) > 0) {
9c6c51
@@ -344,14 +341,8 @@ virHostCPUParseNode(const char *node,
9c6c51
 
9c6c51
         if (virHostCPUGetSocket(cpu, &sock) < 0)
9c6c51
             goto cleanup;
9c6c51
-        if (sock > ID_MAX) {
9c6c51
-            virReportError(VIR_ERR_INTERNAL_ERROR,
9c6c51
-                           _("Socket %d can't be handled (max socket is %d)"),
9c6c51
-                           sock, ID_MAX);
9c6c51
-            goto cleanup;
9c6c51
-        }
9c6c51
 
9c6c51
-        if (virBitmapSetBit(sockets_map, sock) < 0)
9c6c51
+        if (virBitmapSetBitExpand(sockets_map, sock) < 0)
9c6c51
             goto cleanup;
9c6c51
 
9c6c51
         if (sock > sock_max)
9c6c51
@@ -368,7 +359,7 @@ virHostCPUParseNode(const char *node,
9c6c51
         goto cleanup;
9c6c51
 
9c6c51
     for (i = 0; i < sock_max; i++)
9c6c51
-        if (!(cores_maps[i] = virBitmapNew(ID_MAX + 1)))
9c6c51
+        if (!(cores_maps[i] = virBitmapNewEmpty()))
9c6c51
             goto cleanup;
9c6c51
 
9c6c51
     /* Iterate over all CPUs in the node, in ascending order */
9c6c51
@@ -412,14 +403,8 @@ virHostCPUParseNode(const char *node,
9c6c51
             if (virHostCPUGetCore(cpu, &core) < 0)
9c6c51
                 goto cleanup;
9c6c51
         }
9c6c51
-        if (core > ID_MAX) {
9c6c51
-            virReportError(VIR_ERR_INTERNAL_ERROR,
9c6c51
-                           _("Core %d can't be handled (max core is %d)"),
9c6c51
-                           core, ID_MAX);
9c6c51
-            goto cleanup;
9c6c51
-        }
9c6c51
 
9c6c51
-        if (virBitmapSetBit(cores_maps[sock], core) < 0)
9c6c51
+        if (virBitmapSetBitExpand(cores_maps[sock], core) < 0)
9c6c51
             goto cleanup;
9c6c51
 
9c6c51
         if (!(siblings = virHostCPUCountThreadSiblings(cpu)))
9c6c51
-- 
9c6c51
2.18.0
9c6c51