[PATCH v4 03/10] chardev: add qemu_chr_resize()

Filip Hejsek posted 10 patches 2 weeks, 2 days ago
Maintainers: "Gonglei (Arei)" <arei.gonglei@huawei.com>, Zhenwei Pi <pizhenwei@bytedance.com>, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Raphael Norwitz <raphael@enfabrica.net>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Thomas Huth <thuth@redhat.com>, Halil Pasic <pasic@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, "Collin L. Walling" <walling@linux.ibm.com>, Laurent Vivier <lvivier@redhat.com>, Amit Shah <amit@kernel.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Corey Minyard <minyard@acm.org>, Fam Zheng <fam@euphon.net>, Samuel Thibault <samuel.thibault@ens-lyon.org>, "Alex Bennée" <alex.bennee@linaro.org>, "Dr. David Alan Gilbert" <dave@treblig.org>, Markus Armbruster <armbru@redhat.com>, Jason Wang <jasowang@redhat.com>, Eric Blake <eblake@redhat.com>
There is a newer version of this series
[PATCH v4 03/10] chardev: add qemu_chr_resize()
Posted by Filip Hejsek 2 weeks, 2 days ago
From: Szymon Lukasz <noh4hss@gmail.com>

This function should be called whenever we learn about a new size of
the terminal connected to a chardev.

Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
---
 chardev/char.c         | 11 +++++++++++
 include/chardev/char.h |  2 ++
 2 files changed, 13 insertions(+)

diff --git a/chardev/char.c b/chardev/char.c
index 635d19fea4fd4bd0c7f171f055fe940f9f5ebed5..b45d79cb9b57643827eb7479257fdda2cf6b0434 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -351,6 +351,17 @@ int qemu_chr_wait_connected(Chardev *chr, Error **errp)
     return 0;
 }
 
+void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows)
+{
+    if (cols != chr->cols || rows != chr->rows) {
+        chr->cols = cols;
+        chr->rows = rows;
+        if (chr->be_open) {
+            qemu_chr_be_event(chr, CHR_EVENT_RESIZE);
+        }
+    }
+}
+
 QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
                                 bool permit_mux_mon)
 {
diff --git a/include/chardev/char.h b/include/chardev/char.h
index 45cb6349756ac8072dffab9354108caf90cd3565..1e69b038241074d627ebb7f096e98aee9953ebdf 100644
--- a/include/chardev/char.h
+++ b/include/chardev/char.h
@@ -232,6 +232,8 @@ int qemu_chr_write(Chardev *s, const uint8_t *buf, int len, bool write_all);
 #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len, true)
 int qemu_chr_wait_connected(Chardev *chr, Error **errp);
 
+void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows);
+
 #define TYPE_CHARDEV "chardev"
 OBJECT_DECLARE_TYPE(Chardev, ChardevClass, CHARDEV)
 

