From cb42a1b1461e02efb034582ac5d8f71534723b92 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 23 Dec 2010 02:54:08 +0100 Subject: upstream: integrate block changes This large patch upgrades the block support code to the upstream version available in ba5e7f82169f32ab8163c707d97c799ca09f8924 dated 2010-08-08 Change-Id: I8b24df0c287e72f6620650a4d6a62e1bb315453e --- block_int.h | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 11 deletions(-) (limited to 'block_int.h') diff --git a/block_int.h b/block_int.h index 32b66b5..b863451 100644 --- a/block_int.h +++ b/block_int.h @@ -26,6 +26,7 @@ #include "block.h" #include "qemu-option.h" +#include "qemu-queue.h" #define BLOCK_FLAG_ENCRYPT 1 #define BLOCK_FLAG_COMPRESS 2 @@ -50,7 +51,8 @@ struct BlockDriver { int instance_size; int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); int (*bdrv_probe_device)(const char *filename); - int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags); + int (*bdrv_open)(BlockDriverState *bs, int flags); + int (*bdrv_file_open)(BlockDriverState *bs, const char *filename, int flags); int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num, @@ -69,6 +71,14 @@ struct BlockDriver { BlockDriverAIOCB *(*bdrv_aio_writev)(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); + BlockDriverAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, + BlockDriverCompletionFunc *cb, void *opaque); + + int (*bdrv_aio_multiwrite)(BlockDriverState *bs, BlockRequest *reqs, + int num_reqs); + int (*bdrv_merge_requests)(BlockDriverState *bs, BlockRequest* a, + BlockRequest *b); + const char *protocol_name; int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset); @@ -85,10 +95,13 @@ struct BlockDriver { QEMUSnapshotInfo **psn_info); int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); - int (*bdrv_put_buffer)(BlockDriverState *bs, const uint8_t *buf, - int64_t pos, int size); - int (*bdrv_get_buffer)(BlockDriverState *bs, uint8_t *buf, - int64_t pos, int size); + int (*bdrv_save_vmstate)(BlockDriverState *bs, const uint8_t *buf, + int64_t pos, int size); + int (*bdrv_load_vmstate)(BlockDriverState *bs, uint8_t *buf, + int64_t pos, int size); + + int (*bdrv_change_backing_file)(BlockDriverState *bs, + const char *backing_file, const char *backing_fmt); /* removable device specific */ int (*bdrv_is_inserted)(BlockDriverState *bs); @@ -106,21 +119,36 @@ struct BlockDriver { QEMUOptionParameter *create_options; - /* Returns number of errors in image, -errno for internal errors */ - int (*bdrv_check)(BlockDriverState* bs); + /* + * Returns 0 for completed check, -errno for internal errors. + * The check results are stored in result. + */ + int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result); + + void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event); + + /* + * Returns 1 if newly created images are guaranteed to contain only + * zeros, 0 otherwise. + */ + int (*bdrv_has_zero_init)(BlockDriverState *bs); - struct BlockDriver *next; + QLIST_ENTRY(BlockDriver) list; }; struct BlockDriverState { int64_t total_sectors; /* if we are reading a disk image, give its size in sectors */ int read_only; /* if true, the media is read only */ + int keep_read_only; /* if true, the media was requested to stay read only */ + int open_flags; /* flags used to open the file, re-used for re-open */ int removable; /* if true, the media can be removed */ int locked; /* if true, the media cannot temporarily be ejected */ + int tray_open; /* if true, the virtual tray is open */ int encrypted; /* if true, the media is encrypted */ int valid_key; /* if true, a valid encryption key has been set */ int sg; /* if true, the device is a /dev/sg* */ + int probed; /* if true, format was probed automatically */ /* event callback when inserting/removing */ void (*change_cb)(void *opaque); void *change_opaque; @@ -128,6 +156,8 @@ struct BlockDriverState { BlockDriver *drv; /* NULL means no media */ void *opaque; + DeviceState *peer; + char filename[1024]; char backing_file[1024]; /* if non zero, the image is a diff of this file image */ @@ -136,6 +166,8 @@ struct BlockDriverState { int media_changed; BlockDriverState *backing_hd; + BlockDriverState *file; + /* async read/write emulation */ void *sync_aiocb; @@ -145,6 +177,7 @@ struct BlockDriverState { uint64_t wr_bytes; uint64_t rd_ops; uint64_t wr_ops; + uint64_t wr_highest_sector; /* Whether the disk can expand beyond total_sectors */ int growable; @@ -152,12 +185,18 @@ struct BlockDriverState { /* the memory alignment required for the buffers handled by this driver */ int buffer_alignment; + /* do we need to tell the quest if we have a volatile write cache? */ + int enable_write_cache; + /* NOTE: the following infos are only hints for real hardware drivers. They are not used by the block driver */ int cyls, heads, secs, translation; int type; + BlockErrorAction on_read_error, on_write_error; char device_name[32]; - BlockDriverState *next; + unsigned long *dirty_bitmap; + int64_t dirty_count; + QTAILQ_ENTRY(BlockDriverState) list; void *private; }; @@ -177,10 +216,38 @@ void qemu_aio_release(void *p); void *qemu_blockalign(BlockDriverState *bs, size_t size); -extern BlockDriverState *bdrv_first; - #ifdef _WIN32 int is_windows_drive(const char *filename); #endif +typedef struct BlockConf { + BlockDriverState *bs; + uint16_t physical_block_size; + uint16_t logical_block_size; + uint16_t min_io_size; + uint32_t opt_io_size; +} BlockConf; + +static inline unsigned int get_physical_block_exp(BlockConf *conf) +{ + unsigned int exp = 0, size; + + for (size = conf->physical_block_size; + size > conf->logical_block_size; + size >>= 1) { + exp++; + } + + return exp; +} + +#define DEFINE_BLOCK_PROPERTIES(_state, _conf) \ + DEFINE_PROP_DRIVE("drive", _state, _conf.bs), \ + DEFINE_PROP_UINT16("logical_block_size", _state, \ + _conf.logical_block_size, 512), \ + DEFINE_PROP_UINT16("physical_block_size", _state, \ + _conf.physical_block_size, 512), \ + DEFINE_PROP_UINT16("min_io_size", _state, _conf.min_io_size, 0), \ + DEFINE_PROP_UINT32("opt_io_size", _state, _conf.opt_io_size, 0) + #endif /* BLOCK_INT_H */ -- cgit v1.1