conf: Allow omitting 'slots' attribute of <maxMemory>

Memory slots are required only for DIMM-like devices, but the maximum
memory address space is relevant also for other non-DIMM memory devices
such as virtio-mem. Allow configurations where no slots are added.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-06-21 16:01:26 +02:00
parent e3ce39195c
commit e4b4765f4f
8 changed files with 22 additions and 14 deletions

View File

@ -27416,9 +27416,16 @@ virDomainDefFormatInternalSetRootName(virDomainDef *def,
return -1;
if (virDomainDefHasMemoryHotplug(def)) {
virBufferAsprintf(buf,
"<maxMemory slots='%u' unit='KiB'>%llu</maxMemory>\n",
def->mem.memory_slots, def->mem.max_memory);
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) contentBuf = VIR_BUFFER_INITIALIZER;
if (def->mem.memory_slots > 0)
virBufferAsprintf(&attrBuf, " slots='%u'", def->mem.memory_slots);
virBufferAddLit(&attrBuf, " unit='KiB'");
virBufferAsprintf(&contentBuf, "%llu", def->mem.max_memory);
virXMLFormatElementInternal(buf, "maxMemory", &attrBuf, &contentBuf, false, false);
}
virBufferAddLit(buf, "<memory");

View File

@ -72,10 +72,9 @@ virDomainDefPostParseMemory(virDomainDef *def,
def->mem.cur_balloon == 0)
def->mem.cur_balloon = virDomainDefGetMemoryTotal(def);
if ((def->mem.max_memory || def->mem.memory_slots) &&
!(def->mem.max_memory && def->mem.memory_slots)) {
if (def->mem.max_memory == 0 && def->mem.memory_slots > 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("both maximum memory size and memory slot count must be specified"));
_("maximum memory size must be specified when specifying number of memory slots"));
return -1;
}

View File

@ -721,9 +721,11 @@
<optional>
<element name="maxMemory">
<ref name="scaledInteger"/>
<attribute name="slots">
<ref name="unsignedInt"/>
</attribute>
<optional>
<attribute name="slots">
<ref name="unsignedInt"/>
</attribute>
</optional>
</element>
</optional>
<optional>

View File

@ -13,7 +13,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-machine pc,usb=off,dump-guest-core=off,acpi=off \
-accel kvm \
-cpu qemu64 \
-m size=2095104k,slots=1,maxmem=1099511627776k \
-m size=2095104k,maxmem=1099511627776k \
-overcommit mem-lock=off \
-smp 2,sockets=2,dies=1,cores=1,threads=1 \
-object '{"qom-type":"memory-backend-ram","id":"ram-node0","size":2145386496}' \

View File

@ -1,7 +1,7 @@
<domain type='kvm'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<maxMemory slots='1' unit='KiB'>1099511627776</maxMemory>
<maxMemory unit='KiB'>1099511627776</maxMemory>
<memory unit='KiB'>8388608</memory>
<currentMemory unit='KiB'>8388608</currentMemory>
<vcpu placement='static' cpuset='0-1'>2</vcpu>

View File

@ -13,7 +13,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-machine pc-i440fx-5.2,usb=off,dump-guest-core=off \
-accel kvm \
-cpu qemu64 \
-m size=2095104k,slots=16,maxmem=1099511627776k \
-m size=2095104k,maxmem=1099511627776k \
-overcommit mem-lock=off \
-smp 2,sockets=2,dies=1,cores=1,threads=1 \
-object memory-backend-ram,id=ram-node0,size=2145386496 \

View File

@ -13,7 +13,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \
-machine pc,usb=off,dump-guest-core=off,acpi=off \
-accel kvm \
-cpu qemu64 \
-m size=2095104k,slots=16,maxmem=1099511627776k \
-m size=2095104k,maxmem=1099511627776k \
-overcommit mem-lock=off \
-smp 2,sockets=2,dies=1,cores=1,threads=1 \
-object '{"qom-type":"memory-backend-ram","id":"ram-node0","size":2145386496}' \

View File

@ -1,7 +1,7 @@
<domain type='kvm'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<maxMemory slots='16' unit='KiB'>1099511627776</maxMemory>
<maxMemory unit='KiB'>1099511627776</maxMemory>
<memory unit='KiB'>2095104</memory>
<currentMemory unit='KiB'>2095104</currentMemory>
<vcpu placement='static' cpuset='0-1'>2</vcpu>