mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
virsh: Add command 'guestvcpus' implementing virDomain(GS)etGuestVcpus
Add a straightforward implementation for using the new APIs.
This commit is contained in:
parent
3ebf7ca07e
commit
69e0cd3397
@ -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, ¶ms, &nparams, 0) < 0)
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
char *str = vshGetTypedParamValue(ctl, ¶ms[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}
|
||||
};
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user