7a3408
From ce34d90fb56c195924a0ef4d076d39ed4fc4cabc Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <ce34d90fb56c195924a0ef4d076d39ed4fc4cabc@dist-git>
7a3408
From: Michal Privoznik <mprivozn@redhat.com>
7a3408
Date: Fri, 7 Aug 2015 17:30:16 +0200
7a3408
Subject: [PATCH] numa_conf: Introduce virDomainNumaGetMaxCPUID
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1176020
7a3408
7a3408
This function should return the greatest CPU number set in
7a3408
/domain/cpu/numa/cell/@cpus. The idea is that we should compare
7a3408
the returned value against /domain/vcpu value. Yes, there exist
7a3408
users who think the following is a good idea:
7a3408
7a3408
  <vcpu placement='static'>4</vcpu>
7a3408
  <cpu mode='host-model'>
7a3408
    <model fallback='allow'/>
7a3408
    <numa>
7a3408
      <cell id='0' cpus='0-1' memory='1048576' unit='KiB'/>
7a3408
      <cell id='1' cpus='9-10' memory='2097152' unit='KiB'/>
7a3408
    </numa>
7a3408
  </cpu>
7a3408
7a3408
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7a3408
(cherry picked from commit 8f2535dec1fdd969e86aa39c8a2583c723341733)
7a3408
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/conf/numa_conf.c     | 17 +++++++++++++++++
7a3408
 src/conf/numa_conf.h     |  3 +++
7a3408
 src/libvirt_private.syms |  1 +
7a3408
 3 files changed, 21 insertions(+)
7a3408
7a3408
diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
7a3408
index 57da215..5c123b9 100644
7a3408
--- a/src/conf/numa_conf.c
7a3408
+++ b/src/conf/numa_conf.c
7a3408
@@ -847,6 +847,23 @@ virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa)
7a3408
     return ret;
7a3408
 }
7a3408
 
7a3408
+unsigned int
7a3408
+virDomainNumaGetMaxCPUID(virDomainNumaPtr numa)
7a3408
+{
7a3408
+    size_t i;
7a3408
+    unsigned int ret = 0;
7a3408
+
7a3408
+    for (i = 0; i < numa->nmem_nodes; i++) {
7a3408
+        int bit;
7a3408
+
7a3408
+        bit = virBitmapLastSetBit(virDomainNumaGetNodeCpumask(numa, i));
7a3408
+        if (bit > ret)
7a3408
+            ret = bit;
7a3408
+    }
7a3408
+
7a3408
+    return ret;
7a3408
+}
7a3408
+
7a3408
 
7a3408
 virDomainNumaPtr
7a3408
 virDomainNumaNew(void)
7a3408
diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h
7a3408
index 6739065..90deacb 100644
7a3408
--- a/src/conf/numa_conf.h
7a3408
+++ b/src/conf/numa_conf.h
7a3408
@@ -99,6 +99,9 @@ unsigned long long virDomainNumaGetNodeMemorySize(virDomainNumaPtr numa,
7a3408
 unsigned long long virDomainNumaGetMemorySize(virDomainNumaPtr numa)
7a3408
     ATTRIBUTE_NONNULL(1);
7a3408
 
7a3408
+unsigned int
7a3408
+virDomainNumaGetMaxCPUID(virDomainNumaPtr numa);
7a3408
+
7a3408
 /*
7a3408
  * Formatters
7a3408
  */
7a3408
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
7a3408
index 0517c24..ad9ebb1 100644
7a3408
--- a/src/libvirt_private.syms
7a3408
+++ b/src/libvirt_private.syms
7a3408
@@ -679,6 +679,7 @@ virNodeDeviceObjUnlock;
7a3408
 virDomainNumaCheckABIStability;
7a3408
 virDomainNumaEquals;
7a3408
 virDomainNumaFree;
7a3408
+virDomainNumaGetMaxCPUID;
7a3408
 virDomainNumaGetMemorySize;
7a3408
 virDomainNumaGetNodeCount;
7a3408
 virDomainNumaGetNodeCpumask;
7a3408
-- 
7a3408
2.5.0
7a3408