ia64/xen-unstable

changeset 19702:c5fb6374e79f

blktap: fix empty QCOW images (bug 1430 part 2)

Empty QCOW images consist of only the L1 table, this results in a
file size which is not sector-aligned. Since blktap uses O_DIRECT, the
block aligned read of the L1 table will go beyond the end of file and
thus returns the actual file size and not the expected length.
This patch checks whether at least the L1 table has been read.

This should fix bug 1430.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 03 11:11:50 2009 +0100 (2009-06-03)
parents f989778298d8
children 3ee4e1884c4e
files tools/blktap/drivers/block-qcow.c
line diff
     1.1 --- a/tools/blktap/drivers/block-qcow.c	Wed Jun 03 11:11:04 2009 +0100
     1.2 +++ b/tools/blktap/drivers/block-qcow.c	Wed Jun 03 11:11:50 2009 +0100
     1.3 @@ -824,7 +824,7 @@ static int tdqcow_open (struct disk_driv
     1.4  	l1_table_block = ROUNDUP(l1_table_block, 512);
     1.5  	ret = posix_memalign((void **)&buf2, 4096, l1_table_block);
     1.6  	if (ret != 0) goto fail;
     1.7 -	if (read(fd, buf2, l1_table_block) != l1_table_block)
     1.8 +	if (read(fd, buf2, l1_table_block) < l1_table_size + s->l1_table_offset)
     1.9  		goto fail;
    1.10  	memcpy(s->l1_table, buf2 + s->l1_table_offset, l1_table_size);
    1.11  
    1.12 @@ -878,7 +878,8 @@ static int tdqcow_open (struct disk_driv
    1.13  
    1.14  			memcpy(buf2 + s->l1_table_offset, s->l1_table, l1_table_size);
    1.15  			lseek(fd, 0, SEEK_SET);
    1.16 -			if (write(fd, buf2, l1_table_block) != l1_table_block) {
    1.17 +			if (write(fd, buf2, l1_table_block) < 
    1.18 +				l1_table_size + s->l1_table_offset) {
    1.19  				DPRINTF("qcow: Failed to write new L1 table\n");
    1.20  				goto fail;
    1.21  			}