@@ -156,7 +156,7 @@ static int coroutine_fn backup_loop(BackupBlockJob *job)
job->bg_bcs_call = s = block_copy_async(job->bcs, 0,
QEMU_ALIGN_UP(job->len, job->cluster_size),
job->perf.max_workers, job->perf.max_chunk,
- backup_block_copy_callback, job);
+ true, backup_block_copy_callback, job);
while (!block_copy_call_finished(s) &&
!job_is_cancelled(&job->common.job))
@@ -54,6 +54,7 @@ typedef struct BlockCopyCallState {
int max_workers;
int64_t max_chunk;
bool ignore_ratelimit;
+ bool need_final_flush;
BlockCopyAsyncCallbackFunc cb;
void *cb_opaque;
/* Coroutine where async block-copy is running */
@@ -899,6 +900,10 @@ block_copy_common(BlockCopyCallState *call_state)
*/
} while (ret > 0 && !qatomic_read(&call_state->cancelled));
+ if (ret == 0 && call_state->need_final_flush) {
+ ret = bdrv_co_flush(s->target->bs);
+ }
+
qatomic_store_release(&call_state->finished, true);
if (call_state->cb) {
@@ -954,6 +959,7 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
BlockCopyCallState *block_copy_async(BlockCopyState *s,
int64_t offset, int64_t bytes,
int max_workers, int64_t max_chunk,
+ bool need_final_flush,
BlockCopyAsyncCallbackFunc cb,
void *cb_opaque)
{
@@ -965,6 +971,7 @@ BlockCopyCallState *block_copy_async(BlockCopyState *s,
.bytes = bytes,
.max_workers = max_workers,
.max_chunk = max_chunk,
+ .need_final_flush = need_final_flush,
.cb = cb,
.cb_opaque = cb_opaque,
@@ -62,6 +62,7 @@ int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
BlockCopyCallState *block_copy_async(BlockCopyState *s,
int64_t offset, int64_t bytes,
int max_workers, int64_t max_chunk,
+ bool need_final_flush,
BlockCopyAsyncCallbackFunc cb,
void *cb_opaque);
Actually block job is not completed without the final flush. It's rather unexpected to have broken target when job was successfully completed long ago and now we fail to flush or process just crashed/killed. Mirror job already has mirror_flush() for this. So, it's OK. Do this for backup job too. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> --- block/backup.c | 2 +- block/block-copy.c | 7 +++++++ include/block/block-copy.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-)