From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv4-0004Yp-So 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 1apwv3-0008NW-Nu for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:46 -0400 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]:34151) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apwv3-0008NS-Hn for qemu-devel@nongnu.org; Tue, 12 Apr 2016 07:55:45 -0400 Received: by mail-qg0-x236.google.com with SMTP id c6so13191479qga.1 for ; Tue, 12 Apr 2016 04:55:45 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Tue, 12 Apr 2016 13:55:24 +0200 Message-Id: <1460462129-17363-5-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 4/9] Add memory_region_init_ram_from_fd() 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 a new function to Initialize a RAM memory region with a mmap-ed file descriptor. Signed-off-by: Marc-André Lureau --- include/exec/memory.h | 20 ++++++++++++++++++++ memory.c | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index e2a3e99..017bfdd 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -399,6 +399,26 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, bool share, const char *path, Error **errp); + +/** + * memory_region_init_ram_from_fd: 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. + * @share: %true if memory must be mmaped with the MAP_SHARED flag + * @fd: the fd to mmap. + * @errp: pointer to Error*, to store an error if it happens. + */ +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp); #endif /** diff --git a/memory.c b/memory.c index f76f85d..dad99a9 100644 --- a/memory.c +++ b/memory.c @@ -1351,6 +1351,22 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, mr->ram_block = qemu_ram_alloc_from_file(size, mr, share, path, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; } + +void memory_region_init_ram_from_fd(MemoryRegion *mr, + struct Object *owner, + const char *name, + uint64_t size, + bool share, + int fd, + Error **errp) +{ + memory_region_init(mr, owner, name, size); + mr->ram = true; + mr->terminates = true; + mr->destructor = memory_region_destructor_ram; + mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share, fd, errp); + mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; +} #endif void memory_region_init_ram_ptr(MemoryRegion *mr, -- 2.5.5