Received: from eggs.gnu.org ([2001:4830:134:3::10]:37596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1budyV-0004xO-6S for qemu-devel@nongnu.org; Thu, 13 Oct 2016 07:15:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1budyT-0006Du-4Q for qemu-devel@nongnu.org; Thu, 13 Oct 2016 07:14:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56164) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1budyS-0006Di-Re for qemu-devel@nongnu.org; Thu, 13 Oct 2016 07:14:57 -0400 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 13 Oct 2016 15:14:41 +0400 Message-Id: <20161013111449.29387-2-marcandre.lureau@redhat.com> In-Reply-To: <20161013111449.29387-1-marcandre.lureau@redhat.com> References: <20161013111449.29387-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 1/9] Revert "char: use a fixed idx for child muxed chr" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, berrange@redhat.com, imbrenda@linux.vnet.ibm.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= That commit mis-used mux char: the frontend are multiplexed, not the backend. Fix the regression preventing "c-a c" to switch the focus. The following patches will fix the crash (when leaving or removing frontend) by tracking frontends with handler tags. This reverts commit 949055a2549afc4cde06b7972072c7288bb43722. Signed-off-by: Marc-Andr=C3=A9 Lureau --- qemu-char.c | 22 +++++++--------------- include/sysemu/char.h | 1 - 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 721ce21..d83a896 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -165,7 +165,6 @@ CharDriverState *qemu_chr_alloc(ChardevCommon *backen= d, Error **errp) CharDriverState *chr =3D g_malloc0(sizeof(CharDriverState)); qemu_mutex_init(&chr->chr_write_lock); =20 - chr->mux_idx =3D -1; if (backend->has_logfile) { int flags =3D O_WRONLY | O_CREAT; if (backend->has_logappend && @@ -739,25 +738,17 @@ static void mux_chr_update_read_handler(CharDriverS= tate *chr, GMainContext *context) { MuxDriver *d =3D chr->opaque; - int idx; =20 if (d->mux_cnt >=3D MAX_MUX) { fprintf(stderr, "Cannot add I/O handlers, MUX array is full\n"); return; } - - if (chr->mux_idx =3D=3D -1) { - chr->mux_idx =3D d->mux_cnt++; - } - - idx =3D chr->mux_idx; - d->ext_opaque[idx] =3D chr->handler_opaque; - d->chr_can_read[idx] =3D chr->chr_can_read; - d->chr_read[idx] =3D chr->chr_read; - d->chr_event[idx] =3D chr->chr_event; - + d->ext_opaque[d->mux_cnt] =3D chr->handler_opaque; + d->chr_can_read[d->mux_cnt] =3D chr->chr_can_read; + d->chr_read[d->mux_cnt] =3D chr->chr_read; + d->chr_event[d->mux_cnt] =3D chr->chr_event; /* Fix up the real driver with mux routines */ - if (d->mux_cnt =3D=3D 1) { + if (d->mux_cnt =3D=3D 0) { qemu_chr_add_handlers_full(d->drv, mux_chr_can_read, mux_chr_read, mux_chr_event, @@ -766,7 +757,8 @@ static void mux_chr_update_read_handler(CharDriverSta= te *chr, if (d->focus !=3D -1) { mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT); } - d->focus =3D idx; + d->focus =3D d->mux_cnt; + d->mux_cnt++; mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_IN); } =20 diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 0d12175..19dad3f 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -107,7 +107,6 @@ struct CharDriverState { int explicit_be_open; int avail_connections; int is_mux; - int mux_idx; guint fd_in_tag; bool replay; DECLARE_BITMAP(features, QEMU_CHAR_FEATURE_LAST); --=20 2.10.0