[PATCH 3/4] conf: Allow omitting 'slots' attribute of <maxMemory>

Peter Krempa pkrempa at redhat.com
Thu Jun 22 12:58:20 UTC 2023


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 at redhat.com>
---
 src/conf/domain_conf.c                              | 13 ++++++++++---
 src/conf/domain_postparse.c                         |  5 ++---
 src/conf/schemas/domaincommon.rng                   |  8 +++++---
 .../memory-hotplug-virtio-mem.x86_64-latest.args    |  2 +-
 .../qemuxml2argvdata/memory-hotplug-virtio-mem.xml  |  2 +-
 .../memory-hotplug-virtio-pmem.x86_64-5.2.0.args    |  2 +-
 .../memory-hotplug-virtio-pmem.x86_64-latest.args   |  2 +-
 .../qemuxml2argvdata/memory-hotplug-virtio-pmem.xml |  2 +-
 8 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0edb1bda9d..1fde53ff4c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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");
diff --git a/src/conf/domain_postparse.c b/src/conf/domain_postparse.c
index c6695b460d..f1dfdb7665 100644
--- a/src/conf/domain_postparse.c
+++ b/src/conf/domain_postparse.c
@@ -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;
     }

diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincommon.rng
index c1725bb511..4b595fd066 100644
--- a/src/conf/schemas/domaincommon.rng
+++ b/src/conf/schemas/domaincommon.rng
@@ -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>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
index 7309fea2ff..607ce9b0e8 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
@@ -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}' \
diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml
index 6220ab4c82..c578209d8a 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml
@@ -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>
diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-5.2.0.args b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-5.2.0.args
index e28dd339e9..fc42f9b108 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-5.2.0.args
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-5.2.0.args
@@ -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 \
diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.args b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.args
index bd8343c15e..9bbde420a9 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.args
@@ -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}' \
diff --git a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml
index 21b90e4d8a..a8b22dd3c5 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml
+++ b/tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml
@@ -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>
-- 
2.40.1



More information about the libvir-list mailing list