[libvirt] [PATCH 3/4] domain_conf: Add support for iothreads in disk definition

John Ferlan jferlan at redhat.com
Tue Aug 26 00:38:08 UTC 2014


Add a new disk "driver" attribute "iothread" to be parsed as the thread
number for the disk to use. In order to more easily facilitate the usage
and configuration of the iothread, a "zero" for the attribute indicates
iothreads are not supported for the device and a positive value indicates
the specific thread to try and use.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 docs/formatdomain.html.in     |  8 ++++++++
 docs/schemas/domaincommon.rng | 13 +++++++++++++
 src/conf/domain_conf.c        | 24 +++++++++++++++++++++++-
 src/conf/domain_conf.h        |  2 ++
 4 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 0fe10f4..ea0ca83 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -2141,6 +2141,14 @@
             (ignore the discard request).
             <span class='since'>Since 1.0.6 (QEMU and KVM only)</span>
           </li>
+          <li>
+            The optional <code>iothread</code> attribute will assign the
+            disk to an IOThread as defined by the range for the domain
+            <a href="#elementsIOThreadsAllocation"><code>iothreads</code></a>
+            value. Each device must use a unique IOThread and threads will
+            be numbered from 1 to the domain iothreads value.
+            <span class='since'>Since 1.2.8 (QEMU only)</span>
+          </li>
         </ul>
       </dd>
       <dt><code>boot</code></dt>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index b4ac483..40891e4 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1572,6 +1572,9 @@
       <optional>
         <ref name="discard"/>
       </optional>
+      <optional>
+        <ref name="driverIOThread"/>
+      </optional>
       <empty/>
     </element>
   </define>
@@ -1659,6 +1662,11 @@
       </choice>
     </attribute>
   </define>
+  <define name="driverIOThread">
+    <attribute name='iothread'>
+      <ref name="iothreadsid"/>
+    </attribute>
+  </define>
   <define name="controller">
     <element name="controller">
       <attribute name="index">
@@ -4759,6 +4767,11 @@
       <param name="minInclusive">0</param>
     </data>
   </define>
+  <define name="iothreadsid">
+    <data type="unsignedInt">
+      <param name="pattern">[0-9]+</param>
+    </data>
+  </define>
   <define name="vcpuid">
     <data type="unsignedShort">
       <param name="pattern">[0-9]+</param>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 671c41c..b15f279 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5399,6 +5399,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     char *ioeventfd = NULL;
     char *event_idx = NULL;
     char *copy_on_read = NULL;
+    char *driverIOThread = NULL;
     char *devaddr = NULL;
     virStorageEncryptionPtr encryption = NULL;
     char *serial = NULL;
@@ -5547,6 +5548,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
                 event_idx = virXMLPropString(cur, "event_idx");
                 copy_on_read = virXMLPropString(cur, "copy_on_read");
                 discard = virXMLPropString(cur, "discard");
+                driverIOThread = virXMLPropString(cur, "iothread");
             } else if (!def->mirror &&
                        xmlStrEqual(cur->name, BAD_CAST "mirror") &&
                        !(flags & VIR_DOMAIN_XML_INACTIVE)) {
@@ -6080,6 +6082,15 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
         }
     }
 
+    if (driverIOThread) {
+        if (virStrToLong_uip(driverIOThread, NULL, 10, &def->iothread) < 0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("Invalid iothread attribute in disk driver "
+                             "element: %s"), driverIOThread);
+            goto error;
+        }
+    }
+
     if (devaddr) {
         if (virDomainParseLegacyDeviceAddress(devaddr,
                                               &def->info.addr.pci) < 0) {
@@ -6180,6 +6191,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     VIR_FREE(event_idx);
     VIR_FREE(copy_on_read);
     VIR_FREE(discard);
+    VIR_FREE(driverIOThread);
     VIR_FREE(devaddr);
     VIR_FREE(serial);
     virStorageEncryptionFree(encryption);
@@ -11968,6 +11980,14 @@ virDomainDefParseXML(xmlDocPtr xml,
             goto error;
         }
         def->iothreads = count;
+
+        /* Create a bitmap for inuse threads - noting that entries are
+         * numbered 1..def->iothreads since 0 (zero) iothreads means
+         * nothing and assigning a disk to an IOThread requires at least a
+         * thread# > 0 since a zero would indicate no IOThread for the disk
+         */
+        if (!(def->iothreadmap = virBitmapNew(def->iothreads+1)))
+            goto error;
     }
 
     /* Extract cpu tunables. */
@@ -15538,7 +15558,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
     if (def->src->driverName || def->src->format > 0 || def->cachemode ||
         def->error_policy || def->rerror_policy || def->iomode ||
         def->ioeventfd || def->event_idx || def->copy_on_read ||
-        def->discard) {
+        def->discard || def->iothread > 0) {
         virBufferAddLit(buf, "<driver");
         if (def->src->driverName)
             virBufferAsprintf(buf, " name='%s'", def->src->driverName);
@@ -15561,6 +15581,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
             virBufferAsprintf(buf, " copy_on_read='%s'", copy_on_read);
         if (def->discard)
             virBufferAsprintf(buf, " discard='%s'", discard);
+        if (def->iothread > 0)
+            virBufferAsprintf(buf, " iothread='%u'", def->iothread);
         virBufferAddLit(buf, "/>\n");
     }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 705ce32..1bd989d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -667,6 +667,7 @@ struct _virDomainDiskDef {
     int rawio; /* no = 0, yes = 1 */
     int sgio; /* enum virDomainDeviceSGIO */
     int discard; /* enum virDomainDiskDiscard */
+    unsigned int iothread; /* unused = 0, > 0 specific thread # */
 };
 
 
@@ -1909,6 +1910,7 @@ struct _virDomainDef {
     virBitmapPtr cpumask;
 
     unsigned int iothreads;
+    virBitmapPtr iothreadmap;
 
     struct {
         unsigned long shares;
-- 
1.9.3




More information about the libvir-list mailing list