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

2017-09-29 Thread Ján Tomko

On Fri, Sep 29, 2017 at 09:54:23PM +0800, Lin Ma wrote:

@@ -3053,6 +3053,10 @@
bus and "pci" or "ccw" address types.
Since 1.2.8 (QEMU 2.1)
  
+  
+The optional queues attribute specifies the number of
+virt queues for virtio-blk. (Since 
3.8.0)


3.9.0, now that 3.8.0 is frozen


+  
  
  For virtio disks,
  Virtio-specific options can also be



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) {


virStrToLong_ui allows specifying a negative number and wraps it into a
positive number (e.g. -1 is a shortcut for UINT_MAX)
Please use virStrToLong_uip instead.


+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;


This check does not belong in the formatter. If we parsed it, we should
be able to format it back.

Either only parse the attribute if the bus is DISK_BUS_VIRTIO, or add the check
to qemuDomain*DefValidate.


+}
+}

virDomainVirtioOptionsFormat(&driverBuf, def->virtio);




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 QEMU does not have the capability, it would be nice to report an
error to the user instead of quietly doing nothing with the attribute.
(The check also probably belongs in qemuDomain*DefValidate)


+}

if (qemuBuildVirtioOptionsStr(&opt, disk->virtio, qemuCaps) < 0)
goto error;


Jan


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

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

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


  

The corresponding QEMU command line:

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

Signed-off-by: Lin Ma 
---
 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 12 
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 @@
 
   
   
-
+
 
 
   
@@ -3053,6 +3053,10 @@
 bus and "pci" or "ccw" address types.
 Since 1.2.8 (QEMU 2.1)
   
+  
+The optional queues attribute specifies the number of
+virt queues for virtio-blk. (Since 
3.8.0)
+  
   
   For virtio disks,
   Virtio-specific options 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 @@
   
 
   
+  
+
+  
+
+  
   
   
 
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