]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add logical CPU IDs completion for nodecpustats command
authorLin Ma <lma@suse.com>
Tue, 10 Nov 2020 09:50:53 +0000 (17:50 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 10 Nov 2020 17:34:02 +0000 (18:34 +0100)
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-completer-host.c
tools/virsh-completer-host.h
tools/virsh-host.c

index 339390aa00a2e30d27a171d492f29cdc43be5de5..4c277f2adaac2d8c59aaf874f149ce2366ce099d 100644 (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);
+}
index 921beb7a2dba8ae1ebdd156441e2b21d03f623f2..a5022165846a4711258ef6e8668a62c8582dffd3 100644 (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);
index cda2ef4ac156e21189d41dabb2a1bacb29c210d4..ba524523f5d5dc18197920503ad0de636afec99e 100644 (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",