]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
vfio: add strread/writeerror()
authorJohn Levon <john.levon@nutanix.com>
Wed, 7 May 2025 15:20:11 +0000 (16:20 +0100)
committerCédric Le Goater <clg@redhat.com>
Fri, 9 May 2025 10:42:28 +0000 (12:42 +0200)
Add simple helpers to correctly report failures from read/write routines
using the return -errno style.

Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20250507152020.1254632-7-john.levon@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
include/hw/vfio/vfio-device.h

index a7eaaa31e7e98a1ec73eefde0d935842ef9da401..4a3220294309d718bb3230a5d3f4bab9e082f951 100644 (file)
@@ -115,6 +115,20 @@ struct VFIODeviceOps {
     int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f);
 };
 
+/*
+ * Given a return value of either a short number of bytes read or -errno,
+ * construct a meaningful error message.
+ */
+#define strreaderror(ret) \
+    (ret < 0 ? strerror(-ret) : "short read")
+
+/*
+ * Given a return value of either a short number of bytes written or -errno,
+ * construct a meaningful error message.
+ */
+#define strwriteerror(ret) \
+    (ret < 0 ? strerror(-ret) : "short write")
+
 void vfio_device_irq_disable(VFIODevice *vbasedev, int index);
 void vfio_device_irq_unmask(VFIODevice *vbasedev, int index);
 void vfio_device_irq_mask(VFIODevice *vbasedev, int index);