On Thu, Oct 01, 2026 at 02:34:12PM +0400, [email protected] wrote:
> From: Marc-André Lureau <[email protected]>
> 
> 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.

Do you have a real world example of where this was causing a
problem ?

> 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.

IIUC, libvirt expects the agent TCP socket to remain open for
the lifetime of the QEMU process & any premature closure of that
socket would be considered a bug.

> It may be preferable to make this opt-in via a chardev property rather
> than changing the default.

If we want this feature, making it opt-in looks unavoidable.

> 
> Signed-off-by: Marc-André Lureau <[email protected]>
> ---
>  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
> 

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|


Reply via email to