diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-10-22 12:52:52 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-10-24 15:27:20 +0200 |
commit | 32a6ebecd2ffe82ffade5edf9e054e20cb48f281 (patch) | |
tree | b1e82e3f6eb4a28c65098015dd8114e190a064bf /backends/rng-egd.c | |
parent | becdfa00cfa2995e859ccefa4b7d72a72eb96581 (diff) |
char: remaining switch to CharBackend in frontend
Similar to previous change, for the remaining CharDriverState front ends
users.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20161022095318.17775-13-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
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 0f6d0af278..e2f8189d62 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); |