]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh-volume: Introduce virshStorageVolKeyCompleter
authorLin Ma <lma@suse.com>
Wed, 16 Jun 2021 08:02:51 +0000 (16:02 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 16 Jun 2021 08:32:36 +0000 (10:32 +0200)
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-completer-volume.c
tools/virsh-completer-volume.h

index 301ee982a544cb49ea470e6782380c45225a9a85..fcbc28b13b0ccbb70268feb2ba3a8f44930ee305 100644 (file)
@@ -69,3 +69,50 @@ virshStorageVolNameCompleter(vshControl *ctl,
     g_free(vols);
     return ret;
 }
+
+char **
+virshStorageVolKeyCompleter(vshControl *ctl,
+                            const vshCmd *cmd G_GNUC_UNUSED,
+                            unsigned int flags)
+{
+    virshControl *priv = ctl->privData;
+    struct virshStoragePoolList *list = NULL;
+    virStorageVolPtr *vols = NULL;
+    int rc;
+    int nvols = 0;
+    size_t i = 0, j = 0;
+    char **ret = NULL;
+    g_auto(GStrv) tmp = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+        return NULL;
+
+    list = virshStoragePoolListCollect(ctl, VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE);
+    if (!list)
+        goto cleanup;
+
+    for (i = 0; i < list->npools; i++) {
+        if ((rc = virStoragePoolListAllVolumes(list->pools[i], &vols, 0)) < 0)
+            goto cleanup;
+
+        tmp = g_renew(char *, tmp, nvols + rc + 1);
+        memset(&tmp[nvols], 0, sizeof(*tmp) * (rc + 1));
+
+        for (j = 0; j < rc; j++) {
+            const char *key = virStorageVolGetKey(vols[j]);
+            tmp[nvols] = g_strdup(key);
+            nvols++;
+            virStorageVolFree(vols[j]);
+        }
+
+        g_free(vols);
+    }
+
+    ret = g_steal_pointer(&tmp);
+
+ cleanup:
+    virshStoragePoolListFree(list);
+    return ret;
+}
index 6591e13fdffeaf2c49f8ae01aef7ddcfe487f69c..b41d8f4f3eb503fb0837eb16e787e030c8da84a6 100644 (file)
@@ -26,3 +26,8 @@
 char ** virshStorageVolNameCompleter(vshControl *ctl,
                                      const vshCmd *cmd,
                                      unsigned int flags);
+
+
+char ** virshStorageVolKeyCompleter(vshControl *ctl,
+                                    const vshCmd *cmd,
+                                    unsigned int flags);