[PATCH 1/2] virsh: Add mountpoint completion to domfsfreeze/domfsthaw command

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

 



Signed-off-by: Lin Ma <lma@xxxxxxxx>
---
 tools/virsh-completer-domain.c | 43 ++++++++++++++++++++++++++++++++++
 tools/virsh-completer-domain.h |  4 ++++
 tools/virsh-domain.c           |  2 ++
 3 files changed, 49 insertions(+)

diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 99b36a2f9f..f56dc40125 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -872,3 +872,46 @@ virshKeycodeNameCompleter(vshControl *ctl,
 
     return g_steal_pointer(&tmp);
 }
+
+
+char **
+virshDomainFSMountpointsCompleter(vshControl *ctl,
+                                  const vshCmd *cmd,
+                                  unsigned int flags)
+{
+    g_auto(GStrv) tmp = NULL;
+    virDomainPtr dom = NULL;
+    int rc = -1;
+    size_t i;
+    virDomainFSInfoPtr *info = NULL;
+    size_t ninfos = 0;
+    char **ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        return NULL;
+
+    rc = virDomainGetFSInfo(dom, &info, 0);
+    if (rc <= 0) {
+        goto cleanup;
+    }
+    ninfos = rc;
+
+    if (info) {
+        tmp = g_new0(char *, ninfos + 1);
+        for (i = 0; i < ninfos; i++) {
+            tmp[i] = g_strdup(info[i]->mountpoint);
+        }
+        ret = g_steal_pointer(&tmp);
+    }
+
+ cleanup:
+    if (info) {
+        for (i = 0; i < ninfos; i++)
+            virDomainFSInfoFree(info[i]);
+        VIR_FREE(info);
+    }
+    virshDomainFree(dom);
+    return ret;
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index 04a3705ff9..ef242d0c68 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -118,3 +118,7 @@ char ** virshCodesetNameCompleter(vshControl *ctl,
 char ** virshKeycodeNameCompleter(vshControl *ctl,
                                   const vshCmd *cmd,
                                   unsigned int flags);
+
+char ** virshDomainFSMountpointsCompleter(vshControl *ctl,
+                                          const vshCmd *cmd,
+                                          unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index fac590fbc6..9d315bdbcf 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13920,6 +13920,7 @@ static const vshCmdOptDef opts_domfsfreeze[] = {
     VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
     {.name = "mountpoint",
      .type = VSH_OT_ARGV,
+     .completer = virshDomainFSMountpointsCompleter,
      .help = N_("mountpoint path to be frozen")
     },
     {.name = NULL}
@@ -13969,6 +13970,7 @@ static const vshCmdOptDef opts_domfsthaw[] = {
     VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
     {.name = "mountpoint",
      .type = VSH_OT_ARGV,
+     .completer = virshDomainFSMountpointsCompleter,
      .help = N_("mountpoint path to be thawed")
     },
     {.name = NULL}
-- 
2.26.2





[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]

  Powered by Linux