[PATCH v2 7/8] chardev/mux: implement detach of frontends from mux

Roman Penyaev posted 8 patches 1 month, 1 week ago
[PATCH v2 7/8] chardev/mux: implement detach of frontends from mux
Posted by Roman Penyaev 1 month, 1 week ago
With bitset management now it becomes feasible to implement
the logic of detaching frontends from multiplexer.

Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: qemu-devel@nongnu.org
---
 chardev/char-fe.c          |  2 +-
 chardev/char-mux.c         | 21 ++++++++++++++++++---
 chardev/chardev-internal.h |  1 +
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index 3b8771ca2ac4..8ac6bebb6f74 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -225,7 +225,7 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del)
         }
         if (CHARDEV_IS_MUX(b->chr)) {
             MuxChardev *d = MUX_CHARDEV(b->chr);
-            d->backends[b->tag] = NULL;
+            mux_chr_detach_frontend(d, b->tag);
         }
         if (del) {
             Object *obj = OBJECT(b->chr);
diff --git a/chardev/char-mux.c b/chardev/char-mux.c
index 4fc619b2da70..bda5c45e6058 100644
--- a/chardev/char-mux.c
+++ b/chardev/char-mux.c
@@ -290,10 +290,10 @@ static void char_mux_finalize(Object *obj)
     bit = -1;
     while ((bit = find_next_bit(&d->mux_bitset, MAX_MUX, bit + 1)) < MAX_MUX) {
         CharBackend *be = d->backends[bit];
-        if (be) {
-            be->chr = NULL;
-        }
+        be->chr = NULL;
+        d->backends[bit] = NULL;
     }
+    d->mux_bitset = 0;
     qemu_chr_fe_deinit(&d->chr, false);
 }
 
@@ -332,6 +332,21 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
     return true;
 }
 
+bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag)
+{
+    unsigned int bit;
+
+    bit = find_next_bit(&d->mux_bitset, MAX_MUX, tag);
+    if (bit != tag) {
+        return false;
+    }
+
+    d->mux_bitset &= ~(1 << bit);
+    d->backends[bit] = NULL;
+
+    return true;
+}
+
 void mux_set_focus(Chardev *chr, unsigned int focus)
 {
     MuxChardev *d = MUX_CHARDEV(chr);
diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h
index b89aada5413b..853807f3cb88 100644
--- a/chardev/chardev-internal.h
+++ b/chardev/chardev-internal.h
@@ -61,6 +61,7 @@ DECLARE_INSTANCE_CHECKER(MuxChardev, MUX_CHARDEV,
 
 bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
                              unsigned int *tag, Error **errp);
+bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag);
 void mux_set_focus(Chardev *chr, unsigned int focus);
 void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
 
-- 
2.34.1


Re: [PATCH v2 7/8] chardev/mux: implement detach of frontends from mux
Posted by CLEMENT MATHIEU--DRIF 1 month ago

