From 35ba60be36c00eac228508bcea6bcd608bb1237c Mon Sep 17 00:00:00 2001 From: Haonan Wang Date: Thu, 10 Mar 2022 23:22:24 +0800 Subject: [PATCH] virsh: Provide completer for vol-wipe algorithms Related issue: https://gitlab.com/libvirt/libvirt/-/issues/9 Signed-off-by: Haonan Wang Signed-off-by: Michal Privoznik Reviewed-by: Michal Privoznik --- tools/virsh-completer-volume.c | 19 +++++++++++++++++++ tools/virsh-completer-volume.h | 6 ++++++ tools/virsh-volume.c | 2 +- tools/virsh-volume.h | 2 ++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tools/virsh-completer-volume.c b/tools/virsh-completer-volume.c index ac3c472177..bed45fa1ca 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,21 @@ virshStorageVolKeyCompleter(vshControl *ctl, virshStoragePoolListFree(list); return ret; } + +char ** +virshStorageVolWipeAlgorithmCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + char **ret = NULL; + size_t i; + + virCheckFlags(0, NULL); + + ret = g_new0(char *, VIR_STORAGE_VOL_WIPE_ALG_LAST + 1); + + for (i = 0; i < VIR_STORAGE_VOL_WIPE_ALG_LAST; i++) + ret[i] = g_strdup(virshStorageVolWipeAlgorithmTypeToString(i)); + + 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..503acda874 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", diff --git a/tools/virsh-volume.h b/tools/virsh-volume.h index 15cab0fd8c..f8b076d5ca 100644 --- a/tools/virsh-volume.h +++ b/tools/virsh-volume.h @@ -33,3 +33,5 @@ virStorageVolPtr virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, VIRSH_BYUUID | VIRSH_BYNAME) extern const vshCmdDef storageVolCmds[]; + +VIR_ENUM_DECL(virshStorageVolWipeAlgorithm);