]> git.proxmox.com Git - mirror_qemu.git/blame - backends/rng.c
s390x/skeys: Fix instance and class size
[mirror_qemu.git] / backends / rng.c
CommitLineData
a9b7b2ad
AL
1/*
2 * QEMU Random Number Generator Backend
3 *
4 * Copyright IBM, Corp. 2012
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
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.
11 */
12
dccfcd0e 13#include "sysemu/rng.h"
7b1b5d19 14#include "qapi/qmp/qerror.h"
269e09f3 15#include "qom/object_interfaces.h"
a9b7b2ad
AL
16
17void rng_backend_request_entropy(RngBackend *s, size_t size,
18 EntropyReceiveFunc *receive_entropy,
19 void *opaque)
20{
21 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
22
23 if (k->request_entropy) {
24 k->request_entropy(s, size, receive_entropy, opaque);
25 }
26}
27
28void rng_backend_cancel_requests(RngBackend *s)
29{
30 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
31
32 if (k->cancel_requests) {
33 k->cancel_requests(s);
34 }
35}
36
37static bool rng_backend_prop_get_opened(Object *obj, Error **errp)
38{
39 RngBackend *s = RNG_BACKEND(obj);
40
41 return s->opened;
42}
43
57d3e1b3 44static void rng_backend_complete(UserCreatable *uc, Error **errp)
a9b7b2ad 45{
57d3e1b3 46 object_property_set_bool(OBJECT(uc), true, "opened", errp);
a9b7b2ad
AL
47}
48
49static void rng_backend_prop_set_opened(Object *obj, bool value, Error **errp)
50{
51 RngBackend *s = RNG_BACKEND(obj);
52 RngBackendClass *k = RNG_BACKEND_GET_CLASS(s);
65cd9064 53 Error *local_err = NULL;
a9b7b2ad
AL
54
55 if (value == s->opened) {
56 return;
57 }
58
59 if (!value && s->opened) {
c6bd8c70 60 error_setg(errp, QERR_PERMISSION_DENIED);
a9b7b2ad
AL
61 return;
62 }
63
64 if (k->opened) {
65cd9064
MA
65 k->opened(s, &local_err);
66 if (local_err) {
67 error_propagate(errp, local_err);
68 return;
69 }
a9b7b2ad
AL
70 }
71
65cd9064 72 s->opened = true;
a9b7b2ad
AL
73}
74
75static void rng_backend_init(Object *obj)
76{
77 object_property_add_bool(obj, "opened",
78 rng_backend_prop_get_opened,
79 rng_backend_prop_set_opened,
80 NULL);
81}
82
57d3e1b3
IM
83static void rng_backend_class_init(ObjectClass *oc, void *data)
84{
85 UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc);
86
87 ucc->complete = rng_backend_complete;
88}
89
8c43a6f0 90static const TypeInfo rng_backend_info = {
a9b7b2ad
AL
91 .name = TYPE_RNG_BACKEND,
92 .parent = TYPE_OBJECT,
93 .instance_size = sizeof(RngBackend),
94 .instance_init = rng_backend_init,
95 .class_size = sizeof(RngBackendClass),
57d3e1b3 96 .class_init = rng_backend_class_init,
a9b7b2ad 97 .abstract = true,
269e09f3
IM
98 .interfaces = (InterfaceInfo[]) {
99 { TYPE_USER_CREATABLE },
100 { }
101 }
a9b7b2ad
AL
102};
103
104static void register_types(void)
105{
106 type_register_static(&rng_backend_info);
107}
108
109type_init(register_types);