]> git.proxmox.com Git - mirror_qemu.git/blame - include/block/block_int-global-state.h
stream: Allow users to request only format driver names in backing file format
[mirror_qemu.git] / include / block / block_int-global-state.h
CommitLineData
ebc2752b
EGE
1/*
2 * QEMU System Emulator block driver
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
ea9cea93 24
ebc2752b
EGE
25#ifndef BLOCK_INT_GLOBAL_STATE_H
26#define BLOCK_INT_GLOBAL_STATE_H
27
e2c1c34f
MA
28#include "block/blockjob.h"
29#include "block/block_int-common.h"
30#include "qemu/hbitmap.h"
31#include "qemu/main-loop.h"
ebc2752b
EGE
32
33/*
34 * Global state (GS) API. These functions run under the BQL.
35 *
36 * See include/block/block-global-state.h for more information about
37 * the GS API.
38 */
39
40/**
41 * stream_start:
42 * @job_id: The id of the newly-created job, or %NULL to use the
43 * device name of @bs.
44 * @bs: Block device to operate on.
45 * @base: Block device that will become the new base, or %NULL to
46 * flatten the whole backing file chain onto @bs.
47 * @backing_file_str: The file name that will be written to @bs as the
48 * the new backing file if the job completes. Ignored if @base is %NULL.
72098a3a
PK
49 * @backing_mask_protocol: Replace potential protocol name with 'raw' in
50 * 'backing file format' header
ebc2752b
EGE
51 * @creation_flags: Flags that control the behavior of the Job lifetime.
52 * See @BlockJobCreateFlags
53 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
54 * @on_error: The action to take upon error.
55 * @filter_node_name: The node name that should be assigned to the filter
56 * driver that the stream job inserts into the graph above
57 * @bs. NULL means that a node name should be autogenerated.
58 * @errp: Error object.
59 *
60 * Start a streaming operation on @bs. Clusters that are unallocated
61 * in @bs, but allocated in any image between @base and @bs (both
62 * exclusive) will be written to @bs. At the end of a successful
63 * streaming job, the backing file of @bs will be changed to
64 * @backing_file_str in the written image and to @base in the live
65 * BlockDriverState.
66 */
67void stream_start(const char *job_id, BlockDriverState *bs,
68 BlockDriverState *base, const char *backing_file_str,
72098a3a 69 bool backing_mask_protocol,
ebc2752b
EGE
70 BlockDriverState *bottom,
71 int creation_flags, int64_t speed,
72 BlockdevOnError on_error,
73 const char *filter_node_name,
74 Error **errp);
75
76/**
77 * commit_start:
78 * @job_id: The id of the newly-created job, or %NULL to use the
79 * device name of @bs.
80 * @bs: Active block device.
81 * @top: Top block device to be committed.
82 * @base: Block device that will be written into, and become the new top.
83 * @creation_flags: Flags that control the behavior of the Job lifetime.
84 * See @BlockJobCreateFlags
85 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
86 * @on_error: The action to take upon error.
87 * @backing_file_str: String to use as the backing file in @top's overlay
4b028cbe
PK
88 * @backing_mask_protocol: Replace potential protocol name with 'raw' in
89 * 'backing file format' header
ebc2752b
EGE
90 * @filter_node_name: The node name that should be assigned to the filter
91 * driver that the commit job inserts into the graph above @top. NULL means
92 * that a node name should be autogenerated.
93 * @errp: Error object.
94 *
95 */
96void commit_start(const char *job_id, BlockDriverState *bs,
97 BlockDriverState *base, BlockDriverState *top,
98 int creation_flags, int64_t speed,
99 BlockdevOnError on_error, const char *backing_file_str,
4b028cbe 100 bool backing_mask_protocol,
ebc2752b
EGE
101 const char *filter_node_name, Error **errp);
102/**
103 * commit_active_start:
104 * @job_id: The id of the newly-created job, or %NULL to use the
105 * device name of @bs.
106 * @bs: Active block device to be committed.
107 * @base: Block device that will be written into, and become the new top.
108 * @creation_flags: Flags that control the behavior of the Job lifetime.
109 * See @BlockJobCreateFlags
110 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
111 * @on_error: The action to take upon error.
112 * @filter_node_name: The node name that should be assigned to the filter
113 * driver that the commit job inserts into the graph above @bs. NULL means that
114 * a node name should be autogenerated.
115 * @cb: Completion function for the job.
116 * @opaque: Opaque pointer value passed to @cb.
117 * @auto_complete: Auto complete the job.
118 * @errp: Error object.
119 *
120 */
121BlockJob *commit_active_start(const char *job_id, BlockDriverState *bs,
122 BlockDriverState *base, int creation_flags,
123 int64_t speed, BlockdevOnError on_error,
124 const char *filter_node_name,
125 BlockCompletionFunc *cb, void *opaque,
126 bool auto_complete, Error **errp);
127/*
128 * mirror_start:
129 * @job_id: The id of the newly-created job, or %NULL to use the
130 * device name of @bs.
131 * @bs: Block device to operate on.
132 * @target: Block device to write to.
133 * @replaces: Block graph node name to replace once the mirror is done. Can
134 * only be used when full mirroring is selected.
135 * @creation_flags: Flags that control the behavior of the Job lifetime.
136 * See @BlockJobCreateFlags
137 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
138 * @granularity: The chosen granularity for the dirty bitmap.
139 * @buf_size: The amount of data that can be in flight at one time.
140 * @mode: Whether to collapse all images in the chain to the target.
141 * @backing_mode: How to establish the target's backing chain after completion.
142 * @zero_target: Whether the target should be explicitly zero-initialized
143 * @on_source_error: The action to take upon error reading from the source.
144 * @on_target_error: The action to take upon error writing to the target.
145 * @unmap: Whether to unmap target where source sectors only contain zeroes.
146 * @filter_node_name: The node name that should be assigned to the filter
147 * driver that the mirror job inserts into the graph above @bs. NULL means that
148 * a node name should be autogenerated.
149 * @copy_mode: When to trigger writes to the target.
150 * @errp: Error object.
151 *
152 * Start a mirroring operation on @bs. Clusters that are allocated
153 * in @bs will be written to @target until the job is cancelled or
154 * manually completed. At the end of a successful mirroring job,
155 * @bs will be switched to read from @target.
156 */
157void mirror_start(const char *job_id, BlockDriverState *bs,
158 BlockDriverState *target, const char *replaces,
159 int creation_flags, int64_t speed,
160 uint32_t granularity, int64_t buf_size,
161 MirrorSyncMode mode, BlockMirrorBackingMode backing_mode,
162 bool zero_target,
163 BlockdevOnError on_source_error,
164 BlockdevOnError on_target_error,
165 bool unmap, const char *filter_node_name,
166 MirrorCopyMode copy_mode, Error **errp);
167
168/*
169 * backup_job_create:
170 * @job_id: The id of the newly-created job, or %NULL to use the
171 * device name of @bs.
172 * @bs: Block device to operate on.
173 * @target: Block device to write to.
174 * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
175 * @sync_mode: What parts of the disk image should be copied to the destination.
176 * @sync_bitmap: The dirty bitmap if sync_mode is 'bitmap' or 'incremental'
177 * @bitmap_mode: The bitmap synchronization policy to use.
178 * @perf: Performance options. All actual fields assumed to be present,
179 * all ".has_*" fields are ignored.
180 * @on_source_error: The action to take upon error reading from the source.
181 * @on_target_error: The action to take upon error writing to the target.
182 * @creation_flags: Flags that control the behavior of the Job lifetime.
183 * See @BlockJobCreateFlags
184 * @cb: Completion function for the job.
185 * @opaque: Opaque pointer value passed to @cb.
186 * @txn: Transaction that this job is part of (may be NULL).
187 *
188 * Create a backup operation on @bs. Clusters in @bs are written to @target
189 * until the job is cancelled or manually completed.
190 */
191BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs,
192 BlockDriverState *target, int64_t speed,
193 MirrorSyncMode sync_mode,
194 BdrvDirtyBitmap *sync_bitmap,
195 BitmapSyncMode bitmap_mode,
196 bool compress,
197 const char *filter_node_name,
198 BackupPerf *perf,
199 BlockdevOnError on_source_error,
200 BlockdevOnError on_target_error,
201 int creation_flags,
202 BlockCompletionFunc *cb, void *opaque,
203 JobTxn *txn, Error **errp);
204
03b9eaca
KW
205BdrvChild * GRAPH_WRLOCK
206bdrv_root_attach_child(BlockDriverState *child_bs, const char *child_name,
207 const BdrvChildClass *child_class,
208 BdrvChildRole child_role,
209 uint64_t perm, uint64_t shared_perm,
210 void *opaque, Error **errp);
211
ede01e46 212void GRAPH_WRLOCK bdrv_root_unref_child(BdrvChild *child);
ebc2752b 213
bce73bc2
KW
214void GRAPH_RDLOCK bdrv_get_cumulative_perm(BlockDriverState *bs, uint64_t *perm,
215 uint64_t *shared_perm);
ebc2752b
EGE
216
217/**
218 * Sets a BdrvChild's permissions. Avoid if the parent is a BDS; use
219 * bdrv_child_refresh_perms() instead and make the parent's
220 * .bdrv_child_perm() implementation return the correct values.
221 */
3804e3cf
KW
222int GRAPH_RDLOCK
223bdrv_child_try_set_perm(BdrvChild *c, uint64_t perm, uint64_t shared,
224 Error **errp);
ebc2752b
EGE
225
226/**
227 * Calls bs->drv->bdrv_child_perm() and updates the child's permission
228 * masks with the result.
229 * Drivers should invoke this function whenever an event occurs that
230 * makes their .bdrv_child_perm() implementation return different
231 * values than before, but which will not result in the block layer
232 * automatically refreshing the permissions.
233 */
3804e3cf
KW
234int GRAPH_RDLOCK
235bdrv_child_refresh_perms(BlockDriverState *bs, BdrvChild *c, Error **errp);
ebc2752b 236
533c6e4e
KW
237bool GRAPH_RDLOCK bdrv_recurse_can_replace(BlockDriverState *bs,
238 BlockDriverState *to_replace);
ebc2752b
EGE
239
240/*
241 * Default implementation for BlockDriver.bdrv_child_perm() that can
242 * be used by block filters and image formats, as long as they use the
243 * child_of_bds child class and set an appropriate BdrvChildRole.
244 */
245void bdrv_default_perms(BlockDriverState *bs, BdrvChild *c,
246 BdrvChildRole role, BlockReopenQueue *reopen_queue,
247 uint64_t perm, uint64_t shared,
248 uint64_t *nperm, uint64_t *nshared);
249
250void blk_dev_change_media_cb(BlockBackend *blk, bool load, Error **errp);
251bool blk_dev_has_removable_media(BlockBackend *blk);
252void blk_dev_eject_request(BlockBackend *blk, bool force);
253bool blk_dev_is_medium_locked(BlockBackend *blk);
254
255void bdrv_restore_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *backup);
256
257void bdrv_set_monitor_owned(BlockDriverState *bs);
258
259void blockdev_close_all_bdrv_states(void);
260
261BlockDriverState *bds_tree_init(QDict *bs_opts, Error **errp);
262
263/**
264 * Simple implementation of bdrv_co_create_opts for protocol drivers
265 * which only support creation via opening a file
266 * (usually existing raw storage device)
267 */
268int coroutine_fn bdrv_co_create_opts_simple(BlockDriver *drv,
269 const char *filename,
270 QemuOpts *opts,
271 Error **errp);
272
273BdrvDirtyBitmap *block_dirty_bitmap_lookup(const char *node,
274 const char *name,
275 BlockDriverState **pbs,
276 Error **errp);
277BdrvDirtyBitmap *block_dirty_bitmap_merge(const char *node, const char *target,
1466ef6c 278 BlockDirtyBitmapOrStrList *bms,
ebc2752b
EGE
279 HBitmap **backup, Error **errp);
280BdrvDirtyBitmap *block_dirty_bitmap_remove(const char *node, const char *name,
281 bool release,
282 BlockDriverState **bitmap_bs,
283 Error **errp);
284
285
430da832
KW
286BlockDriverState * GRAPH_RDLOCK
287bdrv_skip_implicit_filters(BlockDriverState *bs);
ebc2752b
EGE
288
289/**
290 * bdrv_add_aio_context_notifier:
291 *
292 * If a long-running job intends to be always run in the same AioContext as a
293 * certain BDS, it may use this function to be notified of changes regarding the
294 * association of the BDS to an AioContext.
295 *
296 * attached_aio_context() is called after the target BDS has been attached to a
297 * new AioContext; detach_aio_context() is called before the target BDS is being
298 * detached from its old AioContext.
299 */
300void bdrv_add_aio_context_notifier(BlockDriverState *bs,
301 void (*attached_aio_context)(AioContext *new_context, void *opaque),
302 void (*detach_aio_context)(void *opaque), void *opaque);
303
304/**
305 * bdrv_remove_aio_context_notifier:
306 *
307 * Unsubscribe of change notifications regarding the BDS's AioContext. The
308 * parameters given here have to be the same as those given to
309 * bdrv_add_aio_context_notifier().
310 */
311void bdrv_remove_aio_context_notifier(BlockDriverState *bs,
312 void (*aio_context_attached)(AioContext *,
313 void *),
314 void (*aio_context_detached)(void *),
315 void *opaque);
316
317/**
318 * End all quiescent sections started by bdrv_drain_all_begin(). This is
319 * needed when deleting a BDS before bdrv_drain_all_end() is called.
320 *
321 * NOTE: this is an internal helper for bdrv_close() *only*. No one else
322 * should call it.
323 */
324void bdrv_drain_all_end_quiesce(BlockDriverState *bs);
325
ea9cea93 326#endif /* BLOCK_INT_GLOBAL_STATE_H */