qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v3.1 20/31] hostmem: separate allocation from UserCr


From: Hu Tao
Subject: [Qemu-devel] [PATCH v3.1 20/31] hostmem: separate allocation from UserCreatable complete method
Date: Tue, 6 May 2014 17:27:41 +0800

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>
Signed-off-by: Hu Tao <address@hidden>
---
 backends/hostmem-file.c  |  9 ++++-----
 backends/hostmem-ram.c   |  7 +++----
 backends/hostmem.c       | 12 ++++++++++--
 include/sysemu/hostmem.h |  2 ++
 4 files changed, 19 insertions(+), 11 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 cbf7e5a..7cbc051 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 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 d396fd8..42c98bd 100644
--- a/include/sysemu/hostmem.h
+++ b/include/sysemu/hostmem.h
@@ -32,6 +32,8 @@ typedef struct HostMemoryBackendClass HostMemoryBackendClass;
  */
 struct HostMemoryBackendClass {
     ObjectClass parent_class;
+
+    void (*alloc)(HostMemoryBackend *backend, Error **errp);
 };
 
 /**
-- 
1.8.5.2.229.g4448466




reply via email to

[Prev in Thread] Current Thread [Next in Thread]