Re: [PATCH 5/8] Enable the blkdeviotune command in virsh

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

 



OK.

On Thu, Nov 10, 2011 at 04:32:55AM +0800, Lei HH Li wrote:
> Support virsh command blkdeviotune. Can set or query a block disk 
> I/O throttle setting.
> 
> Signed-off-by: Zhi Yong Wu <wuzhy@xxxxxxxxxxxxxxxxxx>
> Signed-off-by: Lei Li <lilei@xxxxxxxxxxxxxxxxxx>
> ---
>  tools/virsh.c   |  146 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh.pod |   23 +++++++++
>  2 files changed, 169 insertions(+), 0 deletions(-)
> 
> diff --git a/tools/virsh.c b/tools/virsh.c
> index 83dc3c7..df2b399 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -6023,6 +6023,151 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
>      return true;
>  }
> 
> +/*
> + * "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/s")},
> +    {"read_bytes_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("read throughput limit in bytes per second/s")},
> +    {"write_bytes_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("write throughput limit in bytes per second/s")},
> +    {"total_iops_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("total I/O operations limit per second/s")},
> +    {"read_iops_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("read I/O operations limit per second/s")},
> +    {"write_iops_sec", VSH_OT_INT, VSH_OFLAG_NONE, N_("write I/O operations limit per second/s")},
> +    {"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;
> +    virDomainBlockIoTuneInfo info;
> +    virDomainBlockIoTuneInfo reply;
> +    unsigned int flags = 0;
> +    int ret = -1;
> +    int rv = 0;
> +    int set = 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;
> +    }
> +
> +    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 ((rv = vshCommandOptULongLong(cmd, "total_bytes_sec", &info.total_bytes_sec)) < 0) {
> +        vshError(ctl, "%s",
> +                 _("Unable to parse integer parameter"));
> +        goto out;
> +    } else if (rv > 0) {
> +        set++;
> +    }
> +
> +    if ((rv = vshCommandOptULongLong(cmd, "read_bytes_sec", &info.read_bytes_sec)) < 0) {
> +        vshError(ctl, "%s",
> +                 _("Unable to parse integer parameter"));
> +        goto out;
> +    } else if (rv > 0) {
> +        set++;
> +    }
> +
> +    if ((rv = vshCommandOptULongLong(cmd, "write_bytes_sec", &info.write_bytes_sec)) < 0) {
> +        vshError(ctl, "%s",
> +                 _("Unable to parse integer parameter"));
> +        goto out;
> +    } else if (rv > 0) {
> +        set++;
> +    }
> +
> +    if ((rv = vshCommandOptULongLong(cmd, "total_iops_sec", &info.total_iops_sec)) < 0) {
> +        vshError(ctl, "%s",
> +                 _("Unable to parse integer parameter"));
> +        goto out;
> +    } else if (rv > 0) {
> +        set++;
> +    }
> +
> +    if ((rv = vshCommandOptULongLong(cmd, "read_iops_sec", &info.read_iops_sec)) < 0) {
> +        vshError(ctl, "%s",
> +                 _("Unable to parse integer parameter"));
> +        goto out;
> +    } else if (rv > 0) {
> +        set++;
> +    }
> +
> +    if ((rv = vshCommandOptULongLong(cmd, "write_iops_sec", &info.write_iops_sec)) < 0) {
> +        vshError(ctl, "%s",
> +                 _("Unable to parse integer parameter"));
> +        goto out;
> +    } else if (rv > 0) {
> +        set++;
> +    }
> +
> +    if (!set) {
> +
> +        ret = virDomainGetBlockIoTune(dom, disk, &reply, flags);
> +
> +        if (ret != 0)
> +            goto out;
> +
> +        vshPrint(ctl, "%-15s %llu\n", _("total_bytes_sec:"), reply.total_bytes_sec);
> +        vshPrint(ctl, "%-15s %llu\n", _("read_bytes_sec:"), reply.read_bytes_sec);
> +        vshPrint(ctl, "%-15s %llu\n", _("write_bytes_sec:"), reply.write_bytes_sec);
> +        vshPrint(ctl, "%-15s %llu\n", _("total_iops_sec:"), reply.total_iops_sec);
> +        vshPrint(ctl, "%-15s %llu\n", _("read_iops_sec:"), reply.read_iops_sec);
> +        vshPrint(ctl, "%-15s %llu\n", _("write_iops_sec:"), reply.write_iops_sec);
> +
> +        virDomainFree(dom);
> +        return true;
> +    } else {
> +
> +        ret = virDomainSetBlockIoTune(dom, disk, &info, flags);
> +
> +        if (ret == 0) {
> +            virDomainFree(dom);
> +            return true;
> +        }
> +    }
> +
> +out:
> +    virDomainFree(dom);
> +    return false;
> +}
> +
> 
>  /*
>   * "net-autostart" command
> @@ -14023,6 +14168,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..58fcb51 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/s.
> +I<--read_bytes_sec> specifies read throughput limit in bytes per second/s.
> +I<--write_bytes_sec> specifies write throughput limit in bytes per second/s.
> +I<--total_iops_sec> specifies total I/O operations limit per second/s.
> +I<--read_iops_sec> specifies read I/O operations limit per second/s.
> +I<--write_iops_sec> specifies write I/O operations limit per second/s.
> +
> +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
> 

-- 
Adam Litke <agl@xxxxxxxxxx>
IBM Linux Technology Center

--
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]