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

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

 



Signed-off-by: Lin Ma <lma@xxxxxxxx>
---
 tools/virsh-completer.c | 31 +++++++++++++++++++++++++++++++
 tools/virsh-completer.h |  4 ++++
 tools/virsh-nodedev.c   |  1 +
 3 files changed, 36 insertions(+)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 1fab758e12..162b7a0e1c 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -26,6 +26,7 @@
 #include "virsh-domain.h"
 #include "virsh.h"
 #include "virsh-pool.h"
+#include "virsh-nodedev.h"
 #include "virsh-util.h"
 #include "virsh-secret.h"
 #include "internal.h"
@@ -737,3 +738,33 @@ virshPoolEventNameCompleter(vshControl *ctl,
     virStringListFree(ret);
     return NULL;
 }
+
+
+char **
+virshNodedevEventNameCompleter(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_NODE_DEVICE_EVENT_ID_LAST) < 0)
+        goto error;
+
+    for (i = 0; i < VIR_NODE_DEVICE_EVENT_ID_LAST; i++) {
+        if (VIR_STRDUP(ret[i], vshNodedevEventCallbacks[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 76fa31cb47..1190130ec0 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -89,4 +89,8 @@ char ** virshPoolEventNameCompleter(vshControl *ctl,
                                     const vshCmd *cmd,
                                     unsigned int flags);
 
+char ** virshNodedevEventNameCompleter(vshControl *ctl,
+                                       const vshCmd *cmd,
+                                       unsigned int flags);
+
 #endif
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index 66cf46c22f..f6bdeadd62 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -870,6 +870,7 @@ static const vshCmdOptDef opts_node_device_event[] = {
     },
     {.name = "event",
      .type = VSH_OT_STRING,
+     .completer = virshNodedevEventNameCompleter,
      .help = N_("which event type to wait for")
     },
     {.name = "loop",
-- 
2.16.2

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

  Powered by Linux