diff options
author | Matias Bjørling <m@bjorling.me> | 2016-01-12 01:49:38 -0500 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2016-01-12 10:21:18 -0500 |
commit | b769207678176d590ea61ce7a64c9100925668b7 (patch) | |
tree | 74cd968a5a847b6d74fbf42a9b76ce0826ca8eda | |
parent | 5569615424613aa006005f18b03a3a12738a47d7 (diff) |
lightnvm: use system block for mm initialization
Use system block information to register the appropriate media manager.
This enables the LightNVM subsystem to instantiate a media manager
selected by the user, instead of relying on automatic detection by each
media manager loaded in the kernel.
A device must now be initialized before it can proceed to initialize its
media manager. Upon initialization, the configured media manager is
automatically initialized as well.
Signed-off-by: Matias Bjørling <m@bjorling.me>
Signed-off-by: Jens Axboe <axboe@fb.com>
-rw-r--r-- | drivers/lightnvm/core.c | 25 | ||||
-rw-r--r-- | include/linux/lightnvm.h | 3 |
2 files changed, 26 insertions, 2 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index ee08fac6f327..9e5712dda062 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c | |||
@@ -106,6 +106,9 @@ struct nvmm_type *nvm_init_mgr(struct nvm_dev *dev) | |||
106 | lockdep_assert_held(&nvm_lock); | 106 | lockdep_assert_held(&nvm_lock); |
107 | 107 | ||
108 | list_for_each_entry(mt, &nvm_mgrs, list) { | 108 | list_for_each_entry(mt, &nvm_mgrs, list) { |
109 | if (strncmp(dev->sb.mmtype, mt->name, NVM_MMTYPE_LEN)) | ||
110 | continue; | ||
111 | |||
109 | ret = mt->register_mgr(dev); | 112 | ret = mt->register_mgr(dev); |
110 | if (ret < 0) { | 113 | if (ret < 0) { |
111 | pr_err("nvm: media mgr failed to init (%d) on dev %s\n", | 114 | pr_err("nvm: media mgr failed to init (%d) on dev %s\n", |
@@ -569,9 +572,16 @@ int nvm_register(struct request_queue *q, char *disk_name, | |||
569 | } | 572 | } |
570 | } | 573 | } |
571 | 574 | ||
575 | ret = nvm_get_sysblock(dev, &dev->sb); | ||
576 | if (!ret) | ||
577 | pr_err("nvm: device not initialized.\n"); | ||
578 | else if (ret < 0) | ||
579 | pr_err("nvm: err (%d) on device initialization\n", ret); | ||
580 | |||
572 | /* register device with a supported media manager */ | 581 | /* register device with a supported media manager */ |
573 | down_write(&nvm_lock); | 582 | down_write(&nvm_lock); |
574 | dev->mt = nvm_init_mgr(dev); | 583 | if (ret > 0) |
584 | dev->mt = nvm_init_mgr(dev); | ||
575 | list_add(&dev->devices, &nvm_devices); | 585 | list_add(&dev->devices, &nvm_devices); |
576 | up_write(&nvm_lock); | 586 | up_write(&nvm_lock); |
577 | 587 | ||
@@ -1030,6 +1040,7 @@ static long __nvm_ioctl_dev_init(struct nvm_ioctl_dev_init *init) | |||
1030 | { | 1040 | { |
1031 | struct nvm_dev *dev; | 1041 | struct nvm_dev *dev; |
1032 | struct nvm_sb_info info; | 1042 | struct nvm_sb_info info; |
1043 | int ret; | ||
1033 | 1044 | ||
1034 | down_write(&nvm_lock); | 1045 | down_write(&nvm_lock); |
1035 | dev = nvm_find_nvm_dev(init->dev); | 1046 | dev = nvm_find_nvm_dev(init->dev); |
@@ -1044,7 +1055,17 @@ static long __nvm_ioctl_dev_init(struct nvm_ioctl_dev_init *init) | |||
1044 | strncpy(info.mmtype, init->mmtype, NVM_MMTYPE_LEN); | 1055 | strncpy(info.mmtype, init->mmtype, NVM_MMTYPE_LEN); |
1045 | info.fs_ppa.ppa = -1; | 1056 | info.fs_ppa.ppa = -1; |
1046 | 1057 | ||
1047 | return nvm_init_sysblock(dev, &info); | 1058 | ret = nvm_init_sysblock(dev, &info); |
1059 | if (ret) | ||
1060 | return ret; | ||
1061 | |||
1062 | memcpy(&dev->sb, &info, sizeof(struct nvm_sb_info)); | ||
1063 | |||
1064 | down_write(&nvm_lock); | ||
1065 | dev->mt = nvm_init_mgr(dev); | ||
1066 | up_write(&nvm_lock); | ||
1067 | |||
1068 | return 0; | ||
1048 | } | 1069 | } |
1049 | 1070 | ||
1050 | static long nvm_ioctl_dev_init(struct file *file, void __user *arg) | 1071 | static long nvm_ioctl_dev_init(struct file *file, void __user *arg) |
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index 7ad22d3f0d2e..02f36bdf216e 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h | |||
@@ -301,6 +301,9 @@ struct nvm_dev { | |||
301 | struct nvmm_type *mt; | 301 | struct nvmm_type *mt; |
302 | void *mp; | 302 | void *mp; |
303 | 303 | ||
304 | /* System blocks */ | ||
305 | struct nvm_sb_info sb; | ||
306 | |||
304 | /* Device information */ | 307 | /* Device information */ |
305 | int nr_chnls; | 308 | int nr_chnls; |
306 | int nr_planes; | 309 | int nr_planes; |