domain: introduce xml elements for throttle blkio cgroup

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_sec>10000</read_iops_sec>
    <write_iops_sec>10000</write_iops_sec>
    <read_bytes_sec>1000000</read_bytes_sec>
    <write_bytes_sec>1000000</write_bytes_sec>
  </device>
</blkiotune>

Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
This commit is contained in:
Gao feng 2013-12-11 16:29:49 +08:00
parent 8eaa25f2d6
commit fb2fbc6d7b
3 changed files with 103 additions and 14 deletions

View File

@ -646,9 +646,31 @@
<element name="path"> <element name="path">
<ref name="absFilePath"/> <ref name="absFilePath"/>
</element> </element>
<element name="weight"> <optional>
<ref name="weight"/> <element name="weight">
</element> <ref name="weight"/>
</element>
</optional>
<optional>
<element name="read_iops_sec">
<data type='unsignedInt'/>
</element>
</optional>
<optional>
<element name="write_iops_sec">
<data type='unsignedInt'/>
</element>
</optional>
<optional>
<element name="read_bytes_sec">
<data type='unsignedLong'/>
</element>
</optional>
<optional>
<element name="write_bytes_sec">
<data type='unsignedLong'/>
</element>
</optional>
</interleave> </interleave>
</element> </element>
</zeroOrMore> </zeroOrMore>

View File

@ -900,15 +900,19 @@ virBlkioDeviceArrayClear(virBlkioDevicePtr devices,
* <device> * <device>
* <path>/fully/qualified/device/path</path> * <path>/fully/qualified/device/path</path>
* <weight>weight</weight> * <weight>weight</weight>
* <read_bytes_sec>bps</read_bytes_sec>
* <write_bytes_sec>bps</write_bytes_sec>
* <read_iops_sec>iops</read_iops_sec>
* <write_iops_sec>iops</write_iops_sec>
* </device> * </device>
* *
* and fills a virBlkioDeviceTune struct. * and fills a virBlkioDevicePtr struct.
*/ */
static int static int
virDomainBlkioDeviceParseXML(xmlNodePtr root, virDomainBlkioDeviceParseXML(xmlNodePtr root,
virBlkioDevicePtr dev) virBlkioDevicePtr dev)
{ {
char *c; char *c = NULL;
xmlNodePtr node; xmlNodePtr node;
node = root->children; node = root->children;
@ -922,9 +926,43 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root,
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not parse weight %s"), _("could not parse weight %s"),
c); c);
VIR_FREE(c); goto error;
VIR_FREE(dev->path); }
return -1; VIR_FREE(c);
} else if (xmlStrEqual(node->name, BAD_CAST "read_bytes_sec")) {
c = (char *)xmlNodeGetContent(node);
if (virStrToLong_ull(c, NULL, 10, &dev->rbps) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not parse read bytes sec %s"),
c);
goto error;
}
VIR_FREE(c);
} else if (xmlStrEqual(node->name, BAD_CAST "write_bytes_sec")) {
c = (char *)xmlNodeGetContent(node);
if (virStrToLong_ull(c, NULL, 10, &dev->wbps) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not parse write bytes sec %s"),
c);
goto error;
}
VIR_FREE(c);
} else if (xmlStrEqual(node->name, BAD_CAST "read_iops_sec")) {
c = (char *)xmlNodeGetContent(node);
if (virStrToLong_ui(c, NULL, 10, &dev->riops) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not parse read iops sec %s"),
c);
goto error;
}
VIR_FREE(c);
} else if (xmlStrEqual(node->name, BAD_CAST "write_iops_sec")) {
c = (char *)xmlNodeGetContent(node);
if (virStrToLong_ui(c, NULL, 10, &dev->wiops) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("could not parse write iops sec %s"),
c);
goto error;
} }
VIR_FREE(c); VIR_FREE(c);
} }
@ -938,6 +976,11 @@ virDomainBlkioDeviceParseXML(xmlNodePtr root,
} }
return 0; return 0;
error:
VIR_FREE(c);
VIR_FREE(dev->path);
return -1;
} }
@ -11180,7 +11223,7 @@ virDomainDefParseXML(xmlDocPtr xml,
if (STREQ(def->blkio.devices[j].path, if (STREQ(def->blkio.devices[j].path,
def->blkio.devices[i].path)) { def->blkio.devices[i].path)) {
virReportError(VIR_ERR_XML_ERROR, virReportError(VIR_ERR_XML_ERROR,
_("duplicate device weight path '%s'"), _("duplicate blkio device path '%s'"),
def->blkio.devices[i].path); def->blkio.devices[i].path);
goto error; goto error;
} }
@ -16758,7 +16801,11 @@ virDomainDefFormatInternal(virDomainDefPtr def,
blkio = true; blkio = true;
} else { } else {
for (n = 0; n < def->blkio.ndevices; n++) { 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; blkio = true;
break; break;
} }
@ -16773,13 +16820,29 @@ virDomainDefFormatInternal(virDomainDefPtr def,
def->blkio.weight); def->blkio.weight);
for (n = 0; n < def->blkio.ndevices; n++) { 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; continue;
virBufferAddLit(buf, " <device>\n"); virBufferAddLit(buf, " <device>\n");
virBufferEscapeString(buf, " <path>%s</path>\n", virBufferEscapeString(buf, " <path>%s</path>\n",
def->blkio.devices[n].path); dev->path);
virBufferAsprintf(buf, " <weight>%u</weight>\n", if (dev->weight)
def->blkio.devices[n].weight); virBufferAsprintf(buf, " <weight>%u</weight>\n",
dev->weight);
if (dev->riops)
virBufferAsprintf(buf, " <read_iops_sec>%u</read_iops_sec>\n",
dev->riops);
if (dev->wiops)
virBufferAsprintf(buf, " <write_iops_sec>%u</write_iops_sec>\n",
dev->wiops);
if (dev->rbps)
virBufferAsprintf(buf, " <read_bytes_sec>%llu</read_bytes_sec>\n",
dev->rbps);
if (dev->wbps)
virBufferAsprintf(buf, " <write_bytes_sec>%llu</write_bytes_sec>\n",
dev->wbps);
virBufferAddLit(buf, " </device>\n"); virBufferAddLit(buf, " </device>\n");
} }

View File

@ -1877,6 +1877,10 @@ typedef virBlkioDevice *virBlkioDevicePtr;
struct _virBlkioDevice { struct _virBlkioDevice {
char *path; char *path;
unsigned int weight; unsigned int weight;
unsigned int riops;
unsigned int wiops;
unsigned long long rbps;
unsigned long long wbps;
}; };
enum virDomainRNGModel { enum virDomainRNGModel {