xref: /qemu/include/sysemu/block-backend-io.h (revision 69c4befb)
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 char *blk_get_attached_dev_id(BlockBackend *blk);
36 
37 BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
38                                   int64_t bytes, BdrvRequestFlags flags,
39                                   BlockCompletionFunc *cb, void *opaque);
40 
41 BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
42                            QEMUIOVector *qiov, BdrvRequestFlags flags,
43                            BlockCompletionFunc *cb, void *opaque);
44 BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
45                             QEMUIOVector *qiov, BdrvRequestFlags flags,
46                             BlockCompletionFunc *cb, void *opaque);
47 BlockAIOCB *blk_aio_flush(BlockBackend *blk,
48                           BlockCompletionFunc *cb, void *opaque);
49 BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
50                              BlockCompletionFunc *cb, void *opaque);
51 void blk_aio_cancel_async(BlockAIOCB *acb);
52 BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
53                           BlockCompletionFunc *cb, void *opaque);
54 
55 void blk_inc_in_flight(BlockBackend *blk);
56 void blk_dec_in_flight(BlockBackend *blk);
57 bool blk_is_inserted(BlockBackend *blk);
58 bool blk_is_available(BlockBackend *blk);
59 void blk_lock_medium(BlockBackend *blk, bool locked);
60 void blk_eject(BlockBackend *blk, bool eject_flag);
61 int64_t blk_getlength(BlockBackend *blk);
62 void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
63 int64_t blk_nb_sectors(BlockBackend *blk);
64 void *blk_try_blockalign(BlockBackend *blk, size_t size);
65 void *blk_blockalign(BlockBackend *blk, size_t size);
66 bool blk_is_writable(BlockBackend *blk);
67 bool blk_enable_write_cache(BlockBackend *blk);
68 BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read);
69 BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
70                                       int error);
71 void blk_error_action(BlockBackend *blk, BlockErrorAction action,
72                       bool is_read, int error);
73 void blk_iostatus_set_err(BlockBackend *blk, int error);
74 int blk_get_max_iov(BlockBackend *blk);
75 int blk_get_max_hw_iov(BlockBackend *blk);
76 
77 void blk_io_plug(BlockBackend *blk);
78 void blk_io_unplug(BlockBackend *blk);
79 AioContext *blk_get_aio_context(BlockBackend *blk);
80 BlockAcctStats *blk_get_stats(BlockBackend *blk);
81 void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
82                   BlockCompletionFunc *cb, void *opaque);
83 BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
84                                   BlockCompletionFunc *cb,
85                                   void *opaque, int ret);
86 
87 uint32_t blk_get_request_alignment(BlockBackend *blk);
88 uint32_t blk_get_max_transfer(BlockBackend *blk);
89 uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
90 
91 int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
92                                    BlockBackend *blk_out, int64_t off_out,
93                                    int64_t bytes, BdrvRequestFlags read_flags,
94                                    BdrvRequestFlags write_flags);
95 
96 int coroutine_fn blk_co_block_status_above(BlockBackend *blk,
97                                            BlockDriverState *base,
98                                            int64_t offset, int64_t bytes,
99                                            int64_t *pnum, int64_t *map,
100                                            BlockDriverState **file);
101 int coroutine_fn blk_co_is_allocated_above(BlockBackend *blk,
102                                            BlockDriverState *base,
103                                            bool include_base, int64_t offset,
104                                            int64_t bytes, int64_t *pnum);
105 
106 /*
107  * "I/O or GS" API functions. These functions can run without
108  * the BQL, but only in one specific iothread/main loop.
109  *
110  * See include/block/block-io.h for more information about
111  * the "I/O or GS" API.
112  */
113 
114 int co_wrapper_mixed blk_pread(BlockBackend *blk, int64_t offset,
115                                int64_t bytes, void *buf,
116                                BdrvRequestFlags flags);
117 int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes,
118                               void *buf, BdrvRequestFlags flags);
119 
120 int co_wrapper_mixed blk_preadv(BlockBackend *blk, int64_t offset,
121                                 int64_t bytes, QEMUIOVector *qiov,
122                                 BdrvRequestFlags flags);
123 int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
124                                int64_t bytes, QEMUIOVector *qiov,
125                                BdrvRequestFlags flags);
126 
127 int co_wrapper_mixed blk_preadv_part(BlockBackend *blk, int64_t offset,
128                                      int64_t bytes, QEMUIOVector *qiov,
129                                      size_t qiov_offset,
130                                      BdrvRequestFlags flags);
131 int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset,
132                                     int64_t bytes, QEMUIOVector *qiov,
133                                     size_t qiov_offset, BdrvRequestFlags flags);
134 
135 int co_wrapper_mixed blk_pwrite(BlockBackend *blk, int64_t offset,
136                                 int64_t bytes, const void *buf,
137                                 BdrvRequestFlags flags);
138 int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
139                                const void *buf, BdrvRequestFlags flags);
140 
141 int co_wrapper_mixed blk_pwritev(BlockBackend *blk, int64_t offset,
142                                  int64_t bytes, QEMUIOVector *qiov,
143                                  BdrvRequestFlags flags);
144 int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
145                                 int64_t bytes, QEMUIOVector *qiov,
146                                 BdrvRequestFlags flags);
147 
148 int co_wrapper_mixed blk_pwritev_part(BlockBackend *blk, int64_t offset,
149                                       int64_t bytes, QEMUIOVector *qiov,
150                                       size_t qiov_offset,
151                                       BdrvRequestFlags flags);
152 int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
153                                      int64_t bytes,
154                                      QEMUIOVector *qiov, size_t qiov_offset,
155                                      BdrvRequestFlags flags);
156 
157 int co_wrapper_mixed blk_pwrite_compressed(BlockBackend *blk,
158                                            int64_t offset, int64_t bytes,
159                                            const void *buf);
160 int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
161                                           int64_t bytes, const void *buf);
162 
163 int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
164                                        int64_t bytes,
165                                        BdrvRequestFlags flags);
166 int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
167                                       int64_t bytes, BdrvRequestFlags flags);
168 
169 int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,
170                                   int64_t bytes);
171 int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
172                                  int64_t bytes);
173 
174 int co_wrapper_mixed blk_flush(BlockBackend *blk);
175 int coroutine_fn blk_co_flush(BlockBackend *blk);
176 
177 int co_wrapper_mixed blk_ioctl(BlockBackend *blk, unsigned long int req,
178                                void *buf);
179 int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
180                               void *buf);
181 
182 int co_wrapper_mixed blk_truncate(BlockBackend *blk, int64_t offset,
183                                   bool exact, PreallocMode prealloc,
184                                   BdrvRequestFlags flags, Error **errp);
185 int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
186                                  PreallocMode prealloc, BdrvRequestFlags flags,
187                                  Error **errp);
188 
189 #endif /* BLOCK_BACKEND_IO_H */
190