virsh: blockjob: Support --bytes and scaled integers as bandwidth

Use vshBlockJobOptionBandwidth to parse the bandwidth value which will
allow users to specify bandwidth in bytes or as a scaled integer.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1288000
This commit is contained in:
Peter Krempa 2016-03-29 15:52:10 +02:00
parent d18e78c246
commit e54b5484c9
2 changed files with 18 additions and 10 deletions

View File

@ -2492,7 +2492,7 @@ static const vshCmdOptDef opts_block_job[] = {
},
{.name = "bytes",
.type = VSH_OT_BOOL,
.help = N_("with --info, get bandwidth in bytes rather than MiB/s")
.help = N_("get/set bandwidth in bytes rather than MiB/s")
},
{.name = "raw",
.type = VSH_OT_BOOL,
@ -2611,14 +2611,19 @@ static bool
virshBlockJobSetSpeed(vshControl *ctl,
const vshCmd *cmd,
virDomainPtr dom,
const char *path)
const char *path,
bool bytes)
{
unsigned long bandwidth;
unsigned int flags = 0;
if (vshCommandOptULWrap(ctl, cmd, "bandwidth", &bandwidth) < 0)
if (bytes)
flags |= VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES;
if (vshBlockJobOptionBandwidth(ctl, cmd, bytes, &bandwidth) < 0)
return false;
if (virDomainBlockJobSetSpeed(dom, path, bandwidth, 0) < 0)
if (virDomainBlockJobSetSpeed(dom, path, bandwidth, flags) < 0)
return false;
return true;
@ -2672,8 +2677,6 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
VSH_EXCLUSIVE_OPTIONS("bytes", "abort");
VSH_EXCLUSIVE_OPTIONS_VAR(bytes, pivot);
VSH_EXCLUSIVE_OPTIONS_VAR(bytes, async);
/* XXX also support --bytes with bandwidth mode */
VSH_EXCLUSIVE_OPTIONS_VAR(bytes, bandwidth);
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
goto cleanup;
@ -2683,7 +2686,7 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
if (bandwidth)
ret = virshBlockJobSetSpeed(ctl, cmd, dom, path);
ret = virshBlockJobSetSpeed(ctl, cmd, dom, path, bytes);
else if (abortMode || pivot || async)
ret = virshBlockJobAbort(dom, path, pivot, async);
else

View File

@ -1155,10 +1155,15 @@ not supply bytes/s resolution; when omitting the flag, raw output is
listed in MiB/s and human-readable output automatically selects the
best resolution supported by the server.
I<bandwidth> can be used to set bandwidth limit for the active job.
Specifying a negative value is interpreted as an unsigned long long
I<bandwidth> can be used to set bandwidth limit for the active job in MiB/s.
If I<--bytes> is specified then the bandwidth value is interpreted in
bytes/s. Specifying a negative value is interpreted as an unsigned long
value or essentially unlimited. The hypervisor can choose whether to
reject the value or convert it to the maximum value allowed.
reject the value or convert it to the maximum value allowed. Optionally a
scaled positive number may be used as bandwidth (see B<NOTES> above). Using
I<--bytes> with a scaled value allows to use finer granularity. A scaled value
used without I<--bytes> will be rounded down to MiB/s. Note that the
I<--bytes> may be unsupported by the hypervisor.
=item B<blockresize> I<domain> I<path> I<size>