Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1396043
| From | Matias Bjørling <m@bjorling.me> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 10/28] lightnvm: refactor dev->online_target to global nvm_targets |
| Date | 2016-05-06 20:20 +0200 |
| Message-ID | <rvSw1-1EJ-5@gated-at.bofh.it> (permalink) |
| References | <rvSml-1A4-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: "Simon A. F. Lund" <slund@cnexlabs.com>
A target name must be unique. However, a per-device registration of
targets is maintained on a dev->online_targets list, with a per-device
search for targets upon registration.
This results in a name collision when two targets, with the same name,
are created on two different targets, where the per-device list is not
shared.
Signed-off-by: Simon A. F. Lund <slund@cnexlabs.com>
Signed-off-by: Matias Bjørling <m@bjorling.me>
---
drivers/lightnvm/core.c | 47 +++++++++++++++++++++++++----------------------
include/linux/lightnvm.h | 1 -
2 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c
index 240b473..0296223 100644
--- a/drivers/lightnvm/core.c
+++ b/drivers/lightnvm/core.c
@@ -33,8 +33,20 @@
static LIST_HEAD(nvm_tgt_types);
static LIST_HEAD(nvm_mgrs);
static LIST_HEAD(nvm_devices);
+static LIST_HEAD(nvm_targets);
static DECLARE_RWSEM(nvm_lock);
+static struct nvm_target *nvm_find_target(const char *name)
+{
+ struct nvm_target *tgt;
+
+ list_for_each_entry(tgt, &nvm_targets, list)
+ if (!strcmp(name, tgt->disk->disk_name))
+ return tgt;
+
+ return NULL;
+}
+
static struct nvm_tgt_type *nvm_find_target_type(const char *name)
{
struct nvm_tgt_type *tt;
@@ -564,7 +576,6 @@ static int nvm_core_init(struct nvm_dev *dev)
goto err_fmtype;
}
- INIT_LIST_HEAD(&dev->online_targets);
mutex_init(&dev->mlock);
spin_lock_init(&dev->lock);
@@ -744,12 +755,11 @@ static int nvm_create_target(struct nvm_dev *dev,
return -EINVAL;
}
- list_for_each_entry(t, &dev->online_targets, list) {
- if (!strcmp(create->tgtname, t->disk->disk_name)) {
- pr_err("nvm: target name already exists.\n");
- up_write(&nvm_lock);
- return -EINVAL;
- }
+ t = nvm_find_target(create->tgtname);
+ if (t) {
+ pr_err("nvm: target name already exists.\n");
+ up_write(&nvm_lock);
+ return -EINVAL;
}
up_write(&nvm_lock);
@@ -789,7 +799,7 @@ static int nvm_create_target(struct nvm_dev *dev,
t->disk = tdisk;
down_write(&nvm_lock);
- list_add_tail(&t->list, &dev->online_targets);
+ list_add_tail(&t->list, &nvm_targets);
up_write(&nvm_lock);
return 0;
@@ -852,26 +862,19 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create)
static int __nvm_configure_remove(struct nvm_ioctl_remove *remove)
{
- struct nvm_target *t = NULL;
- struct nvm_dev *dev;
- int ret = -1;
+ struct nvm_target *t;
down_write(&nvm_lock);
- list_for_each_entry(dev, &nvm_devices, devices)
- list_for_each_entry(t, &dev->online_targets, list) {
- if (!strcmp(remove->tgtname, t->disk->disk_name)) {
- nvm_remove_target(t);
- ret = 0;
- break;
- }
- }
- up_write(&nvm_lock);
-
- if (ret) {
+ t = nvm_find_target(remove->tgtname);
+ if (!t) {
pr_err("nvm: target \"%s\" doesn't exist.\n", remove->tgtname);
+ up_write(&nvm_lock);
return -EINVAL;
}
+ nvm_remove_target(t);
+ up_write(&nvm_lock);
+
return 0;
}
diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h
index 497da91..5eabdba 100644
--- a/include/linux/lightnvm.h
+++ b/include/linux/lightnvm.h
@@ -308,7 +308,6 @@ struct nvm_dev {
struct nvm_dev_ops *ops;
struct list_head devices;
- struct list_head online_targets;
/* Media manager */
struct nvmm_type *mt;
--
2.1.4
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/28] LightNVM fixes for 4.7 Matias Bjørling <m@bjorling.me> - 2016-05-06 20:10 +0200 [PATCH 04/28] lightnvm: add fpg_size and pfpg_size to struct nvm_dev Matias Bjørling <m@bjorling.me> - 2016-05-06 20:10 +0200 [PATCH 11/28] lightnvm: introduce nvm_for_each_lun_ppa() macro Matias Bjørling <m@bjorling.me> - 2016-05-06 20:10 +0200 [PATCH 05/28] lightnvm: move block fold outside of get_bb_tbl() Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 10/28] lightnvm: refactor dev->online_target to global nvm_targets Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 13/28] lightnvm: remove struct factory_blks Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 07/28] lightnvm: calculate rrpc total blocks and sectors up front Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 09/28] lightnvm: rename nvm_targets to nvm_tgt_type Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 06/28] lightnvm: avoid memory leak when lun_map kcalloc fails Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 02/28] lightnvm: handle submit_io failure Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 12/28] lightnvm: refactor device ops->get_bb_tbl() Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 03/28] lightnvm: implement nvm_submit_ppa_list Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 14/28] lightnvm: make nvm_set_rqd_ppalist() aware of vblks Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 [PATCH 01/28] lightnvm: fix "warning: ‘ret’ may be used uninitialized" Matias Bjørling <m@bjorling.me> - 2016-05-06 20:20 +0200 Re: [PATCH 00/28] LightNVM fixes for 4.7 Jens Axboe <axboe@fb.com> - 2016-05-10 16:50 +0200
csiph-web