render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
7a3408
From ab98ed58d652aff099c8ed1269d01ed23ea81342 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <ab98ed58d652aff099c8ed1269d01ed23ea81342@dist-git>
7a3408
From: Peter Krempa <pkrempa@redhat.com>
7a3408
Date: Tue, 22 Sep 2015 16:59:45 +0200
7a3408
Subject: [PATCH] conf: Don't always recalculate initial memory size from NUMA
7a3408
 size totals
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1252685
7a3408
7a3408
When implementing memory hotplug I've opted to recalculate the initial
7a3408
memory size (contents of the <memory> element) as a sum of the sizes of
7a3408
NUMA nodes when NUMA was enabled. This was based on an assumption that
7a3408
qemu did not allow starting when the NUMA node size total didn't equal
7a3408
to the initial memory size. Unfortunately the check was introduced to
7a3408
qemu just lately.
7a3408
7a3408
This patch uses the new XML parser flag to decide whether it's safe to
7a3408
update the memory size total from the NUMA cell sizes or not.
7a3408
7a3408
As an additional improvement we now report an error in case when the
7a3408
size of hotplug memory would exceed the total memory size.
7a3408
7a3408
The rest of the changes assures that the function is called with correct
7a3408
flags.
7a3408
7a3408
(cherry picked from commit 0fed5a7bc79865fe00fd5a328a2e520934c52ff7)
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/conf/domain_conf.c  | 37 +++++++++++++++++++++++++++++--------
7a3408
 src/conf/domain_conf.h  |  1 +
7a3408
 src/qemu/qemu_command.c |  3 ++-
7a3408
 3 files changed, 32 insertions(+), 9 deletions(-)
7a3408
7a3408
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
7a3408
index 3625310..f5320fe 100644
7a3408
--- a/src/conf/domain_conf.c
7a3408
+++ b/src/conf/domain_conf.c
7a3408
@@ -3640,15 +3640,34 @@ virDomainDefRemoveDuplicateMetadata(virDomainDefPtr def)
7a3408
 
7a3408
 
7a3408
 static int
