root / block_int.h @ 18ebcc86
History | View | Annotate | Download (9 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 | faf07963 | pbrook | #include "block.h" |
28 | 0e7e1989 | Kevin Wolf | #include "qemu-option.h" |
29 | 1b7bdbc1 | Stefan Hajnoczi | #include "qemu-queue.h" |
30 | da1fa91d | Kevin Wolf | #include "qemu-coroutine.h" |
31 | c488c7f6 | Christoph Hellwig | #include "qemu-timer.h" |
32 | b2023818 | Luiz Capitulino | #include "qapi-types.h" |
33 | faf07963 | pbrook | |
34 | ec36ba14 | ths | #define BLOCK_FLAG_ENCRYPT 1 |
35 | ec36ba14 | ths | #define BLOCK_FLAG_COMPAT6 4 |
36 | ec36ba14 | ths | |
37 | 0e7e1989 | Kevin Wolf | #define BLOCK_OPT_SIZE "size" |
38 | 0e7e1989 | Kevin Wolf | #define BLOCK_OPT_ENCRYPT "encryption" |
39 | 0e7e1989 | Kevin Wolf | #define BLOCK_OPT_COMPAT6 "compat6" |
40 | 0e7e1989 | Kevin Wolf | #define BLOCK_OPT_BACKING_FILE "backing_file" |
41 | 0e7e1989 | Kevin Wolf | #define BLOCK_OPT_BACKING_FMT "backing_fmt" |
42 | 73c632ed | Kevin Wolf | #define BLOCK_OPT_CLUSTER_SIZE "cluster_size" |
43 | 75411d23 | Stefan Hajnoczi | #define BLOCK_OPT_TABLE_SIZE "table_size" |
44 | a35e1c17 | Kevin Wolf | #define BLOCK_OPT_PREALLOC "preallocation" |
45 | f66fd6c3 | Fam Zheng | #define BLOCK_OPT_SUBFMT "subformat" |
46 | 0e7e1989 | Kevin Wolf | |
47 | 6bbff9a0 | aliguori | typedef struct AIOPool { |
48 | 6bbff9a0 | aliguori | void (*cancel)(BlockDriverAIOCB *acb);
|
49 | 6bbff9a0 | aliguori | int aiocb_size;
|
50 | 6bbff9a0 | aliguori | BlockDriverAIOCB *free_aiocb; |
51 | 6bbff9a0 | aliguori | } AIOPool; |
52 | 6bbff9a0 | aliguori | |
53 | ea2384d3 | bellard | struct BlockDriver {
|
54 | ea2384d3 | bellard | const char *format_name; |
55 | ea2384d3 | bellard | int instance_size;
|
56 | ea2384d3 | bellard | int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); |
57 | 508c7cb3 | Christoph Hellwig | int (*bdrv_probe_device)(const char *filename); |
58 | 66f82cee | Kevin Wolf | int (*bdrv_open)(BlockDriverState *bs, int flags); |
59 | 66f82cee | Kevin Wolf | int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, int flags); |
60 | 5fafdf24 | ths | int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
|
61 | ea2384d3 | bellard | uint8_t *buf, int nb_sectors);
|
62 | 5fafdf24 | ths | int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
|
63 | ea2384d3 | bellard | const uint8_t *buf, int nb_sectors); |
64 | e2731add | bellard | void (*bdrv_close)(BlockDriverState *bs);
|
65 | 0e7e1989 | Kevin Wolf | int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); |
66 | ea2384d3 | bellard | int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
|
67 | ea2384d3 | bellard | int nb_sectors, int *pnum); |
68 | ea2384d3 | bellard | int (*bdrv_set_key)(BlockDriverState *bs, const char *key); |
69 | 95389c86 | bellard | int (*bdrv_make_empty)(BlockDriverState *bs);
|
70 | 83f64091 | bellard | /* aio */
|
71 | f141eafe | aliguori | BlockDriverAIOCB *(*bdrv_aio_readv)(BlockDriverState *bs, |
72 | f141eafe | aliguori | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
73 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
74 | f141eafe | aliguori | BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs, |
75 | f141eafe | aliguori | int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
|
76 | ce1a14dc | pbrook | BlockDriverCompletionFunc *cb, void *opaque);
|
77 | b2e12bc6 | Christoph Hellwig | BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, |
78 | b2e12bc6 | Christoph Hellwig | BlockDriverCompletionFunc *cb, void *opaque);
|
79 | 4265d620 | Paolo Bonzini | BlockDriverAIOCB *(*bdrv_aio_discard)(BlockDriverState *bs, |
80 | 4265d620 | Paolo Bonzini | int64_t sector_num, int nb_sectors,
|
81 | 4265d620 | Paolo Bonzini | BlockDriverCompletionFunc *cb, void *opaque);
|
82 | 83f64091 | bellard | |
83 | da1fa91d | Kevin Wolf | int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs,
|
84 | da1fa91d | Kevin Wolf | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
|
85 | da1fa91d | Kevin Wolf | int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs,
|
86 | da1fa91d | Kevin Wolf | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
|
87 | 07f07615 | Paolo Bonzini | int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs);
|
88 | 4265d620 | Paolo Bonzini | int coroutine_fn (*bdrv_co_discard)(BlockDriverState *bs,
|
89 | 4265d620 | Paolo Bonzini | int64_t sector_num, int nb_sectors);
|
90 | da1fa91d | Kevin Wolf | |
91 | 40b4f539 | Kevin Wolf | int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs,
|
92 | 40b4f539 | Kevin Wolf | int num_reqs);
|
93 | 40b4f539 | Kevin Wolf | int (*bdrv_merge_requests)(BlockDriverState *bs, BlockRequest* a,
|
94 | 40b4f539 | Kevin Wolf | BlockRequest *b); |
95 | 40b4f539 | Kevin Wolf | |
96 | 40b4f539 | Kevin Wolf | |
97 | 83f64091 | bellard | const char *protocol_name; |
98 | 83f64091 | bellard | int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset);
|
99 | 83f64091 | bellard | int64_t (*bdrv_getlength)(BlockDriverState *bs); |
100 | 4a1d5e1f | Fam Zheng | int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); |
101 | 5fafdf24 | ths | int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
|
102 | faea38e7 | bellard | const uint8_t *buf, int nb_sectors); |
103 | faea38e7 | bellard | |
104 | 5fafdf24 | ths | int (*bdrv_snapshot_create)(BlockDriverState *bs,
|
105 | faea38e7 | bellard | QEMUSnapshotInfo *sn_info); |
106 | 5fafdf24 | ths | int (*bdrv_snapshot_goto)(BlockDriverState *bs,
|
107 | faea38e7 | bellard | const char *snapshot_id); |
108 | faea38e7 | bellard | int (*bdrv_snapshot_delete)(BlockDriverState *bs, const char *snapshot_id); |
109 | 5fafdf24 | ths | int (*bdrv_snapshot_list)(BlockDriverState *bs,
|
110 | faea38e7 | bellard | QEMUSnapshotInfo **psn_info); |
111 | 51ef6727 | edison | int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs,
|
112 | 51ef6727 | edison | const char *snapshot_name); |
113 | faea38e7 | bellard | int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi);
|
114 | 83f64091 | bellard | |
115 | 45566e9c | Christoph Hellwig | int (*bdrv_save_vmstate)(BlockDriverState *bs, const uint8_t *buf, |
116 | 45566e9c | Christoph Hellwig | int64_t pos, int size);
|
117 | 45566e9c | Christoph Hellwig | int (*bdrv_load_vmstate)(BlockDriverState *bs, uint8_t *buf,
|
118 | 45566e9c | Christoph Hellwig | int64_t pos, int size);
|
119 | 178e08a5 | aliguori | |
120 | 756e6736 | Kevin Wolf | int (*bdrv_change_backing_file)(BlockDriverState *bs,
|
121 | 756e6736 | Kevin Wolf | const char *backing_file, const char *backing_fmt); |
122 | 756e6736 | Kevin Wolf | |
123 | 19cb3738 | bellard | /* removable device specific */
|
124 | 19cb3738 | bellard | int (*bdrv_is_inserted)(BlockDriverState *bs);
|
125 | 19cb3738 | bellard | int (*bdrv_media_changed)(BlockDriverState *bs);
|
126 | 822e1cd1 | Markus Armbruster | void (*bdrv_eject)(BlockDriverState *bs, int eject_flag); |
127 | 025e849a | Markus Armbruster | void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked); |
128 | 3b46e624 | ths | |
129 | 985a03b0 | ths | /* to control generic scsi devices */
|
130 | 985a03b0 | ths | int (*bdrv_ioctl)(BlockDriverState *bs, unsigned long int req, void *buf); |
131 | 221f715d | aliguori | BlockDriverAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs, |
132 | 221f715d | aliguori | unsigned long int req, void *buf, |
133 | 221f715d | aliguori | BlockDriverCompletionFunc *cb, void *opaque);
|
134 | 985a03b0 | ths | |
135 | 0e7e1989 | Kevin Wolf | /* List of options for creating images, terminated by name == NULL */
|
136 | 0e7e1989 | Kevin Wolf | QEMUOptionParameter *create_options; |
137 | 0e7e1989 | Kevin Wolf | |
138 | 5eb45639 | aliguori | |
139 | 9ac228e0 | Kevin Wolf | /*
|
140 | 9ac228e0 | Kevin Wolf | * Returns 0 for completed check, -errno for internal errors.
|
141 | 9ac228e0 | Kevin Wolf | * The check results are stored in result.
|
142 | 9ac228e0 | Kevin Wolf | */
|
143 | 9ac228e0 | Kevin Wolf | int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result);
|
144 | e97fc193 | aliguori | |
145 | 8b9b0cc2 | Kevin Wolf | void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
|
146 | 8b9b0cc2 | Kevin Wolf | |
147 | 336c1c12 | Kevin Wolf | /*
|
148 | 336c1c12 | Kevin Wolf | * Returns 1 if newly created images are guaranteed to contain only
|
149 | 336c1c12 | Kevin Wolf | * zeros, 0 otherwise.
|
150 | 336c1c12 | Kevin Wolf | */
|
151 | 336c1c12 | Kevin Wolf | int (*bdrv_has_zero_init)(BlockDriverState *bs);
|
152 | 12c09b8c | Kevin Wolf | |
153 | 8a22f02a | Stefan Hajnoczi | QLIST_ENTRY(BlockDriver) list; |
154 | ea2384d3 | bellard | }; |
155 | ea2384d3 | bellard | |
156 | ea2384d3 | bellard | struct BlockDriverState {
|
157 | d15a771d | bellard | int64_t total_sectors; /* if we are reading a disk image, give its
|
158 | d15a771d | bellard | size in sectors */
|
159 | ea2384d3 | bellard | int read_only; /* if true, the media is read only */ |
160 | 4dca4b63 | Naphtali Sprei | int keep_read_only; /* if true, the media was requested to stay read only */ |
161 | 4dca4b63 | Naphtali Sprei | int open_flags; /* flags used to open the file, re-used for re-open */ |
162 | ea2384d3 | bellard | int encrypted; /* if true, the media is encrypted */ |
163 | c0f4ce77 | aliguori | int valid_key; /* if true, a valid encryption key has been set */ |
164 | 985a03b0 | ths | int sg; /* if true, the device is a /dev/sg* */ |
165 | ea2384d3 | bellard | |
166 | 19cb3738 | bellard | BlockDriver *drv; /* NULL means no media */
|
167 | ea2384d3 | bellard | void *opaque;
|
168 | ea2384d3 | bellard | |
169 | fa879d62 | Markus Armbruster | void *dev; /* attached device model, if any */ |
170 | fa879d62 | Markus Armbruster | /* TODO change to DeviceState when all users are qdevified */
|
171 | 0e49de52 | Markus Armbruster | const BlockDevOps *dev_ops;
|
172 | 0e49de52 | Markus Armbruster | void *dev_opaque;
|
173 | 18846dee | Markus Armbruster | |
174 | ea2384d3 | bellard | char filename[1024]; |
175 | ea2384d3 | bellard | char backing_file[1024]; /* if non zero, the image is a diff of |
176 | ea2384d3 | bellard | this file image */
|
177 | 5eb45639 | aliguori | char backing_format[16]; /* if non-zero and backing_file exists */ |
178 | ea2384d3 | bellard | int is_temporary;
|
179 | 19cb3738 | bellard | |
180 | ea2384d3 | bellard | BlockDriverState *backing_hd; |
181 | 66f82cee | Kevin Wolf | BlockDriverState *file; |
182 | 66f82cee | Kevin Wolf | |
183 | ce1a14dc | pbrook | /* async read/write emulation */
|
184 | 83f64091 | bellard | |
185 | ce1a14dc | pbrook | void *sync_aiocb;
|
186 | 3b46e624 | ths | |
187 | a36e69dd | ths | /* I/O stats (display with "info blockstats"). */
|
188 | a597e79c | Christoph Hellwig | uint64_t nr_bytes[BDRV_MAX_IOTYPE]; |
189 | a597e79c | Christoph Hellwig | uint64_t nr_ops[BDRV_MAX_IOTYPE]; |
190 | c488c7f6 | Christoph Hellwig | uint64_t total_time_ns[BDRV_MAX_IOTYPE]; |
191 | 294cc35f | Kevin Wolf | uint64_t wr_highest_sector; |
192 | a36e69dd | ths | |
193 | 71d0770c | aliguori | /* Whether the disk can expand beyond total_sectors */
|
194 | 71d0770c | aliguori | int growable;
|
195 | 71d0770c | aliguori | |
196 | e268ca52 | aliguori | /* the memory alignment required for the buffers handled by this driver */
|
197 | e268ca52 | aliguori | int buffer_alignment;
|
198 | e268ca52 | aliguori | |
199 | e900a7b7 | Christoph Hellwig | /* do we need to tell the quest if we have a volatile write cache? */
|
200 | e900a7b7 | Christoph Hellwig | int enable_write_cache;
|
201 | e900a7b7 | Christoph Hellwig | |
202 | ea2384d3 | bellard | /* NOTE: the following infos are only hints for real hardware
|
203 | ea2384d3 | bellard | drivers. They are not used by the block driver */
|
204 | 46d4767d | bellard | int cyls, heads, secs, translation;
|
205 | abd7f68d | Markus Armbruster | BlockErrorAction on_read_error, on_write_error; |
206 | d6bf279e | Luiz Capitulino | bool iostatus_enabled;
|
207 | b2023818 | Luiz Capitulino | BlockDeviceIoStatus iostatus; |
208 | ea2384d3 | bellard | char device_name[32]; |
209 | c6d22830 | Jan Kiszka | unsigned long *dirty_bitmap; |
210 | aaa0eb75 | Liran Schour | int64_t dirty_count; |
211 | db593f25 | Marcelo Tosatti | int in_use; /* users other than guest access, eg. block migration */ |
212 | 1b7bdbc1 | Stefan Hajnoczi | QTAILQ_ENTRY(BlockDriverState) list; |
213 | b0a7b120 | aliguori | void *private;
|
214 | ea2384d3 | bellard | }; |
215 | ea2384d3 | bellard | |
216 | 83f64091 | bellard | struct BlockDriverAIOCB {
|
217 | 6bbff9a0 | aliguori | AIOPool *pool; |
218 | 83f64091 | bellard | BlockDriverState *bs; |
219 | 83f64091 | bellard | BlockDriverCompletionFunc *cb; |
220 | ce1a14dc | pbrook | void *opaque;
|
221 | ce1a14dc | pbrook | BlockDriverAIOCB *next; |
222 | 83f64091 | bellard | }; |
223 | 83f64091 | bellard | |
224 | 95389c86 | bellard | void get_tmp_filename(char *filename, int size); |
225 | 95389c86 | bellard | |
226 | c16b5a2c | Christoph Hellwig | void *qemu_aio_get(AIOPool *pool, BlockDriverState *bs,
|
227 | c16b5a2c | Christoph Hellwig | BlockDriverCompletionFunc *cb, void *opaque);
|
228 | ce1a14dc | pbrook | void qemu_aio_release(void *p); |
229 | ce1a14dc | pbrook | |
230 | 508c7cb3 | Christoph Hellwig | #ifdef _WIN32
|
231 | 508c7cb3 | Christoph Hellwig | int is_windows_drive(const char *filename); |
232 | 508c7cb3 | Christoph Hellwig | #endif
|
233 | 508c7cb3 | Christoph Hellwig | |
234 | ea2384d3 | bellard | #endif /* BLOCK_INT_H */ |