From nobody Sat Nov 8 03:36:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 15494751986271001.8609980297412; Wed, 6 Feb 2019 09:46:38 -0800 (PST) Received: from localhost ([127.0.0.1]:55309 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRHK-0007VU-HH for importer@patchew.org; Wed, 06 Feb 2019 12:46:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33871) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRFI-00068h-S0 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grRFB-0004eo-1P for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grRFA-00040y-Kz for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41B2480F7B for ; Wed, 6 Feb 2019 17:43:37 +0000 (UTC) Received: from localhost (unknown [10.36.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F6481048117; Wed, 6 Feb 2019 17:43:35 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 18:43:23 +0100 Message-Id: <20190206174328.9736-2-marcandre.lureau@redhat.com> In-Reply-To: <20190206174328.9736-1-marcandre.lureau@redhat.com> References: <20190206174328.9736-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 06 Feb 2019 17:43:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/6] char: update the mux handlers in class callback 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 , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of handling mux chardev in a special way in qemu_chr_fe_set_handlers(), we may use the chr_update_read_handler class callback instead. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- include/chardev/char-mux.h | 1 - chardev/char-fe.c | 4 ---- chardev/char-mux.c | 5 +++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/include/chardev/char-mux.h b/include/chardev/char-mux.h index 1e13187767..572cefd517 100644 --- a/include/chardev/char-mux.h +++ b/include/chardev/char-mux.h @@ -55,7 +55,6 @@ typedef struct MuxChardev { #define CHARDEV_IS_MUX(chr) \ object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX) =20 -void mux_chr_set_handlers(Chardev *chr, GMainContext *context); void mux_set_focus(Chardev *chr, int focus); void mux_chr_send_all_event(Chardev *chr, int event); =20 diff --git a/chardev/char-fe.c b/chardev/char-fe.c index a8931f7afd..f69ca18647 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -289,10 +289,6 @@ void qemu_chr_fe_set_handlers(CharBackend *b, qemu_chr_be_event(s, CHR_EVENT_OPENED); } } - - if (CHARDEV_IS_MUX(s)) { - mux_chr_set_handlers(s, context); - } } =20 void qemu_chr_fe_take_focus(CharBackend *b) diff --git a/chardev/char-mux.c b/chardev/char-mux.c index 6055e76293..9406eaf08d 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -278,7 +278,7 @@ static void char_mux_finalize(Object *obj) qemu_chr_fe_deinit(&d->chr, false); } =20 -void mux_chr_set_handlers(Chardev *chr, GMainContext *context) +static void mux_chr_update_read_handlers(Chardev *chr) { MuxChardev *d =3D MUX_CHARDEV(chr); =20 @@ -289,7 +289,7 @@ void mux_chr_set_handlers(Chardev *chr, GMainContext *c= ontext) mux_chr_event, NULL, chr, - context, true); + chr->gcontext, true); } =20 void mux_set_focus(Chardev *chr, int focus) @@ -383,6 +383,7 @@ static void char_mux_class_init(ObjectClass *oc, void *= data) cc->chr_add_watch =3D mux_chr_add_watch; cc->chr_be_event =3D mux_chr_be_event; cc->chr_machine_done =3D open_muxes; + cc->chr_update_read_handler =3D mux_chr_update_read_handlers; } =20 static const TypeInfo char_mux_type_info =3D { --=20 2.20.1.519.g8feddda32c From nobody Sat Nov 8 03:36:02 2025 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549475155190764.5239282090209; Wed, 6 Feb 2019 09:45:55 -0800 (PST) Received: from localhost ([127.0.0.1]:55300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRGZ-0006sB-Oi for importer@patchew.org; Wed, 06 Feb 2019 12:45:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grREr-0005i7-Be for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:43:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grREp-0004JX-93 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:43:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53710) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grREo-00049Y-RC for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:43:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9B31119F43 for ; Wed, 6 Feb 2019 17:43:42 +0000 (UTC) Received: from localhost (unknown [10.36.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1470649B5; Wed, 6 Feb 2019 17:43:38 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 18:43:24 +0100 Message-Id: <20190206174328.9736-3-marcandre.lureau@redhat.com> In-Reply-To: <20190206174328.9736-1-marcandre.lureau@redhat.com> References: <20190206174328.9736-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 06 Feb 2019 17:43:42 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/6] char-fe: set_handlers() needs an associated chardev 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 , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" It is futile to call qemu_chr_fe_set_handlers() without an associated chardev, because the function is doing nothing in that case, not even reporting an error, it would likely be a programming error. Let's not handle that hypothetical case. (fwiw, I introduced the check in commit 94a40fc56036b5058b0b194d9e372a22e65ce7be, that was a mistake imho) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- include/chardev/char-fe.h | 2 -- chardev/char-fe.c | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index 46c997d352..54f0d61d32 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -82,8 +82,6 @@ bool qemu_chr_fe_backend_open(CharBackend *be); * * 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(CharBackend *b, IOCanReadHandler *fd_can_read, diff --git a/chardev/char-fe.c b/chardev/char-fe.c index f69ca18647..4ec9823d34 100644 --- a/chardev/char-fe.c +++ b/chardev/char-fe.c @@ -255,14 +255,9 @@ void qemu_chr_fe_set_handlers(CharBackend *b, GMainContext *context, bool set_open) { - Chardev *s; + Chardev *s =3D b->chr; int fe_open; =20 - s =3D b->chr; - if (!s) { - return; - } - if (!opaque && !fd_can_read && !fd_read && !fd_event) { fe_open =3D 0; remove_fd_in_watch(s); --=20 2.20.1.519.g8feddda32c From nobody Sat Nov 8 03:36:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549475456622362.5112635473374; Wed, 6 Feb 2019 09:50:56 -0800 (PST) Received: from localhost ([127.0.0.1]:55895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRLV-0002JX-KE for importer@patchew.org; Wed, 06 Feb 2019 12:50:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33709) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRFB-00062X-E4 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grRFA-0004dP-9s for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53786) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grRFA-0004Dr-0J; Wed, 06 Feb 2019 12:44:16 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 49BA666961; Wed, 6 Feb 2019 17:43:50 +0000 (UTC) Received: from localhost (unknown [10.36.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FE3C608C2; Wed, 6 Feb 2019 17:43:43 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 18:43:25 +0100 Message-Id: <20190206174328.9736-4-marcandre.lureau@redhat.com> In-Reply-To: <20190206174328.9736-1-marcandre.lureau@redhat.com> References: <20190206174328.9736-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 06 Feb 2019 17:43:50 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/6] terminal3270: do not use backend timer sources 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: Cornelia Huck , Peter Xu , Halil Pasic , Christian Borntraeger , "open list:S390" , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" terminal3270 uses the front-end side of the chardev. It shouldn't create sources from backend side context (with backend functions). send_timing_mark_cb calls qemu_chr_fe_write_all() which should be thread safe. This partially reverts changes from commit 2c716ba1506769c9be2caa02f0f6d6e7c00f4304. CC: Peter Xu Signed-off-by: Marc-Andr=C3=A9 Lureau Acked-by: Cornelia Huck Reviewed-by: Paolo Bonzini --- hw/char/terminal3270.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index e9c45e55b1..35b079d5c4 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -31,7 +31,7 @@ typedef struct Terminal3270 { uint8_t outv[OUTPUT_BUFFER_SIZE]; int in_len; bool handshake_done; - GSource *timer_src; + guint timer_tag; } Terminal3270; =20 #define TYPE_TERMINAL_3270 "x-terminal3270" @@ -47,10 +47,9 @@ static int terminal_can_read(void *opaque) =20 static void terminal_timer_cancel(Terminal3270 *t) { - if (t->timer_src) { - g_source_destroy(t->timer_src); - g_source_unref(t->timer_src); - t->timer_src =3D NULL; + if (t->timer_tag) { + g_source_remove(t->timer_tag); + t->timer_tag =3D 0; } } =20 @@ -100,8 +99,7 @@ static void terminal_read(void *opaque, const uint8_t *b= uf, int size) assert(size <=3D (INPUT_BUFFER_SIZE - t->in_len)); =20 terminal_timer_cancel(t); - t->timer_src =3D qemu_chr_timeout_add_ms(t->chr.chr, 600 * 1000, - send_timing_mark_cb, t); + t->timer_tag =3D g_timeout_add_seconds(600, send_timing_mark_cb, t); memcpy(&t->inv[t->in_len], buf, size); t->in_len +=3D size; if (t->in_len < 2) { @@ -160,8 +158,7 @@ static void chr_event(void *opaque, int event) * char-socket.c. Once qemu receives the terminal-type of the * client, mark handshake done and trigger everything rolling agai= n. */ - t->timer_src =3D qemu_chr_timeout_add_ms(t->chr.chr, 600 * 1000, - send_timing_mark_cb, t); + t->timer_tag =3D g_timeout_add_seconds(600, send_timing_mark_cb, t= ); break; case CHR_EVENT_CLOSED: sch->curr_status.scsw.dstat =3D SCSW_DSTAT_DEVICE_END; --=20 2.20.1.519.g8feddda32c From nobody Sat Nov 8 03:36:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1549475163890591.0640402888781; Wed, 6 Feb 2019 09:46:03 -0800 (PST) Received: from localhost ([127.0.0.1]:55303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRGl-000741-Pq for importer@patchew.org; Wed, 06 Feb 2019 12:45:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grREx-0005pX-KD for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grREv-0004R9-Cv for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59486) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grREu-0004M8-Vw for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:01 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10C727F3F4 for ; Wed, 6 Feb 2019 17:43:57 +0000 (UTC) Received: from localhost (unknown [10.36.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id B68621690D; Wed, 6 Feb 2019 17:43:51 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 18:43:26 +0100 Message-Id: <20190206174328.9736-5-marcandre.lureau@redhat.com> In-Reply-To: <20190206174328.9736-1-marcandre.lureau@redhat.com> References: <20190206174328.9736-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 06 Feb 2019 17:43:57 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/6] chardev: add a note about frontend sources and context switch 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 , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- include/chardev/char-fe.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/chardev/char-fe.h b/include/chardev/char-fe.h index 54f0d61d32..2211913734 100644 --- a/include/chardev/char-fe.h +++ b/include/chardev/char-fe.h @@ -166,6 +166,9 @@ void qemu_chr_fe_printf(CharBackend *be, const char *fm= t, ...) * is active; return the #GSource's tag. If it is disconnected, * or without associated Chardev, return 0. * + * Note that you are responsible to update the front-end sources if + * you are switching the main context with qemu_chr_fe_set_handlers(). + * * Returns: the source tag */ guint qemu_chr_fe_add_watch(CharBackend *be, GIOCondition cond, --=20 2.20.1.519.g8feddda32c From nobody Sat Nov 8 03:36:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154947535031226.376480989719198; Wed, 6 Feb 2019 09:49:10 -0800 (PST) Received: from localhost ([127.0.0.1]:55503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRJo-0000zE-BM for importer@patchew.org; Wed, 06 Feb 2019 12:49:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRFA-000623-RE for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grRF9-0004cs-Q5 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39622) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grRF9-0004Sh-C2 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:15 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4D5EC01DDED for ; Wed, 6 Feb 2019 17:44:02 +0000 (UTC) Received: from localhost (unknown [10.36.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 735A11048116; Wed, 6 Feb 2019 17:43:58 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 18:43:27 +0100 Message-Id: <20190206174328.9736-6-marcandre.lureau@redhat.com> In-Reply-To: <20190206174328.9736-1-marcandre.lureau@redhat.com> References: <20190206174328.9736-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 06 Feb 2019 17:44:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/6] char-pty: remove the check for connection on write 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 , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This doesn't help much compared to the 1 second poll PTY timer. I can't think of a use case where this would help. However, we can simplify the code around chr_write(): the write lock is no longer needed for other char-pty callbacks (see following patch). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- chardev/char-pty.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index f681d637c1..f8772c9e15 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -130,11 +130,7 @@ static int char_pty_chr_write(Chardev *chr, const uint= 8_t *buf, int len) PtyChardev *s =3D PTY_CHARDEV(chr); =20 if (!s->connected) { - /* guest sends data, check for (re-)connect */ - pty_chr_update_read_handler_locked(chr); - if (!s->connected) { - return len; - } + return len; } return io_channel_send(s->ioc, buf, len); } --=20 2.20.1.519.g8feddda32c From nobody Sat Nov 8 03:36:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 154947535264473.8328308318977; Wed, 6 Feb 2019 09:49:12 -0800 (PST) Received: from localhost ([127.0.0.1]:55509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRJq-00011A-MZ for importer@patchew.org; Wed, 06 Feb 2019 12:49:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grRFI-00068i-SK for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grRFA-0004e9-P8 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:35014) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grRFA-0004UJ-91 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 12:44:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7FADC058CB7 for ; Wed, 6 Feb 2019 17:44:04 +0000 (UTC) Received: from localhost (unknown [10.36.112.15]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27EA71048127; Wed, 6 Feb 2019 17:44:03 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 18:43:28 +0100 Message-Id: <20190206174328.9736-7-marcandre.lureau@redhat.com> In-Reply-To: <20190206174328.9736-1-marcandre.lureau@redhat.com> References: <20190206174328.9736-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 06 Feb 2019 17:44:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 6/6] char-pty: remove write_lock usage 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 , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The lock usage was described with its introduction in commit 9005b2a7589540a3733b3abdcfbccfe7746cd1a1. It was necessary because PTY write() shares more state than GIOChannel with other operations. This made char-pty a bit different from other chardev, that only lock around the write operation. This was apparent in commit 7b3621f47a990c5099c6385728347f69a8d0e55c, which introduced an idle source to avoid the lock. By removing the PTY chardev state sharing on write() with previous patch, we can remove the lock and the idle source. Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Paolo Bonzini --- chardev/char-pty.c | 50 +++------------------------------------------- 1 file changed, 3 insertions(+), 47 deletions(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index f8772c9e15..b034332edd 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -36,15 +36,12 @@ typedef struct { QIOChannel *ioc; int read_bytes; =20 - /* Protected by the Chardev chr_write_lock. */ int connected; GSource *timer_src; - GSource *open_source; } PtyChardev; =20 #define PTY_CHARDEV(obj) OBJECT_CHECK(PtyChardev, (obj), TYPE_CHARDEV_PTY) =20 -static void pty_chr_update_read_handler_locked(Chardev *chr); static void pty_chr_state(Chardev *chr, int connected); =20 static void pty_chr_timer_cancel(PtyChardev *s) @@ -56,32 +53,19 @@ static void pty_chr_timer_cancel(PtyChardev *s) } } =20 -static void pty_chr_open_src_cancel(PtyChardev *s) -{ - if (s->open_source) { - g_source_destroy(s->open_source); - g_source_unref(s->open_source); - s->open_source =3D NULL; - } -} - static gboolean pty_chr_timer(gpointer opaque) { struct Chardev *chr =3D CHARDEV(opaque); PtyChardev *s =3D PTY_CHARDEV(opaque); =20 - qemu_mutex_lock(&chr->chr_write_lock); pty_chr_timer_cancel(s); - pty_chr_open_src_cancel(s); if (!s->connected) { /* Next poll ... */ - pty_chr_update_read_handler_locked(chr); + qemu_chr_be_update_read_handlers(chr, chr->gcontext); } - qemu_mutex_unlock(&chr->chr_write_lock); return FALSE; } =20 -/* Called with chr_write_lock held. */ static void pty_chr_rearm_timer(Chardev *chr, int ms) { PtyChardev *s =3D PTY_CHARDEV(chr); @@ -94,8 +78,7 @@ static void pty_chr_rearm_timer(Chardev *chr, int ms) g_free(name); } =20 -/* Called with chr_write_lock held. */ -static void pty_chr_update_read_handler_locked(Chardev *chr) +static void pty_chr_update_read_handler(Chardev *chr) { PtyChardev *s =3D PTY_CHARDEV(chr); GPollFD pfd; @@ -117,14 +100,6 @@ static void pty_chr_update_read_handler_locked(Chardev= *chr) } } =20 -static void pty_chr_update_read_handler(Chardev *chr) -{ - qemu_mutex_lock(&chr->chr_write_lock); - pty_chr_update_read_handler_locked(chr); - qemu_mutex_unlock(&chr->chr_write_lock); -} - -/* Called with chr_write_lock held. */ static int char_pty_chr_write(Chardev *chr, const uint8_t *buf, int len) { PtyChardev *s =3D PTY_CHARDEV(chr); @@ -179,23 +154,11 @@ static gboolean pty_chr_read(QIOChannel *chan, GIOCon= dition cond, void *opaque) return TRUE; } =20 -static gboolean qemu_chr_be_generic_open_func(gpointer opaque) -{ - Chardev *chr =3D CHARDEV(opaque); - PtyChardev *s =3D PTY_CHARDEV(opaque); - - s->open_source =3D NULL; - qemu_chr_be_event(chr, CHR_EVENT_OPENED); - return FALSE; -} - -/* Called with chr_write_lock held. */ static void pty_chr_state(Chardev *chr, int connected) { PtyChardev *s =3D PTY_CHARDEV(chr); =20 if (!connected) { - pty_chr_open_src_cancel(s); remove_fd_in_watch(chr); s->connected =3D 0; /* (re-)connect poll interval for idle guests: once per second. @@ -205,13 +168,8 @@ static void pty_chr_state(Chardev *chr, int connected) } else { pty_chr_timer_cancel(s); if (!s->connected) { - g_assert(s->open_source =3D=3D NULL); - s->open_source =3D g_idle_source_new(); s->connected =3D 1; - g_source_set_callback(s->open_source, - qemu_chr_be_generic_open_func, - chr, NULL); - g_source_attach(s->open_source, chr->gcontext); + qemu_chr_be_event(chr, CHR_EVENT_OPENED); } if (!chr->gsource) { chr->gsource =3D io_add_watch_poll(chr, s->ioc, @@ -227,11 +185,9 @@ static void char_pty_finalize(Object *obj) Chardev *chr =3D CHARDEV(obj); PtyChardev *s =3D PTY_CHARDEV(obj); =20 - qemu_mutex_lock(&chr->chr_write_lock); pty_chr_state(chr, 0); object_unref(OBJECT(s->ioc)); pty_chr_timer_cancel(s); - qemu_mutex_unlock(&chr->chr_write_lock); qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } =20 --=20 2.20.1.519.g8feddda32c