]> git.proxmox.com Git - mirror_qemu.git/blame - include/block/block_int-io.h
Merge tag 'pull-maintainer-may24-160524-2' of https://gitlab.com/stsquad/qemu into...
[mirror_qemu.git] / include / block / block_int-io.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 */
24#ifndef BLOCK_INT_IO_H
25#define BLOCK_INT_IO_H
26
e2c1c34f
MA
27#include "block/block_int-common.h"
28#include "qemu/hbitmap.h"
29#include "qemu/main-loop.h"
ebc2752b
EGE
30
31/*
32 * I/O API functions. These functions are thread-safe.
33 *
34 * See include/block/block-io.h for more information about
35 * the I/O API.
36 */
37
7b9e8b22 38int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_snapshot(BdrvChild *child,
ce14f3b4 39 int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset);
7b9e8b22
KW
40int coroutine_fn GRAPH_RDLOCK bdrv_co_snapshot_block_status(
41 BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes,
42 int64_t *pnum, int64_t *map, BlockDriverState **file);
9a5a1c62 43int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *bs,
ce14f3b4
VSO
44 int64_t offset, int64_t bytes);
45
46
b9b10c35 47int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv(BdrvChild *child,
ebc2752b
EGE
48 int64_t offset, int64_t bytes, QEMUIOVector *qiov,
49 BdrvRequestFlags flags);
b9b10c35 50int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_part(BdrvChild *child,
ebc2752b
EGE
51 int64_t offset, int64_t bytes,
52 QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags);
b9b10c35 53int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev(BdrvChild *child,
ebc2752b
EGE
54 int64_t offset, int64_t bytes, QEMUIOVector *qiov,
55 BdrvRequestFlags flags);
b9b10c35 56int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev_part(BdrvChild *child,
ebc2752b
EGE
57 int64_t offset, int64_t bytes,
58 QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags);
59
b9b10c35 60static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pread(BdrvChild *child,
c1458c66 61 int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags)
ebc2752b
EGE
62{
63 QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
967d7905 64 IO_CODE();
b9b10c35 65 assert_bdrv_graph_readable();
ebc2752b
EGE
66
67 return bdrv_co_preadv(child, offset, bytes, &qiov, flags);
68}
69
b9b10c35 70static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pwrite(BdrvChild *child,
c1458c66 71 int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags)
ebc2752b
EGE
72{
73 QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
967d7905 74 IO_CODE();
b9b10c35 75 assert_bdrv_graph_readable();
ebc2752b
EGE
76
77 return bdrv_co_pwritev(child, offset, bytes, &qiov, flags);
78}
79
131498f7 80void coroutine_fn bdrv_make_request_serialising(BdrvTrackedRequest *req,
ebc2752b
EGE
81 uint64_t align);
82BdrvTrackedRequest *coroutine_fn bdrv_co_get_self_request(BlockDriverState *bs);
83
84BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,
85 const char *filename);
86
87/**
88 * bdrv_wakeup:
89 * @bs: The BlockDriverState for which an I/O operation has been completed.
90 *
91 * Wake up the main thread if it is waiting on BDRV_POLL_WHILE. During
92 * synchronous I/O on a BlockDriverState that is attached to another
93 * I/O thread, the main thread lets the I/O thread's event loop run,
94 * waiting for the I/O operation to complete. A bdrv_wakeup will wake
95 * up the main thread if necessary.
96 *
97 * Manual calls to bdrv_wakeup are rarely necessary, because
98 * bdrv_dec_in_flight already calls it.
99 */
100void bdrv_wakeup(BlockDriverState *bs);
101
4026f1c4 102const char * GRAPH_RDLOCK bdrv_get_parent_name(const BlockDriverState *bs);
ebc2752b
EGE
103bool blk_dev_has_tray(BlockBackend *blk);
104bool blk_dev_is_tray_open(BlockBackend *blk);
105
106void bdrv_set_dirty(BlockDriverState *bs, int64_t offset, int64_t bytes);
107
108void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out);
618af89e 109void bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest,
ebc2752b
EGE
110 const BdrvDirtyBitmap *src,
111 HBitmap **backup, bool lock);
112
113void bdrv_inc_in_flight(BlockDriverState *bs);
114void bdrv_dec_in_flight(BlockDriverState *bs);
115
742bf09b
EGE
116int coroutine_fn GRAPH_RDLOCK
117bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset,
118 BdrvChild *dst, int64_t dst_offset,
119 int64_t bytes, BdrvRequestFlags read_flags,
120 BdrvRequestFlags write_flags);
121int coroutine_fn GRAPH_RDLOCK
122bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset,
123 BdrvChild *dst, int64_t dst_offset,
124 int64_t bytes, BdrvRequestFlags read_flags,
125 BdrvRequestFlags write_flags);
ebc2752b 126
8ab8140a
KW
127int coroutine_fn GRAPH_RDLOCK
128bdrv_co_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
129
130int co_wrapper_mixed_bdrv_rdlock
c86422c5 131bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint);
ebc2752b 132
78a9c76e 133BdrvChild * GRAPH_RDLOCK bdrv_cow_child(BlockDriverState *bs);
ec82cc41
KW
134BdrvChild * GRAPH_RDLOCK bdrv_filter_child(BlockDriverState *bs);
135BdrvChild * GRAPH_RDLOCK bdrv_filter_or_cow_child(BlockDriverState *bs);
c0fc5123 136BdrvChild * GRAPH_RDLOCK bdrv_primary_child(BlockDriverState *bs);
ad74751f
KW
137BlockDriverState * GRAPH_RDLOCK bdrv_skip_filters(BlockDriverState *bs);
138BlockDriverState * GRAPH_RDLOCK bdrv_backing_chain_next(BlockDriverState *bs);
ebc2752b 139
78a9c76e
KW
140static inline BlockDriverState * GRAPH_RDLOCK
141bdrv_cow_bs(BlockDriverState *bs)
ebc2752b 142{
967d7905 143 IO_CODE();
ebc2752b
EGE
144 return child_bs(bdrv_cow_child(bs));
145}
146
f5a3a270
KW
147static inline BlockDriverState * GRAPH_RDLOCK
148bdrv_filter_bs(BlockDriverState *bs)
ebc2752b 149{
967d7905 150 IO_CODE();
ebc2752b
EGE
151 return child_bs(bdrv_filter_child(bs));
152}
153
372b69f5
KW
154static inline BlockDriverState * GRAPH_RDLOCK
155bdrv_filter_or_cow_bs(BlockDriverState *bs)
ebc2752b 156{
967d7905 157 IO_CODE();
ebc2752b
EGE
158 return child_bs(bdrv_filter_or_cow_child(bs));
159}
160
c0fc5123
KW
161static inline BlockDriverState * GRAPH_RDLOCK
162bdrv_primary_bs(BlockDriverState *bs)
ebc2752b 163{
967d7905 164 IO_CODE();
ebc2752b
EGE
165 return child_bs(bdrv_primary_child(bs));
166}
167
168/**
169 * Check whether the given offset is in the cached block-status data
170 * region.
171 *
172 * If it is, and @pnum is not NULL, *pnum is set to
173 * `bsc.data_end - offset`, i.e. how many bytes, starting from
174 * @offset, are data (according to the cache).
175 * Otherwise, *pnum is not touched.
176 */
177bool bdrv_bsc_is_data(BlockDriverState *bs, int64_t offset, int64_t *pnum);
178
179/**
180 * If [offset, offset + bytes) overlaps with the currently cached
181 * block-status region, invalidate the cache.
182 *
183 * (To be used by I/O paths that cause data regions to be zero or
184 * holes.)
185 */
186void bdrv_bsc_invalidate_range(BlockDriverState *bs,
187 int64_t offset, int64_t bytes);
188
189/**
190 * Mark the range [offset, offset + bytes) as a data region.
191 */
192void bdrv_bsc_fill(BlockDriverState *bs, int64_t offset, int64_t bytes);
193
ebc2752b 194#endif /* BLOCK_INT_IO_H */