Skip to content

Commit

Permalink
migration: Add Error** argument to .load_setup() handler
Browse files Browse the repository at this point in the history
This will be useful to report errors at a higher level, mostly in VFIO
today.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
Link: https://lore.kernel.org/r/20240320064911.545001-9-clg@redhat.com
[peterx: drop comment for ERRP_GUARD, per Markus]
Signed-off-by: Peter Xu <peterx@redhat.com>
  • Loading branch information
legoater authored and xzpeter committed Apr 23, 2024
1 parent 01c3ac6 commit e4fa064
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions hw/vfio/migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,17 @@ static void vfio_save_state(QEMUFile *f, void *opaque)
}
}

static int vfio_load_setup(QEMUFile *f, void *opaque)
static int vfio_load_setup(QEMUFile *f, void *opaque, Error **errp)
{
VFIODevice *vbasedev = opaque;
int ret;

return vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING,
ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_RESUMING,
vbasedev->migration->device_state);
if (ret) {
error_setg(errp, "%s: Failed to set RESUMING state", vbasedev->name);
}
return ret;
}

static int vfio_load_cleanup(void *opaque)
Expand Down
3 changes: 2 additions & 1 deletion include/migration/register.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ typedef struct SaveVMHandlers {
*
* @f: QEMUFile where to receive the data
* @opaque: data pointer passed to register_savevm_live()
* @errp: pointer to Error*, to store an error if it happens.
*
* Returns zero to indicate success and negative for error
*/
int (*load_setup)(QEMUFile *f, void *opaque);
int (*load_setup)(QEMUFile *f, void *opaque, Error **errp);

/**
* @load_cleanup
Expand Down
3 changes: 2 additions & 1 deletion migration/ram.c
Original file line number Diff line number Diff line change
Expand Up @@ -3704,8 +3704,9 @@ void colo_release_ram_cache(void)
*
* @f: QEMUFile where to receive the data
* @opaque: RAMState pointer
* @errp: pointer to Error*, to store an error if it happens.
*/
static int ram_load_setup(QEMUFile *f, void *opaque)
static int ram_load_setup(QEMUFile *f, void *opaque, Error **errp)
{
xbzrle_load_setup();
ramblock_recv_map_init();
Expand Down
11 changes: 7 additions & 4 deletions migration/savevm.c
Original file line number Diff line number Diff line change
Expand Up @@ -2768,8 +2768,9 @@ static void qemu_loadvm_state_switchover_ack_needed(MigrationIncomingState *mis)
trace_loadvm_state_switchover_ack_needed(mis->switchover_ack_pending_num);
}

static int qemu_loadvm_state_setup(QEMUFile *f)
static int qemu_loadvm_state_setup(QEMUFile *f, Error **errp)
{
ERRP_GUARD();
SaveStateEntry *se;
int ret;

Expand All @@ -2784,10 +2785,11 @@ static int qemu_loadvm_state_setup(QEMUFile *f)
}
}

ret = se->ops->load_setup(f, se->opaque);
ret = se->ops->load_setup(f, se->opaque, errp);
if (ret < 0) {
error_prepend(errp, "Load state of device %s failed: ",
se->idstr);
qemu_file_set_error(f, ret);
error_report("Load state of device %s failed", se->idstr);
return ret;
}
}
Expand Down Expand Up @@ -2968,7 +2970,8 @@ int qemu_loadvm_state(QEMUFile *f)
return ret;
}

if (qemu_loadvm_state_setup(f) != 0) {
if (qemu_loadvm_state_setup(f, &local_err) != 0) {
error_report_err(local_err);
return -EINVAL;
}

Expand Down

0 comments on commit e4fa064

Please sign in to comment.