1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-03 05:17:54 +03:00

virsh: Add logical CPU IDs completion for nodecpustats command

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Lin Ma 2020-11-10 17:50:53 +08:00 committed by Michal Privoznik
parent a9327362cd
commit 4583a49ccf
3 changed files with 36 additions and 0 deletions

View File

@ -136,3 +136,34 @@ virshCellnoCompleter(vshControl *ctl,
return g_steal_pointer(&tmp);
}
char **
virshNodeCpuCompleter(vshControl *ctl,
const vshCmd *cmd G_GNUC_UNUSED,
unsigned int flags)
{
virshControlPtr priv = ctl->privData;
VIR_AUTOSTRINGLIST tmp = NULL;
size_t i;
int cpunum;
size_t offset = 0;
unsigned int online;
g_autofree unsigned char *cpumap = NULL;
virCheckFlags(0, NULL);
if ((cpunum = virNodeGetCPUMap(priv->conn, &cpumap, &online, 0)) < 0)
return NULL;
tmp = g_new0(char *, online + 1);
for (i = 0; i < cpunum; i++) {
if (VIR_CPU_USED(cpumap, i) == 0)
continue;
tmp[offset++] = g_strdup_printf("%zu", i);
}
return g_steal_pointer(&tmp);
}

View File

@ -29,3 +29,7 @@ char ** virshAllocpagesPagesizeCompleter(vshControl *ctl,
char ** virshCellnoCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
char ** virshNodeCpuCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);

View File

@ -751,6 +751,7 @@ static const vshCmdInfo info_nodecpustats[] = {
static const vshCmdOptDef opts_node_cpustats[] = {
{.name = "cpu",
.type = VSH_OT_INT,
.completer = virshNodeCpuCompleter,
.help = N_("prints specified cpu statistics only.")
},
{.name = "percent",