From nobody Tue Dec 16 07:06:21 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520981848254530.953509373568; Tue, 13 Mar 2018 15:57:28 -0700 (PDT) Received: from localhost ([::1]:43328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evsrH-0005AY-An for importer@patchew.org; Tue, 13 Mar 2018 18:57:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1evshp-0005VZ-Kc for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:47:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1evsho-0002zc-6F for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:47:41 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:55340) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1evshn-0002yQ-Sz for qemu-devel@nongnu.org; Tue, 13 Mar 2018 18:47:40 -0400 Received: by mail-wm0-x241.google.com with SMTP id q83so871350wme.5 for ; Tue, 13 Mar 2018 15:47:39 -0700 (PDT) Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id x107sm1557951wrb.97.2018.03.13.15.47.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Mar 2018 15:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ODMIbUWNj1JP1adI+4rQVxRgz3VibYJej0WX91XiScA=; b=ZZrz0EUpUaj/QqOnKtJxZLYiyBz1rPqCVxPU0sokDp4AOu4WR7AskWw+sKE0rX7vte /x/ruYbAx5oMIt8pCpHLdkRJO4W0bvRDSVWZgshqGhjFd9f5zKJQwVOv8ttcZ3tgx2dh nsZiEpGc74NjEPE9il1TJMXmnOoAffQ6aXr0FwSql2hO/qTe6irjRJ2H4auDUVy4m7Hi 674Zl2lFqXgJPsdxWiDnP4m774ywKtXWgdeSFdSCCJ92wedDh8VqYyPtsnyfRLIwSrlg Fwp1HCbQ10Bv+kmfFyQHYQHp9YUw0TEsp+owf+WqH2eHuEG/7lZ+bKHIWnXYjklJpQZz casg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ODMIbUWNj1JP1adI+4rQVxRgz3VibYJej0WX91XiScA=; b=srMV5b13mf9UZPjJYifr9wjaQ7Wof3Is6Vwf6qJKSy/BUty5cGAw9vdfGeZhPGR8ja BhZ0Ny0WB0NX/in/HN40TImlQlyCYcMKxmBhqb7cdQiWF/ter04fUY5FR3NZwy70qY5O r3+x68CTs05eKvW/o03fX86A9tNbeOeIXeOmKYktEkLtujxNUn8cBTcci7y5NqUhhZb8 IUEEePdrWaXmPNRFyb0v6vzYXjMv36Xz/m+qCfZGP8fHHhfRwlRRGKC35RTVEBfWnWeo ytia/ZUVIVfFZ82ThjF3W4RTxsTWBXhUULQnXMAp0boBfVd4H/vlonEpuHcLI4J1DbAj MvPw== X-Gm-Message-State: AElRT7HYkVsXYMQGStxYQlhwE6JdhkSVdch7pkMW/YVMTohnwbDbYNg+ wmI5TOP8fZ82eV/e6sgWmkrr50f/ X-Google-Smtp-Source: AG47ELsr0uWxctYqA9N+Os9FrJuW1c7POYjffAsXLDJ3nWagKussMRkIQ64XAbuZk+G9O41t2xoqKQ== X-Received: by 10.28.20.84 with SMTP id 81mr2154349wmu.70.1520981258438; Tue, 13 Mar 2018 15:47:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 13 Mar 2018 23:46:24 +0100 Message-Id: <20180313224719.4954-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180313224719.4954-1-pbonzini@redhat.com> References: <20180313224719.4954-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::241 Subject: [Qemu-devel] [PULL 14/69] chardev: introduce chr_machine_done hook 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: Peter Xu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 From: Peter Xu Introduce ChardevClass.chr_machine_done() hook so that chardevs can run customized procedures after machine init. There was an existing mux user already that did similar thing but used a raw machine done notifier. Generalize it into a framework, and let the mux chardevs provide such a class-specific hook to achieve the same thing. Then we can move the mux related code to the char-mux.c file. Since at it, replace the mux_realized variable with the global machine_init_done varible. This notifier framework will be further leverged by other type of chardevs soon. Signed-off-by: Peter Xu Message-Id: <20180306053320.15401-6-peterx@redhat.com> Acked-by: Stefan Hajnoczi Reviewed-by: Daniel P. Berrang=C3=A9 Signed-off-by: Paolo Bonzini --- chardev/char-mux.c | 33 +++++++++++++++++++++++++++++---- chardev/char.c | 43 +++++++++++++++++-------------------------- include/chardev/char-mux.h | 2 -- include/chardev/char.h | 2 ++ tests/test-char.c | 1 - 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/chardev/char-mux.c b/chardev/char-mux.c index d48e78103a..1b925c8dec 100644 --- a/chardev/char-mux.c +++ b/chardev/char-mux.c @@ -27,6 +27,7 @@ #include "qemu/option.h" #include "chardev/char.h" #include "sysemu/block-backend.h" +#include "sysemu/sysemu.h" #include "chardev/char-mux.h" =20 /* MUX driver for serial I/O splitting */ @@ -230,14 +231,12 @@ static void mux_chr_read(void *opaque, const uint8_t = *buf, int size) } } =20 -bool muxes_realized; - void mux_chr_send_all_event(Chardev *chr, int event) { MuxChardev *d =3D MUX_CHARDEV(chr); int i; =20 - if (!muxes_realized) { + if (!machine_init_done) { return; } =20 @@ -327,7 +326,7 @@ static void qemu_chr_open_mux(Chardev *chr, /* only default to opened state if we've realized the initial * set of muxes */ - *be_opened =3D muxes_realized; + *be_opened =3D machine_init_done; qemu_chr_fe_init(&d->chr, drv, errp); } =20 @@ -347,6 +346,31 @@ static void qemu_chr_parse_mux(QemuOpts *opts, Chardev= Backend *backend, mux->chardev =3D g_strdup(chardev); } =20 +/** + * Called after processing of default and command-line-specified + * chardevs to deliver CHR_EVENT_OPENED events to any FEs attached + * to a mux chardev. This is done here to ensure that + * output/prompts/banners are only displayed for the FE that has + * focus when initial command-line processing/machine init is + * completed. + * + * After this point, any new FE attached to any new or existing + * mux will receive CHR_EVENT_OPENED notifications for the BE + * immediately. + */ +static int open_muxes(Chardev *chr) +{ + /* send OPENED to all already-attached FEs */ + mux_chr_send_all_event(chr, CHR_EVENT_OPENED); + /* + * mark mux as OPENED so any new FEs will immediately receive + * OPENED event + */ + qemu_chr_be_event(chr, CHR_EVENT_OPENED); + + return 0; +} + static void char_mux_class_init(ObjectClass *oc, void *data) { ChardevClass *cc =3D CHARDEV_CLASS(oc); @@ -357,6 +381,7 @@ static void char_mux_class_init(ObjectClass *oc, void *= data) cc->chr_accept_input =3D mux_chr_accept_input; 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; } =20 static const TypeInfo char_mux_type_info =3D { diff --git a/chardev/char.c b/chardev/char.c index 5d7b079ef0..a6250cac80 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -281,40 +281,31 @@ static const TypeInfo char_type_info =3D { .class_init =3D char_class_init, }; =20 -/** - * Called after processing of default and command-line-specified - * chardevs to deliver CHR_EVENT_OPENED events to any FEs attached - * to a mux chardev. This is done here to ensure that - * output/prompts/banners are only displayed for the FE that has - * focus when initial command-line processing/machine init is - * completed. - * - * After this point, any new FE attached to any new or existing - * mux will receive CHR_EVENT_OPENED notifications for the BE - * immediately. - */ -static int open_muxes(Object *child, void *opaque) +static int chardev_machine_done_notify_one(Object *child, void *opaque) { - if (CHARDEV_IS_MUX(child)) { - /* send OPENED to all already-attached FEs */ - mux_chr_send_all_event(CHARDEV(child), CHR_EVENT_OPENED); - /* mark mux as OPENED so any new FEs will immediately receive - * OPENED event - */ - qemu_chr_be_event(CHARDEV(child), CHR_EVENT_OPENED); + Chardev *chr =3D (Chardev *)child; + ChardevClass *class =3D CHARDEV_GET_CLASS(chr); + + if (class->chr_machine_done) { + return class->chr_machine_done(chr); } =20 return 0; } =20 -static void muxes_realize_done(Notifier *notifier, void *unused) +static void chardev_machine_done_hook(Notifier *notifier, void *unused) { - muxes_realized =3D true; - object_child_foreach(get_chardevs_root(), open_muxes, NULL); + int ret =3D object_child_foreach(get_chardevs_root(), + chardev_machine_done_notify_one, NULL); + + if (ret) { + error_report("Failed to call chardev machine_done hooks"); + exit(1); + } } =20 -static Notifier muxes_realize_notify =3D { - .notify =3D muxes_realize_done, +static Notifier chardev_machine_done_notify =3D { + .notify =3D chardev_machine_done_hook, }; =20 static bool qemu_chr_is_busy(Chardev *s) @@ -1118,7 +1109,7 @@ static void register_types(void) * as part of realize functions like serial_isa_realizefn when -nograp= hic * is specified */ - qemu_add_machine_init_done_notifier(&muxes_realize_notify); + qemu_add_machine_init_done_notifier(&chardev_machine_done_notify); } =20 type_init(register_types); diff --git a/include/chardev/char-mux.h b/include/chardev/char-mux.h index 8928977897..1e13187767 100644 --- a/include/chardev/char-mux.h +++ b/include/chardev/char-mux.h @@ -27,8 +27,6 @@ #include "chardev/char.h" #include "chardev/char-fe.h" =20 -extern bool muxes_realized; - #define MAX_MUX 4 #define MUX_BUFFER_SIZE 32 /* Must be a power of 2. */ #define MUX_BUFFER_MASK (MUX_BUFFER_SIZE - 1) diff --git a/include/chardev/char.h b/include/chardev/char.h index ebf1e0ba04..04de45795e 100644 --- a/include/chardev/char.h +++ b/include/chardev/char.h @@ -248,6 +248,8 @@ typedef struct ChardevClass { void (*chr_set_echo)(Chardev *chr, bool echo); void (*chr_set_fe_open)(Chardev *chr, int fe_open); void (*chr_be_event)(Chardev *s, int event); + /* Return 0 if succeeded, 1 if failed */ + int (*chr_machine_done)(Chardev *chr); } ChardevClass; =20 Chardev *qemu_chardev_new(const char *id, const char *typename, diff --git a/tests/test-char.c b/tests/test-char.c index b3a77af085..c731313098 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -166,7 +166,6 @@ static void char_mux_test(void) FeHandler h1 =3D { 0, }, h2 =3D { 0, }; CharBackend chr_be1, chr_be2; =20 - muxes_realized =3D true; /* done after machine init */ opts =3D qemu_opts_create(qemu_find_opts("chardev"), "mux-label", 1, &error_abort); qemu_opt_set(opts, "backend", "ringbuf", &error_abort); --=20 2.14.3