]> git.proxmox.com Git - mirror_qemu.git/blame - include/block/block.h
Merge remote-tracking branch 'remotes/kraxel/tags/pull-vga-20150615-1' into staging
[mirror_qemu.git] / include / block / block.h
CommitLineData
faf07963
PB
1#ifndef BLOCK_H
2#define BLOCK_H
3
737e150e 4#include "block/aio.h"
3b69e4b9 5#include "qemu-common.h"
1de7afc9 6#include "qemu/option.h"
737e150e 7#include "block/coroutine.h"
5366d0c8 8#include "block/accounting.h"
7b1b5d19 9#include "qapi/qmp/qobject.h"
2f0c9fe6 10#include "qapi-types.h"
a76bab49 11
faf07963 12/* block.c */
faf07963 13typedef struct BlockDriver BlockDriver;
2f0c9fe6 14typedef struct BlockJob BlockJob;
f3930ed0 15typedef struct BdrvChildRole BdrvChildRole;
faf07963 16
faf07963
PB
17typedef struct BlockDriverInfo {
18 /* in bytes, 0 if irrelevant */
19 int cluster_size;
20 /* offset at which the VM state can be saved (0 if not possible) */
21 int64_t vm_state_offset;
64c79160 22 bool is_dirty;
e1a5c4be
PL
23 /*
24 * True if unallocated blocks read back as zeroes. This is equivalent
25 * to the the LBPRZ flag in the SCSI logical block provisioning page.
26 */
27 bool unallocated_blocks_are_zero;
28 /*
29 * True if the driver can optimize writing zeroes by unmapping
30 * sectors. This is equivalent to the BLKDISCARDZEROES ioctl in Linux
31 * with the difference that in qemu a discard is allowed to silently
32 * fail. Therefore we have to use bdrv_write_zeroes with the
33 * BDRV_REQ_MAY_UNMAP flag for an optimized zero write with unmapping.
34 * After this call the driver has to guarantee that the contents read
35 * back as zero. It is additionally required that the block device is
36 * opened with BDRV_O_UNMAP flag for this to work.
37 */
38 bool can_write_zeroes_with_unmap;
85f49cad
FZ
39 /*
40 * True if this block driver only supports compressed writes
41 */
42 bool needs_compressed_writes;
faf07963
PB
43} BlockDriverInfo;
44
f8111c24
DXW
45typedef struct BlockFragInfo {
46 uint64_t allocated_clusters;
47 uint64_t total_clusters;
48 uint64_t fragmented_clusters;
e6439d78 49 uint64_t compressed_clusters;
f8111c24
DXW
50} BlockFragInfo;
51
6faac15f
PL
52typedef enum {
53 BDRV_REQ_COPY_ON_READ = 0x1,
54 BDRV_REQ_ZERO_WRITE = 0x2,
d32f35cb
PL
55 /* The BDRV_REQ_MAY_UNMAP flag is used to indicate that the block driver
56 * is allowed to optimize a write zeroes request by unmapping (discarding)
57 * blocks if it is guaranteed that the result will read back as
58 * zeroes. The flag is only passed to the driver if the block device is
59 * opened with BDRV_O_UNMAP.
60 */
61 BDRV_REQ_MAY_UNMAP = 0x4,
6faac15f
PL
62} BdrvRequestFlags;
63
892b7de8
ET
64typedef struct BlockSizes {
65 uint32_t phys;
66 uint32_t log;
67} BlockSizes;
68
69typedef struct HDGeometry {
70 uint32_t heads;
71 uint32_t sectors;
72 uint32_t cylinders;
73} HDGeometry;
74
faf07963 75#define BDRV_O_RDWR 0x0002
faf07963 76#define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */
8bfea15d 77#define BDRV_O_TEMPORARY 0x0010 /* delete the file after use */
9f7965c7
AL
78#define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */
79#define BDRV_O_CACHE_WB 0x0040 /* use write-back caching */
5c6c3a6c 80#define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the thread pool */
b783e409 81#define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */
016f5cf6 82#define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */
53fec9d3 83#define BDRV_O_COPY_ON_READ 0x0400 /* copy read backing sectors into image */
ccb1f4a7 84#define BDRV_O_INCOMING 0x0800 /* consistency hint for incoming migration */
058f8f16 85#define BDRV_O_CHECK 0x1000 /* open solely for consistency check */
be028adc 86#define BDRV_O_ALLOW_RDWR 0x2000 /* allow reopen to change from r/o to r/w */
9e8f1835 87#define BDRV_O_UNMAP 0x4000 /* execute guest UNMAP/TRIM operations */
2e40134b
HR
88#define BDRV_O_PROTOCOL 0x8000 /* if no block driver is explicitly given:
89 select an appropriate protocol driver,
90 ignoring the format layer */
9f7965c7 91
ceb25e5c 92#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
faf07963 93
54861b92
KW
94
95/* Option names of options parsed by the block layer */
96
97#define BDRV_OPT_CACHE_WB "cache.writeback"
98#define BDRV_OPT_CACHE_DIRECT "cache.direct"
99#define BDRV_OPT_CACHE_NO_FLUSH "cache.no-flush"
100
101
6ea44308 102#define BDRV_SECTOR_BITS 9
c63782cb 103#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)
3abbc4d9 104#define BDRV_SECTOR_MASK ~(BDRV_SECTOR_SIZE - 1)
6ea44308 105
75af1f34
PL
106#define BDRV_REQUEST_MAX_SECTORS MIN(SIZE_MAX >> BDRV_SECTOR_BITS, \
107 INT_MAX >> BDRV_SECTOR_BITS)
108
705be728
FZ
109/*
110 * Allocation status flags
111 * BDRV_BLOCK_DATA: data is read from bs->file or another file
4333bb71
PB
112 * BDRV_BLOCK_ZERO: sectors read as zero
113 * BDRV_BLOCK_OFFSET_VALID: sector stored in bs->file as raw data
e88ae226
KW
114 * BDRV_BLOCK_ALLOCATED: the content of the block is determined by this
115 * layer (as opposed to the backing file)
92bc50a5
PL
116 * BDRV_BLOCK_RAW: used internally to indicate that the request
117 * was answered by the raw driver and that one
118 * should look in bs->file directly.
4333bb71
PB
119 *
120 * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 represent the offset in
121 * bs->file where sector data can be read from as raw data.
122 *
123 * DATA == 0 && ZERO == 0 means that data is read from backing_hd if present.
124 *
125 * DATA ZERO OFFSET_VALID
126 * t t t sectors read as zero, bs->file is zero at offset
127 * t f t sectors read as valid from bs->file at offset
128 * f t t sectors preallocated, read as zero, bs->file not
129 * necessarily zero at offset
130 * f f t sectors preallocated but read from backing_hd,
131 * bs->file contains garbage at offset
132 * t t f sectors preallocated, read as zero, unknown offset
133 * t f f sectors read from unknown file or offset
134 * f t f not allocated or unknown offset, read as zero
135 * f f f not allocated or unknown offset, read from backing_hd
136 */
e88ae226
KW
137#define BDRV_BLOCK_DATA 0x01
138#define BDRV_BLOCK_ZERO 0x02
139#define BDRV_BLOCK_OFFSET_VALID 0x04
140#define BDRV_BLOCK_RAW 0x08
141#define BDRV_BLOCK_ALLOCATED 0x10
4333bb71
PB
142#define BDRV_BLOCK_OFFSET_MASK BDRV_SECTOR_MASK
143
e971aa12
JC
144typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue;
145
146typedef struct BDRVReopenState {
147 BlockDriverState *bs;
148 int flags;
149 void *opaque;
150} BDRVReopenState;
151
8574575f
FZ
152/*
153 * Block operation types
154 */
155typedef enum BlockOpType {
156 BLOCK_OP_TYPE_BACKUP_SOURCE,
157 BLOCK_OP_TYPE_BACKUP_TARGET,
158 BLOCK_OP_TYPE_CHANGE,
bb00021d
FZ
159 BLOCK_OP_TYPE_COMMIT_SOURCE,
160 BLOCK_OP_TYPE_COMMIT_TARGET,
8574575f
FZ
161 BLOCK_OP_TYPE_DATAPLANE,
162 BLOCK_OP_TYPE_DRIVE_DEL,
163 BLOCK_OP_TYPE_EJECT,
164 BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT,
165 BLOCK_OP_TYPE_INTERNAL_SNAPSHOT,
166 BLOCK_OP_TYPE_INTERNAL_SNAPSHOT_DELETE,
167 BLOCK_OP_TYPE_MIRROR,
168 BLOCK_OP_TYPE_RESIZE,
169 BLOCK_OP_TYPE_STREAM,
09158f00 170 BLOCK_OP_TYPE_REPLACE,
8574575f
FZ
171 BLOCK_OP_TYPE_MAX,
172} BlockOpType;
e971aa12 173
28a7282a
LC
174void bdrv_iostatus_enable(BlockDriverState *bs);
175void bdrv_iostatus_reset(BlockDriverState *bs);
176void bdrv_iostatus_disable(BlockDriverState *bs);
177bool bdrv_iostatus_is_enabled(const BlockDriverState *bs);
178void bdrv_iostatus_set_err(BlockDriverState *bs, int error);
d15e5465
LC
179void bdrv_info_print(Monitor *mon, const QObject *data);
180void bdrv_info(Monitor *mon, QObject **ret_data);
218a536a
LC
181void bdrv_stats_print(Monitor *mon, const QObject *data);
182void bdrv_info_stats(Monitor *mon, QObject **ret_data);
faf07963 183
0563e191 184/* disk I/O throttling */
76f4afb4 185void bdrv_io_limits_enable(BlockDriverState *bs, const char *group);
98f90dba 186void bdrv_io_limits_disable(BlockDriverState *bs);
76f4afb4 187void bdrv_io_limits_update_group(BlockDriverState *bs, const char *group);
0563e191 188
faf07963 189void bdrv_init(void);
eb852011 190void bdrv_init_with_whitelist(void);
98289620 191BlockDriver *bdrv_find_protocol(const char *filename,
b65a5e12
HR
192 bool allow_protocol_prefix,
193 Error **errp);
faf07963 194BlockDriver *bdrv_find_format(const char *format_name);
b64ec4e4
FZ
195BlockDriver *bdrv_find_whitelisted_format(const char *format_name,
196 bool readonly);
0e7e1989 197int bdrv_create(BlockDriver *drv, const char* filename,
c282e1fd
CL
198 QemuOpts *opts, Error **errp);
199int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp);
7f06d47e 200BlockDriverState *bdrv_new_root(void);
e4e9986b 201BlockDriverState *bdrv_new(void);
d22b2f41 202void bdrv_make_anon(BlockDriverState *bs);
4ddc07ca 203void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old);
8802d1fd 204void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top);
c3993cdc 205int bdrv_parse_cache_flags(const char *mode, int *flags);
9e8f1835 206int bdrv_parse_discard_flags(const char *mode, int *flags);
da557aac 207int bdrv_open_image(BlockDriverState **pbs, const char *filename,
f3930ed0
KW
208 QDict *options, const char *bdref_key,
209 BlockDriverState* parent, const BdrvChildRole *child_role,
f7d9fd8c 210 bool allow_none, Error **errp);
8d24cce1 211void bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd);
34b5d2c6 212int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp);
6b8aeca5 213int bdrv_append_temp_snapshot(BlockDriverState *bs, int flags, Error **errp);
ddf5636d
HR
214int bdrv_open(BlockDriverState **pbs, const char *filename,
215 const char *reference, QDict *options, int flags,
216 BlockDriver *drv, Error **errp);
e971aa12
JC
217BlockReopenQueue *bdrv_reopen_queue(BlockReopenQueue *bs_queue,
218 BlockDriverState *bs, int flags);
219int bdrv_reopen_multiple(BlockReopenQueue *bs_queue, Error **errp);
220int bdrv_reopen(BlockDriverState *bs, int bdrv_flags, Error **errp);
221int bdrv_reopen_prepare(BDRVReopenState *reopen_state,
222 BlockReopenQueue *queue, Error **errp);
223void bdrv_reopen_commit(BDRVReopenState *reopen_state);
224void bdrv_reopen_abort(BDRVReopenState *reopen_state);
faf07963 225void bdrv_close(BlockDriverState *bs);
d7d512f6 226void bdrv_add_close_notifier(BlockDriverState *bs, Notifier *notify);
faf07963
PB
227int bdrv_read(BlockDriverState *bs, int64_t sector_num,
228 uint8_t *buf, int nb_sectors);
07d27a44
MA
229int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
230 uint8_t *buf, int nb_sectors);
faf07963
PB
231int bdrv_write(BlockDriverState *bs, int64_t sector_num,
232 const uint8_t *buf, int nb_sectors);
4105eaaa 233int bdrv_write_zeroes(BlockDriverState *bs, int64_t sector_num,
aa7bfbff 234 int nb_sectors, BdrvRequestFlags flags);
7c84b1b8
MA
235BlockAIOCB *bdrv_aio_write_zeroes(BlockDriverState *bs, int64_t sector_num,
236 int nb_sectors, BdrvRequestFlags flags,
097310b5 237 BlockCompletionFunc *cb, void *opaque);
d75cbb5e 238int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
faf07963
PB
239int bdrv_pread(BlockDriverState *bs, int64_t offset,
240 void *buf, int count);
241int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
242 const void *buf, int count);
8d3b1a2d 243int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov);
f08145fe
KW
244int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
245 const void *buf, int count);
da1fa91d
KW
246int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
247 int nb_sectors, QEMUIOVector *qiov);
470c0504
SH
248int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs,
249 int64_t sector_num, int nb_sectors, QEMUIOVector *qiov);
da1fa91d
KW
250int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num,
251 int nb_sectors, QEMUIOVector *qiov);
f08f2dda
SH
252/*
253 * Efficiently zero a region of the disk image. Note that this is a regular
254 * I/O request like read or write and should have a reasonable size. This
255 * function is not suitable for zeroing the entire image in a single request
256 * because it may allocate memory for the entire region.
257 */
258int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
aa7bfbff 259 int nb_sectors, BdrvRequestFlags flags);
e8a6bb9c
MT
260BlockDriverState *bdrv_find_backing_image(BlockDriverState *bs,
261 const char *backing_file);
f198fd1c 262int bdrv_get_backing_file_depth(BlockDriverState *bs);
91af7014 263void bdrv_refresh_filename(BlockDriverState *bs);
faf07963 264int bdrv_truncate(BlockDriverState *bs, int64_t offset);
65a9bb25 265int64_t bdrv_nb_sectors(BlockDriverState *bs);
faf07963 266int64_t bdrv_getlength(BlockDriverState *bs);
4a1d5e1f 267int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
96b8f136 268void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
3baca891 269void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
faf07963 270int bdrv_commit(BlockDriverState *bs);
e8877497 271int bdrv_commit_all(void);
756e6736
KW
272int bdrv_change_backing_file(BlockDriverState *bs,
273 const char *backing_file, const char *backing_fmt);
5efa9d5a 274void bdrv_register(BlockDriver *bdrv);
6ebdcee2 275int bdrv_drop_intermediate(BlockDriverState *active, BlockDriverState *top,
54e26900
JC
276 BlockDriverState *base,
277 const char *backing_file_str);
6ebdcee2
JC
278BlockDriverState *bdrv_find_overlay(BlockDriverState *active,
279 BlockDriverState *bs);
79fac568 280BlockDriverState *bdrv_find_base(BlockDriverState *bs);
5efa9d5a 281
e076f338
KW
282
283typedef struct BdrvCheckResult {
284 int corruptions;
285 int leaks;
286 int check_errors;
ccf34716
KW
287 int corruptions_fixed;
288 int leaks_fixed;
c6bb9ad1 289 int64_t image_end_offset;
f8111c24 290 BlockFragInfo bfi;
e076f338
KW
291} BdrvCheckResult;
292
4534ff54
KW
293typedef enum {
294 BDRV_FIX_LEAKS = 1,
295 BDRV_FIX_ERRORS = 2,
296} BdrvCheckMode;
297
298int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
e076f338 299
77485434
HR
300/* The units of offset and total_work_size may be chosen arbitrarily by the
301 * block driver; total_work_size may change during the course of the amendment
302 * operation */
303typedef void BlockDriverAmendStatusCB(BlockDriverState *bs, int64_t offset,
304 int64_t total_work_size);
305int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts,
306 BlockDriverAmendStatusCB *status_cb);
6f176b48 307
f6186f49 308/* external snapshots */
212a5a8f
BC
309bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs,
310 BlockDriverState *candidate);
311bool bdrv_is_first_non_filter(BlockDriverState *candidate);
f6186f49 312
09158f00
BC
313/* check if a named node can be replaced when doing drive-mirror */
314BlockDriverState *check_to_replace_node(const char *node_name, Error **errp);
315
faf07963 316/* async block I/O */
7cd1e32a 317typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
39aa9a12 318 int sector_num);
7c84b1b8
MA
319BlockAIOCB *bdrv_aio_readv(BlockDriverState *bs, int64_t sector_num,
320 QEMUIOVector *iov, int nb_sectors,
097310b5 321 BlockCompletionFunc *cb, void *opaque);
7c84b1b8
MA
322BlockAIOCB *bdrv_aio_writev(BlockDriverState *bs, int64_t sector_num,
323 QEMUIOVector *iov, int nb_sectors,
097310b5 324 BlockCompletionFunc *cb, void *opaque);
7c84b1b8 325BlockAIOCB *bdrv_aio_flush(BlockDriverState *bs,
097310b5 326 BlockCompletionFunc *cb, void *opaque);
7c84b1b8
MA
327BlockAIOCB *bdrv_aio_discard(BlockDriverState *bs,
328 int64_t sector_num, int nb_sectors,
097310b5 329 BlockCompletionFunc *cb, void *opaque);
7c84b1b8
MA
330void bdrv_aio_cancel(BlockAIOCB *acb);
331void bdrv_aio_cancel_async(BlockAIOCB *acb);
faf07963 332
40b4f539
KW
333typedef struct BlockRequest {
334 /* Fields to be filled by multiwrite caller */
335 int64_t sector;
336 int nb_sectors;
d20d9b7c 337 int flags;
40b4f539 338 QEMUIOVector *qiov;
097310b5 339 BlockCompletionFunc *cb;
40b4f539
KW
340 void *opaque;
341
342 /* Filled by multiwrite implementation */
343 int error;
344} BlockRequest;
345
346int bdrv_aio_multiwrite(BlockDriverState *bs, BlockRequest *reqs,
347 int num_reqs);
348
7d780669 349/* sg packet commands */
221f715d 350int bdrv_ioctl(BlockDriverState *bs, unsigned long int req, void *buf);
7c84b1b8 351BlockAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
221f715d 352 unsigned long int req, void *buf,
097310b5 353 BlockCompletionFunc *cb, void *opaque);
7d780669 354
0f15423c 355/* Invalidate any cached metadata used by image formats */
5a8a30db
KW
356void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
357void bdrv_invalidate_cache_all(Error **errp);
0f15423c 358
faf07963 359/* Ensure contents are flushed to disk. */
205ef796 360int bdrv_flush(BlockDriverState *bs);
07f07615 361int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
f0f0fdfe 362int bdrv_flush_all(void);
2bc93fed 363void bdrv_close_all(void);
5b98db0a 364void bdrv_drain(BlockDriverState *bs);
922453bc 365void bdrv_drain_all(void);
c6ca28d6 366
bb8bf76f 367int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
4265d620 368int bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors);
3ac21627 369int bdrv_has_zero_init_1(BlockDriverState *bs);
f2feebbd 370int bdrv_has_zero_init(BlockDriverState *bs);
4ce78691
PL
371bool bdrv_unallocated_blocks_are_zero(BlockDriverState *bs);
372bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs);
b6b8a333
PB
373int64_t bdrv_get_block_status(BlockDriverState *bs, int64_t sector_num,
374 int nb_sectors, int *pnum);
f58c7b35 375int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
39aa9a12 376 int *pnum);
b35b2bba
MR
377int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base,
378 int64_t sector_num, int nb_sectors, int *pnum);
faf07963 379
ff06f5f3
PB
380void bdrv_set_on_error(BlockDriverState *bs, BlockdevOnError on_read_error,
381 BlockdevOnError on_write_error);
1ceee0d5 382BlockdevOnError bdrv_get_on_error(BlockDriverState *bs, bool is_read);
3e1caa5f
PB
383BlockErrorAction bdrv_get_error_action(BlockDriverState *bs, bool is_read, int error);
384void bdrv_error_action(BlockDriverState *bs, BlockErrorAction action,
385 bool is_read, int error);
faf07963 386int bdrv_is_read_only(BlockDriverState *bs);
985a03b0 387int bdrv_is_sg(BlockDriverState *bs);
e900a7b7 388int bdrv_enable_write_cache(BlockDriverState *bs);
425b0148 389void bdrv_set_enable_write_cache(BlockDriverState *bs, bool wce);
faf07963
PB
390int bdrv_is_inserted(BlockDriverState *bs);
391int bdrv_media_changed(BlockDriverState *bs);
025e849a 392void bdrv_lock_medium(BlockDriverState *bs, bool locked);
f36f3949 393void bdrv_eject(BlockDriverState *bs, bool eject_flag);
f8d6bba1 394const char *bdrv_get_format_name(BlockDriverState *bs);
dc364f4c 395BlockDriverState *bdrv_find_node(const char *node_name);
d5a8ee60 396BlockDeviceInfoList *bdrv_named_nodes_list(Error **errp);
12d3ba82
BC
397BlockDriverState *bdrv_lookup_bs(const char *device,
398 const char *node_name,
399 Error **errp);
5a6684d2 400bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base);
04df765a 401BlockDriverState *bdrv_next_node(BlockDriverState *bs);
2f399b0a 402BlockDriverState *bdrv_next(BlockDriverState *bs);
faf07963 403int bdrv_is_encrypted(BlockDriverState *bs);
c0f4ce77 404int bdrv_key_required(BlockDriverState *bs);
faf07963 405int bdrv_set_key(BlockDriverState *bs, const char *key);
4d2855a3 406void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp);
c0f4ce77 407int bdrv_query_missing_keys(void);
faf07963
PB
408void bdrv_iterate_format(void (*it)(void *opaque, const char *name),
409 void *opaque);
20a9e77d 410const char *bdrv_get_node_name(const BlockDriverState *bs);
bfb197e0 411const char *bdrv_get_device_name(const BlockDriverState *bs);
9b2aa84f 412const char *bdrv_get_device_or_node_name(const BlockDriverState *bs);
c8433287 413int bdrv_get_flags(BlockDriverState *bs);
faf07963
PB
414int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
415 const uint8_t *buf, int nb_sectors);
416int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi);
eae041fe 417ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs);
343bded4
PB
418void bdrv_round_to_clusters(BlockDriverState *bs,
419 int64_t sector_num, int nb_sectors,
420 int64_t *cluster_sector_num,
421 int *cluster_nb_sectors);
faf07963 422
045df330 423const char *bdrv_get_encrypted_filename(BlockDriverState *bs);
faf07963
PB
424void bdrv_get_backing_filename(BlockDriverState *bs,
425 char *filename, int filename_size);
dc5a1371 426void bdrv_get_full_backing_filename(BlockDriverState *bs,
9f07429e 427 char *dest, size_t sz, Error **errp);
0a82855a
HR
428void bdrv_get_full_backing_filename_from_filename(const char *backed,
429 const char *backing,
9f07429e
HR
430 char *dest, size_t sz,
431 Error **errp);
199630b6 432int bdrv_is_snapshot(BlockDriverState *bs);
faf07963 433
5c98415b 434int path_has_protocol(const char *path);
faf07963
PB
435int path_is_absolute(const char *path);
436void path_combine(char *dest, int dest_size,
437 const char *base_path,
438 const char *filename);
439
cf8074b3 440int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos);
45566e9c
CH
441int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf,
442 int64_t pos, int size);
178e08a5 443
45566e9c
CH
444int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf,
445 int64_t pos, int size);
178e08a5 446
d92ada22
LC
447void bdrv_img_create(const char *filename, const char *fmt,
448 const char *base_filename, const char *base_fmt,
f382d43a
MR
449 char *options, uint64_t img_size, int flags,
450 Error **errp, bool quiet);
f88e1a42 451
339064d5
KW
452/* Returns the alignment in bytes that is required so that no bounce buffer
453 * is required throughout the stack */
4196d2f0
DL
454size_t bdrv_min_mem_align(BlockDriverState *bs);
455/* Returns optimal alignment in bytes for bounce buffer */
339064d5 456size_t bdrv_opt_mem_align(BlockDriverState *bs);
1b7fd729 457void bdrv_set_guest_block_size(BlockDriverState *bs, int align);
ba5b7ad4 458void *qemu_blockalign(BlockDriverState *bs, size_t size);
9ebd8448 459void *qemu_blockalign0(BlockDriverState *bs, size_t size);
7d2a35cc 460void *qemu_try_blockalign(BlockDriverState *bs, size_t size);
9ebd8448 461void *qemu_try_blockalign0(BlockDriverState *bs, size_t size);
c53b1c51 462bool bdrv_qiov_is_aligned(BlockDriverState *bs, QEMUIOVector *qiov);
ba5b7ad4 463
8f0720ec 464struct HBitmapIter;
e4654d2d 465typedef struct BdrvDirtyBitmap BdrvDirtyBitmap;
0db6e54a 466BdrvDirtyBitmap *bdrv_create_dirty_bitmap(BlockDriverState *bs,
5fba6c0e 467 uint32_t granularity,
0db6e54a 468 const char *name,
b8afb520 469 Error **errp);
9bd2b08f
JS
470int bdrv_dirty_bitmap_create_successor(BlockDriverState *bs,
471 BdrvDirtyBitmap *bitmap,
472 Error **errp);
473BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverState *bs,
474 BdrvDirtyBitmap *bitmap,
475 Error **errp);
476BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs,
477 BdrvDirtyBitmap *bitmap,
478 Error **errp);
0db6e54a
FZ
479BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs,
480 const char *name);
20dca810 481void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap);
e4654d2d 482void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap);
b8e6fb75
JS
483void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
484void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap);
21b56835 485BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs);
341ebc2f 486uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs);
592fdd02 487uint32_t bdrv_dirty_bitmap_granularity(BdrvDirtyBitmap *bitmap);
b8e6fb75 488bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap);
9bd2b08f 489bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap);
9abe3bdc 490DirtyBitmapStatus bdrv_dirty_bitmap_status(BdrvDirtyBitmap *bitmap);
e4654d2d 491int bdrv_get_dirty(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, int64_t sector);
20dca810 492void bdrv_set_dirty_bitmap(BdrvDirtyBitmap *bitmap,
c4237dfa 493 int64_t cur_sector, int nr_sectors);
20dca810 494void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap,
c4237dfa 495 int64_t cur_sector, int nr_sectors);
e74e6b78 496void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap);
20dca810 497void bdrv_dirty_iter_init(BdrvDirtyBitmap *bitmap, struct HBitmapIter *hbi);
d58d8453 498void bdrv_set_dirty_iter(struct HBitmapIter *hbi, int64_t offset);
20dca810 499int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap);
8b9b0cc2 500
53fec9d3
SH
501void bdrv_enable_copy_on_read(BlockDriverState *bs);
502void bdrv_disable_copy_on_read(BlockDriverState *bs);
503
9fcb0251
FZ
504void bdrv_ref(BlockDriverState *bs);
505void bdrv_unref(BlockDriverState *bs);
8b9b0cc2 506
fbe40ff7
FZ
507bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
508void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
509void bdrv_op_unblock(BlockDriverState *bs, BlockOpType op, Error *reason);
510void bdrv_op_block_all(BlockDriverState *bs, Error *reason);
511void bdrv_op_unblock_all(BlockDriverState *bs, Error *reason);
512bool bdrv_op_blocker_is_empty(BlockDriverState *bs);
513
8b9b0cc2 514typedef enum {
8252278a
KW
515 BLKDBG_L1_UPDATE,
516
517 BLKDBG_L1_GROW_ALLOC_TABLE,
518 BLKDBG_L1_GROW_WRITE_TABLE,
519 BLKDBG_L1_GROW_ACTIVATE_TABLE,
520
521 BLKDBG_L2_LOAD,
522 BLKDBG_L2_UPDATE,
523 BLKDBG_L2_UPDATE_COMPRESSED,
524 BLKDBG_L2_ALLOC_COW_READ,
525 BLKDBG_L2_ALLOC_WRITE,
526
8252278a 527 BLKDBG_READ_AIO,
8252278a
KW
528 BLKDBG_READ_BACKING_AIO,
529 BLKDBG_READ_COMPRESSED,
530
531 BLKDBG_WRITE_AIO,
532 BLKDBG_WRITE_COMPRESSED,
533
534 BLKDBG_VMSTATE_LOAD,
535 BLKDBG_VMSTATE_SAVE,
536
537 BLKDBG_COW_READ,
538 BLKDBG_COW_WRITE,
539
540 BLKDBG_REFTABLE_LOAD,
541 BLKDBG_REFTABLE_GROW,
afa50193 542 BLKDBG_REFTABLE_UPDATE,
8252278a
KW
543
544 BLKDBG_REFBLOCK_LOAD,
545 BLKDBG_REFBLOCK_UPDATE,
546 BLKDBG_REFBLOCK_UPDATE_PART,
547 BLKDBG_REFBLOCK_ALLOC,
548 BLKDBG_REFBLOCK_ALLOC_HOOKUP,
549 BLKDBG_REFBLOCK_ALLOC_WRITE,
550 BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS,
551 BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE,
552 BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE,
553
554 BLKDBG_CLUSTER_ALLOC,
555 BLKDBG_CLUSTER_ALLOC_BYTES,
556 BLKDBG_CLUSTER_FREE,
557
bf736fe3
KW
558 BLKDBG_FLUSH_TO_OS,
559 BLKDBG_FLUSH_TO_DISK,
560
9e1cb96d
KW
561 BLKDBG_PWRITEV_RMW_HEAD,
562 BLKDBG_PWRITEV_RMW_AFTER_HEAD,
563 BLKDBG_PWRITEV_RMW_TAIL,
564 BLKDBG_PWRITEV_RMW_AFTER_TAIL,
565 BLKDBG_PWRITEV,
566 BLKDBG_PWRITEV_ZERO,
567 BLKDBG_PWRITEV_DONE,
568
94054183
HR
569 BLKDBG_EMPTY_IMAGE_PREPARE,
570
8b9b0cc2
KW
571 BLKDBG_EVENT_MAX,
572} BlkDebugEvent;
573
574#define BLKDBG_EVENT(bs, evt) bdrv_debug_event(bs, evt)
575void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event);
576
41c695c7
KW
577int bdrv_debug_breakpoint(BlockDriverState *bs, const char *event,
578 const char *tag);
4cc70e93 579int bdrv_debug_remove_breakpoint(BlockDriverState *bs, const char *tag);
41c695c7
KW
580int bdrv_debug_resume(BlockDriverState *bs, const char *tag);
581bool bdrv_debug_is_suspended(BlockDriverState *bs, const char *tag);
582
db519cba
FZ
583/**
584 * bdrv_get_aio_context:
585 *
586 * Returns: the currently bound #AioContext
587 */
588AioContext *bdrv_get_aio_context(BlockDriverState *bs);
589
dcd04228
SH
590/**
591 * bdrv_set_aio_context:
592 *
593 * Changes the #AioContext used for fd handlers, timers, and BHs by this
594 * BlockDriverState and all its children.
595 *
2e5b887c 596 * This function must be called with iothread lock held.
dcd04228
SH
597 */
598void bdrv_set_aio_context(BlockDriverState *bs, AioContext *new_context);
892b7de8
ET
599int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz);
600int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo);
dcd04228 601
448ad91d
ML
602void bdrv_io_plug(BlockDriverState *bs);
603void bdrv_io_unplug(BlockDriverState *bs);
604void bdrv_flush_io_queue(BlockDriverState *bs);
605
5366d0c8
BC
606BlockAcctStats *bdrv_get_stats(BlockDriverState *bs);
607
8a4bc5aa 608#endif