spicevmc -> chardev: restore guest open / close (v2)
cover spicevmc -> chardev: restore guest open / close (v2)
Hi All,
When we moved from the spicevmc device (which directly implemented a virtio serial port) to doing spicevmc as a chardev backend we lost the notification of the guest opening / closing the port to spice server. This causes the server to not fall back to server mouse mode when the agent inside the guest stops / dies (for what ever reason). Which causes the mouse to stop working in this scenario. This patch set fixes this regression.
Changes since v1:
-Replace "return qemu_chr_guest_open(vcon->chr);" with just
"qemu_chr_guest_open(vcon->chr);", since this is a void func. idem for close.
Regards,
Hans
PATCH 1/3 chardev: Allow frontends to notify backends of guest open / close
Some frontends know when the guest has opened the "channel" and is actively listening to it, for example virtio-serial. This patch adds 2 new qemu-chardev functions which can be used by frontends to signal guest open / close, and allows interested backends to listen to this.
--- qemu-char.c | 17 +++++++++++++++++ qemu-char.h | 4 ++++ 2 files changed, 21 insertions(+), 0 deletions(-)
qemu-char.c +17 -0
@@ -476,6 +476,9 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv) chr->chr_write = mux_chr_write; chr->chr_update_read_handler = mux_chr_update_read_handler; chr->chr_accept_input = mux_chr_accept_input; +/* Frontend guest-open / -close notification is not support with muxes */ + chr->chr_guest_open =NULL ; + chr->chr_guest_close =NULL ;/* Muxes are always open on creation */ qemu_chr_generic_open (chr);
@@ -2575,6 +2578,20 @@ void qemu_chr_set_echo(struct CharDriverState *chr, bool echo) } } +void qemu_chr_guest_open (struct CharDriverState *chr) +{ +if (chr->chr_guest_open) { + chr->chr_guest_open (chr); + } +} + +void qemu_chr_guest_close (struct CharDriverState *chr) +{ +if (chr->chr_guest_close) { + chr->chr_guest_close (chr); + } +} +void qemu_chr_close (CharDriverState *chr) {QTAILQ_REMOVE (&chardevs, chr, next);
qemu-char.h +4 -0
@@ -65,6 +65,8 @@ struct CharDriverState {void (*chr_close)(struct CharDriverState *chr);void (*chr_accept_input)(struct CharDriverState *chr);void (*chr_set_echo)(struct CharDriverState *chr,bool echo); +void (*chr_guest_open)(struct CharDriverState *chr); +void (*chr_guest_close)(struct CharDriverState *chr);void *opaque;QEMUBH *bh;char *label;
@@ -78,6 +80,8 @@ CharDriverState *qemu_chr_open_opts(QemuOpts *opts, void (*init)(struct CharDriverState *s));CharDriverState *qemu_chr_open (const char *label,const char *filename,void (*init)(struct CharDriverState *s));void qemu_chr_set_echo (struct CharDriverState *chr,bool echo); +void qemu_chr_guest_open (struct CharDriverState *chr); +void qemu_chr_guest_close (struct CharDriverState *chr);void qemu_chr_close (CharDriverState *chr); void qemu_chr_printf(CharDriverState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
Signature · 1 line
1.7.3.2
PATCH 2/3 virtio-console: notify backend of guest open / close
In reply to Hans de Goede--- hw/virtio-console.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
hw/virtio-console.c +18 -0
@@ -27,6 +27,22 @@ static ssize_t flush_buf(VirtIOSerialPort *port, const uint8_t *buf, size_t len)return qemu_chr_write (vcon->chr, buf, len); } +/* Callback function that's called when the guest opens the port */ +static void guest_open (VirtIOSerialPort *port) +{ +VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); + +qemu_chr_guest_open (vcon->chr); +} + +/* Callback function that's called when the guest closes the port */ +static void guest_close (VirtIOSerialPort *port) +{ +VirtConsole *vcon =DO_UPCAST (VirtConsole, port, port); + +qemu_chr_guest_close (vcon->chr); +} +/* Readiness of the guest to accept data on a port */ static int chr_can_read (void *opaque) {
@@ -63,6 +79,8 @@ static int generic_port_init(VirtConsole *vcon, VirtIOSerialPort *port)qemu_chr_add_handlers (vcon->chr, chr_can_read, chr_read, chr_event, vcon); vcon->port.info->have_data = flush_buf; + vcon->port.info->guest_open = guest_open; + vcon->port.info->guest_close = guest_close; }return 0 ; }
Signature · 1 line
1.7.3.2
PATCH 3/3 spice-chardev: listen to frontend guest open / close
In reply to Hans de GoedeNote the vmc_register_interface() in spice_chr_write is left in place in case someone uses spice-chardev with a frontend which does not have guest open / close notification.
--- spice-qemu-char.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
spice-qemu-char.c +14 -0
@@ -130,6 +130,18 @@ static void spice_chr_close(struct CharDriverState *chr)qemu_free (s); } +static void spice_chr_guest_open (struct CharDriverState *chr) +{ +SpiceCharDriver *s = chr->opaque; +vmc_register_interface (s); +} + +static void spice_chr_guest_close (struct CharDriverState *chr) +{ +SpiceCharDriver *s = chr->opaque; +vmc_unregister_interface (s); +} +static void print_allowed_subtypes (void ) {const char ** psubtype;
@@ -182,6 +194,8 @@ CharDriverState *qemu_chr_open_spice(QemuOpts *opts) chr->opaque = s; chr->chr_write = spice_chr_write; chr->chr_close = spice_chr_close; + chr->chr_guest_open = spice_chr_guest_open; + chr->chr_guest_close = spice_chr_guest_close;qemu_chr_generic_open (chr);
Signature · 1 line
1.7.3.2
Quoted 8 lines · Hans de Goede
Hi All,
When we moved from the spicevmc device (which directly implemented a virtio serial port) to doing spicevmc as a chardev backend we lost the notification of the guest opening / closing the port to spice server. This causes the server to not fall back to server mouse mode when the agent inside the guest stops / dies (for what ever reason). Which causes the mouse to stop working in this scenario. This patch set fixes this regression.
Quoted 9 lines
Changes since v1:
-Replace "returnqemu_chr_guest_open(vcon->chr);" with just
"qemu_chr_guest_open(vcon->chr);", since this is a void func. idem for close.Regards,
Hans
Quoted 9 lines · Hans de Goede
Hi All,
When we moved from the spicevmc device (which directly implemented a virtio serial port) to doing spicevmc as a chardev backend we lost the notification of the guest opening / closing the port to spice server. This causes the server to not fall back to server mouse mode when the agent inside the guest stops / dies (for what ever reason). Which causes the mouse to stop working in this scenario. This patch set fixes this regression.
Quoted 3 lines
Changes since v1:
-Replace "returnqemu_chr_guest_open(vcon->chr);" with just
"qemu_chr_guest_open(vcon->chr);", since this is a void func. idem for close.
I've picked this up in the virtio-serial branch; will do a pull request shortly.
Amit