From: Roman Penyaev <r.peniaev@gmail.com>
Cc: "Roman Penyaev" <r.peniaev@gmail.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
qemu-devel@nongnu.org
Subject: [PATCH v3 2/7] chardev/char: move away mux suspend/resume calls
Date: Thu, 10 Oct 2024 12:18:33 +0200 [thread overview]
Message-ID: <20241010101838.331032-3-r.peniaev@gmail.com> (raw)
In-Reply-To: <20241010101838.331032-1-r.peniaev@gmail.com>
The suspend/resume open multiplexer calls are generic
and will be used for frontend (current mux) and backend
(will follow) implementations. Move them away from the
`char-mux-fe.c` to more generic `char.c` file. Also
for the sake of clarity these renames were made:
s/suspend_mux_open/mux_suspend_open/g
s/resume_mux_open/mux_resume_open/g
No functional changes are made.
Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org
---
chardev/char-mux-fe.c | 63 ++-------------------------------
chardev/char.c | 72 ++++++++++++++++++++++++++++++++++++++
chardev/chardev-internal.h | 3 ++
include/chardev/char.h | 5 +--
system/vl.c | 4 +--
5 files changed, 82 insertions(+), 65 deletions(-)
diff --git a/chardev/char-mux-fe.c b/chardev/char-mux-fe.c
index 673971ca1798..cd9ff0c5dc12 100644
--- a/chardev/char-mux-fe.c
+++ b/chardev/char-mux-fe.c
@@ -33,13 +33,6 @@
/* MUX driver for serial I/O splitting */
-/*
- * Set to false by suspend_mux_open. Open events are delayed until
- * resume_mux_open. Usually suspend_mux_open is called before
- * command line processing and resume_mux_open afterwards.
- */
-static bool muxes_opened = true;
-
/* Called with chr_write_lock held. */
static int mux_chr_write(Chardev *chr, const uint8_t *buf, int len)
{
@@ -239,15 +232,10 @@ static void mux_chr_read(void *opaque, const uint8_t *buf, int size)
}
}
-void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event)
+void mux_fe_chr_send_all_event(MuxFeChardev *d, QEMUChrEvent event)
{
- MuxFeChardev *d = MUX_FE_CHARDEV(chr);
int i;
- if (!muxes_opened) {
- return;
- }
-
/* Send the event to all registered listeners */
for (i = 0; i < d->mux_cnt; i++) {
mux_chr_send_event(d, i, event);
@@ -335,7 +323,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 = muxes_opened;
+ *be_opened = mux_is_opened();
qemu_chr_fe_init(&d->chr, drv, errp);
}
@@ -355,53 +343,6 @@ static void qemu_chr_parse_mux(QemuOpts *opts, ChardevBackend *backend,
mux->chardev = g_strdup(chardev);
}
-/**
- * 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 void 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
- */
- chr->be_open = 1;
-}
-
-void suspend_mux_open(void)
-{
- muxes_opened = false;
-}
-
-static int chardev_options_parsed_cb(Object *child, void *opaque)
-{
- Chardev *chr = (Chardev *)child;
-
- if (!chr->be_open && CHARDEV_IS_MUX_FE(chr)) {
- open_muxes(chr);
- }
-
- return 0;
-}
-
-void resume_mux_open(void)
-{
- muxes_opened = true;
- object_child_foreach(get_chardevs_root(),
- chardev_options_parsed_cb, NULL);
-}
-
static void char_mux_class_init(ObjectClass *oc, void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
diff --git a/chardev/char.c b/chardev/char.c
index 9d180f996dfb..d38a0c76a51e 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -43,6 +43,13 @@
#include "chardev-internal.h"
+/*
+ * Set to false by mux_suspend_open(). Open events are delayed until
+ * mux_resume_open(). Usually mux_suspend_open() is called before
+ * command line processing and mux_resume_open() afterwards.
+ */
+static bool muxes_opened = true;
+
/***********************************************************/
/* character device */
@@ -1259,6 +1266,71 @@ void qemu_chr_cleanup(void)
object_unparent(get_chardevs_root());
}
+/**
+ * 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 void 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
+ */
+ chr->be_open = 1;
+}
+
+void mux_suspend_open(void)
+{
+ muxes_opened = false;
+}
+
+static int chardev_options_parsed_cb(Object *child, void *opaque)
+{
+ Chardev *chr = (Chardev *)child;
+
+ if (!chr->be_open && CHARDEV_IS_MUX_FE(chr)) {
+ open_muxes(chr);
+ }
+
+ return 0;
+}
+
+void mux_resume_open(void)
+{
+ muxes_opened = true;
+ object_child_foreach(get_chardevs_root(),
+ chardev_options_parsed_cb, NULL);
+}
+
+bool mux_is_opened(void)
+{
+ return muxes_opened;
+}
+
+void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event)
+{
+ if (!mux_is_opened()) {
+ return;
+ }
+
+ if (CHARDEV_IS_MUX_FE(chr)) {
+ MuxFeChardev *d = MUX_FE_CHARDEV(chr);
+
+ mux_fe_chr_send_all_event(d, event);
+ }
+}
+
static void register_types(void)
{
type_register_static(&char_type_info);
diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h
index 1b943c81bcd8..a77f0bdaccfa 100644
--- a/chardev/chardev-internal.h
+++ b/chardev/chardev-internal.h
@@ -63,6 +63,9 @@ DECLARE_INSTANCE_CHECKER(MuxFeChardev, MUX_FE_CHARDEV,
void mux_set_focus(Chardev *chr, int focus);
void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
+/* Mux type dependent calls */
+void mux_fe_chr_send_all_event(MuxFeChardev *d, QEMUChrEvent event);
+
Object *get_chardevs_root(void);
#endif /* CHARDEV_INTERNAL_H */
diff --git a/include/chardev/char.h b/include/chardev/char.h
index d9d23b6232db..0bec974f9d73 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -317,7 +317,8 @@ extern int term_escape_char;
GSource *qemu_chr_timeout_add_ms(Chardev *chr, guint ms,
GSourceFunc func, void *private);
-void suspend_mux_open(void);
-void resume_mux_open(void);
+bool mux_is_opened(void);
+void mux_suspend_open(void);
+void mux_resume_open(void);
#endif
diff --git a/system/vl.c b/system/vl.c
index fe547ca47c27..6222e0625b1e 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -3690,7 +3690,7 @@ void qemu_init(int argc, char **argv)
qemu_create_machine(machine_opts_dict);
- suspend_mux_open();
+ mux_suspend_open();
qemu_disable_default_devices();
qemu_setup_display();
@@ -3768,5 +3768,5 @@ void qemu_init(int argc, char **argv)
qemu_init_displays();
accel_setup_post(current_machine);
os_setup_post();
- resume_mux_open();
+ mux_resume_open();
}
--
2.34.1
next prev parent reply other threads:[~2024-10-10 10:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241010101838.331032-1-r.peniaev@gmail.com>
2024-10-10 10:18 ` [PATCH v3 1/7] chardev/char: rename `char-mux.c` to `char-mux-fe.c` Roman Penyaev
2024-10-14 13:57 ` Marc-André Lureau
2024-10-14 14:08 ` Roman Penyaev
2024-10-10 10:18 ` Roman Penyaev [this message]
2024-10-10 10:18 ` [PATCH v3 3/7] chardev/char: rename frontend mux calls Roman Penyaev
2024-10-10 10:18 ` [PATCH v3 4/7] chardev/char: introduce `mux-be-id=ID` option Roman Penyaev
2024-10-10 10:18 ` [PATCH v3 5/7] chardev/char-mux: implement backend chardev multiplexing Roman Penyaev
2024-10-10 10:18 ` [PATCH v3 6/7] tests/unit/test-char: add unit test for the `mux-be` multiplexer Roman Penyaev
2024-10-10 10:18 ` [PATCH v3 7/7] qemu-options.hx: describe multiplexing of several backend devices Roman Penyaev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241010101838.331032-3-r.peniaev@gmail.com \
--to=r.peniaev@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).