[libvirt] [PATCH 4/4] virsh: Add 'iothreads' command

John Ferlan jferlan at redhat.com
Thu Feb 12 13:03:47 UTC 2015


Add the 'iothreads' command to display live IOThread Info data

$ virsh iothreads $dom
 IOThread ID     Thread ID       CPU Affinity
 ------------------------------------------------------------
  1               31983           2
  2               31984           3
  3               31985           0-3

$ echo $?
0

For domains which don't have IOThreads the following is returned:

$ virsh iothreads $dom
error: No IOThreads found for the domain

$ echo $?
0

For domains which are not running the following is returned:

$ virsh iothreads $dom
error: Unable to get domain IOThreads information
error: Requested operation is not valid: cannot list IOThreads for an inactive domain

$ echo $?
1

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 tools/virsh-domain.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/virsh.pod      |  7 +++++
 2 files changed, 79 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 20bafbe..14cb3f8 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6781,6 +6781,72 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "iothreads" command
+ */
+static const vshCmdInfo info_iothreads[] = {
+    {.name = "help",
+     .data = N_("view domain IOThreads")
+    },
+    {.name = "desc",
+     .data = N_("Returns basic information about the domain IOThreads.")
+    },
+    {.name = NULL}
+};
+static const vshCmdOptDef opts_iothreads[] = {
+    {.name = "domain",
+     .type = VSH_OT_DATA,
+     .flags = VSH_OFLAG_REQ,
+     .help = N_("domain name, id or uuid")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdIOThreadsInfo(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    int niothreads = 0;
+    virDomainIOThreadsInfoPtr *info;
+    size_t i;
+    int maxcpu;
+
+    if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
+        goto cleanup;
+
+    if ((niothreads = virDomainGetIOThreadsInfo(dom, &info, 0)) < 0) {
+        vshError(ctl, _("Unable to get domain IOThreads information"));
+        goto cleanup;
+    }
+
+    if (niothreads == 0) {
+        vshError(ctl, _("No IOThreads found for the domain"));
+        goto cleanup;
+    }
+
+    vshPrintExtra(ctl, " %-15s %-15s %-15s\n",
+                  _("IOThread ID"), _("Thread ID"), _("CPU Affinity"));
+    vshPrintExtra(ctl, "------------------------------------------------------------\n");
+    for (i = 0; i < niothreads; i++) {
+
+        vshPrintExtra(ctl, " %-15u %-15u ",
+                      info[i]->iothread_id,
+                      info[i]->thread_id);
+        ignore_value(vshPrintPinInfo(info[i]->cpumap, info[i]->cpumaplen,
+                                     maxcpu, 0));
+        vshPrint(ctl, "\n");
+        virDomainIOThreadsInfoFree(info[i]);
+    }
+    VIR_FREE(info);
+
+ cleanup:
+    virDomainFree(dom);
+    return niothreads >= 0;
+}
+
+/*
  * "cpu-compare" command
  */
 static const vshCmdInfo info_cpu_compare[] = {
@@ -12669,6 +12735,12 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_inject_nmi,
      .flags = 0
     },
+    {.name = "iothreads",
+     .handler = cmdIOThreadsInfo,
+     .opts = opts_iothreads,
+     .info = info_iothreads,
+     .flags = 0
+    },
     {.name = "send-key",
      .handler = cmdSendKey,
      .opts = opts_send_key,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index a3f527f..2c28acc 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1360,6 +1360,13 @@ If I<--timeout> is specified, the command gives up waiting for events
 after I<seconds> have elapsed.   With I<--loop>, the command prints all
 events until a timeout or interrupt key.
 
+=item B<iothreads> I<domain>
+
+Display basic domain IOThreads information including the IOThread ID, the
+Thread ID, and the CPU Affinity for each IOThread.
+
+Note that the display of information only works for active domains.
+
 =item B<managedsave> I<domain> [I<--bypass-cache>]
 [{I<--running> | I<--paused>}] [I<--verbose>]
 
-- 
2.1.0




More information about the libvir-list mailing list