218e99
From 24775aa5499bad8dea9c067908390c778b4ede6c Mon Sep 17 00:00:00 2001
218e99
From: Markus Armbruster <armbru@redhat.com>
218e99
Date: Wed, 18 Sep 2013 09:31:04 +0200
218e99
Subject: [PATCH 20/29] exec: Reduce ifdeffery around -mem-path
218e99
218e99
RH-Author: Markus Armbruster <armbru@redhat.com>
218e99
Message-id: <1379496669-22778-4-git-send-email-armbru@redhat.com>
218e99
Patchwork-id: 54423
218e99
O-Subject: [PATCH 7.0 qemu-kvm 3/8] exec: Reduce ifdeffery around -mem-path
218e99
Bugzilla: 1009328
218e99
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
218e99
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
218e99
From: Markus Armbruster <armbru@redhat.com>
218e99
218e99
Instead of spreading its ifdeffery everywhere, confine it to
218e99
qemu_ram_alloc_from_ptr().  Everywhere else, simply test block->fd,
218e99
which is non-negative exactly when block uses -mem-path.
218e99
218e99
Signed-off-by: Markus Armbruster <armbru@redhat.com>
218e99
Acked-by: Laszlo Ersek <lersek@redhat.com>
218e99
Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
218e99
Message-id: 1375276272-15988-4-git-send-email-armbru@redhat.com
218e99
Signed-off-by: Anthony Liguori <anthony@codemonkey.ws>
218e99
(cherry picked from commit 3435f39513a104294b5e3bbf3612047028d25cfc)
218e99
---
218e99
 exec.c                 | 37 ++++++++++---------------------------
218e99
 include/exec/cpu-all.h |  2 --
218e99
 2 files changed, 10 insertions(+), 29 deletions(-)
218e99
218e99
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
218e99
---
218e99
 exec.c                 |   37 ++++++++++---------------------------
218e99
 include/exec/cpu-all.h |    2 --
218e99
 2 files changed, 10 insertions(+), 29 deletions(-)
218e99
218e99
diff --git a/exec.c b/exec.c
218e99
index ef8d311..32ed61c 100644
218e99
--- a/exec.c
218e99
+++ b/exec.c
218e99
@@ -1045,6 +1045,7 @@ ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host,
218e99
 
218e99
     size = TARGET_PAGE_ALIGN(size);
218e99
     new_block = g_malloc0(sizeof(*new_block));
218e99
+    new_block->fd = -1;
218e99
 
218e99
     /* This assumes the iothread lock is taken here too.  */
218e99
     qemu_mutex_lock_ramlist();
218e99
@@ -1149,17 +1150,9 @@ void qemu_ram_free(ram_addr_t addr)
218e99
                 ;
218e99
             } else if (xen_enabled()) {
218e99
                 xen_invalidate_map_cache_entry(block->host);
218e99
-            } else if (mem_path) {
218e99
-#if defined (__linux__) && !defined(TARGET_S390X)
218e99
-                if (block->fd) {
218e99
-                    munmap(block->host, block->length);
218e99
-                    close(block->fd);
218e99
-                } else {
218e99
-                    qemu_anon_ram_free(block->host, block->length);
218e99
-                }
218e99
-#else
218e99
-                abort();
218e99
-#endif
218e99
+            } else if (block->fd >= 0) {
218e99
+                munmap(block->host, block->length);
218e99
+                close(block->fd);
218e99
             } else {
218e99
                 qemu_anon_ram_free(block->host, block->length);
218e99
             }
218e99
@@ -1190,25 +1183,15 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
218e99
             } else {
218e99
                 flags = MAP_FIXED;
218e99
                 munmap(vaddr, length);
218e99
-                if (mem_path) {
218e99
-#if defined(__linux__) && !defined(TARGET_S390X)
218e99
-                    if (block->fd) {
218e99
+                if (block->fd >= 0) {
218e99
 #ifdef MAP_POPULATE
218e99
-                        flags |= mem_prealloc ? MAP_POPULATE | MAP_SHARED :
218e99
-                            MAP_PRIVATE;
218e99
+                    flags |= mem_prealloc ? MAP_POPULATE | MAP_SHARED :
218e99
+                        MAP_PRIVATE;
218e99
 #else
218e99
-                        flags |= MAP_PRIVATE;
218e99
-#endif
218e99
-                        area = mmap(vaddr, length, PROT_READ | PROT_WRITE,
218e99
-                                    flags, block->fd, offset);
218e99
-                    } else {
218e99
-                        flags |= MAP_PRIVATE | MAP_ANONYMOUS;
218e99
-                        area = mmap(vaddr, length, PROT_READ | PROT_WRITE,
218e99
-                                    flags, -1, 0);
218e99
-                    }
218e99
-#else
218e99
-                    abort();
218e99
+                    flags |= MAP_PRIVATE;
218e99
 #endif
218e99
+                    area = mmap(vaddr, length, PROT_READ | PROT_WRITE,
218e99
+                                flags, block->fd, offset);
218e99
                 } else {
218e99
 #if defined(TARGET_S390X) && defined(CONFIG_KVM)
218e99
                     flags |= MAP_SHARED | MAP_ANONYMOUS;
218e99
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
218e99
index e9c3717..c369b25 100644
218e99
--- a/include/exec/cpu-all.h
218e99
+++ b/include/exec/cpu-all.h
218e99
@@ -476,9 +476,7 @@ typedef struct RAMBlock {
218e99
      * Writes must take both locks.
218e99
      */
218e99
     QTAILQ_ENTRY(RAMBlock) next;
218e99
-#if defined(__linux__) && !defined(TARGET_S390X)
218e99
     int fd;
218e99
-#endif
218e99
 } RAMBlock;
218e99
 
218e99
 typedef struct RAMList {
218e99
-- 
218e99
1.7.1
218e99