migration: Add Error** argument to .save_setup() handler

The purpose is to record a potential error in the migration stream if
qemu_savevm_state_setup() fails. Most of the current .save_setup()
handlers can be modified to use the Error argument instead of managing
their own and calling locally error_report().

Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Harsh Prateek Bora <harshpb@linux.ibm.com>
Cc: Halil Pasic <pasic@linux.ibm.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Cc: John Snow <jsnow@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/r/20240320064911.545001-8-clg@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
Cédric Le Goater 2024-03-20 07:49:03 +01:00 committed by Peter Xu
parent 057a20099b
commit 01c3ac681b
8 changed files with 29 additions and 35 deletions

View file

@ -376,7 +376,7 @@ static int vfio_save_prepare(void *opaque, Error **errp)
return 0;
}
static int vfio_save_setup(QEMUFile *f, void *opaque)
static int vfio_save_setup(QEMUFile *f, void *opaque, Error **errp)
{
VFIODevice *vbasedev = opaque;
VFIOMigration *migration = vbasedev->migration;
@ -390,8 +390,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)
stop_copy_size);
migration->data_buffer = g_try_malloc0(migration->data_buffer_size);
if (!migration->data_buffer) {
error_report("%s: Failed to allocate migration data buffer",
vbasedev->name);
error_setg(errp, "%s: Failed to allocate migration data buffer",
vbasedev->name);
return -ENOMEM;
}
@ -401,8 +401,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)
ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_PRE_COPY,
VFIO_DEVICE_STATE_RUNNING);
if (ret) {
error_report("%s: Failed to set new PRE_COPY state",
vbasedev->name);
error_setg(errp, "%s: Failed to set new PRE_COPY state",
vbasedev->name);
return ret;
}
@ -413,8 +413,8 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)
/* vfio_save_complete_precopy() will go to STOP_COPY */
break;
default:
error_report("%s: Invalid device state %d", vbasedev->name,
migration->device_state);
error_setg(errp, "%s: Invalid device state %d", vbasedev->name,
migration->device_state);
return -EINVAL;
}
}
@ -425,8 +425,7 @@ static int vfio_save_setup(QEMUFile *f, void *opaque)
ret = qemu_file_get_error(f);
if (ret < 0) {
error_report("%s: save setup failed : %s", vbasedev->name,
strerror(-ret));
error_setg_errno(errp, -ret, "%s: save setup failed", vbasedev->name);
}
return ret;