vfio/migration: Add Error ** parameter to vfio_migration_init()
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. Refactor it to return bool as well. Reviewed-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Avihai Horon <avihaih@nvidia.com> Link: https://lore.kernel.org/qemu-devel/20260706085211.13905-11-avihaih@nvidia.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
Avihai Horon committed
Jul 6, 2026 at 11:52 UTC
92e184e09bbcf0eb745499e73e4d2bf5a400e8b0
1 file changed
+18
-18
hw/vfio/migration.c
+18
-18
@@ -1056,7 +1056,7 @@ static bool vfio_dma_logging_supported(VFIODevice *vbasedev)
1056
return !ioctl(vbasedev->fd, VFIO_DEVICE_FEATURE, feature);
1057
}
1058
1059
-static int vfio_migration_init(VFIODevice *vbasedev)
1059
+static bool vfio_migration_init(VFIODevice *vbasedev, Error **errp)
1060
{
1061
int ret;
1062
Object *obj;
@@ -1067,22 +1067,32 @@ static int vfio_migration_init(VFIODevice *vbasedev)
1067
VMChangeStateHandler *prepare_cb;
1068
1069
if (!vbasedev->ops->vfio_get_object) {
1070
- return -EINVAL;
1070
+ error_setg(errp, "no vfio_get_object handler");
1071
+ return false;
1072
}
1073
1074
obj = vbasedev->ops->vfio_get_object(vbasedev);
1075
if (!obj) {
1075
- return -EINVAL;
1076
+ error_setg(errp, "failed to get object");
1077
+ return false;
1078
}
1079
1080
ret = vfio_migration_query_flags(vbasedev, &mig_flags);
1081
if (ret) {
1080
- return ret;
1082
+ if (ret == -ENOTTY) {
1083
+ error_setg_errno(errp, -ret,
1084
+ "migration is not supported in kernel");
1085
+ } else {
1086
+ error_setg_errno(errp, -ret, "failed to query migration flags");
1087
+ }
1088
+
1089
+ return false;
1090
}
1091
1092
/* Basic migration functionality must be supported */
1093
if (!(mig_flags & VFIO_MIGRATION_STOP_COPY)) {
1085
- return -EOPNOTSUPP;
1094
+ error_setg(errp, "VFIO_MIGRATION_STOP_COPY is not supported");
1095
+ return false;
1096
}
1097
1098
vbasedev->migration = g_new0(VFIOMigration, 1);
@@ -1113,7 +1123,7 @@ static int vfio_migration_init(VFIODevice *vbasedev)
1123
migration_add_notifier(&migration->migration_state,
1124
vfio_migration_state_notifier);
1125
1116
- return 0;
1126
+ return true;
1127
}
1128
1129
static Error *multiple_devices_migration_blocker;
@@ -1279,18 +1289,8 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Error **errp)
1289
return !vfio_block_migration(vbasedev, err, errp);
1290
}
1291
1282
- ret = vfio_migration_init(vbasedev);
1283
- if (ret) {
1284
- if (ret == -ENOTTY) {
1285
- error_setg(&err, "%s: VFIO migration is not supported in kernel",
1286
- vbasedev->name);
1287
- } else {
1288
- error_setg(&err,
1289
- "%s: Migration couldn't be initialized for VFIO device, "
1290
- "err: %d (%s)",
1291
- vbasedev->name, ret, strerror(-ret));
1292
- }
1293
-
1292
+ if (!vfio_migration_init(vbasedev, &err)) {
1293
+ error_prepend(&err, "%s: VFIO migration init failed: ", vbasedev->name);
1294
return !vfio_block_migration(vbasedev, err, errp);
1295
}
1296