
From: Neil Brown <neilb@cse.unsw.edu.au>

Addresses http://bugme.osdl.org/show_bug.cgi?id=2355

It seems that a merge_bvec_fn needs to be aware of partitioning...  who
would have thought it :-(

The following patch should fix the merge_bvec_fn for both linear and raid0.
We teach linear and raid0 about partitions in the merge_bvec_fn.

->merge_bvec_fn needs to make decisions based on the physical geometry of the
device.  For raid0, it needs to decide if adding the bvec to the bio will
make the bio span two drives.

To do this, it needs to know where the request is (what the sector number is)
in the whole device.

However when called from bio_add_page, bi_sector is the sector number
relative to the current partition, as generic_make_request hasn't been called
yet.

So raid_mergeable_bvec needs to map bio->bi_sector (which is partition
relative) to a bi_sector which is device relative, so it can perform proper
calculations about when chunk boundaries are.


---

 25-akpm/drivers/md/linear.c |    5 +++--
 25-akpm/drivers/md/raid0.c  |    2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff -puN drivers/md/linear.c~md-merging-fix drivers/md/linear.c
--- 25/drivers/md/linear.c~md-merging-fix	2004-04-03 03:28:32.529887440 -0800
+++ 25-akpm/drivers/md/linear.c	2004-04-03 03:28:32.534886680 -0800
@@ -61,9 +61,10 @@ static int linear_mergeable_bvec(request
 	mddev_t *mddev = q->queuedata;
 	dev_info_t *dev0;
 	unsigned long maxsectors, bio_sectors = bio->bi_size >> 9;
+	sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
 
-	dev0 = which_dev(mddev, bio->bi_sector);
-	maxsectors = (dev0->size << 1) - (bio->bi_sector - (dev0->offset<<1));
+	dev0 = which_dev(mddev, sector);
+	maxsectors = (dev0->size << 1) - (sector - (dev0->offset<<1));
 
 	if (maxsectors < bio_sectors)
 		maxsectors = 0;
diff -puN drivers/md/raid0.c~md-merging-fix drivers/md/raid0.c
--- 25/drivers/md/raid0.c~md-merging-fix	2004-04-03 03:28:32.531887136 -0800
+++ 25-akpm/drivers/md/raid0.c	2004-04-03 03:28:32.535886528 -0800
@@ -219,7 +219,7 @@ static int create_strip_zones (mddev_t *
 static int raid0_mergeable_bvec(request_queue_t *q, struct bio *bio, struct bio_vec *biovec)
 {
 	mddev_t *mddev = q->queuedata;
-	sector_t sector = bio->bi_sector;
+	sector_t sector = bio->bi_sector + get_start_sect(bio->bi_bdev);
 	int max;
 	unsigned int chunk_sectors = mddev->chunk_size >> 9;
 	unsigned int bio_sectors = bio->bi_size >> 9;

_
