Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 319464
b: refs/heads/master
c: eb850de
h: refs/heads/master
v: v3
  • Loading branch information
Mike Snitzer authored and Alasdair G Kergon committed Jul 27, 2012
1 parent 1b6c0e0 commit 03750e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 542f90381422676544382d4071ba44a2de90a0c1
refs/heads/master: eb850de608cc22e0199b3797cd5c0076bae6cda0
4 changes: 2 additions & 2 deletions trunk/Documentation/device-mapper/striped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ devices in parallel.

Parameters: <num devs> <chunk size> [<dev path> <offset>]+
<num devs>: Number of underlying devices.
<chunk size>: Size of each chunk of data. Must be a power-of-2 and at
least as large as the system's PAGE_SIZE.
<chunk size>: Size of each chunk of data. Must be at least as
large as the system's PAGE_SIZE.
<dev path>: Full pathname to the underlying block-device, or a
"major:minor" device-number.
<offset>: Starting sector within the device.
Expand Down
44 changes: 19 additions & 25 deletions trunk/drivers/md/dm-stripe.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ struct stripe_c {
/* The size of this target / num. stripes */
sector_t stripe_width;

/* stripe chunk size */
uint32_t chunk_shift;
sector_t chunk_mask;
uint32_t chunk_size;

/* Needed for handling events */
struct dm_target *ti;
Expand Down Expand Up @@ -90,7 +88,7 @@ static int get_stripe(struct dm_target *ti, struct stripe_c *sc,

/*
* 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)
{
Expand All @@ -111,21 +109,14 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
return -EINVAL;
}

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) ||
if (kstrtouint(argv[1], 10, &chunk_size) ||
(chunk_size < (PAGE_SIZE >> SECTOR_SHIFT))) {
ti->error = "Invalid chunk size";
ti->error = "Invalid chunk_size";
return -EINVAL;
}

if (ti->len & (chunk_size - 1)) {
width = ti->len;
if (sector_div(width, chunk_size)) {
ti->error = "Target length not divisible by "
"chunk size";
return -EINVAL;
Expand Down Expand Up @@ -172,8 +163,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
ti->num_flush_requests = stripes;
ti->num_discard_requests = stripes;

sc->chunk_shift = ffs(chunk_size) - 1;
sc->chunk_mask = ((sector_t) chunk_size) - 1;
sc->chunk_size = chunk_size;

/*
* Get the stripe destinations.
Expand Down Expand Up @@ -212,8 +202,8 @@ static void stripe_dtr(struct dm_target *ti)
static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
uint32_t *stripe, sector_t *result)
{
sector_t offset = dm_target_offset(sc->ti, sector);
sector_t chunk = offset >> sc->chunk_shift;
sector_t chunk = dm_target_offset(sc->ti, sector);
sector_t chunk_offset = sector_div(chunk, sc->chunk_size);

if (sc->stripes_shift < 0)
*stripe = sector_div(chunk, sc->stripes);
Expand All @@ -222,7 +212,7 @@ static void stripe_map_sector(struct stripe_c *sc, sector_t sector,
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,
Expand All @@ -233,9 +223,13 @@ static void stripe_map_range_sector(struct stripe_c *sc, sector_t sector,
stripe_map_sector(sc, sector, &stripe, result);
if (stripe == target_stripe)
return;
*result &= ~sc->chunk_mask; /* round down */

/* round down */
sector = *result;
*result -= sector_div(sector, sc->chunk_size);

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,
Expand Down Expand Up @@ -320,7 +314,7 @@ static int stripe_status(struct dm_target *ti,

case STATUSTYPE_TABLE:
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++)
DMEMIT(" %s %llu", sc->stripe[i].dev->name,
(unsigned long long)sc->stripe[i].physical_start);
Expand Down Expand Up @@ -387,7 +381,7 @@ static void stripe_io_hints(struct dm_target *ti,
struct queue_limits *limits)
{
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_opt(limits, chunk_size * sc->stripes);
Expand Down Expand Up @@ -415,7 +409,7 @@ static int stripe_merge(struct dm_target *ti, struct bvec_merge_data *bvm,

static struct target_type stripe_target = {
.name = "striped",
.version = {1, 4, 0},
.version = {1, 5, 0},
.module = THIS_MODULE,
.ctr = stripe_ctr,
.dtr = stripe_dtr,
Expand Down

0 comments on commit 03750e2

Please sign in to comment.