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 v2 5/8] chardev/mux: introduce `mux_chr_attach_frontend() call
Date: Mon, 14 Oct 2024 17:24:05 +0200 [thread overview]
Message-ID: <20241014152408.427700-6-r.peniaev@gmail.com> (raw)
In-Reply-To: <20241014152408.427700-1-r.peniaev@gmail.com>
Move away logic which attaches frontend device to a mux
from `char-fe.c` to actual `char-mux.c` implementation
and make it a separate function.
No logic 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-fe.c | 9 +--------
chardev/char-mux.c | 17 +++++++++++++++++
chardev/chardev-internal.h | 2 ++
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index 69b47d16bdfa..3b8771ca2ac4 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -197,16 +197,9 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
if (CHARDEV_IS_MUX(s)) {
MuxChardev *d = MUX_CHARDEV(s);
- if (d->mux_cnt >= MAX_MUX) {
- error_setg(errp,
- "too many uses of multiplexed chardev '%s'"
- " (maximum is " stringify(MAX_MUX) ")",
- s->label);
+ if (!mux_chr_attach_frontend(d, b, &tag, errp)) {
return false;
}
-
- d->backends[d->mux_cnt] = b;
- tag = d->mux_cnt++;
} else if (s->be) {
error_setg(errp, "chardev '%s' is already in use", s->label);
return false;
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index b2d7abf2fc01..9294f955462e 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -301,6 +301,23 @@ static void mux_chr_update_read_handlers(Chardev *chr)
chr->gcontext, true, false);
}
+bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
+ unsigned int *tag, Error **errp)
+{
+ if (d->mux_cnt >= MAX_MUX) {
+ error_setg(errp,
+ "too many uses of multiplexed chardev '%s'"
+ " (maximum is " stringify(MAX_MUX) ")",
+ d->parent.label);
+ return false;
+ }
+
+ d->backends[d->mux_cnt] = b;
+ *tag = d->mux_cnt++;
+
+ return true;
+}
+
void mux_set_focus(Chardev *chr, unsigned int focus)
{
MuxChardev *d = MUX_CHARDEV(chr);
diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h
index ab93f6ea1720..8126ce180690 100644
--- a/chardev/chardev-internal.h
+++ b/chardev/chardev-internal.h
@@ -59,6 +59,8 @@ DECLARE_INSTANCE_CHECKER(MuxChardev, MUX_CHARDEV,
#define CHARDEV_IS_MUX(chr) \
object_dynamic_cast(OBJECT(chr), TYPE_CHARDEV_MUX)
+bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
+ unsigned int *tag, Error **errp);
void mux_set_focus(Chardev *chr, unsigned int focus);
void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
--
2.34.1
next prev parent reply other threads:[~2024-10-14 15:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 15:24 [PATCH v2 0/8] chardev/mux: implement frontend detach Roman Penyaev
2024-10-14 15:24 ` [PATCH v2 1/8] chardev/char: fix qemu_chr_is_busy() check Roman Penyaev
2024-10-14 15:24 ` [PATCH v2 2/8] chardev/chardev-internal: remove unused `max_size` struct member Roman Penyaev
2024-10-22 5:21 ` CLEMENT MATHIEU--DRIF
2024-10-14 15:24 ` [PATCH v2 3/8] chardev/mux: use bool type for `linestart` and `term_got_escape` Roman Penyaev
2024-10-22 5:21 ` CLEMENT MATHIEU--DRIF
2024-10-14 15:24 ` [PATCH v2 4/8] chardev/mux: convert size members to unsigned int Roman Penyaev
2024-10-14 15:24 ` Roman Penyaev [this message]
2024-10-14 15:24 ` [PATCH v2 6/8] chardev/mux: switch mux frontends management to bitset Roman Penyaev
2024-10-14 15:24 ` [PATCH v2 7/8] chardev/mux: implement detach of frontends from mux Roman Penyaev
2024-10-22 5:20 ` CLEMENT MATHIEU--DRIF
2024-11-02 11:19 ` Roman Penyaev
2024-10-14 15:24 ` [PATCH v2 8/8] tests/unit/test-char: implement a few mux remove test cases Roman Penyaev
2024-10-15 8:50 ` Marc-André Lureau
2024-10-15 16:51 ` 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=20241014152408.427700-6-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).