mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
numatune: add check for numatune nodeset range
There was no check for 'nodeset' attribute in numatune-related elements. This patch adds validation that any nodeset specified does not exceed maximum host node. Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
This commit is contained in:
parent
d2460f85d3
commit
902864184e
@ -612,3 +612,31 @@ virDomainNumatuneHasPerNodeBinding(virDomainNumatunePtr numatune)
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
virDomainNumatuneSpecifiedMaxNode(virDomainNumatunePtr numatune)
|
||||
{
|
||||
int ret = -1;
|
||||
virBitmapPtr nodemask = NULL;
|
||||
size_t i;
|
||||
int bit;
|
||||
|
||||
if (!numatune)
|
||||
return ret;
|
||||
|
||||
nodemask = virDomainNumatuneGetNodeset(numatune, NULL, -1);
|
||||
if (nodemask)
|
||||
ret = virBitmapLastSetBit(nodemask);
|
||||
|
||||
for (i = 0; i < numatune->nmem_nodes; i++) {
|
||||
nodemask = numatune->mem_nodes[i].nodeset;
|
||||
if (!nodemask)
|
||||
continue;
|
||||
|
||||
bit = virBitmapLastSetBit(nodemask);
|
||||
if (bit > ret)
|
||||
ret = bit;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -102,4 +102,5 @@ bool virDomainNumatuneHasPlacementAuto(virDomainNumatunePtr numatune);
|
||||
|
||||
bool virDomainNumatuneHasPerNodeBinding(virDomainNumatunePtr numatune);
|
||||
|
||||
int virDomainNumatuneSpecifiedMaxNode(virDomainNumatunePtr numatune);
|
||||
#endif /* __NUMATUNE_CONF_H__ */
|
||||
|
@ -1733,6 +1733,7 @@ virNumaGetPageInfo;
|
||||
virNumaGetPages;
|
||||
virNumaIsAvailable;
|
||||
virNumaNodeIsAvailable;
|
||||
virNumaNodesetIsAvailable;
|
||||
virNumaSetPagePoolSize;
|
||||
virNumaSetupMemoryPolicy;
|
||||
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "virstoragefile.h"
|
||||
#include "virtpm.h"
|
||||
#include "virscsi.h"
|
||||
#include "virnuma.h"
|
||||
#if defined(__linux__)
|
||||
# include <linux/capability.h>
|
||||
#endif
|
||||
@ -6664,6 +6665,9 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!virNumaNodesetIsAvailable(def->numatune))
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < def->mem.nhugepages; i++) {
|
||||
ssize_t next_bit, pos = 0;
|
||||
|
||||
|
@ -165,6 +165,33 @@ virNumaSetupMemoryPolicy(virDomainNumatunePtr numatune,
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
virNumaNodesetIsAvailable(virDomainNumatunePtr numatune)
|
||||
{
|
||||
int maxnode;
|
||||
int bit;
|
||||
|
||||
if (!numatune)
|
||||
return true;
|
||||
|
||||
bit = virDomainNumatuneSpecifiedMaxNode(numatune);
|
||||
if (bit < 0)
|
||||
return true;
|
||||
|
||||
if ((maxnode = virNumaGetMaxNode()) < 0)
|
||||
return false;
|
||||
|
||||
maxnode = maxnode < NUMA_NUM_NODES ? maxnode : NUMA_NUM_NODES;
|
||||
if (bit > maxnode)
|
||||
goto error;
|
||||
|
||||
return true;
|
||||
|
||||
error:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("NUMA node %d is out of range"), bit);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
virNumaIsAvailable(void)
|
||||
@ -330,6 +357,17 @@ virNumaSetupMemoryPolicy(virDomainNumatunePtr numatune,
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool
|
||||
virNumaNodesetIsAvailable(virDomainNumatunePtr numatune)
|
||||
{
|
||||
if (virDomainNumatuneSpecifiedMaxNode(numatune) >= 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("libvirt is compiled without NUMA tuning support"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
virNumaIsAvailable(void)
|
||||
|
@ -34,6 +34,7 @@ char *virNumaGetAutoPlacementAdvice(unsigned short vcups,
|
||||
int virNumaSetupMemoryPolicy(virDomainNumatunePtr numatune,
|
||||
virBitmapPtr nodemask);
|
||||
|
||||
bool virNumaNodesetIsAvailable(virDomainNumatunePtr numatune);
|
||||
bool virNumaIsAvailable(void);
|
||||
int virNumaGetMaxNode(void);
|
||||
bool virNumaNodeIsAvailable(int node);
|
||||
|
@ -0,0 +1,35 @@
|
||||
<domain type='qemu'>
|
||||
<name>QEMUGuest1</name>
|
||||
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
|
||||
<memory unit='KiB'>1048576</memory>
|
||||
<currentMemory unit='KiB'>1048576</currentMemory>
|
||||
<vcpu placement='static'>4</vcpu>
|
||||
<numatune>
|
||||
<memnode cellid='0' mode='strict' nodeset='0-8'/>
|
||||
<memnode cellid='1' mode='strict' nodeset='0'/>
|
||||
</numatune>
|
||||
<os>
|
||||
<type arch='i686' machine='pc'>hvm</type>
|
||||
<boot dev='hd'/>
|
||||
</os>
|
||||
<cpu>
|
||||
<numa>
|
||||
<cell id='0' cpus='0-1' memory='524288'/>
|
||||
<cell id='1' cpus='2-3' memory='524288'/>
|
||||
</numa>
|
||||
</cpu>
|
||||
<clock offset='utc'/>
|
||||
<on_poweroff>destroy</on_poweroff>
|
||||
<on_reboot>restart</on_reboot>
|
||||
<on_crash>destroy</on_crash>
|
||||
<devices>
|
||||
<emulator>/usr/bin/qemu-system-x86_64</emulator>
|
||||
<disk type='block' device='disk'>
|
||||
<source dev='/dev/HostVG/QEMUGuest1'/>
|
||||
<target dev='hda' bus='ide'/>
|
||||
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
|
||||
</disk>
|
||||
<controller type='ide' index='0'/>
|
||||
<memballoon model='virtio'/>
|
||||
</devices>
|
||||
</domain>
|
@ -21,6 +21,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "virnuma.h"
|
||||
#include <time.h>
|
||||
|
||||
time_t time(time_t *t)
|
||||
@ -30,3 +31,11 @@ time_t time(time_t *t)
|
||||
*t = ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
virNumaGetMaxNode(void)
|
||||
{
|
||||
const int maxnodesNum = 7;
|
||||
|
||||
return maxnodesNum;
|
||||
}
|
||||
|
@ -1251,6 +1251,8 @@ mymain(void)
|
||||
DO_TEST_FAILURE("numatune-memnode-no-memory", NONE);
|
||||
|
||||
DO_TEST("numatune-auto-nodeset-invalid", NONE);
|
||||
DO_TEST_FAILURE("numatune-static-nodeset-exceed-hostnode",
|
||||
QEMU_CAPS_OBJECT_MEMORY_RAM);
|
||||
DO_TEST_PARSE_ERROR("numatune-memnode-nocpu", NONE);
|
||||
DO_TEST_PARSE_ERROR("numatune-memnodes-problematic", NONE);
|
||||
DO_TEST("numad", NONE);
|
||||
|
Loading…
Reference in New Issue
Block a user