7a3408
From 22c900d292345ae1b4a0babc75b0b30bfea6f10f Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <22c900d292345ae1b4a0babc75b0b30bfea6f10f@dist-git>
7a3408
From: Martin Kletzander <mkletzan@redhat.com>
7a3408
Date: Tue, 6 Oct 2015 15:20:35 +0200
7a3408
Subject: [PATCH] qemu: Use memory-backing-file only when needed
7a3408
7a3408
We are using memory-backing-file even when it's not needed, for example
7a3408
if user requests hugepages for memory backing, but does not specify any
7a3408
pagesize or memory node pinning.  This causes migrations to fail when
7a3408
migrating from older libvirt that did not do this.  So similarly to
7a3408
commit 7832fac84741d65e851dbdbfaf474785cbfdcf3c which does it for
7a3408
memory-backend-ram, this commit makes is more generic and
7a3408
backend-agnostic, so the backend is not used if there is no specific
7a3408
pagesize of hugepages requested, no nodeset the memory node should be
7a3408
bound to, no memory access change required, and so on.
7a3408
7a3408
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1266856
7a3408
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
(cherry picked from commit 41c2aa729f0af084ede95ee9a06219a2dd5fb5df)
7a3408
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_command.c                            | 35 ++++++++++------------
7a3408
 .../qemuxml2argv-hugepages-numa.args               |  6 ++--
7a3408
 2 files changed, 19 insertions(+), 22 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
7a3408
index 1d020d2..9c80e0c 100644
7a3408
--- a/src/qemu/qemu_command.c
7a3408
+++ b/src/qemu/qemu_command.c
7a3408
@@ -4835,12 +4835,6 @@ qemuBuildMemoryBackendStr(unsigned long long size,
7a3408
     }
7a3408
 
7a3408
     if (pagesize || hugepage) {
7a3408
-        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) {
7a3408
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
7a3408
-                           _("this qemu doesn't support hugepage memory backing"));
7a3408
-            goto cleanup;
7a3408
-        }
7a3408
-
7a3408
         if (pagesize) {
7a3408
             /* Now lets see, if the huge page we want to use is even mounted
7a3408
              * and ready to use */
7a3408
@@ -4919,29 +4913,32 @@ qemuBuildMemoryBackendStr(unsigned long long size,
7a3408
             goto cleanup;
7a3408
     }
7a3408
 
7a3408
-    if (!hugepage && !pagesize) {
7a3408
-
7a3408
-        if ((userNodeset || nodeSpecified || force) &&
7a3408
-            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM)) {
7a3408
+    /* If none of the following is requested... */
7a3408
+    if (!pagesize && !userNodeset && !memAccess && !nodeSpecified && !force) {
7a3408
+        /* report back that using the new backend is not necessary
7a3408
+         * to achieve the desired configuration */
7a3408
+        ret = 1;
7a3408
+    } else {
7a3408
+        /* otherwise check the required capability */
7a3408
+        if (STREQ(*backendType, "memory-backend-file") &&
7a3408
+            !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) {
7a3408
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
7a3408
+                           _("this qemu doesn't support the "
7a3408
+                             "memory-backend-file object"));
7a3408
+            goto cleanup;
7a3408
+        } else if (STREQ(*backendType, "memory-backend-ram") &&
7a3408
+                   !virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM)) {
7a3408
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
7a3408
                            _("this qemu doesn't support the "
7a3408
                              "memory-backend-ram object"));
7a3408
             goto cleanup;
7a3408
         }
7a3408
 
7a3408
-        /* report back that using the new backend is not necessary to achieve
7a3408
-         * the desired configuration */
7a3408
-        if (!userNodeset && !nodeSpecified) {
7a3408
-            *backendProps = props;
7a3408
-            props = NULL;
7a3408
-            ret = 1;
7a3408
-            goto cleanup;
7a3408
-        }
7a3408
+        ret = 0;
7a3408
     }
7a3408
 
7a3408
     *backendProps = props;
7a3408
     props = NULL;
7a3408
-    ret = 0;
7a3408
 
7a3408
  cleanup:
7a3408
     virJSONValueFree(props);
7a3408
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args
7a3408
index 37511b1..3496cf1 100644
7a3408
--- a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args
7a3408
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-numa.args
7a3408
@@ -4,9 +4,9 @@ LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=spice \
7a3408
 -M pc-i440fx-2.3 \
7a3408
 -m size=1048576k,slots=16,maxmem=1099511627776k \
7a3408
 -smp 2 \
7a3408
--object memory-backend-file,id=ram-node0,prealloc=yes,\
7a3408
-mem-path=/dev/hugepages2M/libvirt/qemu,size=1073741824 \
7a3408
--numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \
7a3408
+-mem-prealloc \
7a3408
+-mem-path /dev/hugepages2M/libvirt/qemu \
7a3408
+-numa node,nodeid=0,cpus=0-1,mem=1024 \
7a3408
 -object memory-backend-file,id=memdimm0,prealloc=yes,\
7a3408
 mem-path=/dev/hugepages1G/libvirt/qemu,size=1073741824,host-nodes=1-3,policy=bind \
7a3408
 -device pc-dimm,node=0,memdev=memdimm0,id=dimm0 \
7a3408
-- 
7a3408
2.6.1
7a3408