All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: marcandre.lureau@redhat.com
Cc: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH] RFC: chardev: disconnect backend when frontend closes
Date: Mon, 2 Nov 2026 10:09:40 +0000	[thread overview]
Message-ID: <auhhZP8151vP_wSt@redhat.com> (raw)
In-Reply-To: <20261001103412.2162829-1-marcandre.lureau@redhat.com>

On Thu, Oct 01, 2026 at 02:34:12PM +0400, marcandre.lureau@redhat.com wrote:
> 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.

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

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



  parent reply	other threads:[~2026-11-02 10:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 10:34 [PATCH] RFC: chardev: disconnect backend when frontend closes marcandre.lureau
2026-11-01  8:30 ` Marc-André Lureau
2026-11-02 10:09 ` Daniel P. Berrangé [this message]
2026-11-02 13:29   ` 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=auhhZP8151vP_wSt@redhat.com \
    --to=berrange@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=pbonzini@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.