qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
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 v4 0/8] chardev: implement backend chardev multiplexing
Date: Wed, 16 Oct 2024 12:25:57 +0200	[thread overview]
Message-ID: <20241016102605.459395-1-r.peniaev@gmail.com> (raw)

Mux is a character backend (host side) device, which multiplexes
multiple frontends with one backend device. The following is a
few lines from the QEMU manpage [1]:

  A multiplexer is a "1:N" device, and here the "1" end is your
  specified chardev backend, and the "N" end is the various parts
  of QEMU that can talk to a chardev.

But sadly multiple backends are not supported.

This work implements multiplexing capability of several backend
devices, which opens up an opportunity to use a single frontend
device on the guest, which can be manipulated from several
backend devices.

The motivation is the EVE project [2], where it would be very
convenient to have a virtio console frontend device on the guest that
can be controlled from multiple backend devices, namely VNC and local
TTY emulator. The following is an example of the QEMU command line:

   -chardev mux-be,id=mux0 \
   -chardev socket,path=/tmp/sock,server=on,wait=off,id=sock0,mux-be-id=mux0 \
   -chardev vc,id=vc0,mux-be-id=mux0 \
   -device virtconsole,chardev=mux0 \
   -vnc 0.0.0.0:0

which creates 2 backend devices: text virtual console (`vc0`) and a
socket (`sock0`) connected to the single virtio hvc console with the
backend multiplexer (`mux0`) help. `vc0` renders text to an image,
which can be shared over the VNC protocol.  `sock0` is a socket
backend which provides biderectional communication to the virtio hvc
console.

Once QEMU starts VNC client and any TTY emulator can be used to
control a single hvc console, for example these two different
consoles should have similar input and output due the buffer
multiplexing:

   # VNC client
   vncviewer :0

   # TTY emulator
   socat unix-connect:/tmp/sock pty,link=/tmp/pty
   tio /tmp/pty

v3 .. v4:

* Rebase on latest chardev changes
* Add unit tests which test corner cases:
   * Inability to remove mux with active frontend
   * Inability to add more chardevs to a mux than `MUX_MAX`
   * Inability to mix mux-fe and mux-be for the same chardev

v2 .. v3:

* Split frontend and backend multiplexer implementations and
  move them to separate files: char-mux-fe.c and char-mux-be.c

v1 .. v2:

* Separate type for the backend multiplexer `mux-be`
* Handle EAGAIN on write to the backend device
* Support of watch of previously failed backend device
* Proper json support of the `mux-be-id` option
* Unit test for the `mux-be` multiplexer

[1] https://www.qemu.org/docs/master/system/qemu-manpage.html#hxtool-6
[2] https://github.com/lf-edge/eve

Roman Penyaev (8):
  chardev/char: rename `MuxChardev` struct to `MuxFeChardev`
  chardev/char: rename `char-mux.c` to `char-mux-fe.c`
  chardev/char: move away mux suspend/resume calls
  chardev/char: rename frontend mux calls
  chardev/char: introduce `mux-be-id=ID` option
  chardev/char-mux: implement backend chardev multiplexing
  tests/unit/test-char: add unit test for the `mux-be` multiplexer
  qemu-options.hx: describe multiplexing of several backend devices

 chardev/char-fe.c                     |  25 ++-
 chardev/char-mux-be.c                 | 290 ++++++++++++++++++++++++
 chardev/{char-mux.c => char-mux-fe.c} | 157 +++++--------
 chardev/char.c                        | 133 +++++++++--
 chardev/chardev-internal.h            |  55 ++++-
 chardev/meson.build                   |   3 +-
 include/chardev/char.h                |   8 +-
 qapi/char.json                        |  31 ++-
 qemu-options.hx                       |  78 +++++--
 system/vl.c                           |   4 +-
 tests/unit/test-char.c                | 306 +++++++++++++++++++++++++-
 11 files changed, 922 insertions(+), 168 deletions(-)
 create mode 100644 chardev/char-mux-be.c
 rename chardev/{char-mux.c => char-mux-fe.c} (71%)

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org

-- 
2.34.1



             reply	other threads:[~2024-10-16 10:28 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-16 10:25 Roman Penyaev [this message]
2024-10-16 10:25 ` [PATCH v4 1/8] chardev/char: rename `MuxChardev` struct to `MuxFeChardev` Roman Penyaev
2024-10-16 10:25 ` [PATCH v4 2/8] chardev/char: rename `char-mux.c` to `char-mux-fe.c` Roman Penyaev
2024-10-16 10:26 ` [PATCH v4 3/8] chardev/char: move away mux suspend/resume calls Roman Penyaev
2024-10-16 10:26 ` [PATCH v4 4/8] chardev/char: rename frontend mux calls Roman Penyaev
2024-10-16 10:26 ` [PATCH v4 5/8] chardev/char: introduce `mux-be-id=ID` option Roman Penyaev
2024-10-16 10:26 ` [PATCH v4 6/8] chardev/char-mux: implement backend chardev multiplexing Roman Penyaev
2024-10-16 11:13   ` Marc-André Lureau
2024-10-16 11:18     ` Marc-André Lureau
2024-10-16 14:19     ` Roman Penyaev
2024-11-20  8:00     ` Roman Penyaev
2024-12-11  9:42     ` Markus Armbruster
2024-12-17 10:32       ` Roman Penyaev
2024-12-19 13:45         ` Markus Armbruster
2025-01-16 11:27         ` Kevin Wolf
2025-01-17  8:03           ` Roman Penyaev
2025-01-17 13:20             ` Kevin Wolf
2024-10-16 10:26 ` [PATCH v4 7/8] tests/unit/test-char: add unit test for the `mux-be` multiplexer Roman Penyaev
2024-10-16 11:36   ` Marc-André Lureau
2024-10-17 13:48     ` Roman Penyaev
2024-10-16 10:26 ` [PATCH v4 8/8] qemu-options.hx: describe multiplexing of several backend devices Roman Penyaev
2024-10-16 11:27   ` Marc-André Lureau

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=20241016102605.459395-1-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).