]> git.proxmox.com Git - mirror_qemu.git/blame - include/sysemu/block-backend-io.h
dump: Add more offset variables
[mirror_qemu.git] / include / sysemu / block-backend-io.h
CommitLineData
a2c4c3b1
EGE
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
18/*
19 * I/O API functions. These functions are thread-safe.
20 *
21 * See include/block/block-io.h for more information about
22 * the I/O API.
23 */
24
25const char *blk_name(const BlockBackend *blk);
26
27BlockDriverState *blk_bs(BlockBackend *blk);
28
29void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow);
30void blk_set_allow_aio_context_change(BlockBackend *blk, bool allow);
31void blk_set_disable_request_queuing(BlockBackend *blk, bool disable);
32bool blk_iostatus_is_enabled(const BlockBackend *blk);
33
34char *blk_get_attached_dev_id(BlockBackend *blk);
35
36BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
37 int64_t bytes, BdrvRequestFlags flags,
38 BlockCompletionFunc *cb, void *opaque);
39
40BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset,
41 QEMUIOVector *qiov, BdrvRequestFlags flags,
42 BlockCompletionFunc *cb, void *opaque);
43BlockAIOCB *blk_aio_pwritev(BlockBackend *blk, int64_t offset,
44 QEMUIOVector *qiov, BdrvRequestFlags flags,
45 BlockCompletionFunc *cb, void *opaque);
46BlockAIOCB *blk_aio_flush(BlockBackend *blk,
47 BlockCompletionFunc *cb, void *opaque);
48BlockAIOCB *blk_aio_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes,
49 BlockCompletionFunc *cb, void *opaque);
50void blk_aio_cancel_async(BlockAIOCB *acb);
51BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
52 BlockCompletionFunc *cb, void *opaque);
53
54void blk_inc_in_flight(BlockBackend *blk);
55void blk_dec_in_flight(BlockBackend *blk);
56bool blk_is_inserted(BlockBackend *blk);
57bool blk_is_available(BlockBackend *blk);
58void blk_lock_medium(BlockBackend *blk, bool locked);
59void blk_eject(BlockBackend *blk, bool eject_flag);
60int64_t blk_getlength(BlockBackend *blk);
61void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr);
62int64_t blk_nb_sectors(BlockBackend *blk);
63void *blk_try_blockalign(BlockBackend *blk, size_t size);
64void *blk_blockalign(BlockBackend *blk, size_t size);
65bool blk_is_writable(BlockBackend *blk);
66bool blk_enable_write_cache(BlockBackend *blk);
67BlockdevOnError blk_get_on_error(BlockBackend *blk, bool is_read);
68BlockErrorAction blk_get_error_action(BlockBackend *blk, bool is_read,
69 int error);
70void blk_error_action(BlockBackend *blk, BlockErrorAction action,
71 bool is_read, int error);
72void blk_iostatus_set_err(BlockBackend *blk, int error);
73int blk_get_max_iov(BlockBackend *blk);
74int blk_get_max_hw_iov(BlockBackend *blk);
75void blk_set_guest_block_size(BlockBackend *blk, int align);
76
77void blk_io_plug(BlockBackend *blk);
78void blk_io_unplug(BlockBackend *blk);
79AioContext *blk_get_aio_context(BlockBackend *blk);
80BlockAcctStats *blk_get_stats(BlockBackend *blk);
81void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk,
82 BlockCompletionFunc *cb, void *opaque);
83BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
84 BlockCompletionFunc *cb,
85 void *opaque, int ret);
86
87uint32_t blk_get_request_alignment(BlockBackend *blk);
88uint32_t blk_get_max_transfer(BlockBackend *blk);
89uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
90
91int 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
97/*
98 * "I/O or GS" API functions. These functions can run without
99 * the BQL, but only in one specific iothread/main loop.
100 *
101 * See include/block/block-io.h for more information about
102 * the "I/O or GS" API.
103 */
104
105int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes);
106int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
107 BdrvRequestFlags flags);
108int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
109 int64_t bytes, QEMUIOVector *qiov,
110 BdrvRequestFlags flags);
111int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
112 int64_t bytes,
113 QEMUIOVector *qiov, size_t qiov_offset,
114 BdrvRequestFlags flags);
115int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
116 int64_t bytes, QEMUIOVector *qiov,
117 BdrvRequestFlags flags);
118
119static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset,
120 int64_t bytes, void *buf,
121 BdrvRequestFlags flags)
122{
123 QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
37868b2a 124 IO_OR_GS_CODE();
a2c4c3b1
EGE
125
126 assert(bytes <= SIZE_MAX);
127
128 return blk_co_preadv(blk, offset, bytes, &qiov, flags);
129}
130
131static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset,
132 int64_t bytes, void *buf,
133 BdrvRequestFlags flags)
134{
135 QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
37868b2a 136 IO_OR_GS_CODE();
a2c4c3b1
EGE
137
138 assert(bytes <= SIZE_MAX);
139
140 return blk_co_pwritev(blk, offset, bytes, &qiov, flags);
141}
142
143int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
144 int64_t bytes);
145
146int coroutine_fn blk_co_flush(BlockBackend *blk);
147int blk_flush(BlockBackend *blk);
148
149int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
150
151int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
152 int64_t bytes);
153int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes);
154int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
155 int64_t bytes, BdrvRequestFlags flags);
156int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
157 int64_t bytes, BdrvRequestFlags flags);
158int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
159 PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
160
161#endif /* BLOCK_BACKEND_IO_H */