[PATCH 5/8] virsh: block job: Support --bytes and scaled integers when setting speed

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

 



Allow specifying sizes in bytes or as scaled integers for user
convenience.
---
 tools/virsh-domain.c | 31 ++++++++++++++++++++++++-------
 tools/virsh.pod      | 10 +++++++---
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0d0e39e..fef3918 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2541,16 +2541,35 @@ static bool
 vshBlockJobSetSpeed(vshControl *ctl,
                     const vshCmd *cmd,
                     virDomainPtr dom,
-                    const char *path)
+                    const char *path,
+                    bool bytes)
 {
     unsigned long bandwidth;
+    unsigned long long bw;
+    unsigned int flags = 0;
+
+    if (bytes)
+        flags |= VIR_DOMAIN_BLOCK_JOB_SPEED_BANDWIDTH_BYTES;

     if (vshCommandOptULWrap(cmd, "bandwidth", &bandwidth) < 0) {
-        vshError(ctl, "%s", _("bandwidth must be a number"));
-        return false;
+        /* try to parse the number as scaled size */
+        if (vshCommandOptScaledInt(cmd, "bandwidth", &bw, 1, ULLONG_MAX) < 0) {
+            vshError(ctl, "%s", _("bandwidth must be a number"));
+            return false;
+        }
+
+        if (!bytes)
+            bw /= 1024 * 1024;
+
+        if (bw > ULONG_MAX) {
+            vshError(ctl, _("bandwidth must be less than %lu"), ULONG_MAX);
+            return false;
+        }
+
+        bandwidth = bw;
     }

-    if (virDomainBlockJobSetSpeed(dom, path, bandwidth, 0) < 0)
+    if (virDomainBlockJobSetSpeed(dom, path, bandwidth, flags) < 0)
         return false;

     return true;
@@ -2584,8 +2603,6 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
     VSH_EXCLUSIVE_OPTIONS_VAR(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 (abort || pivot || async)
         return blockJobImpl(ctl, cmd, VSH_CMD_BLOCK_JOB_ABORT, NULL);
@@ -2598,7 +2615,7 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;

     if (bandwidth)
-        ret = vshBlockJobSetSpeed(ctl, cmd, dom, path);
+        ret = vshBlockJobSetSpeed(ctl, cmd, dom, path, bytes);
     else
         ret = vshBlockJobInfo(ctl, dom, path, raw, bytes);

diff --git a/tools/virsh.pod b/tools/virsh.pod
index f576fb0..85743c6 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1151,10 +1151,14 @@ 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. Note that the
+I<--bytes> may be unsupported by the hypervisor.

 =item B<blockresize> I<domain> I<path> I<size>

-- 
2.3.5

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