[libvirt] [PATCH] qemu: fix can use setmaxmem to change the maximum memory biger than max memory

Luyao Huang lhuang at redhat.com
Tue Mar 24 14:12:37 UTC 2015


When call qemuDomainSetMemoryFlags() to change maximum memory size, we
do not check if the maximum memory is biger than the max memory, this will
make vm disappear after libvirtd restart if we set a big maximum memory.

Add a check for this, also fix a typos issue.

Signed-off-by: Luyao Huang <lhuang at redhat.com>
---
 src/conf/domain_conf.c | 2 +-
 src/qemu/qemu_driver.c | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d633f93..0d4b165 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16646,7 +16646,7 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
 
     if (src->mem.memory_slots != dst->mem.memory_slots) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Target domain memory slots count '%u' doesn't match source '%u"),
+                       _("Target domain memory slots count '%u' doesn't match source '%u'"),
                        dst->mem.memory_slots, src->mem.memory_slots);
         goto error;
     }
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 3518dec..86b87af 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2324,6 +2324,13 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
                                  "nodes cannot be modified with this API"));
                 goto endjob;
             }
+            if (persistentDef->mem.max_memory &&
+                persistentDef->mem.max_memory < newmem) {
+                virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                               _("cannot set maximum memory size biger than "
+                                 "the max memory size"));
+                goto endjob;
+            }
 
             virDomainDefSetMemoryInitial(persistentDef, newmem);
 
-- 
1.8.3.1




More information about the libvir-list mailing list