char: Slightly better error reporting when chardev is in use

Both

    $ qemu-system-x86_64 -chardev null,id=chr0,mux=on -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0

and

    $ qemu-system-x86_64 -chardev null,id=chr0 -mon chardev=chr0 -mon chardev=chr0
fail with

    qemu-system-x86_64: -mon chardev=chr0: Device 'chr0' is in use

Improve to

    qemu-system-x86_64: -mon chardev=chr0: too many uses of multiplexed chardev 'chr0' (maximum is 4)

and

    qemu-system-x86_64: -mon chardev=chr0: chardev 'chr0' is already in use

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
Markus Armbruster 2024-03-06 09:15:05 +01:00 committed by Michael Tokarev
parent 9bc9e95119
commit d0bad43c4c

View File

@ -199,13 +199,18 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
MuxChardev *d = MUX_CHARDEV(s); MuxChardev *d = MUX_CHARDEV(s);
if (d->mux_cnt >= MAX_MUX) { if (d->mux_cnt >= MAX_MUX) {
goto unavailable; error_setg(errp,
"too many uses of multiplexed chardev '%s'"
" (maximum is " stringify(MAX_MUX) ")",
s->label);
return false;
} }
d->backends[d->mux_cnt] = b; d->backends[d->mux_cnt] = b;
tag = d->mux_cnt++; tag = d->mux_cnt++;
} else if (s->be) { } else if (s->be) {
goto unavailable; error_setg(errp, "chardev '%s' is already in use", s->label);
return false;
} else { } else {
s->be = b; s->be = b;
} }
@ -215,10 +220,6 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
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;
} }
void qemu_chr_fe_deinit(CharBackend *b, bool del) void qemu_chr_fe_deinit(CharBackend *b, bool del)