]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Introduce label-size for NVDIMMs
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 27 Feb 2017 10:20:26 +0000 (11:20 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 15 Mar 2017 13:39:22 +0000 (14:39 +0100)
For NVDIMM devices it is optionally possible to specify the size
of internal storage for namespaces. Namespaces are a feature that
allows users to partition the NVDIMM for different uses.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_command.c
tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-nvdimm-label.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-nvdimm-label.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/qemuxml2xmlout-memory-hotplug-nvdimm-label.xml [new symlink]
tests/qemuxml2xmltest.c

index a8a4191081da305c899a65c96a3b8466b5d87c40..da0ae4aeba20afb2fe06101a3b0cf2575320f2cd 100644 (file)
@@ -7123,6 +7123,9 @@ qemu-kvm -net nic,model=? /dev/null
     &lt;target&gt;
       &lt;size unit='KiB'&gt;524288&lt;/size&gt;
       &lt;node&gt;1&lt;/node&gt;
+      &lt;label&gt;
+        &lt;size unit='KiB'&gt;128&lt;/size&gt;
+      &lt;/label&gt;
     &lt;/target&gt;
   &lt;/memory&gt;
 &lt;/devices&gt;
@@ -7204,6 +7207,20 @@ qemu-kvm -net nic,model=? /dev/null
           attach the memory to. The element shall be used only if the guest has
           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:
+        </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>
       </dd>
     </dl>
 
index 1b7b3c79386d234ddc38ac923521de7eec9d955a..8be5e0873099af3884c43927470d8188e982da0d 100644 (file)
             <ref name="unsignedInt"/>
           </element>
         </optional>
+        <optional>
+          <element name="label">
+            <element name="size">
+              <ref name="scaledInteger"/>
+            </element>
+          </element>
+        </optional>
       </interleave>
     </element>
   </define>
index 7f6eeafbe637010892e3ff59b9633cab56d49689..11fde50d59f136f58488f92d8e846a0a25708dc4 100644 (file)
@@ -13785,6 +13785,24 @@ virDomainMemoryTargetDefParseXML(xmlNodePtr node,
                              &def->size, true, false) < 0)
         goto cleanup;
 
+    if (def->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM) {
+        if (virDomainParseMemory("./label/size", "./label/size/@unit", ctxt,
+                                 &def->labelsize, false, false) < 0)
+            goto cleanup;
+
+        if (def->labelsize && def->labelsize < 128) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("nvdimm label must be at least 128KiB"));
+            goto cleanup;
+        }
+
+        if (def->labelsize >= def->size) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("label size must be smaller than NVDIMM size"));
+            goto cleanup;
+        }
+    }
+
     ret = 0;
 
  cleanup:
@@ -19468,6 +19486,15 @@ virDomainMemoryDefCheckABIStability(virDomainMemoryDefPtr src,
         return false;
     }
 
+    if (src->model == VIR_DOMAIN_MEMORY_MODEL_NVDIMM &&
+        src->labelsize != dst->labelsize) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("Target NVDIMM label size '%llu' doesn't match "
+                         "source NVDIMM label size '%llu'"),
+                       src->labelsize, dst->labelsize);
+        return false;
+    }
+
     return virDomainDeviceInfoCheckABIStability(&src->info, &dst->info);
 }
 
@@ -22624,6 +22651,13 @@ virDomainMemoryTargetDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf, "<size unit='KiB'>%llu</size>\n", def->size);
     if (def->targetNode >= 0)
         virBufferAsprintf(buf, "<node>%d</node>\n", def->targetNode);
+    if (def->labelsize) {
+        virBufferAddLit(buf, "<label>\n");
+        virBufferAdjustIndent(buf, 2);
+        virBufferAsprintf(buf, "<size unit='KiB'>%llu</size>\n", def->labelsize);
+        virBufferAdjustIndent(buf, -2);
+        virBufferAddLit(buf, "</label>\n");
+    }
 
     virBufferAdjustIndent(buf, -2);
     virBufferAddLit(buf, "</target>\n");
