mirror of https://gitee.com/openkylin/libvirt.git
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: Julio Faracco <jcfaracco@gmail.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
2fdfe0c98e
commit
4b9af8625a
|
@ -396,6 +396,10 @@ static const vshCmdOptDef opts_domblkinfo[] = {
|
|||
.flags = VSH_OFLAG_REQ,
|
||||
.help = N_("block device")
|
||||
},
|
||||
{.name = "human",
|
||||
.type = VSH_OT_BOOL,
|
||||
.help = N_("Human readable output")
|
||||
},
|
||||
{.name = NULL}
|
||||
};
|
||||
|
||||
|
@ -405,6 +409,7 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
|
|||
virDomainBlockInfo info;
|
||||
virDomainPtr dom;
|
||||
bool ret = false;
|
||||
bool human = false;
|
||||
const char *device = NULL;
|
||||
|
||||
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
|
||||
|
@ -416,9 +421,23 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
|
|||
if (virDomainGetBlockInfo(dom, device, &info, 0) < 0)
|
||||
goto cleanup;
|
||||
|
||||
human = vshCommandOptBool(cmd, "human");
|
||||
|
||||
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;
|
||||
|
||||
|
|
|
@ -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 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
|
||||
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
|
||||
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>]
|
||||
|
||||
|
|
Loading…
Reference in New Issue