With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:
virsh blkiotune domain1 --device-read-bytes-sec
/dev/sda1,100,/dev/sda2,200
--device-write-bytes-sec /dev/sda1,100 --device-read-iops-sec
/dev/sda1,1
--device-write-iops-sec /dev/sda1,1,/dev/sda2,0
This patch also add manpage for these new options.
Signed-off-by: Guan Qiang hzguanqi...@corp.netease.com
Signed-off-by: Gao feng gaof...@cn.fujitsu.com
---
include/libvirt/libvirt.h.in | 45 +++
tools/virsh-domain.c | 64
tools/virsh.pod | 36 +++--
3 files changed, 143 insertions(+), 2 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 29d4dce..9ebf3c4 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1806,6 +1806,51 @@ char *
virDomainGetSchedulerType(virDomainPtr domain,
#define VIR_DOMAIN_BLKIO_DEVICE_WEIGHT device_weight
+/**
+ * VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS:
+ *
+ * Macro for the blkio tunable throttle.read_iops_device: it represents
+ * the number of reading the block device per second, as a string. The
+ * string is parsed as a series of /path/to/device, read_iops elements,
+ * separated by ','.
+ */
+
+#define VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS device_read_iops_sec
+
+
+/**
+ * VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS:
+ *
+ * Macro for the blkio tunable throttle.write_iops_device: it represents
+ * the number of writing the block device per second, as a string. The
+ * string is parsed as a series of /path/to/device, write_iops elements,
+ * separated by ','.
+ */
+#define VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS device_write_iops_sec
+
+
+/**
+ * VIR_DOMAIN_BLKIO_DEVICE_READ_BPS:
+ *
+ * Macro for the blkio tunable throttle.read_iops_device: it represents
+ * the bytes of reading the block device per second, as a string. The
+ * string is parsed as a series of /path/to/device, read_bps elements,
+ * separated by ','.
+ */
+#define VIR_DOMAIN_BLKIO_DEVICE_READ_BPS device_read_bytes_sec
+
+
+/**
+ * VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS:
+ *
+ * Macro for the blkio tunable throttle.read_iops_device: it represents
+ * the number of reading the block device per second, as a string. The
+ * string is parsed as a series of /path/to/device, write_bps elements,
+ * separated by ','.
+ */
+#define VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS device_write_bytes_sec
+
+
/* Set Blkio tunables for the domain*/
int virDomainSetBlkioParameters(virDomainPtr domain,
virTypedParameterPtr params,
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 8b80e1e..f7e7959 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -1250,6 +1250,22 @@ static const vshCmdOptDef opts_blkiotune[] = {
.type = VSH_OT_STRING,
.help = N_(per-device IO Weights, in the form of
/path/to/device,weight,...)
},
+{.name = device-read-iops-sec,
+ .type = VSH_OT_STRING,
+ .help = N_(per-device read I/O limit per second, in the form of
/path/to/device,read_iops_sec,...)
+},
+{.name = device-write-iops-sec,
+ .type = VSH_OT_STRING,
+ .help = N_(per-device write I/O limit per second, in the form of
/path/to/device,write_iops_sec,...)
+},
+{.name = device-read-bytes-sec,
+ .type = VSH_OT_STRING,
+ .help = N_(per-device bytes read per second, in the form of
/path/to/device,read_bytes_sec,...)
+},
+{.name = device-write-bytes-sec,
+ .type = VSH_OT_STRING,
+ .help = N_(per-device bytes wrote per second, in the form of
/path/to/device,write_bytes_sec,...)
+},
{.name = config,
.type = VSH_OT_BOOL,
.help = N_(affect next boot)
@@ -1270,6 +1286,10 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
{
virDomainPtr dom;
const char *device_weight = NULL;
+const char *device_riops = NULL;
+const char *device_wiops = NULL;
+const char *device_rbps = NULL;
+const char *device_wbps = NULL;
int weight = 0;
int nparams = 0;
int maxparams = 0;
@@ -1317,6 +1337,50 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
goto save_error;
}
+rv = vshCommandOptString(cmd, device-read-iops-sec, device_riops);
+if (rv 0) {
+vshError(ctl, %s, _(Unable to parse string parameter));
+goto cleanup;
+} else if (rv 0) {
+if (virTypedParamsAddString(params, nparams, maxparams,
+VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS,
+device_riops) 0)
+goto save_error;
+}
+
+rv = vshCommandOptString(cmd, device-write-iops-sec, device_wiops);
+if (rv 0) {
+vshError(ctl, %s, _(Unable to parse string parameter));
+goto cleanup;
+} else if (rv 0) {
+if (virTypedParamsAddString(params, nparams, maxparams,
+