Now that the size of guest's memory can be inferred from the NUMA configuration (if present) make it optional to specify <memory> 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 ++++++- .../qemuxml2argv-cpu-numa-no-memory-element.args | 7 ++++++ .../qemuxml2argv-cpu-numa-no-memory-element.xml | 24 +++++++++++++++++++ .../qemuxml2argv-minimal-no-memory.xml | 25 +++++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ .../qemuxml2xmlout-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 56ea6a4..3e2fe45 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -582,14 +582,16 @@ --> <define name="resources"> <interleave> - <element name="memory"> - <ref name='scaledInteger'/> - <optional> - <attribute name="dumpCore"> - <ref name="virOnOff"/> - </attribute> - </optional> - </element> + <optional> + <element name="memory"> + <ref name='scaledInteger'/> + <optional> + <attribute name="dumpCore"> + <ref name="virOnOff"/> + </attribute> + </optional> + </element> + </optional> <optional> <element name="currentMemory"> <ref name='scaledInteger'/> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 638c258..3a12b35 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -3210,6 +3210,13 @@ virDomainDefPostParseInternal(virDomainDefPtr def, return -1; } + if (virDomainDefGetMemoryInitial(def) == 0) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Memory size must be specified via <memory> or in the " + "<numa> 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 @@ -13226,7 +13233,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 0000000..ca34f73 --- /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 0000000..fbdc5e6 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-numa-no-memory-element.xml @@ -0,0 +1,24 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>16</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu> + <topology sockets='2' cores='4' threads='2'/> + <numa> + <cell id='1' cpus='8-15' memory='109550' unit='KiB'/> + <cell id='0' cpus='0-7' memory='109550' unit='KiB'/> + </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</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-minimal-no-memory.xml b/tests/qemuxml2argvdata/qemuxml2argv-minimal-no-memory.xml new file mode 100644 index 0000000..6824651 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-minimal-no-memory.xml @@ -0,0 +1,25 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</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='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 00fd044..373595d 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 0000000..58f40b9 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-cpu-numa-no-memory-element.xml @@ -0,0 +1,28 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>16</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu> + <topology sockets='2' cores='4' threads='2'/> + <numa> + <cell id='0' cpus='0-7' memory='109550' unit='KiB'/> + <cell id='1' cpus='8-15' memory='109550' unit='KiB'/> + </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</emulator> + <controller type='usb' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 2bec2b2..d255595 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -408,6 +408,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"); -- 2.2.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list