[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/9] Add memory_region_init_ram_from_fd()
From: |
marcandre . lureau |
Subject: |
[Qemu-devel] [PATCH 4/9] Add memory_region_init_ram_from_fd() |
Date: |
Tue, 12 Apr 2016 13:55:24 +0200 |
From: Marc-André Lureau <address@hidden>
Add a new function to Initialize a RAM memory region with a mmap-ed file
descriptor.
Signed-off-by: Marc-André Lureau <address@hidden>
---
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
- [Qemu-devel] [PATCH 0/9] RFC: add memfd memory backend, marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 1/9] exec: check kvm mmu notifiers earlier, marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 2/9] exec: split file_ram_alloc(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 3/9] exec: split qemu_ram_alloc_from_file(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 5/9] RFC: ivshmem: use ram_from_fd(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 4/9] Add memory_region_init_ram_from_fd(),
marcandre . lureau <=
- [Qemu-devel] [PATCH 6/9] exec: remove qemu_set_ram_fd(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 7/9] memfd: split qemu_memfd_alloc(), marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 8/9] Add memfd based hostmem, marcandre . lureau, 2016/04/12
- [Qemu-devel] [PATCH 9/9] tests: use memfd in vhost-user-test, marcandre . lureau, 2016/04/12