setvcpus: add "--current" option to "virsh setvcpus"

This patch adds the --current option to "virsh setvcpus"
command. Currently "virsh setvcpus" command supports
"--live" and "--config" , but "--current" option.
From view of consistency, it's reasonable to support
"--current" option too.

When --current is specified, it affects a "current"
domain.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
This commit is contained in:
Taku Izumi 2011-07-15 16:02:00 +09:00 committed by Eric Blake
parent c147b93739
commit 3807d552c7
2 changed files with 26 additions and 6 deletions

View File

@ -3257,6 +3257,7 @@ static const vshCmdOptDef opts_setvcpus[] = {
{"maximum", VSH_OT_BOOL, 0, N_("set maximum limit on next boot")},
{"config", VSH_OT_BOOL, 0, N_("affect next boot")},
{"live", VSH_OT_BOOL, 0, N_("affect running domain")},
{"current", VSH_OT_BOOL, 0, N_("affect current domain")},
{NULL, 0, 0, NULL}
};
@ -3269,9 +3270,24 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
int maximum = vshCommandOptBool(cmd, "maximum");
int config = vshCommandOptBool(cmd, "config");
int live = vshCommandOptBool(cmd, "live");
int flags = ((maximum ? VIR_DOMAIN_VCPU_MAXIMUM : 0) |
(config ? VIR_DOMAIN_AFFECT_CONFIG : 0) |
(live ? VIR_DOMAIN_AFFECT_LIVE : 0));
int current = vshCommandOptBool(cmd, "current");
int flags = 0;
if (current) {
if (live || config) {
vshError(ctl, "%s", _("--current must be specified exclusively"));
return false;
}
flags = VIR_DOMAIN_AFFECT_CURRENT;
} else {
if (config)
flags |= VIR_DOMAIN_AFFECT_CONFIG;
if (live)
flags |= VIR_DOMAIN_AFFECT_LIVE;
/* neither option is specified */
if (!live && !config && !maximum)
flags = -1;
}
if (!vshConnectionUsability(ctl, ctl->conn))
return false;
@ -3284,7 +3300,7 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
if (!flags) {
if (flags == -1) {
if (virDomainSetVcpus(dom, count) != 0) {
ret = false;
}
@ -3294,6 +3310,8 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
if (maximum) {
vshDebug(ctl, VSH_ERR_DEBUG, "--maximum flag was given\n");
flags |= VIR_DOMAIN_VCPU_MAXIMUM;
/* If neither the --config nor --live flags were given, OR
if just the --live flag was given, we need to error out
warning the user that the --maximum flag can only be used

View File

@ -740,7 +740,7 @@ exclusive. If no flag is specified, behavior is different depending
on hypervisor.
=item B<setvcpus> I<domain-id> I<count> optional I<--maximum> I<--config>
I<--live>
I<--live> I<--current>
Change the number of virtual CPUs active in a guest domain. By default,
this command works on active guest domains. To change the settings for an
@ -758,7 +758,9 @@ If I<--live> is specified, the guest domain must be active, and the change
takes place immediately. Both the I<--config> and I<--live> flags may be
specified together if supported by the hypervisor.
When neither the I<--config> nor I<--live> flags are given, the I<--live>
If I<--current> is specified, affect the current guest state.
When no flags are given, the I<--live>
flag is assumed and the guest domain must be active. In this situation it
is up to the hypervisor whether the I<--config> flag is also assumed, and
therefore whether the XML configuration is adjusted to make the change