[libvirt] [PATCH v1] domain_conf: add the support for disk I/O throttle setting

Zhi Yong Wu wuzhy at linux.vnet.ibm.com
Wed Sep 7 10:38:56 UTC 2011


The first patch is only used to see if it is suitable for exteeding blkiotune to implement disk I/O throttling.
As you have known, when blkiotune is issued without options, it will display current tuning parameters; If we exceed it, without options, what should it display? both info will? or should one new option be added to separately display them?

Signed-off-by: Zhi Yong Wu <wuzhy at linux.vnet.ibm.com>
---
 src/conf/domain_conf.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/conf/domain_conf.h |   11 +++++++
 2 files changed, 79 insertions(+), 2 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index cce9955..d9108fa 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2225,6 +2225,7 @@ cleanup:
 static virDomainDiskDefPtr
 virDomainDiskDefParseXML(virCapsPtr caps,
                          xmlNodePtr node,
+                         xmlXPathContextPtr ctxt,
                          virBitmapPtr bootMap,
                          unsigned int flags)
 {
@@ -2266,7 +2267,9 @@ virDomainDiskDefParseXML(virCapsPtr caps,
     }
 
     cur = node->children;
+    xmlNodePtr oldnode = ctxt->node;
     while (cur != NULL) {
+        ctxt->node = cur;
         if (cur->type == XML_ELEMENT_NODE) {
             if ((source == NULL && hosts == NULL) &&
                 (xmlStrEqual(cur->name, BAD_CAST "source"))) {
@@ -2362,6 +2365,36 @@ virDomainDiskDefParseXML(virCapsPtr caps,
                 iotag = virXMLPropString(cur, "io");
                 ioeventfd = virXMLPropString(cur, "ioeventfd");
                 event_idx = virXMLPropString(cur, "event_idx");
+            } else if (xmlStrEqual(cur->name, BAD_CAST "blkiothrottle")) {
+                if (virXPathULongLong("string(./blkiothrottle/bps)", ctxt,
+                    &def->blkiothrottle.bps) < 0) {
+                    def->blkiothrottle.bps = 0;
+                }
+
+                if (virXPathULongLong("string(./blkiothrottle/bps_rd)", ctxt,
+                    &def->blkiothrottle.bps_rd) < 0) {
+                    def->blkiothrottle.bps_rd = 0;
+                }
+
+                if (virXPathULongLong("string(./blkiothrottle/bps_wr)", ctxt,
+                    &def->blkiothrottle.bps_wr) < 0) {
+                    def->blkiothrottle.bps_wr = 0;
+                }
+
+                if (virXPathULongLong("string(./blkiothrottle/iops)", ctxt,
+                    &def->blkiothrottle.iops) < 0) {
+                    def->blkiothrottle.iops = 0;
+                }
+
+                if (virXPathULongLong("string(./blkiothrottle/iops_rd)", ctxt,
+                    &def->blkiothrottle.iops_rd) < 0) {
+                    def->blkiothrottle.iops_rd = 0;
+                }
+
+                if (virXPathULongLong("string(./blkiothrottle/iops_wr)", ctxt,
+                    &def->blkiothrottle.iops_wr) < 0) {
+                    def->blkiothrottle.iops_wr = 0;
+                }
             } else if (xmlStrEqual(cur->name, BAD_CAST "readonly")) {
                 def->readonly = 1;
             } else if (xmlStrEqual(cur->name, BAD_CAST "shareable")) {
@@ -2387,6 +2420,7 @@ virDomainDiskDefParseXML(virCapsPtr caps,
         }
         cur = cur->next;
     }
+    ctxt->node = oldnode;
 
     device = virXMLPropString(node, "device");
     if (device) {
@@ -5684,9 +5718,13 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
 
     if (xmlStrEqual(node->name, BAD_CAST "disk")) {
         dev->type = VIR_DOMAIN_DEVICE_DISK;
-        if (!(dev->data.disk = virDomainDiskDefParseXML(caps, node,
-                                                        NULL, flags)))
+        xmlNodePtr oldnode = ctxt->node;
+        if (!(dev->data.disk = virDomainDiskDefParseXML(caps, node, ctxt,
+                                                        NULL, flags))) {
+            ctxt->node = oldnode;
             goto error;
+        }
+        ctxt->node = oldnode;
     } else if (xmlStrEqual(node->name, BAD_CAST "lease")) {
         dev->type = VIR_DOMAIN_DEVICE_LEASE;
         if (!(dev->data.lease = virDomainLeaseDefParseXML(node)))
@@ -6725,11 +6763,16 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     }
     if (n && VIR_ALLOC_N(def->disks, n) < 0)
         goto no_memory;
+
+    xmlNodePtr oldnode = ctxt->node;
     for (i = 0 ; i < n ; i++) {
+        ctxt->node = nodes[i];
         virDomainDiskDefPtr disk = virDomainDiskDefParseXML(caps,
                                                             nodes[i],
+                                                            ctxt,
                                                             bootMap,
                                                             flags);
+        ctxt->node = oldnode;
         if (!disk)
             goto error;
 
@@ -9065,6 +9108,29 @@ virDomainDiskDefFormat(virBufferPtr buf,
     virBufferAsprintf(buf, "      <target dev='%s' bus='%s'/>\n",
                       def->dst, bus);
 
+    /*disk I/O throttling*/
+    if (def->blkio.blkiothrottle.bps
+        || def->blkio.blkiothrottle.bps_rd
+        || def->blkio.blkiothrottle.bps_wr
+        || def->blkio.blkiothrottle.iops
+        || def->blkio.blkiothrottle.iops_rd
+        || def->blkio.blkiothrottle.iops_wr) {
+        virBufferAsprintf(&buf, "  <blkiothrottle>\n");
+        virBufferAsprintf(&buf, "    <bps>%llu</bps>\n",
+                          def->blkiothrottle.bps);
+        virBufferAsprintf(&buf, "    <bps_rd>%llu</bps_rd>\n",
+                          def->blkiothrottle.bps_rd);
+        virBufferAsprintf(&buf, "    <bps_wr>%llu</bps_wr>\n",
+                          def->blkiothrottle.bps_wr);
+        virBufferAsprintf(&buf, "    <iops>%llu</iops>\n",
+                          def->blkiothrottle.iops);
+        virBufferAsprintf(&buf, "    <iops_rd>%llu</iops_rd>\n",
+                          def->blkiothrottle.iops_rd);
+        virBufferAsprintf(&buf, "    <iops_wr>%llu</iops_wr>\n",
+                          def->blkiothrottle.iops_wr);
+        virBufferAsprintf(&buf, "  </blkiothrottle>\n");
+    }
+
     if (def->bootIndex)
         virBufferAsprintf(buf, "      <boot order='%d'/>\n", def->bootIndex);
     if (def->readonly)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e218a30..5902377 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -258,6 +258,17 @@ struct _virDomainDiskDef {
     virDomainDiskHostDefPtr hosts;
     char *driverName;
     char *driverType;
+
+    /*disk I/O throttling*/
+    struct {
+        unsigned long long bps;
+        unsigned long long bps_rd;
+        unsigned long long bps_wr;
+        unsigned long long iops;
+        unsigned long long iops_rd;
+        unsigned long long iops_wr;
+    } blkiothrottle;
+
     char *serial;
     int cachemode;
     int error_policy;
-- 
1.7.6




More information about the libvir-list mailing list