dm stripe: move sector translation to a function

Move sector to stripe translation into a function.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>

authored by Mikulas Patocka and committed by Alasdair G Kergon 65988525 38e1b257

+14 -7
+14 -7
drivers/md/dm-stripe.c
··· 207 kfree(sc); 208 } 209 210 static int stripe_map(struct dm_target *ti, struct bio *bio, 211 union map_info *map_context) 212 { 213 - struct stripe_c *sc = (struct stripe_c *) ti->private; 214 - sector_t offset, chunk; 215 uint32_t stripe; 216 unsigned target_request_nr; 217 ··· 231 return DM_MAPIO_REMAPPED; 232 } 233 234 - offset = dm_target_offset(ti, bio->bi_sector); 235 - chunk = offset >> sc->chunk_shift; 236 - stripe = sector_div(chunk, sc->stripes); 237 238 bio->bi_bdev = sc->stripe[stripe].dev->bdev; 239 - bio->bi_sector = sc->stripe[stripe].physical_start + 240 - (chunk << sc->chunk_shift) + (offset & sc->chunk_mask); 241 return DM_MAPIO_REMAPPED; 242 } 243
··· 207 kfree(sc); 208 } 209 210 + static void stripe_map_sector(struct stripe_c *sc, sector_t sector, 211 + uint32_t *stripe, sector_t *result) 212 + { 213 + sector_t offset = dm_target_offset(sc->ti, sector); 214 + sector_t chunk = offset >> sc->chunk_shift; 215 + 216 + *stripe = sector_div(chunk, sc->stripes); 217 + *result = (chunk << sc->chunk_shift) | (offset & sc->chunk_mask); 218 + } 219 + 220 static int stripe_map(struct dm_target *ti, struct bio *bio, 221 union map_info *map_context) 222 { 223 + struct stripe_c *sc = ti->private; 224 uint32_t stripe; 225 unsigned target_request_nr; 226 ··· 222 return DM_MAPIO_REMAPPED; 223 } 224 225 + stripe_map_sector(sc, bio->bi_sector, &stripe, &bio->bi_sector); 226 227 + bio->bi_sector += sc->stripe[stripe].physical_start; 228 bio->bi_bdev = sc->stripe[stripe].dev->bdev; 229 + 230 return DM_MAPIO_REMAPPED; 231 } 232