[libvirt] [PATCH 1/2] numa_conf: Introduce virDomainNumaGetMaxCPUID

This function should return the greatest CPU number set in /domain/cpu/numa/cell/@cpus. The idea is that we should compare the returned value against /domain/vcpu value. Yes, there exist users who think the following is a good idea: <vcpu placement='static'>4</vcpu> <cpu mode='host-model'> <model fallback='allow'/> <numa> <cell id='0' cpus='0-1' memory='1048576' unit='KiB'/> <cell id='1' cpus='9-10' memory='2097152' unit='KiB'/> </numa> </cpu> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/numa_conf.c | 17 +++++++++++++++++ src/conf/numa_conf.h | 3 +++ src/libvirt_private.syms | 1 + 3 files changed, 21 insertions(+) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 57da215..5c123b9 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -847,6 +847,23 @@ virDomainNumaGetCPUCountTotal(virDomainNumaPtr numa) return ret; } +unsigned int +virDomainNumaGetMaxCPUID(virDomainNumaPtr numa) +{ + size_t i; + unsigned int ret = 0; + + for (i = 0; i < numa->nmem_nodes; i++) { + int bit; + + bit = virBitmapLastSetBit(virDomainNumaGetNodeCpumask(numa, i)); + if (bit > ret) + ret = bit; + } + + return ret; +} + virDomainNumaPtr virDomainNumaNew(void) diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h index 6739065..90deacb 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -99,6 +99,9 @@ unsigned long long virDomainNumaGetNodeMemorySize(virDomainNumaPtr numa, unsigned long long virDomainNumaGetMemorySize(virDomainNumaPtr numa) ATTRIBUTE_NONNULL(1); +unsigned int +virDomainNumaGetMaxCPUID(virDomainNumaPtr numa); + /* * Formatters */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 0517c24..0b67bfe 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -684,6 +684,7 @@ virDomainNumaGetNodeCount; virDomainNumaGetNodeCpumask; virDomainNumaGetNodeMemoryAccessMode; virDomainNumaGetNodeMemorySize; +virDomainNumaGetMaxCPUID; virDomainNumaNew; virDomainNumaSetNodeMemorySize; virDomainNumatuneFormatNodeset; -- 2.4.6

https://bugzilla.redhat.com/show_bug.cgi?id=1176020 Some users think this is a good idea: <vcpu placement='static'>4</vcpu> <cpu mode='host-model'> <model fallback='allow'/> <numa> <cell id='0' cpus='0-1' memory='1048576' unit='KiB'/> <cell id='1' cpus='9-10' memory='2097152' unit='KiB'/> </numa> </cpu> It's not. Lets therefore introduce a check and discourage them in doing so. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5eaeb21..e4114f8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15105,6 +15105,12 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } + if (virDomainNumaGetMaxCPUID(def->numa) >= def->maxvcpus) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("CPU IDs in <numa> exceed the <vcpu> count")); + goto error; + } + if (virDomainNumatuneParseXML(def->numa, def->placement_mode == VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC, -- 2.4.6

On Fri, Aug 07, 2015 at 04:39:43PM +0200, Michal Privoznik wrote:
This function should return the greatest CPU number set in /domain/cpu/numa/cell/@cpus. The idea is that we should compare the returned value against /domain/vcpu value. Yes, there exist users who think the following is a good idea:
Sure it is, I do that all the time :-D ACK to both, almost trivial :)
participants (2)
-
Martin Kletzander
-
Michal Privoznik