]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Implement command for virDomainSetVcpu called setvcpu
authorPeter Krempa <pkrempa@redhat.com>
Tue, 21 Jun 2016 08:55:30 +0000 (10:55 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 21 Feb 2017 14:06:59 +0000 (15:06 +0100)
Add a simple virsh command handler which makes use of the new API.

tools/virsh-domain.c
tools/virsh.pod

index 023ec8a8b3dff95638f76284ebfebb421c9290d5..09a9f82033fb3ba1ac6bc6f65230bf04315fb277 100644 (file)
@@ -7014,6 +7014,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
  */
@@ -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}
 };
index 90f4b5a1f73cfe549b64e3d55fdbbe1e85dd75b4..fd1f5206571af6561536b4e50a2cb499975c3b09 100644 (file)
@@ -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