mbox series

[0/2] chardev: implement backend chardev multiplexing

Message ID 20240913163636.253949-1-r.peniaev@gmail.com (mailing list archive)
Headers show
Series chardev: implement backend chardev multiplexing | expand

Message

Roman Penyaev Sept. 13, 2024, 4:36 p.m. UTC
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 main motivation of this work is to use a virtio console
frontend device on the guest, which can be manipulated from
several backend devices. The following is QEMU command line
example:

  -chardev socket,path=/tmp/sock,server=on,wait=off,id=sock0 \
  -chardev vc,id=vc0 \
  -chardev mux,id=mux0,chardev=vc0,,sock0 \
  -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 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

[1] https://www.qemu.org/docs/master/system/qemu-manpage.html#hxtool-6

Roman Penyaev (2):
  chardev: implement backend chardev multiplexing
  qemu-options.hx: describe multiplexing of several backend devices

 chardev/char-fe.c          |  14 +++--
 chardev/char-mux.c         | 120 +++++++++++++++++++++++++++++--------
 chardev/char.c             |   2 +-
 chardev/chardev-internal.h |   7 ++-
 qemu-options.hx            |  44 ++++++++++++--
 5 files changed, 151 insertions(+), 36 deletions(-)

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