Support virsh command blkdeviotune. Can set or query a block disk I/O throttle setting. Signed-off-by: Lei Li <lilei@xxxxxxxxxxxxxxxxxx> Signed-off-by: Zhi Yong Wu <wuzhy@xxxxxxxxxxxxxxxxxx> --- tools/virsh.c | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/virsh.pod | 23 +++++ 2 files changed, 263 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 83dc3c7..9eec68e 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -6074,6 +6074,245 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd) } /* + * "blkdeviotune" command + */ +static const vshCmdInfo info_blkdeviotune[] = { + {"help", N_("Set or query a block disk I/O throttle setting.")}, + {"desc", N_("Set or query a block disk I/O throttle setting.\n" \ + " To query the block disk I/O throttle setting use the following" \ + " command: \n\n" \ + " virsh # blkdeviotune <domain> <device>")}, + {NULL, NULL} +}; + +static const vshCmdOptDef opts_blkdeviotune[] = { + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, + {"device", VSH_OT_DATA, VSH_OFLAG_REQ, N_("block device")}, + {"total_bytes_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("total throughput limit in bytes per second")}, + {"read_bytes_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("read throughput limit in bytes per second")}, + {"write_bytes_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("write throughput limit in bytes per second")}, + {"total_iops_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("total I/O operations limit per second")}, + {"read_iops_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("read I/O operations limit per second")}, + {"write_iops_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("write I/O operations limit per second")}, + {"config", VSH_OT_BOOL, 0, N_("affect next boot")}, + {"live", VSH_OT_BOOL, 0, N_("affect running domain")}, + {"current", VSH_OT_BOOL, 0, N_("affect current domain")}, + {NULL, 0, 0, NULL} +}; + +static bool +cmdBlkdeviotune(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom = NULL; + const char *name, *disk; + unsigned long long total_bytes_sec = 0, read_bytes_sec = 0, write_bytes_sec = 0; + unsigned long long total_iops_sec = 0, read_iops_sec = 0, write_iops_sec = 0; + int nparams = 0; + virTypedParameterPtr params = NULL, temp = NULL; + unsigned int flags = 0, i = 0; + int rv = 0; + int current = vshCommandOptBool(cmd, "current"); + int config = vshCommandOptBool(cmd, "config"); + int live = vshCommandOptBool(cmd, "live"); + + if (current) { + if (live || config) { + vshError(ctl, "%s", _("--current must be specified exclusively")); + return false; + } + flags = VIR_DOMAIN_AFFECT_CURRENT; + } else { + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + } + + if (!vshConnectionUsability(ctl, ctl->conn)) + goto out; + + if (!(dom = vshCommandOptDomain(ctl, cmd, &name))) + goto out; + + if (vshCommandOptString(cmd, "device", &disk) < 0) + goto out; + + if ((rv = vshCommandOptULongLong(cmd, "total_bytes_sec", &total_bytes_sec)) < 0) { + vshError(ctl, "%s", + _("Unable to parse integer parameter")); + goto out; + } else if (rv > 0) { + nparams++; + } + + if ((rv = vshCommandOptULongLong(cmd, "read_bytes_sec", &read_bytes_sec)) < 0) { + vshError(ctl, "%s", + _("Unable to parse integer parameter")); + goto out; + } else if (rv > 0) { + nparams++; + } + + if ((rv = vshCommandOptULongLong(cmd, "write_bytes_sec", &write_bytes_sec)) < 0) { + vshError(ctl, "%s", + _("Unable to parse integer parameter")); + goto out; + } else if (rv > 0) { + nparams++; + } + + if ((rv = vshCommandOptULongLong(cmd, "total_iops_sec", &total_iops_sec)) < 0) { + vshError(ctl, "%s", + _("Unable to parse integer parameter")); + goto out; + } else if (rv > 0) { + nparams++; + } + + if ((rv = vshCommandOptULongLong(cmd, "read_iops_sec", &read_iops_sec)) < 0) { + vshError(ctl, "%s", + _("Unable to parse integer parameter")); + goto out; + } else if (rv > 0) { + nparams++; + } + + if ((rv = vshCommandOptULongLong(cmd, "write_iops_sec", &write_iops_sec)) < 0) { + vshError(ctl, "%s", + _("Unable to parse integer parameter")); + goto out; + } else if (rv > 0) { + nparams++; + } + + if (nparams == 0) { + + if ((virDomainGetBlockIoTune(dom, disk, NULL, &nparams, flags)) != 0) { + vshError(ctl, "%s", + _("Unable to get number of block I/O throttle parameters")); + goto out; + } + + if (nparams == 0) { + virDomainFree(dom); + return true; + } + + params = vshCalloc(ctl, nparams, sizeof(*params)); + + if ((virDomainGetBlockIoTune(dom, disk, params, &nparams, flags)) != 0) { + vshError(ctl, "%s", + _("Unable to get block I/O throttle parameters")); + goto out; + } + + for (i = 0; i < nparams; i++) { + switch(params[i].type) { + case VIR_TYPED_PARAM_INT: + vshPrint(ctl, "%-15s: %d\n", params[i].field, + params[i].value.i); + break; + case VIR_TYPED_PARAM_UINT: + vshPrint(ctl, "%-15s: %u\n", params[i].field, + params[i].value.ui); + break; + case VIR_TYPED_PARAM_LLONG: + vshPrint(ctl, "%-15s: %lld\n", params[i].field, + params[i].value.l); + break; + case VIR_TYPED_PARAM_ULLONG: + vshPrint(ctl, "%-15s: %llu\n", params[i].field, + params[i].value.ul); + break; + case VIR_TYPED_PARAM_DOUBLE: + vshPrint(ctl, "%-15s: %f\n", params[i].field, + params[i].value.d); + break; + case VIR_TYPED_PARAM_BOOLEAN: + vshPrint(ctl, "%-15s: %d\n", params[i].field, + params[i].value.b); + break; + default: + vshPrint(ctl, "unimplemented block I/O throttle parameter type\n"); + } + } + + virDomainFree(dom); + return true; + } else { + /* Set the block I/O throttle, match by opt since parameters can be 0 */ + params = vshCalloc(ctl, nparams, sizeof(*params)); + i = 0; + + if ((i < nparams) && (vshCommandOptBool(cmd, "total_bytes_sec"))) { + temp = ¶ms[i]; + temp->type = VIR_TYPED_PARAM_ULLONG; + strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_BYTES_SEC, + sizeof(temp->field)); + temp->value.ul = total_bytes_sec; + i++; + } + + if ((i < nparams) && (vshCommandOptBool(cmd, "read_bytes_sec"))) { + temp = ¶ms[i]; + temp->type = VIR_TYPED_PARAM_ULLONG; + strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_READ_BYTES_SEC, + sizeof(temp->field)); + temp->value.ul = read_bytes_sec; + i++; + } + + if ((i < nparams) && (vshCommandOptBool(cmd, "write_bytes_sec"))) { + temp = ¶ms[i]; + temp->type = VIR_TYPED_PARAM_ULLONG; + strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_BYTES_SEC, + sizeof(temp->field)); + temp->value.ul = write_bytes_sec; + i++; + } + + if ((i < nparams) && (vshCommandOptBool(cmd, "total_iops_sec"))) { + temp = ¶ms[i]; + temp->type = VIR_TYPED_PARAM_ULLONG; + strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_TOTAL_IOPS_SEC, + sizeof(temp->field)); + temp->value.ul = total_iops_sec; + i++; + } + + if ((i < nparams) && (vshCommandOptBool(cmd, "read_iops_sec"))) { + temp = ¶ms[i]; + temp->type = VIR_TYPED_PARAM_ULLONG; + strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_READ_IOPS_SEC, + sizeof(temp->field)); + temp->value.ul = read_iops_sec; + i++; + } + + if ((i < nparams) && (vshCommandOptBool(cmd, "write_iops_sec"))) { + temp = ¶ms[i]; + temp->type = VIR_TYPED_PARAM_ULLONG; + strncpy(temp->field, VIR_DOMAIN_BLOCK_IOTUNE_WRITE_IOPS_SEC, + sizeof(temp->field)); + temp->value.ul = write_iops_sec; + } + + if ((virDomainSetBlockIoTune(dom, disk, params, nparams, flags)) != 0) { + vshError(ctl, "%s", + _("Unable to change block I/O throttle")); + goto out; + } else { + virDomainFree(dom); + return true; + } + } + +out: + virDomainFree(dom); + return false; +} + +/* * "net-create" command */ static const vshCmdInfo info_network_create[] = { @@ -14023,6 +14262,7 @@ static const vshCmdDef domManagementCmds[] = { {"blkiotune", cmdBlkiotune, opts_blkiotune, info_blkiotune, 0}, {"blockpull", cmdBlockPull, opts_block_pull, info_block_pull, 0}, {"blockjob", cmdBlockJob, opts_block_job, info_block_job, 0}, + {"blkdeviotune", cmdBlkdeviotune, opts_blkdeviotune, info_blkdeviotune, 0}, #ifndef WIN32 {"console", cmdConsole, opts_console, info_console, 0}, #endif diff --git a/tools/virsh.pod b/tools/virsh.pod index 775d302..fedb8b1 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -572,6 +572,29 @@ operation can be checked with B<blockjob>. I<path> specifies fully-qualified path of the disk. I<bandwidth> specifies copying bandwidth limit in Mbps. +=item B<blkdeviotune> I<domain> I<device> [[I<--total_bytes_sec> B<total_bytes_sec>] +| [[I<--read_bytes_sec> B<read_bytes_sec>] [I<--write_bytes_sec> B<write_bytes_sec>]] +[[I<--total_iops_sec> B<total_iops_sec>] | [[I<--read_iops_sec> B<read_iops_sec>] +[I<--write_iops_sec> B<write_iops_sec>]] [[I<--config>] [I<--live>] | [I<--current>]] + +Set or query the block disk io limits settting. +I<path> specifies block disk name. +I<--total_bytes_sec> specifies total throughput limit in bytes per second. +I<--read_bytes_sec> specifies read throughput limit in bytes per second. +I<--write_bytes_sec> specifies write throughput limit in bytes per second. +I<--total_iops_sec> specifies total I/O operations limit per second. +I<--read_iops_sec> specifies read I/O operations limit per second. +I<--write_iops_sec> specifies write I/O operations limit per second. + +If I<--live> is specified, affect a running guest. +If I<--config> is specified, affect the next boot of a persistent guest. +If I<--current> is specified, affect the current guest state. +Both I<--live> and I<--current> flags may be given, but I<--current> is +exclusive. If no flag is specified, behavior is different depending +on hypervisor. + +If no limit is specified, it will query current I/O limits setting. + =item B<blockjob> I<domain> I<path> [I<--abort>] [I<--info>] [I<bandwidth>] Manage active block operations. -- 1.7.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list