virsh: make vcpucount use --current consistently

Rename the existing --current flag to the new name --active,
while adding a new flag --current to expose the new
VIR_DOMAIN_AFFECT_CURRENT flag of virDomainGetVcpusFlags.

For backwards compability, the output does not change (even
though the label "current" no longer matches the spelling of
the option that would trigger that number in isolation), and
we accept "--current --live" as an undocumented synonym for
"--active --live" to avoid breaking any existing clients.

* tools/virsh.c (cmdVcpucount): Add --active flag, and rearrange
existing flag handling to expose VIR_DOMAIN_AFFECT_CURRENT support.
* tools/virsh.pod (vcpucount): Document this.
This commit is contained in:
Eric Blake 2011-07-18 16:01:48 -06:00
parent 59d042871c
commit 4b7a8e9c0d
2 changed files with 71 additions and 33 deletions

View File

@ -3043,9 +3043,11 @@ static const vshCmdInfo info_vcpucount[] = {
static const vshCmdOptDef opts_vcpucount[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"maximum", VSH_OT_BOOL, 0, N_("get maximum cap on vcpus")},
{"current", VSH_OT_BOOL, 0, N_("get current vcpu usage")},
{"config", VSH_OT_BOOL, 0, N_("get value to be used on next boot")},
{"active", VSH_OT_BOOL, 0, N_("get number of currently active vcpus")},
{"live", VSH_OT_BOOL, 0, N_("get value from running domain")},
{"config", VSH_OT_BOOL, 0, N_("get value to be used on next boot")},
{"current", VSH_OT_BOOL, 0,
N_("get value according to current domain state")},
{NULL, 0, 0, NULL}
};
@ -3055,31 +3057,50 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom;
bool ret = true;
int maximum = vshCommandOptBool(cmd, "maximum");
int current = vshCommandOptBool(cmd, "current");
int active = vshCommandOptBool(cmd, "active");
int config = vshCommandOptBool(cmd, "config");
int live = vshCommandOptBool(cmd, "live");
bool all = maximum + current + config + live == 0;
int current = vshCommandOptBool(cmd, "current");
bool all = maximum + active + current + config + live == 0;
int count;
if (maximum && current) {
vshError(ctl, "%s",
_("--maximum and --current cannot both be specified"));
return false;
}
if (config && live) {
vshError(ctl, "%s",
_("--config and --live cannot both be specified"));
return false;
}
/* We want one of each pair of mutually exclusive options; that
* is, use of flags requires exactly two options. */
if (maximum + current + config + live == 1) {
vshError(ctl,
_("when using --%s, either --%s or --%s must be specified"),
(maximum ? "maximum" : current ? "current"
: config ? "config" : "live"),
maximum + current ? "config" : "maximum",
maximum + current ? "live" : "current");
* is, use of flags requires exactly two options. We reject the
* use of more than 2 flags later on. */
if (maximum + active + current + config + live == 1) {
if (maximum || active) {
vshError(ctl,
_("when using --%s, one of --config, --live, or --current "
"must be specified"),
maximum ? "maximum" : "active");
} else {
vshError(ctl,
_("when using --%s, either --maximum or --active must be "
"specified"),
(current ? "current" : config ? "config" : "live"));
}
return false;
}
/* Backwards compatibility: prior to 0.9.4,
* VIR_DOMAIN_AFFECT_CURRENT was unsupported, and --current meant
* the opposite of --maximum. Translate the old '--current
* --live' into the new '--active --live', while treating the new
* '--maximum --current' correctly rather than rejecting it as
* '--maximum --active'. */
if (!maximum && !active && current) {
current = false;
active = true;
}
if (maximum && active) {
vshError(ctl, "%s",
_("--maximum and --active cannot both be specified"));
return false;
}
if (current + config + live > 1) {
vshError(ctl, "%s",
_("--config, --live, and --current are mutually exclusive"));
return false;
}
@ -3090,8 +3111,20 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
return false;
/* In all cases, try the new API first; if it fails because we are
* talking to an older client, try a fallback API before giving
* up. */
* talking to an older client, generally we try a fallback API
* before giving up. --current requires the new API, since we
* don't know whether the domain is running or inactive. */
if (current) {
count = virDomainGetVcpusFlags(dom,
maximum ? VIR_DOMAIN_VCPU_MAXIMUM : 0);
if (count < 0) {
virshReportError(ctl);
ret = false;
} else {
vshPrint(ctl, "%d\n", count);
}
}
if (all || (maximum && config)) {
count = virDomainGetVcpusFlags(dom, (VIR_DOMAIN_VCPU_MAXIMUM |
VIR_DOMAIN_AFFECT_CONFIG));
@ -3143,7 +3176,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
last_error = NULL;
}
if (all || (current && config)) {
if (all || (active && config)) {
count = virDomainGetVcpusFlags(dom, VIR_DOMAIN_AFFECT_CONFIG);
if (count < 0 && (last_error->code == VIR_ERR_NO_SUPPORT
|| last_error->code == VIR_ERR_INVALID_ARG)) {
@ -3180,7 +3213,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
last_error = NULL;
}
if (all || (current && live)) {
if (all || (active && live)) {
count = virDomainGetVcpusFlags(dom, VIR_DOMAIN_AFFECT_LIVE);
if (count < 0 && (last_error->code == VIR_ERR_NO_SUPPORT
|| last_error->code == VIR_ERR_INVALID_ARG)) {

View File

@ -894,20 +894,25 @@ to undefine a domain with a managed save image will fail.
NOTE: For an inactive domain, the domain name or UUID must be used as the
I<domain-id>.
=item B<vcpucount> I<domain-id> [{I<--maximum> | I<--current>}
{I<--config> | I<--live>}]
=item B<vcpucount> I<domain-id> [{I<--maximum> | I<--active>}
{I<--config> | I<--live> | I<--current>}]
Print information about the virtual cpu counts of the given
I<domain-id>. If no flags are specified, all possible counts are
listed in a table; otherwise, the output is limited to just the
numeric value requested.
numeric value requested. For historical reasons, the table
lists the label "current" on the rows that can be queried in isolation
via the I<--active> flag, rather than relating to the I<--current> flag.
I<--maximum> requests information on the maximum cap of vcpus that a
domain can add via B<setvcpus>, while I<--current> shows the current
domain can add via B<setvcpus>, while I<--active> shows the current
usage; these two flags cannot both be specified. I<--config>
requests information regarding the next time the domain will be
booted, while I<--live> requires a running domain and lists current
values; these two flags cannot both be specified.
requires a persistent domain and requests information regarding the next
time the domain will be booted, I<--live> requires a running domain and
lists current values, and I<--current> queries according to the current
state of the domain (corresponding to I<--live> if running, or
I<--config> if inactive); these three flags are mutually exclusive.
Thus, this command always takes exactly zero or two flags.
=item B<vcpuinfo> I<domain-id>