diff --git a/block-migration.c b/block-migration.c index bcd00390257a0d2d6179f34f987644b34597c1ad..43ab2028c0bb544f422c11677e729897e6500256 100644 --- a/block-migration.c +++ b/block-migration.c @@ -539,6 +539,7 @@ static int block_save_setup(QEMUFile *f, void *opaque) static int block_save_iterate(QEMUFile *f, void *opaque) { int ret; + int64_t last_ftell = qemu_ftell(f); DPRINTF("Enter save live iterate submitted %d transferred %d\n", block_mig_state.submitted, block_mig_state.transferred); @@ -582,12 +583,7 @@ static int block_save_iterate(QEMUFile *f, void *opaque) qemu_put_be64(f, BLK_MIG_FLAG_EOS); - /* Complete when bulk transfer is done and all dirty blocks have been - * transferred. - */ - return block_mig_state.bulk_completed && - block_mig_state.submitted == 0 && - block_mig_state.read_done == 0; + return qemu_ftell(f) - last_ftell; } static int block_save_complete(QEMUFile *f, void *opaque) @@ -629,10 +625,18 @@ static int block_save_complete(QEMUFile *f, void *opaque) static uint64_t block_save_pending(QEMUFile *f, void *opaque, uint64_t max_size) { + /* Estimate pending number of bytes to send */ + uint64_t pending = get_remaining_dirty() + + block_mig_state.submitted * BLOCK_SIZE + + block_mig_state.read_done * BLOCK_SIZE; + + /* Report at least one block pending during bulk phase */ + if (pending == 0 && !block_mig_state.bulk_completed) { + pending = BLOCK_SIZE; + } - DPRINTF("Enter save live pending %ld\n", get_remaining_dirty()); - - return get_remaining_dirty(); + DPRINTF("Enter save live pending %" PRIu64 "\n", pending); + return pending; } static int block_load(QEMUFile *f, void *opaque, int version_id)