[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] [blktap] Fix block device getsize bug in qcow when backing_filename is a block device.
# HG changeset patch # User jchesterfield@xxxxxxxxxxxxxxxxxxxxxxx # Node ID 323a89a3c01c6c1c0b421b5ff9877ab3d3b31364 # Parent 45746c770018bc8ab54b39d5798bfd47eeb73cbc [blktap] Fix block device getsize bug in qcow when backing_filename is a block device. --- tools/blktap/drivers/block-qcow.c | 29 +++++++++++++++++++++++++---- 1 files changed, 25 insertions(+), 4 deletions(-) diff -r 45746c770018 -r 323a89a3c01c tools/blktap/drivers/block-qcow.c --- a/tools/blktap/drivers/block-qcow.c Tue Sep 05 14:28:19 2006 +0100 +++ b/tools/blktap/drivers/block-qcow.c Tue Sep 05 15:35:42 2006 +0100 @@ -235,6 +235,25 @@ static uint32_t gen_cksum(char *ptr, int memcpy(&ret, md, sizeof(uint32_t)); free(md); return ret; +} + +static int get_filesize(char *filename, uint64_t *size, struct stat *st) +{ + int blockfd; + + /*Set to the backing file size*/ + if(S_ISBLK(st->st_mode)) { + blockfd = open(filename, O_RDONLY); + if (blockfd < 0) + return -1; + if (ioctl(blockfd,BLKGETSIZE,size)!=0) { + printf("Unable to get Block device size\n"); + close(blockfd); + return -1; + } + close(blockfd); + } else *size = (st->st_size >> SECTOR_SHIFT); + return 0; } static int qcow_set_key(struct td_state *bs, const char *key) @@ -1204,12 +1223,14 @@ int qcow_create(const char *filename, ui header_size += backing_filename_len; /*Set to the backing file size*/ - size = (st.st_size >> SECTOR_SHIFT); + if(get_filesize(backing_filename, &size, &st)) { + return -1; + } DPRINTF("Backing file size detected: %lld sectors" "(total %lld [%lld MB])\n", - (long long)total_size, - (long long)(total_size << SECTOR_SHIFT), - (long long)(total_size >> 11)); + (long long)size, + (long long)(size << SECTOR_SHIFT), + (long long)(size >> 11)); } else { backing_file = NULL; DPRINTF("Setting file size: %lld (total %lld)\n", _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |