Skip to content

Commit

Permalink
dm unstripe: support non-power-of-2 chunk size
Browse files Browse the repository at this point in the history
Address "FIXME: must support non power of 2 chunk_size, dm-stripe.c does".

Bump target version to indicate change.

Signed-off-by: Heinz Mauelshagen <[email protected]>
Tested-by: Scott Bauer <[email protected]>
Reviewed-by: Scott Bauer <[email protected]>
Signed-off-by: Mike Snitzer <[email protected]>
  • Loading branch information
mauelsha authored and snitm committed Apr 3, 2018
1 parent 5059353 commit 2ae600c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions drivers/md/dm-unstripe.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ static int unstripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
goto err;
}

// FIXME: must support non power of 2 chunk_size, dm-stripe.c does
if (!is_power_of_2(uc->chunk_size)) {
ti->error = "Non power of 2 chunk_size is not supported yet";
goto err;
}

if (kstrtouint(argv[2], 10, &uc->unstripe)) {
ti->error = "Invalid stripe number";
goto err;
Expand All @@ -98,7 +92,7 @@ static int unstripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)

uc->unstripe_offset = uc->unstripe * uc->chunk_size;
uc->unstripe_width = (uc->stripes - 1) * uc->chunk_size;
uc->chunk_shift = fls(uc->chunk_size) - 1;
uc->chunk_shift = is_power_of_2(uc->chunk_size) ? fls(uc->chunk_size) - 1 : 0;

tmp_len = ti->len;
if (sector_div(tmp_len, uc->chunk_size)) {
Expand Down Expand Up @@ -129,14 +123,18 @@ static sector_t map_to_core(struct dm_target *ti, struct bio *bio)
{
struct unstripe_c *uc = ti->private;
sector_t sector = bio->bi_iter.bi_sector;
sector_t tmp_sector = sector;

/* Shift us up to the right "row" on the stripe */
sector += uc->unstripe_width * (sector >> uc->chunk_shift);
if (uc->chunk_shift)
tmp_sector >>= uc->chunk_shift;
else
sector_div(tmp_sector, uc->chunk_size);

/* Account for what stripe we're operating on */
sector += uc->unstripe_offset;
sector += uc->unstripe_width * tmp_sector;

return sector;
/* Account for what stripe we're operating on */
return sector + uc->unstripe_offset;
}

static int unstripe_map(struct dm_target *ti, struct bio *bio)
Expand Down Expand Up @@ -185,7 +183,7 @@ static void unstripe_io_hints(struct dm_target *ti,

static struct target_type unstripe_target = {
.name = "unstriped",
.version = {1, 0, 0},
.version = {1, 1, 0},
.module = THIS_MODULE,
.ctr = unstripe_ctr,
.dtr = unstripe_dtr,
Expand Down

0 comments on commit 2ae600c

Please sign in to comment.