]> git.proxmox.com Git - mirror_qemu.git/blob - block/block-copy.c
block/block-copy: add max_chunk and max_workers parameters
[mirror_qemu.git] / block / block-copy.c
1 /*
2 * block_copy API
3 *
4 * Copyright (C) 2013 Proxmox Server Solutions
5 * Copyright (c) 2019 Virtuozzo International GmbH.
6 *
7 * Authors:
8 * Dietmar Maurer (dietmar@proxmox.com)
9 * Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
10 *
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
13 */
14
15 #include "qemu/osdep.h"
16
17 #include "trace.h"
18 #include "qapi/error.h"
19 #include "block/block-copy.h"
20 #include "sysemu/block-backend.h"
21 #include "qemu/units.h"
22 #include "qemu/coroutine.h"
23 #include "block/aio_task.h"
24
25 #define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB)
26 #define BLOCK_COPY_MAX_BUFFER (1 * MiB)
27 #define BLOCK_COPY_MAX_MEM (128 * MiB)
28 #define BLOCK_COPY_MAX_WORKERS 64
29
30 static coroutine_fn int block_copy_task_entry(AioTask *task);
31
32 typedef struct BlockCopyCallState {
33 /* IN parameters. Initialized in block_copy_async() and never changed. */
34 BlockCopyState *s;
35 int64_t offset;
36 int64_t bytes;
37 int max_workers;
38 int64_t max_chunk;
39 BlockCopyAsyncCallbackFunc cb;
40 void *cb_opaque;
41
42 /* Coroutine where async block-copy is running */
43 Coroutine *co;
44
45 /* State */
46 int ret;
47 bool finished;
48
49 /* OUT parameters */
50 bool error_is_read;
51 } BlockCopyCallState;
52
53 typedef struct BlockCopyTask {
54 AioTask task;
55
56 BlockCopyState *s;
57 BlockCopyCallState *call_state;
58 int64_t offset;
59 int64_t bytes;
60 bool zeroes;
61 QLIST_ENTRY(BlockCopyTask) list;
62 CoQueue wait_queue; /* coroutines blocked on this task */
63 } BlockCopyTask;
64
65 static int64_t task_end(BlockCopyTask *task)
66 {
67 return task->offset + task->bytes;
68 }
69
70 typedef struct BlockCopyState {
71 /*
72 * BdrvChild objects are not owned or managed by block-copy. They are
73 * provided by block-copy user and user is responsible for appropriate
74 * permissions on these children.
75 */
76 BdrvChild *source;
77 BdrvChild *target;
78 BdrvDirtyBitmap *copy_bitmap;
79 int64_t in_flight_bytes;
80 int64_t cluster_size;
81 bool use_copy_range;
82 int64_t copy_size;
83 uint64_t len;
84 QLIST_HEAD(, BlockCopyTask) tasks;
85
86 BdrvRequestFlags write_flags;
87
88 /*
89 * skip_unallocated:
90 *
91 * Used by sync=top jobs, which first scan the source node for unallocated
92 * areas and clear them in the copy_bitmap. During this process, the bitmap
93 * is thus not fully initialized: It may still have bits set for areas that
94 * are unallocated and should actually not be copied.
95 *
96 * This is indicated by skip_unallocated.
97 *
98 * In this case, block_copy() will query the source’s allocation status,
99 * skip unallocated regions, clear them in the copy_bitmap, and invoke
100 * block_copy_reset_unallocated() every time it does.
101 */
102 bool skip_unallocated;
103
104 ProgressMeter *progress;
105 /* progress_bytes_callback: called when some copying progress is done. */
106 ProgressBytesCallbackFunc progress_bytes_callback;
107 void *progress_opaque;
108
109 SharedResource *mem;
110 } BlockCopyState;
111
112 static BlockCopyTask *find_conflicting_task(BlockCopyState *s,
113 int64_t offset, int64_t bytes)
114 {
115 BlockCopyTask *t;
116
117 QLIST_FOREACH(t, &s->tasks, list) {
118 if (offset + bytes > t->offset && offset < t->offset + t->bytes) {
119 return t;
120 }
121 }
122
123 return NULL;
124 }
125
126 /*
127 * If there are no intersecting tasks return false. Otherwise, wait for the
128 * first found intersecting tasks to finish and return true.
129 */
130 static bool coroutine_fn block_copy_wait_one(BlockCopyState *s, int64_t offset,
131 int64_t bytes)
132 {
133 BlockCopyTask *task = find_conflicting_task(s, offset, bytes);
134
135 if (!task) {
136 return false;
137 }
138
139 qemu_co_queue_wait(&task->wait_queue, NULL);
140
141 return true;
142 }
143
144 /*
145 * Search for the first dirty area in offset/bytes range and create task at
146 * the beginning of it.
147 */
148 static BlockCopyTask *block_copy_task_create(BlockCopyState *s,
149 BlockCopyCallState *call_state,
150 int64_t offset, int64_t bytes)
151 {
152 BlockCopyTask *task;
153 int64_t max_chunk = MIN_NON_ZERO(s->copy_size, call_state->max_chunk);
154
155 if (!bdrv_dirty_bitmap_next_dirty_area(s->copy_bitmap,
156 offset, offset + bytes,
157 max_chunk, &offset, &bytes))
158 {
159 return NULL;
160 }
161
162 assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
163 bytes = QEMU_ALIGN_UP(bytes, s->cluster_size);
164
165 /* region is dirty, so no existent tasks possible in it */
166 assert(!find_conflicting_task(s, offset, bytes));
167
168 bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes);
169 s->in_flight_bytes += bytes;
170
171 task = g_new(BlockCopyTask, 1);
172 *task = (BlockCopyTask) {
173 .task.func = block_copy_task_entry,
174 .s = s,
175 .call_state = call_state,
176 .offset = offset,
177 .bytes = bytes,
178 };
179 qemu_co_queue_init(&task->wait_queue);
180 QLIST_INSERT_HEAD(&s->tasks, task, list);
181
182 return task;
183 }
184
185 /*
186 * block_copy_task_shrink
187 *
188 * Drop the tail of the task to be handled later. Set dirty bits back and
189 * wake up all tasks waiting for us (may be some of them are not intersecting
190 * with shrunk task)
191 */
192 static void coroutine_fn block_copy_task_shrink(BlockCopyTask *task,
193 int64_t new_bytes)
194 {
195 if (new_bytes == task->bytes) {
196 return;
197 }
198
199 assert(new_bytes > 0 && new_bytes < task->bytes);
200
201 task->s->in_flight_bytes -= task->bytes - new_bytes;
202 bdrv_set_dirty_bitmap(task->s->copy_bitmap,
203 task->offset + new_bytes, task->bytes - new_bytes);
204
205 task->bytes = new_bytes;
206 qemu_co_queue_restart_all(&task->wait_queue);
207 }
208
209 static void coroutine_fn block_copy_task_end(BlockCopyTask *task, int ret)
210 {
211 task->s->in_flight_bytes -= task->bytes;
212 if (ret < 0) {
213 bdrv_set_dirty_bitmap(task->s->copy_bitmap, task->offset, task->bytes);
214 }
215 QLIST_REMOVE(task, list);
216 qemu_co_queue_restart_all(&task->wait_queue);
217 }
218
219 void block_copy_state_free(BlockCopyState *s)
220 {
221 if (!s) {
222 return;
223 }
224
225 bdrv_release_dirty_bitmap(s->copy_bitmap);
226 shres_destroy(s->mem);
227 g_free(s);
228 }
229
230 static uint32_t block_copy_max_transfer(BdrvChild *source, BdrvChild *target)
231 {
232 return MIN_NON_ZERO(INT_MAX,
233 MIN_NON_ZERO(source->bs->bl.max_transfer,
234 target->bs->bl.max_transfer));
235 }
236
237 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
238 int64_t cluster_size, bool use_copy_range,
239 BdrvRequestFlags write_flags, Error **errp)
240 {
241 BlockCopyState *s;
242 BdrvDirtyBitmap *copy_bitmap;
243
244 copy_bitmap = bdrv_create_dirty_bitmap(source->bs, cluster_size, NULL,
245 errp);
246 if (!copy_bitmap) {
247 return NULL;
248 }
249 bdrv_disable_dirty_bitmap(copy_bitmap);
250
251 s = g_new(BlockCopyState, 1);
252 *s = (BlockCopyState) {
253 .source = source,
254 .target = target,
255 .copy_bitmap = copy_bitmap,
256 .cluster_size = cluster_size,
257 .len = bdrv_dirty_bitmap_size(copy_bitmap),
258 .write_flags = write_flags,
259 .mem = shres_create(BLOCK_COPY_MAX_MEM),
260 };
261
262 if (block_copy_max_transfer(source, target) < cluster_size) {
263 /*
264 * copy_range does not respect max_transfer. We don't want to bother
265 * with requests smaller than block-copy cluster size, so fallback to
266 * buffered copying (read and write respect max_transfer on their
267 * behalf).
268 */
269 s->use_copy_range = false;
270 s->copy_size = cluster_size;
271 } else if (write_flags & BDRV_REQ_WRITE_COMPRESSED) {
272 /* Compression supports only cluster-size writes and no copy-range. */
273 s->use_copy_range = false;
274 s->copy_size = cluster_size;
275 } else {
276 /*
277 * We enable copy-range, but keep small copy_size, until first
278 * successful copy_range (look at block_copy_do_copy).
279 */
280 s->use_copy_range = use_copy_range;
281 s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
282 }
283
284 QLIST_INIT(&s->tasks);
285
286 return s;
287 }
288
289 void block_copy_set_progress_callback(
290 BlockCopyState *s,
291 ProgressBytesCallbackFunc progress_bytes_callback,
292 void *progress_opaque)
293 {
294 s->progress_bytes_callback = progress_bytes_callback;
295 s->progress_opaque = progress_opaque;
296 }
297
298 void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm)
299 {
300 s->progress = pm;
301 }
302
303 /*
304 * Takes ownership of @task
305 *
306 * If pool is NULL directly run the task, otherwise schedule it into the pool.
307 *
308 * Returns: task.func return code if pool is NULL
309 * otherwise -ECANCELED if pool status is bad
310 * otherwise 0 (successfully scheduled)
311 */
312 static coroutine_fn int block_copy_task_run(AioTaskPool *pool,
313 BlockCopyTask *task)
314 {
315 if (!pool) {
316 int ret = task->task.func(&task->task);
317
318 g_free(task);
319 return ret;
320 }
321
322 aio_task_pool_wait_slot(pool);
323 if (aio_task_pool_status(pool) < 0) {
324 co_put_to_shres(task->s->mem, task->bytes);
325 block_copy_task_end(task, -ECANCELED);
326 g_free(task);
327 return -ECANCELED;
328 }
329
330 aio_task_pool_start_task(pool, &task->task);
331
332 return 0;
333 }
334
335 /*
336 * block_copy_do_copy
337 *
338 * Do copy of cluster-aligned chunk. Requested region is allowed to exceed
339 * s->len only to cover last cluster when s->len is not aligned to clusters.
340 *
341 * No sync here: nor bitmap neighter intersecting requests handling, only copy.
342 *
343 * Returns 0 on success.
344 */
345 static int coroutine_fn block_copy_do_copy(BlockCopyState *s,
346 int64_t offset, int64_t bytes,
347 bool zeroes, bool *error_is_read)
348 {
349 int ret;
350 int64_t nbytes = MIN(offset + bytes, s->len) - offset;
351 void *bounce_buffer = NULL;
352
353 assert(offset >= 0 && bytes > 0 && INT64_MAX - offset >= bytes);
354 assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
355 assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
356 assert(offset < s->len);
357 assert(offset + bytes <= s->len ||
358 offset + bytes == QEMU_ALIGN_UP(s->len, s->cluster_size));
359 assert(nbytes < INT_MAX);
360
361 if (zeroes) {
362 ret = bdrv_co_pwrite_zeroes(s->target, offset, nbytes, s->write_flags &
363 ~BDRV_REQ_WRITE_COMPRESSED);
364 if (ret < 0) {
365 trace_block_copy_write_zeroes_fail(s, offset, ret);
366 *error_is_read = false;
367 }
368 return ret;
369 }
370
371 if (s->use_copy_range) {
372 ret = bdrv_co_copy_range(s->source, offset, s->target, offset, nbytes,
373 0, s->write_flags);
374 if (ret < 0) {
375 trace_block_copy_copy_range_fail(s, offset, ret);
376 s->use_copy_range = false;
377 s->copy_size = MAX(s->cluster_size, BLOCK_COPY_MAX_BUFFER);
378 /* Fallback to read+write with allocated buffer */
379 } else {
380 if (s->use_copy_range) {
381 /*
382 * Successful copy-range. Now increase copy_size. copy_range
383 * does not respect max_transfer (it's a TODO), so we factor
384 * that in here.
385 *
386 * Note: we double-check s->use_copy_range for the case when
387 * parallel block-copy request unsets it during previous
388 * bdrv_co_copy_range call.
389 */
390 s->copy_size =
391 MIN(MAX(s->cluster_size, BLOCK_COPY_MAX_COPY_RANGE),
392 QEMU_ALIGN_DOWN(block_copy_max_transfer(s->source,
393 s->target),
394 s->cluster_size));
395 }
396 goto out;
397 }
398 }
399
400 /*
401 * In case of failed copy_range request above, we may proceed with buffered
402 * request larger than BLOCK_COPY_MAX_BUFFER. Still, further requests will
403 * be properly limited, so don't care too much. Moreover the most likely
404 * case (copy_range is unsupported for the configuration, so the very first
405 * copy_range request fails) is handled by setting large copy_size only
406 * after first successful copy_range.
407 */
408
409 bounce_buffer = qemu_blockalign(s->source->bs, nbytes);
410
411 ret = bdrv_co_pread(s->source, offset, nbytes, bounce_buffer, 0);
412 if (ret < 0) {
413 trace_block_copy_read_fail(s, offset, ret);
414 *error_is_read = true;
415 goto out;
416 }
417
418 ret = bdrv_co_pwrite(s->target, offset, nbytes, bounce_buffer,
419 s->write_flags);
420 if (ret < 0) {
421 trace_block_copy_write_fail(s, offset, ret);
422 *error_is_read = false;
423 goto out;
424 }
425
426 out:
427 qemu_vfree(bounce_buffer);
428
429 return ret;
430 }
431
432 static coroutine_fn int block_copy_task_entry(AioTask *task)
433 {
434 BlockCopyTask *t = container_of(task, BlockCopyTask, task);
435 bool error_is_read = false;
436 int ret;
437
438 ret = block_copy_do_copy(t->s, t->offset, t->bytes, t->zeroes,
439 &error_is_read);
440 if (ret < 0 && !t->call_state->ret) {
441 t->call_state->ret = ret;
442 t->call_state->error_is_read = error_is_read;
443 } else {
444 progress_work_done(t->s->progress, t->bytes);
445 t->s->progress_bytes_callback(t->bytes, t->s->progress_opaque);
446 }
447 co_put_to_shres(t->s->mem, t->bytes);
448 block_copy_task_end(t, ret);
449
450 return ret;
451 }
452
453 static int block_copy_block_status(BlockCopyState *s, int64_t offset,
454 int64_t bytes, int64_t *pnum)
455 {
456 int64_t num;
457 BlockDriverState *base;
458 int ret;
459
460 if (s->skip_unallocated) {
461 base = bdrv_backing_chain_next(s->source->bs);
462 } else {
463 base = NULL;
464 }
465
466 ret = bdrv_block_status_above(s->source->bs, base, offset, bytes, &num,
467 NULL, NULL);
468 if (ret < 0 || num < s->cluster_size) {
469 /*
470 * On error or if failed to obtain large enough chunk just fallback to
471 * copy one cluster.
472 */
473 num = s->cluster_size;
474 ret = BDRV_BLOCK_ALLOCATED | BDRV_BLOCK_DATA;
475 } else if (offset + num == s->len) {
476 num = QEMU_ALIGN_UP(num, s->cluster_size);
477 } else {
478 num = QEMU_ALIGN_DOWN(num, s->cluster_size);
479 }
480
481 *pnum = num;
482 return ret;
483 }
484
485 /*
486 * Check if the cluster starting at offset is allocated or not.
487 * return via pnum the number of contiguous clusters sharing this allocation.
488 */
489 static int block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset,
490 int64_t *pnum)
491 {
492 BlockDriverState *bs = s->source->bs;
493 int64_t count, total_count = 0;
494 int64_t bytes = s->len - offset;
495 int ret;
496
497 assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
498
499 while (true) {
500 ret = bdrv_is_allocated(bs, offset, bytes, &count);
501 if (ret < 0) {
502 return ret;
503 }
504
505 total_count += count;
506
507 if (ret || count == 0) {
508 /*
509 * ret: partial segment(s) are considered allocated.
510 * otherwise: unallocated tail is treated as an entire segment.
511 */
512 *pnum = DIV_ROUND_UP(total_count, s->cluster_size);
513 return ret;
514 }
515
516 /* Unallocated segment(s) with uncertain following segment(s) */
517 if (total_count >= s->cluster_size) {
518 *pnum = total_count / s->cluster_size;
519 return 0;
520 }
521
522 offset += count;
523 bytes -= count;
524 }
525 }
526
527 /*
528 * Reset bits in copy_bitmap starting at offset if they represent unallocated
529 * data in the image. May reset subsequent contiguous bits.
530 * @return 0 when the cluster at @offset was unallocated,
531 * 1 otherwise, and -ret on error.
532 */
533 int64_t block_copy_reset_unallocated(BlockCopyState *s,
534 int64_t offset, int64_t *count)
535 {
536 int ret;
537 int64_t clusters, bytes;
538
539 ret = block_copy_is_cluster_allocated(s, offset, &clusters);
540 if (ret < 0) {
541 return ret;
542 }
543
544 bytes = clusters * s->cluster_size;
545
546 if (!ret) {
547 bdrv_reset_dirty_bitmap(s->copy_bitmap, offset, bytes);
548 progress_set_remaining(s->progress,
549 bdrv_get_dirty_count(s->copy_bitmap) +
550 s->in_flight_bytes);
551 }
552
553 *count = bytes;
554 return ret;
555 }
556
557 /*
558 * block_copy_dirty_clusters
559 *
560 * Copy dirty clusters in @offset/@bytes range.
561 * Returns 1 if dirty clusters found and successfully copied, 0 if no dirty
562 * clusters found and -errno on failure.
563 */
564 static int coroutine_fn
565 block_copy_dirty_clusters(BlockCopyCallState *call_state)
566 {
567 BlockCopyState *s = call_state->s;
568 int64_t offset = call_state->offset;
569 int64_t bytes = call_state->bytes;
570
571 int ret = 0;
572 bool found_dirty = false;
573 int64_t end = offset + bytes;
574 AioTaskPool *aio = NULL;
575
576 /*
577 * block_copy() user is responsible for keeping source and target in same
578 * aio context
579 */
580 assert(bdrv_get_aio_context(s->source->bs) ==
581 bdrv_get_aio_context(s->target->bs));
582
583 assert(QEMU_IS_ALIGNED(offset, s->cluster_size));
584 assert(QEMU_IS_ALIGNED(bytes, s->cluster_size));
585
586 while (bytes && aio_task_pool_status(aio) == 0) {
587 BlockCopyTask *task;
588 int64_t status_bytes;
589
590 task = block_copy_task_create(s, call_state, offset, bytes);
591 if (!task) {
592 /* No more dirty bits in the bitmap */
593 trace_block_copy_skip_range(s, offset, bytes);
594 break;
595 }
596 if (task->offset > offset) {
597 trace_block_copy_skip_range(s, offset, task->offset - offset);
598 }
599
600 found_dirty = true;
601
602 ret = block_copy_block_status(s, task->offset, task->bytes,
603 &status_bytes);
604 assert(ret >= 0); /* never fail */
605 if (status_bytes < task->bytes) {
606 block_copy_task_shrink(task, status_bytes);
607 }
608 if (s->skip_unallocated && !(ret & BDRV_BLOCK_ALLOCATED)) {
609 block_copy_task_end(task, 0);
610 progress_set_remaining(s->progress,
611 bdrv_get_dirty_count(s->copy_bitmap) +
612 s->in_flight_bytes);
613 trace_block_copy_skip_range(s, task->offset, task->bytes);
614 offset = task_end(task);
615 bytes = end - offset;
616 g_free(task);
617 continue;
618 }
619 task->zeroes = ret & BDRV_BLOCK_ZERO;
620
621 trace_block_copy_process(s, task->offset);
622
623 co_get_from_shres(s->mem, task->bytes);
624
625 offset = task_end(task);
626 bytes = end - offset;
627
628 if (!aio && bytes) {
629 aio = aio_task_pool_new(call_state->max_workers);
630 }
631
632 ret = block_copy_task_run(aio, task);
633 if (ret < 0) {
634 goto out;
635 }
636 }
637
638 out:
639 if (aio) {
640 aio_task_pool_wait_all(aio);
641
642 /*
643 * We are not really interested in -ECANCELED returned from
644 * block_copy_task_run. If it fails, it means some task already failed
645 * for real reason, let's return first failure.
646 * Still, assert that we don't rewrite failure by success.
647 *
648 * Note: ret may be positive here because of block-status result.
649 */
650 assert(ret >= 0 || aio_task_pool_status(aio) < 0);
651 ret = aio_task_pool_status(aio);
652
653 aio_task_pool_free(aio);
654 }
655
656 return ret < 0 ? ret : found_dirty;
657 }
658
659 /*
660 * block_copy_common
661 *
662 * Copy requested region, accordingly to dirty bitmap.
663 * Collaborate with parallel block_copy requests: if they succeed it will help
664 * us. If they fail, we will retry not-copied regions. So, if we return error,
665 * it means that some I/O operation failed in context of _this_ block_copy call,
666 * not some parallel operation.
667 */
668 static int coroutine_fn block_copy_common(BlockCopyCallState *call_state)
669 {
670 int ret;
671
672 do {
673 ret = block_copy_dirty_clusters(call_state);
674
675 if (ret == 0) {
676 ret = block_copy_wait_one(call_state->s, call_state->offset,
677 call_state->bytes);
678 }
679
680 /*
681 * We retry in two cases:
682 * 1. Some progress done
683 * Something was copied, which means that there were yield points
684 * and some new dirty bits may have appeared (due to failed parallel
685 * block-copy requests).
686 * 2. We have waited for some intersecting block-copy request
687 * It may have failed and produced new dirty bits.
688 */
689 } while (ret > 0);
690
691 call_state->finished = true;
692
693 if (call_state->cb) {
694 call_state->cb(call_state->cb_opaque);
695 }
696
697 return ret;
698 }
699
700 int coroutine_fn block_copy(BlockCopyState *s, int64_t start, int64_t bytes,
701 bool *error_is_read)
702 {
703 BlockCopyCallState call_state = {
704 .s = s,
705 .offset = start,
706 .bytes = bytes,
707 .max_workers = BLOCK_COPY_MAX_WORKERS,
708 };
709
710 int ret = block_copy_common(&call_state);
711
712 if (error_is_read && ret < 0) {
713 *error_is_read = call_state.error_is_read;
714 }
715
716 return ret;
717 }
718
719 static void coroutine_fn block_copy_async_co_entry(void *opaque)
720 {
721 block_copy_common(opaque);
722 }
723
724 BlockCopyCallState *block_copy_async(BlockCopyState *s,
725 int64_t offset, int64_t bytes,
726 int max_workers, int64_t max_chunk,
727 BlockCopyAsyncCallbackFunc cb,
728 void *cb_opaque)
729 {
730 BlockCopyCallState *call_state = g_new(BlockCopyCallState, 1);
731
732 *call_state = (BlockCopyCallState) {
733 .s = s,
734 .offset = offset,
735 .bytes = bytes,
736 .max_workers = max_workers,
737 .max_chunk = max_chunk,
738 .cb = cb,
739 .cb_opaque = cb_opaque,
740
741 .co = qemu_coroutine_create(block_copy_async_co_entry, call_state),
742 };
743
744 qemu_coroutine_enter(call_state->co);
745
746 return call_state;
747 }
748
749 void block_copy_call_free(BlockCopyCallState *call_state)
750 {
751 if (!call_state) {
752 return;
753 }
754
755 assert(call_state->finished);
756 g_free(call_state);
757 }
758
759 bool block_copy_call_finished(BlockCopyCallState *call_state)
760 {
761 return call_state->finished;
762 }
763
764 bool block_copy_call_succeeded(BlockCopyCallState *call_state)
765 {
766 return call_state->finished && call_state->ret == 0;
767 }
768
769 bool block_copy_call_failed(BlockCopyCallState *call_state)
770 {
771 return call_state->finished && call_state->ret < 0;
772 }
773
774 int block_copy_call_status(BlockCopyCallState *call_state, bool *error_is_read)
775 {
776 assert(call_state->finished);
777 if (error_is_read) {
778 *error_is_read = call_state->error_is_read;
779 }
780 return call_state->ret;
781 }
782
783 BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s)
784 {
785 return s->copy_bitmap;
786 }
787
788 void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip)
789 {
790 s->skip_unallocated = skip;
791 }