]> xenbits.xensource.com Git - libvirt.git/commitdiff
conf: Introduce 'readonly' element into xml for NVDIMM memory
authorLuyao Zhong <luyao.zhong@intel.com>
Thu, 20 Dec 2018 09:14:42 +0000 (17:14 +0800)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 2 Jan 2019 14:00:34 +0000 (09:00 -0500)
The 'readonly' option allows users to mark vNVDIMM read-only:

<devices>
  ...
  <memory model='nvdimm' access='shared'>
      <source>
          <path>/dev/dax0.0</path>
      </source>
      <target>
          <size unit='MiB'>4094</size>
          <node>0</node>
          <label>
              <size unit='MiB'>2</size>
          </label>
          <readonly/>
      </target>
  </memory>
  ...
</devices>

Signed-off-by: Luyao Zhong <luyao.zhong@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml [new file with mode: 0644]
tests/qemuxml2xmloutdata/memory-hotplug-nvdimm-readonly.xml [new symlink]
tests/qemuxml2xmltest.c

index 0b1b478b2af4aa00f74d7007f2a3e007a6839f1b..7f07bb7f559bd840aa5b31214ce6c3dcde65ee0d 100644 (file)
@@ -8330,6 +8330,7 @@ qemu-kvm -net nic,model=? /dev/null
       &lt;label&gt;
         &lt;size unit='KiB'&gt;128&lt;/size&gt;
       &lt;/label&gt;
+      &lt;readonly/&gt;
     &lt;/target&gt;
   &lt;/memory&gt;
   &lt;memory model='nvdimm'&gt;
@@ -8465,19 +8466,39 @@ qemu-kvm -net nic,model=? /dev/null
           NUMA nodes configured.
         </p>
         <p>
-          For NVDIMM type devices one can optionally use
-          <code>label</code> and its subelement <code>size</code>
-          to configure the size of namespaces label storage
-          within the NVDIMM module. The <code>size</code> element
-          has usual meaning described
-          <a href="#elementsMemoryAllocation">here</a>.
-          For QEMU domains the following restrictions apply:
+          The following optional elements may be used:
         </p>
-        <ol>
-          <li>the minimum label size is 128KiB,</li>
-          <li>the remaining size (total-size - label-size) has to be aligned to
-            4KiB</li>
-        </ol>
+
+        <dl>
+          <dt><code>label</code></dt>
+          <dd>
+            <p>
+              For NVDIMM type devices one can optionally use
+              <code>label</code> and its subelement <code>size</code>
+              to configure the size of namespaces label storage
+              within the NVDIMM module. The <code>size</code> element
+              has usual meaning described
+              <a href="#elementsMemoryAllocation">here</a>.
+              For QEMU domains the following restrictions apply:
+            </p>
+            <ol>
+              <li>the minimum label size is 128KiB,</li>
+              <li>the remaining size (total-size - label-size) will be aligned
+                to 4KiB as default.</li>
+            </ol>
+          </dd>
+
+          <dt><code>readonly</code></dt>
+          <dd>
+            <p>
+              The <code>readonly</code> element is used to mark the vNVDIMM
+              as read-only. Only the real NVDIMM device backend can guarantee
+              the guest write persistence, so other backend types should use
+              the <code>readonly</code> element.
+              <span class="since">Since 5.0.0</span>
+            </p>
+          </dd>
+        </dl>
       </dd>
     </dl>
 
index a7b7164ad1004315d23544d72474e89fd9a408fe..6518aff73aa22525f20c675461e8a84075078dc0 100644 (file)
             </element>
           </element>
         </optional>
+        <optional>
+          <element name="readonly">
+            <empty/>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
index 9edaf6d4935d5072496898b54c1166e4cca4064f..222bb8c482901a21ac93ee1353ad50a632b13f28 100644 (file)
@@ -15844,6 +15844,9 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
                            _("label size must be smaller than NVDIMM size"));
             goto cleanup;
         }
+
+        if (virXPathBoolean("boolean(./readonly)", ctxt))
+            def->readonly = true;
     }
 
     ret = 0;
@@ -22766,6 +22769,13 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDefPtr src,
                              "source NVDIMM pmem flag"));
             return false;
         }
+
+        if (src->readonly != dst->readonly) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Target NVDIMM readonly flag doesn't match "
+                             "source NVDIMM readonly flag"));
+            return false;
+        }
     }
 
     return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info);
@@ -26344,6 +26354,8 @@ virDomainMemoryTargetDefFormat(virBufferPtr buf,
         virBufferAdjustIndent(buf, -2);
         virBufferAddLit(buf, "</label>\n");
     }
+    if (def->readonly)
+        virBufferAddLit(buf, "<readonly/>\n");
 
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</target>\n");
index a63afdca12c1c242d04a57a6164f4aac9a2479f0..fae130668f2a4eafa070ee2ade20e3d1a6b4b9a9 100644 (file)
@@ -2155,6 +2155,7 @@ struct _virDomainMemoryDef {
     int targetNode;
     unsigned long long size; /* kibibytes */
     unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */
+    bool readonly; /* valid only for NVDIMM */
 
     virDomainDeviceInfo info;
 };
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
new file mode 100644 (file)
index 0000000..170992c
--- /dev/null
@@ -0,0 +1,58 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <maxMemory slots='16' unit='KiB'>1099511627776</maxMemory>
+  <memory unit='KiB'>1267710</memory>
+  <currentMemory unit='KiB'>1267710</currentMemory>
+  <vcpu placement='static' cpuset='0-1'>2</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <idmap>
+    <uid start='0' target='1000' count='10'/>
+    <gid start='0' target='1000' count='10'/>
+  </idmap>
+  <cpu>
+    <topology sockets='2' cores='1' threads='1'/>
+    <numa>
+      <cell id='0' cpus='0-1' memory='219136' 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-system-i686</emulator>
+    <disk type='block' device='disk'>
+      <driver name='qemu' type='raw'/>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='hda' bus='ide'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='usb' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='virtio'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </memballoon>
+    <memory model='nvdimm' access='private'>
+      <source>
+        <path>/tmp/nvdimm</path>
+      </source>
+      <target>
+        <size unit='KiB'>523264</size>
+        <node>0</node>
+        <readonly/>
+      </target>
+      <address type='dimm' slot='0'/>
+    </memory>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmloutdata/memory-hotplug-nvdimm-readonly.xml b/tests/qemuxml2xmloutdata/memory-hotplug-nvdimm-readonly.xml
new file mode 120000 (symlink)
index 0000000..10be844
--- /dev/null
@@ -0,0 +1 @@
+../qemuxml2argvdata/memory-hotplug-nvdimm-readonly.xml
\ No newline at end of file
index ef3ece8902b516d3724301203a253dc1ae7ded65..82e2c0ee0fc2ce468627e54017c4601fcfdc059f 100644 (file)
@@ -1118,6 +1118,7 @@ mymain(void)
     DO_TEST("memory-hotplug-nvdimm-label", NONE);
     DO_TEST("memory-hotplug-nvdimm-align", NONE);
     DO_TEST("memory-hotplug-nvdimm-pmem", NONE);
+    DO_TEST("memory-hotplug-nvdimm-readonly", NONE);
     DO_TEST("net-udp", NONE);
 
     DO_TEST("video-virtio-gpu-device", NONE);