block/block-copy: rename start to offset in interfaces
[qemu/kevin.git] / include / block / block-copy.h
blobb76efb736f7e7c2e487cf89e645075dfaac49226
1 /*
2 * block_copy API
4 * Copyright (C) 2013 Proxmox Server Solutions
5 * Copyright (c) 2019 Virtuozzo International GmbH.
7 * Authors:
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.
15 #ifndef BLOCK_COPY_H
16 #define BLOCK_COPY_H
18 #include "block/block.h"
19 #include "qemu/co-shared-resource.h"
21 typedef struct BlockCopyInFlightReq {
22 int64_t offset;
23 int64_t bytes;
24 QLIST_ENTRY(BlockCopyInFlightReq) list;
25 CoQueue wait_queue; /* coroutines blocked on this request */
26 } BlockCopyInFlightReq;
28 typedef void (*ProgressBytesCallbackFunc)(int64_t bytes, void *opaque);
29 typedef struct BlockCopyState {
31 * BdrvChild objects are not owned or managed by block-copy. They are
32 * provided by block-copy user and user is responsible for appropriate
33 * permissions on these children.
35 BdrvChild *source;
36 BdrvChild *target;
37 BdrvDirtyBitmap *copy_bitmap;
38 int64_t in_flight_bytes;
39 int64_t cluster_size;
40 bool use_copy_range;
41 int64_t copy_size;
42 uint64_t len;
43 QLIST_HEAD(, BlockCopyInFlightReq) inflight_reqs;
45 BdrvRequestFlags write_flags;
48 * skip_unallocated:
50 * Used by sync=top jobs, which first scan the source node for unallocated
51 * areas and clear them in the copy_bitmap. During this process, the bitmap
52 * is thus not fully initialized: It may still have bits set for areas that
53 * are unallocated and should actually not be copied.
55 * This is indicated by skip_unallocated.
57 * In this case, block_copy() will query the source’s allocation status,
58 * skip unallocated regions, clear them in the copy_bitmap, and invoke
59 * block_copy_reset_unallocated() every time it does.
61 bool skip_unallocated;
63 ProgressMeter *progress;
64 /* progress_bytes_callback: called when some copying progress is done. */
65 ProgressBytesCallbackFunc progress_bytes_callback;
66 void *progress_opaque;
68 SharedResource *mem;
69 } BlockCopyState;
71 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
72 int64_t cluster_size,
73 BdrvRequestFlags write_flags,
74 Error **errp);
76 void block_copy_set_progress_callback(
77 BlockCopyState *s,
78 ProgressBytesCallbackFunc progress_bytes_callback,
79 void *progress_opaque);
81 void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);
83 void block_copy_state_free(BlockCopyState *s);
85 int64_t block_copy_reset_unallocated(BlockCopyState *s,
86 int64_t offset, int64_t *count);
88 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
89 bool *error_is_read);
91 #endif /* BLOCK_COPY_H */