[libvirt] [PATCH 5/5] setmaxmem: add the new options to "virsh setmaxmem" command

Taku Izumi izumi.taku at jp.fujitsu.com
Fri Mar 18 02:50:42 UTC 2011


This patch adds the new options (--live and --config) to "virsh setmaxmem"
command. The behavior of above options is the same as that of "virsh setmem".
When the --config option is specified, a modofication is effective for the
persistent domain, while --live option is specified, a modification is effective
for an active domain.


Signed-off-by: Taku Izumi <izumi.taku at jp.fujitsu.com>
---
 tools/virsh.c   |   27 ++++++++++++++++++++++++---
 tools/virsh.pod |   12 ++++++------
 2 files changed, 30 insertions(+), 9 deletions(-)

Index: libvirt/tools/virsh.c
===================================================================
--- libvirt.orig/tools/virsh.c
+++ libvirt/tools/virsh.c
@@ -2998,6 +2998,8 @@ 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")},
     {NULL, 0, 0, NULL}
 };

@@ -3008,6 +3010,18 @@ cmdSetmaxmem(vshControl *ctl, const vshC
     virDomainInfo info;
     int 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;
@@ -3032,9 +3046,16 @@ cmdSetmaxmem(vshControl *ctl, const vshC
         return FALSE;
     }

-    if (virDomainSetMaxMemory(dom, kilobytes) != 0) {
-        vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
-        ret = FALSE;
+    if (!flags) {
+        if (virDomainSetMaxMemory(dom, kilobytes) != 0) {
+            vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
+            ret = FALSE;
+        }
+    } else {
+        if (virDomainSetMaxMemoryFlags(dom, kilobytes, flags) < 0) {
+            vshError(ctl, "%s", _("Unable to change MaxMemorySize"));
+            ret = FALSE;
+        }
     }

     virDomainFree(dom);
Index: libvirt/tools/virsh.pod
===================================================================
--- libvirt.orig/tools/virsh.pod
+++ libvirt/tools/virsh.pod
@@ -593,12 +593,14 @@ rounds the parameter up unless the kB ar
 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>

-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.
+Both flags may be given. If neither flag is given, I<--live> is assumed.

-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
@@ -606,8 +608,6 @@ is one of these, requiring the parameter
 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>




More information about the libvir-list mailing list