vfio/migration: Extract VFIO_MIG_FLAG_DEV_INIT_DATA_SENT sending to helper
Extract the VFIO_MIG_FLAG_DEV_INIT_DATA_SENT flag sending logic from vfio_save_iterate() into vfio_send_init_data_flag() for clarity. Also add a trace while at it. Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Avihai Horon <avihaih@nvidia.com> Link: https://lore.kernel.org/qemu-devel/20260706085211.13905-10-avihaih@nvidia.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
Avihai Horon committed
Jul 6, 2026 at 11:52 UTC
309ea71a6a7a62e8eb1f8c21d226c439655a7472
2 files changed
+22
-5
hw/vfio/migration.c
+21
-5
@@ -480,6 +480,26 @@ static void vfio_update_estimated_pending_data(VFIOMigration *migration,
480
data_size);
481
}
482
483
+/* Returns true if the init data flag was sent, false otherwise */
484
+static bool vfio_send_init_data_flag(QEMUFile *f, VFIOMigration *migration)
485
+{
486
+ VFIODevice *vbasedev = migration->vbasedev;
487
+
488
+ if (!migrate_switchover_ack()) {
489
+ return false;
490
+ }
491
+
492
+ if (migration->precopy_init_size || migration->initial_data_sent) {
493
+ return false;
494
+ }
495
+
496
+ qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT);
497
+ migration->initial_data_sent = true;
498
+ trace_vfio_send_init_data_flag(vbasedev->name);
499
+
500
+ return true;
501
+}
502
+
503
static bool vfio_precopy_supported(VFIODevice *vbasedev)
504
{
505
VFIOMigration *migration = vbasedev->migration;
@@ -693,11 +713,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque)
713
714
vfio_update_estimated_pending_data(migration, data_size);
715
696
- if (migrate_switchover_ack() && !migration->precopy_init_size &&
697
- !migration->initial_data_sent) {
698
- qemu_put_be64(f, VFIO_MIG_FLAG_DEV_INIT_DATA_SENT);
699
- migration->initial_data_sent = true;
700
- } else {
716
+ if (!vfio_send_init_data_flag(f, migration)) {
717
qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE);
718
}
719
hw/vfio/trace-events
+1
@@ -177,6 +177,7 @@ vfio_save_iterate(const char *name, uint64_t precopy_init_size, uint64_t precopy
177
vfio_save_iterate_start(const char *name) " (%s)"
178
vfio_save_setup(const char *name, uint64_t data_buffer_size) " (%s) data buffer size %"PRIu64
179
vfio_state_pending(const char *name, uint64_t stopcopy_size, uint64_t precopy_init_size, uint64_t precopy_dirty_size, bool exact, bool final) " (%s) stopcopy size %"PRIu64", precopy initial size %"PRIu64", precopy dirty size %"PRIu64", exact %d, final %d"
180
+vfio_send_init_data_flag(const char *name) " (%s)"
181
vfio_vmstate_change(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"
182
vfio_vmstate_change_prepare(const char *name, int running, const char *reason, const char *dev_state) " (%s) running %d reason %s device state %s"
183