block-backend-io.h 11 KB

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