On 6/3/2026 2:38 PM, Philippe Mathieu-Daudé wrote:
External email: Use caution opening links or attachments
Hi Avihai,
On 2/6/26 11:26, Avihai Horon wrote:
vfio_migration_init() already has many failure points and a new one will
be added in next patch.
Add Error ** parameter to vfio_migration_init() to report a detailed
error message through it.
Signed-off-by: Avihai Horon <[email protected]>
---
hw/vfio/migration.c | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index a15e877fd3..02ef216712 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -1055,7 +1055,7 @@ static bool
vfio_dma_logging_supported(VFIODevice *vbasedev)
return !ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature);
}
-static int vfio_migration_init(VFIODevice *vbasedev)
+static int vfio_migration_init(VFIODevice *vbasedev, Error **errp)
{
int ret;
Object *obj;
@@ -1066,21 +1066,31 @@ static int vfio_migration_init(VFIODevice
*vbasedev)
VMChangeStateHandler *prepare_cb;
if (!vbasedev->ops->vfio_get_object) {
+ error_setg(errp, "no vfio_get_object handler");
return -EINVAL;
}
obj = vbasedev->ops->vfio_get_object(vbasedev);
if (!obj) {
+ error_setg(errp, "failed to get object");
return -EINVAL;
}
ret = vfio_migration_query_flags(vbasedev, &mig_flags);
if (ret) {
+ if (ret == -ENOTTY) {
+ error_setg_errno(errp, -ret,
+ "migration is not supported in kernel");
+ } else {
+ error_setg_errno(errp, -ret, "failed to query migration
flags");
+ }
+
return ret;
}
/* Basic migration functionality must be supported */
if (!(mig_flags & VFIO_MIGRATION_STOP_COPY)) {
+ error_setg(errp, "VFIO_MIGRATION_STOP_COPY is not supported");
return -EOPNOTSUPP;
}
@@ -1278,18 +1288,9 @@ bool vfio_migration_realize(VFIODevice
*vbasedev, Error **errp)
return !vfio_block_migration(vbasedev, err, errp);
}
- ret = vfio_migration_init(vbasedev);
+ ret = vfio_migration_init(vbasedev, &err);
if (ret) {
Only 'ret' boolean part is used now, have the method return a boolean
instead, like other methods with Error **errp last param?
Sure, I will change it.
Thanks.
- if (ret == -ENOTTY) {
- error_setg(&err, "%s: VFIO migration is not supported in
kernel",
- vbasedev->name);
- } else {
- error_setg(&err,
- "%s: Migration couldn't be initialized for
VFIO device, "
- "err: %d (%s)",
- vbasedev->name, ret, strerror(-ret));
- }
-
+ error_prepend(&err, "%s: VFIO migration init failed: ",
vbasedev->name);
return !vfio_block_migration(vbasedev, err, errp);
}