7a3408
-virDomainDefPostParseMemory(virDomainDefPtr def)
7a3408
+virDomainDefPostParseMemory(virDomainDefPtr def,
7a3408
+                            unsigned int parseFlags)
7a3408
 {
7a3408
     size_t i;
7a3408
+    unsigned long long numaMemory = 0;
7a3408
+    unsigned long long hotplugMemory = 0;
7a3408
 
7a3408
-    if ((def->mem.initial_memory = virDomainNumaGetMemorySize(def->numa)) == 0) {
7a3408
-        def->mem.initial_memory = def->mem.total_memory;
7a3408
+    /* Attempt to infer the initial memory size from the sum NUMA memory sizes
7a3408
+     * in case ABI updates are allowed or the <memory> element wasn't specified */
7a3408
+    if (def->mem.total_memory == 0 ||
7a3408
+        parseFlags & VIR_DOMAIN_DEF_PARSE_ABI_UPDATE)
7a3408
+        numaMemory = virDomainNumaGetMemorySize(def->numa);
7a3408
 
7a3408
+    if (numaMemory) {
7a3408
+        virDomainDefSetMemoryInitial(def, numaMemory);
7a3408
+    } else {
7a3408
+        /* calculate the sizes of hotplug memory */
7a3408
         for (i = 0; i < def->nmems; i++)
7a3408
-            def->mem.initial_memory -= def->mems[i]->size;
7a3408
+            hotplugMemory += def->mems[i]->size;
7a3408
+
7a3408
+        if (hotplugMemory > def->mem.total_memory) {
7a3408
+            virReportError(VIR_ERR_XML_ERROR, "%s",
7a3408
+                           _("Total size of memory devices exceeds the total "
7a3408
+                             "memory size"));
7a3408
+            return -1;
7a3408
+        }
7a3408
+
7a3408
+        virDomainDefSetMemoryInitial(def, def->mem.total_memory - hotplugMemory);
7a3408
     }
7a3408
 
7a3408
     if (virDomainDefGetMemoryInitial(def) == 0) {
7a3408
@@ -3684,7 +3703,8 @@ virDomainDefPostParseMemory(virDomainDefPtr def)
7a3408
 
7a3408
 static int
7a3408
 virDomainDefPostParseInternal(virDomainDefPtr def,
7a3408
-                              virCapsPtr caps ATTRIBUTE_UNUSED)
7a3408
+                              virCapsPtr caps ATTRIBUTE_UNUSED,
7a3408
+                              unsigned int parseFlags)
7a3408
 {
7a3408
     size_t i;
7a3408
 
7a3408
@@ -3695,7 +3715,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
7a3408
         return -1;
7a3408
     }
7a3408
 
7a3408
-    if (virDomainDefPostParseMemory(def) < 0)
7a3408
+    if (virDomainDefPostParseMemory(def, parseFlags) < 0)
7a3408
         return -1;
7a3408
 
7a3408
     /*
7a3408
@@ -3993,6 +4013,7 @@ virDomainDefPostParseDeviceIterator(virDomainDefPtr def ATTRIBUTE_UNUSED,
7a3408
 int
7a3408
 virDomainDefPostParse(virDomainDefPtr def,
7a3408
                       virCapsPtr caps,
7a3408
+                      unsigned int parseFlags,
7a3408
                       virDomainXMLOptionPtr xmlopt)
7a3408
 {
7a3408
     int ret;
7a3408
@@ -4018,7 +4039,7 @@ virDomainDefPostParse(virDomainDefPtr def,
7a3408
         return ret;
7a3408
 
7a3408
 
7a3408
-    if ((ret = virDomainDefPostParseInternal(def, caps)) < 0)
7a3408
+    if ((ret = virDomainDefPostParseInternal(def, caps, parseFlags)) < 0)
7a3408
         return ret;
7a3408
 
7a3408
     return 0;
7a3408
@@ -16278,7 +16299,7 @@ virDomainDefParseXML(xmlDocPtr xml,
7a3408
         goto error;
7a3408
 
7a3408
     /* callback to fill driver specific domain aspects */
7a3408
-    if (virDomainDefPostParse(def, caps, xmlopt) < 0)
7a3408
+    if (virDomainDefPostParse(def, caps, flags, xmlopt) < 0)
7a3408
         goto error;
7a3408
 
7a3408
     /* Auto-add any implied controllers which aren't present */
7a3408
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
7a3408
index 61bf963..e322adf 100644
7a3408
--- a/src/conf/domain_conf.h
7a3408
+++ b/src/conf/domain_conf.h
7a3408
@@ -2423,6 +2423,7 @@ virDomainXMLOptionGetNamespace(virDomainXMLOptionPtr xmlopt)
7a3408
 int
7a3408
 virDomainDefPostParse(virDomainDefPtr def,
7a3408
                       virCapsPtr caps,
7a3408
+                      unsigned int parseFlags,
7a3408
                       virDomainXMLOptionPtr xmlopt);
7a3408
 
7a3408
 static inline bool
7a3408
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
7a3408
index 3fd695b..701ccc3 100644
7a3408
--- a/src/qemu/qemu_command.c
7a3408
+++ b/src/qemu/qemu_command.c
7a3408
@@ -13672,7 +13672,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
7a3408
     if (virDomainDefAddImplicitControllers(def) < 0)
7a3408
         goto error;
7a3408
 
7a3408
-    if (virDomainDefPostParse(def, qemuCaps, xmlopt) < 0)
7a3408
+    if (virDomainDefPostParse(def, qemuCaps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE,
7a3408
+                              xmlopt) < 0)
7a3408
         goto error;
7a3408
 
7a3408
     if (cmd->num_args || cmd->num_env) {
7a3408
-- 
7a3408
2.5.3
7a3408