]> xenbits.xensource.com Git - libvirt.git/commitdiff
setmem: add the new options to "virsh setmem" command
authorTaku Izumi <izumi.taku@jp.fujitsu.com>
Wed, 2 Mar 2011 08:13:39 +0000 (17:13 +0900)
committerEric Blake <eblake@redhat.com>
Thu, 10 Mar 2011 22:02:58 +0000 (15:02 -0700)
This patch adds the new options (--live and --config)  to "virsh setmem" command.
The behavior of above options is the same as that of "virsh setvcpus" and so on.
That is, when the --config option is specified, a modification is effective for
the persistent domain. Moreover we can modify the memory size of inactive domains
as well as that of active domains.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
tools/virsh.c
tools/virsh.pod

index 14c6d6b0b08ac0f08668ff2e4a237acd83fcfeda..3213b57b7fb2a6d4ce425605f07070b6be33f4e1 100644 (file)
@@ -2904,6 +2904,8 @@ static const vshCmdInfo info_setmem[] = {
 static const vshCmdOptDef opts_setmem[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {"kilobytes", VSH_OT_INT, VSH_OFLAG_REQ, N_("number of kilobytes of memory")},
+    {"config", VSH_OT_BOOL, 0, N_("affect next boot")},
+    {"live", VSH_OT_BOOL, 0, N_("affect running domain")},
     {NULL, 0, 0, NULL}
 };
 
@@ -2914,6 +2916,17 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
     virDomainInfo info;
     unsigned long kilobytes = 0;
     int ret = TRUE;
+    int config = vshCommandOptBool(cmd, "config");
+    int live = vshCommandOptBool(cmd, "live");
+    int flags = 0;
+
+    /* Need to use flags if config was specified, but prefer older api
+     * for live-only behavior otherwise */
+    if (config) {
+        flags = VIR_DOMAIN_MEM_CONFIG;
+        if (live)
+            flags |= VIR_DOMAIN_MEM_LIVE;
+    }
 
     if (!vshConnectionUsability(ctl, ctl->conn))
         return FALSE;
@@ -2945,8 +2958,14 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
     }
 
-    if (virDomainSetMemory(dom, kilobytes) != 0) {
-        ret = FALSE;
+    if (!flags) {
+        if (virDomainSetMemory(dom, kilobytes) != 0) {
+            ret = FALSE;
+        }
+    } else {
+        if (virDomainSetMemoryFlags(dom, kilobytes, flags) < 0) {
+            ret = FALSE;
+        }
     }
 
     virDomainFree(dom);
index a2ca3844be39765685b1786b437acd9727837dfb..7c12399ba6f95cba78c2d9c71c439e1d831c62cb 100644 (file)
@@ -578,9 +578,12 @@ Therefore, -1 is a useful shorthand for 262144.
 B<Note>: The weight and cap parameters are defined only for the
 XEN_CREDIT scheduler and are now I<DEPRECATED>.
 
-=item B<setmem> I<domain-id> B<kilobytes>
+=item B<setmem> I<domain-id> B<kilobytes> optional I<--config> I<--live>
 
-Immediately change the current memory allocation for an active guest domain.
+Change the memory allocation for a guest domain.
+If I<--live> is specified, perform a memory balloon of a running guest.
+If I<--config> is specified, affect the next boot of a persistent guest.
+Both flags may be given.  If neither flag is given, I<--live> is assumed.
 
 Some hypervisors require a larger granularity than kilobytes, and requests
 that are not an even multiple will be rounded up.  For example, vSphere/ESX
@@ -590,10 +593,6 @@ rounds the parameter up unless the kB argument is evenly divisible by 1024
 For Xen, you can only adjust the memory of a running domain if the domain is
 paravirtualized or running the PV balloon driver.
 
-Note, this command only works on active guest domains.  To change the memory
-allocation for an inactive guest domain, use the virsh B<edit> command to
-update the XML <currentMemory> element.
-
 =item B<setmaxmem> I<domain-id> B<kilobytes>
 
 Change the maximum memory allocation limit for an inactive guest domain.