On 14/10/2024 17:24, Roman Penyaev wrote:
> Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.
> 
> 
> With bitset management now it becomes feasible to implement
> the logic of detaching frontends from multiplexer.
> 
> Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
> Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
> Cc: qemu-devel@nongnu.org
> ---
>   chardev/char-fe.c          |  2 +-
>   chardev/char-mux.c         | 21 ++++++++++++++++++---
>   chardev/chardev-internal.h |  1 +
>   3 files changed, 20 insertions(+), 4 deletions(-)
> 
> diff --git a/chardev/char-fe.c b/chardev/char-fe.c
> index 3b8771ca2ac4..8ac6bebb6f74 100644
> --- a/chardev/char-fe.c
> +++ b/chardev/char-fe.c
> @@ -225,7 +225,7 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del)
>           }
>           if (CHARDEV_IS_MUX(b->chr)) {
>               MuxChardev *d = MUX_CHARDEV(b->chr);
> -            d->backends[b->tag] = NULL;
> +            mux_chr_detach_frontend(d, b->tag);
>           }
>           if (del) {
>               Object *obj = OBJECT(b->chr);
> diff --git a/chardev/char-mux.c b/chardev/char-mux.c
> index 4fc619b2da70..bda5c45e6058 100644
> --- a/chardev/char-mux.c
> +++ b/chardev/char-mux.c
> @@ -290,10 +290,10 @@ static void char_mux_finalize(Object *obj)
>       bit = -1;
>       while ((bit = find_next_bit(&d->mux_bitset, MAX_MUX, bit + 1)) < MAX_MUX) {
>           CharBackend *be = d->backends[bit];
> -        if (be) {
> -            be->chr = NULL;
> -        }
> +        be->chr = NULL;
> +        d->backends[bit] = NULL;
>       }
> +    d->mux_bitset = 0;
>       qemu_chr_fe_deinit(&d->chr, false);
>   }
> 
> @@ -332,6 +332,21 @@ bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
>       return true;
>   }
> 
> +bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag)
> +{
> +    unsigned int bit;
> +
> +    bit = find_next_bit(&d->mux_bitset, MAX_MUX, tag);
> +    if (bit != tag) {
> +        return false;
> +    }
> +
> +    d->mux_bitset &= ~(1 << bit);

mux_bitset is unsigned long, I think we should use 1ul here even id 
MAX_MUX is a low value

> +    d->backends[bit] = NULL;
> +
> +    return true;
> +}
> +
>   void mux_set_focus(Chardev *chr, unsigned int focus)
>   {
>       MuxChardev *d = MUX_CHARDEV(chr);
> diff --git a/chardev/chardev-internal.h b/chardev/chardev-internal.h
> index b89aada5413b..853807f3cb88 100644
> --- a/chardev/chardev-internal.h
> +++ b/chardev/chardev-internal.h
> @@ -61,6 +61,7 @@ DECLARE_INSTANCE_CHECKER(MuxChardev, MUX_CHARDEV,
> 
>   bool mux_chr_attach_frontend(MuxChardev *d, CharBackend *b,
>                                unsigned int *tag, Error **errp);
> +bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag);
>   void mux_set_focus(Chardev *chr, unsigned int focus);
>   void mux_chr_send_all_event(Chardev *chr, QEMUChrEvent event);
> 
> --
> 2.34.1
> 
> 
Re: [PATCH v2 7/8] chardev/mux: implement detach of frontends from mux
Posted by Roman Penyaev 3 weeks ago
Hi,

On Tue, Oct 22, 2024, 07:21 CLEMENT MATHIEU--DRIF <
clement.mathieu--drif@eviden.com> wrote:

>
>
> On 14/10/2024 17:24, Roman Penyaev wrote:
> > Caution: External email. Do not open attachments or click links, unless
> this email comes from a known sender and you know the content is safe.
> >
> >
> > With bitset management now it becomes feasible to implement
> > the logic of detaching frontends from multiplexer.
> >
> > Signed-off-by: Roman Penyaev <r.peniaev@gmail.com>
> > Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
> > Cc: qemu-devel@nongnu.org
> > ---
> >   chardev/char-fe.c          |  2 +-
> >   chardev/char-mux.c         | 21 ++++++++++++++++++---
> >   chardev/chardev-internal.h |  1 +
> >   3 files changed, 20 insertions(+), 4 deletions(-)
> >
> > diff --git a/chardev/char-fe.c b/chardev/char-fe.c
> > index 3b8771ca2ac4..8ac6bebb6f74 100644
> > --- a/chardev/char-fe.c
> > +++ b/chardev/char-fe.c
> > @@ -225,7 +225,7 @@ void qemu_chr_fe_deinit(CharBackend *b, bool del)
> >           }
> >           if (CHARDEV_IS_MUX(b->chr)) {
> >               MuxChardev *d = MUX_CHARDEV(b->chr);
> > -            d->backends[b->tag] = NULL;
> > +            mux_chr_detach_frontend(d, b->tag);
> >           }
> >           if (del) {
> >               Object *obj = OBJECT(b->chr);
> > diff --git a/chardev/char-mux.c b/chardev/char-mux.c
> > index 4fc619b2da70..bda5c45e6058 100644
> > --- a/chardev/char-mux.c
> > +++ b/chardev/char-mux.c
> > @@ -290,10 +290,10 @@ static void char_mux_finalize(Object *obj)
> >       bit = -1;
> >       while ((bit = find_next_bit(&d->mux_bitset, MAX_MUX, bit + 1)) <
> MAX_MUX) {
> >           CharBackend *be = d->backends[bit];
> > -        if (be) {
> > -            be->chr = NULL;
> > -        }
> > +        be->chr = NULL;
> > +        d->backends[bit] = NULL;
> >       }
> > +    d->mux_bitset = 0;
> >       qemu_chr_fe_deinit(&d->chr, false);
> >   }
> >
> > @@ -332,6 +332,21 @@ bool mux_chr_attach_frontend(MuxChardev *d,
> CharBackend *b,
> >       return true;
> >   }
> >
> > +bool mux_chr_detach_frontend(MuxChardev *d, unsigned int tag)
> > +{
> > +    unsigned int bit;
> > +
> > +    bit = find_next_bit(&d->mux_bitset, MAX_MUX, tag);
> > +    if (bit != tag) {
> > +        return false;
> > +    }
> > +
> > +    d->mux_bitset &= ~(1 << bit);
>
> mux_bitset is unsigned long, I think we should use 1ul here even id
> MAX_MUX is a low value
>


Sent a patch on that. Thanks.

--
Roman