From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv4-0004X0-88 for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apwv1-0008N9-Cu for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:46 -0400 Received: from mail-qg0-x229.google.com ([2607:f8b0:400d:c04::229]:34142) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv1-0008Mf-40 for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:43 -0400 Received: by mail-qg0-x229.google.com with SMTP id c6so13190700qga.1 for ; Tue, 12 Apr 2016 04:55:42 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Tue, 12 Apr 2016 13:55:23 +0200 Message-Id: <1460462129-17363-4-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> References: <1460462129-17363-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 3/9] exec: split qemu_ram_alloc_from_file() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau Add qemu_ram_alloc_from_fd(), which can be use to allocate ramblock from fd only. Signed-off-by: Marc-André Lureau --- exec.c | 45 ++++++++++++++++++++++++++++++--------------- include/exec/ram_addr.h | 3 +++ 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/exec.c b/exec.c index 422ea3e..8675b5e 100644 --- a/exec.c +++ b/exec.c @@ -1646,14 +1646,12 @@ static void ram_block_add(RAMBlock *new_block, Error **errp) } #ifdef __linux__ -RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, - bool share, const char *mem_path, - Error **errp) +RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, + bool share, int fd, + Error **errp) { RAMBlock *new_block; Error *local_err = NULL; - int fd; - bool created; if (xen_enabled()) { error_setg(errp, "-mem-path not supported with Xen"); @@ -1677,11 +1675,6 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } - fd = file_ram_open(mem_path, memory_region_name(mr), &created, errp); - if (fd < 0) { - return NULL; - } - size = HOST_PAGE_ALIGN(size); new_block = g_malloc0(sizeof(*new_block)); new_block->mr = mr; @@ -1690,11 +1683,6 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, new_block->flags = share ? RAM_SHARED : 0; new_block->host = file_ram_alloc(new_block, size, fd, errp); if (!new_block->host) { - if (created) { - unlink(mem_path); - } - close(fd); - g_free(new_block); return NULL; } @@ -1705,6 +1693,33 @@ RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, return NULL; } return new_block; + +} + + +RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, + bool share, const char *mem_path, + Error **errp) +{ + int fd; + bool created; + RAMBlock *block; + + fd = file_ram_open(mem_path, memory_region_name(mr), &created, errp); + if (fd < 0) { + return NULL; + } + + block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp); + if (!block) { + if (created) { + unlink(mem_path); + } + close(fd); + return NULL; + } + + return block; } #endif diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 5adf7a4..153f1b2 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -97,6 +97,9 @@ void qemu_mutex_unlock_ramlist(void); RAMBlock *qemu_ram_alloc_from_file(ram_addr_t size, MemoryRegion *mr, bool share, const char *mem_path, Error **errp); +RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr, + bool share, int fd, + Error **errp); RAMBlock *qemu_ram_alloc_from_ptr(ram_addr_t size, void *host, MemoryRegion *mr, Error **errp); RAMBlock *qemu_ram_alloc(ram_addr_t size, MemoryRegion *mr, Error **errp); -- 2.5.5