From patchwork Mon Nov 5 12:45:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 10668141 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6979515A6 for ; Mon, 5 Nov 2018 12:46:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56E07296BE for ; Mon, 5 Nov 2018 12:46:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 46AFB296F3; Mon, 5 Nov 2018 12:46:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A585B296BE for ; Mon, 5 Nov 2018 12:46:50 +0000 (UTC) Received: from localhost ([::1]:34838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJeHJ-0007Wm-Rl for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Nov 2018 07:46:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJeG9-0006n5-M7 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 07:45:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJeG2-0000aW-QR for qemu-devel@nongnu.org; Mon, 05 Nov 2018 07:45:34 -0500 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]:43360) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gJeFw-0000BL-SE for qemu-devel@nongnu.org; Mon, 05 Nov 2018 07:45:29 -0500 Received: by mail-lf1-x141.google.com with SMTP id u18so6001105lff.10 for ; Mon, 05 Nov 2018 04:45:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=9+4xm0B1hPigXzlDjPkcNL/M/Sy3m1J3ULk/LoLr5d4=; b=CuK2xKIzX60l5UaGylco3MxBBPclMeE8g3NQGtq7yL+rJT5v+dSsvhWQnzhAp4mPH7 4yLBPu5u3FrqEvUSKoyGB6oX8aXNGpMHuG4jZrqX4tgZ/AOz2uHNysgVaN51rz/g3OhN TTpL6GDl+lYOPSl2j57AyPA4fxAPzeFECRDIpkiunCpsHHzbhfX98Tgl8bZZKJfJDrd8 HnoKJgwTlJZF8gmEn4aEBrJ8vRTplmeunQgMtGdJpZzBORzJUOL6n6T0GmaWQEVpmQ1W LV863qdN3tJpp5E+oSFFDN1Xc/W0r9TleKM2fzPbWwGQZ9Mv4iF+UnkLxzXVls7Te963 6oEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=9+4xm0B1hPigXzlDjPkcNL/M/Sy3m1J3ULk/LoLr5d4=; b=sgdbKIqMNQuTz7o1pSKI4alL8r6j1mxWX1MKY66RtJyFcvdSl0/grf2RuL3rB1UaBP fIX+GC4kghstOJtOp5Uc19RHfkucKnsGf8mM4gwwHtqLXqy24t/ahI3G9A7fs+Qo5Wr3 Yb/WzFVCkiLJaTlfm7MiHQewD1CfSTm3CgLYsW5DQYuIWfKpx5HcpuiY/HDwDRH3ppKv tbzGV63T3SFfXAcecq0KE+wVtbPnytYYvWELzcRefO6dKw/YXTT0eQGIlJjrSpq0cqo6 jumW++2jH+ZUU7b6mDnowJSfuEZsBmMs/PW5asY5BfUrCVxt/uD3NyrhBj1gIepOO4no vAGA== X-Gm-Message-State: AGRZ1gLZCF5TA+xPGBQAUjUHI96LMMoptn/ldrt20bjgmjNKm/DPiLQc g5I4q4G5BVnje+Ao2+6YAzu9cIeX X-Google-Smtp-Source: AJdET5ds5pZwsU7bbnIpVoa3YvUQZ+Bh07MJGnI6yqFcyJQwYPLeMvvzeuDMKUFL9rGDcuaXxO+rSA== X-Received: by 2002:a19:cfc6:: with SMTP id f189mr13377253lfg.102.1541421918716; Mon, 05 Nov 2018 04:45:18 -0800 (PST) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id 4-v6sm3967415ljw.84.2018.11.05.04.45.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Nov 2018 04:45:18 -0800 (PST) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Mon, 5 Nov 2018 18:45:09 +0600 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::141 Subject: [Qemu-devel] [PATCH v2 1/2] chardev: fix mess in OPENED/CLOSED events when muxed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Artem Pisarenko , =?utf-8?q?Marc-Andr=C3=A9_Lu?= =?utf-8?q?reau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When chardev is multiplexed (mux=on) there are a lot of cases, when CHR_EVENT_OPENED/CHR_EVENT_CLOSED events pairing (expected from frontend side) is broken. There are either generation of multiple repeated or extra CHR_EVENT_OPENED events, or CHR_EVENT_CLOSED just isn't generated at all (when it does with mux=off). Fix that. Signed-off-by: Artem Pisarenko --- chardev/char-fe.c | 33 ++++++++++++++++++++++++--------- chardev/char-mux.c | 16 ++++++++-------- include/chardev/char-fe.h | 18 +++++++++++++++++- 3 files changed, 49 insertions(+), 18 deletions(-) diff --git a/chardev/char-fe.c b/chardev/char-fe.c index a8931f7..b7bcbd5 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -246,14 +246,15 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del) } } -void qemu_chr_fe_set_handlers(CharBackend *b, - IOCanReadHandler *fd_can_read, - IOReadHandler *fd_read, - IOEventHandler *fd_event, - BackendChangeHandler *be_change, - void *opaque, - GMainContext *context, - bool set_open) +void qemu_chr_fe_set_handlers_full(CharBackend *b, + IOCanReadHandler *fd_can_read, + IOReadHandler *fd_read, + IOEventHandler *fd_event, + BackendChangeHandler *be_change, + void *opaque, + GMainContext *context, + bool set_open, + bool sync_state) { Chardev *s; int fe_open; @@ -285,7 +286,7 @@ void qemu_chr_fe_set_handlers(CharBackend *b, qemu_chr_fe_take_focus(b); /* We're connecting to an already opened device, so let's make sure we also get the open event */ - if (s->be_open) { + if (sync_state && s->be_open) { qemu_chr_be_event(s, CHR_EVENT_OPENED); } } @@ -295,6 +296,20 @@ void qemu_chr_fe_set_handlers(CharBackend *b, } } +void qemu_chr_fe_set_handlers(CharBackend *b, + IOCanReadHandler *fd_can_read, + IOReadHandler *fd_read, + IOEventHandler *fd_event, + BackendChangeHandler *be_change, + void *opaque, + GMainContext *context, + bool set_open) +{ + qemu_chr_fe_set_handlers_full(b, fd_can_read, fd_read, fd_event, be_change, + opaque, context, set_open, + true); +} + void qemu_chr_fe_take_focus(CharBackend *b) { if (!b->chr) { diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 6055e76..1199d32 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -283,13 +283,13 @@ void mux_chr_set_handlers(Chardev *chr, GMainContext *context) MuxChardev *d = MUX_CHARDEV(chr); /* Fix up the real driver with mux routines */ - qemu_chr_fe_set_handlers(&d->chr, - mux_chr_can_read, - mux_chr_read, - mux_chr_event, - NULL, - chr, - context, true); + qemu_chr_fe_set_handlers_full(&d->chr, + mux_chr_can_read, + mux_chr_read, + mux_chr_event, + NULL, + chr, + context, true, false); } void mux_set_focus(Chardev *chr, int focus) @@ -367,7 +367,7 @@ static int open_muxes(Chardev *chr) * mark mux as OPENED so any new FEs will immediately receive * OPENED event */ - qemu_chr_be_event(chr, CHR_EVENT_OPENED); + chr->be_open = 1; return 0; } diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index 46c997d..c1b7fd9 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -67,7 +67,7 @@ bool qemu_chr_fe_backend_connected(CharBackend *be); bool qemu_chr_fe_backend_open(CharBackend *be); /** - * qemu_chr_fe_set_handlers: + * qemu_chr_fe_set_handlers_full: * @b: a CharBackend * @fd_can_read: callback to get the amount of data the frontend may * receive @@ -79,12 +79,28 @@ bool qemu_chr_fe_backend_open(CharBackend *be); * @context: a main loop context or NULL for the default * @set_open: whether to call qemu_chr_fe_set_open() implicitely when * any of the handler is non-NULL + * @sync_state: whether to issue event callback with updated state * * Set the front end char handlers. The front end takes the focus if * any of the handler is non-NULL. * * Without associated Chardev, nothing is changed. */ +void qemu_chr_fe_set_handlers_full(CharBackend *b, + IOCanReadHandler *fd_can_read, + IOReadHandler *fd_read, + IOEventHandler *fd_event, + BackendChangeHandler *be_change, + void *opaque, + GMainContext *context, + bool set_open, + bool sync_state); + +/** + * qemu_chr_fe_set_handlers: + * + * Version of qemu_chr_fe_set_handlers_full() with sync_state = true. + */ void qemu_chr_fe_set_handlers(CharBackend *b, IOCanReadHandler *fd_can_read, IOReadHandler *fd_read,