]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add logical CPU list completion for --cpulist argument
authorLin Ma <morecache@gmail.com>
Fri, 11 Sep 2020 07:13:14 +0000 (15:13 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 14 Sep 2020 13:52:40 +0000 (15:52 +0200)
Currently this patch works for the commands emulatorpin, iothreadpin and
vcpupin.

Signed-off-by: Lin Ma <lma@suse.de>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-completer-domain.c
tools/virsh-completer-domain.h
tools/virsh-domain.c

index 281091c41c3c9727b43acad09f8b976c060bd8c6..6bd09dcb0f89e376a7d47a3f53e57dbe984e18ef 100644 (file)
@@ -564,3 +564,34 @@ virshDomainVcpulistCompleter(vshControl *ctl,
     virshDomainFree(dom);
     return ret;
 }
+
+
+char **
+virshDomainCpulistCompleter(vshControl *ctl,
+                            const vshCmd *cmd,
+                            unsigned int flags)
+{
+    virshControlPtr priv = ctl->privData;
+    size_t i;
+    int cpunum;
+    g_autofree unsigned char *cpumap = NULL;
+    unsigned int online;
+    VIR_AUTOSTRINGLIST cpulist = NULL;
+    const char *cpuid = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "cpulist", &cpuid) < 0)
+        return NULL;
+
+    if ((cpunum = virNodeGetCPUMap(priv->conn, &cpumap, &online, 0)) < 0)
+        return NULL;
+
+    if (VIR_ALLOC_N(cpulist, cpunum + 1) < 0)
+        return NULL;
+
+    for (i = 0; i < cpunum; i++)
+        cpulist[i] = g_strdup_printf("%zu", i);
+
+    return virshCommaStringListComplete(cpuid, (const char **)cpulist);
+}
index d9ed5b44b3dad9be3d1e26a17e6a059dac05b745..d38efd5ea806fd59b109a5a75cbdaef5ff63dbcb 100644 (file)
@@ -86,3 +86,7 @@ char ** virshDomainVcpuCompleter(vshControl *ctl,
 char ** virshDomainVcpulistCompleter(vshControl *ctl,
                                      const vshCmd *cmd,
                                      unsigned int flags);
+
+char ** virshDomainCpulistCompleter(vshControl *ctl,
+                                    const vshCmd *cmd,
+                                    unsigned int flags);
index baec00645a9a1083dc514c9512ed744750579bc1..f0ca6f7b831ab29b6d4110f61e5af4574ffb6484 100644 (file)
@@ -7008,6 +7008,7 @@ static const vshCmdOptDef opts_vcpupin[] = {
     {.name = "cpulist",
      .type = VSH_OT_STRING,
      .flags = VSH_OFLAG_EMPTY_OK,
+     .completer = virshDomainCpulistCompleter,
      .help = N_("host cpu number(s) to set, or omit option to query")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
@@ -7235,6 +7236,7 @@ static const vshCmdOptDef opts_emulatorpin[] = {
     {.name = "cpulist",
      .type = VSH_OT_STRING,
      .flags = VSH_OFLAG_EMPTY_OK,
+     .completer = virshDomainCpulistCompleter,
      .help = N_("host cpu number(s) to set, or omit option to query")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
@@ -7757,6 +7759,7 @@ static const vshCmdOptDef opts_iothreadpin[] = {
     {.name = "cpulist",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshDomainCpulistCompleter,
      .help = N_("host cpu number(s) to set")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,