[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 13/17] virsh: Add logical CPU list completion for --cpulist argument



Currently this patch works for the commands emulatorpin, iothreadpin and
vcpupin.

Signed-off-by: Lin Ma <lma suse de>
---
 tools/virsh-completer-domain.c | 33 +++++++++++++++++++++++++++++++++
 tools/virsh-completer-domain.h |  5 +++++
 tools/virsh-domain.c           |  3 +++
 3 files changed, 41 insertions(+)

diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 218f10e5ba..e02c3b0c31 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -564,3 +564,36 @@ virshDomainVcpulistCompleter(vshControl *ctl,
     virshDomainFree(dom);
     return ret;
 }
+
+
+char **
+virshDomainCpulistCompleter(vshControl *ctl,
+                            const vshCmd *cmd,
+                            unsigned int flags G_GNUC_UNUSED)
+{
+    int i, cpunum;
+    unsigned char *cpumap = NULL;
+    unsigned int online;
+    VIR_AUTOSTRINGLIST cpulist = NULL;
+    const char *cpuid = NULL;
+    char **ret = NULL;
+    virshControlPtr priv = ctl->privData;
+
+    if ((cpunum = virNodeGetCPUMap(priv->conn, &cpumap, &online, 0)) < 0)
+        goto cleanup;
+
+    if (VIR_ALLOC_N(cpulist, cpunum + 1) < 0)
+        goto cleanup;
+
+    for (i = 0; i < cpunum; i++)
+        cpulist[i] = g_strdup_printf("%u", i);
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "cpulist", &cpuid) < 0)
+        goto cleanup;
+
+    ret = virshCommaStringListComplete(cpuid, (const char **)cpulist);
+
+ cleanup:
+    VIR_FREE(cpumap);
+    return ret;
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index 84219ab088..a5477c4ae5 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -88,3 +88,8 @@ char **
 virshDomainVcpulistCompleter(vshControl *ctl,
                              const vshCmd *cmd,
                              unsigned int flags);
+
+char **
+virshDomainCpulistCompleter(vshControl *ctl,
+                            const vshCmd *cmd,
+                            unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index c3ac28cab0..6b2787b8d5 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -7011,6 +7011,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,
@@ -7238,6 +7239,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,
@@ -7762,6 +7764,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,
-- 
2.26.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]