root / block.h @ c48c6522
History | View | Annotate | Download (18.1 kB)
1 | faf07963 | pbrook | #ifndef BLOCK_H
|
---|---|---|---|
2 | faf07963 | pbrook | #define BLOCK_H
|
3 | faf07963 | pbrook | |
4 | a76bab49 | aliguori | #include "qemu-aio.h" |
5 | 3b69e4b9 | aliguori | #include "qemu-common.h" |
6 | 0e7e1989 | Kevin Wolf | #include "qemu-option.h" |
7 | da1fa91d | Kevin Wolf | #include "qemu-coroutine.h" |
8 | d15e5465 | Luiz Capitulino | #include "qobject.h" |
9 | a76bab49 | aliguori | |
10 | faf07963 | pbrook | /* block.c */
|
11 | faf07963 | pbrook | typedef struct BlockDriver BlockDriver; |
12 | faf07963 | pbrook | |
13 | faf07963 | pbrook | typedef struct BlockDriverInfo { |
14 | faf07963 | pbrook | /* in bytes, 0 if irrelevant */
|
15 | faf07963 | pbrook | int cluster_size;
|
16 | faf07963 | pbrook | /* offset at which the VM state can be saved (0 if not possible) */
|
17 | faf07963 | pbrook | int64_t vm_state_offset; |
18 | 64c79160 | Dong Xu Wang | bool is_dirty;
|
19 | faf07963 | pbrook | } BlockDriverInfo; |
20 | faf07963 | pbrook | |
21 | f8111c24 | Dong Xu Wang | typedef struct BlockFragInfo { |
22 | f8111c24 | Dong Xu Wang | uint64_t allocated_clusters; |
23 | f8111c24 | Dong Xu Wang | uint64_t total_clusters; |
24 | f8111c24 | Dong Xu Wang | uint64_t fragmented_clusters; |
25 | f8111c24 | Dong Xu Wang | } BlockFragInfo; |
26 | f8111c24 | Dong Xu Wang | |
27 | faf07963 | pbrook | typedef struct QEMUSnapshotInfo { |
28 | faf07963 | pbrook | char id_str[128]; /* unique snapshot id */ |
29 | faf07963 | pbrook | /* the following fields are informative. They are not needed for
|
30 | faf07963 | pbrook | the consistency of the snapshot */
|
31 | e7d81004 | Stefan Weil | char name[256]; /* user chosen name */ |
32 | c2c9a466 | Kevin Wolf | uint64_t vm_state_size; /* VM state info size */
|
33 | faf07963 | pbrook | uint32_t date_sec; /* UTC date of the snapshot */
|
34 | faf07963 | pbrook | uint32_t date_nsec; |
35 | faf07963 | pbrook | uint64_t vm_clock_nsec; /* VM clock relative to boot */
|
36 | faf07963 | pbrook | } QEMUSnapshotInfo; |
37 | faf07963 | pbrook | |
38 | 145feb17 | Markus Armbruster | /* Callbacks for block device models */
|
39 | 0e49de52 | Markus Armbruster | typedef struct BlockDevOps { |
40 | 145feb17 | Markus Armbruster | /*
|
41 | 145feb17 | Markus Armbruster | * Runs when virtual media changed (monitor commands eject, change)
|
42 | 7d4b4ba5 | Markus Armbruster | * Argument load is true on load and false on eject.
|
43 | 145feb17 | Markus Armbruster | * Beware: doesn't run when a host device's physical media
|
44 | 145feb17 | Markus Armbruster | * changes. Sure would be useful if it did.
|
45 | 2c6942fa | Markus Armbruster | * Device models with removable media must implement this callback.
|
46 | 145feb17 | Markus Armbruster | */
|
47 | 7d4b4ba5 | Markus Armbruster | void (*change_media_cb)(void *opaque, bool load); |
48 | 145feb17 | Markus Armbruster | /*
|
49 | 025ccaa7 | Paolo Bonzini | * Runs when an eject request is issued from the monitor, the tray
|
50 | 025ccaa7 | Paolo Bonzini | * is closed, and the medium is locked.
|
51 | 025ccaa7 | Paolo Bonzini | * Device models that do not implement is_medium_locked will not need
|
52 | 025ccaa7 | Paolo Bonzini | * this callback. Device models that can lock the medium or tray might
|
53 | 025ccaa7 | Paolo Bonzini | * want to implement the callback and unlock the tray when "force" is
|
54 | 025ccaa7 | Paolo Bonzini | * true, even if they do not support eject requests.
|
55 | 025ccaa7 | Paolo Bonzini | */
|
56 | 025ccaa7 | Paolo Bonzini | void (*eject_request_cb)(void *opaque, bool force); |
57 | 025ccaa7 | Paolo Bonzini | /*
|
58 | e4def80b | Markus Armbruster | * Is the virtual tray open?
|
59 | e4def80b | Markus Armbruster | * Device models implement this only when the device has a tray.
|
60 | e4def80b | Markus Armbruster | */
|
61 | e4def80b | Markus Armbruster | bool (*is_tray_open)(void *opaque); |
62 | e4def80b | Markus Armbruster | /*
|
63 | f107639a | Markus Armbruster | * Is the virtual medium locked into the device?
|
64 | f107639a | Markus Armbruster | * Device models implement this only when device has such a lock.
|
65 | f107639a | Markus Armbruster | */
|
66 | f107639a | Markus Armbruster | bool (*is_medium_locked)(void *opaque); |
67 | f107639a | Markus Armbruster | /*
|
68 | 145feb17 | Markus Armbruster | * Runs when the size changed (e.g. monitor command block_resize)
|
69 | 145feb17 | Markus Armbruster | */
|
70 | 145feb17 | Markus Armbruster | void (*resize_cb)(void *opaque); |
71 | 0e49de52 | Markus Armbruster | } BlockDevOps; |
72 | 0e49de52 | Markus Armbruster | |
73 | faf07963 | pbrook | #define BDRV_O_RDWR 0x0002 |
74 | faf07963 | pbrook | #define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */ |
75 | 9f7965c7 | aliguori | #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */ |
76 | 9f7965c7 | aliguori | #define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */ |
77 | 5c6c3a6c | Christoph Hellwig | #define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the thread pool */ |
78 | b783e409 | Kevin Wolf | #define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */ |
79 | 016f5cf6 | Alexander Graf | #define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */ |
80 | 53fec9d3 | Stefan Hajnoczi | #define BDRV_O_COPY_ON_READ 0x0400 /* copy read backing sectors into image */ |
81 | ccb1f4a7 | Benoît Canet | #define BDRV_O_INCOMING 0x0800 /* consistency hint for incoming migration */ |
82 | 9f7965c7 | aliguori | |
83 | ceb25e5c | Kevin Wolf | #define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
|
84 | faf07963 | pbrook | |
85 | 6ea44308 | Jan Kiszka | #define BDRV_SECTOR_BITS 9 |
86 | c63782cb | Jes Sorensen | #define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS) |
87 | 3abbc4d9 | Stefan Hajnoczi | #define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1) |
88 | 6ea44308 | Jan Kiszka | |
89 | 2582bfed | Luiz Capitulino | typedef enum { |
90 | abd7f68d | Markus Armbruster | BLOCK_ERR_REPORT, BLOCK_ERR_IGNORE, BLOCK_ERR_STOP_ENOSPC, |
91 | abd7f68d | Markus Armbruster | BLOCK_ERR_STOP_ANY |
92 | abd7f68d | Markus Armbruster | } BlockErrorAction; |
93 | abd7f68d | Markus Armbruster | |
94 | abd7f68d | Markus Armbruster | typedef enum { |
95 | 2582bfed | Luiz Capitulino | BDRV_ACTION_REPORT, BDRV_ACTION_IGNORE, BDRV_ACTION_STOP |
96 | 329c0a48 | Luiz Capitulino | } BlockQMPEventAction; |
97 | 2582bfed | Luiz Capitulino | |
98 | 28a7282a | Luiz Capitulino | void bdrv_iostatus_enable(BlockDriverState *bs);
|
99 | 28a7282a | Luiz Capitulino | void bdrv_iostatus_reset(BlockDriverState *bs);
|
100 | 28a7282a | Luiz Capitulino | void bdrv_iostatus_disable(BlockDriverState *bs);
|
101 | 28a7282a | Luiz Capitulino | bool bdrv_iostatus_is_enabled(const BlockDriverState *bs); |
102 | 28a7282a | Luiz Capitulino | void bdrv_iostatus_set_err(BlockDriverState *bs, int error); |
103 | 329c0a48 | Luiz Capitulino | void bdrv_emit_qmp_error_event(const BlockDriverState *bdrv, |
104 | 329c0a48 | Luiz Capitulino | BlockQMPEventAction action, int is_read);
|
105 | d15e5465 | Luiz Capitulino | void bdrv_info_print(Monitor *mon, const QObject *data); |
106 | d15e5465 | Luiz Capitulino | void bdrv_info(Monitor *mon, QObject **ret_data);
|
107 | 218a536a | Luiz Capitulino | void bdrv_stats_print(Monitor *mon, const QObject *data); |
108 | 218a536a | Luiz Capitulino | void bdrv_info_stats(Monitor *mon, QObject **ret_data);
|
109 | faf07963 | pbrook | |
110 | 0563e191 | Zhi Yong Wu | /* disk I/O throttling */
|
111 | 0563e191 | Zhi Yong Wu | void bdrv_io_limits_enable(BlockDriverState *bs);
|
112 | 98f90dba | Zhi Yong Wu | void bdrv_io_limits_disable(BlockDriverState *bs);
|
113 | 0563e191 | Zhi Yong Wu | bool bdrv_io_limits_enabled(BlockDriverState *bs);
|
114 | 0563e191 | Zhi Yong Wu | |
115 | faf07963 | pbrook | void bdrv_init(void); |
116 | eb852011 | Markus Armbruster | void bdrv_init_with_whitelist(void); |
117 | b50cbabc | MORITA Kazutaka | BlockDriver *bdrv_find_protocol(const char *filename); |
118 | faf07963 | pbrook | BlockDriver *bdrv_find_format(const char *format_name); |
119 | eb852011 | Markus Armbruster | BlockDriver *bdrv_find_whitelisted_format(const char *format_name); |
120 | 0e7e1989 | Kevin Wolf | int bdrv_create(BlockDriver *drv, const char* filename, |
121 | 0e7e1989 | Kevin Wolf | QEMUOptionParameter *options); |
122 | 84a12e66 | Christoph Hellwig | int bdrv_create_file(const char* filename, QEMUOptionParameter *options); |
123 | faf07963 | pbrook | BlockDriverState *bdrv_new(const char *device_name); |
124 | d22b2f41 | Ryan Harper | void bdrv_make_anon(BlockDriverState *bs);
|
125 | 8802d1fd | Jeff Cody | void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
|
126 | faf07963 | pbrook | void bdrv_delete(BlockDriverState *bs);
|
127 | c3993cdc | Stefan Hajnoczi | int bdrv_parse_cache_flags(const char *mode, int *flags); |
128 | faf07963 | pbrook | int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags); |
129 | d6e9098e | Kevin Wolf | int bdrv_open(BlockDriverState *bs, const char *filename, int flags, |
130 | d6e9098e | Kevin Wolf | BlockDriver *drv); |
131 | faf07963 | pbrook | void bdrv_close(BlockDriverState *bs);
|
132 | fa879d62 | Markus Armbruster | int bdrv_attach_dev(BlockDriverState *bs, void *dev); |
133 | fa879d62 | Markus Armbruster | void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev); |
134 | fa879d62 | Markus Armbruster | void bdrv_detach_dev(BlockDriverState *bs, void *dev); |
135 | fa879d62 | Markus Armbruster | void *bdrv_get_attached_dev(BlockDriverState *bs);
|
136 | 0e49de52 | Markus Armbruster | void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, |
137 | 0e49de52 | Markus Armbruster | void *opaque);
|
138 | 025ccaa7 | Paolo Bonzini | void bdrv_dev_eject_request(BlockDriverState *bs, bool force); |
139 | 2c6942fa | Markus Armbruster | bool bdrv_dev_has_removable_media(BlockDriverState *bs);
|
140 | e4def80b | Markus Armbruster | bool bdrv_dev_is_tray_open(BlockDriverState *bs);
|
141 | f107639a | Markus Armbruster | bool bdrv_dev_is_medium_locked(BlockDriverState *bs);
|
142 | faf07963 | pbrook | int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
143 | faf07963 | pbrook | uint8_t *buf, int nb_sectors);
|
144 | faf07963 | pbrook | int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
145 | faf07963 | pbrook | const uint8_t *buf, int nb_sectors); |
146 | faf07963 | pbrook | int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
147 | faf07963 | pbrook | void *buf, int count); |
148 | faf07963 | pbrook | int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
149 | faf07963 | pbrook | const void *buf, int count); |
150 | f08145fe | Kevin Wolf | int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
|
151 | f08145fe | Kevin Wolf | const void *buf, int count); |
152 | da1fa91d | Kevin Wolf | int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
|
153 | da1fa91d | Kevin Wolf | int nb_sectors, QEMUIOVector *qiov);
|
154 | 470c0504 | Stefan Hajnoczi | int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
|
155 | 470c0504 | Stefan Hajnoczi | int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
|
156 | da1fa91d | Kevin Wolf | int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
|
157 | da1fa91d | Kevin Wolf | int nb_sectors, QEMUIOVector *qiov);
|
158 | f08f2dda | Stefan Hajnoczi | /*
|
159 | f08f2dda | Stefan Hajnoczi | * Efficiently zero a region of the disk image. Note that this is a regular
|
160 | f08f2dda | Stefan Hajnoczi | * I/O request like read or write and should have a reasonable size. This
|
161 | f08f2dda | Stefan Hajnoczi | * function is not suitable for zeroing the entire image in a single request
|
162 | f08f2dda | Stefan Hajnoczi | * because it may allocate memory for the entire region.
|
163 | f08f2dda | Stefan Hajnoczi | */
|
164 | f08f2dda | Stefan Hajnoczi | int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
165 | f08f2dda | Stefan Hajnoczi | int nb_sectors);
|
166 | 060f51c9 | Stefan Hajnoczi | int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
167 | 060f51c9 | Stefan Hajnoczi | int nb_sectors, int *pnum); |
168 | 188a7bbf | Paolo Bonzini | int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top,
|
169 | 188a7bbf | Paolo Bonzini | BlockDriverState *base, |
170 | 188a7bbf | Paolo Bonzini | int64_t sector_num, |
171 | 188a7bbf | Paolo Bonzini | int nb_sectors, int *pnum); |
172 | e8a6bb9c | Marcelo Tosatti | BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs, |
173 | e8a6bb9c | Marcelo Tosatti | const char *backing_file); |
174 | faf07963 | pbrook | int bdrv_truncate(BlockDriverState *bs, int64_t offset);
|
175 | faf07963 | pbrook | int64_t bdrv_getlength(BlockDriverState *bs); |
176 | 4a1d5e1f | Fam Zheng | int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); |
177 | 96b8f136 | ths | void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
|
178 | f3d54fc4 | aliguori | void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs); |
179 | faf07963 | pbrook | int bdrv_commit(BlockDriverState *bs);
|
180 | e8877497 | Stefan Hajnoczi | int bdrv_commit_all(void); |
181 | 756e6736 | Kevin Wolf | int bdrv_change_backing_file(BlockDriverState *bs,
|
182 | 756e6736 | Kevin Wolf | const char *backing_file, const char *backing_fmt); |
183 | 5efa9d5a | Anthony Liguori | void bdrv_register(BlockDriver *bdrv);
|
184 | 5efa9d5a | Anthony Liguori | |
185 | e076f338 | Kevin Wolf | |
186 | e076f338 | Kevin Wolf | typedef struct BdrvCheckResult { |
187 | e076f338 | Kevin Wolf | int corruptions;
|
188 | e076f338 | Kevin Wolf | int leaks;
|
189 | e076f338 | Kevin Wolf | int check_errors;
|
190 | ccf34716 | Kevin Wolf | int corruptions_fixed;
|
191 | ccf34716 | Kevin Wolf | int leaks_fixed;
|
192 | f8111c24 | Dong Xu Wang | BlockFragInfo bfi; |
193 | e076f338 | Kevin Wolf | } BdrvCheckResult; |
194 | e076f338 | Kevin Wolf | |
195 | 4534ff54 | Kevin Wolf | typedef enum { |
196 | 4534ff54 | Kevin Wolf | BDRV_FIX_LEAKS = 1,
|
197 | 4534ff54 | Kevin Wolf | BDRV_FIX_ERRORS = 2,
|
198 | 4534ff54 | Kevin Wolf | } BdrvCheckMode; |
199 | 4534ff54 | Kevin Wolf | |
200 | 4534ff54 | Kevin Wolf | int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
|
201 | e076f338 | Kevin Wolf | |
202 | faf07963 | pbrook | /* async block I/O */
|
203 | 7cd1e32a | lirans@il.ibm.com | typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector, |
204 | 39aa9a12 | Devin Nakamura | int sector_num);
|
205 | 3b69e4b9 | aliguori | BlockDriverAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num, |
206 | 3b69e4b9 | aliguori | QEMUIOVector *iov, int nb_sectors,
|
207 | 3b69e4b9 | aliguori | BlockDriverCompletionFunc *cb, void *opaque);
|
208 | 3b69e4b9 | aliguori | BlockDriverAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num, |
209 | 3b69e4b9 | aliguori | QEMUIOVector *iov, int nb_sectors,
|
210 | 3b69e4b9 | aliguori | BlockDriverCompletionFunc *cb, void *opaque);
|
211 | b2e12bc6 | Christoph Hellwig | BlockDriverAIOCB *bdrv_aio_flush(BlockDriverState *bs, |
212 | 39aa9a12 | Devin Nakamura | BlockDriverCompletionFunc *cb, void *opaque);
|
213 | 4265d620 | Paolo Bonzini | BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs, |
214 | 4265d620 | Paolo Bonzini | int64_t sector_num, int nb_sectors,
|
215 | 4265d620 | Paolo Bonzini | BlockDriverCompletionFunc *cb, void *opaque);
|
216 | faf07963 | pbrook | void bdrv_aio_cancel(BlockDriverAIOCB *acb);
|
217 | faf07963 | pbrook | |
218 | 40b4f539 | Kevin Wolf | typedef struct BlockRequest { |
219 | 40b4f539 | Kevin Wolf | /* Fields to be filled by multiwrite caller */
|
220 | 40b4f539 | Kevin Wolf | int64_t sector; |
221 | 40b4f539 | Kevin Wolf | int nb_sectors;
|
222 | 40b4f539 | Kevin Wolf | QEMUIOVector *qiov; |
223 | 40b4f539 | Kevin Wolf | BlockDriverCompletionFunc *cb; |
224 | 40b4f539 | Kevin Wolf | void *opaque;
|
225 | 40b4f539 | Kevin Wolf | |
226 | 40b4f539 | Kevin Wolf | /* Filled by multiwrite implementation */
|
227 | 40b4f539 | Kevin Wolf | int error;
|
228 | 40b4f539 | Kevin Wolf | } BlockRequest; |
229 | 40b4f539 | Kevin Wolf | |
230 | 40b4f539 | Kevin Wolf | int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs,
|
231 | 40b4f539 | Kevin Wolf | int num_reqs);
|
232 | 40b4f539 | Kevin Wolf | |
233 | 7d780669 | aliguori | /* sg packet commands */
|
234 | 221f715d | aliguori | int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf); |
235 | 221f715d | aliguori | BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs, |
236 | 221f715d | aliguori | unsigned long int req, void *buf, |
237 | 221f715d | aliguori | BlockDriverCompletionFunc *cb, void *opaque);
|
238 | 7d780669 | aliguori | |
239 | 0f15423c | Anthony Liguori | /* Invalidate any cached metadata used by image formats */
|
240 | 0f15423c | Anthony Liguori | void bdrv_invalidate_cache(BlockDriverState *bs);
|
241 | 0f15423c | Anthony Liguori | void bdrv_invalidate_cache_all(void); |
242 | 0f15423c | Anthony Liguori | |
243 | 07789269 | Benoît Canet | void bdrv_clear_incoming_migration_all(void); |
244 | 07789269 | Benoît Canet | |
245 | faf07963 | pbrook | /* Ensure contents are flushed to disk. */
|
246 | 205ef796 | Kevin Wolf | int bdrv_flush(BlockDriverState *bs);
|
247 | 07f07615 | Paolo Bonzini | int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
|
248 | c6ca28d6 | aliguori | void bdrv_flush_all(void); |
249 | 2bc93fed | MORITA Kazutaka | void bdrv_close_all(void); |
250 | 922453bc | Stefan Hajnoczi | void bdrv_drain_all(void); |
251 | c6ca28d6 | aliguori | |
252 | bb8bf76f | Christoph Hellwig | int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); |
253 | 4265d620 | Paolo Bonzini | int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors); |
254 | f2feebbd | Kevin Wolf | int bdrv_has_zero_init(BlockDriverState *bs);
|
255 | f58c7b35 | ths | int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, |
256 | 39aa9a12 | Devin Nakamura | int *pnum);
|
257 | faf07963 | pbrook | |
258 | faf07963 | pbrook | #define BIOS_ATA_TRANSLATION_AUTO 0 |
259 | faf07963 | pbrook | #define BIOS_ATA_TRANSLATION_NONE 1 |
260 | faf07963 | pbrook | #define BIOS_ATA_TRANSLATION_LBA 2 |
261 | faf07963 | pbrook | #define BIOS_ATA_TRANSLATION_LARGE 3 |
262 | faf07963 | pbrook | #define BIOS_ATA_TRANSLATION_RECHS 4 |
263 | faf07963 | pbrook | |
264 | faf07963 | pbrook | void bdrv_set_geometry_hint(BlockDriverState *bs,
|
265 | faf07963 | pbrook | int cyls, int heads, int secs); |
266 | faf07963 | pbrook | void bdrv_set_translation_hint(BlockDriverState *bs, int translation); |
267 | faf07963 | pbrook | void bdrv_get_geometry_hint(BlockDriverState *bs,
|
268 | faf07963 | pbrook | int *pcyls, int *pheads, int *psecs); |
269 | 5bbdbb46 | Blue Swirl | typedef enum FDriveType { |
270 | 5bbdbb46 | Blue Swirl | FDRIVE_DRV_144 = 0x00, /* 1.44 MB 3"5 drive */ |
271 | 5bbdbb46 | Blue Swirl | FDRIVE_DRV_288 = 0x01, /* 2.88 MB 3"5 drive */ |
272 | 5bbdbb46 | Blue Swirl | FDRIVE_DRV_120 = 0x02, /* 1.2 MB 5"25 drive */ |
273 | 5bbdbb46 | Blue Swirl | FDRIVE_DRV_NONE = 0x03, /* No drive connected */ |
274 | 5bbdbb46 | Blue Swirl | } FDriveType; |
275 | 5bbdbb46 | Blue Swirl | |
276 | f8d3d128 | Hervé Poussineau | typedef enum FDriveRate { |
277 | f8d3d128 | Hervé Poussineau | FDRIVE_RATE_500K = 0x00, /* 500 Kbps */ |
278 | f8d3d128 | Hervé Poussineau | FDRIVE_RATE_300K = 0x01, /* 300 Kbps */ |
279 | f8d3d128 | Hervé Poussineau | FDRIVE_RATE_250K = 0x02, /* 250 Kbps */ |
280 | f8d3d128 | Hervé Poussineau | FDRIVE_RATE_1M = 0x03, /* 1 Mbps */ |
281 | f8d3d128 | Hervé Poussineau | } FDriveRate; |
282 | f8d3d128 | Hervé Poussineau | |
283 | 5bbdbb46 | Blue Swirl | void bdrv_get_floppy_geometry_hint(BlockDriverState *bs, int *nb_heads, |
284 | 5bbdbb46 | Blue Swirl | int *max_track, int *last_sect, |
285 | f8d3d128 | Hervé Poussineau | FDriveType drive_in, FDriveType *drive, |
286 | f8d3d128 | Hervé Poussineau | FDriveRate *rate); |
287 | faf07963 | pbrook | int bdrv_get_translation_hint(BlockDriverState *bs);
|
288 | abd7f68d | Markus Armbruster | void bdrv_set_on_error(BlockDriverState *bs, BlockErrorAction on_read_error,
|
289 | abd7f68d | Markus Armbruster | BlockErrorAction on_write_error); |
290 | abd7f68d | Markus Armbruster | BlockErrorAction bdrv_get_on_error(BlockDriverState *bs, int is_read);
|
291 | faf07963 | pbrook | int bdrv_is_read_only(BlockDriverState *bs);
|
292 | 985a03b0 | ths | int bdrv_is_sg(BlockDriverState *bs);
|
293 | e900a7b7 | Christoph Hellwig | int bdrv_enable_write_cache(BlockDriverState *bs);
|
294 | 425b0148 | Paolo Bonzini | void bdrv_set_enable_write_cache(BlockDriverState *bs, bool wce); |
295 | faf07963 | pbrook | int bdrv_is_inserted(BlockDriverState *bs);
|
296 | faf07963 | pbrook | int bdrv_media_changed(BlockDriverState *bs);
|
297 | 025e849a | Markus Armbruster | void bdrv_lock_medium(BlockDriverState *bs, bool locked); |
298 | f36f3949 | Luiz Capitulino | void bdrv_eject(BlockDriverState *bs, bool eject_flag); |
299 | f8d6bba1 | Markus Armbruster | const char *bdrv_get_format_name(BlockDriverState *bs); |
300 | faf07963 | pbrook | BlockDriverState *bdrv_find(const char *name); |
301 | 2f399b0a | Markus Armbruster | BlockDriverState *bdrv_next(BlockDriverState *bs); |
302 | 51de9760 | aliguori | void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), |
303 | 51de9760 | aliguori | void *opaque);
|
304 | faf07963 | pbrook | int bdrv_is_encrypted(BlockDriverState *bs);
|
305 | c0f4ce77 | aliguori | int bdrv_key_required(BlockDriverState *bs);
|
306 | faf07963 | pbrook | int bdrv_set_key(BlockDriverState *bs, const char *key); |
307 | c0f4ce77 | aliguori | int bdrv_query_missing_keys(void); |
308 | faf07963 | pbrook | void bdrv_iterate_format(void (*it)(void *opaque, const char *name), |
309 | faf07963 | pbrook | void *opaque);
|
310 | faf07963 | pbrook | const char *bdrv_get_device_name(BlockDriverState *bs); |
311 | c8433287 | Markus Armbruster | int bdrv_get_flags(BlockDriverState *bs);
|
312 | faf07963 | pbrook | int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
313 | faf07963 | pbrook | const uint8_t *buf, int nb_sectors); |
314 | faf07963 | pbrook | int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
|
315 | faf07963 | pbrook | |
316 | 045df330 | aliguori | const char *bdrv_get_encrypted_filename(BlockDriverState *bs); |
317 | faf07963 | pbrook | void bdrv_get_backing_filename(BlockDriverState *bs,
|
318 | faf07963 | pbrook | char *filename, int filename_size); |
319 | dc5a1371 | Paolo Bonzini | void bdrv_get_full_backing_filename(BlockDriverState *bs,
|
320 | dc5a1371 | Paolo Bonzini | char *dest, size_t sz);
|
321 | feeee5ac | Miguel Di Ciurcio Filho | int bdrv_can_snapshot(BlockDriverState *bs);
|
322 | 199630b6 | Blue Swirl | int bdrv_is_snapshot(BlockDriverState *bs);
|
323 | f9092b10 | Markus Armbruster | BlockDriverState *bdrv_snapshots(void);
|
324 | faf07963 | pbrook | int bdrv_snapshot_create(BlockDriverState *bs,
|
325 | faf07963 | pbrook | QEMUSnapshotInfo *sn_info); |
326 | faf07963 | pbrook | int bdrv_snapshot_goto(BlockDriverState *bs,
|
327 | faf07963 | pbrook | const char *snapshot_id); |
328 | faf07963 | pbrook | int bdrv_snapshot_delete(BlockDriverState *bs, const char *snapshot_id); |
329 | faf07963 | pbrook | int bdrv_snapshot_list(BlockDriverState *bs,
|
330 | faf07963 | pbrook | QEMUSnapshotInfo **psn_info); |
331 | 51ef6727 | edison | int bdrv_snapshot_load_tmp(BlockDriverState *bs,
|
332 | 51ef6727 | edison | const char *snapshot_name); |
333 | faf07963 | pbrook | char *bdrv_snapshot_dump(char *buf, int buf_size, QEMUSnapshotInfo *sn); |
334 | faf07963 | pbrook | |
335 | faf07963 | pbrook | char *get_human_readable_size(char *buf, int buf_size, int64_t size); |
336 | faf07963 | pbrook | int path_is_absolute(const char *path); |
337 | faf07963 | pbrook | void path_combine(char *dest, int dest_size, |
338 | faf07963 | pbrook | const char *base_path, |
339 | faf07963 | pbrook | const char *filename); |
340 | faf07963 | pbrook | |
341 | 45566e9c | Christoph Hellwig | int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, |
342 | 45566e9c | Christoph Hellwig | int64_t pos, int size);
|
343 | 178e08a5 | aliguori | |
344 | 45566e9c | Christoph Hellwig | int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
|
345 | 45566e9c | Christoph Hellwig | int64_t pos, int size);
|
346 | 178e08a5 | aliguori | |
347 | f88e1a42 | Jes Sorensen | int bdrv_img_create(const char *filename, const char *fmt, |
348 | f88e1a42 | Jes Sorensen | const char *base_filename, const char *base_fmt, |
349 | f88e1a42 | Jes Sorensen | char *options, uint64_t img_size, int flags); |
350 | f88e1a42 | Jes Sorensen | |
351 | 7b6f9300 | Markus Armbruster | void bdrv_set_buffer_alignment(BlockDriverState *bs, int align); |
352 | ba5b7ad4 | Markus Armbruster | void *qemu_blockalign(BlockDriverState *bs, size_t size);
|
353 | ba5b7ad4 | Markus Armbruster | |
354 | 23bd90d2 | Jan Kiszka | #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048 |
355 | 6ea44308 | Jan Kiszka | |
356 | 7cd1e32a | lirans@il.ibm.com | void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable); |
357 | 7cd1e32a | lirans@il.ibm.com | int bdrv_get_dirty(BlockDriverState *bs, int64_t sector);
|
358 | a55eb92c | Jan Kiszka | void bdrv_reset_dirty(BlockDriverState *bs, int64_t cur_sector,
|
359 | a55eb92c | Jan Kiszka | int nr_sectors);
|
360 | aaa0eb75 | Liran Schour | int64_t bdrv_get_dirty_count(BlockDriverState *bs); |
361 | 8b9b0cc2 | Kevin Wolf | |
362 | 53fec9d3 | Stefan Hajnoczi | void bdrv_enable_copy_on_read(BlockDriverState *bs);
|
363 | 53fec9d3 | Stefan Hajnoczi | void bdrv_disable_copy_on_read(BlockDriverState *bs);
|
364 | 53fec9d3 | Stefan Hajnoczi | |
365 | db593f25 | Marcelo Tosatti | void bdrv_set_in_use(BlockDriverState *bs, int in_use); |
366 | db593f25 | Marcelo Tosatti | int bdrv_in_use(BlockDriverState *bs);
|
367 | 8b9b0cc2 | Kevin Wolf | |
368 | a597e79c | Christoph Hellwig | enum BlockAcctType {
|
369 | a597e79c | Christoph Hellwig | BDRV_ACCT_READ, |
370 | a597e79c | Christoph Hellwig | BDRV_ACCT_WRITE, |
371 | a597e79c | Christoph Hellwig | BDRV_ACCT_FLUSH, |
372 | a597e79c | Christoph Hellwig | BDRV_MAX_IOTYPE, |
373 | a597e79c | Christoph Hellwig | }; |
374 | a597e79c | Christoph Hellwig | |
375 | a597e79c | Christoph Hellwig | typedef struct BlockAcctCookie { |
376 | a597e79c | Christoph Hellwig | int64_t bytes; |
377 | c488c7f6 | Christoph Hellwig | int64_t start_time_ns; |
378 | a597e79c | Christoph Hellwig | enum BlockAcctType type;
|
379 | a597e79c | Christoph Hellwig | } BlockAcctCookie; |
380 | a597e79c | Christoph Hellwig | |
381 | a597e79c | Christoph Hellwig | void bdrv_acct_start(BlockDriverState *bs, BlockAcctCookie *cookie,
|
382 | a597e79c | Christoph Hellwig | int64_t bytes, enum BlockAcctType type);
|
383 | a597e79c | Christoph Hellwig | void bdrv_acct_done(BlockDriverState *bs, BlockAcctCookie *cookie);
|
384 | a597e79c | Christoph Hellwig | |
385 | 8b9b0cc2 | Kevin Wolf | typedef enum { |
386 | 8252278a | Kevin Wolf | BLKDBG_L1_UPDATE, |
387 | 8252278a | Kevin Wolf | |
388 | 8252278a | Kevin Wolf | BLKDBG_L1_GROW_ALLOC_TABLE, |
389 | 8252278a | Kevin Wolf | BLKDBG_L1_GROW_WRITE_TABLE, |
390 | 8252278a | Kevin Wolf | BLKDBG_L1_GROW_ACTIVATE_TABLE, |
391 | 8252278a | Kevin Wolf | |
392 | 8252278a | Kevin Wolf | BLKDBG_L2_LOAD, |
393 | 8252278a | Kevin Wolf | BLKDBG_L2_UPDATE, |
394 | 8252278a | Kevin Wolf | BLKDBG_L2_UPDATE_COMPRESSED, |
395 | 8252278a | Kevin Wolf | BLKDBG_L2_ALLOC_COW_READ, |
396 | 8252278a | Kevin Wolf | BLKDBG_L2_ALLOC_WRITE, |
397 | 8252278a | Kevin Wolf | |
398 | 8252278a | Kevin Wolf | BLKDBG_READ, |
399 | 8252278a | Kevin Wolf | BLKDBG_READ_AIO, |
400 | 8252278a | Kevin Wolf | BLKDBG_READ_BACKING, |
401 | 8252278a | Kevin Wolf | BLKDBG_READ_BACKING_AIO, |
402 | 8252278a | Kevin Wolf | BLKDBG_READ_COMPRESSED, |
403 | 8252278a | Kevin Wolf | |
404 | 8252278a | Kevin Wolf | BLKDBG_WRITE_AIO, |
405 | 8252278a | Kevin Wolf | BLKDBG_WRITE_COMPRESSED, |
406 | 8252278a | Kevin Wolf | |
407 | 8252278a | Kevin Wolf | BLKDBG_VMSTATE_LOAD, |
408 | 8252278a | Kevin Wolf | BLKDBG_VMSTATE_SAVE, |
409 | 8252278a | Kevin Wolf | |
410 | 8252278a | Kevin Wolf | BLKDBG_COW_READ, |
411 | 8252278a | Kevin Wolf | BLKDBG_COW_WRITE, |
412 | 8252278a | Kevin Wolf | |
413 | 8252278a | Kevin Wolf | BLKDBG_REFTABLE_LOAD, |
414 | 8252278a | Kevin Wolf | BLKDBG_REFTABLE_GROW, |
415 | 8252278a | Kevin Wolf | |
416 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_LOAD, |
417 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_UPDATE, |
418 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_UPDATE_PART, |
419 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_ALLOC, |
420 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_ALLOC_HOOKUP, |
421 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_ALLOC_WRITE, |
422 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS, |
423 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE, |
424 | 8252278a | Kevin Wolf | BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE, |
425 | 8252278a | Kevin Wolf | |
426 | 8252278a | Kevin Wolf | BLKDBG_CLUSTER_ALLOC, |
427 | 8252278a | Kevin Wolf | BLKDBG_CLUSTER_ALLOC_BYTES, |
428 | 8252278a | Kevin Wolf | BLKDBG_CLUSTER_FREE, |
429 | 8252278a | Kevin Wolf | |
430 | 8b9b0cc2 | Kevin Wolf | BLKDBG_EVENT_MAX, |
431 | 8b9b0cc2 | Kevin Wolf | } BlkDebugEvent; |
432 | 8b9b0cc2 | Kevin Wolf | |
433 | 8b9b0cc2 | Kevin Wolf | #define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
|
434 | 8b9b0cc2 | Kevin Wolf | void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
|
435 | 8b9b0cc2 | Kevin Wolf | |
436 | d1a0739d | Markus Armbruster | |
437 | d1a0739d | Markus Armbruster | /* Convenience for block device models */
|
438 | d1a0739d | Markus Armbruster | |
439 | d1a0739d | Markus Armbruster | typedef struct BlockConf { |
440 | d1a0739d | Markus Armbruster | BlockDriverState *bs; |
441 | d1a0739d | Markus Armbruster | uint16_t physical_block_size; |
442 | d1a0739d | Markus Armbruster | uint16_t logical_block_size; |
443 | d1a0739d | Markus Armbruster | uint16_t min_io_size; |
444 | d1a0739d | Markus Armbruster | uint32_t opt_io_size; |
445 | d1a0739d | Markus Armbruster | int32_t bootindex; |
446 | d1a0739d | Markus Armbruster | uint32_t discard_granularity; |
447 | d1a0739d | Markus Armbruster | } BlockConf; |
448 | d1a0739d | Markus Armbruster | |
449 | d1a0739d | Markus Armbruster | static inline unsigned int get_physical_block_exp(BlockConf *conf) |
450 | d1a0739d | Markus Armbruster | { |
451 | d1a0739d | Markus Armbruster | unsigned int exp = 0, size; |
452 | d1a0739d | Markus Armbruster | |
453 | d1a0739d | Markus Armbruster | for (size = conf->physical_block_size;
|
454 | d1a0739d | Markus Armbruster | size > conf->logical_block_size; |
455 | d1a0739d | Markus Armbruster | size >>= 1) {
|
456 | d1a0739d | Markus Armbruster | exp++; |
457 | d1a0739d | Markus Armbruster | } |
458 | d1a0739d | Markus Armbruster | |
459 | d1a0739d | Markus Armbruster | return exp;
|
460 | d1a0739d | Markus Armbruster | } |
461 | d1a0739d | Markus Armbruster | |
462 | d1a0739d | Markus Armbruster | #define DEFINE_BLOCK_PROPERTIES(_state, _conf) \
|
463 | d1a0739d | Markus Armbruster | DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \
|
464 | 1fc86bf9 | Stefan Hajnoczi | DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \
|
465 | 1fc86bf9 | Stefan Hajnoczi | _conf.logical_block_size, 512), \
|
466 | 1fc86bf9 | Stefan Hajnoczi | DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \
|
467 | 1fc86bf9 | Stefan Hajnoczi | _conf.physical_block_size, 512), \
|
468 | d1a0739d | Markus Armbruster | DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ |
469 | d1a0739d | Markus Armbruster | DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0), \ |
470 | d1a0739d | Markus Armbruster | DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1), \ |
471 | d1a0739d | Markus Armbruster | DEFINE_PROP_UINT32("discard_granularity", _state, \
|
472 | d1a0739d | Markus Armbruster | _conf.discard_granularity, 0)
|
473 | d1a0739d | Markus Armbruster | |
474 | faf07963 | pbrook | #endif
|