On 4/22/21 12:38 PM, Lin Ma wrote:
Signed-off-by: Lin Ma <lma(a)suse.com>
---
tools/virsh-completer-domain.c | 43 ++++++++++++++++++++++++++++++++++
tools/virsh-completer-domain.h | 4 ++++
tools/virsh-domain.c | 2 ++
3 files changed, 49 insertions(+)
diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 99b36a2f9f..f56dc40125 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -872,3 +872,46 @@ virshKeycodeNameCompleter(vshControl *ctl,
return g_steal_pointer(&tmp);
}
+
+
+char **
+virshDomainFSMountpointsCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags)
+{
+ g_auto(GStrv) tmp = NULL;
+ virDomainPtr dom = NULL;
+ int rc = -1;
+ size_t i;
+ virDomainFSInfoPtr *info = NULL;
+ size_t ninfos = 0;
+ char **ret = NULL;
+
+ virCheckFlags(0, NULL);
+
+ if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+ return NULL;
+
+ rc = virDomainGetFSInfo(dom, &info, 0);
+ if (rc <= 0) {
+ goto cleanup;
+ }
+ ninfos = rc;
+
+ if (info) {
This feels redundant. @ninfos is > 0 at this point, thus @info must be
!NULL. I know you took inspiration from cmdDomFSInfo() but the same
argument applies there.
+ tmp = g_new0(char *, ninfos + 1);
+ for (i = 0; i < ninfos; i++) {
+ tmp[i] = g_strdup(info[i]->mountpoint);
+ }
+ ret = g_steal_pointer(&tmp);
+ }
+
+ cleanup:
+ if (info) {
+ for (i = 0; i < ninfos; i++)
+ virDomainFSInfoFree(info[i]);
+ VIR_FREE(info);
+ }
+ virshDomainFree(dom);
+ return ret;
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index 04a3705ff9..ef242d0c68 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -118,3 +118,7 @@ char ** virshCodesetNameCompleter(vshControl *ctl,
char ** virshKeycodeNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
+
+char ** virshDomainFSMountpointsCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index fac590fbc6..9d315bdbcf 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13920,6 +13920,7 @@ static const vshCmdOptDef opts_domfsfreeze[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "mountpoint",
.type = VSH_OT_ARGV,
+ .completer = virshDomainFSMountpointsCompleter,
.help = N_("mountpoint path to be frozen")
},
{.name = NULL}
@@ -13969,6 +13970,7 @@ static const vshCmdOptDef opts_domfsthaw[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "mountpoint",
.type = VSH_OT_ARGV,
+ .completer = virshDomainFSMountpointsCompleter,
.help = N_("mountpoint path to be thawed")
},
{.name = NULL}
Missed one more: opts_domfstrim.
Michal