diff --git a/tools/virsh.c b/tools/virsh.c index bd6fea7cd2..b8f357bb32 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -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 diff --git a/tools/virsh.pod b/tools/virsh.pod index 1a98ec1d70..2686c9afce 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -740,7 +740,7 @@ exclusive. If no flag is specified, behavior is different depending on hypervisor. =item B I I 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