提交 2ad38fdb 编写于 作者: E Eric Blake

virsh: additional scaled output units

The parser accepts P and E, so the formatter should too.

* tools/virsh.c (vshPrettyCapacity): Handle larger units.
Signed-off-by: NEric Blake <eblake@redhat.com>
上级 1120c06b
...@@ -151,22 +151,40 @@ vshNameSorter(const void *a, const void *b) ...@@ -151,22 +151,40 @@ vshNameSorter(const void *a, const void *b)
double double
vshPrettyCapacity(unsigned long long val, const char **unit) vshPrettyCapacity(unsigned long long val, const char **unit)
{ {
if (val < 1024) { double limit = 1024;
if (val < limit) {
*unit = "B"; *unit = "B";
return (double)val; return val;
} else if (val < (1024.0l * 1024.0l)) { }
limit *= 1024;
if (val < limit) {
*unit = "KiB"; *unit = "KiB";
return (((double)val / 1024.0l)); return val / (limit / 1024);
} else if (val < (1024.0l * 1024.0l * 1024.0l)) { }
limit *= 1024;
if (val < limit) {
*unit = "MiB"; *unit = "MiB";
return (double)val / (1024.0l * 1024.0l); return val / (limit / 1024);
} else if (val < (1024.0l * 1024.0l * 1024.0l * 1024.0l)) { }
limit *= 1024;
if (val < limit) {
*unit = "GiB"; *unit = "GiB";
return (double)val / (1024.0l * 1024.0l * 1024.0l); return val / (limit / 1024);
} else { }
limit *= 1024;
if (val < limit) {
*unit = "TiB"; *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);
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册