Update DM core's max_io_len() to use sector_div() to support a target's
use of a non power of 2 blocksize.
Rename split_io to max_io_len in the dm_target structure and change data
type from sector_t to uint32_t. Introduce dm_set_target_max_io_len() to
check that each target's max_io_len does not exceed UINT_MAX.
Add do_div wrappers (dm_do_div and dm_do_mod) that don't modify the
dividend; these will be used by thin-pool and striped targets.
/* Assume there are no metadata devices until the drives are parsed */
rs->md.persistent = 0;
Index: linux/drivers/md/dm-raid1.c
================================================== =================
--- linux.orig/drivers/md/dm-raid1.c
+++ linux/drivers/md/dm-raid1.c
@@ -1081,7 +1081,9 @@ static int mirror_ctr(struct dm_target *
}
/*
- * snapshot-merge acts as an origin, so set ti->split_io
+ * snapshot-merge acts as an origin, so set ti->max_io_len
*/
- ti->split_io = get_origin_minimum_chunksize(s->origin->bdev);
+ ti->max_io_len = get_origin_minimum_chunksize(s->origin->bdev);
/*
- * The origin's __minimum_chunk_size() got stored in split_io
+ * The origin's __minimum_chunk_size() got stored in max_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_io_len)
if (__origin_write(&o->snapshots, sector + n, NULL) ==
DM_MAPIO_SUBMITTED)
must_wait = 1;
@@ -2138,14 +2141,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_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 = tc->pool->sectors_per_block;
+ r = dm_set_target_max_io_len(ti, tc->pool->sectors_per_block);
+ if (r < 0)
+ goto bad_thin_open;
ti->num_flush_requests = 1;
/* In case the pool supports discards, pass them on. */
Index: linux/drivers/md/dm.c
================================================== =================
--- linux.orig/drivers/md/dm.c
+++ linux/drivers/md/dm.c
@@ -970,20 +970,34 @@ 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_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_io_len;
+ sector_t max_len = ti->max_io_len - sector_div(boundary, ti->max_io_len);
+
+ if (len > max_len)
+ len = max_len;
}
- /* Always a power of 2 */
- sector_t split_io;
+ /* If non-zero, maximum size of I/O submitted to a target. */
+ uint32_t max_io_len;
/*
* A number of zero-length barrier requests that will be submitted
@@ -503,6 +503,20 @@ static inline unsigned long to_bytes(sec
return (n << SECTOR_SHIFT);
}
+/*
+ * do_div wrappers that don't modify the dividend
+ */
+static inline sector_t dm_do_div(sector_t a, uint32_t b)
+{
+ do_div(a, b);
+ return a;
+}
+
+static inline uint32_t dm_do_mod(sector_t a, uint32_t b)
+{
+ return do_div(a, b);
+}
+
/*-----------------------------------------------------------------
* Helper for block layer and dm core operations
*---------------------------------------------------------------*/
@@ -511,4 +525,6 @@ void dm_requeue_unmapped_request(struct
void dm_kill_unmapped_request(struct request *rq, int error);
int dm_underlying_device_busy(struct request_queue *q);