conf: Move hugepage XML validation check out of qemu_command

We can safely validate the hugepage nodeset attribute at a define time.
This validation is not done for already existing domains when the daemon
is restarted.

All the changes to the tests are necessary because we move the error
from domain start into XML parse.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2018-08-09 14:02:16 +02:00
parent 154b08a3a7
commit 5c93dfb46d
9 changed files with 43 additions and 51 deletions

View File

@ -6184,6 +6184,35 @@ virDomainDefLifecycleActionValidate(const virDomainDef *def)
}
static int
virDomainDefMemtuneValidate(const virDomainDef *def)
{
const virDomainMemtune *mem = &(def->mem);
size_t i;
ssize_t pos = virDomainNumaGetNodeCount(def->numa) - 1;
for (i = 0; i < mem->nhugepages; i++) {
ssize_t nextBit;
if (!mem->hugepages[i].nodemask) {
/* This is the master hugepage to use. Skip it as it has no
* nodemask anyway. */
continue;
}
nextBit = virBitmapNextSetBit(mem->hugepages[i].nodemask, pos);
if (nextBit >= 0) {
virReportError(VIR_ERR_XML_DETAIL,
_("hugepages: node %zd not found"),
nextBit);
return -1;
}
}
return 0;
}
static int
virDomainDefValidateInternal(const virDomainDef *def)
{
@ -6219,6 +6248,9 @@ virDomainDefValidateInternal(const virDomainDef *def)
if (virDomainDefLifecycleActionValidate(def) < 0)
return -1;
if (virDomainDefMemtuneValidate(def) < 0)
return -1;
return 0;
}

View File

@ -7433,16 +7433,6 @@ qemuBuildMemPathStr(virQEMUDriverConfigPtr cfg,
if (!def->mem.nhugepages)
return 0;
if (def->mem.hugepages[0].nodemask) {
ssize_t next_bit = virBitmapNextSetBit(def->mem.hugepages[0].nodemask, -1);
if (next_bit >= 0) {
virReportError(VIR_ERR_XML_DETAIL,
_("hugepages: node %zd not found"),
next_bit);
return -1;
}
}
/* There is one special case: if user specified "huge"
* pages of regular system pages size.
* And there is nothing to do in this case.
@ -7575,30 +7565,6 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
if (!virDomainNumatuneNodesetIsAvailable(def->numa, priv->autoNodeset))
goto cleanup;
for (i = 0; i < def->mem.nhugepages; i++) {
ssize_t next_bit, pos = 0;
if (!def->mem.hugepages[i].nodemask) {
/* This is the master hugepage to use. Skip it as it has no
* nodemask anyway. */
continue;
}
if (ncells) {
/* Fortunately, we allow only guest NUMA nodes to be continuous
* starting from zero. */
pos = ncells - 1;
}
next_bit = virBitmapNextSetBit(def->mem.hugepages[i].nodemask, pos);
if (next_bit >= 0) {
virReportError(VIR_ERR_XML_DETAIL,
_("hugepages: node %zd not found"),
next_bit);
goto cleanup;
}
}
if (VIR_ALLOC_N(nodeBackends, ncells) < 0)
goto cleanup;

View File

@ -5,7 +5,7 @@
<currentMemory unit='KiB'>262144</currentMemory>
<memoryBacking>
<hugepages>
<page size='2048' unit='KiB' nodeset='0'/>
<page size='2048' unit='KiB'/>
</hugepages>
</memoryBacking>
<vcpu placement='static'>4</vcpu>

View File

@ -958,12 +958,12 @@ mymain(void)
DO_TEST("hugepages-default", NONE);
DO_TEST("hugepages-default-2M", NONE);
DO_TEST("hugepages-default-system-size", NONE);
DO_TEST("hugepages-default-1G-nodeset-2M", NONE);
DO_TEST_FAILURE("hugepages-nodeset", NONE);
DO_TEST_FAILURE("hugepages-nodeset-nonexist",
QEMU_CAPS_DEVICE_PC_DIMM,
QEMU_CAPS_OBJECT_MEMORY_FILE,
QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD);
DO_TEST_PARSE_ERROR("hugepages-default-1G-nodeset-2M", NONE);
DO_TEST_PARSE_ERROR("hugepages-nodeset", NONE);
DO_TEST_PARSE_ERROR("hugepages-nodeset-nonexist",
QEMU_CAPS_DEVICE_PC_DIMM,
QEMU_CAPS_OBJECT_MEMORY_FILE,
QEMU_CAPS_OBJECT_MEMORY_FILE_DISCARD);
DO_TEST("hugepages-numa-default",
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST("hugepages-numa-default-2M",
@ -978,9 +978,9 @@ mymain(void)
DO_TEST("hugepages-numa-nodeset-part",
QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST_FAILURE("hugepages-numa-nodeset-nonexist",
QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST_PARSE_ERROR("hugepages-numa-nodeset-nonexist",
QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE);
DO_TEST("hugepages-shared",
QEMU_CAPS_OBJECT_MEMORY_RAM,
QEMU_CAPS_OBJECT_MEMORY_FILE);

View File

@ -1 +0,0 @@
../qemuxml2argvdata/hugepages-default-1G-nodeset-2M.xml

View File

@ -1 +0,0 @@
../qemuxml2argvdata/hugepages-nodeset.xml

View File

@ -1 +0,0 @@
../qemuxml2argvdata/hugepages-numa-nodeset-nonexist.xml

View File

@ -5,7 +5,7 @@
<currentMemory unit='KiB'>262144</currentMemory>
<memoryBacking>
<hugepages>
<page size='2048' unit='KiB' nodeset='0'/>
<page size='2048' unit='KiB'/>
</hugepages>
</memoryBacking>
<vcpu placement='static'>4</vcpu>

View File

@ -331,13 +331,10 @@ mymain(void)
DO_TEST("hugepages-default", NONE);
DO_TEST("hugepages-default-2M", NONE);
DO_TEST("hugepages-default-system-size", NONE);
DO_TEST("hugepages-default-1G-nodeset-2M", NONE);
DO_TEST("hugepages-nodeset", NONE);
DO_TEST("hugepages-numa-default-2M", NONE);
DO_TEST("hugepages-numa-default-dimm", NONE);
DO_TEST("hugepages-numa-nodeset", NONE);
DO_TEST("hugepages-numa-nodeset-part", NONE);
DO_TEST("hugepages-numa-nodeset-nonexist", NONE);
DO_TEST("hugepages-shared", NONE);
DO_TEST("hugepages-memaccess", NONE);
DO_TEST("hugepages-memaccess2", NONE);