Skip to content

Commit 2a68553

Browse files
Christoph Hellwigdjbw
authored andcommitted
dm-stripe: add a stripe_dax_pgoff helper
Add a helper to perform the entire remapping for DAX accesses. This helper open codes bdev_dax_pgoff given that the alignment checks have already been done by the submitting file system and don't need to be repeated. Signed-off-by: Christoph Hellwig <[email protected]> Acked-by: Mike Snitzer <[email protected]> Reviewed-by: Dan Williams <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent d19bd67 commit 2a68553

File tree

1 file changed

+15
-48
lines changed

1 file changed

+15
-48
lines changed

drivers/md/dm-stripe.c

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -301,83 +301,50 @@ static int stripe_map(struct dm_target *ti, struct bio *bio)
301301
}
302302

303303
#if IS_ENABLED(CONFIG_FS_DAX)
304-
static long stripe_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
305-
long nr_pages, void **kaddr, pfn_t *pfn)
304+
static struct dax_device *stripe_dax_pgoff(struct dm_target *ti, pgoff_t *pgoff)
306305
{
307-
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
308306
struct stripe_c *sc = ti->private;
309-
struct dax_device *dax_dev;
310307
struct block_device *bdev;
308+
sector_t dev_sector;
311309
uint32_t stripe;
312-
long ret;
313310

314-
stripe_map_sector(sc, sector, &stripe, &dev_sector);
311+
stripe_map_sector(sc, *pgoff * PAGE_SECTORS, &stripe, &dev_sector);
315312
dev_sector += sc->stripe[stripe].physical_start;
316-
dax_dev = sc->stripe[stripe].dev->dax_dev;
317313
bdev = sc->stripe[stripe].dev->bdev;
318314

319-
ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff);
320-
if (ret)
321-
return ret;
315+
*pgoff = (get_start_sect(bdev) + dev_sector) >> PAGE_SECTORS_SHIFT;
316+
return sc->stripe[stripe].dev->dax_dev;
317+
}
318+
319+
static long stripe_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
320+
long nr_pages, void **kaddr, pfn_t *pfn)
321+
{
322+
struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
323+
322324
return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
323325
}
324326

325327
static size_t stripe_dax_copy_from_iter(struct dm_target *ti, pgoff_t pgoff,
326328
void *addr, size_t bytes, struct iov_iter *i)
327329
{
328-
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
329-
struct stripe_c *sc = ti->private;
330-
struct dax_device *dax_dev;
331-
struct block_device *bdev;
332-
uint32_t stripe;
333-
334-
stripe_map_sector(sc, sector, &stripe, &dev_sector);
335-
dev_sector += sc->stripe[stripe].physical_start;
336-
dax_dev = sc->stripe[stripe].dev->dax_dev;
337-
bdev = sc->stripe[stripe].dev->bdev;
330+
struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
338331

339-
if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
340-
return 0;
341332
return dax_copy_from_iter(dax_dev, pgoff, addr, bytes, i);
342333
}
343334

344335
static size_t stripe_dax_copy_to_iter(struct dm_target *ti, pgoff_t pgoff,
345336
void *addr, size_t bytes, struct iov_iter *i)
346337
{
347-
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
348-
struct stripe_c *sc = ti->private;
349-
struct dax_device *dax_dev;
350-
struct block_device *bdev;
351-
uint32_t stripe;
352-
353-
stripe_map_sector(sc, sector, &stripe, &dev_sector);
354-
dev_sector += sc->stripe[stripe].physical_start;
355-
dax_dev = sc->stripe[stripe].dev->dax_dev;
356-
bdev = sc->stripe[stripe].dev->bdev;
338+
struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
357339

358-
if (bdev_dax_pgoff(bdev, dev_sector, ALIGN(bytes, PAGE_SIZE), &pgoff))
359-
return 0;
360340
return dax_copy_to_iter(dax_dev, pgoff, addr, bytes, i);
361341
}
362342

363343
static int stripe_dax_zero_page_range(struct dm_target *ti, pgoff_t pgoff,
364344
size_t nr_pages)
365345
{
366-
int ret;
367-
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
368-
struct stripe_c *sc = ti->private;
369-
struct dax_device *dax_dev;
370-
struct block_device *bdev;
371-
uint32_t stripe;
346+
struct dax_device *dax_dev = stripe_dax_pgoff(ti, &pgoff);
372347

373-
stripe_map_sector(sc, sector, &stripe, &dev_sector);
374-
dev_sector += sc->stripe[stripe].physical_start;
375-
dax_dev = sc->stripe[stripe].dev->dax_dev;
376-
bdev = sc->stripe[stripe].dev->bdev;
377-
378-
ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages << PAGE_SHIFT, &pgoff);
379-
if (ret)
380-
return ret;
381348
return dax_zero_page_range(dax_dev, pgoff, nr_pages);
382349
}
383350

0 commit comments

Comments
 (0)