[PATCH 3/3] setvcpus: add "--current" option to "virsh setvcpus"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 tools/virsh.c   |   26 ++++++++++++++++++++++----
 tools/virsh.pod |    6 ++++--
 2 files changed, 26 insertions(+), 6 deletions(-)

Index: libvirt/tools/virsh.c
===================================================================
--- libvirt.orig/tools/virsh.c
+++ libvirt/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 vshCm
     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 vshCm
         goto cleanup;
     }
 
-    if (!flags) {
+    if (flags == -1) {
         if (virDomainSetVcpus(dom, count) != 0) {
             ret = false;
         }
@@ -3294,6 +3310,8 @@ cmdSetvcpus(vshControl *ctl, const vshCm
         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
Index: libvirt/tools/virsh.pod
===================================================================
--- libvirt.orig/tools/virsh.pod
+++ libvirt/tools/virsh.pod
@@ -740,7 +740,7 @@ exclusive. If no flag is specified, beha
 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 dom
 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 neither 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]