[PATCHv2] qemu: Add cmd_per_lun, max_sectors to virtio-scsi

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This introduces two new attributes "cmd_per_lun" and "max_sectors" same
with the names QEMU uses for virtio-scsi. An example of the XML:

<controller type='scsi' index='0' model='virtio-scsi' cmd_per_lun='50'
max_sectors='512'/>

The corresponding QEMU command line:

-device virtio-scsi-pci,id=scsi0,cmd_per_lun=50,max_sectors=512,
bus=pci.0,addr=0x3

Signed-off-by: Mike Perez <thingee@xxxxxxxxx>
---
 docs/formatdomain.html.in                          | 29 +++++++++++++++++++---
 docs/schemas/domaincommon.rng                      | 10 ++++++++
 src/conf/domain_conf.c                             | 27 ++++++++++++++++++--
 src/conf/domain_conf.h                             |  2 ++
 src/qemu/qemu_command.c                            | 27 ++++++++++++++++----
 .../qemuxml2argv-disk-virtio-scsi-cmd-per-lun.args |  9 +++++++
 .../qemuxml2argv-disk-virtio-scsi-cmd-per-lun.xml  | 29 ++++++++++++++++++++++
 .../qemuxml2argv-disk-virtio-scsi-max-sectors.args |  9 +++++++
 .../qemuxml2argv-disk-virtio-scsi-max-sectors.xml  | 29 ++++++++++++++++++++++
 tests/qemuxml2argvtest.c                           |  6 +++++
 tests/qemuxml2xmltest.c                            |  2 ++
 11 files changed, 168 insertions(+), 11 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.xml
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.args
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.xml

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 691a451..8d44bc8 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2559,11 +2559,32 @@
 
     <p>
       An optional sub-element <code>driver</code> can specify the driver
-      specific options. Currently it only supports attribute <code>queues</code>
-      (<span class="since">1.0.5</span>, QEMU and KVM only), which specifies the
-      number of queues for the controller. For best performance, it's recommended
-      to specify a value matching the number of vCPUs.
+      specific options:
     </p>
+    <dl>
+      <dt><code>queues</code></dt>
+      <dd>
+        The optional <code>queues</code> attribute specifies the number of
+        queues for the controller. For best performance, it's recommended to
+        specify a value matching the number of vCPUs.
+        <span class="since">Since 1.0.5 (QEMU and KVM only)</span>
+      </dd>
+      <dt><code>cmd-per-lun</code></dt>
+      <dd>
+        The optional <code>cmd-per-lun</code> attribute specifies the maximum
+        number of commands that can be queued on devices controlled by the
+        host.
+        <span class="since">Since 1.2.5 (QEMU and KVM only)</span>
+      </dd>
+      <dt><code>max-sectors</code></dt>
+      <dd>
+        The optional <code>max-sectors</code> attribute specifies the maximum
+        amount of data in bytes that will be transferred to or from the device
+        in a single command. The transfer length is measured in sectors, where
+        a sector is 512 bytes.
+        <span class="since">Since 1.2.5 (QEMU and KVM only)</span>
+      </dd>
+    </dl>
     <p>
       USB companion controllers have an optional
       sub-element <code>&lt;master&gt;</code> to specify the exact
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 4249ed5..d2ed8df 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1735,6 +1735,16 @@
                 <ref name="unsignedInt"/>
               </attribute>
             </optional>
