[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] ioemu block device extent checks
Daniel P. Berrange writes ("Re: [Xen-devel] [PATCH] ioemu block device extent checks"): > The qcow driver though calls back into > the raw driver for performing I/O on its underlying file. The qcow > driver relies on this file being grow-on-demand for purposes of allocating > new qcow sectors. The safety checks cause this allocation to fail and > it all goes downhill from there :-( Oh dear. (I'm a bit surprised that it's taken this long to spot!) Here is a patch for xen-unstable which I think will fix it. Could you give it a quick spin, if you have a suitable test setup ? Sadly it's rather more intrusive than ideal, since it needs all of the drivers which are going to extend files via their parents to announce this, and a couple of bits of necessary infrastructure needed adding. Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> diff -r 757cd7bb5e35 tools/ioemu/block-qcow.c --- a/tools/ioemu/block-qcow.c Fri Feb 22 16:49:56 2008 +0000 +++ b/tools/ioemu/block-qcow.c Wed Feb 27 11:09:56 2008 +0000 @@ -95,7 +95,7 @@ static int qcow_open(BlockDriverState *b int len, i, shift, ret; QCowHeader header; - ret = bdrv_file_open(&s->hd, filename, flags); + ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE); if (ret < 0) return ret; if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != sizeof(header)) diff -r 757cd7bb5e35 tools/ioemu/block-qcow2.c --- a/tools/ioemu/block-qcow2.c Fri Feb 22 16:49:56 2008 +0000 +++ b/tools/ioemu/block-qcow2.c Wed Feb 27 11:09:56 2008 +0000 @@ -191,7 +191,7 @@ static int qcow_open(BlockDriverState *b int len, i, shift, ret; QCowHeader header; - ret = bdrv_file_open(&s->hd, filename, flags); + ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE); if (ret < 0) return ret; if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != sizeof(header)) diff -r 757cd7bb5e35 tools/ioemu/block-raw.c --- a/tools/ioemu/block-raw.c Fri Feb 22 16:49:56 2008 +0000 +++ b/tools/ioemu/block-raw.c Wed Feb 27 11:12:28 2008 +0000 @@ -1489,5 +1489,7 @@ BlockDriver bdrv_host_device = { .bdrv_pread = raw_pread, .bdrv_pwrite = raw_pwrite, .bdrv_getlength = raw_getlength, + + .bdrv_flags = BLOCK_DRIVER_FLAG_EXTENDABLE }; #endif /* _WIN32 */ diff -r 757cd7bb5e35 tools/ioemu/block-vmdk.c --- a/tools/ioemu/block-vmdk.c Fri Feb 22 16:49:56 2008 +0000 +++ b/tools/ioemu/block-vmdk.c Wed Feb 27 11:10:02 2008 +0000 @@ -352,7 +352,7 @@ static int vmdk_open(BlockDriverState *b uint32_t magic; int l1_size, i, ret; - ret = bdrv_file_open(&s->hd, filename, flags); + ret = bdrv_file_open(&s->hd, filename, flags | BDRV_O_EXTENDABLE); if (ret < 0) return ret; if (bdrv_pread(s->hd, 0, &magic, sizeof(magic)) != sizeof(magic)) diff -r 757cd7bb5e35 tools/ioemu/block.c --- a/tools/ioemu/block.c Fri Feb 22 16:49:56 2008 +0000 +++ b/tools/ioemu/block.c Wed Feb 27 11:13:57 2008 +0000 @@ -123,20 +123,23 @@ static int bdrv_rw_badreq_sectors(BlockD static int bdrv_rw_badreq_sectors(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { - return + return ( nb_sectors < 0 || nb_sectors > bs->total_sectors || - sector_num > bs->total_sectors - nb_sectors; + sector_num > bs->total_sectors - nb_sectors + ) && !bs->extendable; } static int bdrv_rw_badreq_bytes(BlockDriverState *bs, int64_t offset, int count) { int64_t size = bs->total_sectors << SECTOR_BITS; - return + return ( count < 0 || count > size || - offset > size - count; + offset > size - count + ) && !bs->extendable; + } void bdrv_register(BlockDriver *bdrv) @@ -347,6 +350,12 @@ int bdrv_open2(BlockDriverState *bs, con bs->is_temporary = 0; bs->encrypted = 0; + if (flags & BDRV_O_EXTENDABLE) { + if (!(drv->bdrv_flags & BLOCK_DRIVER_FLAG_EXTENDABLE)) + return -ENOSYS; + bs->extendable = 1; + } + if (flags & BDRV_O_SNAPSHOT) { BlockDriverState *bs1; int64_t total_size; diff -r 757cd7bb5e35 tools/ioemu/block_int.h --- a/tools/ioemu/block_int.h Fri Feb 22 16:49:56 2008 +0000 +++ b/tools/ioemu/block_int.h Wed Feb 27 11:11:39 2008 +0000 @@ -23,6 +23,8 @@ */ #ifndef BLOCK_INT_H #define BLOCK_INT_H + +#define BLOCK_DRIVER_FLAG_EXTENDABLE 0x0001u struct BlockDriver { const char *format_name; @@ -76,6 +78,7 @@ struct BlockDriver { int (*bdrv_eject)(BlockDriverState *bs, int eject_flag); int (*bdrv_set_locked)(BlockDriverState *bs, int locked); + unsigned bdrv_flags; BlockDriverAIOCB *free_aiocb; struct BlockDriver *next; }; @@ -87,6 +90,7 @@ struct BlockDriverState { int removable; /* if true, the media can be removed */ int locked; /* if true, the media cannot temporarily be ejected */ int encrypted; /* if true, the media is encrypted */ + int extendable;/* if true, we may write out of original range */ /* event callback when inserting/removing */ void (*change_cb)(void *opaque); void *change_opaque; diff -r 757cd7bb5e35 tools/ioemu/vl.h --- a/tools/ioemu/vl.h Fri Feb 22 16:49:56 2008 +0000 +++ b/tools/ioemu/vl.h Wed Feb 27 11:12:03 2008 +0000 @@ -614,6 +614,8 @@ typedef struct QEMUSnapshotInfo { use a disk image format on top of it (default for bdrv_file_open()) */ +#define BDRV_O_EXTENDABLE 0x0080 /* allow writes out of original size range; + only effective for some drivers */ void bdrv_init(void); BlockDriver *bdrv_find_format(const char *format_name); _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |