]> xenbits.xensource.com Git - libvirt.git/commitdiff
setmaxmem: add the new options to "virsh setmaxmem" command
authorTaku Izumi <izumi.taku@jp.fujitsu.com>
Fri, 8 Apr 2011 05:08:52 +0000 (14:08 +0900)
committerEric Blake <eblake@redhat.com>
Sat, 9 Apr 2011 02:22:12 +0000 (20:22 -0600)
This patch adds the new options (--live, --config, and --current) to
"virsh setmaxmem" command. The behavior of above options is the same
as that of "virsh setmem".  When the --config option is specified, a
modification is effective for the persistent domain, while the --live
option is specified, a modification is effective for an active
domain. The --current option is specified, it affects a current
domain.

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

index e186c757c7685ac0d2f932b962af6a92058b02f9..2e350214412db39e89857c638d0273aaea6e7746 100644 (file)
@@ -3020,6 +3020,9 @@ static const vshCmdInfo info_setmaxmem[] = {
 static const vshCmdOptDef opts_setmaxmem[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {"kilobytes", VSH_OT_INT, VSH_OFLAG_REQ, N_("maximum memory limit in kilobytes")},
+    {"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}
 };
 
@@ -3030,6 +3033,25 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
     virDomainInfo info;
     int kilobytes = 0;
     int ret = TRUE;
+    int config = vshCommandOptBool(cmd, "config");
+    int live = vshCommandOptBool(cmd, "live");
+    int current = vshCommandOptBool(cmd, "current");
+    int flags = VIR_DOMAIN_MEM_MAXIMUM;
+
+    if (current) {
+        if (live || config) {
+            vshError(ctl, "%s", _("--current must be specified exclusively"));
+            return FALSE;
+        }
+    } else {
+        if (config)
+            flags |= VIR_DOMAIN_MEM_CONFIG;
+        if (live)
+            flags |= VIR_DOMAIN_MEM_LIVE;
+        /* neither option is specified */
+        if (!live && !config)
+            flags = -1;
+    }
 
     if (!vshConnectionUsability(ctl, ctl->conn))
         return FALSE;
@@ -3054,9 +3076,16 @@ cmdSetmaxmem(vshControl *ctl, const vshCmd *cmd)
         return FALSE;
     }
 
-    if (virDomainSetMaxMemory(dom, kilobytes) != 0) {
-        vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
-        ret = FALSE;
+    if (flags == -1) {
+        if (virDomainSetMaxMemory(dom, kilobytes) != 0) {
+            vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
+            ret = FALSE;
+        }
+    } else {
+        if (virDomainSetMemoryFlags(dom, kilobytes, flags) < 0) {
+            vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
+            ret = FALSE;
+        }
     }
 
     virDomainFree(dom);
@@ -9279,7 +9308,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if(xmlNodeDump(xml_buf, xml, obj->nodesetval->nodeTab[i], 0, 0) < 0){
+    if (xmlNodeDump(xml_buf, xml, obj->nodesetval->nodeTab[i], 0, 0) < 0) {
         vshError(ctl, "%s", _("Failed to create XML"));
         goto cleanup;
     }
@@ -9538,7 +9567,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if(xmlNodeDump(xml_buf, xml, obj->nodesetval->nodeTab[i], 0, 0) < 0){
+    if (xmlNodeDump(xml_buf, xml, obj->nodesetval->nodeTab[i], 0, 0) < 0) {
         vshError(ctl, "%s", _("Failed to create XML"));
         goto cleanup;
     }
@@ -10971,7 +11000,7 @@ vshCmddefSearch(const char *cmdname)
 
     for (g = cmdGroups; g->name; g++) {
         for (c = g->commands; c->name; c++) {
-            if(STREQ(c->name, cmdname))
+            if (STREQ(c->name, cmdname))
                 return c;
         }
     }
@@ -10985,7 +11014,7 @@ vshCmdGrpSearch(const char *grpname)
     const vshCmdGrp *g;
 
     for (g = cmdGroups; g->name; g++) {
-        if(STREQ(g->name, grpname) || STREQ(g->keyword, grpname))
+        if (STREQ(g->name, grpname) || STREQ(g->keyword, grpname))
             return g;
     }
 
index 16c37ff894fb9dc7596ade89589cd8949b78d05c..9c42008301903890accf6a3e7751e70894b1b397 100644 (file)
@@ -602,12 +602,18 @@ 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.
 
-=item B<setmaxmem> I<domain-id> B<kilobytes>
+=item B<setmaxmem> I<domain-id> B<kilobytes> optional I<--config> I<--live>
+I<--current>
 
-Change the maximum memory allocation limit for an inactive guest domain.
+Change the maximum memory allocation limit for a guest domain.
+If I<--live> is specified, affect a running guest.
+If I<--config> is specified, affect the next boot of a persistent guest.
+If I<--current> is specified, affect the current guest state.
+Both I<--live> and I<--current> flags may be given, but I<--current> is
+exclusive. If no flag is specified, behavior is different depending
+on hypervisor.
 
-This command works for at least the Xen and vSphere/ESX hypervisors,
-but not for QEMU/KVM.
+This command works for at least the Xen, QEMU/KVM and vSphere/ESX hypervisors.
 
 Some hypervisors require a larger granularity than kilobytes, rounding up
 requests that are not an even multiple of the desired amount.  vSphere/ESX
@@ -615,8 +621,6 @@ is one of these, requiring the parameter to be evenly divisible by 4MB.  For
 vSphere/ESX, 263168 (257MB) would be rounded up because it's not a multiple
 of 4MB, while 266240 (260MB) is valid without rounding.
 
-Note, to change the maximum memory allocation for a QEMU/KVM guest domain,
-use the virsh B<edit> command instead to update its XML <memory> element.
 
 =item B<memtune> I<domain-id> optional I<--hard-limit> B<kilobytes>
 optional I<--soft-limit> B<kilobytes> optional I<--swap-hard-limit>