diff mbox

[21/38] char: move front end handlers in CharBackend

Message ID a91a1d5b-ba1f-5827-226a-ea3ce4892863@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Oct. 24, 2016, 1:40 p.m. UTC
On 22/10/2016 11:53, Marc-André Lureau wrote:
> -    if (chr->chr_can_read || chr->chr_read ||
> -        chr->chr_event || chr->handler_opaque) {
> +    if (chr->be) {
>          error_setg(errp, "Chardev '%s' is busy", id);

This doesn't work with the mux chardev.  To some extent a preexisting
bug, but made worse by this patch.  But it can be fixed easily:
diff mbox

Patch

diff --git a/qemu-char.c b/qemu-char.c
index b9330f3..6dd779f 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -915,6 +915,16 @@  unavailable:
     return false;
 }
 
+static bool qemu_chr_is_busy(CharDriverState *s)
+{
+    if (s->is_mux) {
+        MuxDriver *d = s->opaque;
+        return d->mux_cnt >= 0;
+    } else {
+        return s->be != NULL;
+    }
+}
+
 void qemu_chr_fe_deinit(CharBackend *b)
 {
     assert(b);
@@ -4807,7 +4817,7 @@  void qmp_chardev_remove(const char *id, Error **errp)
         error_setg(errp, "Chardev '%s' not found", id);
         return;
     }
-    if (chr->be) {
+    if (qemu_chr_is_busy(chr)) {
         error_setg(errp, "Chardev '%s' is busy", id);
         return;
     }