Add a simple virsh command handler which makes use of the new API.
---
tools/virsh-domain.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/virsh.pod | 19 ++++++++++++
2 files changed, 107 insertions(+)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 023ec8a8b..09a9f8203 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -7015,6 +7015,88 @@ cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd)
/*
+ * "setvcpu" command
+ */
+static const vshCmdInfo info_setvcpu[] = {
+ {.name = "help",
+ .data = N_("attach/detach vcpu or groups of threads")
+ },
+ {.name = "desc",
+ .data = N_("Add or remove vcpus")
+ },
+ {.name = NULL}
+};
+
+static const vshCmdOptDef opts_setvcpu[] = {
+ VIRSH_COMMON_OPT_DOMAIN_FULL,
+ {.name = "vcpulist",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("ids of vcpus to manipulate")
+ },
+ {.name = "enable",
+ .type = VSH_OT_BOOL,
+ .help = N_("enable cpus specified by cpumap")
+ },
+ {.name = "disable",
+ .type = VSH_OT_BOOL,
+ .help = N_("disable cpus specified by cpumap")
+ },
+ VIRSH_COMMON_OPT_DOMAIN_CONFIG,
+ VIRSH_COMMON_OPT_DOMAIN_LIVE,
+ VIRSH_COMMON_OPT_DOMAIN_CURRENT,
+ {.name = NULL}
+};
+
+static bool
+cmdSetvcpu(vshControl *ctl, const vshCmd *cmd)
+{
+ virDomainPtr dom;
+ bool enable = vshCommandOptBool(cmd, "enable");
+ bool disable = vshCommandOptBool(cmd, "disable");
+ bool config = vshCommandOptBool(cmd, "config");
+ bool live = vshCommandOptBool(cmd, "live");
+ const char *vcpulist = NULL;
+ int state = 0;
+ bool ret = false;
+ unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+
+ VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable);
+
+ VSH_EXCLUSIVE_OPTIONS("current", "live");
+ VSH_EXCLUSIVE_OPTIONS("current", "config");
+
+ if (config)
+ flags |= VIR_DOMAIN_AFFECT_CONFIG;
+ if (live)
+ flags |= VIR_DOMAIN_AFFECT_LIVE;
+
+ if (!(enable || disable)) {
+ vshError(ctl, "%s", _("one of --enable, --disable is
required"));
+ return false;
+ }
+
+ if (vshCommandOptStringReq(ctl, cmd, "vcpulist", &vcpulist))
+ return false;
+
+ if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+ return false;
+
+ if (enable)
+ state = 1;
+
+ if (virDomainSetVcpu(dom, vcpulist, state, flags) < 0)
+ goto cleanup;
+
+ ret = true;
+
+ cleanup:
+ virDomainFree(dom);
+ return ret;
+}
+
+
+/*
* "iothreadinfo" command
*/
static const vshCmdInfo info_iothreadinfo[] = {
@@ -13951,5 +14033,11 @@ const vshCmdDef domManagementCmds[] = {
.info = info_guestvcpus,
.flags = 0
},
+ {.name = "setvcpu",
+ .handler = cmdSetvcpu,
+ .opts = opts_setvcpu,
+ .info = info_setvcpu,
+ .flags = 0
+ },
{.name = NULL}
};
diff --git a/tools/virsh.pod b/tools/virsh.pod
index a47040984..606792df1 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2418,6 +2418,25 @@ be hot-plugged the next time the domain is booted. As such, it
must only be
used with the I<--config> flag, and not with the I<--live> or the
I<--current>
flag.
+=item B<setvcpu> I<domain> I<vcpulist> [I<--enable>] |
[I<--disable>]
+[[I<--live>] [I<--config>] | [I<--current>]]
+
+Change state of individual vCPUs using hot(un)plug mechanism.
+
+See B<vcpupin> for information on format of I<vcpulist>. Hypervisor drivers
may
+require that I<vcpulist> contains exactly vCPUs belonging to one hotpluggable
+entity. This is usually just a single vCPU but certain architectures such as
+ppc64 require a full core to be specified at once.
+
+Note that hypervisors may refuse to disable certain vcpus such as vcpu 0 or
+others.
+
+If I<--live> is specified, affect a running domain.
+If I<--config> is specified, affect the next startup of a persistent domain.
+If I<--current> is specified, affect the current domain state. This is the
+default. Both I<--live> and I<--config> flags may be given, but
I<--current> is
+exclusive.
+
=item B<shutdown> I<domain> [I<--mode MODE-LIST>]
Gracefully shuts down a domain. This coordinates with the domain OS
--
2.11.0