On Thu, Oct 27, 2011 at 05:20:09PM +0800, Lei HH Li wrote: > > Signed-off-by: Zhi Yong Wu <wuzhy@xxxxxxxxxxxxxxxxxx> > Signed-off-by: Lei Li <lilei@xxxxxxxxxxxxxxxxxx> > --- > tools/virsh.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ > tools/virsh.pod | 13 +++++++ > 2 files changed, 112 insertions(+), 0 deletions(-) > > diff --git a/tools/virsh.c b/tools/virsh.c > index 72344f0..de86c40 100644 > --- a/tools/virsh.c > +++ b/tools/virsh.c > @@ -6023,6 +6023,104 @@ 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} > +}; > + > +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)) { What if I want to set one of these values to zero (ie. erase a current limit)? Won't this mistakenly just print out the current settings? I think you'll need a bit more sophistication here. > + > + ret = virDomainGetBlockIoThrottle(dom, disk, &reply, flags); > + > + if (ret != 0) > + goto out; > + > + vshPrint(ctl, "%-15s %llu\n", _("bps:"), reply.bps); > + vshPrint(ctl, "%-15s %llu\n", _("bps_rd:"), reply.bps_rd); > + vshPrint(ctl, "%-15s %llu\n", _("bps_wr:"), reply.bps_wr); > + vshPrint(ctl, "%-15s %llu\n", _("iops:"), reply.iops); > + vshPrint(ctl, "%-15s %llu\n", _("iops_rd:"), reply.iops_rd); > + vshPrint(ctl, "%-15s %llu\n", _("iops_wr:"), reply.iops_wr); > + > + virDomainFree(dom); > + return true; > + } else { > + flags = 1; > + > + ret = virDomainSetBlockIoThrottle(dom, disk, &info, flags); > + > + if (ret == 0) { > + virDomainFree(dom); > + return true; > + } > + } > + > +out: > + virDomainFree(dom); > + return false; > +} > > /* > * "net-autostart" command > @@ -14017,6 +14115,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 775d302..61ec613 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@xxxxxxxxxx> IBM Linux Technology Center -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list