Skip to contentSkip to conversation

virtio: prefix error messages with "virtio:"

PATCH New Alessandro Ratti 1 participant 2 messages Aug 30, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: prefix error messages with "virtio:"

Hi,

This patch follows up on a previous attempt [1] to improve error messages in virtio_init_region_cache(), where the messages:

Cannot map desc
Cannot map used
Cannot map avail

were changed to:

Virtio cannot map desc
...

While this was an improvement in clarity, a reviewer (Alex Bennée) pointed out that all such messages go through virtio_error(), and suggested a cleaner and more scalable solution: prefixing all messages in virtio_error() itself.

This patch implements that suggestion. It modifies virtio_error() to prepend "virtio: " to all messages, improving clarity across all call sites without duplicating the prefix manually.

I tested the change by forcibly triggering an error inside virtio_init_region_cache() and verified the resulting output includes the new prefix, as expected.

  ~/qemu/build$ sudo ./qemu-system-x86_64  \
      -enable-kvm   \
      -m 512   \
      -drive \
      if=virtio,file=/tmp/some.img,format=raw

qemu-system-x86_64: virtio: Cannot map used (debug test)
qemu-system-x86_64: virtio: Cannot map used (debug test)
qemu-system-x86_64: virtio: Cannot map used (debug test)
qemu-system-x86_64: virtio: Cannot map used (debug test)
qemu-system-x86_64: virtio: Cannot map used (debug test)
qemu-system-x86_64: virtio: Cannot map used (debug test) ^Cqemu-system-x86_64: terminating on signal 2

This should address the original concern in a more maintainable way.

Thank you for your time and consideration.

Best regards,
Alessandro Ratti

[1]: https://patchwork.kernel.org/project/qemu-devel/patch/[email protected]/

#1 lore raw

PATCH 1/1 virtio: prefix error messages with "virtio:"

The error message introduced in commit e45da653223 in virtio_init_region_cache() was unclear:

qemu-system-i386: Cannot map used

This patch modifies virtio_error() to prepend all error messages with "virtio: ", making it easier to trace their origin.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/230

---
 hw/virtio/virtio.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
hw/virtio/virtio.c +6 -1
index 9a81ad912e..c43ac4d320 100644
@@ -3934,11 +3934,16 @@ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name)
 void G_GNUC_PRINTF(2, 3) virtio_error(VirtIODevice *vdev, const char *fmt, ...)
 {
     va_list ap;
+    char *prefixed_fmt;
+
+    prefixed_fmt = g_strdup_printf("virtio: %s", fmt);
 
     va_start(ap, fmt);
-    error_vreport(fmt, ap);
+    error_vreport(prefixed_fmt, ap);
     va_end(ap);
 
+    g_free(prefixed_fmt);
+
     if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
         vdev->status = vdev->status | VIRTIO_CONFIG_S_NEEDS_RESET;
         virtio_notify_config(vdev);
Signature · 1 line
2.39.5