aboutsummaryrefslogtreecommitdiff
path: root/backends/hostmem.c
diff options
context:
space:
mode:
authorHu Tao <hutao@cn.fujitsu.com>2014-06-10 19:15:19 +0800
committerMichael S. Tsirkin <mst@redhat.com>2014-06-19 18:44:20 +0300
commitbd9262d95f9172a5f4897aeea341c219a6c6cf96 (patch)
tree32f8d88adff799545a71253f6cbdb08cbb60ba08 /backends/hostmem.c
parent58f4662c6c98a9fd05519745661177792d7aeede (diff)
downloadqemu-bd9262d95f9172a5f4897aeea341c219a6c6cf96.zip
qemu-bd9262d95f9172a5f4897aeea341c219a6c6cf96.tar.gz
qemu-bd9262d95f9172a5f4897aeea341c219a6c6cf96.tar.bz2
hostmem: separate allocation from UserCreatable complete method
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 <pbonzini@redhat.com> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Acked-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'backends/hostmem.c')
-rw-r--r--backends/hostmem.c20
1 files changed, 20 insertions, 0 deletions
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,