]> git.proxmox.com Git - mirror_qemu.git/blob - include/block/block-copy.h
block: move block_copy from block/backup.c to separate file
[mirror_qemu.git] / include / block / block-copy.h
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 #ifndef BLOCK_COPY_H
16 #define BLOCK_COPY_H
17
18 #include "block/block.h"
19
20 typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque);
21 typedef void (*ProgressResetCallbackFunc)(void *opaque);
22 typedef struct BlockCopyState {
23 BlockBackend *source;
24 BlockBackend *target;
25 BdrvDirtyBitmap *copy_bitmap;
26 int64_t cluster_size;
27 bool use_copy_range;
28 int64_t copy_range_size;
29 uint64_t len;
30
31 BdrvRequestFlags write_flags;
32
33 /*
34 * skip_unallocated:
35 *
36 * Used by sync=top jobs, which first scan the source node for unallocated
37 * areas and clear them in the copy_bitmap. During this process, the bitmap
38 * is thus not fully initialized: It may still have bits set for areas that
39 * are unallocated and should actually not be copied.
40 *
41 * This is indicated by skip_unallocated.
42 *
43 * In this case, block_copy() will query the source’s allocation status,
44 * skip unallocated regions, clear them in the copy_bitmap, and invoke
45 * block_copy_reset_unallocated() every time it does.
46 */
47 bool skip_unallocated;
48
49 /* progress_bytes_callback: called when some copying progress is done. */
50 ProgressBytesCallbackFunc progress_bytes_callback;
51
52 /*
53 * progress_reset_callback: called when some bytes reset from copy_bitmap
54 * (see @skip_unallocated above). The callee is assumed to recalculate how
55 * many bytes remain based on the dirty bit count of copy_bitmap.
56 */
57 ProgressResetCallbackFunc progress_reset_callback;
58 void *progress_opaque;
59 } BlockCopyState;
60
61 BlockCopyState *block_copy_state_new(
62 BlockDriverState *source, BlockDriverState *target,
63 int64_t cluster_size, BdrvRequestFlags write_flags,
64 ProgressBytesCallbackFunc progress_bytes_callback,
65 ProgressResetCallbackFunc progress_reset_callback,
66 void *progress_opaque, Error **errp);
67
68 void block_copy_state_free(BlockCopyState *s);
69
70 int64_t block_copy_reset_unallocated(BlockCopyState *s,
71 int64_t offset, int64_t *count);
72
73 int coroutine_fn block_copy(BlockCopyState *s, int64_t start, uint64_t bytes,
74 bool *error_is_read, bool is_write_notifier);
75
76 #endif /* BLOCK_COPY_H */