[libvirt] [PATCH 2/2] qemu: Support multiqueue virtio-blk

Lin Ma lma at suse.com
Fri Sep 29 13:54:23 UTC 2017


qemu 2.7.0 introduces multiqueue virtio-blk(commit 2f27059).
This patch introduces a new attribute "queues". An example of
the XML:

<disk type='file' device='disk'>
  <driver name='qemu' type='qcow2' queues='4'/>

The corresponding QEMU command line:

-device virtio-blk-pci,scsi=off,num-queues=4,id=virtio-disk0

Signed-off-by: Lin Ma <lma at suse.com>
---
 docs/formatdomain.html.in                          |  6 +++-
 docs/schemas/domaincommon.rng                      |  5 ++++
 src/conf/domain_conf.c                             | 19 ++++++++++++
 src/conf/domain_conf.h                             |  1 +
 src/qemu/qemu_capabilities.c                       |  2 ++
 src/qemu/qemu_capabilities.h                       |  1 +
 src/qemu/qemu_command.c                            |  4 +++
 .../qemuxml2argv-disk-virtio-drive-queues.args     | 24 +++++++++++++++
 .../qemuxml2argv-disk-virtio-drive-queues.xml      | 34 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  2 ++
 .../qemuxml2xmlout-disk-virtio-drive-queues.xml    |  1 +
 tests/qemuxml2xmltest.c                            |  1 +
 12 files changed, 99 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.xml
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-virtio-drive-queues.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 5bdcb569c..2b4eac1f8 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2393,7 +2393,7 @@
     <target dev='vdc' bus='virtio'/>
   </disk>
   <disk type='file' device='disk'>
-    <driver name='qemu' type='qcow2'/>
+    <driver name='qemu' type='qcow2' queues='4'/>
     <source file='/var/lib/libvirt/images/domain.qcow'/>
     <backingStore type='file'>
       <format type='qcow2'/>
@@ -3053,6 +3053,10 @@
             <code>bus</code> and "pci" or "ccw" <code>address</code> types.
             <span class='since'>Since 1.2.8 (QEMU 2.1)</span>
           </li>
+          <li>
+            The optional <code>queues</code> attribute specifies the number of
+            virt queues for virtio-blk. (<span class="since">Since 3.8.0</span>)
+          </li>
           <li>
           For virtio disks,
           <a href="#elementsVirtio">Virtio-specific options</a> can also be
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index bac371ea3..66b3d70c6 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1811,6 +1811,11 @@
       <optional>
         <ref name="detect_zeroes"/>
       </optional>
+      <optional>
+        <attribute name='queues'>
+          <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 87192eb2d..90572d51a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8761,6 +8761,15 @@ virDomainDiskDefDriverParseXML(virDomainDiskDefPtr def,
     }
     VIR_FREE(tmp);
 
+    if ((tmp = virXMLPropString(cur, "queues")) &&
+        virStrToLong_ui(tmp, NULL, 10, &def->queues) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("'queues' attribute must be positive number: %s"),
+                       tmp);
+        goto cleanup;
+    }
+    VIR_FREE(tmp);
+
     ret = 0;
 
  cleanup:
@@ -21996,6 +22005,16 @@ virDomainDiskDefFormat(virBufferPtr buf,
         virBufferAsprintf(&driverBuf, " iothread='%u'", def->iothread);
     if (def->detect_zeroes)
         virBufferAsprintf(&driverBuf, " detect_zeroes='%s'", detect_zeroes);
+    if (def->queues) {
+        if (def->bus == VIR_DOMAIN_DISK_BUS_VIRTIO)
+            virBufferAsprintf(&driverBuf, " queues='%u'", def->queues);
+        else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("queues attribute in disk driver element is only "
+                             "supported by virtio-blk"));
+            return -1;
+        }
+    }
 
     virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 05a035a16..28abe2b0b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -668,6 +668,7 @@ struct _virDomainDiskDef {
     unsigned int iothread; /* unused = 0, > 0 specific thread # */
     int detect_zeroes; /* enum virDomainDiskDetectZeroes */
     char *domain_name; /* backend domain name */
+    unsigned int queues;
     virDomainVirtioOptionsPtr virtio;
 };
 
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 085910dd4..f9028157f 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -442,6 +442,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST,
 
               /* 270 */
               "vxhs",
+              "virtio-blk.num-queues",
     );
 
 
@@ -1692,6 +1693,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioBlk[] = {
     { "event_idx", QEMU_CAPS_VIRTIO_BLK_EVENT_IDX },
     { "scsi", QEMU_CAPS_VIRTIO_BLK_SCSI },
     { "logical_block_size", QEMU_CAPS_BLOCKIO },
+    { "num-queues", QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES },
 };
 
 static struct virQEMUCapsStringFlags virQEMUCapsObjectPropsVirtioNet[] = {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 214734ff2..2d16e5b0e 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -428,6 +428,7 @@ typedef enum {
 
     /* 270 */
     QEMU_CAPS_VXHS, /* -drive file.driver=vxhs via query-qmp-schema */
+    QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES, /* virtio-blk-*.num-queues */
 
     QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 4f141e0ac..4d2787d8f 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2082,6 +2082,10 @@ qemuBuildDriveDevStr(const virDomainDef *def,
                               (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN)
                               ? "on" : "off");
         }
+        if (disk->queues &&
+            virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_BLK_NUM_QUEUES)) {
+            virBufferAsprintf(&opt, ",num-queues=%u", disk->queues);
+        }
 
         if (qemuBuildVirtioOptionsStr(&opt, disk->virtio, qemuCaps) < 0)
             goto error;
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.args
new file mode 100644
index 000000000..5e0ce8b8f
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.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/data.img,format=raw,if=none,id=drive-virtio-disk0 \
+-device virtio-blk-pci,num-queues=4,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,\
+id=virtio-disk0
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.xml
new file mode 100644
index 000000000..37885c6f9
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.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='raw' queues='4'/>
+      <source file='/tmp/data.img'/>
+      <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 7271ea07e..a505864b8 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -892,6 +892,8 @@ mymain(void)
             QEMU_CAPS_VIRTIO_CCW, QEMU_CAPS_VIRTIO_S390);
     DO_TEST("disk-order",
             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-boot-disk",
             QEMU_CAPS_DRIVE_BOOT);
     DO_TEST("disk-drive-boot-cdrom",
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-virtio-drive-queues.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-virtio-drive-queues.xml
new file mode 120000
index 000000000..a4efc340e
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-virtio-drive-queues.xml
@@ -0,0 +1 @@
+../qemuxml2argvdata/qemuxml2argv-disk-virtio-drive-queues.xml
\ No newline at end of file
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 2dba3607c..73489eed9 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -449,6 +449,7 @@ mymain(void)
     DO_TEST("disk-usb-device", NONE);
     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-boot-disk", NONE);
     DO_TEST("disk-drive-boot-cdrom", NONE);
     DO_TEST("disk-drive-error-policy-stop", NONE);
-- 
2.14.0




More information about the libvir-list mailing list