diff options
author | Dan Williams <dan.j.williams@intel.com> | 2017-04-12 16:37:44 -0400 |
---|---|---|
committer | Dan Williams <dan.j.williams@intel.com> | 2017-04-25 16:20:36 -0400 |
commit | 817bf40265459578abc36c6bd53e27775b5c7ec4 (patch) | |
tree | 7f77cc1bb97457d10d92df83a640d8d90023a653 /drivers | |
parent | f26c5719b2d7b00de69eb83eb1c1c831759fdc9b (diff) |
dm: teach dm-targets to use a dax_device + dax_operations
Arrange for dm to lookup the dax services available from member devices.
Update the dax-capable targets, linear and stripe, to route dax
operations to the underlying device. Changes the target-internal
->direct_access() method to more closely align with the dax_operations
->direct_access() calling convention.
Cc: Toshi Kani <toshi.kani@hpe.com>
Reviewed-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/md/dm-linear.c | 27 | ||||
-rw-r--r-- | drivers/md/dm-snap.c | 6 | ||||
-rw-r--r-- | drivers/md/dm-stripe.c | 29 | ||||
-rw-r--r-- | drivers/md/dm-target.c | 6 | ||||
-rw-r--r-- | drivers/md/dm.c | 16 |
5 files changed, 39 insertions, 45 deletions
diff --git a/drivers/md/dm-linear.c b/drivers/md/dm-linear.c index 4788b0b989a9..c5a52f4dae81 100644 --- a/drivers/md/dm-linear.c +++ b/drivers/md/dm-linear.c | |||
@@ -9,6 +9,7 @@ | |||
9 | #include <linux/init.h> | 9 | #include <linux/init.h> |
10 | #include <linux/blkdev.h> | 10 | #include <linux/blkdev.h> |
11 | #include <linux/bio.h> | 11 | #include <linux/bio.h> |
12 | #include <linux/dax.h> | ||
12 | #include <linux/slab.h> | 13 | #include <linux/slab.h> |
13 | #include <linux/device-mapper.h> | 14 | #include <linux/device-mapper.h> |
14 | 15 | ||
@@ -141,22 +142,20 @@ static int linear_iterate_devices(struct dm_target *ti, | |||
141 | return fn(ti, lc->dev, lc->start, ti->len, data); | 142 | return fn(ti, lc->dev, lc->start, ti->len, data); |
142 | } | 143 | } |
143 | 144 | ||
144 | static long linear_direct_access(struct dm_target *ti, sector_t sector, | 145 | static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
145 | void **kaddr, pfn_t *pfn, long size) | 146 | long nr_pages, void **kaddr, pfn_t *pfn) |
146 | { | 147 | { |
148 | long ret; | ||
147 | struct linear_c *lc = ti->private; | 149 | struct linear_c *lc = ti->private; |
148 | struct block_device *bdev = lc->dev->bdev; | 150 | struct block_device *bdev = lc->dev->bdev; |
149 | struct blk_dax_ctl dax = { | 151 | struct dax_device *dax_dev = lc->dev->dax_dev; |
150 | .sector = linear_map_sector(ti, sector), | 152 | sector_t dev_sector, sector = pgoff * PAGE_SECTORS; |
151 | .size = size, | 153 | |
152 | }; | 154 | dev_sector = linear_map_sector(ti, sector); |
153 | long ret; | 155 | ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff); |
154 | 156 | if (ret) | |
155 | ret = bdev_direct_access(bdev, &dax); | 157 | return ret; |
156 | *kaddr = dax.addr; | 158 | return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn); |
157 | *pfn = dax.pfn; | ||
158 | |||
159 | return ret; | ||
160 | } | 159 | } |
161 | 160 | ||
162 | static struct target_type linear_target = { | 161 | static struct target_type linear_target = { |
@@ -169,7 +168,7 @@ static struct target_type linear_target = { | |||
169 | .status = linear_status, | 168 | .status = linear_status, |
170 | .prepare_ioctl = linear_prepare_ioctl, | 169 | .prepare_ioctl = linear_prepare_ioctl, |
171 | .iterate_devices = linear_iterate_devices, | 170 | .iterate_devices = linear_iterate_devices, |
172 | .direct_access = linear_direct_access, | 171 | .direct_access = linear_dax_direct_access, |
173 | }; | 172 | }; |
174 | 173 | ||
175 | int __init dm_linear_init(void) | 174 | int __init dm_linear_init(void) |
diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index c65feeada864..e152d9817c81 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c | |||
@@ -2302,8 +2302,8 @@ static int origin_map(struct dm_target *ti, struct bio *bio) | |||
2302 | return do_origin(o->dev, bio); | 2302 | return do_origin(o->dev, bio); |
2303 | } | 2303 | } |
2304 | 2304 | ||
2305 | static long origin_direct_access(struct dm_target *ti, sector_t sector, | 2305 | static long origin_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
2306 | void **kaddr, pfn_t *pfn, long size) | 2306 | long nr_pages, void **kaddr, pfn_t *pfn) |
2307 | { | 2307 | { |
2308 | DMWARN("device does not support dax."); | 2308 | DMWARN("device does not support dax."); |
2309 | return -EIO; | 2309 | return -EIO; |
@@ -2368,7 +2368,7 @@ static struct target_type origin_target = { | |||
2368 | .postsuspend = origin_postsuspend, | 2368 | .postsuspend = origin_postsuspend, |
2369 | .status = origin_status, | 2369 | .status = origin_status, |
2370 | .iterate_devices = origin_iterate_devices, | 2370 | .iterate_devices = origin_iterate_devices, |
2371 | .direct_access = origin_direct_access, | 2371 | .direct_access = origin_dax_direct_access, |
2372 | }; | 2372 | }; |
2373 | 2373 | ||
2374 | static struct target_type snapshot_target = { | 2374 | static struct target_type snapshot_target = { |
diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c index 28193a57bf47..cb4b1e9e16ab 100644 --- a/drivers/md/dm-stripe.c +++ b/drivers/md/dm-stripe.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/init.h> | 11 | #include <linux/init.h> |
12 | #include <linux/blkdev.h> | 12 | #include <linux/blkdev.h> |
13 | #include <linux/bio.h> | 13 | #include <linux/bio.h> |
14 | #include <linux/dax.h> | ||
14 | #include <linux/slab.h> | 15 | #include <linux/slab.h> |
15 | #include <linux/log2.h> | 16 | #include <linux/log2.h> |
16 | 17 | ||
@@ -308,27 +309,25 @@ static int stripe_map(struct dm_target *ti, struct bio *bio) | |||
308 | return DM_MAPIO_REMAPPED; | 309 | return DM_MAPIO_REMAPPED; |
309 | } | 310 | } |
310 | 311 | ||
311 | static long stripe_direct_access(struct dm_target *ti, sector_t sector, | 312 | static long stripe_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
312 | void **kaddr, pfn_t *pfn, long size) | 313 | long nr_pages, void **kaddr, pfn_t *pfn) |
313 | { | 314 | { |
315 | sector_t dev_sector, sector = pgoff * PAGE_SECTORS; | ||
314 | struct stripe_c *sc = ti->private; | 316 | struct stripe_c *sc = ti->private; |
315 | uint32_t stripe; | 317 | struct dax_device *dax_dev; |
316 | struct block_device *bdev; | 318 | struct block_device *bdev; |
317 | struct blk_dax_ctl dax = { | 319 | uint32_t stripe; |
318 | .size = size, | ||
319 | }; | ||
320 | long ret; | 320 | long ret; |
321 | 321 | ||
322 | stripe_map_sector(sc, sector, &stripe, &dax.sector); | 322 | stripe_map_sector(sc, sector, &stripe, &dev_sector); |
323 | 323 | dev_sector += sc->stripe[stripe].physical_start; | |
324 | dax.sector += sc->stripe[stripe].physical_start; | 324 | dax_dev = sc->stripe[stripe].dev->dax_dev; |
325 | bdev = sc->stripe[stripe].dev->bdev; | 325 | bdev = sc->stripe[stripe].dev->bdev; |
326 | 326 | ||
327 | ret = bdev_direct_access(bdev, &dax); | 327 | ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff); |
328 | *kaddr = dax.addr; | 328 | if (ret) |
329 | *pfn = dax.pfn; | 329 | return ret; |
330 | 330 | return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn); | |
331 | return ret; | ||
332 | } | 331 | } |
333 | 332 | ||
334 | /* | 333 | /* |
@@ -448,7 +447,7 @@ static struct target_type stripe_target = { | |||
448 | .status = stripe_status, | 447 | .status = stripe_status, |
449 | .iterate_devices = stripe_iterate_devices, | 448 | .iterate_devices = stripe_iterate_devices, |
450 | .io_hints = stripe_io_hints, | 449 | .io_hints = stripe_io_hints, |
451 | .direct_access = stripe_direct_access, | 450 | .direct_access = stripe_dax_direct_access, |
452 | }; | 451 | }; |
453 | 452 | ||
454 | int __init dm_stripe_init(void) | 453 | int __init dm_stripe_init(void) |
diff --git a/drivers/md/dm-target.c b/drivers/md/dm-target.c index 43d3445b121d..6a7968f93f3c 100644 --- a/drivers/md/dm-target.c +++ b/drivers/md/dm-target.c | |||
@@ -142,8 +142,8 @@ static void io_err_release_clone_rq(struct request *clone) | |||
142 | { | 142 | { |
143 | } | 143 | } |
144 | 144 | ||
145 | static long io_err_direct_access(struct dm_target *ti, sector_t sector, | 145 | static long io_err_dax_direct_access(struct dm_target *ti, pgoff_t pgoff, |
146 | void **kaddr, pfn_t *pfn, long size) | 146 | long nr_pages, void **kaddr, pfn_t *pfn) |
147 | { | 147 | { |
148 | return -EIO; | 148 | return -EIO; |
149 | } | 149 | } |
@@ -157,7 +157,7 @@ static struct target_type error_target = { | |||
157 | .map = io_err_map, | 157 | .map = io_err_map, |
158 | .clone_and_map_rq = io_err_clone_and_map_rq, | 158 | .clone_and_map_rq = io_err_clone_and_map_rq, |
159 | .release_clone_rq = io_err_release_clone_rq, | 159 | .release_clone_rq = io_err_release_clone_rq, |
160 | .direct_access = io_err_direct_access, | 160 | .direct_access = io_err_dax_direct_access, |
161 | }; | 161 | }; |
162 | 162 | ||
163 | int __init dm_target_init(void) | 163 | int __init dm_target_init(void) |
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index bd56dfe43a99..ef4c6f8cad47 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -630,6 +630,7 @@ static int open_table_device(struct table_device *td, dev_t dev, | |||
630 | } | 630 | } |
631 | 631 | ||
632 | td->dm_dev.bdev = bdev; | 632 | td->dm_dev.bdev = bdev; |
633 | td->dm_dev.dax_dev = dax_get_by_host(bdev->bd_disk->disk_name); | ||
633 | return 0; | 634 | return 0; |
634 | } | 635 | } |
635 | 636 | ||
@@ -643,7 +644,9 @@ static void close_table_device(struct table_device *td, struct mapped_device *md | |||
643 | 644 | ||
644 | bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md)); | 645 | bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md)); |
645 | blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL); | 646 | blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL); |
647 | put_dax(td->dm_dev.dax_dev); | ||
646 | td->dm_dev.bdev = NULL; | 648 | td->dm_dev.bdev = NULL; |
649 | td->dm_dev.dax_dev = NULL; | ||
647 | } | 650 | } |
648 | 651 | ||
649 | static struct table_device *find_table_device(struct list_head *l, dev_t dev, | 652 | static struct table_device *find_table_device(struct list_head *l, dev_t dev, |
@@ -945,16 +948,9 @@ static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, | |||
945 | if (len < 1) | 948 | if (len < 1) |
946 | goto out; | 949 | goto out; |
947 | nr_pages = min(len, nr_pages); | 950 | nr_pages = min(len, nr_pages); |
948 | if (ti->type->direct_access) { | 951 | if (ti->type->direct_access) |
949 | ret = ti->type->direct_access(ti, sector, kaddr, pfn, | 952 | ret = ti->type->direct_access(ti, pgoff, nr_pages, kaddr, pfn); |
950 | nr_pages * PAGE_SIZE); | 953 | |
951 | /* | ||
952 | * FIXME: convert ti->type->direct_access to return | ||
953 | * nr_pages directly. | ||
954 | */ | ||
955 | if (ret >= 0) | ||
956 | ret /= PAGE_SIZE; | ||
957 | } | ||
958 | out: | 954 | out: |
959 | dm_put_live_table(md, srcu_idx); | 955 | dm_put_live_table(md, srcu_idx); |
960 | 956 | ||