From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwxNc-0007ot-F4 for qemu-devel@nongnu.org; Tue, 17 Jun 2014 13:41:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WwxNW-0004x9-V8 for qemu-devel@nongnu.org; Tue, 17 Jun 2014 13:41:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10794) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WwxNW-0004wy-Nk for qemu-devel@nongnu.org; Tue, 17 Jun 2014 13:41:02 -0400 Date: Tue, 17 Jun 2014 20:40:59 +0300 From: "Michael S. Tsirkin" Message-ID: <1403021756-15960-78-git-send-email-mst@redhat.com> References: <1403021756-15960-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1403021756-15960-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PULL 077/103] memory: move mem_path handling to memory_region_allocate_system_memory List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , Eduardo Habkost , Juan Quintela , Hu Tao , Orit Wasserman , Anthony Liguori , Jan Kiszka , Paolo Bonzini , =?us-ascii?B?PT9VVEYtOD9xP0FuZHJlYXM9MjBGPUMzPUE0cmJlcj89?= , Wanlong Gao From: Paolo Bonzini Like the previous patch did in exec.c, split memory_region_init_ram and memory_region_init_ram_from_file, and push mem_path one step further up. Other RAM regions than system memory will now be backed by regular RAM. Also, boards that do not use memory_region_allocate_system_memory will not support -mem-path anymore. This can be changed before the patches are merged by migrating boards to use the function. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao Acked-by: Michael S. Tsirkin --- include/exec/memory.h | 18 ++++++++++++++++++ exec.c | 10 ++-------- memory.c | 21 ++++++++++++++++----- numa.c | 11 ++++++++++- 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/include/exec/memory.h b/include/exec/memory.h index ab11c32..58c3fe4 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -311,6 +311,24 @@ void memory_region_init_ram(MemoryRegion *mr, const char *name, uint64_t size); +#ifdef __linux__ +/** + * memory_region_init_ram_from_file: Initialize RAM memory region with a + * mmap-ed backend. + * + * @mr: the #MemoryRegion to be initialized. + * @owner: the object that tracks the region's reference count + * @name: the name of the region. + * @size: size of the region. + * @path: the path in which to allocate the RAM. + */ +void memory_region_init_ram_from_file(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + const char *path); +#endif + /** * memory_region_init_ram_ptr: Initialize RAM memory region from a * user-provided pointer. Accesses into the diff --git a/exec.c b/exec.c index 98878a4..f9effe9 100644 --- a/exec.c +++ b/exec.c @@ -1090,14 +1090,6 @@ error: } return NULL; } -#else -static void *file_ram_alloc(RAMBlock *block, - ram_addr_t memory, - const char *path) -{ - fprintf(stderr, "-mem-path not supported on this host\n"); - exit(1); -} #endif static ram_addr_t find_ram_offset(ram_addr_t size) @@ -1271,6 +1263,7 @@ static ram_addr_t ram_block_add(RAMBlock *new_block) return new_block->offset; } +#ifdef __linux__ ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, const char *mem_path) { @@ -1299,6 +1292,7 @@ ram_addr_t qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, new_block->host = file_ram_alloc(new_block, size, mem_path); return ram_block_add(new_block); } +#endif ram_addr_t qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr) diff --git a/memory.c b/memory.c index 43b90eb..6192377 100644 --- a/memory.c +++ b/memory.c @@ -1017,13 +1017,24 @@ void memory_region_init_ram(MemoryRegion *mr, mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - if (mem_path) { - mr->ram_addr = qemu_ram_alloc_from_file(size, mr, mem_path); - } else { - mr->ram_addr = qemu_ram_alloc(size, mr); - } + mr->ram_addr = qemu_ram_alloc(size, mr); } +#ifdef __linux__ +void memory_region_init_ram_from_file(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + const char *path) +{ + memory_region_init(mr, owner, name, size); + mr->ram = true; + mr->terminates = true; + mr->destructor = memory_region_destructor_ram; + mr->ram_addr = qemu_ram_alloc_from_file(size, mr, path); +} +#endif + void memory_region_init_ram_ptr(MemoryRegion *mr, Object *owner, const char *name, diff --git a/numa.c b/numa.c index b24bb9d..7c36bb5 100644 --- a/numa.c +++ b/numa.c @@ -228,7 +228,16 @@ static void allocate_system_memory_nonnuma(MemoryRegion *mr, Object *owner, const char *name, uint64_t ram_size) { - memory_region_init_ram(mr, owner, name, ram_size); + if (mem_path) { +#ifdef __linux__ + memory_region_init_ram_from_file(mr, owner, name, ram_size, mem_path); +#else + fprintf(stderr, "-mem-path not supported on this host\n"); + exit(1); +#endif + } else { + memory_region_init_ram(mr, owner, name, ram_size); + } vmstate_register_ram_global(mr); } -- MST