From patchwork Wed May 14 09:43:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hu Tao X-Patchwork-Id: 348717 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C2785140096 for ; Wed, 14 May 2014 19:56:45 +1000 (EST) Received: from localhost ([::1]:50590 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkVvU-0006pf-KE for incoming@patchwork.ozlabs.org; Wed, 14 May 2014 05:56:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33305) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkVlA-0005sY-4k for qemu-devel@nongnu.org; Wed, 14 May 2014 05:46:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkVl5-0006Lv-9w for qemu-devel@nongnu.org; Wed, 14 May 2014 05:46:00 -0400 Received: from [59.151.112.132] (port=7463 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkVl4-0006Gp-Ta for qemu-devel@nongnu.org; Wed, 14 May 2014 05:45:55 -0400 X-IronPort-AV: E=Sophos;i="4.97,1051,1389715200"; d="scan'208";a="30507063" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 14 May 2014 17:43:07 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s4E9jc3Q002799; Wed, 14 May 2014 17:45:38 +0800 Received: from G08FNSTD100614.fnst.cn.fujitsu.com (10.167.226.102) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Wed, 14 May 2014 17:45:49 +0800 From: Hu Tao To: Date: Wed, 14 May 2014 17:43:24 +0800 Message-ID: X-Mailer: git-send-email 1.8.5.2.229.g4448466 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.226.102] X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Cc: Paolo Bonzini , Igor Mammedov Subject: [Qemu-devel] [PATCH v3.2 20/31] hostmem: separate allocation from UserCreatable complete method X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paolo Bonzini This allows the superclass to set various policies on the memory region that the subclass creates. Signed-off-by: Paolo Bonzini Signed-off-by: Hu Tao --- 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); }; /**