All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: Alessandro Ratti <alessandro@0x65c.net>
Cc: qemu-devel@nongnu.org,  alessandro.ratti@gmail.com,  philmd@linaro.org
Subject: Re: [PATCH] virtio: Add function name to error messages
Date: Mon, 15 Sep 2025 11:35:08 +0100	[thread overview]
Message-ID: <87a52wqa03.fsf@draig.linaro.org> (raw)
In-Reply-To: <20250915100701.224156-2-alessandro@0x65c.net> (Alessandro Ratti's message of "Mon, 15 Sep 2025 12:01:07 +0200")

Alessandro Ratti <alessandro@0x65c.net> writes:

> Replace virtio_error() with a macro that automatically prepends the
> calling function name to error messages. This provides better context
> for debugging virtio issues by showing exactly which function
> encountered the error.
>
> Before: "Invalid queue size: 1024"
> After:  "virtio_queue_set_num: Invalid queue size: 1024"
>
> The implementation uses a macro to insert __func__ at compile time,
> avoiding any runtime overhead while providing more specific error
> context than a generic "virtio:" prefix.
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/230
> Buglink: https://bugs.launchpad.net/qemu/+bug/1919021
>
> Signed-off-by: Alessandro Ratti <alessandro@0x65c.net>
> ---
>  hw/virtio/virtio.c         | 2 +-
>  include/hw/virtio/virtio.h | 4 +++-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 9a81ad912e..44528d7f2b 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -3931,7 +3931,7 @@ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name)
>      vdev->bus_name = g_strdup(bus_name);
>  }
>  
> -void G_GNUC_PRINTF(2, 3) virtio_error(VirtIODevice *vdev, const char *fmt, ...)
> +void G_GNUC_PRINTF(2, 3) virtio_error_impl(VirtIODevice *vdev, const char *fmt, ...)
>  {
>      va_list ap;
>  
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index c594764f23..961d021497 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -249,7 +249,9 @@ void virtio_init(VirtIODevice *vdev, uint16_t device_id, size_t config_size);
>  
>  void virtio_cleanup(VirtIODevice *vdev);
>  
> -void virtio_error(VirtIODevice *vdev, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
> +#define virtio_error(vdev, fmt, ...) \
> +    virtio_error_impl(vdev, "%s: " fmt, __func__, ##__VA_ARGS__)
> +void virtio_error_impl(VirtIODevice *vdev, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
>  
>  /* Set the child bus name. */
>  void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name);

For completeness you could also fixup:

  virtio_error(vdev, "%s: %d reason unknown", __func__, pnd->reason);

for virtio-ballon. Otherwise:

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>


-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


  reply	other threads:[~2025-09-15 10:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 10:01 [PATCH] virtio: Add function name to error messages Alessandro Ratti
2025-09-15 10:01 ` Alessandro Ratti
2025-09-15 10:35   ` Alex Bennée [this message]
2025-09-15 16:19     ` Alessandro Ratti
2025-09-15 16:19       ` [PATCH v2] " Alessandro Ratti
2025-09-22  9:33         ` Alessandro Ratti
2025-09-22  9:33           ` Alessandro Ratti
2025-09-22 10:37           ` Alex Bennée
2025-09-22 10:37         ` Markus Armbruster
2025-09-22 10:47           ` Daniel P. Berrangé
2025-09-22 11:06             ` Alex Bennée
2025-09-22 12:29               ` Markus Armbruster
2025-09-22 13:37                 ` Alessandro Ratti
2025-09-22 14:23                   ` Markus Armbruster
2025-09-23  9:42                     ` Alessandro Ratti
2025-09-23 13:33                       ` Markus Armbruster

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=87a52wqa03.fsf@draig.linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=alessandro.ratti@gmail.com \
    --cc=alessandro@0x65c.net \
    --cc=philmd@linaro.org \
    --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.