提交 4b9af862 编写于 作者: J Julio Faracco 提交者: Michal Privoznik

virsh-domain-monitor: add human readable output for 'domblkinfo'.

https://bugzilla.redhat.com/show_bug.cgi?id=1330940

The virsh command 'domblkinfo' returns the capacity, allocation and phisycal
size of the devices attached in a domain. Usually, this sizes are very big
and hard to understand and calculate. This commits introduce a human readable
support to check the size of each field easilly.

For example, the command before:

virsh # domblkinfo my_domain hda
Capacity:       21474836480
Allocation:     14875545600
Physical:       21474836480

and after this patch:

virsh # domblkinfo my_domain hda --human
Capacity:       20.000G
Allocation:     13.900G
Physical:       20.000G
Signed-off-by: NJulio Faracco <jcfaracco@gmail.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 2fdfe0c9
...@@ -396,6 +396,10 @@ static const vshCmdOptDef opts_domblkinfo[] = { ...@@ -396,6 +396,10 @@ static const vshCmdOptDef opts_domblkinfo[] = {
.flags = VSH_OFLAG_REQ, .flags = VSH_OFLAG_REQ,
.help = N_("block device") .help = N_("block device")
}, },
{.name = "human",
.type = VSH_OT_BOOL,
.help = N_("Human readable output")
},
{.name = NULL} {.name = NULL}
}; };
...@@ -405,6 +409,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -405,6 +409,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
virDomainBlockInfo info; virDomainBlockInfo info;
virDomainPtr dom; virDomainPtr dom;
bool ret = false; bool ret = false;
bool human = false;
const char *device = NULL; const char *device = NULL;
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
...@@ -416,9 +421,23 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -416,9 +421,23 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
if (virDomainGetBlockInfo(dom, device, &info, 0) < 0) if (virDomainGetBlockInfo(dom, device, &info, 0) < 0)
goto cleanup; goto cleanup;
vshPrint(ctl, "%-15s %llu\n", _("Capacity:"), info.capacity); human = vshCommandOptBool(cmd, "human");
vshPrint(ctl, "%-15s %llu\n", _("Allocation:"), info.allocation);
vshPrint(ctl, "%-15s %llu\n", _("Physical:"), info.physical); if (!human) {
vshPrint(ctl, "%-15s %llu\n", _("Capacity:"), info.capacity);
vshPrint(ctl, "%-15s %llu\n", _("Allocation:"), info.allocation);
vshPrint(ctl, "%-15s %llu\n", _("Physical:"), info.physical);
} else {
double val;
const char *unit;
val = vshPrettyCapacity(info.capacity, &unit);
vshPrint(ctl, "%-15s %-.3lf %s\n", _("Capacity:"), val, unit);
val = vshPrettyCapacity(info.allocation, &unit);
vshPrint(ctl, "%-15s %-.3lf %s\n", _("Allocation:"), val, unit);
val = vshPrettyCapacity(info.physical, &unit);
vshPrint(ctl, "%-15s %-.3lf %s\n", _("Physical:"), val, unit);
}
ret = true; ret = true;
......
...@@ -841,12 +841,13 @@ B<domstate> command says that a domain was paused due to I/O error. ...@@ -841,12 +841,13 @@ B<domstate> command says that a domain was paused due to I/O error.
The B<domblkerror> command lists all block devices in error state and The B<domblkerror> command lists all block devices in error state and
the error seen on each of them. the error seen on each of them.
=item B<domblkinfo> I<domain> I<block-device> =item B<domblkinfo> I<domain> I<block-device> [I<--human>]
Get block device size info for a domain. A I<block-device> corresponds Get block device size info for a domain. A I<block-device> corresponds
to a unique target name (<target dev='name'/>) or source file (<source to a unique target name (<target dev='name'/>) or source file (<source
file='name'/>) for one of the disk devices attached to I<domain> (see file='name'/>) for one of the disk devices attached to I<domain> (see
also B<domblklist> for listing these names). also B<domblklist> for listing these names). If I<--human> is set, the
output will have a human readable output.
=item B<domblklist> I<domain> [I<--inactive>] [I<--details>] =item B<domblklist> I<domain> [I<--inactive>] [I<--details>]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册