https://bugzilla.redhat.com/show_bug.cgi?id=1135491
$ virsh iothreads --help
NAME
iothreads - view domain IOThreads
SYNOPSIS
iothreads <domain> [--iothread_id <number>] [--cpulist <string>]
[--config] [--live] [--current]
DESCRIPTION
Returns basic information about the domain IOThreads.
OPTIONS
[--domain] <string> domain name, id or uuid
--iothread_id <number> iothread_id number
--cpulist <string> host cpu number(s) to set affinity
--config affect next boot
--live affect running domain
--current affect current domain
The changes will now also allow viewing just one iothread if so
desired, such as:
$ virsh iothreads f18iothr 2
IOThread ID CPU Affinity Resource(s)
-----------------------------------------------------------------
2 3 /home/vm-images/iothr-vol1
In order to change the IOThread pinning, the following would be used:
$ virsh iothreads f18iothr 2 0,1
Then to view the change:
$ virsh iothreads f18iothr 2
IOThread ID CPU Affinity Resource(s)
-----------------------------------------------------------------
2 0-1 /home/vm-images/iothr-vol1
$
If an invalid value is supplied, an error will be displayed
$ virsh iothreads f18iothr 4 3
error: invalid argument: iothread value out of range 4 > 3
$
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
tools/virsh-domain.c | 99 ++++++++++++++++++++++++++++++++++++++++------------
tools/virsh.pod | 24 ++++++++-----
2 files changed, 92 insertions(+), 31 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ffb0392..66757eb 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6814,6 +6814,15 @@ static const vshCmdOptDef opts_iothreads[] = {
.flags = VSH_OFLAG_REQ,
.help = N_("domain name, id or uuid")
},
+ {.name = "iothread_id",
+ .type = VSH_OT_INT,
+ .help = N_("iothread_id number")
+ },
+ {.name = "cpulist",
+ .type = VSH_OT_STRING,
+ .flags = VSH_OFLAG_EMPTY_OK,
+ .help = N_("host cpu number(s) to set affinity")
+ },
{.name = "config",
.type = VSH_OT_BOOL,
.help = N_("affect next boot")
@@ -6840,6 +6849,13 @@ cmdIOThreadsInfo(vshControl *ctl, const vshCmd *cmd)
virDomainIOThreadsInfoPtr *info;
size_t i, j;
int maxcpu;
+ bool ret = false;
+ bool query = false; /* Query mode if no cpulist */
+ unsigned int iothread_val = 0;
+ int got_iothread;
+ unsigned char *cpumap = NULL;
+ size_t cpumaplen;
+ const char *cpulist = NULL;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
@@ -6850,45 +6866,82 @@ cmdIOThreadsInfo(vshControl *ctl, const vshCmd *cmd)
if (live)
flags |= VIR_DOMAIN_AFFECT_LIVE;
+ if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0)
+ return false;
+
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
- goto cleanup;
+ query = !cpulist;
- if ((niothreads = virDomainGetIOThreadsInfo(dom, &info, flags)) < 0) {
- vshError(ctl, _("Unable to get domain IOThreads information"));
+ if ((got_iothread = vshCommandOptUInt(cmd, "iothread_id",
+ &iothread_val)) < 0) {
+ vshError(ctl, "%s", _("iothreads: Invalid IOThread
number."));
goto cleanup;
}
- if (niothreads == 0) {
- vshError(ctl, _("No IOThreads found for the domain"));
+ /* In set mode, "iothread_val" is necessary */
+ if (!query && got_iothread == 0) {
+ vshError(ctl, "%s", _("iothreads: set missing IOThreads
number."));
goto cleanup;
}
- vshPrintExtra(ctl, " %-15s %-15s %-15s\n",
- _("IOThread ID"), _("CPU Affinity"),
_("Resource(s)"));
- vshPrintExtra(ctl,
"-----------------------------------------------------------------\n");
- for (i = 0; i < niothreads; i++) {
+ if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
+ goto cleanup;
- vshPrintExtra(ctl, " %-15u ", info[i]->iothread_id);
- ignore_value(vshPrintPinInfo(info[i]->cpumap, info[i]->cpumaplen,
- maxcpu, 0));
- for (j = 0; j < info[i]->nresources; j++) {
- if (j == 0)
- vshPrintExtra(ctl, "\t\t %s", info[i]->resources[j]);
- else
- vshPrintExtra(ctl, "\n %-15s %s\t\t %s",
- " ", " ", info[i]->resources[j]);
+ /* Query mode: show CPU affinity information then exit.*/
+ if (query) {
+ if ((niothreads = virDomainGetIOThreadsInfo(dom, &info, flags)) < 0) {
+ vshError(ctl, _("Unable to get domain IOThreads information"));
+ goto cleanup;
}
- vshPrint(ctl, "\n");
- virDomainIOThreadsInfoFree(info[i]);
+
+ if (niothreads == 0) {
+ vshError(ctl, _("No IOThreads found for the domain"));
+ ret = true;
+ goto cleanup;
+ }
+
+ vshPrintExtra(ctl, " %-15s %-15s %-15s\n",
+ _("IOThread ID"), _("CPU Affinity"),
_("Resource(s)"));
+ vshPrintExtra(ctl,
"-----------------------------------------------------------------\n");
+ for (i = 0; i < niothreads; i++) {
+
+ if (iothread_val && (i + 1) != iothread_val)
+ continue;
+ vshPrintExtra(ctl, " %-15u ", info[i]->iothread_id);
+ ignore_value(vshPrintPinInfo(info[i]->cpumap, info[i]->cpumaplen,
+ maxcpu, 0));
+ for (j = 0; j < info[i]->nresources; j++) {
+ if (j == 0)
+ vshPrintExtra(ctl, "\t\t %s", info[i]->resources[j]);
+ else
+ vshPrintExtra(ctl, "\n %-15s %s\t\t %s",
+ " ", " ",
info[i]->resources[j]);
+ }
+ vshPrint(ctl, "\n");
+ virDomainIOThreadsInfoFree(info[i]);
+ }
+ VIR_FREE(info);
+ ret = true;
+ goto cleanup;
}
- VIR_FREE(info);
+
+ /* We are pinning specified iothread_val to specified physical cpus */
+ cpumaplen = VIR_CPU_MAPLEN(maxcpu);
+ if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
+ goto cleanup;
+
+ flags |= VIR_DOMAIN_IOTHREADS_PIN;
+ if (virDomainSetIOThreads(dom, iothread_val,
+ cpumap, cpumaplen, flags) < 0)
+ goto cleanup;
+
+ ret = true;
cleanup:
virDomainFree(dom);
- return niothreads >= 0;
+ return ret;
}
/*
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 22e988b..8b75476 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1360,17 +1360,25 @@ 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> [[I<--live>] [I<--config>] |
[I<--current>]]
+=item B<iothreads> I<domain> [I<iothread_id>] [I<cpulist>]
+[[I<--live>] [I<--config>] | [I<--current>]]
-Display basic domain IOThreads information including the IOThread ID,
-the CPU Affinity, and Resources assigned to each IOThread.
+Query or change the IOThreads information for the domain. To display the
+basic IOThread information including the IOThread ID, CPU Affinity, and
+Resources associated with each IOThread omit both the I<iothread_id> and
+I<cpulist>.
-If I<--live> is specified, get the IOThreads data from the running guest. If
-the guest is not running, an error is returned.
-If I<--config> is specified, get the IOThreads data from the next boot of
-a persistent guest.
+The I<iothread_id> may be used to query a specific IOThread ID or it can
+be omitted to list all the IOThreads for the domain. It must be used in
+order to set the I<cpulist> for a specific IOThread ID.
+See B<vcpupin> for I<cpulist>.
+If I<--live> is specified, affect a running guest. If the guest is not running,
+an error is returned.
+If I<--config> is specified, affect the next boot of a persistent guest.
If I<--current> is specified or I<--live> and I<--config> are not
specified,
-then get the IOThread data based on the current guest state.
+affect the current guest state.
+Both I<--live> and I<--config> flags may be given if I<cpulist> is
present,
+but I<--current> is exclusive.
=item B<managedsave> I<domain> [I<--bypass-cache>]
[{I<--running> | I<--paused>}] [I<--verbose>]
--
2.1.0