diff options
Diffstat (limited to 'backends/rng-egd.c')
-rw-r--r-- | backends/rng-egd.c | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/backends/rng-egd.c b/backends/rng-egd.c index 0f6d0af..e2f8189 100644 --- a/backends/rng-egd.c +++ b/backends/rng-egd.c @@ -23,7 +23,7 @@ typedef struct RngEgd { RngBackend parent; - CharDriverState *chr; + CharBackend chr; char *chr_name; } RngEgd; @@ -42,7 +42,7 @@ static void rng_egd_request_entropy(RngBackend *b, RngRequest *req) /* XXX this blocks entire thread. Rewrite to use * qemu_chr_fe_write and background I/O callbacks */ - qemu_chr_fe_write_all(s->chr, header, sizeof(header)); + qemu_chr_fe_write_all(s->chr.chr, header, sizeof(header)); size -= len; } @@ -86,6 +86,7 @@ static void rng_egd_chr_read(void *opaque, const uint8_t *buf, int size) static void rng_egd_opened(RngBackend *b, Error **errp) { RngEgd *s = RNG_EGD(b); + CharDriverState *chr; if (s->chr_name == NULL) { error_setg(errp, QERR_INVALID_PARAMETER_VALUE, @@ -93,21 +94,23 @@ static void rng_egd_opened(RngBackend *b, Error **errp) return; } - s->chr = qemu_chr_find(s->chr_name); - if (s->chr == NULL) { + chr = qemu_chr_find(s->chr_name); + if (chr == NULL) { error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND, "Device '%s' not found", s->chr_name); return; } - - if (qemu_chr_fe_claim(s->chr) != 0) { + if (qemu_chr_fe_claim(chr) != 0) { error_setg(errp, QERR_DEVICE_IN_USE, s->chr_name); return; } + if (!qemu_chr_fe_init(&s->chr, chr, errp)) { + return; + } /* FIXME we should resubmit pending requests when the CDS reconnects. */ - qemu_chr_add_handlers(s->chr, rng_egd_chr_can_read, rng_egd_chr_read, - NULL, s); + qemu_chr_add_handlers(s->chr.chr, rng_egd_chr_can_read, + rng_egd_chr_read, NULL, s); } static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp) @@ -127,8 +130,8 @@ static char *rng_egd_get_chardev(Object *obj, Error **errp) { RngEgd *s = RNG_EGD(obj); - if (s->chr && s->chr->label) { - return g_strdup(s->chr->label); + if (s->chr.chr && s->chr.chr->label) { + return g_strdup(s->chr.chr->label); } return NULL; @@ -145,9 +148,9 @@ static void rng_egd_finalize(Object *obj) { RngEgd *s = RNG_EGD(obj); - if (s->chr) { - qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, NULL); - qemu_chr_fe_release(s->chr); + if (s->chr.chr) { + qemu_chr_add_handlers(s->chr.chr, NULL, NULL, NULL, NULL); + qemu_chr_fe_release(s->chr.chr); } g_free(s->chr_name); |