1a2c4c3b1SEmanuele Giuseppe Esposito /*
2a2c4c3b1SEmanuele Giuseppe Esposito  * QEMU Block backends
3a2c4c3b1SEmanuele Giuseppe Esposito  *
4a2c4c3b1SEmanuele Giuseppe Esposito  * Copyright (C) 2014-2016 Red Hat, Inc.
5a2c4c3b1SEmanuele Giuseppe Esposito  *
6a2c4c3b1SEmanuele Giuseppe Esposito  * Authors:
7a2c4c3b1SEmanuele Giuseppe Esposito  *  Markus Armbruster <armbru@redhat.com>,
8a2c4c3b1SEmanuele Giuseppe Esposito  *
9a2c4c3b1SEmanuele Giuseppe Esposito  * This work is licensed under the terms of the GNU LGPL, version 2.1
10a2c4c3b1SEmanuele Giuseppe Esposito  * or later.  See the COPYING.LIB file in the top-level directory.
11a2c4c3b1SEmanuele Giuseppe Esposito  */
12a2c4c3b1SEmanuele Giuseppe Esposito 
13a2c4c3b1SEmanuele Giuseppe Esposito #ifndef BLOCK_BACKEND_IO_H
14a2c4c3b1SEmanuele Giuseppe Esposito #define BLOCK_BACKEND_IO_H
15a2c4c3b1SEmanuele Giuseppe Esposito 
16a2c4c3b1SEmanuele Giuseppe Esposito #include "block-backend-common.h"
17e2c1c34fSMarkus Armbruster #include "block/accounting.h"
18a2c4c3b1SEmanuele Giuseppe Esposito 
19a2c4c3b1SEmanuele Giuseppe Esposito /*
20a2c4c3b1SEmanuele Giuseppe Esposito  * I/O API functions. These functions are thread-safe.
21a2c4c3b1SEmanuele Giuseppe Esposito  *
22a2c4c3b1SEmanuele Giuseppe Esposito  * See include/block/block-io.h for more information about
23a2c4c3b1SEmanuele Giuseppe Esposito  * the I/O API.
24a2c4c3b1SEmanuele Giuseppe Esposito  */
25a2c4c3b1SEmanuele Giuseppe Esposito 
26a2c4c3b1SEmanuele Giuseppe Esposito const char *blk_name(const BlockBackend *blk);
27a2c4c3b1SEmanuele Giuseppe Esposito 
28a2c4c3b1SEmanuele Giuseppe Esposito BlockDriverState *blk_bs(BlockBackend *blk);
29a2c4c3b1SEmanuele Giuseppe Esposito 
30a2c4c3b1SEmanuele Giuseppe Esposito void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
31a2c4c3b1SEmanuele Giuseppe Esposito void blk_set_allow_aio_context_change(BlockBackend *blk, bool allow);
32a2c4c3b1SEmanuele Giuseppe Esposito void blk_set_disable_request_queuing(BlockBackend *blk, bool disable);
33a2c4c3b1SEmanuele Giuseppe Esposito bool blk_iostatus_is_enabled(const BlockBackend *blk);
34a2c4c3b1SEmanuele Giuseppe Esposito 
35a2c4c3b1SEmanuele Giuseppe Esposito char *blk_get_attached_dev_id(BlockBackend *blk);
36a2c4c3b1SEmanuele Giuseppe Esposito 
37a2c4c3b1SEmanuele Giuseppe Esposito BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
38a2c4c3b1SEmanuele Giuseppe Esposito                                   int64_t bytes, BdrvRequestFlags flags,
39a2c4c3b1SEmanuele Giuseppe Esposito                                   BlockCompletionFunc *cb, void *opaque);
40a2c4c3b1SEmanuele Giuseppe Esposito 
41a2c4c3b1SEmanuele Giuseppe Esposito BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
42a2c4c3b1SEmanuele Giuseppe Esposito                            QEMUIOVector *qiov, BdrvRequestFlags flags,
43a2c4c3b1SEmanuele Giuseppe Esposito                            BlockCompletionFunc *cb, void *opaque);
44a2c4c3b1SEmanuele Giuseppe Esposito BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
45a2c4c3b1SEmanuele Giuseppe Esposito                             QEMUIOVector *qiov, BdrvRequestFlags flags,
46a2c4c3b1SEmanuele Giuseppe Esposito                             BlockCompletionFunc *cb, void *opaque);
47a2c4c3b1SEmanuele Giuseppe Esposito BlockAIOCB *blk_aio_flush(BlockBackend *blk,
48a2c4c3b1SEmanuele Giuseppe Esposito                           BlockCompletionFunc *cb, void *opaque);
496d43eaa3SSam Li BlockAIOCB *blk_aio_zone_report(BlockBackend *blk, int64_t offset,
506d43eaa3SSam Li                                 unsigned int *nr_zones,
516d43eaa3SSam Li                                 BlockZoneDescriptor *zones,
526d43eaa3SSam Li                                 BlockCompletionFunc *cb, void *opaque);
536d43eaa3SSam Li BlockAIOCB *blk_aio_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
546d43eaa3SSam Li                               int64_t offset, int64_t len,
556d43eaa3SSam Li                               BlockCompletionFunc *cb, void *opaque);
56*4751d09aSSam Li BlockAIOCB *blk_aio_zone_append(BlockBackend *blk, int64_t *offset,
57*4751d09aSSam Li                                 QEMUIOVector *qiov, BdrvRequestFlags flags,
58*4751d09aSSam Li                                 BlockCompletionFunc *cb, void *opaque);
59a2c4c3b1SEmanuele Giuseppe Esposito BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
60a2c4c3b1SEmanuele Giuseppe Esposito                              BlockCompletionFunc *cb, void *opaque);
61a2c4c3b1SEmanuele Giuseppe Esposito void blk_aio_cancel_async(BlockAIOCB *acb);
62a2c4c3b1SEmanuele Giuseppe Esposito BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
63a2c4c3b1SEmanuele Giuseppe Esposito                           BlockCompletionFunc *cb, void *opaque);
64a2c4c3b1SEmanuele Giuseppe Esposito 
65a2c4c3b1SEmanuele Giuseppe Esposito void blk_inc_in_flight(BlockBackend *blk);
66a2c4c3b1SEmanuele Giuseppe Esposito void blk_dec_in_flight(BlockBackend *blk);
671e97be91SEmanuele Giuseppe Esposito 
68c73ff92cSEmanuele Giuseppe Esposito bool coroutine_fn GRAPH_RDLOCK blk_co_is_inserted(BlockBackend *blk);
69c73ff92cSEmanuele Giuseppe Esposito bool co_wrapper_mixed_bdrv_rdlock blk_is_inserted(BlockBackend *blk);
701e97be91SEmanuele Giuseppe Esposito 
71c73ff92cSEmanuele Giuseppe Esposito bool coroutine_fn GRAPH_RDLOCK blk_co_is_available(BlockBackend *blk);
72c73ff92cSEmanuele Giuseppe Esposito bool co_wrapper_mixed_bdrv_rdlock blk_is_available(BlockBackend *blk);
732c75261cSEmanuele Giuseppe Esposito 
742c75261cSEmanuele Giuseppe Esposito void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked);
752c75261cSEmanuele Giuseppe Esposito void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked);
762531b390SEmanuele Giuseppe Esposito 
772531b390SEmanuele Giuseppe Esposito void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag);
782531b390SEmanuele Giuseppe Esposito void co_wrapper blk_eject(BlockBackend *blk, bool eject_flag);
79c86422c5SEmanuele Giuseppe Esposito 
80c86422c5SEmanuele Giuseppe Esposito int64_t coroutine_fn blk_co_getlength(BlockBackend *blk);
81c86422c5SEmanuele Giuseppe Esposito int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk);
82c86422c5SEmanuele Giuseppe Esposito 
83d8fbf9aaSKevin Wolf void coroutine_fn blk_co_get_geometry(BlockBackend *blk,
84d8fbf9aaSKevin Wolf                                       uint64_t *nb_sectors_ptr);
8581f730d4SPaolo Bonzini void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
86c86422c5SEmanuele Giuseppe Esposito 
87c86422c5SEmanuele Giuseppe Esposito int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk);
8881f730d4SPaolo Bonzini int64_t blk_nb_sectors(BlockBackend *blk);
89c86422c5SEmanuele Giuseppe Esposito 
90a2c4c3b1SEmanuele Giuseppe Esposito void *blk_try_blockalign(BlockBackend *blk, size_t size);
91a2c4c3b1SEmanuele Giuseppe Esposito void *blk_blockalign(BlockBackend *blk, size_t size);
92a2c4c3b1SEmanuele Giuseppe Esposito bool blk_is_writable(BlockBackend *blk);
93a2c4c3b1SEmanuele Giuseppe Esposito bool blk_enable_write_cache(BlockBackend *blk);
94a2c4c3b1SEmanuele Giuseppe Esposito BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read);
95a2c4c3b1SEmanuele Giuseppe Esposito BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
96a2c4c3b1SEmanuele Giuseppe Esposito                                       int error);
97a2c4c3b1SEmanuele Giuseppe Esposito void blk_error_action(BlockBackend *blk, BlockErrorAction action,
98a2c4c3b1SEmanuele Giuseppe Esposito                       bool is_read, int error);
99a2c4c3b1SEmanuele Giuseppe Esposito void blk_iostatus_set_err(BlockBackend *blk, int error);
100a2c4c3b1SEmanuele Giuseppe Esposito int blk_get_max_iov(BlockBackend *blk);
101a2c4c3b1SEmanuele Giuseppe Esposito int blk_get_max_hw_iov(BlockBackend *blk);
102a2c4c3b1SEmanuele Giuseppe Esposito 
103a2c4c3b1SEmanuele Giuseppe Esposito AioContext *blk_get_aio_context(BlockBackend *blk);
104a2c4c3b1SEmanuele Giuseppe Esposito BlockAcctStats *blk_get_stats(BlockBackend *blk);
105a2c4c3b1SEmanuele Giuseppe Esposito void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
106a2c4c3b1SEmanuele Giuseppe Esposito                   BlockCompletionFunc *cb, void *opaque);
107a2c4c3b1SEmanuele Giuseppe Esposito BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
108a2c4c3b1SEmanuele Giuseppe Esposito                                   BlockCompletionFunc *cb,
109a2c4c3b1SEmanuele Giuseppe Esposito                                   void *opaque, int ret);
110a2c4c3b1SEmanuele Giuseppe Esposito 
111a2c4c3b1SEmanuele Giuseppe Esposito uint32_t blk_get_request_alignment(BlockBackend *blk);
112a2c4c3b1SEmanuele Giuseppe Esposito uint32_t blk_get_max_transfer(BlockBackend *blk);
113a2c4c3b1SEmanuele Giuseppe Esposito uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
114a2c4c3b1SEmanuele Giuseppe Esposito 
115a2c4c3b1SEmanuele Giuseppe Esposito int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
116a2c4c3b1SEmanuele Giuseppe Esposito                                    BlockBackend *blk_out, int64_t off_out,
117a2c4c3b1SEmanuele Giuseppe Esposito                                    int64_t bytes, BdrvRequestFlags read_flags,
118a2c4c3b1SEmanuele Giuseppe Esposito                                    BdrvRequestFlags write_flags);
119a2c4c3b1SEmanuele Giuseppe Esposito 
120ff7e261bSEmanuele Giuseppe Esposito int coroutine_fn blk_co_block_status_above(BlockBackend *blk,
121ff7e261bSEmanuele Giuseppe Esposito                                            BlockDriverState *base,
122ff7e261bSEmanuele Giuseppe Esposito                                            int64_t offset, int64_t bytes,
123ff7e261bSEmanuele Giuseppe Esposito                                            int64_t *pnum, int64_t *map,
124ff7e261bSEmanuele Giuseppe Esposito                                            BlockDriverState **file);
125ff7e261bSEmanuele Giuseppe Esposito int coroutine_fn blk_co_is_allocated_above(BlockBackend *blk,
126ff7e261bSEmanuele Giuseppe Esposito                                            BlockDriverState *base,
127ff7e261bSEmanuele Giuseppe Esposito                                            bool include_base, int64_t offset,
128ff7e261bSEmanuele Giuseppe Esposito                                            int64_t bytes, int64_t *pnum);
129a2c4c3b1SEmanuele Giuseppe Esposito 
130a2c4c3b1SEmanuele Giuseppe Esposito /*
131a2c4c3b1SEmanuele Giuseppe Esposito  * "I/O or GS" API functions. These functions can run without
132a2c4c3b1SEmanuele Giuseppe Esposito  * the BQL, but only in one specific iothread/main loop.
133a2c4c3b1SEmanuele Giuseppe Esposito  *
134a2c4c3b1SEmanuele Giuseppe Esposito  * See include/block/block-io.h for more information about
135a2c4c3b1SEmanuele Giuseppe Esposito  * the "I/O or GS" API.
136a2c4c3b1SEmanuele Giuseppe Esposito  */
137a2c4c3b1SEmanuele Giuseppe Esposito 
1381bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_pread(BlockBackend *blk, int64_t offset,
139facbaad9SAlberto Faria                                int64_t bytes, void *buf,
1403b35d454SAlberto Faria                                BdrvRequestFlags flags);
1416f675c93SAlberto Faria int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes,
1426f675c93SAlberto Faria                               void *buf, BdrvRequestFlags flags);
1436f675c93SAlberto Faria 
1441bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_preadv(BlockBackend *blk, int64_t offset,
1456f675c93SAlberto Faria                                 int64_t bytes, QEMUIOVector *qiov,
146facbaad9SAlberto Faria                                 BdrvRequestFlags flags);
1476f675c93SAlberto Faria int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
1486f675c93SAlberto Faria                                int64_t bytes, QEMUIOVector *qiov,
1496f675c93SAlberto Faria                                BdrvRequestFlags flags);
1506f675c93SAlberto Faria 
1511bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_preadv_part(BlockBackend *blk, int64_t offset,
152d1d3fc3dSAlberto Faria                                      int64_t bytes, QEMUIOVector *qiov,
153d1d3fc3dSAlberto Faria                                      size_t qiov_offset,
154d1d3fc3dSAlberto Faria                                      BdrvRequestFlags flags);
155d1d3fc3dSAlberto Faria int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset,
156d1d3fc3dSAlberto Faria                                     int64_t bytes, QEMUIOVector *qiov,
157d1d3fc3dSAlberto Faria                                     size_t qiov_offset, BdrvRequestFlags flags);
1586f675c93SAlberto Faria 
1591bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_pwrite(BlockBackend *blk, int64_t offset,
1606f675c93SAlberto Faria                                 int64_t bytes, const void *buf,
1616f675c93SAlberto Faria                                 BdrvRequestFlags flags);
1626f675c93SAlberto Faria int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
1636f675c93SAlberto Faria                                const void *buf, BdrvRequestFlags flags);
1646f675c93SAlberto Faria 
1651bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_pwritev(BlockBackend *blk, int64_t offset,
1667c8cd723SAlberto Faria                                  int64_t bytes, QEMUIOVector *qiov,
1677c8cd723SAlberto Faria                                  BdrvRequestFlags flags);
1686f675c93SAlberto Faria int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
169a2c4c3b1SEmanuele Giuseppe Esposito                                 int64_t bytes, QEMUIOVector *qiov,
170a2c4c3b1SEmanuele Giuseppe Esposito                                 BdrvRequestFlags flags);
1716f675c93SAlberto Faria 
1721bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_pwritev_part(BlockBackend *blk, int64_t offset,
17309cca043SAlberto Faria                                       int64_t bytes, QEMUIOVector *qiov,
17409cca043SAlberto Faria                                       size_t qiov_offset,
17509cca043SAlberto Faria                                       BdrvRequestFlags flags);
176a2c4c3b1SEmanuele Giuseppe Esposito int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
177a2c4c3b1SEmanuele Giuseppe Esposito                                      int64_t bytes,
178a2c4c3b1SEmanuele Giuseppe Esposito                                      QEMUIOVector *qiov, size_t qiov_offset,
179a2c4c3b1SEmanuele Giuseppe Esposito                                      BdrvRequestFlags flags);
1806f675c93SAlberto Faria 
1811bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_pwrite_compressed(BlockBackend *blk,
1826f675c93SAlberto Faria                                            int64_t offset, int64_t bytes,
1836f675c93SAlberto Faria                                            const void *buf);
1846f675c93SAlberto Faria int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
1856f675c93SAlberto Faria                                           int64_t bytes, const void *buf);
1866f675c93SAlberto Faria 
1871bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
1886f675c93SAlberto Faria                                        int64_t bytes,
1897c8cd723SAlberto Faria                                        BdrvRequestFlags flags);
1906f675c93SAlberto Faria int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
1916f675c93SAlberto Faria                                       int64_t bytes, BdrvRequestFlags flags);
192a2c4c3b1SEmanuele Giuseppe Esposito 
1936d43eaa3SSam Li int coroutine_fn blk_co_zone_report(BlockBackend *blk, int64_t offset,
1946d43eaa3SSam Li                                     unsigned int *nr_zones,
1956d43eaa3SSam Li                                     BlockZoneDescriptor *zones);
1966d43eaa3SSam Li int co_wrapper_mixed blk_zone_report(BlockBackend *blk, int64_t offset,
1976d43eaa3SSam Li                                          unsigned int *nr_zones,
1986d43eaa3SSam Li                                          BlockZoneDescriptor *zones);
1996d43eaa3SSam Li int coroutine_fn blk_co_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
2006d43eaa3SSam Li                                   int64_t offset, int64_t len);
2016d43eaa3SSam Li int co_wrapper_mixed blk_zone_mgmt(BlockBackend *blk, BlockZoneOp op,
2026d43eaa3SSam Li                                        int64_t offset, int64_t len);
203*4751d09aSSam Li int coroutine_fn blk_co_zone_append(BlockBackend *blk, int64_t *offset,
204*4751d09aSSam Li                                     QEMUIOVector *qiov,
205*4751d09aSSam Li                                     BdrvRequestFlags flags);
206*4751d09aSSam Li int co_wrapper_mixed blk_zone_append(BlockBackend *blk, int64_t *offset,
207*4751d09aSSam Li                                          QEMUIOVector *qiov,
208*4751d09aSSam Li                                          BdrvRequestFlags flags);
2096d43eaa3SSam Li 
2101bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset,
21150db162dSAlberto Faria                                   int64_t bytes);
212a2c4c3b1SEmanuele Giuseppe Esposito int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
213a2c4c3b1SEmanuele Giuseppe Esposito                                  int64_t bytes);
214a2c4c3b1SEmanuele Giuseppe Esposito 
2151bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_flush(BlockBackend *blk);
216a2c4c3b1SEmanuele Giuseppe Esposito int coroutine_fn blk_co_flush(BlockBackend *blk);
217a2c4c3b1SEmanuele Giuseppe Esposito 
2181bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_ioctl(BlockBackend *blk, unsigned long int req,
219df02da00SAlberto Faria                                void *buf);
220df02da00SAlberto Faria int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
221df02da00SAlberto Faria                               void *buf);
222a2c4c3b1SEmanuele Giuseppe Esposito 
2231bd54201SEmanuele Giuseppe Esposito int co_wrapper_mixed blk_truncate(BlockBackend *blk, int64_t offset,
224015ed252SAlberto Faria                                   bool exact, PreallocMode prealloc,
225015ed252SAlberto Faria                                   BdrvRequestFlags flags, Error **errp);
226015ed252SAlberto Faria int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
227015ed252SAlberto Faria                                  PreallocMode prealloc, BdrvRequestFlags flags,
228015ed252SAlberto Faria                                  Error **errp);
229a2c4c3b1SEmanuele Giuseppe Esposito 
230a2c4c3b1SEmanuele Giuseppe Esposito #endif /* BLOCK_BACKEND_IO_H */
231