[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 22/34] hostmem: separate allocation from UserCrea
From: |
address@hidden |
Subject: |
[Qemu-devel] [PATCH v3 22/34] hostmem: separate allocation from UserCreatable complete method |
Date: |
Wed, 26 Mar 2014 10:37:00 +0000 |
From: Paolo Bonzini <address@hidden>
This allows the superclass to set various policies on the memory
region that the subclass creates.
Signed-off-by: Paolo Bonzini <address@hidden>
---
backends/hostmem-file.c | 9 ++++-----
backends/hostmem-ram.c | 8 +++-----
backends/hostmem.c | 12 ++++++++++--
include/sysemu/hostmem.h | 2 ++
4 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index e22bcef..75a165a 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -30,10 +30,9 @@ struct HostMemoryBackendFile {
};
static void
-file_backend_memory_init(UserCreatable *uc, Error **errp)
+file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
- HostMemoryBackend *backend = MEMORY_BACKEND(uc);
- HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(uc);
+ HostMemoryBackendFile *fb = MEMORY_BACKEND_FILE(backend);
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
@@ -58,9 +57,9 @@ file_backend_memory_init(UserCreatable *uc, Error **errp)
static void
file_backend_class_init(ObjectClass *oc, void *data)
{
- UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+ HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
- ucc->complete = file_backend_memory_init;
+ bc->alloc = file_backend_memory_alloc;
}
static char *get_mem_path(Object *o, Error **errp)
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index ce06fbe..e4d244a 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -16,10 +16,8 @@
static void
-ram_backend_memory_init(UserCreatable *uc, Error **errp)
+ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
{
- HostMemoryBackend *backend = MEMORY_BACKEND(uc);
-
if (!backend->size) {
error_setg(errp, "can't create backend with size 0");
return;
@@ -33,9 +31,9 @@ ram_backend_memory_init(UserCreatable *uc, Error **errp)
static void
ram_backend_class_init(ObjectClass *oc, void *data)
{
- UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+ HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
- ucc->complete = ram_backend_memory_init;
+ bc->alloc = ram_backend_memory_alloc;
}
static const TypeInfo ram_backend_info = {
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 6f26605..5b2117d 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -68,8 +68,16 @@ static void host_memory_backend_finalize(Object *obj)
static void
host_memory_backend_memory_init(UserCreatable *uc, Error **errp)
{
- error_setg(errp, "memory_init is not implemented for type [%s]",
- object_get_typename(OBJECT(uc)));
+ HostMemoryBackend *backend = MEMORY_BACKEND(uc);
+ HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
+
+ if (!bc->alloc) {
+ error_setg(errp, "memory_alloc is not implemented for type [%s]",
+ object_get_typename(OBJECT(uc)));
+ return;
+ }
+
+ bc->alloc(backend, errp);
}
MemoryRegion *
diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
index 8b1eb7d..9a9e0cd 100644
--- a/include/sysemu/hostmem.h
+++ b/include/sysemu/hostmem.h
@@ -33,6 +33,8 @@ typedef struct HostMemoryBackendClass HostMemoryBackendClass;
*/
struct HostMemoryBackendClass {
ObjectClass parent_class;
+
+ void (*alloc)(HostMemoryBackend *backend, Error **errp);
};
/**
--
1.8.5.2.229.g4448466
- [Qemu-devel] [PATCH v3 01/34] NUMA: move numa related code to new file numa.c, (continued)
- [Qemu-devel] [PATCH v3 01/34] NUMA: move numa related code to new file numa.c, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 12/34] pc: pass QEMUMachineInitArgs to pc_memory_init, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 16/34] memory: reorganize file-based allocation, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 15/34] numa: add -numa node,memdev= option, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 09/34] vl: redo -object parsing, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 05/34] NUMA: expand MAX_NODES from 64 to 128, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 18/34] memory: add error propagation to file-based RAM allocation, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 08/34] vl: convert -m to QemuOpts, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 14/34] add memdev backend infrastructure, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 21/34] hostmem: add file-based HostMemoryBackend, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 22/34] hostmem: separate allocation from UserCreatable complete method,
address@hidden <=
- [Qemu-devel] [PATCH v3 26/34] configure: add Linux libnuma detection, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 24/34] hostmem: allow preallocation of any memory region, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 27/34] hostmem: add properties for NUMA memory policy, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 11/34] qmp: improve error reporting for -object and object-add, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 32/34] qom: introduce object_property_get_enum and object_property_get_uint16List, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 20/34] memory: move RAM_PREALLOC_MASK to exec.c, rename, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 25/34] hostmem: add property to map memory with MAP_SHARED, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 23/34] hostmem: add merge and dump properties, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 34/34] hmp: add info memdev, address@hidden, 2014/03/26
- [Qemu-devel] [PATCH v3 28/34] hw: switch all boards to use memory_region_allocate_system_memory, address@hidden, 2014/03/26