[libvirt] [PATCH 2/2] qemu: Add support for 'l2-cache-size' property of qcow2

Lin Ma lma at suse.com
Wed Nov 15 01:58:58 UTC 2017


Signed-off-by: Lin Ma <lma at suse.com>
---
 docs/formatdomain.html.in                          | 11 +++++++
 docs/schemas/domaincommon.rng                      |  5 ++++
 src/conf/domain_conf.c                             | 11 +++++++
 src/conf/domain_conf.h                             |  1 +
 src/qemu/qemu_command.c                            | 18 ++++++++++++
 .../qemuxml2argv-disk-drive-l2-cache-size.args     | 24 +++++++++++++++
 .../qemuxml2argv-disk-drive-l2-cache-size.xml      | 34 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  2 ++
 .../qemuxml2xmlout-disk-drive-l2-cache-size.xml    | 34 ++++++++++++++++++++++
 tests/qemuxml2xmltest.c                            |  1 +
 10 files changed, 141 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.xml
 create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-l2-cache-size.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 8dbea6a..6f4b043 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2513,6 +2513,11 @@
     </backingStore>
     <target dev='vdd' bus='virtio'/>
   </disk>
+  <disk type='file' device='disk'>
+    <driver name='qemu' type='qcow2' l2-cache-size='2097152'/>
+    <source file='/var/lib/libvirt/images/domain.qcow2'/>
+    <target dev='vde' bus='virtio'/>
+  </disk>
 </devices>
 ...</pre>
 
@@ -3195,6 +3200,12 @@
             virt queues for virtio-blk. (<span class="since">Since 3.9.0</span>)
           </li>
           <li>
+            The optional <code>l2-cache-size</code> attribute specifies the
+            maximum size of the L2 table cache for qcow2 image. The size must
+            be a multiple of the cluster size.(QEMU currently defaults to 64
+            KB clusters)(<span class="since">Since 3.10.0</span>)
+          </li>
+          <li>
           For virtio disks,
           <a href="#elementsVirtio">Virtio-specific options</a> can also be
           set. (<span class="since">Since 3.5.0</span>)
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 82fdfd5..4036a41 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1864,6 +1864,11 @@
           <ref name="positiveInteger"/>
         </attribute>
       </optional>
+      <optional>
+        <attribute name='l2-cache-size'>
+          <ref name="positiveInteger"/>
+        </attribute>
+      </optional>
       <ref name="virtioOptions"/>
       <empty/>
     </element>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 62d0a16..27b536b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9082,6 +9082,15 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
     }
     VIR_FREE(tmp);
 
+    if ((tmp = virXMLPropString(cur, "l2-cache-size")) &&
+        virStrToLong_uip(tmp, NULL, 10, &def->l2_cache_size) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("'l2-cache-size' attribute must be positive number: %s"),
+                       tmp);
+        goto cleanup;
+    }
+    VIR_FREE(tmp);
+
     ret = 0;
 
  cleanup:
@@ -22495,6 +22504,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
         virBufferAsprintf(&driverBuf, " detect_zeroes='%s'", detect_zeroes);
     if (def->queues)
         virBufferAsprintf(&driverBuf, " queues='%u'", def->queues);
+    if (def->l2_cache_size)
+        virBufferAsprintf(&driverBuf, " l2-cache-size='%u'", def->l2_cache_size);
 
     virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 41443a0..1331feb 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -669,6 +669,7 @@ struct _virDomainDiskDef {
     int detect_zeroes; /* enum virDomainDiskDetectZeroes */
     char *domain_name; /* backend domain name */
     unsigned int queues;
+    unsigned int l2_cache_size;
     virDomainVirtioOptionsPtr virtio;
 };
 
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 56729e4..3a35ef8 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1338,6 +1338,13 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk,
         return -1;
     }
 
+    if (disk->l2_cache_size &&
+        disk->src->format != VIR_STORAGE_FILE_QCOW2) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Only 'qcow2' format supports the l2-cache-size"));
+        return -1;
+    }
+
     if (qemuCaps) {
         if (disk->serial &&
             virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_SERIAL)) {
@@ -1391,6 +1398,13 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk,
                            _("disk aio mode not supported with this QEMU binary"));
             return -1;
         }
+
+        if (disk->l2_cache_size &&
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_L2_CACHE_SIZE)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("'l2-cache-size' isn't supported with this QEMU binary"));
+            return -1;
+        }
     }
 
     if (disk->serial &&
@@ -1726,6 +1740,10 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
                           virDomainDiskDetectZeroesTypeToString(detect_zeroes));
     }
 
+    if (disk->l2_cache_size) {
+        virBufferAsprintf(&opt, ",l2-cache-size=%u", disk->l2_cache_size);
+    }
+
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_MONITOR_JSON)) {
         const char *wpolicy = NULL, *rpolicy = NULL;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.args
new file mode 100644
index 0000000..327e916
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.args
@@ -0,0 +1,24 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-i686 \
+-name QEMUGuest1 \
+-S \
+-M pc \
+-m 214 \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-nographic \
+-nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\
+server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=readline \
+-no-acpi \
+-boot c \
+-usb \
+-drive file=/tmp/disk0.qcow2,format=qcow2,if=none,id=drive-virtio-disk0,l2-cache-size=2097152 \
+-device virtio-blk-pci,bus=pci.0,addr=0x3,\
+drive=drive-virtio-disk0,id=virtio-disk0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.xml
new file mode 100644
index 0000000..623c7ed
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-drive-l2-cache-size.xml
@@ -0,0 +1,34 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <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='file' device='disk'>
+      <driver name='qemu' type='qcow2' l2-cache-size='2097152'/>
+      <source file='/tmp/disk0.qcow2'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </disk>
+    <controller type='usb' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1bedc68..6277a64 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -894,6 +894,8 @@ mymain(void)
             QEMU_CAPS_DRIVE_BOOT, QEMU_CAPS_VIRTIO_BLK_SCSI);
     DO_TEST("disk-virtio-drive-queues",
             QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES);
+    DO_TEST("disk-drive-l2-cache-size",
+            QEMU_CAPS_DRIVE_L2_CACHE_SIZE);
     DO_TEST("disk-drive-boot-disk",
             QEMU_CAPS_DRIVE_BOOT);
     DO_TEST("disk-drive-boot-cdrom",
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-l2-cache-size.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-l2-cache-size.xml
new file mode 100644
index 0000000..623c7ed
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-l2-cache-size.xml
@@ -0,0 +1,34 @@
+<domain type='qemu'>
+  <name>QEMUGuest1</name>
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='i686' machine='pc'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <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='file' device='disk'>
+      <driver name='qemu' type='qcow2' l2-cache-size='2097152'/>
+      <source file='/tmp/disk0.qcow2'/>
+      <target dev='vda' bus='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </disk>
+    <controller type='usb' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+    </controller>
+    <controller type='ide' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <input type='mouse' bus='ps2'/>
+    <input type='keyboard' bus='ps2'/>
+    <memballoon model='none'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 1afd0d2..89423f0 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -496,6 +496,7 @@ mymain(void)
     DO_TEST("disk-virtio", NONE);
     DO_TEST("floppy-drive-fat", NONE);
     DO_TEST("disk-virtio-drive-queues", QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES);
+    DO_TEST("disk-drive-l2-cache-size", QEMU_CAPS_DRIVE_L2_CACHE_SIZE);
     DO_TEST("disk-drive-boot-disk", NONE);
     DO_TEST("disk-drive-boot-cdrom", NONE);
     DO_TEST("disk-drive-error-policy-stop", NONE);
-- 
2.9.2




More information about the libvir-list mailing list