[libvirt] [PATCH v2 5/5] virsh: expose virDomainGetFSInfo

John Ferlan jferlan at redhat.com
Wed Nov 19 22:52:22 UTC 2014



On 11/17/2014 06:27 PM, Tomoki Sekiyama wrote:
> Add a "domfsinfo" command that shows a list of filesystems info mounted in
> the guest. For example:
> 
> virsh # domfsinfo vm1
> Mountpoint                           Name     Type     Target
> -------------------------------------------------------------------
> /                                    sda1     ext4     hdc
> /opt                                 dm-2     vfat     vda,vdb
> /mnt/test                            sdb1     xfs      sda
> 
> Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama at hds.com>
> ---
>  tools/virsh-domain.c |   74 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  tools/virsh.pod      |    9 ++++++
>  2 files changed, 83 insertions(+)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index a7e9151..ab8ebab 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -12120,6 +12120,74 @@ cmdDomFSThaw(vshControl *ctl, const vshCmd *cmd)
>      return ret >= 0;
>  }
>  
> +static const vshCmdInfo info_domfsinfo[] = {
> +    {.name = "help",
> +     .data = N_("Get information of domain's mounted filesystems.")
> +    },
> +    {.name = "desc",
> +     .data = N_("Get information of domain's mounted filesystems.")
> +    },
> +    {.name = NULL}
> +};
> +
> +static const vshCmdOptDef opts_domfsinfo[] = {
> +    {.name = "domain",
> +     .type = VSH_OT_DATA,
> +     .flags = VSH_OFLAG_REQ,
> +     .help = N_("domain name, id or uuid")
> +    },
> +    {.name = NULL}
> +};
> +
> +static bool
> +cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd)
> +{
> +    virDomainPtr dom = NULL;
> +    int ret = -1;
> +    size_t i;
> +    virDomainFSInfoPtr *info;
> +    char **alias;
> +
> +    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
> +        return false;
> +
> +    ret = virDomainGetFSInfo(dom, &info, 0);
> +    if (ret < 0) {
> +        vshError(ctl, _("Unable to get filesystems information"));

You missed the "get domain filesystem", but I see you're mostly
following other examples.  So I'll just change this to:

"Unable to get filesystem information"

I could have gone with "filesystem(s)", but just didn't read correctly

> +        goto cleanup;
> +    }
> +    if (ret == 0) {
> +        vshError(ctl, _("No filesystems are mounted in the domain"));
> +        goto cleanup;
> +    }
> +
> +    if (info) {
> +        vshPrintExtra(ctl, "%-36s %-8s %-8s %s\n",
> +                      _("Mountpoint"), _("Name"), _("Type"), _("Target"));
> +        vshPrintExtra(ctl, "-------------------------------------------------------------------\n");
> +        for (i = 0; i < ret; i++) {
> +            vshPrintExtra(ctl, "%-36s %-8s %-8s ",
> +                          info[i]->mountpoint, info[i]->name, info[i]->type);
> +            alias = info[i]->devAlias;
> +            if (alias) {
> +                while (*alias) {
> +                    vshPrintExtra(ctl, "%s", *alias++);
> +                    if (*alias)
> +                        vshPrint(ctl, ",");
> +                }
> +            }
> +            vshPrint(ctl, "\n");
> +
> +            virDomainFSInfoFree(info[i]);
> +        }
> +        VIR_FREE(info);
> +    }
> +
> + cleanup:
> +    virDomainFree(dom);
> +    return ret >= 0;
> +}
> +
>  const vshCmdDef domManagementCmds[] = {
>      {.name = "attach-device",
>       .handler = cmdAttachDevice,
> @@ -12279,6 +12347,12 @@ const vshCmdDef domManagementCmds[] = {
>       .info = info_domfsthaw,
>       .flags = 0
>      },
> +    {.name = "domfsinfo",
> +     .handler = cmdDomFSInfo,
> +     .opts = opts_domfsinfo,
> +     .info = info_domfsinfo,
> +     .flags = 0
> +    },
>      {.name = "domfstrim",
>       .handler = cmdDomFSTrim,
>       .opts = opts_domfstrim,
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index d5608cc..de8f2c3 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -1144,6 +1144,15 @@ Output a URI which can be used to connect to the graphical display of the
>  domain via VNC, SPICE or RDP. If I<--include-password> is specified, the
>  SPICE channel password will be included in the URI.
>  
> +=item B<domfsinfo> I<domain>
> +
> +Show a list of mounted filesystems within the running domain. The list contains
> +mountpoints, names of a mounted device in the guest, filesystem types, and
> +unique target names used in the domain XML (<target dev='name'/>).
> +
> +Note that this command requires a guest agent configured and running in the
> +domain's guest OS.
> +
>  =item B<domfsfreeze> I<domain> [[I<--mountpoint>] B<mountpoint>...]
>  
>  Freeze mounted filesystems within a running domain to prepare for consistent
> 




More information about the libvir-list mailing list