]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
tools: fix the wrong check when use virsh setvcpus --maximum
authorLuyao Huang <lhuang@redhat.com>
Fri, 20 Mar 2015 14:39:03 +0000 (15:39 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 4 May 2015 08:26:57 +0000 (10:26 +0200)
The --maximum option wasn't properly parsed and the equivalent flag
wasn't set.  Fix this bug and also rewrite the way we check this option
by using new macro.  The new approach is that --maximum requires
--config, no other combination is allowed, because they don't make sense.

The new error will be:

 # virsh setvcpus test --maximum 10
 error: Option --config is required by option --maximum

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1204033

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
tools/virsh-domain.c
tools/virsh.pod

index 4b627e1cd251f13235e55b55dd7ef80842025c79..861766f540f03d8316bb9f70989de64a0bc13955 100644 (file)
@@ -6657,15 +6657,16 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
     VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
     VSH_EXCLUSIVE_OPTIONS_VAR(guest, config);
 
+    VSH_REQUIRE_OPTION_VAR(maximum, config);
+
     if (config)
         flags |= VIR_DOMAIN_AFFECT_CONFIG;
     if (live)
         flags |= VIR_DOMAIN_AFFECT_LIVE;
     if (guest)
         flags |= VIR_DOMAIN_VCPU_GUEST;
-    /* none of the options were specified */
-    if (!current && flags == 0)
-        flags = -1;
+    if (maximum)
+        flags |= VIR_DOMAIN_VCPU_MAXIMUM;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -6675,30 +6676,11 @@ cmdSetvcpus(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if (flags == -1) {
+    /* none of the options were specified */
+    if (!current && flags == 0) {
         if (virDomainSetVcpus(dom, count) != 0)
             goto cleanup;
     } else {
-        /* If the --maximum flag was given, we need to ensure only the
-           --config flag is in effect as well */
-        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
-               with the --config flag */
-            if (live || !config) {
-
-                /* Warn the user about the invalid flag combination */
-                vshError(ctl, _("--maximum must be used with --config only"));
-                goto cleanup;
-            }
-        }
-
-        /* Apply the virtual cpu changes */
         if (virDomainSetVcpusFlags(dom, count, flags) < 0)
             goto cleanup;
     }
index f8496f32f530a587a1b8dc9ed58fff6f0c68997f..1bb655bdd7ee2ca9430f5ed2b2a90adef090db76 100644 (file)
@@ -2181,7 +2181,8 @@ and may require guest agent to be configured in the guest.
 
 The I<--maximum> flag controls the maximum number of virtual cpus that can
 be hot-plugged the next time the domain is booted.  As such, it must only be
-used with the I<--config> flag, and not with the I<--live> flag.
+used with the I<--config> flag, and not with the I<--live> or the I<--current>
+flag.
 
 =item B<shutdown> I<domain> [I<--mode MODE-LIST>]