mirror of
https://github.com/qemu/qemu.git
synced 2025-08-16 23:02:44 +00:00
char: replace avail_connections
No need to count the users of a CharDriverState, it can rely on the fact of whether there is a CharBackend associated or if there is enough space in the muxer. Simplify and fold chr_mux_new_fe() in qemu_chr_fe_init() since there is a single user now. Also switch from fprintf to raising error instead. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20161022100951.19562-5-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
58fa54947e
commit
3aef23d7d8
@ -468,7 +468,6 @@ CharDriverState *uart_hci_init(void)
|
|||||||
s->chr.opaque = s;
|
s->chr.opaque = s;
|
||||||
s->chr.chr_write = csrhci_write;
|
s->chr.chr_write = csrhci_write;
|
||||||
s->chr.chr_ioctl = csrhci_ioctl;
|
s->chr.chr_ioctl = csrhci_ioctl;
|
||||||
s->chr.avail_connections = 1;
|
|
||||||
|
|
||||||
s->hci = qemu_next_hci();
|
s->hci = qemu_next_hci();
|
||||||
s->hci->opaque = s;
|
s->hci->opaque = s;
|
||||||
|
@ -110,7 +110,6 @@ struct CharDriverState {
|
|||||||
int logfd;
|
int logfd;
|
||||||
int be_open;
|
int be_open;
|
||||||
int explicit_be_open;
|
int explicit_be_open;
|
||||||
int avail_connections;
|
|
||||||
int is_mux;
|
int is_mux;
|
||||||
guint fd_in_tag;
|
guint fd_in_tag;
|
||||||
bool replay;
|
bool replay;
|
||||||
|
34
qemu-char.c
34
qemu-char.c
@ -808,20 +808,6 @@ static void mux_chr_free(struct CharDriverState *chr)
|
|||||||
g_free(d);
|
g_free(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mux_chr_new_fe(CharDriverState *chr, CharBackend *be, Error **errp)
|
|
||||||
{
|
|
||||||
MuxDriver *d = chr->opaque;
|
|
||||||
|
|
||||||
if (d->mux_cnt >= MAX_MUX) {
|
|
||||||
fprintf(stderr, "Cannot add I/O handlers, MUX array is full\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
d->backends[d->mux_cnt] = be;
|
|
||||||
|
|
||||||
return d->mux_cnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void mux_chr_set_handlers(CharDriverState *chr, GMainContext *context)
|
static void mux_chr_set_handlers(CharDriverState *chr, GMainContext *context)
|
||||||
{
|
{
|
||||||
MuxDriver *d = chr->opaque;
|
MuxDriver *d = chr->opaque;
|
||||||
@ -902,10 +888,16 @@ bool qemu_chr_fe_init(CharBackend *b, CharDriverState *s, Error **errp)
|
|||||||
int tag = 0;
|
int tag = 0;
|
||||||
|
|
||||||
if (s->is_mux) {
|
if (s->is_mux) {
|
||||||
tag = mux_chr_new_fe(s, b, errp);
|
MuxDriver *d = s->opaque;
|
||||||
if (tag < 0) {
|
|
||||||
return false;
|
if (d->mux_cnt >= MAX_MUX) {
|
||||||
|
goto unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d->backends[d->mux_cnt] = b;
|
||||||
|
tag = d->mux_cnt++;
|
||||||
|
} else if (s->be) {
|
||||||
|
goto unavailable;
|
||||||
} else {
|
} else {
|
||||||
s->be = b;
|
s->be = b;
|
||||||
}
|
}
|
||||||
@ -913,8 +905,11 @@ bool qemu_chr_fe_init(CharBackend *b, CharDriverState *s, Error **errp)
|
|||||||
b->fe_open = false;
|
b->fe_open = false;
|
||||||
b->tag = tag;
|
b->tag = tag;
|
||||||
b->chr = s;
|
b->chr = s;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
unavailable:
|
||||||
|
error_setg(errp, QERR_DEVICE_IN_USE, s->label);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool qemu_chr_is_busy(CharDriverState *s)
|
static bool qemu_chr_is_busy(CharDriverState *s)
|
||||||
@ -933,7 +928,6 @@ void qemu_chr_fe_deinit(CharBackend *b)
|
|||||||
|
|
||||||
if (b->chr) {
|
if (b->chr) {
|
||||||
qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, true);
|
qemu_chr_fe_set_handlers(b, NULL, NULL, NULL, NULL, NULL, true);
|
||||||
b->chr->avail_connections++;
|
|
||||||
b->chr->be = NULL;
|
b->chr->be = NULL;
|
||||||
if (b->chr->is_mux) {
|
if (b->chr->is_mux) {
|
||||||
MuxDriver *d = b->chr->opaque;
|
MuxDriver *d = b->chr->opaque;
|
||||||
@ -4782,8 +4776,6 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
|
|||||||
}
|
}
|
||||||
|
|
||||||
chr->label = g_strdup(id);
|
chr->label = g_strdup(id);
|
||||||
chr->avail_connections =
|
|
||||||
(backend->type == CHARDEV_BACKEND_KIND_MUX) ? MAX_MUX : 1;
|
|
||||||
if (!chr->filename) {
|
if (!chr->filename) {
|
||||||
chr->filename = g_strdup(ChardevBackendKind_lookup[backend->type]);
|
chr->filename = g_strdup(ChardevBackendKind_lookup[backend->type]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user