diff options
author | Simon A. F. Lund <slund@cnexlabs.com> | 2016-05-06 14:03:03 -0400 |
---|---|---|
committer | Jens Axboe <axboe@fb.com> | 2016-05-06 14:51:10 -0400 |
commit | 6f8645cba54a4b2983bbd46f462b5891ffbd72fc (patch) | |
tree | 5ec5bc7246b403109203cb58c9aa164b0b2f3ae4 /drivers/lightnvm/core.c | |
parent | 6063fe399d0913e7bd4462650cd4f31b479a83c9 (diff) |
lightnvm: refactor dev->online_target to global nvm_targets
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>
Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'drivers/lightnvm/core.c')
-rw-r--r-- | drivers/lightnvm/core.c | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 240b4731c35e..0296223392f7 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c | |||
@@ -33,8 +33,20 @@ | |||
33 | static LIST_HEAD(nvm_tgt_types); | 33 | static LIST_HEAD(nvm_tgt_types); |
34 | static LIST_HEAD(nvm_mgrs); | 34 | static LIST_HEAD(nvm_mgrs); |
35 | static LIST_HEAD(nvm_devices); | 35 | static LIST_HEAD(nvm_devices); |
36 | static LIST_HEAD(nvm_targets); | ||
36 | static DECLARE_RWSEM(nvm_lock); | 37 | static DECLARE_RWSEM(nvm_lock); |
37 | 38 | ||
39 | static struct nvm_target *nvm_find_target(const char *name) | ||
40 | { | ||
41 | struct nvm_target *tgt; | ||
42 | |||
43 | list_for_each_entry(tgt, &nvm_targets, list) | ||
44 | if (!strcmp(name, tgt->disk->disk_name)) | ||
45 | return tgt; | ||
46 | |||
47 | return NULL; | ||
48 | } | ||
49 | |||
38 | static struct nvm_tgt_type *nvm_find_target_type(const char *name) | 50 | static struct nvm_tgt_type *nvm_find_target_type(const char *name) |
39 | { | 51 | { |
40 | struct nvm_tgt_type *tt; | 52 | struct nvm_tgt_type *tt; |
@@ -564,7 +576,6 @@ static int nvm_core_init(struct nvm_dev *dev) | |||
564 | goto err_fmtype; | 576 | goto err_fmtype; |
565 | } | 577 | } |
566 | 578 | ||
567 | INIT_LIST_HEAD(&dev->online_targets); | ||
568 | mutex_init(&dev->mlock); | 579 | mutex_init(&dev->mlock); |
569 | spin_lock_init(&dev->lock); | 580 | spin_lock_init(&dev->lock); |
570 | 581 | ||
@@ -744,12 +755,11 @@ static int nvm_create_target(struct nvm_dev *dev, | |||
744 | return -EINVAL; | 755 | return -EINVAL; |
745 | } | 756 | } |
746 | 757 | ||
747 | list_for_each_entry(t, &dev->online_targets, list) { | 758 | t = nvm_find_target(create->tgtname); |
748 | if (!strcmp(create->tgtname, t->disk->disk_name)) { | 759 | if (t) { |
749 | pr_err("nvm: target name already exists.\n"); | 760 | pr_err("nvm: target name already exists.\n"); |
750 | up_write(&nvm_lock); | 761 | up_write(&nvm_lock); |
751 | return -EINVAL; | 762 | return -EINVAL; |
752 | } | ||
753 | } | 763 | } |
754 | up_write(&nvm_lock); | 764 | up_write(&nvm_lock); |
755 | 765 | ||
@@ -789,7 +799,7 @@ static int nvm_create_target(struct nvm_dev *dev, | |||
789 | t->disk = tdisk; | 799 | t->disk = tdisk; |
790 | 800 | ||
791 | down_write(&nvm_lock); | 801 | down_write(&nvm_lock); |
792 | list_add_tail(&t->list, &dev->online_targets); | 802 | list_add_tail(&t->list, &nvm_targets); |
793 | up_write(&nvm_lock); | 803 | up_write(&nvm_lock); |
794 | 804 | ||
795 | return 0; | 805 | return 0; |
@@ -852,26 +862,19 @@ static int __nvm_configure_create(struct nvm_ioctl_create *create) | |||
852 | 862 | ||
853 | static int __nvm_configure_remove(struct nvm_ioctl_remove *remove) | 863 | static int __nvm_configure_remove(struct nvm_ioctl_remove *remove) |
854 | { | 864 | { |
855 | struct nvm_target *t = NULL; | 865 | struct nvm_target *t; |
856 | struct nvm_dev *dev; | ||
857 | int ret = -1; | ||
858 | 866 | ||
859 | down_write(&nvm_lock); | 867 | down_write(&nvm_lock); |
860 | list_for_each_entry(dev, &nvm_devices, devices) | 868 | t = nvm_find_target(remove->tgtname); |
861 | list_for_each_entry(t, &dev->online_targets, list) { | 869 | if (!t) { |
862 | if (!strcmp(remove->tgtname, t->disk->disk_name)) { | ||
863 | nvm_remove_target(t); | ||
864 | ret = 0; | ||
865 | break; | ||
866 | } | ||
867 | } | ||
868 | up_write(&nvm_lock); | ||
869 | |||
870 | if (ret) { | ||
871 | pr_err("nvm: target \"%s\" doesn't exist.\n", remove->tgtname); | 870 | pr_err("nvm: target \"%s\" doesn't exist.\n", remove->tgtname); |
871 | up_write(&nvm_lock); | ||
872 | return -EINVAL; | 872 | return -EINVAL; |
873 | } | 873 | } |
874 | 874 | ||
875 | nvm_remove_target(t); | ||
876 | up_write(&nvm_lock); | ||
877 | |||
875 | return 0; | 878 | return 0; |
876 | } | 879 | } |
877 | 880 | ||