[libvirt] [PATCH v3 2/4] cmdDomblkinfo: add --all to show all block devices info

John Ferlan jferlan at redhat.com
Thu Jun 21 21:37:03 UTC 2018



On 06/19/2018 06:01 AM, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao at 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
> 
> Target     Capacity        Allocation      Physical
> ---------------------------------------------------
> hda        40.000 GiB      9.200 GiB       9.200 GiB
> vda        10.000 GiB      9.999 GiB       10.000 GiB
> 
> Signed-off-by: Chen Hanxiao <chenhanxiao at gmail.com>
> ---
> v3:
>   check error code on network disk
> v2:
>   add support --human to --all
> v1.1:
>   fix self-test
> 
>  tools/virsh-domain-monitor.c | 128 +++++++++++++++++++++++++++++------
>  tools/virsh.pod              |   5 +-
>  2 files changed, 112 insertions(+), 21 deletions(-)
> 

Made a few adjustments as noted below... and will push shortly.

Reviewed-by: John Ferlan <jferlan at redhat.com>

John

> diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
> index daa86e8310..43e39f79c1 100644
> --- a/tools/virsh-domain-monitor.c
> +++ b/tools/virsh-domain-monitor.c

[...]

>  
>  static bool
> @@ -430,25 +466,77 @@ cmdDomblkinfo(vshControl *ctl, const vshCmd *cmd)
>      virDomainPtr dom;
>      bool ret = false;
>      bool human = false;

[...]

> +
> +        for (i = 0; i < ndisks; i++) {
> +            ctxt->node = disks[i];
> +            protocol = virXPathString("string(./source/@protocol)", ctxt);
> +            target = virXPathString("string(./target/@dev)", ctxt);
> +
> +            rc = virDomainGetBlockInfo(dom, target, &info, 0);
> +
> +            if (rc < 0) {

Added the following comment:

    /* If protocol is present that's an indication of a networked
     * storage device which cannot provide statistics, so generate
     * 0 based data and get the next disk. */

> +                if (protocol && !active &&
> +                    virGetLastErrorCode() == VIR_ERR_INTERNAL_ERROR &&
> +                    virGetLastErrorDomain() == VIR_FROM_STORAGE)
> +                    memset(&info, 0, sizeof(info));

Since we're ditching the error and continuing:

    vshResetLibvirtError();

> +                else
> +                    goto cleanup;
> +            }
> +
> +            cmdDomblkinfoPrint(ctl, &info, target, human, false);
> +
> +            VIR_FREE(target);

Since we're in the loop:

    VIR_FREE(protocol);

> +        }
> +    } else {
> +        if (virDomainGetBlockInfo(dom, device, &info, 0) < 0)
> +            goto cleanup;
> +
> +        cmdDomblkinfoPrint(ctl, &info, NULL, human, false);
> +    }
>  
>      ret = true;
[...]




More information about the libvir-list mailing list