]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: blockjob: Support --bytes and scaled integers as bandwidth
authorPeter Krempa <pkrempa@redhat.com>
Tue, 29 Mar 2016 13:52:10 +0000 (15:52 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 29 Mar 2016 13:52:10 +0000 (15:52 +0200)
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

tools/virsh-domain.c
tools/virsh.pod

index cecab63b381d7592d928f80a2d0ae0bf16c74638..c24710231e41144de3600056a82b260c207f84ce 100644 (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
index 95951993ad0dd96308248911654a52986eb42c92..eb4e14775258883af88e89e64088af31c170415b 100644 (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>