[PATCH 8/9] virsh: Introduce virshDomainBlockTargetCompleter

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

 



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

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index e3b8234b41..11fe44055d 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -143,6 +143,54 @@ virshDomainInterfaceCompleter(vshControl *ctl,
 }
 
 
+char **
+virshDomainBlockTargetCompleter(vshControl *ctl,
+                                const vshCmd *cmd,
+                                unsigned int flags)
+{
+    virshControlPtr priv = ctl->privData;
+    xmlDocPtr xmldoc = NULL;
+    xmlXPathContextPtr ctxt = NULL;
+    xmlNodePtr *disks = NULL;
+    int ndisks;
+    size_t i;
+    char **ret = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    if (virshDomainGetXML(ctl, cmd, 0, &xmldoc, &ctxt) < 0)
+        goto error;
+
+    ndisks = virXPathNodeSet("./devices/disk", ctxt, &disks);
+    if (ndisks < 0)
+        goto error;
+
+    if (VIR_ALLOC_N(ret, ndisks + 1) < 0)
+        goto error;
+
+    for (i = 0; i < ndisks; i++) {
+        ctxt->node = disks[i];
+        if (!(ret[i] = virXPathString("string(./target/@dev)", ctxt)))
+            goto error;
+    }
+
+    VIR_FREE(disks);
+    xmlFreeDoc(xmldoc);
+    xmlXPathFreeContext(ctxt);
+    return ret;
+
+ error:
+    VIR_FREE(disks);
+    xmlFreeDoc(xmldoc);
+    xmlXPathFreeContext(ctxt);
+    virStringListFree(ret);
+    return NULL;
+}
+
+
 char **
 virshStoragePoolNameCompleter(vshControl *ctl,
                               const vshCmd *cmd ATTRIBUTE_UNUSED,
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index fa443d3ad7..7b830b4ca5 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -38,6 +38,10 @@ char ** virshDomainInterfaceCompleter(vshControl *ctl,
                                       const vshCmd *cmd,
                                       unsigned int flags);
 
+char ** virshDomainBlockTargetCompleter(vshControl *ctl,
+                                        const vshCmd *cmd,
+                                        unsigned int flags);
+
 char ** virshStoragePoolNameCompleter(vshControl *ctl,
                                       const vshCmd *cmd,
                                       unsigned int flags);
-- 
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