From: Mike Snitzer <snitzer@redhat.com>

Required to support a target's use of a non power of 2 blocksize.

Renamed split_io to max_target_io_len.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>

FIXME: Cope with 32-bit + LBD + split_io>32bit
FIXME: Write patch header
FIXME: Split out the renaming?
---
drivers/md/dm.c |    6 +++---
 drivers/md/dm-raid.c          |    8 ++++----
 drivers/md/dm-raid1.c         |    2 +-
 drivers/md/dm-snap.c          |   16 ++++++++--------
 drivers/md/dm.c               |   15 ++++++++-------
 include/linux/device-mapper.h |    4 ++--
 5 files changed, 23 insertions(+), 22 deletions(-)

Index: linux-3.4-rc5/drivers/md/dm-raid.c
===================================================================
--- linux-3.4-rc5.orig/drivers/md/dm-raid.c
+++ linux-3.4-rc5/drivers/md/dm-raid.c
@@ -525,14 +525,14 @@ static int parse_raid_params(struct raid
 		return -EINVAL;
 
 	if (rs->md.chunk_sectors)
-		rs->ti->split_io = rs->md.chunk_sectors;
+		rs->ti->max_target_io_len = rs->md.chunk_sectors;
 	else
-		rs->ti->split_io = region_size;
+		rs->ti->max_target_io_len = region_size;
 
 	if (rs->md.chunk_sectors)
-		rs->ti->split_io = rs->md.chunk_sectors;
+		rs->ti->max_target_io_len = rs->md.chunk_sectors;
 	else
-		rs->ti->split_io = region_size;
+		rs->ti->max_target_io_len = region_size;
 
 	/* Assume there are no metadata devices until the drives are parsed */
 	rs->md.persistent = 0;
Index: linux-3.4-rc5/drivers/md/dm-raid1.c
===================================================================
--- linux-3.4-rc5.orig/drivers/md/dm-raid1.c
+++ linux-3.4-rc5/drivers/md/dm-raid1.c
@@ -1081,7 +1081,7 @@ static int mirror_ctr(struct dm_target *
 	}
 
 	ti->private = ms;
-	ti->split_io = dm_rh_get_region_size(ms->rh);
+	ti->max_target_io_len = dm_rh_get_region_size(ms->rh);
 	ti->num_flush_requests = 1;
 	ti->num_discard_requests = 1;
 
Index: linux-3.4-rc5/drivers/md/dm-snap.c
===================================================================
--- linux-3.4-rc5.orig/drivers/md/dm-snap.c
+++ linux-3.4-rc5/drivers/md/dm-snap.c
@@ -1172,7 +1172,7 @@ static int snapshot_ctr(struct dm_target
 		ti->error = "Chunk size not set";
 		goto bad_read_metadata;
 	}
-	ti->split_io = s->store->chunk_size;
+	ti->max_target_io_len = s->store->chunk_size;
 
 	return 0;
 
@@ -1239,7 +1239,7 @@ static void __handover_exceptions(struct
 	snap_dest->store->snap = snap_dest;
 	snap_src->store->snap = snap_src;
 
-	snap_dest->ti->split_io = snap_dest->store->chunk_size;
+	snap_dest->ti->max_target_io_len = snap_dest->store->chunk_size;
 	snap_dest->valid = snap_src->valid;
 
 	/*
@@ -1838,9 +1838,9 @@ static void snapshot_merge_resume(struct
 	snapshot_resume(ti);
 
 	/*
-	 * snapshot-merge acts as an origin, so set ti->split_io
+	 * snapshot-merge acts as an origin, so set ti->max_target_io_len
 	 */
-	ti->split_io = get_origin_minimum_chunksize(s->origin->bdev);
+	ti->max_target_io_len = get_origin_minimum_chunksize(s->origin->bdev);
 
 	start_merge(s);
 }
@@ -2073,12 +2073,12 @@ static int origin_write_extent(struct dm
 	struct origin *o;
 
 	/*
-	 * The origin's __minimum_chunk_size() got stored in split_io
+	 * The origin's __minimum_chunk_size() got stored in max_target_io_len
 	 * by snapshot_merge_resume().
 	 */
 	down_read(&_origins_lock);
 	o = __lookup_origin(merging_snap->origin->bdev);
-	for (n = 0; n < size; n += merging_snap->ti->split_io)
+	for (n = 0; n < size; n += merging_snap->ti->max_target_io_len)
 		if (__origin_write(&o->snapshots, sector + n, NULL) ==
 		    DM_MAPIO_SUBMITTED)
 			must_wait = 1;
@@ -2138,14 +2138,14 @@ static int origin_map(struct dm_target *
 }
 
 /*
- * Set the target "split_io" field to the minimum of all the snapshots'
+ * Set the target "max_target_io_len" field to the minimum of all the snapshots'
  * chunk sizes.
  */
 static void origin_resume(struct dm_target *ti)
 {
 	struct dm_dev *dev = ti->private;
 
-	ti->split_io = get_origin_minimum_chunksize(dev->bdev);
+	ti->max_target_io_len = get_origin_minimum_chunksize(dev->bdev);
 }
 
 static int origin_status(struct dm_target *ti, status_type_t type, char *result,
Index: linux-3.4-rc5/drivers/md/dm.c
===================================================================
--- linux-3.4-rc5.orig/drivers/md/dm.c
+++ linux-3.4-rc5/drivers/md/dm.c
@@ -970,15 +970,16 @@ static sector_t max_io_len(sector_t sect
 	sector_t len = max_io_len_target_boundary(sector, ti);
 
 	/*
-	 * Does the target need to split even further ?
+	 * Does the target need to split even further?
 	 */
-	if (ti->split_io) {
-		sector_t boundary;
+	if (ti->max_target_io_len) {
 		sector_t offset = dm_target_offset(ti, sector);
-		boundary = ((offset + ti->split_io) & ~(ti->split_io - 1))
-			   - offset;
-		if (len > boundary)
-			len = boundary;
+		sector_t boundary = offset + ti->max_target_io_len;
+// FIXME Don't truncate here!
+		sector_t max_len = ti->max_target_io_len - sector_div(boundary, (uint32_t) ti->max_target_io_len);
+
+		if (len > max_len)
+			len = max_len;
 	}
 
 	return len;
Index: linux-3.4-rc5/include/linux/device-mapper.h
===================================================================
--- linux-3.4-rc5.orig/include/linux/device-mapper.h
+++ linux-3.4-rc5/include/linux/device-mapper.h
@@ -188,8 +188,8 @@ struct dm_target {
 	sector_t begin;
 	sector_t len;
 
-	/* Always a power of 2 */
-	sector_t split_io;
+	/* If non-zero, maximum size of I/O submitted to a target. */
+	sector_t max_target_io_len;
 
 	/*
 	 * A number of zero-length barrier requests that will be submitted
