From: Martin K. Petersen <[email-masked]>

The DM device limits function passes the start offset within the block
device to the block layer stacking function.  The stacking function
expects the provided start offset to be relative to start of the disk
(request_queue).  Until now DM was passing a start offset that was
relative to beginning of the partition (block_device), resulting in
incorrect alignment stacking.

Add the partition offset to the values passed to blk_stack_limits().

Also clarify, in the DMWARN message, that the device which caused
blk_stack_limits() to return failure isn't necessarily misaligned
itself.  It caused the top-level (DM) device to have inconsistent
alignment when taken in combination with all previously stacked
device(s).

Cc: [email-masked]
Signed-off-by: Martin K. Petersen <[email-masked]>
Signed-off-by: Mike Snitzer <[email-masked]>
Signed-off-by: Alasdair G Kergon <[email-masked]>

[FIXME - type problems - offset is *not* sector_t here]

---
 drivers/md/dm-table.c |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Index: linux-2.6.33-rc2/drivers/md/dm-table.c
===================================================================
--- linux-2.6.33-rc2.orig/drivers/md/dm-table.c
+++ linux-2.6.33-rc2/drivers/md/dm-table.c
@@ -495,6 +495,7 @@ int dm_set_device_limits(struct dm_targe
 	struct queue_limits *limits = data;
 	struct block_device *bdev = dev->bdev;
 	struct request_queue *q = bdev_get_queue(bdev);
+	sector_t offset = (get_start_sect(bdev) + start) << SECTOR_SHIFT;
 	char b[BDEVNAME_SIZE];
 
 	if (unlikely(!q)) {
@@ -503,15 +504,15 @@ int dm_set_device_limits(struct dm_targe
 		return 0;
 	}
 
-	if (blk_stack_limits(limits, &q->limits, start << 9) < 0)
-		DMWARN("%s: target device %s is misaligned: "
+	if (blk_stack_limits(limits, &q->limits, offset) < 0)
+		DMWARN("%s: adding target device %s caused an alignment inconsistency: "
 		       "physical_block_size=%u, logical_block_size=%u, "
 		       "alignment_offset=%u, start=%llu",
 		       dm_device_name(ti->table->md), bdevname(bdev, b),
 		       q->limits.physical_block_size,
 		       q->limits.logical_block_size,
 		       q->limits.alignment_offset,
-		       (unsigned long long) start << 9);
+		       (unsigned long long) offset);

 	/*