]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Allow omitting 'slots' attribute of <maxMemory>
authorPeter Krempa <pkrempa@redhat.com>
Wed, 21 Jun 2023 14:01:26 +0000 (16:01 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Jun 2023 10:58:24 +0000 (12:58 +0200)
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>
src/conf/domain_conf.c
src/conf/domain_postparse.c
src/conf/schemas/domaincommon.rng
tests/qemuxml2argvdata/memory-hotplug-virtio-mem.x86_64-latest.args
tests/qemuxml2argvdata/memory-hotplug-virtio-mem.xml
tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-5.2.0.args
tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.x86_64-latest.args
tests/qemuxml2argvdata/memory-hotplug-virtio-pmem.xml

index 0edb1bda9d64270d2ae19b486ad31a1dde409382..1fde53ff4c00d9e7322c00842e221b0963dbc2b0 100644 (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");
index c6695b460d9dfcb2d5159fcdf92570b55437ccc9..f1dfdb766500204170fad151a00485c66b7ac428 100644 (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;
     }
 
index c1725bb5118ab558b73454b76e7b7d946b9bdda8..4b595fd066e7cd639e828c4bbdd644d9bbdd966e 100644 (file)
       <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>
index 7309fea2ff0626b6c025b7633e9fde418f62fdc6..607ce9b0e884827f6af668f080f95c31d8db4689 100644 (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}' \
index 6220ab4c82e52f91893f428a16ae94f86e0fc469..c578209d8a1cf1d5f1db19b9b5c459eacf6be627 100644 (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>
index e28dd339e9242ebcfad2b7906f6528a4c6413e54..fc42f9b1082f557017378e883599bbe226b340cd 100644 (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 \
index bd8343c15e4f4be410cc096672ece9bdde015187..9bbde420a965a4f572b7121cd5e77d6bad712d3e 100644 (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}' \
index 21b90e4d8a45e3e1af32c354834769f067245eda..a8b22dd3c5eb53aa6f157f3339c17d042eaf2a8c 100644 (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>