Commit eb850de6 authored by Mike Snitzer's avatar Mike Snitzer Committed by Alasdair G Kergon

dm stripe: support for non power of 2 chunksize

Support non-power-of-2 chunk sizes with dm striping for proper alignment
of stripe IO on storage that has non-power-of-2 optimal IO sizes (e.g.
RAID6 10+2).
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 542f9038
...@@ -9,8 +9,8 @@ devices in parallel. ...@@ -9,8 +9,8 @@ devices in parallel.
Parameters: <num devs> <chunk size> [<dev path> <offset>]+ Parameters: <num devs> <chunk size> [<dev path> <offset>]+
<num devs>: Number of underlying devices. <num devs>: Number of underlying devices.
<chunk size>: Size of each chunk of data. Must be a power-of-2 and at <chunk size>: Size of each chunk of data. Must be at least as
least as large as the system's PAGE_SIZE. large as the system's PAGE_SIZE.
<dev path>: Full pathname to the underlying block-device, or a <dev path>: Full pathname to the underlying block-device, or a
"major:minor" device-number. "major:minor" device-number.
<offset>: Starting sector within the device. <offset>: Starting sector within the device.
......
...@@ -30,9 +30,7 @@ struct stripe_c { ...@@ -30,9 +30,7 @@ struct stripe_c {
/* The size of this target / num. stripes */ /* The size of this target / num. stripes */
sector_t stripe_width; sector_t stripe_width;
/* stripe chunk size */ uint32_t chunk_size;
uint32_t chunk_shift;
sector_t chunk_mask;
/* Needed for handling events */ /* Needed for handling events */
struct dm_target *ti; struct dm_target *ti;
...@@ -90,7 +88,7 @@ static int get_stripe(struct dm_target *ti, struct stripe_c *sc, ...@@ -90,7 +88,7 @@ static int get_stripe(struct dm_target *ti, struct stripe_c *sc,
/* /*
* Construct a striped mapping. * Construct a striped mapping.
* <number of stripes> <chunk size (2^^n)> [<dev_path> <offset>]+ * <number of stripes> <chunk size> [<dev_path> <offset>]+
*/ */
static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv) static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
{ {
...@@ -111,21 +109,14 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -111,21 +109,14 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
return -EINVAL; return -EINVAL;
} }
if (kstrtouint(argv[1], 10, &chunk_size)) { if (kstrtouint(argv[1], 10, &chunk_size) ||
ti->error = "Invalid chunk_size";
return -EINVAL;
}
/*
* chunk_size is a power of two
*/
if (!is_power_of_2(chunk_size) ||
(chunk_size < (PAGE_SIZE >> SECTOR_SHIFT))) { (chunk_size < (PAGE_SIZE >> SECTOR_SHIFT))) {
ti->error = "Invalid chunk size"; ti->error = "Invalid chunk_size";
return -EINVAL; return -EINVAL;
} }
if (ti->len & (chunk_size - 1)) { width = ti->len;
if (sector_div(width, chunk_size)) {
ti->error = "Target length not divisible by " ti->error = "Target length not divisible by "
"chunk size"; "chunk size";
return -EINVAL; return -EINVAL;
...@@ -172,8 +163,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv) ...@@ -172,8 +163,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
ti->num_flush_requests = stripes; ti->num_flush_requests = stripes;
ti->num_discard_requests = stripes; ti->num_discard_requests = stripes;
sc->chunk_shift = ffs(chunk_size) - 1; sc->chunk_size = chunk_size;
sc->chunk_mask = ((sector_t) chunk_size) - 1;
/* /*
* Get the stripe destinations. * Get the stripe destinations.
...@@ -212,8 +202,8 @@ static void stripe_dtr(struct dm_target *ti) ...@@ -212,8 +202,8 @@ static void stripe_dtr(struct dm_target *ti)
static void stripe_map_sector(struct stripe_c *sc, sector_t sector, static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
uint32_t *stripe, sector_t *result) uint32_t *stripe, sector_t *result)
{ {
sector_t offset = dm_target_offset(sc->ti, sector); sector_t chunk = dm_target_offset(sc->ti, sector);
sector_t chunk = offset >> sc->chunk_shift; sector_t chunk_offset = sector_div(chunk, sc->chunk_size);
if (sc->stripes_shift < 0) if (sc->stripes_shift < 0)
*stripe = sector_div(chunk, sc->stripes); *stripe = sector_div(chunk, sc->stripes);
...@@ -222,7 +212,7 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector, ...@@ -222,7 +212,7 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
chunk >>= sc->stripes_shift; chunk >>= sc->stripes_shift;
} }
*result = (chunk << sc->chunk_shift) | (offset & sc->chunk_mask); *result = (chunk * sc->chunk_size) + chunk_offset;
} }
static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector, static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector,
...@@ -233,9 +223,13 @@ static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector, ...@@ -233,9 +223,13 @@ static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector,
stripe_map_sector(sc, sector, &stripe, result); stripe_map_sector(sc, sector, &stripe, result);
if (stripe == target_stripe) if (stripe == target_stripe)
return; return;
*result &= ~sc->chunk_mask; /* round down */
/* round down */
sector = *result;
*result -= sector_div(sector, sc->chunk_size);
if (target_stripe < stripe) if (target_stripe < stripe)
*result += sc->chunk_mask + 1; /* next chunk */ *result += sc->chunk_size; /* next chunk */
} }
static int stripe_map_discard(struct stripe_c *sc, struct bio *bio, static int stripe_map_discard(struct stripe_c *sc, struct bio *bio,
...@@ -320,7 +314,7 @@ static int stripe_status(struct dm_target *ti, ...@@ -320,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
case STATUSTYPE_TABLE: case STATUSTYPE_TABLE:
DMEMIT("%d %llu", sc->stripes, DMEMIT("%d %llu", sc->stripes,
(unsigned long long)sc->chunk_mask + 1); (unsigned long long)sc->chunk_size);
for (i = 0; i < sc->stripes; i++) for (i = 0; i < sc->stripes; i++)
DMEMIT(" %s %llu", sc->stripe[i].dev->name, DMEMIT(" %s %llu", sc->stripe[i].dev->name,
(unsigned long long)sc->stripe[i].physical_start); (unsigned long long)sc->stripe[i].physical_start);
...@@ -387,7 +381,7 @@ static void stripe_io_hints(struct dm_target *ti, ...@@ -387,7 +381,7 @@ static void stripe_io_hints(struct dm_target *ti,
struct queue_limits *limits) struct queue_limits *limits)
{ {
struct stripe_c *sc = ti->private; struct stripe_c *sc = ti->private;
unsigned chunk_size = (sc->chunk_mask + 1) << 9; unsigned chunk_size = sc->chunk_size << SECTOR_SHIFT;
blk_limits_io_min(limits, chunk_size); blk_limits_io_min(limits, chunk_size);
blk_limits_io_opt(limits, chunk_size * sc->stripes); blk_limits_io_opt(limits, chunk_size * sc->stripes);
...@@ -415,7 +409,7 @@ static int stripe_merge(struct dm_target *ti, struct bvec_merge_data *bvm, ...@@ -415,7 +409,7 @@ static int stripe_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
static struct target_type stripe_target = { static struct target_type stripe_target = {
.name = "striped", .name = "striped",
.version = {1, 4, 0}, .version = {1, 5, 0},
.module = THIS_MODULE, .module = THIS_MODULE,
.ctr = stripe_ctr, .ctr = stripe_ctr,
.dtr = stripe_dtr, .dtr = stripe_dtr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment