mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
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>
This commit is contained in:
parent
becdfa00cf
commit
32a6ebecd2
14 changed files with 211 additions and 164 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue