All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Fix 32-bit sector number overflow in blktap userspace
@ 2006-11-27 13:35 Daniel P. Berrange
  0 siblings, 0 replies; only message in thread
From: Daniel P. Berrange @ 2006-11-27 13:35 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 1412 bytes --]

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>

(Reposted from http://lists.xensource.com/archives/html/xen-devel/2006-11/msg01131.html)

Regards,
Dan.
-- 
|=- Red Hat, Engineering, Emerging Technologies, Boston.  +1 978 392 2496 -=|
|=-           Perl modules: http://search.cpan.org/~danberr/              -=|
|=-               Projects: http://freshmeat.net/~danielpb/               -=|
|=-  GnuPG: 7D3B9505   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505  -=| 

[-- Attachment #2: blktap-2tb-2.patch --]
[-- Type: text/plain, Size: 3206 bytes --]

diff -r 00ed59a6f043 tools/blktap/drivers/blktapctrl.c
--- a/tools/blktap/drivers/blktapctrl.c	Tue Nov 21 10:22:19 2006 +0000
+++ b/tools/blktap/drivers/blktapctrl.c	Tue Nov 21 14:53:39 2006 -0500
@@ -420,7 +420,7 @@ static int read_msg(int fd, int msgtype,
 			image->secsize = img->secsize;
 			image->info = img->info;
 
-			DPRINTF("Received CTLMSG_IMG: %lu, %lu, %lu\n",
+			DPRINTF("Received CTLMSG_IMG: %llu, %lu, %u\n",
 				image->size, image->secsize, image->info);
 			if(msgtype != CTLMSG_IMG) ret = 0;
 			break;
diff -r 00ed59a6f043 tools/blktap/drivers/blktapctrl.h
--- a/tools/blktap/drivers/blktapctrl.h	Tue Nov 21 10:22:19 2006 +0000
+++ b/tools/blktap/drivers/blktapctrl.h	Tue Nov 21 14:53:39 2006 -0500
@@ -30,19 +30,19 @@
  */
 
 
-static inline long int tapdisk_get_size(blkif_t *blkif)
+static inline unsigned long long tapdisk_get_size(blkif_t *blkif)
 {
 	image_t *img = (image_t *)blkif->prv;
 	return img->size;
 }
 
-static inline long int tapdisk_get_secsize(blkif_t *blkif)
+static inline unsigned long tapdisk_get_secsize(blkif_t *blkif)
 {
 	image_t *img = (image_t *)blkif->prv;
 	return img->secsize;
 }
 
-static inline unsigned tapdisk_get_info(blkif_t *blkif)
+static inline unsigned int tapdisk_get_info(blkif_t *blkif)
 {
 	image_t *img = (image_t *)blkif->prv;
 	return img->info;
diff -r 00ed59a6f043 tools/blktap/drivers/tapdisk.h
--- a/tools/blktap/drivers/tapdisk.h	Tue Nov 21 10:22:19 2006 +0000
+++ b/tools/blktap/drivers/tapdisk.h	Tue Nov 21 14:53:39 2006 -0500
@@ -74,9 +74,9 @@ struct td_state {
 	void *ring_info;
 	void *fd_entry;
 	char backing_file[1024]; /*Used by differencing disks, e.g. qcow*/
-	long int   sector_size;
-	uint64_t   size;
-	long int   info;
+	unsigned long      sector_size;
+	unsigned long long size;
+	unsigned int       info;
 };
 
 /* Prototype of the callback to activate as requests complete.              */
diff -r 00ed59a6f043 tools/blktap/lib/blktaplib.h
--- a/tools/blktap/lib/blktaplib.h	Tue Nov 21 10:22:19 2006 +0000
+++ b/tools/blktap/lib/blktaplib.h	Tue Nov 21 14:54:21 2006 -0500
@@ -97,9 +97,9 @@ typedef struct {
 } pending_req_t;
 
 struct blkif_ops {
-	long int (*get_size)(struct blkif *blkif);
-	long int (*get_secsize)(struct blkif *blkif);
-	unsigned (*get_info)(struct blkif *blkif);
+	unsigned long long (*get_size)(struct blkif *blkif);
+	unsigned long (*get_secsize)(struct blkif *blkif);
+	unsigned int (*get_info)(struct blkif *blkif);
 };
 
 typedef struct blkif {
@@ -156,9 +156,9 @@ typedef struct domid_translate {
 } domid_translate_t ;
 
 typedef struct image {
-	long int size;
-	long int secsize;
-	long int info;
+	unsigned long long size;
+	unsigned long secsize;
+	unsigned int info;
 } image_t;
 
 typedef struct msg_hdr {
diff -r 00ed59a6f043 tools/blktap/lib/xenbus.c
--- a/tools/blktap/lib/xenbus.c	Tue Nov 21 10:22:19 2006 +0000
+++ b/tools/blktap/lib/xenbus.c	Tue Nov 21 14:53:58 2006 -0500
@@ -219,7 +219,7 @@ static void ueblktap_setup(struct xs_han
 	}
 
 	/* Supply the information about the device to xenstore */
-	er = xs_printf(h, be->backpath, "sectors", "%lu",
+	er = xs_printf(h, be->backpath, "sectors", "%llu",
 			be->blkif->ops->get_size(be->blkif));
 
 	if (er == 0) {

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-11-27 13:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-27 13:35 [PATCH] Fix 32-bit sector number overflow in blktap userspace Daniel P. Berrange

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.