migration: Use the new save_query_pending() API directly
It's easier to use the new API directly in the migration iterations. This also paves way for follow up patches to add new data to report directly to the iterator function. When at it, merge the tracepoints too into one. No functional change intended. Reviewed-by: Juraj Marcin <jmarcin@redhat.com> Reviewed-by: Avihai Horon <avihaih@nvidia.com> Link: https://lore.kernel.org/r/20260421202110.306051-7-peterx@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com>
Peter Xu committed
Apr 21, 2026 at 16:21 UTC
0b881dc13761b5df22cda5d9d30bdf3610e37d49
4 files changed
+10
-36
migration/migration.c
+7
-9
@@ -3208,17 +3208,17 @@ typedef enum {
3208
*/
3209
static MigIterateState migration_iteration_run(MigrationState *s)
3210
{
3211
- uint64_t must_precopy, can_postcopy, pending_size;
3211
Error *local_err = NULL;
3212
bool in_postcopy = (s->state == MIGRATION_STATUS_POSTCOPY_DEVICE ||
3213
s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE);
3214
bool can_switchover = migration_can_switchover(s);
3215
+ MigPendingData pending = { };
3216
+ uint64_t pending_size;
3217
bool complete_ready;
3218
3219
/* Fast path - get the estimated amount of pending data */
3219
- qemu_savevm_state_pending_estimate(&must_precopy, &can_postcopy);
3220
- pending_size = must_precopy + can_postcopy;
3221
- trace_migrate_pending_estimate(pending_size, must_precopy, can_postcopy);
3220
+ qemu_savevm_query_pending(&pending, false);
3221
+ pending_size = pending.precopy_bytes + pending.postcopy_bytes;
3222
3223
if (in_postcopy) {
3224
/*
@@ -3259,14 +3259,12 @@ static MigIterateState migration_iteration_run(MigrationState *s)
3259
* during postcopy phase.
3260
*/
3261
if (pending_size <= s->threshold_size) {
3262
- qemu_savevm_state_pending_exact(&must_precopy, &can_postcopy);
3263
- pending_size = must_precopy + can_postcopy;
3264
- trace_migrate_pending_exact(pending_size, must_precopy,
3265
- can_postcopy);
3262
+ qemu_savevm_query_pending(&pending, true);
3263
+ pending_size = pending.precopy_bytes + pending.postcopy_bytes;
3264
}
3265
3266
/* Should we switch to postcopy now? */
3269
- if (must_precopy <= s->threshold_size &&
3267
+ if (pending.precopy_bytes <= s->threshold_size &&
3268
can_switchover && qatomic_read(&s->start_postcopy)) {
3269
if (postcopy_start(s, &local_err)) {
3270
migrate_error_propagate(s, error_copy(local_err));
migration/savevm.c
+2
-21
@@ -1812,28 +1812,9 @@ void qemu_savevm_query_pending(MigPendingData *pending, bool exact)
1812
}
1813
se->ops->save_query_pending(se->opaque, pending, exact);
1814
}
1815
-}
1816
-
1817
-void qemu_savevm_state_pending_estimate(uint64_t *must_precopy,
1818
- uint64_t *can_postcopy)
1819
-{
1820
- MigPendingData pending;
1821
-
1822
- qemu_savevm_query_pending(&pending, false);
1823
-
1824
- *must_precopy = pending.precopy_bytes;
1825
- *can_postcopy = pending.postcopy_bytes;
1826
-}
1827
-
1828
-void qemu_savevm_state_pending_exact(uint64_t *must_precopy,
1829
- uint64_t *can_postcopy)
1830
-{
1831
- MigPendingData pending;
1832
-
1833
- qemu_savevm_query_pending(&pending, true);
1815
1835
- *must_precopy = pending.precopy_bytes;
1836
- *can_postcopy = pending.postcopy_bytes;
1816
+ trace_qemu_savevm_query_pending(exact, pending->precopy_bytes,
1817
+ pending->postcopy_bytes);
1818
}
1819
1820
void qemu_savevm_state_cleanup(void)
migration/savevm.h
-4
@@ -46,10 +46,6 @@ void qemu_savevm_state_cleanup(void);
46
void qemu_savevm_state_complete_postcopy(QEMUFile *f);
47
int qemu_savevm_state_complete_precopy(MigrationState *s);
48
void qemu_savevm_query_pending(MigPendingData *pending, bool exact);
49
-void qemu_savevm_state_pending_exact(uint64_t *must_precopy,
50
- uint64_t *can_postcopy);
51
-void qemu_savevm_state_pending_estimate(uint64_t *must_precopy,
52
- uint64_t *can_postcopy);
49
int qemu_savevm_state_complete_precopy_iterable(QEMUFile *f, bool in_postcopy);
50
bool qemu_savevm_state_postcopy_prepare(QEMUFile *f, Error **errp);
51
void qemu_savevm_state_end(QEMUFile *f);
migration/trace-events
+1
-2
@@ -7,6 +7,7 @@ qemu_loadvm_state_section_partend(uint32_t section_id) "%u"
7
qemu_loadvm_state_post_main(int ret) "%d"
8
qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u"
9
qemu_savevm_send_packaged(void) ""
10
+qemu_savevm_query_pending(bool exact, uint64_t precopy, uint64_t postcopy) "exact=%d, precopy=%"PRIu64", postcopy=%"PRIu64
11
loadvm_state_switchover_ack_needed(unsigned int switchover_ack_pending_num) "Switchover ack pending num=%u"
12
loadvm_state_setup(void) ""
13
loadvm_state_cleanup(void) ""
@@ -161,8 +162,6 @@ migration_cleanup(void) ""
162
migrate_error(const char *error_desc) "error=%s"
163
migration_cancel(void) ""
164
migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) "in %s at 0x%zx len 0x%zx"
164
-migrate_pending_exact(uint64_t size, uint64_t pre, uint64_t post) "exact pending size %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")"
165
-migrate_pending_estimate(uint64_t size, uint64_t pre, uint64_t post) "estimate pending size %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")"
165
migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d"
166
migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%"PRIi64
167
migration_completion_file_err(void) ""