summaryrefslogtreecommitdiffstats
path: root/drivers/block/null_blk.c
diff options
context:
space:
mode:
authorMatias Bjørling <m@bjorling.me>2016-09-16 14:25:07 +0200
committerJens Axboe <axboe@fb.com>2016-09-21 15:56:18 +0200
commitb0b4e09c1ae71c4ec33df0616b830ae050006e9b (patch)
tree67a148740845d77af662b36ec17d88f991c84d72 /drivers/block/null_blk.c
parentblk-mq: register device instead of disk (diff)
downloadlinux-b0b4e09c1ae71c4ec33df0616b830ae050006e9b.tar.xz
linux-b0b4e09c1ae71c4ec33df0616b830ae050006e9b.zip
lightnvm: control life of nvm_dev in driver
LightNVM compatible device drivers does not have a method to expose LightNVM specific sysfs entries. To enable LightNVM sysfs entries to be exposed, lightnvm device drivers require a struct device to attach it to. To allow both the actual device driver and lightnvm sysfs entries to coexist, the device driver tracks the lifetime of the nvm_dev structure. This patch refactors NVMe and null_blk to handle the lifetime of struct nvm_dev, which eliminates the need for struct gendisk when a lightnvm compatible device is provided. Signed-off-by: Matias Bjørling <m@bjorling.me> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/block/null_blk.c')
-rw-r--r--drivers/block/null_blk.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index 895867a8a783..91e1de898daf 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -34,6 +34,7 @@ struct nullb {
unsigned int index;
struct request_queue *q;
struct gendisk *disk;
+ struct nvm_dev *ndev;
struct blk_mq_tag_set tag_set;
struct hrtimer timer;
unsigned int queue_depth;
@@ -550,12 +551,29 @@ static struct nvm_dev_ops null_lnvm_dev_ops = {
static int null_nvm_register(struct nullb *nullb)
{
- return nvm_register(nullb->q, nullb->disk_name, &null_lnvm_dev_ops);
+ struct nvm_dev *dev;
+ int rv;
+
+ dev = nvm_alloc_dev(0);
+ if (!dev)
+ return -ENOMEM;
+
+ dev->q = nullb->q;
+ memcpy(dev->name, nullb->disk_name, DISK_NAME_LEN);
+ dev->ops = &null_lnvm_dev_ops;
+
+ rv = nvm_register(dev);
+ if (rv) {
+ kfree(dev);
+ return rv;
+ }
+ nullb->ndev = dev;
+ return 0;
}
static void null_nvm_unregister(struct nullb *nullb)
{
- nvm_unregister(nullb->disk_name);
+ nvm_unregister(nullb->ndev);
}
#else
static int null_nvm_register(struct nullb *nullb)