root / include / block / block_int.h @ 793ed47a
History | View | Annotate | Download (19.5 kB)
1 | ea2384d3 | bellard | /*
|
---|---|---|---|
2 | ea2384d3 | bellard | * QEMU System Emulator block driver
|
3 | 5fafdf24 | ths | *
|
4 | ea2384d3 | bellard | * Copyright (c) 2003 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | ea2384d3 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | ea2384d3 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | ea2384d3 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | ea2384d3 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | ea2384d3 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | ea2384d3 | bellard | * furnished to do so, subject to the following conditions:
|
12 | ea2384d3 | bellard | *
|
13 | ea2384d3 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | ea2384d3 | bellard | * all copies or substantial portions of the Software.
|
15 | ea2384d3 | bellard | *
|
16 | ea2384d3 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | ea2384d3 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | ea2384d3 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | ea2384d3 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | ea2384d3 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | ea2384d3 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | ea2384d3 | bellard | * THE SOFTWARE.
|
23 | ea2384d3 | bellard | */
|
24 | ea2384d3 | bellard | #ifndef BLOCK_INT_H
|
25 | ea2384d3 | bellard | #define BLOCK_INT_H
|
26 | ea2384d3 | bellard | |
27 | 737e150e | Paolo Bonzini | #include "block/block.h" |
28 | 1de7afc9 | Paolo Bonzini | #include "qemu/option.h" |
29 | 1de7afc9 | Paolo Bonzini | #include "qemu/queue.h" |
30 | 737e150e | Paolo Bonzini | #include "block/coroutine.h" |
31 | 1de7afc9 | Paolo Bonzini | #include "qemu/timer.h" |
32 | b2023818 | Luiz Capitulino | #include "qapi-types.h" |
33 | 7b1b5d19 | Paolo Bonzini | #include "qapi/qmp/qerror.h" |
34 | 83c9089e | Paolo Bonzini | #include "monitor/monitor.h" |
35 | 8f0720ec | Paolo Bonzini | #include "qemu/hbitmap.h" |
36 | f364ec65 | Wenchao Xia | #include "block/snapshot.h" |
37 | 6a1751b7 | Alex Bligh | #include "qemu/main-loop.h" |
38 | cc0681c4 | Benoît Canet | #include "qemu/throttle.h" |
39 | faf07963 | pbrook | |
40 | bfe8043e | Stefan Hajnoczi | #define BLOCK_FLAG_ENCRYPT 1 |
41 | bfe8043e | Stefan Hajnoczi | #define BLOCK_FLAG_COMPAT6 4 |
42 | bfe8043e | Stefan Hajnoczi | #define BLOCK_FLAG_LAZY_REFCOUNTS 8 |
43 | ec36ba14 | ths | |
44 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_SIZE "size" |
45 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_ENCRYPT "encryption" |
46 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_COMPAT6 "compat6" |
47 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_BACKING_FILE "backing_file" |
48 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_BACKING_FMT "backing_fmt" |
49 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_CLUSTER_SIZE "cluster_size" |
50 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_TABLE_SIZE "table_size" |
51 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_PREALLOC "preallocation" |
52 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_SUBFMT "subformat" |
53 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_COMPAT_LEVEL "compat" |
54 | bfe8043e | Stefan Hajnoczi | #define BLOCK_OPT_LAZY_REFCOUNTS "lazy_refcounts" |
55 | 7f2039f6 | Othmar Pasteka | #define BLOCK_OPT_ADAPTER_TYPE "adapter_type" |
56 | b3af018f | Liu Yuan | #define BLOCK_OPT_REDUNDANCY "redundancy" |
57 | 0e7e1989 | Kevin Wolf | |
58 | d616b224 | Stefan Hajnoczi | typedef struct BdrvTrackedRequest { |
59 | d616b224 | Stefan Hajnoczi | BlockDriverState *bs; |
60 | 793ed47a | Kevin Wolf | int64_t offset; |
61 | 793ed47a | Kevin Wolf | unsigned int bytes; |
62 | d616b224 | Stefan Hajnoczi | bool is_write;
|
63 | d616b224 | Stefan Hajnoczi | QLIST_ENTRY(BdrvTrackedRequest) list; |
64 | d616b224 | Stefan Hajnoczi | Coroutine *co; /* owner, used for deadlock detection */
|
65 | d616b224 | Stefan Hajnoczi | CoQueue wait_queue; /* coroutines blocked on this request */
|
66 | d616b224 | Stefan Hajnoczi | } BdrvTrackedRequest; |
67 | d616b224 | Stefan Hajnoczi | |
68 | ea2384d3 | bellard | struct BlockDriver {
|
69 | ea2384d3 | bellard | const char *format_name; |
70 | ea2384d3 | bellard | int instance_size;
|
71 | f6186f49 | Benoît Canet | |
72 | 212a5a8f | Benoît Canet | /* this table of boolean contains authorizations for the block operations */
|
73 | 212a5a8f | Benoît Canet | bool authorizations[BS_AUTHORIZATION_COUNT];
|
74 | 212a5a8f | Benoît Canet | /* for snapshots complex block filter like Quorum can implement the
|
75 | 212a5a8f | Benoît Canet | * following recursive callback instead of BS_IS_A_FILTER.
|
76 | 212a5a8f | Benoît Canet | * It's purpose is to recurse on the filter children while calling
|
77 | 212a5a8f | Benoît Canet | * bdrv_recurse_is_first_non_filter on them.
|
78 | 212a5a8f | Benoît Canet | * For a sample implementation look in the future Quorum block filter.
|
79 | f6186f49 | Benoît Canet | */
|
80 | 212a5a8f | Benoît Canet | bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs,
|
81 | 212a5a8f | Benoît Canet | BlockDriverState *candidate); |
82 | f6186f49 | Benoît Canet | |
83 | ea2384d3 | bellard | int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); |
84 | 508c7cb3 | Christoph Hellwig | int (*bdrv_probe_device)(const char *filename); |
85 | c2ad1b0c | Kevin Wolf | |
86 | c2ad1b0c | Kevin Wolf | /* Any driver implementing this callback is expected to be able to handle
|
87 | c2ad1b0c | Kevin Wolf | * NULL file names in its .bdrv_open() implementation */
|
88 | 6963a30d | Kevin Wolf | void (*bdrv_parse_filename)(const char *filename, QDict *options, Error **errp); |
89 | 030be321 | Benoît Canet | /* Drivers not implementing bdrv_parse_filename nor bdrv_open should have
|
90 | 030be321 | Benoît Canet | * this field set to true, except ones that are defined only by their
|
91 | 030be321 | Benoît Canet | * child's bs.
|
92 | 030be321 | Benoît Canet | * An example of the last type will be the quorum block driver.
|
93 | 030be321 | Benoît Canet | */
|
94 | 030be321 | Benoît Canet | bool bdrv_needs_filename;
|
95 | e971aa12 | Jeff Cody | |
96 | e971aa12 | Jeff Cody | /* For handling image reopen for split or non-split files */
|
97 | e971aa12 | Jeff Cody | int (*bdrv_reopen_prepare)(BDRVReopenState *reopen_state,
|
98 | e971aa12 | Jeff Cody | BlockReopenQueue *queue, Error **errp); |
99 | e971aa12 | Jeff Cody | void (*bdrv_reopen_commit)(BDRVReopenState *reopen_state);
|
100 | e971aa12 | Jeff Cody | void (*bdrv_reopen_abort)(BDRVReopenState *reopen_state);
|
101 | e971aa12 | Jeff Cody | |
102 | 015a1036 | Max Reitz | int (*bdrv_open)(BlockDriverState *bs, QDict *options, int flags, |
103 | 015a1036 | Max Reitz | Error **errp); |
104 | 015a1036 | Max Reitz | int (*bdrv_file_open)(BlockDriverState *bs, QDict *options, int flags, |
105 | 015a1036 | Max Reitz | Error **errp); |
106 | 5fafdf24 | ths | int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
|
107 | ea2384d3 | bellard | uint8_t *buf, int nb_sectors);
|
108 | 5fafdf24 | ths | int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
|
109 | ea2384d3 | bellard | const uint8_t *buf, int nb_sectors); |
110 | e2731add | bellard | void (*bdrv_close)(BlockDriverState *bs);
|
111 | e023b2e2 | Paolo Bonzini | void (*bdrv_rebind)(BlockDriverState *bs);
|
112 | d5124c00 | Max Reitz | int (*bdrv_create)(const char *filename, QEMUOptionParameter *options, |
113 | d5124c00 | Max Reitz | Error **errp); |
114 | ea2384d3 | bellard | int (*bdrv_set_key)(BlockDriverState *bs, const char *key); |
115 | 95389c86 | bellard | int (*bdrv_make_empty)(BlockDriverState *bs);
|
116 | 83f64091 | bellard | /* aio */
|
117 | f141eafe | aliguori | BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs, |
118 | f141eafe | aliguori | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
119 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
120 | f141eafe | aliguori | BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs, |
121 | f141eafe | aliguori | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
122 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
123 | b2e12bc6 | Christoph Hellwig | BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, |
124 | b2e12bc6 | Christoph Hellwig | BlockDriverCompletionFunc *cb, void *opaque);
|
125 | 4265d620 | Paolo Bonzini | BlockDriverAIOCB *(*bdrv_aio_discard)(BlockDriverState *bs, |
126 | 4265d620 | Paolo Bonzini | int64_t sector_num, int nb_sectors,
|
127 | 4265d620 | Paolo Bonzini | BlockDriverCompletionFunc *cb, void *opaque);
|
128 | 83f64091 | bellard | |
129 | da1fa91d | Kevin Wolf | int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
|
130 | da1fa91d | Kevin Wolf | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
|
131 | da1fa91d | Kevin Wolf | int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs,
|
132 | da1fa91d | Kevin Wolf | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
|
133 | f08f2dda | Stefan Hajnoczi | /*
|
134 | f08f2dda | Stefan Hajnoczi | * Efficiently zero a region of the disk image. Typically an image format
|
135 | f08f2dda | Stefan Hajnoczi | * would use a compact metadata representation to implement this. This
|
136 | f08f2dda | Stefan Hajnoczi | * function pointer may be NULL and .bdrv_co_writev() will be called
|
137 | f08f2dda | Stefan Hajnoczi | * instead.
|
138 | f08f2dda | Stefan Hajnoczi | */
|
139 | f08f2dda | Stefan Hajnoczi | int coroutine_fn (*bdrv_co_write_zeroes)(BlockDriverState *bs,
|
140 | aa7bfbff | Peter Lieven | int64_t sector_num, int nb_sectors, BdrvRequestFlags flags);
|
141 | 4265d620 | Paolo Bonzini | int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,
|
142 | 4265d620 | Paolo Bonzini | int64_t sector_num, int nb_sectors);
|
143 | b6b8a333 | Paolo Bonzini | int64_t coroutine_fn (*bdrv_co_get_block_status)(BlockDriverState *bs, |
144 | 376ae3f1 | Stefan Hajnoczi | int64_t sector_num, int nb_sectors, int *pnum); |
145 | da1fa91d | Kevin Wolf | |
146 | c68b89ac | Kevin Wolf | /*
|
147 | 0f15423c | Anthony Liguori | * Invalidate any cached meta-data.
|
148 | 0f15423c | Anthony Liguori | */
|
149 | 0f15423c | Anthony Liguori | void (*bdrv_invalidate_cache)(BlockDriverState *bs);
|
150 | 0f15423c | Anthony Liguori | |
151 | 0f15423c | Anthony Liguori | /*
|
152 | c68b89ac | Kevin Wolf | * Flushes all data that was already written to the OS all the way down to
|
153 | c68b89ac | Kevin Wolf | * the disk (for example raw-posix calls fsync()).
|
154 | c68b89ac | Kevin Wolf | */
|
155 | c68b89ac | Kevin Wolf | int coroutine_fn (*bdrv_co_flush_to_disk)(BlockDriverState *bs);
|
156 | c68b89ac | Kevin Wolf | |
157 | eb489bb1 | Kevin Wolf | /*
|
158 | eb489bb1 | Kevin Wolf | * Flushes all internal caches to the OS. The data may still sit in a
|
159 | eb489bb1 | Kevin Wolf | * writeback cache of the host OS, but it will survive a crash of the qemu
|
160 | eb489bb1 | Kevin Wolf | * process.
|
161 | eb489bb1 | Kevin Wolf | */
|
162 | eb489bb1 | Kevin Wolf | int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs);
|
163 | eb489bb1 | Kevin Wolf | |
164 | 83f64091 | bellard | const char *protocol_name; |
165 | 83f64091 | bellard | int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
|
166 | b94a2610 | Kevin Wolf | |
167 | 83f64091 | bellard | int64_t (*bdrv_getlength)(BlockDriverState *bs); |
168 | b94a2610 | Kevin Wolf | bool has_variable_length;
|
169 | 4a1d5e1f | Fam Zheng | int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); |
170 | b94a2610 | Kevin Wolf | |
171 | 5fafdf24 | ths | int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
|
172 | faea38e7 | bellard | const uint8_t *buf, int nb_sectors); |
173 | faea38e7 | bellard | |
174 | 5fafdf24 | ths | int (*bdrv_snapshot_create)(BlockDriverState *bs,
|
175 | faea38e7 | bellard | QEMUSnapshotInfo *sn_info); |
176 | 5fafdf24 | ths | int (*bdrv_snapshot_goto)(BlockDriverState *bs,
|
177 | faea38e7 | bellard | const char *snapshot_id); |
178 | a89d89d3 | Wenchao Xia | int (*bdrv_snapshot_delete)(BlockDriverState *bs,
|
179 | a89d89d3 | Wenchao Xia | const char *snapshot_id, |
180 | a89d89d3 | Wenchao Xia | const char *name, |
181 | a89d89d3 | Wenchao Xia | Error **errp); |
182 | 5fafdf24 | ths | int (*bdrv_snapshot_list)(BlockDriverState *bs,
|
183 | faea38e7 | bellard | QEMUSnapshotInfo **psn_info); |
184 | 51ef6727 | edison | int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
|
185 | 7b4c4781 | Wenchao Xia | const char *snapshot_id, |
186 | 7b4c4781 | Wenchao Xia | const char *name, |
187 | 7b4c4781 | Wenchao Xia | Error **errp); |
188 | faea38e7 | bellard | int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
|
189 | eae041fe | Max Reitz | ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs); |
190 | 83f64091 | bellard | |
191 | cf8074b3 | Kevin Wolf | int (*bdrv_save_vmstate)(BlockDriverState *bs, QEMUIOVector *qiov,
|
192 | cf8074b3 | Kevin Wolf | int64_t pos); |
193 | 45566e9c | Christoph Hellwig | int (*bdrv_load_vmstate)(BlockDriverState *bs, uint8_t *buf,
|
194 | 45566e9c | Christoph Hellwig | int64_t pos, int size);
|
195 | 178e08a5 | aliguori | |
196 | 756e6736 | Kevin Wolf | int (*bdrv_change_backing_file)(BlockDriverState *bs,
|
197 | 756e6736 | Kevin Wolf | const char *backing_file, const char *backing_fmt); |
198 | 756e6736 | Kevin Wolf | |
199 | 19cb3738 | bellard | /* removable device specific */
|
200 | 19cb3738 | bellard | int (*bdrv_is_inserted)(BlockDriverState *bs);
|
201 | 19cb3738 | bellard | int (*bdrv_media_changed)(BlockDriverState *bs);
|
202 | f36f3949 | Luiz Capitulino | void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); |
203 | 025e849a | Markus Armbruster | void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked); |
204 | 3b46e624 | ths | |
205 | 985a03b0 | ths | /* to control generic scsi devices */
|
206 | 985a03b0 | ths | int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf); |
207 | 221f715d | aliguori | BlockDriverAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs, |
208 | 221f715d | aliguori | unsigned long int req, void *buf, |
209 | 221f715d | aliguori | BlockDriverCompletionFunc *cb, void *opaque);
|
210 | 985a03b0 | ths | |
211 | 0e7e1989 | Kevin Wolf | /* List of options for creating images, terminated by name == NULL */
|
212 | 0e7e1989 | Kevin Wolf | QEMUOptionParameter *create_options; |
213 | 0e7e1989 | Kevin Wolf | |
214 | 5eb45639 | aliguori | |
215 | 9ac228e0 | Kevin Wolf | /*
|
216 | 9ac228e0 | Kevin Wolf | * Returns 0 for completed check, -errno for internal errors.
|
217 | 9ac228e0 | Kevin Wolf | * The check results are stored in result.
|
218 | 9ac228e0 | Kevin Wolf | */
|
219 | 4534ff54 | Kevin Wolf | int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
|
220 | 4534ff54 | Kevin Wolf | BdrvCheckMode fix); |
221 | e97fc193 | aliguori | |
222 | 6f176b48 | Max Reitz | int (*bdrv_amend_options)(BlockDriverState *bs,
|
223 | 6f176b48 | Max Reitz | QEMUOptionParameter *options); |
224 | 6f176b48 | Max Reitz | |
225 | 8b9b0cc2 | Kevin Wolf | void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
|
226 | 8b9b0cc2 | Kevin Wolf | |
227 | 41c695c7 | Kevin Wolf | /* TODO Better pass a option string/QDict/QemuOpts to add any rule? */
|
228 | 41c695c7 | Kevin Wolf | int (*bdrv_debug_breakpoint)(BlockDriverState *bs, const char *event, |
229 | 41c695c7 | Kevin Wolf | const char *tag); |
230 | 4cc70e93 | Fam Zheng | int (*bdrv_debug_remove_breakpoint)(BlockDriverState *bs,
|
231 | 4cc70e93 | Fam Zheng | const char *tag); |
232 | 41c695c7 | Kevin Wolf | int (*bdrv_debug_resume)(BlockDriverState *bs, const char *tag); |
233 | 41c695c7 | Kevin Wolf | bool (*bdrv_debug_is_suspended)(BlockDriverState *bs, const char *tag); |
234 | 41c695c7 | Kevin Wolf | |
235 | d34682cd | Kevin Wolf | int (*bdrv_refresh_limits)(BlockDriverState *bs);
|
236 | d34682cd | Kevin Wolf | |
237 | 336c1c12 | Kevin Wolf | /*
|
238 | 336c1c12 | Kevin Wolf | * Returns 1 if newly created images are guaranteed to contain only
|
239 | 336c1c12 | Kevin Wolf | * zeros, 0 otherwise.
|
240 | 336c1c12 | Kevin Wolf | */
|
241 | 336c1c12 | Kevin Wolf | int (*bdrv_has_zero_init)(BlockDriverState *bs);
|
242 | 12c09b8c | Kevin Wolf | |
243 | 8a22f02a | Stefan Hajnoczi | QLIST_ENTRY(BlockDriver) list; |
244 | ea2384d3 | bellard | }; |
245 | ea2384d3 | bellard | |
246 | fe81c2cc | Peter Lieven | typedef struct BlockLimits { |
247 | fe81c2cc | Peter Lieven | /* maximum number of sectors that can be discarded at once */
|
248 | fe81c2cc | Peter Lieven | int max_discard;
|
249 | fe81c2cc | Peter Lieven | |
250 | fe81c2cc | Peter Lieven | /* optimal alignment for discard requests in sectors */
|
251 | fe81c2cc | Peter Lieven | int64_t discard_alignment; |
252 | fe81c2cc | Peter Lieven | |
253 | fe81c2cc | Peter Lieven | /* maximum number of sectors that can zeroized at once */
|
254 | fe81c2cc | Peter Lieven | int max_write_zeroes;
|
255 | fe81c2cc | Peter Lieven | |
256 | fe81c2cc | Peter Lieven | /* optimal alignment for write zeroes requests in sectors */
|
257 | fe81c2cc | Peter Lieven | int64_t write_zeroes_alignment; |
258 | 7337acaf | Peter Lieven | |
259 | 7337acaf | Peter Lieven | /* optimal transfer length in sectors */
|
260 | 7337acaf | Peter Lieven | int opt_transfer_length;
|
261 | 339064d5 | Kevin Wolf | |
262 | 339064d5 | Kevin Wolf | /* memory alignment so that no bounce buffer is needed */
|
263 | 339064d5 | Kevin Wolf | size_t opt_mem_alignment; |
264 | fe81c2cc | Peter Lieven | } BlockLimits; |
265 | fe81c2cc | Peter Lieven | |
266 | 8802d1fd | Jeff Cody | /*
|
267 | 8802d1fd | Jeff Cody | * Note: the function bdrv_append() copies and swaps contents of
|
268 | 8802d1fd | Jeff Cody | * BlockDriverStates, so if you add new fields to this struct, please
|
269 | 8802d1fd | Jeff Cody | * inspect bdrv_append() to determine if the new fields need to be
|
270 | 8802d1fd | Jeff Cody | * copied as well.
|
271 | 8802d1fd | Jeff Cody | */
|
272 | ea2384d3 | bellard | struct BlockDriverState {
|
273 | d15a771d | bellard | int64_t total_sectors; /* if we are reading a disk image, give its
|
274 | d15a771d | bellard | size in sectors */
|
275 | ea2384d3 | bellard | int read_only; /* if true, the media is read only */ |
276 | 4dca4b63 | Naphtali Sprei | int open_flags; /* flags used to open the file, re-used for re-open */ |
277 | ea2384d3 | bellard | int encrypted; /* if true, the media is encrypted */ |
278 | c0f4ce77 | aliguori | int valid_key; /* if true, a valid encryption key has been set */ |
279 | 985a03b0 | ths | int sg; /* if true, the device is a /dev/sg* */ |
280 | 53fec9d3 | Stefan Hajnoczi | int copy_on_read; /* if true, copy read backing sectors into image |
281 | 53fec9d3 | Stefan Hajnoczi | note this is a reference count */
|
282 | ea2384d3 | bellard | |
283 | 19cb3738 | bellard | BlockDriver *drv; /* NULL means no media */
|
284 | ea2384d3 | bellard | void *opaque;
|
285 | ea2384d3 | bellard | |
286 | fa879d62 | Markus Armbruster | void *dev; /* attached device model, if any */ |
287 | fa879d62 | Markus Armbruster | /* TODO change to DeviceState when all users are qdevified */
|
288 | 0e49de52 | Markus Armbruster | const BlockDevOps *dev_ops;
|
289 | 0e49de52 | Markus Armbruster | void *dev_opaque;
|
290 | 18846dee | Markus Armbruster | |
291 | ea2384d3 | bellard | char filename[1024]; |
292 | ea2384d3 | bellard | char backing_file[1024]; /* if non zero, the image is a diff of |
293 | ea2384d3 | bellard | this file image */
|
294 | 5eb45639 | aliguori | char backing_format[16]; /* if non-zero and backing_file exists */ |
295 | ea2384d3 | bellard | int is_temporary;
|
296 | 19cb3738 | bellard | |
297 | ea2384d3 | bellard | BlockDriverState *backing_hd; |
298 | 66f82cee | Kevin Wolf | BlockDriverState *file; |
299 | 66f82cee | Kevin Wolf | |
300 | d7d512f6 | Paolo Bonzini | NotifierList close_notifiers; |
301 | d7d512f6 | Paolo Bonzini | |
302 | d616b224 | Stefan Hajnoczi | /* Callback before write request is processed */
|
303 | d616b224 | Stefan Hajnoczi | NotifierWithReturnList before_write_notifiers; |
304 | d616b224 | Stefan Hajnoczi | |
305 | 470c0504 | Stefan Hajnoczi | /* number of in-flight copy-on-read requests */
|
306 | 470c0504 | Stefan Hajnoczi | unsigned int copy_on_read_in_flight; |
307 | 470c0504 | Stefan Hajnoczi | |
308 | cc0681c4 | Benoît Canet | /* I/O throttling */
|
309 | cc0681c4 | Benoît Canet | ThrottleState throttle_state; |
310 | cc0681c4 | Benoît Canet | CoQueue throttled_reqs[2];
|
311 | 0563e191 | Zhi Yong Wu | bool io_limits_enabled;
|
312 | 0563e191 | Zhi Yong Wu | |
313 | a36e69dd | ths | /* I/O stats (display with "info blockstats"). */
|
314 | a597e79c | Christoph Hellwig | uint64_t nr_bytes[BDRV_MAX_IOTYPE]; |
315 | a597e79c | Christoph Hellwig | uint64_t nr_ops[BDRV_MAX_IOTYPE]; |
316 | c488c7f6 | Christoph Hellwig | uint64_t total_time_ns[BDRV_MAX_IOTYPE]; |
317 | 294cc35f | Kevin Wolf | uint64_t wr_highest_sector; |
318 | a36e69dd | ths | |
319 | fe81c2cc | Peter Lieven | /* I/O Limits */
|
320 | fe81c2cc | Peter Lieven | BlockLimits bl; |
321 | fe81c2cc | Peter Lieven | |
322 | 71d0770c | aliguori | /* Whether the disk can expand beyond total_sectors */
|
323 | 71d0770c | aliguori | int growable;
|
324 | 71d0770c | aliguori | |
325 | 0d51b4de | Asias He | /* Whether produces zeros when read beyond eof */
|
326 | 0d51b4de | Asias He | bool zero_beyond_eof;
|
327 | 0d51b4de | Asias He | |
328 | c25f53b0 | Paolo Bonzini | /* Alignment requirement for offset/length of I/O requests */
|
329 | c25f53b0 | Paolo Bonzini | unsigned int request_alignment; |
330 | c25f53b0 | Paolo Bonzini | |
331 | 1b7fd729 | Paolo Bonzini | /* the block size for which the guest device expects atomicity */
|
332 | 1b7fd729 | Paolo Bonzini | int guest_block_size;
|
333 | e268ca52 | aliguori | |
334 | e900a7b7 | Christoph Hellwig | /* do we need to tell the quest if we have a volatile write cache? */
|
335 | e900a7b7 | Christoph Hellwig | int enable_write_cache;
|
336 | e900a7b7 | Christoph Hellwig | |
337 | ea2384d3 | bellard | /* NOTE: the following infos are only hints for real hardware
|
338 | ea2384d3 | bellard | drivers. They are not used by the block driver */
|
339 | ff06f5f3 | Paolo Bonzini | BlockdevOnError on_read_error, on_write_error; |
340 | d6bf279e | Luiz Capitulino | bool iostatus_enabled;
|
341 | b2023818 | Luiz Capitulino | BlockDeviceIoStatus iostatus; |
342 | dc364f4c | Benoît Canet | |
343 | dc364f4c | Benoît Canet | /* the following member gives a name to every node on the bs graph. */
|
344 | dc364f4c | Benoît Canet | char node_name[32]; |
345 | dc364f4c | Benoît Canet | /* element of the list of named nodes building the graph */
|
346 | dc364f4c | Benoît Canet | QTAILQ_ENTRY(BlockDriverState) node_list; |
347 | dc364f4c | Benoît Canet | /* Device name is the name associated with the "drive" the guest sees */
|
348 | ea2384d3 | bellard | char device_name[32]; |
349 | dc364f4c | Benoît Canet | /* element of the list of "drives" the guest sees */
|
350 | dc364f4c | Benoît Canet | QTAILQ_ENTRY(BlockDriverState) device_list; |
351 | e4654d2d | Fam Zheng | QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; |
352 | 9fcb0251 | Fam Zheng | int refcnt;
|
353 | db593f25 | Marcelo Tosatti | int in_use; /* users other than guest access, eg. block migration */ |
354 | dbffbdcf | Stefan Hajnoczi | |
355 | dbffbdcf | Stefan Hajnoczi | QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; |
356 | eeec61f2 | Stefan Hajnoczi | |
357 | eeec61f2 | Stefan Hajnoczi | /* long-running background operation */
|
358 | eeec61f2 | Stefan Hajnoczi | BlockJob *job; |
359 | e971aa12 | Jeff Cody | |
360 | de9c0cec | Kevin Wolf | QDict *options; |
361 | ea2384d3 | bellard | }; |
362 | ea2384d3 | bellard | |
363 | eba25057 | Jim Meyering | int get_tmp_filename(char *filename, int size); |
364 | 95389c86 | bellard | |
365 | 0563e191 | Zhi Yong Wu | void bdrv_set_io_limits(BlockDriverState *bs,
|
366 | cc0681c4 | Benoît Canet | ThrottleConfig *cfg); |
367 | cc0681c4 | Benoît Canet | |
368 | 0563e191 | Zhi Yong Wu | |
369 | 85d126f3 | Stefan Hajnoczi | /**
|
370 | d616b224 | Stefan Hajnoczi | * bdrv_add_before_write_notifier:
|
371 | d616b224 | Stefan Hajnoczi | *
|
372 | d616b224 | Stefan Hajnoczi | * Register a callback that is invoked before write requests are processed but
|
373 | d616b224 | Stefan Hajnoczi | * after any throttling or waiting for overlapping requests.
|
374 | d616b224 | Stefan Hajnoczi | */
|
375 | d616b224 | Stefan Hajnoczi | void bdrv_add_before_write_notifier(BlockDriverState *bs,
|
376 | d616b224 | Stefan Hajnoczi | NotifierWithReturn *notifier); |
377 | d616b224 | Stefan Hajnoczi | |
378 | d616b224 | Stefan Hajnoczi | /**
|
379 | 85d126f3 | Stefan Hajnoczi | * bdrv_get_aio_context:
|
380 | 85d126f3 | Stefan Hajnoczi | *
|
381 | 85d126f3 | Stefan Hajnoczi | * Returns: the currently bound #AioContext
|
382 | 85d126f3 | Stefan Hajnoczi | */
|
383 | 85d126f3 | Stefan Hajnoczi | AioContext *bdrv_get_aio_context(BlockDriverState *bs); |
384 | 85d126f3 | Stefan Hajnoczi | |
385 | 508c7cb3 | Christoph Hellwig | #ifdef _WIN32
|
386 | 508c7cb3 | Christoph Hellwig | int is_windows_drive(const char *filename); |
387 | 508c7cb3 | Christoph Hellwig | #endif
|
388 | 32c81a4a | Paolo Bonzini | void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, |
389 | 32c81a4a | Paolo Bonzini | enum MonitorEvent ev,
|
390 | 32c81a4a | Paolo Bonzini | BlockErrorAction action, bool is_read);
|
391 | 508c7cb3 | Christoph Hellwig | |
392 | dc534f8f | Paolo Bonzini | /**
|
393 | dc534f8f | Paolo Bonzini | * stream_start:
|
394 | dc534f8f | Paolo Bonzini | * @bs: Block device to operate on.
|
395 | dc534f8f | Paolo Bonzini | * @base: Block device that will become the new base, or %NULL to
|
396 | dc534f8f | Paolo Bonzini | * flatten the whole backing file chain onto @bs.
|
397 | dc534f8f | Paolo Bonzini | * @base_id: The file name that will be written to @bs as the new
|
398 | dc534f8f | Paolo Bonzini | * backing file if the job completes. Ignored if @base is %NULL.
|
399 | c83c66c3 | Stefan Hajnoczi | * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
|
400 | 1d809098 | Paolo Bonzini | * @on_error: The action to take upon error.
|
401 | dc534f8f | Paolo Bonzini | * @cb: Completion function for the job.
|
402 | dc534f8f | Paolo Bonzini | * @opaque: Opaque pointer value passed to @cb.
|
403 | fd7f8c65 | Stefan Hajnoczi | * @errp: Error object.
|
404 | dc534f8f | Paolo Bonzini | *
|
405 | dc534f8f | Paolo Bonzini | * Start a streaming operation on @bs. Clusters that are unallocated
|
406 | dc534f8f | Paolo Bonzini | * in @bs, but allocated in any image between @base and @bs (both
|
407 | dc534f8f | Paolo Bonzini | * exclusive) will be written to @bs. At the end of a successful
|
408 | dc534f8f | Paolo Bonzini | * streaming job, the backing file of @bs will be changed to
|
409 | dc534f8f | Paolo Bonzini | * @base_id in the written image and to @base in the live BlockDriverState.
|
410 | dc534f8f | Paolo Bonzini | */
|
411 | fd7f8c65 | Stefan Hajnoczi | void stream_start(BlockDriverState *bs, BlockDriverState *base,
|
412 | 1d809098 | Paolo Bonzini | const char *base_id, int64_t speed, BlockdevOnError on_error, |
413 | c83c66c3 | Stefan Hajnoczi | BlockDriverCompletionFunc *cb, |
414 | fd7f8c65 | Stefan Hajnoczi | void *opaque, Error **errp);
|
415 | 4f1043b4 | Stefan Hajnoczi | |
416 | 747ff602 | Jeff Cody | /**
|
417 | 747ff602 | Jeff Cody | * commit_start:
|
418 | 03544a6e | Fam Zheng | * @bs: Active block device.
|
419 | 03544a6e | Fam Zheng | * @top: Top block device to be committed.
|
420 | 03544a6e | Fam Zheng | * @base: Block device that will be written into, and become the new top.
|
421 | 747ff602 | Jeff Cody | * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
|
422 | 747ff602 | Jeff Cody | * @on_error: The action to take upon error.
|
423 | 747ff602 | Jeff Cody | * @cb: Completion function for the job.
|
424 | 747ff602 | Jeff Cody | * @opaque: Opaque pointer value passed to @cb.
|
425 | 747ff602 | Jeff Cody | * @errp: Error object.
|
426 | 747ff602 | Jeff Cody | *
|
427 | 747ff602 | Jeff Cody | */
|
428 | 747ff602 | Jeff Cody | void commit_start(BlockDriverState *bs, BlockDriverState *base,
|
429 | 747ff602 | Jeff Cody | BlockDriverState *top, int64_t speed, |
430 | 92aa5c6d | Paolo Bonzini | BlockdevOnError on_error, BlockDriverCompletionFunc *cb, |
431 | 747ff602 | Jeff Cody | void *opaque, Error **errp);
|
432 | 03544a6e | Fam Zheng | /**
|
433 | 03544a6e | Fam Zheng | * commit_active_start:
|
434 | 03544a6e | Fam Zheng | * @bs: Active block device to be committed.
|
435 | 03544a6e | Fam Zheng | * @base: Block device that will be written into, and become the new top.
|
436 | 03544a6e | Fam Zheng | * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
|
437 | 03544a6e | Fam Zheng | * @on_error: The action to take upon error.
|
438 | 03544a6e | Fam Zheng | * @cb: Completion function for the job.
|
439 | 03544a6e | Fam Zheng | * @opaque: Opaque pointer value passed to @cb.
|
440 | 03544a6e | Fam Zheng | * @errp: Error object.
|
441 | 03544a6e | Fam Zheng | *
|
442 | 03544a6e | Fam Zheng | */
|
443 | 03544a6e | Fam Zheng | void commit_active_start(BlockDriverState *bs, BlockDriverState *base,
|
444 | 03544a6e | Fam Zheng | int64_t speed, |
445 | 03544a6e | Fam Zheng | BlockdevOnError on_error, |
446 | 03544a6e | Fam Zheng | BlockDriverCompletionFunc *cb, |
447 | 03544a6e | Fam Zheng | void *opaque, Error **errp);
|
448 | 893f7eba | Paolo Bonzini | /*
|
449 | 893f7eba | Paolo Bonzini | * mirror_start:
|
450 | 893f7eba | Paolo Bonzini | * @bs: Block device to operate on.
|
451 | 893f7eba | Paolo Bonzini | * @target: Block device to write to.
|
452 | 893f7eba | Paolo Bonzini | * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
|
453 | eee13dfe | Paolo Bonzini | * @granularity: The chosen granularity for the dirty bitmap.
|
454 | 08e4ed6c | Paolo Bonzini | * @buf_size: The amount of data that can be in flight at one time.
|
455 | 893f7eba | Paolo Bonzini | * @mode: Whether to collapse all images in the chain to the target.
|
456 | b952b558 | Paolo Bonzini | * @on_source_error: The action to take upon error reading from the source.
|
457 | b952b558 | Paolo Bonzini | * @on_target_error: The action to take upon error writing to the target.
|
458 | 893f7eba | Paolo Bonzini | * @cb: Completion function for the job.
|
459 | 893f7eba | Paolo Bonzini | * @opaque: Opaque pointer value passed to @cb.
|
460 | 893f7eba | Paolo Bonzini | * @errp: Error object.
|
461 | 893f7eba | Paolo Bonzini | *
|
462 | 893f7eba | Paolo Bonzini | * Start a mirroring operation on @bs. Clusters that are allocated
|
463 | 893f7eba | Paolo Bonzini | * in @bs will be written to @bs until the job is cancelled or
|
464 | 893f7eba | Paolo Bonzini | * manually completed. At the end of a successful mirroring job,
|
465 | 893f7eba | Paolo Bonzini | * @bs will be switched to read from @target.
|
466 | 893f7eba | Paolo Bonzini | */
|
467 | 893f7eba | Paolo Bonzini | void mirror_start(BlockDriverState *bs, BlockDriverState *target,
|
468 | 08e4ed6c | Paolo Bonzini | int64_t speed, int64_t granularity, int64_t buf_size, |
469 | 08e4ed6c | Paolo Bonzini | MirrorSyncMode mode, BlockdevOnError on_source_error, |
470 | b952b558 | Paolo Bonzini | BlockdevOnError on_target_error, |
471 | 893f7eba | Paolo Bonzini | BlockDriverCompletionFunc *cb, |
472 | 893f7eba | Paolo Bonzini | void *opaque, Error **errp);
|
473 | 893f7eba | Paolo Bonzini | |
474 | 98d2c6f2 | Dietmar Maurer | /*
|
475 | 98d2c6f2 | Dietmar Maurer | * backup_start:
|
476 | 98d2c6f2 | Dietmar Maurer | * @bs: Block device to operate on.
|
477 | 98d2c6f2 | Dietmar Maurer | * @target: Block device to write to.
|
478 | 98d2c6f2 | Dietmar Maurer | * @speed: The maximum speed, in bytes per second, or 0 for unlimited.
|
479 | fc5d3f84 | Ian Main | * @sync_mode: What parts of the disk image should be copied to the destination.
|
480 | 98d2c6f2 | Dietmar Maurer | * @on_source_error: The action to take upon error reading from the source.
|
481 | 98d2c6f2 | Dietmar Maurer | * @on_target_error: The action to take upon error writing to the target.
|
482 | 98d2c6f2 | Dietmar Maurer | * @cb: Completion function for the job.
|
483 | 98d2c6f2 | Dietmar Maurer | * @opaque: Opaque pointer value passed to @cb.
|
484 | 98d2c6f2 | Dietmar Maurer | *
|
485 | 98d2c6f2 | Dietmar Maurer | * Start a backup operation on @bs. Clusters in @bs are written to @target
|
486 | 98d2c6f2 | Dietmar Maurer | * until the job is cancelled or manually completed.
|
487 | 98d2c6f2 | Dietmar Maurer | */
|
488 | 98d2c6f2 | Dietmar Maurer | void backup_start(BlockDriverState *bs, BlockDriverState *target,
|
489 | fc5d3f84 | Ian Main | int64_t speed, MirrorSyncMode sync_mode, |
490 | fc5d3f84 | Ian Main | BlockdevOnError on_source_error, |
491 | 98d2c6f2 | Dietmar Maurer | BlockdevOnError on_target_error, |
492 | 98d2c6f2 | Dietmar Maurer | BlockDriverCompletionFunc *cb, void *opaque,
|
493 | 98d2c6f2 | Dietmar Maurer | Error **errp); |
494 | 98d2c6f2 | Dietmar Maurer | |
495 | ea2384d3 | bellard | #endif /* BLOCK_INT_H */ |