]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add iothread IDs completion to iothread* commands
authorLin Ma <morecache@gmail.com>
Fri, 11 Sep 2020 07:13:10 +0000 (15:13 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 14 Sep 2020 13:52:40 +0000 (15:52 +0200)
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 e63e5686ac485d12a7d4af2a1aa3e5f99e26d1f3..a13e2fa7794e56739bce03e664e0ea870ec3540d 100644 (file)
@@ -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 = NULL;
+    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;
+}
index 9a8b962cb756933c6f735e917b7982529cfc9cf0..91731da778b78c6b296610cb17e36305838c8085 100644 (file)
@@ -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);
index 48958d6974a4519c00528fd3098bc6e6ad62b005..1d33c51b35d9386ecf2624f70836272284034135 100644 (file)
@@ -243,6 +243,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "iothread",
      .type = VSH_OT_STRING,
+     .completer = virshDomainIOThreadIdCompleter,
      .help = N_("IOThread to be used by supported device")
     },
     {.name = "cache",
@@ -7748,6 +7749,7 @@ static const vshCmdOptDef opts_iothreadpin[] = {
     {.name = "iothread",
      .type = VSH_OT_INT,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshDomainIOThreadIdCompleter,
      .help = N_("IOThread ID number")
     },
     {.name = "cpulist",
@@ -7896,6 +7898,7 @@ static const vshCmdOptDef opts_iothreadset[] = {
     {.name = "id",
      .type = VSH_OT_INT,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshDomainIOThreadIdCompleter,
      .help = N_("iothread id of existing IOThread")
     },
     {.name = "poll-max-ns",
@@ -7999,6 +8002,7 @@ static const vshCmdOptDef opts_iothreaddel[] = {
     {.name = "id",
      .type = VSH_OT_INT,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshDomainIOThreadIdCompleter,
      .help = N_("iothread_id for the IOThread to delete")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,