https://bugzilla.redhat.com/show_bug.cgi?id=1161617
Add command to allow adding and removing IOThreads from the domain including
the configuration and live domain.
$ virsh setiothreads --help
NAME
setiothreads - change number of IOThreads
SYNOPSIS
setiothreads <domain> <count> [--config] [--live] [--current]
DESCRIPTION
Change the number of IOThreads in the guest domain.
OPTIONS
[--domain] <string> domain name, id or uuid
[--count] <number> number of IOThreads
--config affect next boot
--live affect running domain
--current affect current domain
Assuming a domain with multiple IOThreads assigned to various threads and
trying to remove an IOThread assigned to a disk resource results in an
error on removal attempt:
$ virsh iothreadsinfo $dom
IOThread ID CPU Affinity
---------------------------------------------------
1 2
2 3
3 0-3
$ virsh setiothreads $dom 1
error: invalid argument: cannot remove IOThread 2 since it is being used by disk path
'/home/vm-images/iothr-vol1'
Adding an IOThread to a domain and then removing it:
$ virsh iothreadsinfo $dom
No IOThreads found for the domain
$ virsh setiothreads $dom 1
$ virsh iothreadsinfo $dom
IOThread ID CPU Affinity
---------------------------------------------------
1 0-3
$ virsh setiothreads $dom 0
$ virsh iothreadsinfo $dom
No IOThreads found for the domain
$
Invalid number of IOThreads provided:
$ virsh setiothreads $dom -1
error: Invalid number of IOThreads
$
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
tools/virsh-domain.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 17 +++++++++++
2 files changed, 99 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1d8225c..69d2a94 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6978,6 +6978,82 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
}
/*
+ * "setiothreads" command
+ */
+static const vshCmdInfo info_setiothreads[] = {
+ {.name = "help",
+ .data = N_("change number of IOThreads")
+ },
+ {.name = "desc",
+ .data = N_("Change the number of IOThreads in the guest domain.")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_setiothreads[] = {
+ {.name = "domain",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("domain name, id or uuid")
+ },
+ {.name = "count",
+ .type = VSH_OT_INT,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("number of IOThreads")
+ },
+ {.name = "config",
+ .type = VSH_OT_BOOL,
+ .help = N_("affect next boot")
+ },
+ {.name = "live",
+ .type = VSH_OT_BOOL,
+ .help = N_("affect running domain")
+ },
+ {.name = "current",
+ .type = VSH_OT_BOOL,
+ .help = N_("affect current domain")
+ },
+ {.name = NULL}
+};
+
+static bool
+cmdSetIOThreads(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom;
+ int count = 0;
+ bool ret = false;
+ bool config = vshCommandOptBool(cmd, "config");
+ bool live = vshCommandOptBool(cmd, "live");
+ bool current = vshCommandOptBool(cmd, "current");
+ unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+
+ VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
+ VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
+
+ if (config)
+ flags |= VIR_DOMAIN_AFFECT_CONFIG;
+ if (live)
+ flags |= VIR_DOMAIN_AFFECT_LIVE;
+
+ if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (vshCommandOptInt(cmd, "count", &count) < 0 || count < 0) {
+ vshError(ctl, "%s", _("Invalid number of IOThreads"));
+ goto cleanup;
+ }
+
+ if (virDomainSetIOThreads(dom, count, flags) < 0)
+ goto cleanup;
+
+ ret = true;
+
+ cleanup:
+ virDomainFree(dom);
+ return ret;
+}
+
+/*
* "cpu-compare" command
*/
static const vshCmdInfo info_cpu_compare[] = {
@@ -12903,6 +12979,12 @@ const vshCmdDef domManagementCmds[] = {
.info = info_iothreadpin,
.flags = 0
},
+ {.name = "setiothreads",
+ .handler = cmdSetIOThreads,
+ .opts = opts_setiothreads,
+ .info = info_setiothreads,
+ .flags = 0
+ },
{.name = "send-key",
.handler = cmdSendKey,
.opts = opts_send_key,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 8262a45..3376e49 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1416,6 +1416,23 @@ If no flag is specified, behavior is different depending on
hypervisor.
B<Note>: The expression is sequentially evaluated, so "0-15,^8" is
identical to "9-14,0-7,15" but not identical to "^8,0-15".
+=item B<setiothreads> I<domain> I<count>
+[[I<--config>] [I<--live>] | [I<--current>]]
+
+Change the number of IOThreads in a guest domain. The I<count> value may be
+limited by host or hypervisor. A value of zero removes all IOThreads from
+the guest domain. If an IOThread is currently assigned to a disk resource
+such as via the B<attach-disk> command, then an attempt to remove the
+IOThread will fail.
+
+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,
+affect the current guest state.
+Both I<--live> and I<--config> flags may be given, but if not flag is
+specified, behavior is dfferent depending on hypervisor.
+
=item B<managedsave> I<domain> [I<--bypass-cache>]
[{I<--running> | I<--paused>}] [I<--verbose>]
--
2.1.0