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}
};
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"));
+ /* We want one of each pair of mutually exclusive options; that
+ * 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;
}
- if (config && live) {
+
+ /* 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",
- _("--config and --live cannot both be specified"));
+ _("--maximum and --active 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");
+ if (current + config + live > 1) {
+ vshError(ctl, "%s",
+ _("--config, --live, and --current are mutually exclusive"));
return false;
}
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));
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)) {
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)) {
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>