Re: [PATCH 5/5] virsh: expose virDomainGetFSInfo

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 09/30/2014 08:20 PM, Tomoki Sekiyama wrote:
> Add a "domfsinfo" command that shows a list of filesystems info mounted in
> the guest.
> 

Perhaps a small example of the command being run and expected output
would be nice.

> Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@xxxxxxx>
> ---
>  tools/virsh-domain.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 70 insertions(+)
> 

You'll need to modify virsh.pod (e.g. man page) in order to complete
this work.  Be sure to note that the guest agent is required - there are
examples within other commands.

> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index ce59406..cc07bc3 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -11999,6 +11999,70 @@ 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"));

s/get filesystems /get domain filesystem /

> +        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, ",");

Theoretically speaking this could be very wide...  You may want to
consider some sort of verbose option which would print all aliases
beyond the first alias found.  Not sure of the best way to handle this
though and whether there are "other" examples.

John

> +                }
> +            }
> +            vshPrint(ctl, "\n");
> +
> +            virDomainFSInfoFree(info[i]);
> +        }
> +        VIR_FREE(info);
> +    }
> +
> + cleanup:
> +    virDomainFree(dom);
> +    return ret >= 0;
> +}
> +
>  const vshCmdDef domManagementCmds[] = {
>      {.name = "attach-device",
>       .handler = cmdAttachDevice,
> @@ -12158,6 +12222,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,
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]