[PATCH 4/9] domain: introduce xml elements for throttle blkio cgroup

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

 



This patch introduces new xml elements under <blkiotune>,
we use these new elements to setup the throttle blkio
cgroup for domain. The new blkiotune node looks like this:

<blkiotune>
  <device>
    <path>/path/to/block</path>
    <weight>1000</weight>
    <read_iops>10000</read_iops>
    <write_iops>10000</write_iops>
    <read_bps>10000</read_bps>
    <write_bps>10000</write_bps>
  </device>
</blkiotune>

Signed-off-by: Guan Qiang <hzguanqiang@xxxxxxxxxxxxxxxx>
Signed-off-by: Gao feng <gaofeng@xxxxxxxxxxxxxx>
---
 docs/schemas/domaincommon.rng | 28 +++++++++++++--
 src/conf/domain_conf.c        | 83 +++++++++++++++++++++++++++++++++++++------
 src/conf/domain_conf.h        |  4 +++
 3 files changed, 102 insertions(+), 13 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 80848d2..e3e4766 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -621,9 +621,31 @@
               <element name="path">
                 <ref name="absFilePath"/>
               </element>
-              <element name="weight">
-                <ref name="weight"/>
-              </element>
+              <optional>
+                <element name="weight">
+                  <ref name="weight"/>
+                </element>
+              </optional>
+              <optional>
+                <element name="read_iops">
+                  <data type='unsignedInt'/>
+                </element>
+              </optional>
+              <optional>
+                <element name="write_iops">
+                  <data type='unsignedInt'/>
+                </element>
+              </optional>
+              <optional>
+                <element name="read_bps">
+                  <data type='unsignedLong'/>
+                </element>
+              </optional>
+              <optional>
+                <element name="write_bps">
+                  <data type='unsignedLong'/>
+                </element>
+              </optional>
             </interleave>
           </element>
         </zeroOrMore>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 98754e5..9bcc14f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -899,6 +899,10 @@ virBlkioDeviceArrayClear(virBlkioDevicePtr devices,
  *   <device>
  *     <path>/fully/qualified/device/path</path>
  *     <weight>weight</weight>
+ *     <read_bps>bps</read_bps>
+ *     <read_iops>iops</read_iops>
+ *     <write_bps>bps</write_bps>
+ *     <write_iops>iops</write_iops>
  *   </device>
  *
  * and fills a virBlkioDeviceTune struct.
@@ -907,7 +911,7 @@ static int
 virDomainBlkioDeviceParseXML(xmlNodePtr root,
                              virBlkioDevicePtr dev)
 {
-    char *c;
+    char *c = NULL;
     xmlNodePtr node;
 
     node = root->children;
@@ -921,9 +925,43 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root,
                     virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                                    _("could not parse weight %s"),
                                    c);
-                    VIR_FREE(c);
-                    VIR_FREE(dev->path);
-                    return -1;
+                        goto error;
+                }
+                VIR_FREE(c);
+            } else if (xmlStrEqual(node->name, BAD_CAST "read_bps")) {
+                c = (char *)xmlNodeGetContent(node);
+                if (virStrToLong_ull(c, NULL, 10, &dev->rbps) < 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("could not parse read bps %s"),
+                                   c);
+                    goto error;
+                }
+                VIR_FREE(c);
+            } else if (xmlStrEqual(node->name, BAD_CAST "write_bps")) {
+                c = (char *)xmlNodeGetContent(node);
+                if (virStrToLong_ull(c, NULL, 10, &dev->wbps) < 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("could not parse write bps %s"),
+                                   c);
+                    goto error;
+                }
+                VIR_FREE(c);
+            } else if (xmlStrEqual(node->name, BAD_CAST "read_iops")) {
+                c = (char *)xmlNodeGetContent(node);
+                if (virStrToLong_ui(c, NULL, 10, &dev->riops) < 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("could not parse read iops %s"),
+                                   c);
+                    goto error;
+                }
+                VIR_FREE(c);
+            } else if (xmlStrEqual(node->name, BAD_CAST "write_iops")) {
+                c = (char *)xmlNodeGetContent(node);
+                if (virStrToLong_ui(c, NULL, 10, &dev->wiops) < 0) {
+                    virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                                   _("could not parse write iops %s"),
+                                   c);
+                    goto error;
                 }
                 VIR_FREE(c);
             }
@@ -937,6 +975,11 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root,
     }
 
     return 0;
+
+error:
+    VIR_FREE(c);
+    VIR_FREE(dev->path);
+    return -1;
 }
 
 
@@ -11045,7 +11088,7 @@ virDomainDefParseXML(xmlDocPtr xml,
             if (STREQ(def->blkio.devices[j].path,
                       def->blkio.devices[i].path)) {
                 virReportError(VIR_ERR_XML_ERROR,
-                               _("duplicate device weight path '%s'"),
+                               _("duplicate blkio device path '%s'"),
                                def->blkio.devices[i].path);
                 goto error;
             }
@@ -16524,7 +16567,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         blkio = true;
     } else {
         for (n = 0; n < def->blkio.ndevices; n++) {
-            if (def->blkio.devices[n].weight) {
+            if (def->blkio.devices[n].weight ||
+                def->blkio.devices[n].riops ||
+                def->blkio.devices[n].wiops ||
+                def->blkio.devices[n].rbps ||
+                def->blkio.devices[n].wbps) {
                 blkio = true;
                 break;
             }
@@ -16539,13 +16586,29 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                               def->blkio.weight);
 
         for (n = 0; n < def->blkio.ndevices; n++) {
-            if (def->blkio.devices[n].weight == 0)
+            virBlkioDevicePtr dev = &def->blkio.devices[n];
+
+            if (!dev->weight && !dev->riops && !dev->wiops &&
+                !dev->rbps && !dev->wbps)
                 continue;
             virBufferAddLit(buf, "    <device>\n");
             virBufferEscapeString(buf, "      <path>%s</path>\n",
-                                  def->blkio.devices[n].path);
-            virBufferAsprintf(buf, "      <weight>%u</weight>\n",
-                              def->blkio.devices[n].weight);
+                                  dev->path);
+            if (dev->weight)
+                virBufferAsprintf(buf, "      <weight>%u</weight>\n",
+                                  dev->weight);
+            if (dev->riops)
+                virBufferAsprintf(buf, "      <read_iops>%u</read_iops>\n",
+                                  dev->riops);
+            if (dev->wiops)
+                virBufferAsprintf(buf, "      <write_iops>%u</write_iops>\n",
+                                  dev->wiops);
+            if (dev->rbps)
+                virBufferAsprintf(buf, "      <read_bps>%llu</read_bps>\n",
+                                  dev->rbps);
+            if (dev->wbps)
+                virBufferAsprintf(buf, "      <write_bps>%llu</write_bps>\n",
+                                  dev->wbps);
             virBufferAddLit(buf, "    </device>\n");
         }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c53084c..ac8e314 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1864,6 +1864,10 @@ typedef virBlkioDevice *virBlkioDevicePtr;
 struct _virBlkioDevice {
     char *path;
     unsigned int weight;
+    unsigned int riops;
+    unsigned int wiops;
+    unsigned long long rbps;
+    unsigned long long wbps;
 };
 
 enum virDomainRNGModel {
-- 
1.8.3.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]