iotests: implement pretty-print for log and qmp_log
[qemu/ericb.git] / backends / hostmem-ram.c
blob24b65d9ae365f554f126dae99ef799bce6ff166e
1 /*
2 * QEMU Host Memory Backend
4 * Copyright (C) 2013-2014 Red Hat Inc
6 * Authors:
7 * Igor Mammedov <imammedo@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "sysemu/hostmem.h"
14 #include "qapi/error.h"
15 #include "qom/object_interfaces.h"
17 #define TYPE_MEMORY_BACKEND_RAM "memory-backend-ram"
19 static void
20 ram_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
22 char *name;
24 if (!backend->size) {
25 error_setg(errp, "can't create backend with size 0");
26 return;
29 name = host_memory_backend_get_name(backend);
30 memory_region_init_ram_shared_nomigrate(&backend->mr, OBJECT(backend), name,
31 backend->size, backend->share, errp);
32 g_free(name);
35 static void
36 ram_backend_class_init(ObjectClass *oc, void *data)
38 HostMemoryBackendClass *bc = MEMORY_BACKEND_CLASS(oc);
40 bc->alloc = ram_backend_memory_alloc;
43 static const TypeInfo ram_backend_info = {
44 .name = TYPE_MEMORY_BACKEND_RAM,
45 .parent = TYPE_MEMORY_BACKEND,
46 .class_init = ram_backend_class_init,
49 static void register_types(void)
51 type_register_static(&ram_backend_info);
54 type_init(register_types);