migration: handle CANCELLING state in migration_completion()
[qemu/kevin.git] / backends / rng-builtin.c
blobf38dff117d150a3a80618d2d1aebfc129e6d3e85
1 /*
2 * QEMU Builtin Random Number Generator Backend
4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
5 * See the COPYING file in the top-level directory.
6 */
8 #include "qemu/osdep.h"
9 #include "sysemu/rng.h"
10 #include "qemu/main-loop.h"
11 #include "qemu/guest-random.h"
12 #include "qom/object.h"
14 OBJECT_DECLARE_SIMPLE_TYPE(RngBuiltin, RNG_BUILTIN)
16 struct RngBuiltin {
17 RngBackend parent;
18 QEMUBH *bh;
21 static void rng_builtin_receive_entropy_bh(void *opaque)
23 RngBuiltin *s = opaque;
25 while (!QSIMPLEQ_EMPTY(&s->parent.requests)) {
26 RngRequest *req = QSIMPLEQ_FIRST(&s->parent.requests);
28 qemu_guest_getrandom_nofail(req->data, req->size);
30 req->receive_entropy(req->opaque, req->data, req->size);
32 rng_backend_finalize_request(&s->parent, req);
36 static void rng_builtin_request_entropy(RngBackend *b, RngRequest *req)
38 RngBuiltin *s = RNG_BUILTIN(b);
40 qemu_bh_schedule(s->bh);
43 static void rng_builtin_init(Object *obj)
45 RngBuiltin *s = RNG_BUILTIN(obj);
47 s->bh = qemu_bh_new(rng_builtin_receive_entropy_bh, s);
50 static void rng_builtin_finalize(Object *obj)
52 RngBuiltin *s = RNG_BUILTIN(obj);
54 qemu_bh_delete(s->bh);
57 static void rng_builtin_class_init(ObjectClass *klass, void *data)
59 RngBackendClass *rbc = RNG_BACKEND_CLASS(klass);
61 rbc->request_entropy = rng_builtin_request_entropy;
64 static const TypeInfo rng_builtin_info = {
65 .name = TYPE_RNG_BUILTIN,
66 .parent = TYPE_RNG_BACKEND,
67 .instance_size = sizeof(RngBuiltin),
68 .instance_init = rng_builtin_init,
69 .instance_finalize = rng_builtin_finalize,
70 .class_init = rng_builtin_class_init,
73 static void register_types(void)
75 type_register_static(&rng_builtin_info);
78 type_init(register_types);