diff mbox series

char: Slightly better error reporting when chardev is in use

Message ID 20240306081505.2258405-1-armbru@redhat.com (mailing list archive)
State New, archived
Headers show
Series char: Slightly better error reporting when chardev is in use | expand

Commit Message

Markus Armbruster March 6, 2024, 8:15 a.m. UTC
Both

    $ qemu-system-x86_64 -chardev null,id=chr0,mux=on -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0

and

    $ qemu-system-x86_64 -chardev null,id=chr0 -mon chardev=chr0 -mon chardev=chr0
fail with

    qemu-system-x86_64: -mon chardev=chr0: Device 'chr0' is in use

Improve to

    qemu-system-x86_64: -mon chardev=chr0: too many uses of multiplexed chardev 'chr0' (maximum is 4)

and

    qemu-system-x86_64: -mon chardev=chr0: chardev 'chr0' is already in use

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 chardev/char-fe.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Marc-André Lureau March 6, 2024, 8:20 a.m. UTC | #1
Hi

On Wed, Mar 6, 2024 at 12:15 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> Both
>
>     $ qemu-system-x86_64 -chardev null,id=chr0,mux=on -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0
>
> and
>
>     $ qemu-system-x86_64 -chardev null,id=chr0 -mon chardev=chr0 -mon chardev=chr0
> fail with
>
>     qemu-system-x86_64: -mon chardev=chr0: Device 'chr0' is in use
>
> Improve to
>
>     qemu-system-x86_64: -mon chardev=chr0: too many uses of multiplexed chardev 'chr0' (maximum is 4)
>
> and
>
>     qemu-system-x86_64: -mon chardev=chr0: chardev 'chr0' is already in use
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

lgtm
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  chardev/char-fe.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/chardev/char-fe.c b/chardev/char-fe.c
> index 20222a4cad..66cee8475a 100644
> --- a/chardev/char-fe.c
> +++ b/chardev/char-fe.c
> @@ -199,13 +199,18 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
>              MuxChardev *d = MUX_CHARDEV(s);
>
>              if (d->mux_cnt >= MAX_MUX) {
> -                goto unavailable;
> +                error_setg(errp,
> +                           "too many uses of multiplexed chardev '%s'"
> +                           " (maximum is " stringify(MAX_MUX) ")",
> +                           s->label);
> +                return false;
>              }
>
>              d->backends[d->mux_cnt] = b;
>              tag = d->mux_cnt++;
>          } else if (s->be) {
> -            goto unavailable;
> +            error_setg(errp, "chardev '%s' is already in use", s->label);
> +            return false;
>          } else {
>              s->be = b;
>          }
> @@ -215,10 +220,6 @@ bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
>      b->tag = tag;
>      b->chr = s;
>      return true;
> -
> -unavailable:
> -    error_setg(errp, QERR_DEVICE_IN_USE, s->label);

QERR_DEVICE_IN_USE is now left with a single user in blockdev.c. Is it worth it?
Markus Armbruster March 6, 2024, 10:17 a.m. UTC | #2
Marc-André Lureau <marcandre.lureau@gmail.com> writes:

> Hi
>
> On Wed, Mar 6, 2024 at 12:15 PM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Both
>>
>>     $ qemu-system-x86_64 -chardev null,id=chr0,mux=on -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0 -mon chardev=chr0
>>
>> and
>>
>>     $ qemu-system-x86_64 -chardev null,id=chr0 -mon chardev=chr0 -mon chardev=chr0
>> fail with
>>
>>     qemu-system-x86_64: -mon chardev=chr0: Device 'chr0' is in use
>>
>> Improve to
>>
>>     qemu-system-x86_64: -mon chardev=chr0: too many uses of multiplexed chardev 'chr0' (maximum is 4)
>>
>> and
>>
>>     qemu-system-x86_64: -mon chardev=chr0: chardev 'chr0' is already in use
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> lgtm
> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Thanks!

[...]

> QERR_DEVICE_IN_USE is now left with a single user in blockdev.c. Is it worth it?

Nope, that one needs to go, too.  How to reproduce it isn't obvious to
me.  I'll figure it out.
diff mbox series

Patch

diff --git a/chardev/char-fe.c b/chardev/char-fe.c
index 20222a4cad..66cee8475a 100644
--- a/chardev/char-fe.c
+++ b/chardev/char-fe.c
@@ -199,13 +199,18 @@  bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
             MuxChardev *d = MUX_CHARDEV(s);
 
             if (d->mux_cnt >= MAX_MUX) {
-                goto unavailable;
+                error_setg(errp,
+                           "too many uses of multiplexed chardev '%s'"
+                           " (maximum is " stringify(MAX_MUX) ")",
+                           s->label);
+                return false;
             }
 
             d->backends[d->mux_cnt] = b;
             tag = d->mux_cnt++;
         } else if (s->be) {
-            goto unavailable;
+            error_setg(errp, "chardev '%s' is already in use", s->label);
+            return false;
         } else {
             s->be = b;
         }
@@ -215,10 +220,6 @@  bool qemu_chr_fe_init(CharBackend *b, Chardev *s, Error **errp)
     b->tag = tag;
     b->chr = s;
     return true;
-
-unavailable:
-    error_setg(errp, QERR_DEVICE_IN_USE, s->label);
-    return false;
 }
 
 void qemu_chr_fe_deinit(CharBackend *b, bool del)