提交 817bf402 编写于 作者: D Dan Williams

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: NMike Snitzer <snitzer@redhat.com>
Signed-off-by: NDan Williams <dan.j.williams@intel.com>
上级 f26c5719
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/dax.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/device-mapper.h> #include <linux/device-mapper.h>
...@@ -141,22 +142,20 @@ static int linear_iterate_devices(struct dm_target *ti, ...@@ -141,22 +142,20 @@ static int linear_iterate_devices(struct dm_target *ti,
return fn(ti, lc->dev, lc->start, ti->len, data); return fn(ti, lc->dev, lc->start, ti->len, data);
} }
static long linear_direct_access(struct dm_target *ti, sector_t sector, static long linear_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
void **kaddr, pfn_t *pfn, long size) long nr_pages, void **kaddr, pfn_t *pfn)
{ {
long ret;
struct linear_c *lc = ti->private; struct linear_c *lc = ti->private;
struct block_device *bdev = lc->dev->bdev; struct block_device *bdev = lc->dev->bdev;
struct blk_dax_ctl dax = { struct dax_device *dax_dev = lc->dev->dax_dev;
.sector = linear_map_sector(ti, sector), sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
.size = size,
}; dev_sector = linear_map_sector(ti, sector);
long ret; ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff);
if (ret)
ret = bdev_direct_access(bdev, &dax); return ret;
*kaddr = dax.addr; return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
*pfn = dax.pfn;
return ret;
} }
static struct target_type linear_target = { static struct target_type linear_target = {
...@@ -169,7 +168,7 @@ static struct target_type linear_target = { ...@@ -169,7 +168,7 @@ static struct target_type linear_target = {
.status = linear_status, .status = linear_status,
.prepare_ioctl = linear_prepare_ioctl, .prepare_ioctl = linear_prepare_ioctl,
.iterate_devices = linear_iterate_devices, .iterate_devices = linear_iterate_devices,
.direct_access = linear_direct_access, .direct_access = linear_dax_direct_access,
}; };
int __init dm_linear_init(void) int __init dm_linear_init(void)
......
...@@ -2302,8 +2302,8 @@ static int origin_map(struct dm_target *ti, struct bio *bio) ...@@ -2302,8 +2302,8 @@ static int origin_map(struct dm_target *ti, struct bio *bio)
return do_origin(o->dev, bio); return do_origin(o->dev, bio);
} }
static long origin_direct_access(struct dm_target *ti, sector_t sector, static long origin_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
void **kaddr, pfn_t *pfn, long size) long nr_pages, void **kaddr, pfn_t *pfn)
{ {
DMWARN("device does not support dax."); DMWARN("device does not support dax.");
return -EIO; return -EIO;
...@@ -2368,7 +2368,7 @@ static struct target_type origin_target = { ...@@ -2368,7 +2368,7 @@ static struct target_type origin_target = {
.postsuspend = origin_postsuspend, .postsuspend = origin_postsuspend,
.status = origin_status, .status = origin_status,
.iterate_devices = origin_iterate_devices, .iterate_devices = origin_iterate_devices,
.direct_access = origin_direct_access, .direct_access = origin_dax_direct_access,
}; };
static struct target_type snapshot_target = { static struct target_type snapshot_target = {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include <linux/bio.h> #include <linux/bio.h>
#include <linux/dax.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/log2.h> #include <linux/log2.h>
...@@ -308,27 +309,25 @@ static int stripe_map(struct dm_target *ti, struct bio *bio) ...@@ -308,27 +309,25 @@ static int stripe_map(struct dm_target *ti, struct bio *bio)
return DM_MAPIO_REMAPPED; return DM_MAPIO_REMAPPED;
} }
static long stripe_direct_access(struct dm_target *ti, sector_t sector, static long stripe_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
void **kaddr, pfn_t *pfn, long size) long nr_pages, void **kaddr, pfn_t *pfn)
{ {
sector_t dev_sector, sector = pgoff * PAGE_SECTORS;
struct stripe_c *sc = ti->private; struct stripe_c *sc = ti->private;
uint32_t stripe; struct dax_device *dax_dev;
struct block_device *bdev; struct block_device *bdev;
struct blk_dax_ctl dax = { uint32_t stripe;
.size = size,
};
long ret; long ret;
stripe_map_sector(sc, sector, &stripe, &dax.sector); stripe_map_sector(sc, sector, &stripe, &dev_sector);
dev_sector += sc->stripe[stripe].physical_start;
dax.sector += sc->stripe[stripe].physical_start; dax_dev = sc->stripe[stripe].dev->dax_dev;
bdev = sc->stripe[stripe].dev->bdev; bdev = sc->stripe[stripe].dev->bdev;
ret = bdev_direct_access(bdev, &dax); ret = bdev_dax_pgoff(bdev, dev_sector, nr_pages * PAGE_SIZE, &pgoff);
*kaddr = dax.addr; if (ret)
*pfn = dax.pfn; return ret;
return dax_direct_access(dax_dev, pgoff, nr_pages, kaddr, pfn);
return ret;
} }
/* /*
...@@ -448,7 +447,7 @@ static struct target_type stripe_target = { ...@@ -448,7 +447,7 @@ static struct target_type stripe_target = {
.status = stripe_status, .status = stripe_status,
.iterate_devices = stripe_iterate_devices, .iterate_devices = stripe_iterate_devices,
.io_hints = stripe_io_hints, .io_hints = stripe_io_hints,
.direct_access = stripe_direct_access, .direct_access = stripe_dax_direct_access,
}; };
int __init dm_stripe_init(void) int __init dm_stripe_init(void)
......
...@@ -142,8 +142,8 @@ static void io_err_release_clone_rq(struct request *clone) ...@@ -142,8 +142,8 @@ static void io_err_release_clone_rq(struct request *clone)
{ {
} }
static long io_err_direct_access(struct dm_target *ti, sector_t sector, static long io_err_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
void **kaddr, pfn_t *pfn, long size) long nr_pages, void **kaddr, pfn_t *pfn)
{ {
return -EIO; return -EIO;
} }
...@@ -157,7 +157,7 @@ static struct target_type error_target = { ...@@ -157,7 +157,7 @@ static struct target_type error_target = {
.map = io_err_map, .map = io_err_map,
.clone_and_map_rq = io_err_clone_and_map_rq, .clone_and_map_rq = io_err_clone_and_map_rq,
.release_clone_rq = io_err_release_clone_rq, .release_clone_rq = io_err_release_clone_rq,
.direct_access = io_err_direct_access, .direct_access = io_err_dax_direct_access,
}; };
int __init dm_target_init(void) int __init dm_target_init(void)
......
...@@ -630,6 +630,7 @@ static int open_table_device(struct table_device *td, dev_t dev, ...@@ -630,6 +630,7 @@ static int open_table_device(struct table_device *td, dev_t dev,
} }
td->dm_dev.bdev = bdev; td->dm_dev.bdev = bdev;
td->dm_dev.dax_dev = dax_get_by_host(bdev->bd_disk->disk_name);
return 0; return 0;
} }
...@@ -643,7 +644,9 @@ static void close_table_device(struct table_device *td, struct mapped_device *md ...@@ -643,7 +644,9 @@ static void close_table_device(struct table_device *td, struct mapped_device *md
bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md)); bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md));
blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL); blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL);
put_dax(td->dm_dev.dax_dev);
td->dm_dev.bdev = NULL; td->dm_dev.bdev = NULL;
td->dm_dev.dax_dev = NULL;
} }
static struct table_device *find_table_device(struct list_head *l, dev_t dev, 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,16 +948,9 @@ static long dm_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff,
if (len < 1) if (len < 1)
goto out; goto out;
nr_pages = min(len, nr_pages); nr_pages = min(len, nr_pages);
if (ti->type->direct_access) { if (ti->type->direct_access)
ret = ti->type->direct_access(ti, sector, kaddr, pfn, ret = ti->type->direct_access(ti, pgoff, nr_pages, kaddr, pfn);
nr_pages * PAGE_SIZE);
/*
* FIXME: convert ti->type->direct_access to return
* nr_pages directly.
*/
if (ret >= 0)
ret /= PAGE_SIZE;
}
out: out:
dm_put_live_table(md, srcu_idx); dm_put_live_table(md, srcu_idx);
......
...@@ -128,14 +128,15 @@ typedef int (*dm_busy_fn) (struct dm_target *ti); ...@@ -128,14 +128,15 @@ typedef int (*dm_busy_fn) (struct dm_target *ti);
* < 0 : error * < 0 : error
* >= 0 : the number of bytes accessible at the address * >= 0 : the number of bytes accessible at the address
*/ */
typedef long (*dm_direct_access_fn) (struct dm_target *ti, sector_t sector, typedef long (*dm_dax_direct_access_fn) (struct dm_target *ti, pgoff_t pgoff,
void **kaddr, pfn_t *pfn, long size); long nr_pages, void **kaddr, pfn_t *pfn);
#define PAGE_SECTORS (PAGE_SIZE / 512) #define PAGE_SECTORS (PAGE_SIZE / 512)
void dm_error(const char *message); void dm_error(const char *message);
struct dm_dev { struct dm_dev {
struct block_device *bdev; struct block_device *bdev;
struct dax_device *dax_dev;
fmode_t mode; fmode_t mode;
char name[16]; char name[16];
}; };
...@@ -177,7 +178,7 @@ struct target_type { ...@@ -177,7 +178,7 @@ struct target_type {
dm_busy_fn busy; dm_busy_fn busy;
dm_iterate_devices_fn iterate_devices; dm_iterate_devices_fn iterate_devices;
dm_io_hints_fn io_hints; dm_io_hints_fn io_hints;
dm_direct_access_fn direct_access; dm_dax_direct_access_fn direct_access;
/* For internal device-mapper use. */ /* For internal device-mapper use. */
struct list_head list; struct list_head list;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册