[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 082/103] hostmem: separate allocation from UserCreata
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 082/103] hostmem: separate allocation from UserCreatable complete method |
Date: |
Tue, 17 Jun 2014 20:41:18 +0300 |
From: Hu Tao <address@hidden>
This allows the superclass to set various policies on the memory
region that the subclass creates. Drops hostmem-ram's complete method
accordingly.
Signed-off-by: Paolo Bonzini <address@hidden>
Signed-off-by: Hu Tao <address@hidden>
Acked-by: Michael S. Tsirkin <address@hidden>
---
include/sysemu/hostmem.h | 2 ++
backends/hostmem-ram.c | 7 +++----
backends/hostmem.c | 20 ++++++++++++++++++++
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
index 4fc081e..923f672 100644
--- a/include/sysemu/hostmem.h
+++ b/include/sysemu/hostmem.h
@@ -34,6 +34,8 @@ typedef struct HostMemoryBackendClass HostMemoryBackendClass;
*/
struct HostMemoryBackendClass {
ObjectClass parent_class;
+
+ void (*alloc)(HostMemoryBackend *backend, Error **errp);
};
/**
diff --git a/backends/hostmem-ram.c b/backends/hostmem-ram.c
index bba2ebc..d9a8290 100644
--- a/backends/hostmem-ram.c
+++ b/backends/hostmem-ram.c
@@ -16,9 +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);
char *path;
if (!backend->size) {
@@ -35,9 +34,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 2d9fd00..1738774 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -75,11 +75,31 @@ host_memory_backend_get_memory(HostMemoryBackend *backend,
Error **errp)
return memory_region_size(&backend->mr) ? &backend->mr : NULL;
}
+static void
+host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
+{
+ HostMemoryBackend *backend = MEMORY_BACKEND(uc);
+ HostMemoryBackendClass *bc = MEMORY_BACKEND_GET_CLASS(uc);
+
+ if (bc->alloc) {
+ bc->alloc(backend, errp);
+ }
+}
+
+static void
+host_memory_backend_class_init(ObjectClass *oc, void *data)
+{
+ UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
+
+ ucc->complete = host_memory_backend_memory_complete;
+}
+
static const TypeInfo host_memory_backend_info = {
.name = TYPE_MEMORY_BACKEND,
.parent = TYPE_OBJECT,
.abstract = true,
.class_size = sizeof(HostMemoryBackendClass),
+ .class_init = host_memory_backend_class_init,
.instance_size = sizeof(HostMemoryBackend),
.instance_init = host_memory_backend_init,
.instance_finalize = host_memory_backend_finalize,
--
MST
- [Qemu-devel] [PULL 072/103] memory: move RAM_PREALLOC_MASK to exec.c, rename, (continued)
- [Qemu-devel] [PULL 072/103] memory: move RAM_PREALLOC_MASK to exec.c, rename, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 073/103] configure: add Linux libnuma detection, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 074/103] Introduce signed range., Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 075/103] qom: introduce object_property_get_enum and object_property_get_uint16List, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 076/103] numa: add -numa node,memdev= option, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 078/103] memory: add error propagation to file-based RAM allocation, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 079/103] vl: redo -object parsing, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 080/103] pc: pass MachineState to pc_memory_init, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 081/103] backend:hostmem: replace hostmemory with host_memory, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 082/103] hostmem: separate allocation from UserCreatable complete method,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 083/103] hostmem: add file-based HostMemoryBackend, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 077/103] memory: move mem_path handling to memory_region_allocate_system_memory, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 084/103] hostmem: add merge and dump properties, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 085/103] hostmem: allow preallocation of any memory region, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 089/103] hmp: add info memdev, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 090/103] tests: fix memory leak in test of string input visitor, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 091/103] qapi: make string input visitor parse int list, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 092/103] qapi: make string output visitor parse int list, Michael S. Tsirkin, 2014/06/17