virsh: Add event completer to --enable/--disable args of perf command

Signed-off-by: Lin Ma <lma@suse.de>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Lin Ma 2020-09-11 15:13:06 +08:00 committed by Michal Privoznik
parent a2ab5eb8e1
commit eddd9932ee
3 changed files with 59 additions and 0 deletions

View File

@ -29,6 +29,7 @@
#include "virsh.h"
#include "virstring.h"
#include "virxml.h"
#include "virperf.h"
char **
virshDomainNameCompleter(vshControl *ctl,
@ -338,3 +339,51 @@ virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
return ret;
}
char **
virshDomainPerfEnableCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags)
{
size_t i = 0;
VIR_AUTOSTRINGLIST events = NULL;
const char *event = NULL;
virCheckFlags(0, NULL);
if (VIR_ALLOC_N(events, VIR_PERF_EVENT_LAST + 1) < 0)
return NULL;
for (i = 0; i < VIR_PERF_EVENT_LAST; i++)
events[i] = g_strdup(virPerfEventTypeToString(i));
if (vshCommandOptStringQuiet(ctl, cmd, "enable", &event) < 0)
return NULL;
return virshCommaStringListComplete(event, (const char **)events);
}
char **
virshDomainPerfDisableCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags)
{
size_t i = 0;
VIR_AUTOSTRINGLIST events = NULL;
const char *event = NULL;
virCheckFlags(0, NULL);
if (VIR_ALLOC_N(events, VIR_PERF_EVENT_LAST + 1) < 0)
return NULL;
for (i = 0; i < VIR_PERF_EVENT_LAST; i++)
events[i] = g_strdup(virPerfEventTypeToString(i));
if (vshCommandOptStringQuiet(ctl, cmd, "disable", &event) < 0)
return NULL;
return virshCommaStringListComplete(event, (const char **)events);
}

View File

@ -62,3 +62,11 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl,
char ** virshDomainHostnameSourceCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshDomainPerfEnableCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshDomainPerfDisableCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);

View File

@ -9332,10 +9332,12 @@ static const vshCmdOptDef opts_perf[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(0),
{.name = "enable",
.type = VSH_OT_STRING,
.completer = virshDomainPerfEnableCompleter,
.help = N_("perf events which will be enabled")
},
{.name = "disable",
.type = VSH_OT_STRING,
.completer = virshDomainPerfDisableCompleter,
.help = N_("perf events which will be disabled")
},
VIRSH_COMMON_OPT_DOMAIN_CONFIG,