[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2.1 22/28] hostmem: separate allocation from Use
From: |
Hu Tao |
Subject: |
Re: [Qemu-devel] [PATCH 2.1 22/28] hostmem: separate allocation from UserCreatable complete method |
Date: |
Fri, 7 Mar 2014 15:08:33 +0800 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Tue, Mar 04, 2014 at 03:00:50PM +0100, Paolo Bonzini wrote:
> This allows the superclass to set various policies on the memory
> region that the subclass creates.
>
> Suggested-by: Igor Mammedov <address@hidden>
> 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 8c6ea5d..7e91665 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 06817dd..7d6199f 100644
> --- a/backends/hostmem.c
> +++ b/backends/hostmem.c
> @@ -69,8 +69,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_init is not implemented for type [%s]",
s/memory_init/memory_alloc/ ?
> + object_get_typename(OBJECT(uc)));
> + return;
> + }
> +
> + bc->alloc(backend, errp);
> }
>
> MemoryRegion *
> diff --git a/include/sysemu/hostmem.h b/include/sysemu/hostmem.h
> index bc3ffb3..4738107 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);
> };
>
> /**
> --
> 1.8.5.3
>
- Re: [Qemu-devel] [PATCH 2.1 16/28] memory: reorganize file-based allocation, (continued)
- [Qemu-devel] [PATCH 2.1 17/28] memory: move mem_path handling to memory_region_allocate_system_memory, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 18/28] memory: add error propagation to file-based RAM allocation, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 19/28] memory: move preallocation code out of exec.c, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 20/28] memory: move RAM_PREALLOC_MASK to exec.c, rename, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 21/28] hostmem: add file-based HostMemoryBackend, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 22/28] hostmem: separate allocation from UserCreatable complete method, Paolo Bonzini, 2014/03/04
- Re: [Qemu-devel] [PATCH 2.1 22/28] hostmem: separate allocation from UserCreatable complete method,
Hu Tao <=
- [Qemu-devel] [PATCH 2.1 23/28] hostmem: add merge and dump properties, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 26/28] configure: add Linux libnuma detection, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 24/28] hostmem: allow preallocation of any memory region, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 27/28] hostmem: add properties for NUMA memory policy, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 25/28] hostmem: add property to map memory with MAP_SHARED, Paolo Bonzini, 2014/03/04
- [Qemu-devel] [PATCH 2.1 28/28] qmp: add query-memdev, Paolo Bonzini, 2014/03/04