
At 2018-06-09 04:49:08, "John Ferlan" <jferlan@redhat.com> wrote:
On 06/07/2018 12:19 AM, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@gmail.com>
This patch introduces --all to show all block devices info of guests like:
virsh # domblkinfo w08 --all Target Capacity Allocation Physical --------------------------------------------------- hda 42949672960 9878110208 9878110208 vda 10737418240 10736439296 10737418240
You don't handle the --pretty at all.
Will do in v2.
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com> ---
...
+ vshPrint(ctl, "%-15s %-.3lf %s\n", _("Physical:"), val, unit);
Maybe you should create/insert a patch which "first just" moves the printing to a separate method such as :
static void cmdDomblkinfoPrint(vshControl *ctl, const virDomainBlockInfo *info, bool human)
Passing
cmdDomblkinfoPrint(ctl, &info, human);
Then when adding the "all" functionality, the printing does get a bit trickier, but it's not impossible to figure out. Look at the volume list details code for some ideas... The real "problem" lies in the length of the data and trying to figure an optimal sizes to create the formatting string so that everything looks good. Consider small sizes and larger sizes in the output. When printing pretty - you won't have something like "1000.000 MiB" because that'd be "1.000 GiB". At the very least you'd have:
1.000 GiB 1.000 GiB 1.000 GiB
and at the very most you'd have
999.000 MiB 999.000 MiB 999.000 MiB
right? So make everything line up from that knowledge.
We can use virAsprintf to combine val and unit together. As the longest len(999.000 MiB) = 12, so %-15s will be enough. Thanks for your comments. V2 will come soon. Regards, - Chen