[libvirt] [RFC PATCH 4/5] Enable the virDomainBlockIoThrottle API in virsh

Adam Litke agl at us.ibm.com
Tue Oct 11 15:23:22 UTC 2011


On Mon, Oct 10, 2011 at 09:45:12PM +0800, Lei HH Li wrote:
> 
> Signed-off-by: Zhi Yong Wu <wuzhy at linux.vnet.ibm.com>
> ---
>  tools/virsh.c   |   86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh.pod |   13 ++++++++
>  2 files changed, 99 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 9532bc3..51487b7 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -6019,6 +6019,91 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
>      return true;
>  }
> 
> +/*
> + * "blkiothrottle" command
> + */
> +static const vshCmdInfo info_blkiothrottle[] = {
> +    {"help", N_("Set or display a block disk I/O throttle setting.")},
> +    {"desc", N_("Set or display a block disk I/O throttle setting.")},
> +    {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_blkiothrottle[] = {
> +    {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
> +    {"device", VSH_OT_DATA, VSH_OFLAG_REQ, N_("block device")},
> +    {"bps", VSH_OT_INT, VSH_OFLAG_NONE, N_("total throughput limits in bytes/s")},
> +    {"bps_rd", VSH_OT_INT, VSH_OFLAG_NONE, N_("read throughput limits in bytes/s")},
> +    {"bps_wr", VSH_OT_INT, VSH_OFLAG_NONE, N_("write throughput limits in bytes/s")},
> +    {"iops", VSH_OT_INT, VSH_OFLAG_NONE, N_("total operation limits in numbers/s")},
> +    {"iops_rd", VSH_OT_INT, VSH_OFLAG_NONE, N_("read operation limits in numbers/s")},
> +    {"iops_wr", VSH_OT_INT, VSH_OFLAG_NONE, N_("write operation limits in numbers/s")},
> +    {NULL, 0, 0, NULL}
> +};

This command should also be able to display the current settings.  My suggestion
would be that if none of the settings are named on the command line, the
behavior is to displaty the current settings.  I can see that the command
documentation agrees with me and this is just a TODO.  You should tell us that
in the patch summary :)

> +
> +static bool
> +cmdBlkIoThrottle(vshControl *ctl, const vshCmd *cmd)
> +{
> +    virDomainPtr dom = NULL;
> +    const char *name, *disk;
> +    virDomainBlockIoThrottleInfo info;
> +    virDomainBlockIoThrottleInfo reply;
> +    unsigned int flags = 0;
> +    int ret = -1;
> +
> +    memset(&info, 0, sizeof(info));
> +
> +    if (!vshConnectionUsability(ctl, ctl->conn))
> +        goto out;
> +
> +    if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
> +        goto out;
> +
> +    if (vshCommandOptString(cmd, "device", &disk) < 0)
> +        goto out;
> +
> +    if (vshCommandOptULongLong(cmd, "bps", &info.bps) < 0) {
> +        info.bps = 0;
> +    }
> +
> +    if (vshCommandOptULongLong(cmd, "bps_rd", &info.bps_rd) < 0) {
> +        info.bps_rd = 0;
> +    }
> +
> +    if (vshCommandOptULongLong(cmd, "bps_wr", &info.bps_wr) < 0) {
> +        info.bps_wr = 0;
> +    }
> +
> +    if (vshCommandOptULongLong(cmd, "iops", &info.iops) < 0) {
> +        info.iops = 0;
> +    }
> +
> +    if (vshCommandOptULongLong(cmd, "iops_rd", &info.iops_rd) < 0) {
> +        info.iops_wr = 0;
> +    }
> +
> +    if (vshCommandOptULongLong(cmd, "iops_wr", &info.iops_wr) < 0) {
> +        info.bps_wr = 0;
> +    }
> +
> +    if ((info.bps == 0) && (info.bps_rd == 0) && (info.bps_wr == 0)
> +        && (info.iops == 0) && (info.iops_rd == 0) && (info.iops_wr == 0)) {
> +        flags = 0;
> +    } else {
> +        flags = 1;
> +    }
> +
> +    ret = virDomainBlockIoThrottle(dom, disk, &info, &reply, flags);
> +
> +    if (ret == 0) {
> +        virDomainFree(dom);
> +        return true;
> +    }
> +
> +out:
> +    virDomainFree(dom);
> +    return false;
> +}
> +
> 
>  /*
>   * "net-autostart" command
> @@ -13712,6 +13797,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},
> +    {"blkiothrottle", cmdBlkIoThrottle, opts_blkiothrottle, info_blkiothrottle, 0},
>  #ifndef WIN32
>      {"console", cmdConsole, opts_console, info_console, 0},
>  #endif
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index 1f7c76f..5b52980 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -572,6 +572,19 @@ 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<blkiothrottle> I<domain> I<device> [[I<--bps> B<bps>] | [[I<--bps_rd> B<bps_rd>] [I<--bps_wr> B<bps_wr>]] [[I<--iops> B<iops>] | [[I<--iops_rd> B<iops_rd>] [I<--iops_wr> B<iops_wr>]]
> +
> +Set or display the block disk io limits settting.
> +I<path> specifies block disk name.
> +I<--bps> specifies total throughput limit in bytes/s.
> +I<--bps_rd> specifies read throughput limit in bytes/s.
> +I<--bps_wr> specifies write throughput limit in bytes/s.
> +I<--iops> specifies total operation limit in numbers/s.
> +I<--iops_rd> specifies read operation limit in numbers/s.
> +I<--iops_wr> specifies write operation limit in numbers/s.
> +
> +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
> 

-- 
Adam Litke <agl at us.ibm.com>
IBM Linux Technology Center




More information about the libvir-list mailing list