Move trace_vfio_migration_set_state() to the top of the function, add
recover_state to it, and add a new trace event to
vfio_migration_set_device_state().
This improves tracing of device state changes as state changes are now
also logged when vfio_migration_set_state() fails (covering recover
state and device reset transitions) and in no-op state transitions to
the same state.
Suggested-by: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Avihai Horon <avihaih@nvidia.com>
---
hw/vfio/migration.c | 8 ++++++--
hw/vfio/trace-events | 3 ++-
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index f2b7a3067b..7f0d76ab50 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -129,6 +129,9 @@ static void vfio_migration_set_device_state(VFIODevice *vbasedev,
{
VFIOMigration *migration = vbasedev->migration;
+ trace_vfio_migration_set_device_state(vbasedev->name,
+ mig_state_to_str(state));
+
migration->device_state = state;
vfio_migration_send_event(vbasedev);
}
@@ -146,6 +149,9 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,
(struct vfio_device_feature_mig_state *)feature->data;
int ret;
+ trace_vfio_migration_set_state(vbasedev->name, mig_state_to_str(new_state),
+ mig_state_to_str(recover_state));
+
if (new_state == migration->device_state) {
return 0;
}
@@ -203,8 +209,6 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,
migration->data_fd = mig_state->data_fd;
}
- trace_vfio_migration_set_state(vbasedev->name, mig_state_to_str(new_state));
-
return 0;
reset_device:
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
index f0474b244b..64161bf6f4 100644
--- a/hw/vfio/trace-events
+++ b/hw/vfio/trace-events
@@ -152,7 +152,8 @@ vfio_load_device_config_state(const char *name) " (%s)"
vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64
vfio_load_state_device_data(const char *name, uint64_t data_size, int ret) " (%s) size 0x%"PRIx64" ret %d"
vfio_migration_realize(const char *name) " (%s)"
-vfio_migration_set_state(const char *name, const char *state) " (%s) state %s"
+vfio_migration_set_device_state(const char *name, const char *state) " (%s) state %s"
+vfio_migration_set_state(const char *name, const char *new_state, const char *recover_state) " (%s) new state %s, recover state %s"
vfio_migration_state_notifier(const char *name, int state) " (%s) state %d"
vfio_save_block(const char *name, int data_size) " (%s) data_size %d"
vfio_save_cleanup(const char *name) " (%s)"
--
2.26.3
On 5/15/24 15:21, Avihai Horon wrote:
> Move trace_vfio_migration_set_state() to the top of the function, add
> recover_state to it, and add a new trace event to
> vfio_migration_set_device_state().
>
> This improves tracing of device state changes as state changes are now
> also logged when vfio_migration_set_state() fails (covering recover
> state and device reset transitions) and in no-op state transitions to
> the same state.
>
> Suggested-by: Cédric Le Goater <clg@redhat.com>
> Signed-off-by: Avihai Horon <avihaih@nvidia.com>
Thanks for doing so,
Reviewed-by: Cédric Le Goater <clg@redhat.com>
C.
> ---
> hw/vfio/migration.c | 8 ++++++--
> hw/vfio/trace-events | 3 ++-
> 2 files changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> index f2b7a3067b..7f0d76ab50 100644
> --- a/hw/vfio/migration.c
> +++ b/hw/vfio/migration.c
> @@ -129,6 +129,9 @@ static void vfio_migration_set_device_state(VFIODevice *vbasedev,
> {
> VFIOMigration *migration = vbasedev->migration;
>
> + trace_vfio_migration_set_device_state(vbasedev->name,
> + mig_state_to_str(state));
> +
> migration->device_state = state;
> vfio_migration_send_event(vbasedev);
> }
> @@ -146,6 +149,9 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,
> (struct vfio_device_feature_mig_state *)feature->data;
> int ret;
>
> + trace_vfio_migration_set_state(vbasedev->name, mig_state_to_str(new_state),
> + mig_state_to_str(recover_state));
> +
> if (new_state == migration->device_state) {
> return 0;
> }
> @@ -203,8 +209,6 @@ static int vfio_migration_set_state(VFIODevice *vbasedev,
> migration->data_fd = mig_state->data_fd;
> }
>
> - trace_vfio_migration_set_state(vbasedev->name, mig_state_to_str(new_state));
> -
> return 0;
>
> reset_device:
> diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
> index f0474b244b..64161bf6f4 100644
> --- a/hw/vfio/trace-events
> +++ b/hw/vfio/trace-events
> @@ -152,7 +152,8 @@ vfio_load_device_config_state(const char *name) " (%s)"
> vfio_load_state(const char *name, uint64_t data) " (%s) data 0x%"PRIx64
> vfio_load_state_device_data(const char *name, uint64_t data_size, int ret) " (%s) size 0x%"PRIx64" ret %d"
> vfio_migration_realize(const char *name) " (%s)"
> -vfio_migration_set_state(const char *name, const char *state) " (%s) state %s"
> +vfio_migration_set_device_state(const char *name, const char *state) " (%s) state %s"
> +vfio_migration_set_state(const char *name, const char *new_state, const char *recover_state) " (%s) new state %s, recover state %s"
> vfio_migration_state_notifier(const char *name, int state) " (%s) state %d"
> vfio_save_block(const char *name, int data_size) " (%s) data_size %d"
> vfio_save_cleanup(const char *name) " (%s)"
© 2016 - 2026 Red Hat, Inc.