[libvirt] [ [PATCH v3 6/8] virsh: Add event name completion to 'pool-event' command

Lin Ma lma at suse.com
Wed May 23 06:32:44 UTC 2018


Signed-off-by: Lin Ma <lma at suse.com>
---
 tools/virsh-completer.c | 30 ++++++++++++++++++++++++++++++
 tools/virsh-completer.h |  4 ++++
 tools/virsh-pool.c      |  1 +
 3 files changed, 35 insertions(+)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index c0c3c5571a..1fab758e12 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -707,3 +707,33 @@ virshEventNameCompleter(vshControl *ctl,
     virStringListFree(ret);
     return NULL;
 }
+
+
+char **
+virshPoolEventNameCompleter(vshControl *ctl,
+                            const vshCmd *cmd ATTRIBUTE_UNUSED,
+                            unsigned int flags)
+{
+    virshControlPtr priv = ctl->privData;
+    size_t i = 0;
+    char **ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(ret, VIR_STORAGE_POOL_EVENT_ID_LAST) < 0)
+        goto error;
+
+    for (i = 0; i < VIR_STORAGE_POOL_EVENT_ID_LAST; i++) {
+        if (VIR_STRDUP(ret[i], vshPoolEventCallbacks[i].name) < 0)
+            goto error;
+    }
+
+    return ret;
+
+ error:
+    virStringListFree(ret);
+    return NULL;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index 9f8dc3dfa8..76fa31cb47 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -85,4 +85,8 @@ char ** virshSecretEventNameCompleter(vshControl *ctl,
                                       const vshCmd *cmd,
                                       unsigned int flags);
 
+char ** virshPoolEventNameCompleter(vshControl *ctl,
+                                    const vshCmd *cmd,
+                                    unsigned int flags);
+
 #endif
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index f0544d2e2d..5f59e35894 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -2098,6 +2098,7 @@ static const vshCmdOptDef opts_pool_event[] = {
     },
     {.name = "event",
      .type = VSH_OT_STRING,
+     .completer = virshPoolEventNameCompleter,
      .help = N_("which event type to wait for")
     },
     {.name = "loop",
-- 
2.16.2




More information about the libvir-list mailing list