From 4bca6192f20802773012d935145811fb4ba4a4d4 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 4 Mar 2015 11:04:27 +0100 Subject: [PATCH] conf: Make specifying optional Now that the size of guest's memory can be inferred from the NUMA configuration (if present) make it optional to specify explicitly. To make sure that memory is specified add a check that some form of memory size was specified. One side effect of this change is that it is no longer possible to specify 0KiB as memory size for the VM, but I don't think it would be any useful to do so. (I can imagine embedded systems without memory, just registers, but that's far from what libvirt is usually doing). Forbidding 0 memory for guests also fixes a few corner cases where 0 was not interpreted correctly and caused failures. (Arguments for numad when using automatic placement, size of the balloon). This fixes problems described in https://bugzilla.redhat.com/show_bug.cgi?id=1161461 Test case changes are added to verify that the schema change and code behave correctly. --- docs/schemas/domaincommon.rng | 18 ++++++------ src/conf/domain_conf.c | 9 +++++- ...muxml2argv-cpu-numa-no-memory-element.args | 7 +++++ ...emuxml2argv-cpu-numa-no-memory-element.xml | 24 ++++++++++++++++ .../qemuxml2argv-minimal-no-memory.xml | 25 +++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ ...uxml2xmlout-cpu-numa-no-memory-element.xml | 28 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 8 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-minimal-no-memory.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa-no-memory-element.xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index b1d883fcbb..e98e9052aa 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -582,14 +582,16 @@ --> - - - - - - - - + + + + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4ecb58c90f..ca02bb9493 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3208,6 +3208,13 @@ virDomainDefPostParseInternal(virDomainDefPtr def, return -1; } + if (virDomainDefGetMemoryInitial(def) == 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Memory size must be specified via or in the " + " configuration")); + return -1; + } + if (def->mem.cur_balloon > virDomainDefGetMemoryActual(def)) { /* Older libvirt could get into this situation due to * rounding; if the discrepancy is less than 4MiB, we silently @@ -13245,7 +13252,7 @@ virDomainDefParseXML(xmlDocPtr xml, /* Extract domain memory */ if (virDomainParseMemory("./memory[1]", NULL, ctxt, - &def->mem.max_balloon, true, true) < 0) + &def->mem.max_balloon, false, true) < 0) goto error; if (virDomainParseMemory("./currentMemory[1]", NULL, ctxt, diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.args new file mode 100644 index 0000000000..ca34f734fe --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.args @@ -0,0 +1,7 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \ +/usr/bin/qemu -S -M pc \ +-m 214 -smp 16,sockets=2,cores=4,threads=2 \ +-numa node,nodeid=0,cpus=0-7,mem=107 \ +-numa node,nodeid=1,cpus=8-15,mem=107 -nographic -monitor \ +unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -usb -net none -serial none \ +-parallel none diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.xml new file mode 100644 index 0000000000..fbdc5e60cf --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.xml @@ -0,0 +1,24 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 16 + + hvm + + + + + + + + + + + destroy + restart + destroy + + /usr/bin/qemu + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-minimal-no-memory.xml b/tests/qemuxml2argvdata/qemuxml2argv-minimal-no-memory.xml new file mode 100644 index 0000000000..68246512ab --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-minimal-no-memory.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + +
+ + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 5e7dd63f27..fcf5218730 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -594,6 +594,7 @@ mymain(void) unsetenv("SDL_AUDIODRIVER"); DO_TEST("minimal", QEMU_CAPS_NAME); + DO_TEST_PARSE_ERROR("minimal-no-memory", NONE); DO_TEST("minimal-msg-timestamp", QEMU_CAPS_NAME, QEMU_CAPS_MSG_TIMESTAMP); DO_TEST("minimal-s390", QEMU_CAPS_NAME); DO_TEST("machine-aliases1", NONE); @@ -1235,6 +1236,7 @@ mymain(void) DO_TEST("cpu-strict1", QEMU_CAPS_KVM); DO_TEST("cpu-numa1", NONE); DO_TEST("cpu-numa2", QEMU_CAPS_SMP_TOPOLOGY); + DO_TEST("cpu-numa-no-memory-element", QEMU_CAPS_SMP_TOPOLOGY); DO_TEST_PARSE_ERROR("cpu-numa3", NONE); DO_TEST_FAILURE("cpu-numa-disjoint", NONE); DO_TEST("cpu-numa-disjoint", QEMU_CAPS_NUMA); diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa-no-memory-element.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa-no-memory-element.xml new file mode 100644 index 0000000000..58f40b9902 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa-no-memory-element.xml @@ -0,0 +1,28 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 16 + + hvm + + + + + + + + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 8e12e84fcc..6ffe36b700 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -409,6 +409,7 @@ mymain(void) DO_TEST_DIFFERENT("cpu-numa1"); DO_TEST_DIFFERENT("cpu-numa2"); + DO_TEST_DIFFERENT("cpu-numa-no-memory-element"); DO_TEST("cpu-numa-disjoint"); DO_TEST("cpu-numa-memshared");