ia64/xen-unstable

changeset 19701:f989778298d8

blktap: fix and use ROUNDUP macro (bug 1430 part 1)

As pointed out in Xen Bugzilla 1430 in the blktap QCOW driver the
rounding function is wrong in line 824 of block-qcow.c.
This patch replaces this (and other roundings) with the already
existing ROUNDUP macro (and fixes the usual macro pitfall).

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 03 11:11:04 2009 +0100 (2009-06-03)
parents e7b63b30ae3d
children c5fb6374e79f
files tools/blktap/drivers/block-qcow.c
line diff
     1.1 --- a/tools/blktap/drivers/block-qcow.c	Wed Jun 03 11:10:07 2009 +0100
     1.2 +++ b/tools/blktap/drivers/block-qcow.c	Wed Jun 03 11:11:04 2009 +0100
     1.3 @@ -55,7 +55,7 @@
     1.4  #define ROUNDUP(l, s) \
     1.5  ({ \
     1.6      (uint64_t)( \
     1.7 -        (l + (s - 1)) - ((l + (s - 1)) % s)); \
     1.8 +        ((l) + ((s) - 1)) - (((l) + ((s) - 1)) % (s))); \
     1.9  })
    1.10  
    1.11  #undef IOCB_IDX
    1.12 @@ -800,14 +800,14 @@ static int tdqcow_open (struct disk_driv
    1.13  
    1.14  	/* read the level 1 table */
    1.15  	shift = s->cluster_bits + s->l2_bits;
    1.16 -	s->l1_size = (header->size + (1LL << shift) - 1) >> shift;
    1.17 +	s->l1_size = ROUNDUP(header->size, 1LL << shift);
    1.18  	
    1.19  	s->l1_table_offset = header->l1_table_offset;
    1.20  
    1.21  	/*allocate a 4Kbyte multiple of memory*/
    1.22  	l1_table_size = s->l1_size * sizeof(uint64_t);
    1.23  	if (l1_table_size % 4096 > 0) {
    1.24 -		l1_table_size = ((l1_table_size >> 12) + 1) << 12;
    1.25 +		l1_table_size = ROUNDUP(l1_table_size, 4096);
    1.26  	}
    1.27  	ret = posix_memalign((void **)&s->l1_table, 4096, l1_table_size);
    1.28  	if (ret != 0) goto fail;
    1.29 @@ -821,7 +821,7 @@ static int tdqcow_open (struct disk_driv
    1.30  
    1.31  	lseek(fd, 0, SEEK_SET);
    1.32  	l1_table_block = l1_table_size + s->l1_table_offset;
    1.33 -	l1_table_block = l1_table_block + 512 - (l1_table_block % 512); 
    1.34 +	l1_table_block = ROUNDUP(l1_table_block, 512);
    1.35  	ret = posix_memalign((void **)&buf2, 4096, l1_table_block);
    1.36  	if (ret != 0) goto fail;
    1.37  	if (read(fd, buf2, l1_table_block) != l1_table_block)
    1.38 @@ -1226,11 +1226,11 @@ int qcow_create(const char *filename, ui
    1.39  	
    1.40  	header_size = (header_size + 7) & ~7;
    1.41  	if (header_size % 4096 > 0) {
    1.42 -		header_size = ((header_size >> 12) + 1) << 12;
    1.43 +		header_size = ROUNDUP(header_size, 4096);
    1.44  	}
    1.45  
    1.46  	shift = header.cluster_bits + header.l2_bits;
    1.47 -	l1_size = ((size * 512) + (1LL << shift) - 1) >> shift;
    1.48 +	l1_size = ROUNDUP(size * 512, 1LL << shift);
    1.49  
    1.50  	header.l1_table_offset = cpu_to_be64(header_size);
    1.51  	DPRINTF("L1 Table offset: %d, size %d\n",