[PATCH] virsh: Provide completer for vol-wipe algorithms

Haonan Wang hnwanga1 at gmail.com
Thu Mar 10 13:40:50 UTC 2022


Related issue: https://gitlab.com/libvirt/libvirt/-/issues/9

Signed-off-by: Haonan Wang <hnwanga1 at gmail.com>
---
 tools/virsh-completer-volume.c | 20 ++++++++++++++++++++
 tools/virsh-completer-volume.h |  6 ++++++
 tools/virsh-volume.c           |  3 +--
 tools/virsh-volume.h           |  3 +++
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-completer-volume.c b/tools/virsh-completer-volume.c
index ac3c472177..66b8828702 100644
--- a/tools/virsh-completer-volume.c
+++ b/tools/virsh-completer-volume.c
@@ -26,6 +26,7 @@
 #include "virsh-pool.h"
 #include "virsh.h"
 #include "virstring.h"
+#include "virsh-volume.h"
 
 char **
 virshStorageVolNameCompleter(vshControl *ctl,
@@ -116,3 +117,22 @@ virshStorageVolKeyCompleter(vshControl *ctl,
     virshStoragePoolListFree(list);
     return ret;
 }
+
+char**
+virshStorageVolWipeAlgorithmCompleter(vshControl *ctl G_GNUC_UNUSED,
+                                      const vshCmd *cmd G_GNUC_UNUSED,
+                                      unsigned int completerflags G_GNUC_UNUSED)
+{
+    size_t nalgorithms = VIR_STORAGE_VOL_WIPE_ALG_LAST;
+    size_t i = 0;
+    char **ret = NULL;
+    g_auto(GStrv) tmp = g_new0(char *, nalgorithms);
+
+    for (i = 0; i < nalgorithms; i++) {
+        const char *str = virshStorageVolWipeAlgorithmTypeToString(i);
+        tmp[i] = g_strdup(str);
+    }
+
+    ret = g_steal_pointer(&tmp);
+    return ret;
+}
diff --git a/tools/virsh-completer-volume.h b/tools/virsh-completer-volume.h
index dc6eeb4b3c..17e50f450d 100644
--- a/tools/virsh-completer-volume.h
+++ b/tools/virsh-completer-volume.h
@@ -33,3 +33,9 @@ char **
 virshStorageVolKeyCompleter(vshControl *ctl,
                             const vshCmd *cmd,
                             unsigned int flags);
+
+
+char **
+virshStorageVolWipeAlgorithmCompleter(vshControl *ctl,
+                                      const vshCmd *cmd,
+                                      unsigned int flags);
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index d005602fe8..b6fa9555ad 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -902,12 +902,12 @@ static const vshCmdOptDef opts_vol_wipe[] = {
     VIRSH_COMMON_OPT_POOL_OPTIONAL,
     {.name = "algorithm",
      .type = VSH_OT_STRING,
+     .completer = virshStorageVolWipeAlgorithmCompleter,
      .help = N_("perform selected wiping algorithm")
     },
     {.name = NULL}
 };
 
-VIR_ENUM_DECL(virshStorageVolWipeAlgorithm);
 VIR_ENUM_IMPL(virshStorageVolWipeAlgorithm,
               VIR_STORAGE_VOL_WIPE_ALG_LAST,
               "zero", "nnsa", "dod", "bsi", "gutmann", "schneier",
@@ -950,7 +950,6 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
 }
 
 
-VIR_ENUM_DECL(virshStorageVol);
 VIR_ENUM_IMPL(virshStorageVol,
               VIR_STORAGE_VOL_LAST,
               N_("file"),
diff --git a/tools/virsh-volume.h b/tools/virsh-volume.h
index 15cab0fd8c..32e5394f5c 100644
--- a/tools/virsh-volume.h
+++ b/tools/virsh-volume.h
@@ -33,3 +33,6 @@ virStorageVolPtr virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
                          VIRSH_BYUUID | VIRSH_BYNAME)
 
 extern const vshCmdDef storageVolCmds[];
+
+VIR_ENUM_DECL(virshStorageVolWipeAlgorithm);
+VIR_ENUM_DECL(virshStorageVol);
-- 
2.25.1



More information about the libvir-list mailing list