migration: Fix qmp_query_migrate mbps value
authorFabiano Rosas <farosas@suse.de>
Mon, 26 Feb 2024 14:33:35 +0000 (11:33 -0300)
committerPeter Xu <peterx@redhat.com>
Wed, 28 Feb 2024 03:31:28 +0000 (11:31 +0800)
commit63f64d77f04337c21564fead6e9a55fdb2c80740
tree591ac9ed8f1fd7a49b16131e751920f68bf1685e
parentcbdafc1b348b9a9dd6e0e6c82ff3e281c93205fe
migration: Fix qmp_query_migrate mbps value

The QMP command query_migrate might see incorrect throughput numbers
if it runs after we've set the migration completion status but before
migration_calculate_complete() has updated s->total_time and s->mbps.

The migration status would show COMPLETED, but the throughput value
would be the one from the last iteration and not the one from the
whole migration. This will usually be a larger value due to the time
period being smaller (one iteration).

Move migration_calculate_complete() earlier so that the status
MIGRATION_STATUS_COMPLETED is only emitted after the final counters
update. Keep everything under the BQL so the QMP thread sees the
updates as atomic.

Rename migration_calculate_complete to migration_completion_end to
reflect its new purpose of also updating s->state.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20240226143335.14282-1-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
migration/migration.c