Signed-off-by: Lin Ma <lma@xxxxxxx> --- tools/virsh-completer-domain.c | 37 ++++++++++++++++++++++++++++++++++ tools/virsh-completer-domain.h | 4 ++++ tools/virsh-domain.c | 6 ++++++ 3 files changed, 47 insertions(+) diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index ae8baa52e3..56f014ae40 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -439,3 +439,40 @@ virshDomainPerfDisableCompleter(vshControl *ctl, return virshCommaStringListComplete(event, (const char **)events); } + + +char ** +virshDomainIOThreadIdCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virDomainPtr dom; + size_t niothreads = 0; + g_autofree virDomainIOThreadInfoPtr *info = NULL; + size_t i; + int rc; + char **ret = NULL; + VIR_AUTOSTRINGLIST tmp = NULL; + + virCheckFlags(0, NULL); + + if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if ((rc = virDomainGetIOThreadInfo(dom, &info, flags)) < 0) + goto cleanup; + + niothreads = rc; + + if (VIR_ALLOC_N(tmp, niothreads + 1) < 0) + goto cleanup; + + for (i = 0; i < niothreads; i++) + tmp[i] = g_strdup_printf("%u", info[i]->iothread_id); + + ret = g_steal_pointer(&tmp); + + cleanup: + virshDomainFree(dom); + return ret; +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 9a8b962cb7..91731da778 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -74,3 +74,7 @@ char ** virshDomainPerfDisableCompleter(vshControl *ctl, char ** virshDomainUUIDCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshDomainIOThreadIdCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c07c8c3527..5222bbb566 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -7749,6 +7749,8 @@ static const vshCmdOptDef opts_iothreadpin[] = { {.name = "iothread", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, + .completer = virshDomainIOThreadIdCompleter, + .completer_flags = 0, .help = N_("IOThread ID number") }, {.name = "cpulist", @@ -7897,6 +7899,8 @@ static const vshCmdOptDef opts_iothreadset[] = { {.name = "id", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, + .completer = virshDomainIOThreadIdCompleter, + .completer_flags = 0, .help = N_("iothread id of existing IOThread") }, {.name = "poll-max-ns", @@ -8000,6 +8004,8 @@ static const vshCmdOptDef opts_iothreaddel[] = { {.name = "id", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, + .completer = virshDomainIOThreadIdCompleter, + .completer_flags = 0, .help = N_("iothread_id for the IOThread to delete") }, VIRSH_COMMON_OPT_DOMAIN_CONFIG, -- 2.26.0