osdep: include glib-compat.h before other QEMU headers
[qemu/ar7.git] / include / block / block-copy.h
blob338f2ea7fdf6360ae69a6c4480c1bbd860ff2f29
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 void (*BlockCopyAsyncCallbackFunc)(void *opaque);
22 typedef struct BlockCopyState BlockCopyState;
23 typedef struct BlockCopyCallState BlockCopyCallState;
25 BlockCopyState *block_copy_state_new(BdrvChild *source, BdrvChild *target,
26 int64_t cluster_size, bool use_copy_range,
27 BdrvRequestFlags write_flags,
28 Error **errp);
30 void block_copy_set_progress_meter(BlockCopyState *s, ProgressMeter *pm);
32 void block_copy_state_free(BlockCopyState *s);
34 int64_t block_copy_reset_unallocated(BlockCopyState *s,
35 int64_t offset, int64_t *count);
37 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t bytes,
38 bool ignore_ratelimit);
41 * Run block-copy in a coroutine, create corresponding BlockCopyCallState
42 * object and return pointer to it. Never returns NULL.
44 * Caller is responsible to call block_copy_call_free() to free
45 * BlockCopyCallState object.
47 * @max_workers means maximum of parallel coroutines to execute sub-requests,
48 * must be > 0.
50 * @max_chunk means maximum length for one IO operation. Zero means unlimited.
52 BlockCopyCallState *block_copy_async(BlockCopyState *s,
53 int64_t offset, int64_t bytes,
54 int max_workers, int64_t max_chunk,
55 BlockCopyAsyncCallbackFunc cb,
56 void *cb_opaque);
59 * Free finished BlockCopyCallState. Trying to free running
60 * block-copy will crash.
62 void block_copy_call_free(BlockCopyCallState *call_state);
65 * Note, that block-copy call is marked finished prior to calling
66 * the callback.
68 bool block_copy_call_finished(BlockCopyCallState *call_state);
69 bool block_copy_call_succeeded(BlockCopyCallState *call_state);
70 bool block_copy_call_failed(BlockCopyCallState *call_state);
71 bool block_copy_call_cancelled(BlockCopyCallState *call_state);
72 int block_copy_call_status(BlockCopyCallState *call_state, bool *error_is_read);
74 void block_copy_set_speed(BlockCopyState *s, uint64_t speed);
75 void block_copy_kick(BlockCopyCallState *call_state);
78 * Cancel running block-copy call.
80 * Cancel leaves block-copy state valid: dirty bits are correct and you may use
81 * cancel + <run block_copy with same parameters> to emulate pause/resume.
83 * Note also, that the cancel is async: it only marks block-copy call to be
84 * cancelled. So, the call may be cancelled (block_copy_call_cancelled() reports
85 * true) but not yet finished (block_copy_call_finished() reports false).
87 void block_copy_call_cancel(BlockCopyCallState *call_state);
89 BdrvDirtyBitmap *block_copy_dirty_bitmap(BlockCopyState *s);
90 void block_copy_set_skip_unallocated(BlockCopyState *s, bool skip);
92 #endif /* BLOCK_COPY_H */