]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: additional scaled output units
authorEric Blake <eblake@redhat.com>
Tue, 9 Sep 2014 04:09:53 +0000 (22:09 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 9 Sep 2014 14:19:02 +0000 (08:19 -0600)
The parser accepts P and E, so the formatter should too.

* tools/virsh.c (vshPrettyCapacity): Handle larger units.

Signed-off-by: Eric Blake <eblake@redhat.com>
tools/virsh.c

index 9706acc88ed6333b605e79a824372063e4e60d41..64195a40db47a4ed6f25fd66f473ceb14b1862e2 100644 (file)
@@ -151,22 +151,40 @@ vshNameSorter(const void *a, const void *b)
 double
 vshPrettyCapacity(unsigned long long val, const char **unit)
 {
-    if (val < 1024) {
+    double limit = 1024;
+
+    if (val < limit) {
         *unit = "B";
-        return (double)val;
-    } else if (val < (1024.0l * 1024.0l)) {
+        return val;
+    }
+    limit *= 1024;
+    if (val < limit) {
         *unit = "KiB";
-        return (((double)val / 1024.0l));
-    } else if (val < (1024.0l * 1024.0l * 1024.0l)) {
+        return val / (limit / 1024);
+    }
+    limit *= 1024;
+    if (val < limit) {
         *unit = "MiB";
-        return (double)val / (1024.0l * 1024.0l);
-    } else if (val < (1024.0l * 1024.0l * 1024.0l * 1024.0l)) {
+        return val / (limit / 1024);
+    }
+    limit *= 1024;
+    if (val < limit) {
         *unit = "GiB";
-        return (double)val / (1024.0l * 1024.0l * 1024.0l);
-    } else {
+        return val / (limit / 1024);
+    }
+    limit *= 1024;
+    if (val < limit) {
         *unit = "TiB";
-        return (double)val / (1024.0l * 1024.0l * 1024.0l * 1024.0l);
+        return val / (limit / 1024);
+    }
+    limit *= 1024;
+    if (val < limit) {
+        *unit = "PiB";
+        return val / (limit / 1024);
     }
+    limit *= 1024;
+    *unit = "EiB";
+    return val / (limit / 1024);
 }
 
 /*