4 * Copyright (C) 2013 Proxmox Server Solutions
5 * Copyright (c) 2019 Virtuozzo International GmbH.
8 * Dietmar Maurer (dietmar@proxmox.com)
9 * Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
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.
18 #include "block/block.h"
20 typedef void (*ProgressBytesCallbackFunc
)(int64_t bytes
, void *opaque
);
21 typedef void (*ProgressResetCallbackFunc
)(void *opaque
);
22 typedef struct BlockCopyState
{
25 BdrvDirtyBitmap
*copy_bitmap
;
28 int64_t copy_range_size
;
31 BdrvRequestFlags write_flags
;
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.
41 * This is indicated by skip_unallocated.
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.
47 bool skip_unallocated
;
49 /* progress_bytes_callback: called when some copying progress is done. */
50 ProgressBytesCallbackFunc progress_bytes_callback
;
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.
57 ProgressResetCallbackFunc progress_reset_callback
;
58 void *progress_opaque
;
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
);
68 void block_copy_state_free(BlockCopyState
*s
);
70 int64_t block_copy_reset_unallocated(BlockCopyState
*s
,
71 int64_t offset
, int64_t *count
);
73 int coroutine_fn
block_copy(BlockCopyState
*s
, int64_t start
, uint64_t bytes
,
74 bool *error_is_read
, bool is_write_notifier
);
76 #endif /* BLOCK_COPY_H */