]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: Add command 'guestvcpus' implementing virDomain(GS)etGuestVcpus
authorPeter Krempa <pkrempa@redhat.com>
Mon, 20 Jun 2016 07:57:53 +0000 (09:57 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 22 Jun 2016 07:26:08 +0000 (09:26 +0200)
Add a straightforward implementation for using the new APIs.

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

index 7c3fc862b595d2f5ed5c9d946ad771948e0d4beb..3c11be6f729ca91011c9b93644af339dd9523805 100644 (file)
@@ -6762,6 +6762,93 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
     return ret;
 }
 
+
+/*
+ * "guestvcpus" command
+ */
+static const vshCmdInfo info_guestvcpus[] = {
+    {.name = "help",
+     .data = N_("query or modify state of vcpu in the guest (via agent)")
+    },
+    {.name = "desc",
+     .data = N_("Use the guest agent to query or set cpu state from guest's "
+                "point of view")
+    },
+    {.name = NULL}
+};
+
+static const vshCmdOptDef opts_guestvcpus[] = {
+    VIRSH_COMMON_OPT_DOMAIN_FULL,
+    {.name = "cpulist",
+     .type = VSH_OT_STRING,
+     .help = N_("list of cpus to enable or disable")
+    },
+    {.name = "enable",
+     .type = VSH_OT_BOOL,
+     .help = N_("enable cpus specified by cpulist")
+    },
+    {.name = "disable",
+     .type = VSH_OT_BOOL,
+     .help = N_("disable cpus specified by cpulist")
+    },
+    {.name = NULL}
+};
+
+static bool
+cmdGuestvcpus(vshControl *ctl, const vshCmd *cmd)
+{
+    virDomainPtr dom;
+    bool enable = vshCommandOptBool(cmd, "enable");
+    bool disable = vshCommandOptBool(cmd, "disable");
+    virTypedParameterPtr params = NULL;
+    unsigned int nparams = 0;
+    const char *cpulist = NULL;
+    int state = 0;
+    size_t i;
+    bool ret = false;
+
+    VSH_EXCLUSIVE_OPTIONS_VAR(enable, disable);
+    VSH_REQUIRE_OPTION("enable", "cpulist");
+    VSH_REQUIRE_OPTION("disable", "cpulist");
+
+    if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist))
+        return false;
+
+    if (cpulist && !(enable | disable)) {
+        vshError(ctl, _("One of options --enable or --disable is required by "
+                        "option --cpulist"));
+        return false;
+    }
+
+    if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+        return false;
+
+    if (enable)
+        state = 1;
+
+    if (cpulist) {
+        if (virDomainSetGuestVcpus(dom, cpulist, state, 0) < 0)
+            goto cleanup;
+    } else {
+        if (virDomainGetGuestVcpus(dom, &params, &nparams, 0) < 0)
+            goto cleanup;
+
+        for (i = 0; i < nparams; i++) {
+            char *str = vshGetTypedParamValue(ctl, &params[i]);
+            vshPrint(ctl, "%-15s: %s\n", params[i].field, str);
+            VIR_FREE(str);
+        }
+    }
+
+    ret = true;
+
+ cleanup:
+    virTypedParamsFree(params, nparams);
+    virDomainFree(dom);
+    return ret;
+}
+
+
 /*
  * "iothreadinfo" command
  */
@@ -13602,5 +13689,11 @@ const vshCmdDef domManagementCmds[] = {
      .info = info_vncdisplay,
      .flags = 0
     },
+    {.name = "guestvcpus",
+     .handler = cmdGuestvcpus,
+     .opts = opts_guestvcpus,
+     .info = info_guestvcpus,
+     .flags = 0
+    },
     {.name = NULL}
 };
index 8e3ba69fd3a74bbc7f313ac3c32665b897dc4c78..2b1d83fa414b9a14250e9c55ceca130293cdfb8d 100644 (file)
@@ -2501,6 +2501,16 @@ Both I<--live> and I<--config> flags may be given if I<cpulist> is present,
 but I<--current> is exclusive.
 If no flag is specified, behavior is different depending on hypervisor.
 
+=item B<guestvcpus> I<domain> [[I<--enable>] | [I<--disable>]] [I<cpulist>]
+
+Query or change state of vCPUs from guest's point of view using the guest agent.
+When invoked without I<cpulist> the guest is queried for available guest vCPUs,
+their state and possibility to be offlined.
+
+If I<cpulist> is provided then one of I<--enable> or I<--disable> must be
+provided too. The desired operation is then executed on the domain.
+
+See B<vcpupin> for information on I<cpulist>.
 
 =item B<vncdisplay> I<domain>