-- 
2.51.0
Re: [PATCH v4 03/10] chardev: add qemu_chr_resize()
Posted by Maximilian Immanuel Brandtner 1 week, 3 days ago
On Fri, 2025-09-12 at 05:39 +0200, Filip Hejsek wrote:
> From: Szymon Lukasz <noh4hss@gmail.com>
> 
> This function should be called whenever we learn about a new size of
> the terminal connected to a chardev.
> 
> Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> ---
>  chardev/char.c         | 11 +++++++++++
>  include/chardev/char.h |  2 ++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/chardev/char.c b/chardev/char.c
> index
> 635d19fea4fd4bd0c7f171f055fe940f9f5ebed5..b45d79cb9b57643827eb7479257
> fdda2cf6b0434 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -351,6 +351,17 @@ int qemu_chr_wait_connected(Chardev *chr, Error
> **errp)
>      return 0;
>  }
>  
> +void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows)
> +{
> +    if (cols != chr->cols || rows != chr->rows) {

Perhaps it would be better to discard resize events if the requested
cols or rows is 0 as it indicates that an error has occurred at some
point during the process of receiving the winsize.

> +        chr->cols = cols;
> +        chr->rows = rows;
> +        if (chr->be_open) {
> +            qemu_chr_be_event(chr, CHR_EVENT_RESIZE);
> +        }
> +    }
> +}
> +
>  QemuOpts *qemu_chr_parse_compat(const char *label, const char
> *filename,
>                                  bool permit_mux_mon)
>  {
> diff --git a/include/chardev/char.h b/include/chardev/char.h
> index
> 45cb6349756ac8072dffab9354108caf90cd3565..1e69b038241074d627ebb7f096e
> 98aee9953ebdf 100644
> --- a/include/chardev/char.h
> +++ b/include/chardev/char.h
> @@ -232,6 +232,8 @@ int qemu_chr_write(Chardev *s, const uint8_t
> *buf, int len, bool write_all);
>  #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len,
> true)
>  int qemu_chr_wait_connected(Chardev *chr, Error **errp);
>  
> +void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows);
> +
>  #define TYPE_CHARDEV "chardev"
>  OBJECT_DECLARE_TYPE(Chardev, ChardevClass, CHARDEV)
>  
> 
Re: [PATCH v4 03/10] chardev: add qemu_chr_resize()
Posted by Filip Hejsek 1 week, 3 days ago
On September 18, 2025 10:45:13 AM GMT+02:00, Maximilian Immanuel Brandtner <maxbr@linux.ibm.com> wrote:
> On Fri, 2025-09-12 at 05:39 +0200, Filip Hejsek wrote:
> > From: Szymon Lukasz <noh4hss@gmail.com>
> > 
> > This function should be called whenever we learn about a new size of
> > the terminal connected to a chardev.
> > 
> > Signed-off-by: Szymon Lukasz <noh4hss@gmail.com>
> > Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> > ---
> >  chardev/char.c         | 11 +++++++++++
> >  include/chardev/char.h |  2 ++
> >  2 files changed, 13 insertions(+)
> > 
> > diff --git a/chardev/char.c b/chardev/char.c
> > index
> > 635d19fea4fd4bd0c7f171f055fe940f9f5ebed5..b45d79cb9b57643827eb7479257
> > fdda2cf6b0434 100644
> > --- a/chardev/char.c
> > +++ b/chardev/char.c
> > @@ -351,6 +351,17 @@ int qemu_chr_wait_connected(Chardev *chr, Error
> > **errp)
> >      return 0;
> >  }
> >  
> > +void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows)
> > +{
> > +    if (cols != chr->cols || rows != chr->rows) {
> 
> Perhaps it would be better to discard resize events if the requested
> cols or rows is 0 as it indicates that an error has occurred at some
> point during the process of receiving the winsize.

Maybe. But then if the size actually changes from known
to unknown, it wouldn't be possible to get it back to the unknown
state. And what if only
one of the values is 0, and the other differs from the last value?

What I want to say is, I don't think QEMU should be in the business
of trying to fix broken size info. The kernel gave us zero,
so we should forward that and let the guest handle it.

> > +        chr->cols = cols;
> > +        chr->rows = rows;
> > +        if (chr->be_open) {
> > +            qemu_chr_be_event(chr, CHR_EVENT_RESIZE);
> > +        }
> > +    }
> > +}
> > +
> >  QemuOpts *qemu_chr_parse_compat(const char *label, const char
> > *filename,
> >                                  bool permit_mux_mon)
> >  {
> > diff --git a/include/chardev/char.h b/include/chardev/char.h
> > index
> > 45cb6349756ac8072dffab9354108caf90cd3565..1e69b038241074d627ebb7f096e
> > 98aee9953ebdf 100644
> > --- a/include/chardev/char.h
> > +++ b/include/chardev/char.h
> > @@ -232,6 +232,8 @@ int qemu_chr_write(Chardev *s, const uint8_t
> > *buf, int len, bool write_all);
> >  #define qemu_chr_write_all(s, buf, len) qemu_chr_write(s, buf, len,
> > true)
> >  int qemu_chr_wait_connected(Chardev *chr, Error **errp);
> >  
> > +void qemu_chr_resize(Chardev *chr, uint16_t cols, uint16_t rows);
> > +
> >  #define TYPE_CHARDEV "chardev"
> >  OBJECT_DECLARE_TYPE(Chardev, ChardevClass, CHARDEV)
> >  
> > 
>