xref: /qemu/include/system/block-backend-io.h (revision 513823e7521a09ed7ad1e32e6454bac3b2cbf52d)
1 /*
2  * QEMU Block backends
3  *
4  * Copyright (C) 2014-2016 Red Hat, Inc.
5  *
6  * Authors:
7  *  Markus Armbruster <armbru@redhat.com>,
8  *
9  * This work is licensed under the terms of the GNU LGPL, version 2.1
10  * or later.  See the COPYING.LIB file in the top-level directory.
11  */
12 
13 #ifndef BLOCK_BACKEND_IO_H
14 #define BLOCK_BACKEND_IO_H
15 
16 #include "block-backend-common.h"
17 #include "block/accounting.h"
18 
19 /*
20  * I/O API functions. These functions are thread-safe.
21  *
22  * See include/block/block-io.h for more information about
23  * the I/O API.
24  */
25 
26 const char *blk_name(const BlockBackend *blk);
27 
28 BlockDriverState *blk_bs(BlockBackend *blk);
29 
30 void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
31 void blk_set_allow_aio_context_change(BlockBackend *blk, bool allow);
32 void blk_set_disable_request_queuing(BlockBackend *blk, bool disable);
33 bool blk_iostatus_is_enabled(const BlockBackend *blk);
34 
35 /*
36  * Return the qdev ID, or if no ID is assigned the QOM path,
37  * of the block device attached to the BlockBackend.
38  *
39  * The caller is responsible for releasing the value returned
40  * with g_free() after use.
41  */
42 char *blk_get_attached_dev_id(BlockBackend *blk);
43 
44 BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
45                                   int64_t bytes, BdrvRequestFlags flags,
46                                   BlockCompletionFunc *cb, void *opaque);
47 
48 BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
49                            QEMUIOVector *qiov, BdrvRequestFlags flags,
50                            BlockCompletionFunc *cb, void *opaque);
51 BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
52                             QEMUIOVector *qiov, BdrvRequestFlags flags,
53                             BlockCompletionFunc *cb, void *opaque);
54 BlockAIOCB *blk_aio_flush(BlockBackend *blk,
55                           BlockCompletionFunc *cb, void *opaque);
56 BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset,
57                                 unsigned int *nr_zones,
58                                 BlockZoneDescriptor *zones,
59                                 BlockCompletionFunc *cb, void *opaque);
60 BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
61                               int64_t offset, int64_t len,
62                               BlockCompletionFunc *cb, void *opaque);
63 BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, int64_t *offset,
64                                 QEMUIOVector *qiov, BdrvRequestFlags flags,
65                                 BlockCompletionFunc *cb, void *opaque);
66 BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
67                              BlockCompletionFunc *cb, void *opaque);
68 void blk_aio_cancel_async(BlockAIOCB *acb);
69 BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
70                           BlockCompletionFunc *cb, void *opaque);
71 
72 void blk_inc_in_flight(BlockBackend *blk);
73 void blk_dec_in_flight(BlockBackend *blk);
74 
75 bool coroutine_fn GRAPH_RDLOCK blk_co_is_inserted(BlockBackend *blk);
76 bool co_wrapper_mixed_bdrv_rdlock blk_is_inserted(BlockBackend *blk);
77 
78 bool coroutine_fn GRAPH_RDLOCK blk_co_is_available(BlockBackend *blk);
79 bool co_wrapper_mixed_bdrv_rdlock blk_is_available(BlockBackend *blk);
80 
81 void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked);
82 void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked);
83 
84 void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag);
85 void co_wrapper blk_eject(BlockBackend *blk, bool eject_flag);
86 
87 int64_t coroutine_fn blk_co_getlength(BlockBackend *blk);
88 int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk);
89 
90 void coroutine_fn blk_co_get_geometry(BlockBackend *blk,
91                                       uint64_t *nb_sectors_ptr);
92 void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
93 
94 int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk);
95 int64_t blk_nb_sectors(BlockBackend *blk);
96 
97 void *blk_try_blockalign(BlockBackend *blk, size_t size);
98 void *blk_blockalign(BlockBackend *blk, size_t size);
99 bool blk_is_writable(BlockBackend *blk);
100 bool blk_enable_write_cache(BlockBackend *blk);
101 BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read);
102 BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
103                                       int error);
104 void blk_error_action(BlockBackend *blk, BlockErrorAction action,
105                       bool is_read, int error);
106 void blk_iostatus_set_err(BlockBackend *blk, int error);
107 int blk_get_max_iov(BlockBackend *blk);
108 int blk_get_max_hw_iov(BlockBackend *blk);
109 
110 AioContext *blk_get_aio_context(BlockBackend *blk);
111 BlockAcctStats *blk_get_stats(BlockBackend *blk);
112 void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
113                   BlockCompletionFunc *cb, void *opaque);
114 BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
115                                   BlockCompletionFunc *cb,
116                                   void *opaque, int ret);
117 
118 uint32_t blk_get_request_alignment(BlockBackend *blk);
119 uint32_t blk_get_max_transfer(BlockBackend *blk);
120 uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
121 
122 int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
123                                    BlockBackend *blk_out, int64_t off_out,
124                                    int64_t bytes, BdrvRequestFlags read_flags,
125                                    BdrvRequestFlags write_flags);
126 
127 int coroutine_fn blk_co_block_status_above(BlockBackend *blk,
128                                            BlockDriverState *base,
129                                            int64_t offset, int64_t bytes,
130                                            int64_t *pnum, int64_t *map,
131                                            BlockDriverState **file);
132 int coroutine_fn blk_co_is_allocated_above(BlockBackend *blk,
133                                            BlockDriverState *base,
134                                            bool include_base, int64_t offset,
135                                            int64_t bytes, int64_t *pnum);
136 
137 /*
138  * "I/O or GS" API functions. These functions can run without
139  * the BQL, but only in one specific iothread/main loop.
140  *
141  * See include/block/block-io.h for more information about
142  * the "I/O or GS" API.
143  */
144 
145 int co_wrapper_mixed blk_pread(BlockBackend *blk, int64_t offset,
146                                int64_t bytes, void *buf,
147                                BdrvRequestFlags flags);
148 int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes,
149                               void *buf, BdrvRequestFlags flags);
150 
151 int co_wrapper_mixed blk_preadv(BlockBackend *blk, int64_t offset,
152                                 int64_t bytes, QEMUIOVector *qiov,
153                                 BdrvRequestFlags flags);
154 int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
155                                int64_t bytes, QEMUIOVector *qiov,
156                                BdrvRequestFlags flags);
157 
158 int co_wrapper_mixed blk_preadv_part(BlockBackend *blk, int64_t offset,
159                                      int64_t bytes, QEMUIOVector *qiov,
160                                      size_t qiov_offset,
161                                      BdrvRequestFlags flags);
162 int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset,
163                                     int64_t bytes, QEMUIOVector *qiov,
164                                     size_t qiov_offset, BdrvRequestFlags flags);
165 
166 int co_wrapper_mixed blk_pwrite(BlockBackend *blk, int64_t offset,
167                                 int64_t bytes, const void *buf,
168                                 BdrvRequestFlags flags);
169 int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
170                                const void *buf, BdrvRequestFlags flags);
171 
172 int co_wrapper_mixed blk_pwritev(BlockBackend *blk, int64_t offset,
173                                  int64_t bytes, QEMUIOVector *qiov,
174                                  BdrvRequestFlags flags);
175 int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
176                                 int64_t bytes, QEMUIOVector *qiov,
177                                 BdrvRequestFlags flags);
178 
179 int co_wrapper_mixed blk_pwritev_part(BlockBackend *blk, int64_t offset,
180                                       int64_t bytes, QEMUIOVector *qiov,
181                                       size_t qiov_offset,
182                                       BdrvRequestFlags flags);
183 int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
184                                      int64_t bytes,
185                                      QEMUIOVector *qiov, size_t qiov_offset,
186                                      BdrvRequestFlags flags);
187 
188 int co_wrapper_mixed blk_pwrite_compressed(BlockBackend *blk,
189                                            int64_t offset, int64_t bytes,
190                                            const void *buf);
191 int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
192                                           int64_t bytes, const void *buf);
193 
194 int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
195                                        int64_t bytes,
196                                        BdrvRequestFlags flags);
197 int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
198                                       int64_t bytes, BdrvRequestFlags flags);
199 
200 int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset,
201                                     unsigned int *nr_zones,
202                                     BlockZoneDescriptor *zones);
203 int co_wrapper_mixed blk_zone_report(BlockBackend *blk, int64_t offset,
204                                          unsigned int *nr_zones,
205                                          BlockZoneDescriptor *zones);
206 int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
207                                   int64_t offset, int64_t len);
208 int co_wrapper_mixed blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
209                                        int64_t offset, int64_t len);
210 int coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset,
211                                     QEMUIOVector *qiov,
212                                     BdrvRequestFlags flags);
213 int co_wrapper_mixed blk_zone_append(BlockBackend *blk, int64_t *offset,
214                                          QEMUIOVector *qiov,
215                                          BdrvRequestFlags flags);
216 
217 int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,
218                                   int64_t bytes);
219 int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
220                                  int64_t bytes);
221 
222 int co_wrapper_mixed blk_flush(BlockBackend *blk);
223 int coroutine_fn blk_co_flush(BlockBackend *blk);
224 
225 int co_wrapper_mixed blk_ioctl(BlockBackend *blk, unsigned long int req,
226                                void *buf);
227 int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
228                               void *buf);
229 
230 int co_wrapper_mixed blk_truncate(BlockBackend *blk, int64_t offset,
231                                   bool exact, PreallocMode prealloc,
232                                   BdrvRequestFlags flags, Error **errp);
233 int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
234                                  PreallocMode prealloc, BdrvRequestFlags flags,
235                                  Error **errp);
236 
237 #endif /* BLOCK_BACKEND_IO_H */
238