index 16e14321985090d82f77c494274df2f97ab84002..826afb42cb3ac8ff9bc05ed1ba5b7b050f7e40ea 100644 (file)
@@ -2014,6 +2014,7 @@ struct _virDomainMemoryDef {
     int model; /* virDomainMemoryModel */
     int targetNode;
     unsigned long long size; /* kibibytes */
+    unsigned long long labelsize; /* kibibytes; valid only for NVDIMM */
 
     virDomainDeviceInfo info;
 };
index b655f23da4ddda7e25c96492a5cf3a1999820bbb..61d9eb94adbe7ee67ae9aa5ca901db7e6d3dd76e 100644 (file)
@@ -3519,6 +3519,9 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem)
         if (mem->targetNode >= 0)
             virBufferAsprintf(&buf, "node=%d,", mem->targetNode);
 
+        if (mem->labelsize)
+            virBufferAsprintf(&buf, "label-size=%llu,", mem->labelsize * 1024);
+
         virBufferAsprintf(&buf, "memdev=mem%s,id=%s",
                           mem->info.alias, mem->info.alias);
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-nvdimm-label.args b/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-nvdimm-label.args
new file mode 100644 (file)
index 0000000..8669f2d
--- /dev/null
@@ -0,0 +1,26 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu \
+-name QEMUGuest1 \
+-S \
+-machine pc,accel=tcg,nvdimm=on \
+-m size=219136k,slots=16,maxmem=1099511627776k \
+-smp 2,sockets=2,cores=1,threads=1 \
+-numa node,nodeid=0,cpus=0-1,mem=214 \
+-object memory-backend-file,id=memnvdimm0,prealloc=yes,mem-path=/tmp/nvdimm,\
+share=no,size=536870912 \
+-device nvdimm,node=0,label-size=131072,memdev=memnvdimm0,id=nvdimm0,slot=0 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefaults \
+-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-nvdimm-label.xml b/tests/qemuxml2argvdata/qemuxml2argv-memory-hotplug-nvdimm-label.xml
new file mode 100644 (file)
index 0000000..4253852
--- /dev/null
@@ -0,0 +1,59 @@
+<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</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='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>
+        <label>
+          <size unit='KiB'>128</size>
+        </label>
+      </target>
+      <address type='dimm' slot='0'/>
+    </memory>
+  </devices>
+</domain>
index eb05b8a82cc293203f5b9dbb278a8885cdabc1b8..5716509befa9b8c0a08ea368494f990005d06a9f 100644 (file)
@@ -2338,6 +2338,8 @@ mymain(void)
             QEMU_CAPS_NUMA, QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
     DO_TEST("memory-hotplug-nvdimm-access", QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_DEVICE_NVDIMM,
             QEMU_CAPS_NUMA, QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
+    DO_TEST("memory-hotplug-nvdimm-label", QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_DEVICE_NVDIMM,
+            QEMU_CAPS_NUMA, QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
 
     DO_TEST("machine-aeskeywrap-on-caps",
             QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_AES_KEY_WRAP,
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-memory-hotplug-nvdimm-label.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-memory-hotplug-nvdimm-label.xml
new file mode 120000 (symlink)
index 0000000..0d599a1
--- /dev/null
@@ -0,0 +1 @@
+../qemuxml2argvdata/qemuxml2argv-memory-hotplug-nvdimm-label.xml
\ No newline at end of file
index ef49a79ca5b371422923f9b764ca51f501390da9..bf62dbbb26820c613d18511802026ffb7ecf3e82 100644 (file)
@@ -1080,6 +1080,7 @@ mymain(void)
     DO_TEST("memory-hotplug-dimm", NONE);
     DO_TEST("memory-hotplug-nvdimm", NONE);
     DO_TEST("memory-hotplug-nvdimm-access", NONE);
+    DO_TEST("memory-hotplug-nvdimm-label", NONE);
     DO_TEST("net-udp", NONE);
 
     DO_TEST("video-virtio-gpu-device", NONE);