Commit 65988525abde0b0a5833c4e20f32967184a5dcf0
Committed by
Alasdair G Kergon
1 parent
38e1b257fd
Exists in
master
and in
7 other branches
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>
Showing 1 changed file with 14 additions and 7 deletions Side-by-side Diff
drivers/md/dm-stripe.c
... | ... | @@ -207,11 +207,20 @@ |
207 | 207 | kfree(sc); |
208 | 208 | } |
209 | 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 | + | |
210 | 220 | static int stripe_map(struct dm_target *ti, struct bio *bio, |
211 | 221 | union map_info *map_context) |
212 | 222 | { |
213 | - struct stripe_c *sc = (struct stripe_c *) ti->private; | |
214 | - sector_t offset, chunk; | |
223 | + struct stripe_c *sc = ti->private; | |
215 | 224 | uint32_t stripe; |
216 | 225 | unsigned target_request_nr; |
217 | 226 | |
218 | 227 | |
219 | 228 | |
... | ... | @@ -222,13 +231,11 @@ |
222 | 231 | return DM_MAPIO_REMAPPED; |
223 | 232 | } |
224 | 233 | |
225 | - offset = dm_target_offset(ti, bio->bi_sector); | |
226 | - chunk = offset >> sc->chunk_shift; | |
227 | - stripe = sector_div(chunk, sc->stripes); | |
234 | + stripe_map_sector(sc, bio->bi_sector, &stripe, &bio->bi_sector); | |
228 | 235 | |
236 | + bio->bi_sector += sc->stripe[stripe].physical_start; | |
229 | 237 | bio->bi_bdev = sc->stripe[stripe].dev->bdev; |
230 | - bio->bi_sector = sc->stripe[stripe].physical_start + | |
231 | - (chunk << sc->chunk_shift) + (offset & sc->chunk_mask); | |
238 | + | |
232 | 239 | return DM_MAPIO_REMAPPED; |
233 | 240 | } |
234 | 241 |