[PATCH 8/8] virsh: support memory hotplug with guest agent in virsh

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

 



support memory hotplug with the arg --guest in virsh command 'setmem'.

fix a little bug in qemu_driver.c at the meanwhile.

Signed-off-by: Zhang Bo <oscar.zhangbo@xxxxxxxxxx>
Signed-off-by: Li Bin <binlibin.li@xxxxxxxxxx>
---
 src/libvirt-domain.c   |  5 ++++-
 src/qemu/qemu_driver.c |  3 ++-
 tools/virsh-domain.c   | 10 +++++++++-
 tools/virsh.pod        |  7 ++++++-
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 155fb92..a1250b6 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -1947,7 +1947,10 @@ virDomainSetMemory(virDomainPtr domain, unsigned long memory)
  * size rather than current memory size.
  * If VIR_DOMAIN_MEM_GUEST is set, it changes the domain's memory size inside
  * the guest instead of the hypervisor. This flag can only be used with live guests.
- * The usage of this flag may require a guest agent configured.
+ * The usage of this flag may require a guest agent configured. Note that because we
+ * hotplug memory logically by online/offline MEMORY BLOCKS, and each memory block has
+ * a size much bigger than KiB, there's a deviation with the range of (0, block_size).
+ * block_size may be 128MB or 256MB or etc., it differs on different OSes.
  *
  * Not all hypervisors can support all flag combinations.
  *
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 2a20bef..e96465c 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2397,7 +2397,8 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
             if (ret < 0)
                 goto endjob;
 
-            if (qemuAgentUpdateMemblocks(newmem_MB, memblocks, nblocks, meminfo->blockSize))
+            ret = qemuAgentUpdateMemblocks(newmem_MB, memblocks, nblocks, meminfo->blockSize);
+            if (ret < 0)
                 goto endjob;
 
             qemuDomainObjEnterAgent(vm);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index a25b7ba..ddb1cf9 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -8333,6 +8333,10 @@ static const vshCmdOptDef opts_setmem[] = {
      .type = VSH_OT_BOOL,
      .help = N_("affect current domain")
     },
+    {.name = "guest",
+     .type = VSH_OT_BOOL,
+     .help = N_("use guest agent based hotplug, by enabling/disabling memory blocks")
+    },
     {.name = NULL}
 };
 
@@ -8347,17 +8351,21 @@ cmdSetmem(vshControl *ctl, const vshCmd *cmd)
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
     bool current = vshCommandOptBool(cmd, "current");
+    bool guest = vshCommandOptBool(cmd, "guest");
     unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
 
     VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
     VSH_EXCLUSIVE_OPTIONS_VAR(current, config);
+    VSH_EXCLUSIVE_OPTIONS_VAR(guest, config);
 
     if (config)
         flags |= VIR_DOMAIN_AFFECT_CONFIG;
     if (live)
         flags |= VIR_DOMAIN_AFFECT_LIVE;
+    if (guest)
+        flags |= VIR_DOMAIN_MEM_GUEST;
     /* none of the options were specified */
-    if (!current && !live && !config)
+    if (!current && flags == 0)
         flags = -1;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 4e3f82a..534cc5e 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1988,7 +1988,7 @@ B<Examples>
   virsh send-process-signal myguest 1 SIG_HUP
 
 =item B<setmem> I<domain> B<size> [[I<--config>] [I<--live>] |
-[I<--current>]]
+[I<--current>]] [I<--guest>]
 
 Change the memory allocation for a guest domain.
 If I<--live> is specified, perform a memory balloon of a running guest.
@@ -1997,6 +1997,11 @@ If I<--current> is specified, affect the current guest state.
 Both I<--live> and I<--config> flags may be given, but I<--current> is
 exclusive. If no flag is specified, behavior is different depending
 on hypervisor.
+If I<--guest> is specified, it use guest agent based hotplug, by
+enabling/disabling memory blocks. Note that because we hotplug memory logically
+by online/offline MEMORY BLOCKS, and each memory block has a size much bigger
+than KiB, there's a deviation with the range of (0, block_size). block_size
+may be 128MB or 256MB or etc., it differs on different OSes.
 
 I<size> is a scaled integer (see B<NOTES> above); it defaults to kibibytes
 (blocks of 1024 bytes) unless you provide a suffix (and the older option
-- 
1.7.12.4


--
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]