master
h 105 lines 3.88 KB
Raw
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-common.h"
19 #include "block/graph-lock.h"
20 #include "qemu/progress_meter.h"
21
22 /* All APIs are thread-safe */
23
24 typedef void (*BlockCopyAsyncCallbackFunc)(void *opaque);
25 typedef struct BlockCopyState BlockCopyState;
26 typedef struct BlockCopyCallState BlockCopyCallState;
27
28 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
29 BlockDriverState *copy_bitmap_bs,
30 const BdrvDirtyBitmap *bitmap,
31 bool discard_source,
32 uint64_t min_cluster_size,
33 Error **errp);
34
35 /* Function should be called prior any actual copy request */
36 void block_copy_set_copy_opts(BlockCopyState *s, bool use_copy_range,
37 bool compress);
38 void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);
39
40 void block_copy_state_free(BlockCopyState *s);
41
42 void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes);
43
44 int64_t coroutine_fn GRAPH_RDLOCK
45 block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *count);
46
47 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
48 bool ignore_ratelimit, uint64_t timeout_ns,
49 BlockCopyAsyncCallbackFunc cb,
50 void *cb_opaque);
51
52 /*
53 * Run block-copy in a coroutine, create corresponding BlockCopyCallState
54 * object and return pointer to it. Never returns NULL.
55 *
56 * Caller is responsible to call block_copy_call_free() to free
57 * BlockCopyCallState object.
58 *
59 * @max_workers means maximum of parallel coroutines to execute sub-requests,
60 * must be > 0.
61 *
62 * @max_chunk means maximum length for one IO operation. Zero means unlimited.
63 */
64 BlockCopyCallState *block_copy_async(BlockCopyState *s,
65 int64_t offset, int64_t bytes,
66 int max_workers, int64_t max_chunk,
67 BlockCopyAsyncCallbackFunc cb,
68 void *cb_opaque);
69
70 /*
71 * Free finished BlockCopyCallState. Trying to free running
72 * block-copy will crash.
73 */
74 void block_copy_call_free(BlockCopyCallState *call_state);
75
76 /*
77 * Note, that block-copy call is marked finished prior to calling
78 * the callback.
79 */
80 bool block_copy_call_finished(BlockCopyCallState *call_state);
81 bool block_copy_call_succeeded(BlockCopyCallState *call_state);
82 bool block_copy_call_failed(BlockCopyCallState *call_state);
83 bool block_copy_call_cancelled(BlockCopyCallState *call_state);
84 int block_copy_call_status(BlockCopyCallState *call_state, bool *error_is_read);
85
86 void block_copy_set_speed(BlockCopyState *s, uint64_t speed);
87 void block_copy_kick(BlockCopyCallState *call_state);
88
89 /*
90 * Cancel running block-copy call.
91 *
92 * Cancel leaves block-copy state valid: dirty bits are correct and you may use
93 * cancel + <run block_copy with same parameters> to emulate pause/resume.
94 *
95 * Note also, that the cancel is async: it only marks block-copy call to be
96 * cancelled. So, the call may be cancelled (block_copy_call_cancelled() reports
97 * true) but not yet finished (block_copy_call_finished() reports false).
98 */
99 void block_copy_call_cancel(BlockCopyCallState *call_state);
100
101 BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s);
102 int64_t block_copy_cluster_size(BlockCopyState *s);
103 void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip);
104
105 #endif /* BLOCK_COPY_H */