ia64/xen-unstable

changeset 12619:4666710bfc55

[BLKTAP] Use lartge enough types to express parameters of large block devices.

While the kernel side of blktap drivers is using 64-bit sector numbers
correctly when reporting disk sizing, the userspace parts where this
dat is actually generated is truncating at 32-bit. There are 3 variables
related to disk sizing which are used in the kernel/userspace code
'size', 'sector size' & 'info'. In kernel space these are treated as being
unsigned long long, unsigned long, and unsigned int, respectively. In
the blktap userspace code this were all varyingly long, unsigned long.
This mismatch caused 32-bit wraparound on large disks. The attached
patch updates the blktap userspace to use the same data types as
kernel space for all these params, thus both fixing the 32-bit bug &
giving the code consistency.

This patch has been tested both by comparing /proc/partitions in the
guest, with the image size seen in the host, and by using Stephen
Tweedie's 'verify-data' tool on a variety of multi-TB sized disks.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
author kfraser@localhost.localdomain
date Tue Nov 28 13:50:32 2006 +0000 (2006-11-28)
parents 99878f3f74ee
children 5c47222b60dc
files tools/blktap/drivers/blktapctrl.c tools/blktap/drivers/blktapctrl.h tools/blktap/drivers/tapdisk.h tools/blktap/lib/blktaplib.h tools/blktap/lib/xenbus.c
line diff
     1.1 --- a/tools/blktap/drivers/blktapctrl.c	Tue Nov 28 13:48:47 2006 +0000
     1.2 +++ b/tools/blktap/drivers/blktapctrl.c	Tue Nov 28 13:50:32 2006 +0000
     1.3 @@ -420,7 +420,7 @@ static int read_msg(int fd, int msgtype,
     1.4  			image->secsize = img->secsize;
     1.5  			image->info = img->info;
     1.6  
     1.7 -			DPRINTF("Received CTLMSG_IMG: %lu, %lu, %lu\n",
     1.8 +			DPRINTF("Received CTLMSG_IMG: %llu, %lu, %u\n",
     1.9  				image->size, image->secsize, image->info);
    1.10  			if(msgtype != CTLMSG_IMG) ret = 0;
    1.11  			break;
     2.1 --- a/tools/blktap/drivers/blktapctrl.h	Tue Nov 28 13:48:47 2006 +0000
     2.2 +++ b/tools/blktap/drivers/blktapctrl.h	Tue Nov 28 13:50:32 2006 +0000
     2.3 @@ -30,19 +30,19 @@
     2.4   */
     2.5  
     2.6  
     2.7 -static inline long int tapdisk_get_size(blkif_t *blkif)
     2.8 +static inline unsigned long long tapdisk_get_size(blkif_t *blkif)
     2.9  {
    2.10  	image_t *img = (image_t *)blkif->prv;
    2.11  	return img->size;
    2.12  }
    2.13  
    2.14 -static inline long int tapdisk_get_secsize(blkif_t *blkif)
    2.15 +static inline unsigned long tapdisk_get_secsize(blkif_t *blkif)
    2.16  {
    2.17  	image_t *img = (image_t *)blkif->prv;
    2.18  	return img->secsize;
    2.19  }
    2.20  
    2.21 -static inline unsigned tapdisk_get_info(blkif_t *blkif)
    2.22 +static inline unsigned int tapdisk_get_info(blkif_t *blkif)
    2.23  {
    2.24  	image_t *img = (image_t *)blkif->prv;
    2.25  	return img->info;
     3.1 --- a/tools/blktap/drivers/tapdisk.h	Tue Nov 28 13:48:47 2006 +0000
     3.2 +++ b/tools/blktap/drivers/tapdisk.h	Tue Nov 28 13:50:32 2006 +0000
     3.3 @@ -74,9 +74,9 @@ struct td_state {
     3.4  	void *ring_info;
     3.5  	void *fd_entry;
     3.6  	char backing_file[1024]; /*Used by differencing disks, e.g. qcow*/
     3.7 -	long int   sector_size;
     3.8 -	uint64_t   size;
     3.9 -	long int   info;
    3.10 +	unsigned long      sector_size;
    3.11 +	unsigned long long size;
    3.12 +	unsigned int       info;
    3.13  };
    3.14  
    3.15  /* Prototype of the callback to activate as requests complete.              */
     4.1 --- a/tools/blktap/lib/blktaplib.h	Tue Nov 28 13:48:47 2006 +0000
     4.2 +++ b/tools/blktap/lib/blktaplib.h	Tue Nov 28 13:50:32 2006 +0000
     4.3 @@ -97,9 +97,9 @@ typedef struct {
     4.4  } pending_req_t;
     4.5  
     4.6  struct blkif_ops {
     4.7 -	long int (*get_size)(struct blkif *blkif);
     4.8 -	long int (*get_secsize)(struct blkif *blkif);
     4.9 -	unsigned (*get_info)(struct blkif *blkif);
    4.10 +	unsigned long long (*get_size)(struct blkif *blkif);
    4.11 +	unsigned long (*get_secsize)(struct blkif *blkif);
    4.12 +	unsigned int (*get_info)(struct blkif *blkif);
    4.13  };
    4.14  
    4.15  typedef struct blkif {
    4.16 @@ -156,9 +156,9 @@ typedef struct domid_translate {
    4.17  } domid_translate_t ;
    4.18  
    4.19  typedef struct image {
    4.20 -	long int size;
    4.21 -	long int secsize;
    4.22 -	long int info;
    4.23 +	unsigned long long size;
    4.24 +	unsigned long secsize;
    4.25 +	unsigned int info;
    4.26  } image_t;
    4.27  
    4.28  typedef struct msg_hdr {
     5.1 --- a/tools/blktap/lib/xenbus.c	Tue Nov 28 13:48:47 2006 +0000
     5.2 +++ b/tools/blktap/lib/xenbus.c	Tue Nov 28 13:50:32 2006 +0000
     5.3 @@ -219,7 +219,7 @@ static void ueblktap_setup(struct xs_han
     5.4  	}
     5.5  
     5.6  	/* Supply the information about the device to xenstore */
     5.7 -	er = xs_printf(h, be->backpath, "sectors", "%lu",
     5.8 +	er = xs_printf(h, be->backpath, "sectors", "%llu",
     5.9  			be->blkif->ops->get_size(be->blkif));
    5.10  
    5.11  	if (er == 0) {