chardev/char.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
From: Marc-André Lureau <marcandre.lureau@redhat.com>
When the guest closes a virtio-serial channel, QEMU notifies some
backends (spice, dbus) via their chr_set_fe_open handlers. Backends
without such a handler, like socket, keep the connection open even
though the frontend is no longer active. This is problematic for
stateful protocols, as the peer has no way to know the channel was
reset and must handle re-synchronization on its own. Disconnecting
gives the peer a clean signal to reset its state.
Add a base-class chr_set_fe_open handler that calls chr_disconnect
when the frontend signals close. Subclasses that already override
chr_set_fe_open are unaffected. For the socket backend, this tears
down the connection and allows reconnection when combined with the
reconnect option.
Note: this is a behavior change that may break existing setups that
rely on the connection staying up across frontend close/reopen cycles.
It may be preferable to make this opt-in via a chardev property rather
than changing the default.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
chardev/char.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/chardev/char.c b/chardev/char.c
index 7daf87f0363e..58c69db7340e 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -331,12 +331,22 @@ static int null_chr_write(Chardev *chr, const uint8_t *buf, int len)
return len;
}
+static void chr_set_fe_open(Chardev *chr, int fe_open)
+{
+ ChardevClass *cc = CHARDEV_GET_CLASS(chr);
+
+ if (!fe_open && cc->chr_disconnect) {
+ cc->chr_disconnect(chr);
+ }
+}
+
static void char_class_init(ObjectClass *oc, const void *data)
{
ChardevClass *cc = CHARDEV_CLASS(oc);
cc->chr_write = null_chr_write;
cc->chr_be_event = chr_be_event;
+ cc->chr_set_fe_open = chr_set_fe_open;
}
static void char_finalize(Object *obj)
--
2.56.0.rc0.29.g47ce80527c56
© 2016 - 2026 Red Hat, Inc.