]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: expose virDomainGetFSInfo
authorTomoki Sekiyama <tomoki.sekiyama@hds.com>
Sat, 22 Nov 2014 01:27:52 +0000 (20:27 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 24 Nov 2014 15:29:16 +0000 (10:29 -0500)
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@hds.com>
tools/virsh-domain.c
tools/virsh.pod

index 4f03956e30146e30dddea8db5fdd4c84ba2d8748..750411b826c9ce86ff978625849430d5c2743157 100644 (file)
@@ -12225,6 +12225,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, j;
+    virDomainFSInfoPtr *info;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    ret = virDomainGetFSInfo(dom, &info, 0);
+    if (ret < 0) {
+        vshError(ctl, _("Unable to get filesystem information"));
+        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]->fstype);
+            for (j = 0; j < info[i]->ndevAlias; j++) {
+                vshPrintExtra(ctl, "%s", info[i]->devAlias[j]);
+                if (j != info[i]->ndevAlias - 1)
+                    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,
@@ -12384,6 +12448,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,
index 5a577f631eefc777e7f405f406e066657b983a9d..da9c894690df484297c0d85fcc0dff499027016d 100644 (file)
@@ -1146,6 +1146,15 @@ be selected using the B<type> parameter (e.g. "vnc", "spice", "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