+            <optional>
+              <attribute name="cmd-per-lun">
+                <ref name="unsignedInt"/>
+              </attribute>
+            </optional>
+            <optional>
+              <attribute name="max-sectors">
+                <ref name="unsignedInt"/>
+              </attribute>
+            </optional>
           </element>
         </optional>
       </interleave>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 40c385e..9132463 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6041,6 +6041,8 @@ virDomainControllerDefParseXML(xmlNodePtr node,
     char *idx = NULL;
     char *model = NULL;
     char *queues = NULL;
+    char *cmd_per_lun = NULL;
+    char *max_sectors = NULL;
     xmlNodePtr saved = ctxt->node;
     int rc;
 
@@ -6084,6 +6086,8 @@ virDomainControllerDefParseXML(xmlNodePtr node,
         if (cur->type == XML_ELEMENT_NODE) {
             if (xmlStrEqual(cur->name, BAD_CAST "driver"))
                 queues = virXMLPropString(cur, "queues");
+                cmd_per_lun = virXMLPropString(cur, "cmd-per-lun");
+                max_sectors = virXMLPropString(cur, "max-sectors");
         }
         cur = cur->next;
     }
@@ -6094,6 +6098,17 @@ virDomainControllerDefParseXML(xmlNodePtr node,
         goto error;
     }
 
+    if (cmd_per_lun && virStrToLong_ui(cmd_per_lun, NULL, 10, &def->cmd_per_lun) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Malformed 'cmd-per-lun' value '%s'"), cmd_per_lun);
+        goto error;
+    }
+
+    if (max_sectors && virStrToLong_ui(max_sectors, NULL, 10, &def->max_sectors) < 0) {
+        virReportError(VIR_ERR_XML_ERROR,
+                       _("Malformed 'max-sectors' value %s'"), max_sectors);
+    }
+
     if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
         goto error;
 
@@ -6201,6 +6216,8 @@ virDomainControllerDefParseXML(xmlNodePtr node,
     VIR_FREE(idx);
     VIR_FREE(model);
     VIR_FREE(queues);
+    VIR_FREE(cmd_per_lun);
+    VIR_FREE(max_sectors);
 
     return def;
 
@@ -15279,13 +15296,19 @@ virDomainControllerDefFormat(virBufferPtr buf,
         break;
     }
 
-    if (def->queues || virDomainDeviceInfoIsSet(&def->info, flags) ||
-        pcihole64) {
+    if (def->queues || def->cmd_per_lun || def->max_sectors ||
+        virDomainDeviceInfoIsSet(&def->info, flags) || pcihole64) {
         virBufferAddLit(buf, ">\n");
         virBufferAdjustIndent(buf, 2);
         if (def->queues)
             virBufferAsprintf(buf, "<driver queues='%u'/>\n", def->queues);
 
+        if (def->cmd_per_lun)
+            virBufferAsprintf(buf, "<driver cmd-per-lun='%u'/>\n", def->cmd_per_lun);
+
+        if (def->max_sectors)
+            virBufferAsprintf(buf, "<driver max-sectors='%u'/>\n", def->max_sectors);
+
         if (virDomainDeviceInfoIsSet(&def->info, flags) &&
             virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
             return -1;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index bde303c..66484a1 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -720,6 +720,8 @@ struct _virDomainControllerDef {
     unsigned int idx;
     int model; /* -1 == undef */
     unsigned int queues;
+    unsigned int cmd_per_lun;
+    unsigned int max_sectors;
     union {
         virDomainVirtioSerialOpts vioserial;
         virDomainPCIControllerOpts pciopts;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 193959f..da4543b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -4236,12 +4236,23 @@ qemuBuildControllerDevStr(virDomainDefPtr domainDef,
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     int model;
 
-    if (def->queues &&
-        !(def->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI &&
+    if (!(def->type == VIR_DOMAIN_CONTROLLER_TYPE_SCSI &&
           def->model == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_VIRTIO_SCSI)) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("'queues' is only supported by virtio-scsi controller"));
-        return NULL;
+        if (def->queues) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("'queues' is only supported by virtio-scsi controller"));
+            return NULL;
+        }
+        if (def->cmd_per_lun) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("'cmd-per-lun' is only supported by virtio-scsi controller"));
+            return NULL;
+        }
+        if (def->max_sectors) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("'max-sectors' is only supported by virtio-scsi controller"));
+            return NULL;
+        }
     }
 
     switch (def->type) {
@@ -4369,6 +4380,12 @@ qemuBuildControllerDevStr(virDomainDefPtr domainDef,
     if (def->queues)
         virBufferAsprintf(&buf, ",num_queues=%u", def->queues);
 
+    if (def->cmd_per_lun)
+        virBufferAsprintf(&buf, ",cmd_per_lun=%u", def->cmd_per_lun);
+
+    if (def->max_sectors)
+        virBufferAsprintf(&buf, ",max_sectors=%u", def->max_sectors);
+
     if (qemuBuildDeviceAddressStr(&buf, domainDef, &def->info, qemuCaps) < 0)
         goto error;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.args
new file mode 100644
index 0000000..2c75790
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.args
@@ -0,0 +1,9 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu -S -M pc -m 214 -smp 8 -nographic -nodefconfig -nodefaults \
+-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \
+-device virtio-scsi-pci,id=scsi0,cmd_per_lun=50,bus=pci.0,addr=0x3 \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-scsi0-0-0-0 \
+-device scsi-disk,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\
+drive=drive-scsi0-0-0-0,id=scsi0-0-0-0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.xml
new file mode 100644
index 0000000..e35603a
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-cmd-per-lun.xml
@@ -0,0 +1,29 @@
+<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'>8</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</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='sdb' bus='scsi'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='scsi' index='0' model='virtio-scsi'>
+      <driver cmd-per-lun='50'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.args
new file mode 100644
index 0000000..895f379
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.args
@@ -0,0 +1,9 @@
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
+/usr/bin/qemu -S -M pc -m 214 -smp 8 -nographic -nodefconfig -nodefaults \
+-monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot c \
+-device virtio-scsi-pci,id=scsi0,max_sectors=512,bus=pci.0,addr=0x3 \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest1,if=none,id=drive-scsi0-0-0-0 \
+-device scsi-disk,bus=scsi0.0,channel=0,scsi-id=0,lun=0,\
+drive=drive-scsi0-0-0-0,id=scsi0-0-0-0 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.xml
new file mode 100644
index 0000000..0ad94fc
--- /dev/null
+++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-max-sectors.xml
@@ -0,0 +1,29 @@
+<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'>8</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</emulator>
+    <disk type='block' device='disk'>
+      <source dev='/dev/HostVG/QEMUGuest1'/>
+      <target dev='sdb' bus='scsi'/>
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+    </disk>
+    <controller type='usb' index='0'/>
+    <controller type='scsi' index='0' model='virtio-scsi'>
+      <driver max-sectors='512'/>
+    </controller>
+    <controller type='pci' index='0' model='pci-root'/>
+    <memballoon model='virtio'/>
+  </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 1ea7bf8..6f4e14b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -807,6 +807,12 @@ mymain(void)
     DO_TEST("disk-virtio-scsi-num_queues",
             QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_VIRTIO_SCSI);
+    DO_TEST("disk-virtio-scsi-cmd-per-lun",
+            QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_VIRTIO_SCSI);
+    DO_TEST("disk-virtio-scsi-max-sectors",
+            QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
+            QEMU_CAPS_VIRTIO_SCSI);
     DO_TEST("disk-scsi-megasas",
             QEMU_CAPS_DRIVE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,
             QEMU_CAPS_SCSI_MEGASAS);
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index da528da..a17e432 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -223,6 +223,8 @@ mymain(void)
     DO_TEST("disk-scsi-vscsi");
     DO_TEST("disk-scsi-virtio-scsi");
     DO_TEST("disk-virtio-scsi-num_queues");
+    DO_TEST("disk-virtio-scsi-cmd-per-lun");
+    DO_TEST("disk-virtio-scsi-max-sectors");
     DO_TEST("disk-scsi-megasas");
     DO_TEST_FULL("disk-mirror", false, WHEN_ACTIVE);
     DO_TEST_FULL("disk-mirror", true, WHEN_INACTIVE);
-- 
1.9.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]