* [PATCH 0/2] lightnvm: preparation patches for sysfs @ 2016-04-13 12:15 Simon A. F. Lund 2016-04-13 12:15 ` [PATCH 1/2] lightnvm: rename nvm_targets to nvm_tgt_type Simon A. F. Lund 2016-04-13 12:15 ` [PATCH 2/2] lightnvm: refactor dev->online_target to global nvm_targets Simon A. F. Lund 0 siblings, 2 replies; 5+ messages in thread From: Simon A. F. Lund @ 2016-04-13 12:15 UTC (permalink / raw) To: linux-block, linux-kernel, mb; +Cc: Simon A. F. Lund Hi, Here are two preparation patches for the upcoming sysfs implementation. Thanks Simon A. F. Lund (2): lightnvm: rename nvm_targets to nvm_tgt_type lightnvm: refactor dev->online_target to global nvm_targets drivers/lightnvm/core.c | 63 +++++++++++++++++++++++++----------------------- drivers/lightnvm/rrpc.c | 4 +-- include/linux/lightnvm.h | 5 ++-- 3 files changed, 37 insertions(+), 35 deletions(-) -- 2.5.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] lightnvm: rename nvm_targets to nvm_tgt_type 2016-04-13 12:15 [PATCH 0/2] lightnvm: preparation patches for sysfs Simon A. F. Lund @ 2016-04-13 12:15 ` Simon A. F. Lund 2016-04-16 14:19 ` Matias Bjørling 2016-04-13 12:15 ` [PATCH 2/2] lightnvm: refactor dev->online_target to global nvm_targets Simon A. F. Lund 1 sibling, 1 reply; 5+ messages in thread From: Simon A. F. Lund @ 2016-04-13 12:15 UTC (permalink / raw) To: linux-block, linux-kernel, mb; +Cc: Simon A. F. Lund The functions nvm_register_target(), nvm_unregister_target() and associated list refers to a target type that is being registered by a target type module. Rename nvm_*_targets() to nvm_*_tgt_type(), so that the intension is clear. This enables target instances to use the _nvm_*_targets() naming. Signed-off-by: Simon A. F. Lund <slund@cnexlabs.com> --- drivers/lightnvm/core.c | 16 ++++++++-------- drivers/lightnvm/rrpc.c | 4 ++-- include/linux/lightnvm.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 74fb049..240b473 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -30,7 +30,7 @@ #include <linux/sched/sysctl.h> #include <uapi/linux/lightnvm.h> -static LIST_HEAD(nvm_targets); +static LIST_HEAD(nvm_tgt_types); static LIST_HEAD(nvm_mgrs); static LIST_HEAD(nvm_devices); static DECLARE_RWSEM(nvm_lock); @@ -39,14 +39,14 @@ static struct nvm_tgt_type *nvm_find_target_type(const char *name) { struct nvm_tgt_type *tt; - list_for_each_entry(tt, &nvm_targets, list) + list_for_each_entry(tt, &nvm_tgt_types, list) if (!strcmp(name, tt->name)) return tt; return NULL; } -int nvm_register_target(struct nvm_tgt_type *tt) +int nvm_register_tgt_type(struct nvm_tgt_type *tt) { int ret = 0; @@ -54,14 +54,14 @@ int nvm_register_target(struct nvm_tgt_type *tt) if (nvm_find_target_type(tt->name)) ret = -EEXIST; else - list_add(&tt->list, &nvm_targets); + list_add(&tt->list, &nvm_tgt_types); up_write(&nvm_lock); return ret; } -EXPORT_SYMBOL(nvm_register_target); +EXPORT_SYMBOL(nvm_register_tgt_type); -void nvm_unregister_target(struct nvm_tgt_type *tt) +void nvm_unregister_tgt_type(struct nvm_tgt_type *tt) { if (!tt) return; @@ -70,7 +70,7 @@ void nvm_unregister_target(struct nvm_tgt_type *tt) list_del(&tt->list); up_write(&nvm_lock); } -EXPORT_SYMBOL(nvm_unregister_target); +EXPORT_SYMBOL(nvm_unregister_tgt_type); void *nvm_dev_dma_alloc(struct nvm_dev *dev, gfp_t mem_flags, dma_addr_t *dma_handler) @@ -1020,7 +1020,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) info->version[2] = NVM_VERSION_PATCH; down_write(&nvm_lock); - list_for_each_entry(tt, &nvm_targets, list) { + list_for_each_entry(tt, &nvm_tgt_types, list) { struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter]; tgt->version[0] = tt->version[0]; diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c index 3ab6495..4625e9c 100644 --- a/drivers/lightnvm/rrpc.c +++ b/drivers/lightnvm/rrpc.c @@ -1468,12 +1468,12 @@ static struct nvm_tgt_type tt_rrpc = { static int __init rrpc_module_init(void) { - return nvm_register_target(&tt_rrpc); + return nvm_register_tgt_type(&tt_rrpc); } static void rrpc_module_exit(void) { - nvm_unregister_target(&tt_rrpc); + nvm_unregister_tgt_type(&tt_rrpc); } module_init(rrpc_module_init); diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h index dacaa28..497da91 100644 --- a/include/linux/lightnvm.h +++ b/include/linux/lightnvm.h @@ -453,8 +453,8 @@ struct nvm_tgt_type { struct list_head list; }; -extern int nvm_register_target(struct nvm_tgt_type *); -extern void nvm_unregister_target(struct nvm_tgt_type *); +extern int nvm_register_tgt_type(struct nvm_tgt_type *); +extern void nvm_unregister_tgt_type(struct nvm_tgt_type *); extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *); extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t); -- 2.5.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] lightnvm: rename nvm_targets to nvm_tgt_type 2016-04-13 12:15 ` [PATCH 1/2] lightnvm: rename nvm_targets to nvm_tgt_type Simon A. F. Lund @ 2016-04-16 14:19 ` Matias Bjørling 0 siblings, 0 replies; 5+ messages in thread From: Matias Bjørling @ 2016-04-16 14:19 UTC (permalink / raw) To: Simon A. F. Lund, linux-block, linux-kernel On 04/13/2016 02:15 PM, Simon A. F. Lund wrote: > The functions nvm_register_target(), nvm_unregister_target() and > associated list refers to a target type that is being registered by a > target type module. Rename nvm_*_targets() to nvm_*_tgt_type(), so that > the intension is clear. > > This enables target instances to use the _nvm_*_targets() naming. > > Signed-off-by: Simon A. F. Lund <slund@cnexlabs.com> > --- > drivers/lightnvm/core.c | 16 ++++++++-------- > drivers/lightnvm/rrpc.c | 4 ++-- > include/linux/lightnvm.h | 4 ++-- > 3 files changed, 12 insertions(+), 12 deletions(-) > > diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c > index 74fb049..240b473 100644 > --- a/drivers/lightnvm/core.c > +++ b/drivers/lightnvm/core.c > @@ -30,7 +30,7 @@ > #include <linux/sched/sysctl.h> > #include <uapi/linux/lightnvm.h> > > -static LIST_HEAD(nvm_targets); > +static LIST_HEAD(nvm_tgt_types); > static LIST_HEAD(nvm_mgrs); > static LIST_HEAD(nvm_devices); > static DECLARE_RWSEM(nvm_lock); > @@ -39,14 +39,14 @@ static struct nvm_tgt_type *nvm_find_target_type(const char *name) > { > struct nvm_tgt_type *tt; > > - list_for_each_entry(tt, &nvm_targets, list) > + list_for_each_entry(tt, &nvm_tgt_types, list) > if (!strcmp(name, tt->name)) > return tt; > > return NULL; > } > > -int nvm_register_target(struct nvm_tgt_type *tt) > +int nvm_register_tgt_type(struct nvm_tgt_type *tt) > { > int ret = 0; > > @@ -54,14 +54,14 @@ int nvm_register_target(struct nvm_tgt_type *tt) > if (nvm_find_target_type(tt->name)) > ret = -EEXIST; > else > - list_add(&tt->list, &nvm_targets); > + list_add(&tt->list, &nvm_tgt_types); > up_write(&nvm_lock); > > return ret; > } > -EXPORT_SYMBOL(nvm_register_target); > +EXPORT_SYMBOL(nvm_register_tgt_type); > > -void nvm_unregister_target(struct nvm_tgt_type *tt) > +void nvm_unregister_tgt_type(struct nvm_tgt_type *tt) > { > if (!tt) > return; > @@ -70,7 +70,7 @@ void nvm_unregister_target(struct nvm_tgt_type *tt) > list_del(&tt->list); > up_write(&nvm_lock); > } > -EXPORT_SYMBOL(nvm_unregister_target); > +EXPORT_SYMBOL(nvm_unregister_tgt_type); > > void *nvm_dev_dma_alloc(struct nvm_dev *dev, gfp_t mem_flags, > dma_addr_t *dma_handler) > @@ -1020,7 +1020,7 @@ static long nvm_ioctl_info(struct file *file, void __user *arg) > info->version[2] = NVM_VERSION_PATCH; > > down_write(&nvm_lock); > - list_for_each_entry(tt, &nvm_targets, list) { > + list_for_each_entry(tt, &nvm_tgt_types, list) { > struct nvm_ioctl_info_tgt *tgt = &info->tgts[tgt_iter]; > > tgt->version[0] = tt->version[0]; > diff --git a/drivers/lightnvm/rrpc.c b/drivers/lightnvm/rrpc.c > index 3ab6495..4625e9c 100644 > --- a/drivers/lightnvm/rrpc.c > +++ b/drivers/lightnvm/rrpc.c > @@ -1468,12 +1468,12 @@ static struct nvm_tgt_type tt_rrpc = { > > static int __init rrpc_module_init(void) > { > - return nvm_register_target(&tt_rrpc); > + return nvm_register_tgt_type(&tt_rrpc); > } > > static void rrpc_module_exit(void) > { > - nvm_unregister_target(&tt_rrpc); > + nvm_unregister_tgt_type(&tt_rrpc); > } > > module_init(rrpc_module_init); > diff --git a/include/linux/lightnvm.h b/include/linux/lightnvm.h > index dacaa28..497da91 100644 > --- a/include/linux/lightnvm.h > +++ b/include/linux/lightnvm.h > @@ -453,8 +453,8 @@ struct nvm_tgt_type { > struct list_head list; > }; > > -extern int nvm_register_target(struct nvm_tgt_type *); > -extern void nvm_unregister_target(struct nvm_tgt_type *); > +extern int nvm_register_tgt_type(struct nvm_tgt_type *); > +extern void nvm_unregister_tgt_type(struct nvm_tgt_type *); > > extern void *nvm_dev_dma_alloc(struct nvm_dev *, gfp_t, dma_addr_t *); > extern void nvm_dev_dma_free(struct nvm_dev *, void *, dma_addr_t); > Thanks Simon. Applied for 4.7. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] lightnvm: refactor dev->online_target to global nvm_targets 2016-04-13 12:15 [PATCH 0/2] lightnvm: preparation patches for sysfs Simon A. F. Lund 2016-04-13 12:15 ` [PATCH 1/2] lightnvm: rename nvm_targets to nvm_tgt_type Simon A. F. Lund @ 2016-04-13 12:15 ` Simon A. F. Lund 2016-04-16 14:20 ` Matias Bjørling 1 sibling, 1 reply; 5+ messages in thread From: Simon A. F. Lund @ 2016-04-13 12:15 UTC (permalink / raw) To: linux-block, linux-kernel, mb; +Cc: Simon A. F. Lund 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> --- 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.5.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] lightnvm: refactor dev->online_target to global nvm_targets 2016-04-13 12:15 ` [PATCH 2/2] lightnvm: refactor dev->online_target to global nvm_targets Simon A. F. Lund @ 2016-04-16 14:20 ` Matias Bjørling 0 siblings, 0 replies; 5+ messages in thread From: Matias Bjørling @ 2016-04-16 14:20 UTC (permalink / raw) To: Simon A. F. Lund, linux-block, linux-kernel On 04/13/2016 02:15 PM, Simon A. F. Lund wrote: > 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> > --- > 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; > Thanks. Applied for 4.7. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-04-16 14:20 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2016-04-13 12:15 [PATCH 0/2] lightnvm: preparation patches for sysfs Simon A. F. Lund 2016-04-13 12:15 ` [PATCH 1/2] lightnvm: rename nvm_targets to nvm_tgt_type Simon A. F. Lund 2016-04-16 14:19 ` Matias Bjørling 2016-04-13 12:15 ` [PATCH 2/2] lightnvm: refactor dev->online_target to global nvm_targets Simon A. F. Lund 2016-04-16 14:20 ` Matias Bjørling
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox