diff --git a/src/conf/numatune_conf.c b/src/conf/numatune_conf.c index 48d1d04fe6..ff0f3eb34e 100644 --- a/src/conf/numatune_conf.c +++ b/src/conf/numatune_conf.c @@ -437,14 +437,27 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr, int mode, virBitmapPtr nodeset) { - bool create = !*numatunePtr; /* Whether we are creating new struct */ + bool created = false; int ret = -1; - virDomainNumatunePtr numatune = NULL; + virDomainNumatunePtr numatune; /* No need to do anything in this case */ if (mode == -1 && placement == -1 && !nodeset) return 0; + if (!(*numatunePtr)) { + if (VIR_ALLOC(*numatunePtr) < 0) + goto cleanup; + + created = true; + if (mode == -1) + mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; + if (placement == -1) + placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT; + } + + numatune = *numatunePtr; + /* Range checks */ if (mode != -1 && (mode < 0 || mode >= VIR_DOMAIN_NUMATUNE_MEM_LAST)) { @@ -453,6 +466,7 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr, mode); goto cleanup; } + if (placement != -1 && (placement < 0 || placement >= VIR_DOMAIN_NUMATUNE_PLACEMENT_LAST)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -461,21 +475,9 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr, goto cleanup; } - if (create && VIR_ALLOC(*numatunePtr) < 0) - goto cleanup; - numatune = *numatunePtr; - - if (create) { - /* Defaults for new struct */ - if (mode == -1) - mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT; - - if (placement == -1) - placement = VIR_DOMAIN_NUMATUNE_PLACEMENT_DEFAULT; - } - if (mode != -1) numatune->memory.mode = mode; + if (nodeset) { virBitmapFree(numatune->memory.nodeset); numatune->memory.nodeset = virBitmapNewCopy(nodeset); @@ -500,13 +502,26 @@ virDomainNumatuneSet(virDomainNumatunePtr *numatunePtr, goto cleanup; } + /* setting nodeset when placement auto is invalid */ + if (placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_AUTO && + numatune->memory.nodeset) { + virBitmapFree(numatune->memory.nodeset); + numatune->memory.nodeset = NULL; + } + if (placement != -1) numatune->memory.placement = placement; numatune->memory.specified = true; ret = 0; + cleanup: + if (ret < 0 && created) { + virDomainNumatuneFree(*numatunePtr); + *numatunePtr = NULL; + } + return ret; } diff --git a/tests/qemuxml2argvdata/qemuxml2argv-numad-auto-vcpu-static-numatune-no-nodeset.xml b/tests/qemuxml2argvdata/qemuxml2argv-numad-auto-vcpu-static-numatune-no-nodeset.xml new file mode 100644 index 0000000000..b3cb5c5f42 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-numad-auto-vcpu-static-numatune-no-nodeset.xml @@ -0,0 +1,31 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 2 + + + + + hvm + + + + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 65dc9c708f..b289d0e843 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1223,6 +1223,7 @@ mymain(void) DO_TEST_PARSE_ERROR("numatune-memnodes-problematic", NONE); DO_TEST("numad", NONE); DO_TEST("numad-auto-vcpu-static-numatune", NONE); + DO_TEST_PARSE_ERROR("numad-auto-vcpu-static-numatune-no-nodeset", NONE); DO_TEST("numad-auto-memory-vcpu-cpuset", NONE); DO_TEST("numad-auto-memory-vcpu-no-cpuset-and-placement", NONE); DO_TEST("numad-static-memory-auto-vcpu", NONE);