idr: final idr_alloc() conversions and deprecation of old interface
Subsystems (8)
Tejun Heo
maintainerPATCH 1/1 idr: final idr_alloc() conversions and deprecation of old interface
Hello,
These are the final pieces of idr_alloc() conversion and deprecation of idr_pre_get() and idr_get_new*().
This patchset contains the following seven patches.
0001-nfsd-remove-unused-get_new_stid.patch 0002-nfsd-convert-to-idr_alloc.patch 0003-workqueue-convert-to-idr_alloc.patch 0004-mlx4-remove-leftover-idr_pre_get-call.patch 0005-zcache-convert-to-idr_alloc.patch 0006-tidspbridge-convert-to-idr_alloc.patch 0007-idr-deprecate-idr_pre_get-and-idr_get_new-_above.patch
The patches based on top of v3.9-rc1 and are also available in the following git branch.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/misc.git idr_alloc-final
Andrew, can you please route these through -mm?
diffstat follows, thanks.
drivers/infiniband/hw/mlx4/cm.c | 1 drivers/staging/tidspbridge/rmgr/drv.c | 70 ++++++++++++--------------------- drivers/staging/zcache/ramster/tcp.c | 25 ++++------- fs/nfsd/nfs4state.c | 36 ---------------- include/linux/idr.h | 66 +++++++++++++++++++++++-------- kernel/workqueue.c | 7 +-- lib/idr.c | 41 ++----------------- 7 files changed, 97 insertions(+), 149 deletions(-)
--
tejun
Tejun Heo
maintainerPATCH 1/7 nfsd: remove unused get_new_stid()
get_new_stid() is no longer used since 3abdb607125 ("nfsd4: simplify idr allocation"). Remove it.
--- fs/nfsd/nfs4state.c | 31 ------------------------------- 1 file changed, 31 deletions(-)
fs/nfsd/nfs4state.c +0 -31
@@ -230,37 +230,6 @@ static void nfs4_file_put_access(struct nfs4_file *fp, int oflag)__nfs4_file_put_access (fp, oflag); } -static inline int get_new_stid (struct nfs4_stid *stid) -{ -static int min_stateid =0 ; -struct idr *stateids = &stid->sc_client->cl_stateids; -int new_stid; -int error; - - error =idr_get_new_above (stateids, stid, min_stateid, &new_stid); -/* -* Note: the necessary preallocation was done in -* nfs4_alloc_stateid(). The idr code caps the number of -* preallocations that can exist at a time, but the state lock -* prevents anyone from using ours before we get here: -*/ -WARN_ON_ONCE (error); -/* -* It shouldn't be a problem to reuse an opaque stateid value. -* I don't think it is for 4.1. But with 4.0 I worry that, for -* example, a stray write retransmission could be accepted by -* the server when it should have been rejected. Therefore, -* adopt a trick from the sctp code to attempt to maximize the -* amount of time until an id is reused, by ensuring they always -* "increase" (mod INT_MAX): -*/ - - min_stateid = new_stid+1 ; -if (min_stateid ==INT_MAX ) - min_stateid =0 ; -return new_stid; -} -static struct nfs4_stid *nfs4_alloc_stid (struct nfs4_client *cl,struct kmem_cache *slab) {
Signature · 1 line
1.8.1.4
Re: [PATCH 1/7] nfsd: remove unused get_new_stid()
Quoted 2 lines · Tejun Heo
get_new_stid()is no longer used since3abdb607125("nfsd4: simplify idr allocation"). Remove it.
Whoops, thanks for catching that.
Quoted 53 lines
Signed-off-by Tejun Heo <[email protected]>Cc "J. Bruce Fields" <[email protected]>--- fs/nfsd/nfs4state.c | 31 ------------------------------- 1 file changed, 31 deletions(-)fs/nfsd/nfs4state.c +0
-31@@ -230,37 +230,6 @@ static void nfs4_file_put_access(struct nfs4_file *fp, int oflag)__nfs4_file_put_access (fp, oflag); } -static inline int get_new_stid (struct nfs4_stid *stid) -{ -static int min_stateid =0 ; -struct idr *stateids = &stid->sc_client->cl_stateids; -int new_stid; -int error; - - error =idr_get_new_above (stateids, stid, min_stateid, &new_stid); -/* -* Note: the necessary preallocation was done in -* nfs4_alloc_stateid(). The idr code caps the number of -* preallocations that can exist at a time, but the state lock -* prevents anyone from using ours before we get here: -*/ -WARN_ON_ONCE (error); -/* -* It shouldn't be a problem to reuse an opaque stateid value. -* I don't think it is for 4.1. But with 4.0 I worry that, for -* example, a stray write retransmission could be accepted by -* the server when it should have been rejected. Therefore, -* adopt a trick from the sctp code to attempt to maximize the -* amount of time until an id is reused, by ensuring they always -* "increase" (mod INT_MAX): -*/ - - min_stateid = new_stid+1 ; -if (min_stateid ==INT_MAX ) - min_stateid =0 ; -return new_stid; -} -static struct nfs4_stid *nfs4_alloc_stid (struct nfs4_client *cl,struct kmem_cache *slab) {Signature · 1 line
1.8.1.4
Tejun Heo
maintainerPATCH 2/7 nfsd: convert to idr_alloc()
In reply to Tejun Heoidr_get_new*() and friends are about to be deprecated. Convert to the new idr_alloc() interface.
Only compile-tested.
--- fs/nfsd/nfs4state.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/nfsd/nfs4state.c +2 -3
@@ -242,9 +242,8 @@ kmem_cache *slab)if (!stid)return NULL ; -if (!idr_pre_get (stateids,GFP_KERNEL )) - goto out_free; -if (idr_get_new_above (stateids, stid, min_stateid, &new_id)) + new_id =idr_alloc (stateids, stid, min_stateid,0 ,GFP_KERNEL ); +if (new_id <0 ) goto out_free; stid->sc_client = cl; stid->sc_type =0 ;
Signature · 1 line
1.8.1.4
Re: [PATCH 2/7] nfsd: convert to idr_alloc()
Quoted 4 lines · Tejun Heo
idr_get_new*() and friends are about to be deprecated. Convert to the new
idr_alloc()interface.Only compile-tested.
Runs fine too--thanks.
--b.
Quoted 27 lines
Signed-off-by Tejun Heo <[email protected]>Cc "J. Bruce Fields" <[email protected]>--- fs/nfsd/nfs4state.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)fs/nfsd/nfs4state.c +2
-3@@ -242,9 +242,8 @@ kmem_cache *slab)if (!stid)return NULL ; -if (!idr_pre_get (stateids,GFP_KERNEL )) - goto out_free; -if (idr_get_new_above (stateids, stid, min_stateid, &new_id)) + new_id =idr_alloc (stateids, stid, min_stateid,0 ,GFP_KERNEL ); +if (new_id <0 ) goto out_free; stid->sc_client = cl; stid->sc_type =0 ;Signature · 1 line
1.8.1.4
Tejun Heo
maintainerPATCH 3/7 workqueue: convert to idr_alloc()
In reply to Tejun Heoidr_get_new*() and friends are about to be deprecated. Convert to the new idr_alloc() interface.
--- kernel/workqueue.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
kernel/workqueue.c +4 -3
@@ -457,11 +457,12 @@ static int worker_pool_assign_id(struct worker_pool *pool)int ret;mutex_lock (&worker_pool_idr_mutex); -idr_pre_get (&worker_pool_idr,GFP_KERNEL ); - ret =idr_get_new (&worker_pool_idr, pool, &pool->id); + ret =idr_alloc (&worker_pool_idr, pool,0 ,0 ,GFP_KERNEL ); +if (ret >=0 ) + pool->id = ret;mutex_unlock (&worker_pool_idr_mutex); -return ret; +return ret <0 ? ret :0 ; }/*
Signature · 1 line
1.8.1.4
Tejun Heo
maintainerPATCH 4/7 mlx4: remove leftover idr_pre_get() call
In reply to Tejun Heo6a9200603d ("IB/mlx4: convert to idr_alloc()") forgot to remove idr_pre_get() call in mlx4_ib_cm_paravirt_init(). It's unnecessary and idr_pre_get() will soon be deprecated. Remove it.
--- drivers/infiniband/hw/mlx4/cm.c | 1 - 1 file changed, 1 deletion(-)
drivers/infiniband/hw/mlx4/cm.c +0 -1
@@ -362,7 +362,6 @@ void mlx4_ib_cm_paravirt_init(struct mlx4_ib_dev *dev)INIT_LIST_HEAD (&dev->sriov.cm_list); dev->sriov.sl_id_map =RB_ROOT ;idr_init (&dev->sriov.pv_id_table); -idr_pre_get (&dev->sriov.pv_id_table,GFP_KERNEL ); }/* slave = -1 ==> all slaves */
Signature · 1 line
1.8.1.4
Tejun Heo
maintainerPATCH 5/7 zcache: convert to idr_alloc()
In reply to Tejun Heoidr_get_new*() and friends are about to be deprecated. Convert to the new idr_alloc() interface.
Only compile tested.
--- drivers/staging/zcache/ramster/tcp.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
drivers/staging/zcache/ramster/tcp.c +10 -15
@@ -300,27 +300,22 @@ static u8 r2net_num_from_nn(struct r2net_node *nn)static int r2net_prep_nsw (struct r2net_node *nn,struct r2net_status_wait *nsw) { -int ret =0 ; +int ret; -do { -if (!idr_pre_get (&nn->nn_status_idr,GFP_ATOMIC )) { - ret = -EAGAIN ; -break ; - } -spin_lock (&nn->nn_lock); - ret =idr_get_new (&nn->nn_status_idr, nsw, &nsw->ns_id); -if (ret ==0 ) -list_add_tail (&nsw->ns_node_item, - &nn->nn_status_list); -spin_unlock (&nn->nn_lock); - }while (ret == -EAGAIN ); +spin_lock (&nn->nn_lock); + ret =idr_alloc (&nn->nn_status_idr, nsw,0 ,0 ,GFP_ATOMIC ); +if (ret >=0 ) { + nsw->ns_id = ret; +list_add_tail (&nsw->ns_node_item, &nn->nn_status_list); + } +spin_unlock (&nn->nn_lock); -if (ret ==0 ) { +if (ret >=0 ) {init_waitqueue_head (&nsw->ns_wq); nsw->ns_sys_status =R2NET_ERR_NONE ; nsw->ns_status =0 ; +return 0 ; } -return ret; }
Signature · 1 line
1.8.1.4
Re: [PATCH 5/7] zcache: convert to idr_alloc()
Quoted 10 lines · Tejun Heo
idr_get_new*() and friends are about to be deprecated. Convert to the new
idr_alloc()interface.Only compile tested.
Signed-off-by Tejun Heo <[email protected]>Cc Dan Magenheimer <[email protected]>--- drivers/staging/zcache/ramster/tcp.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-)
Tejun Heo
maintainerPATCH 6/7 tidspbridge: convert to idr_alloc()
In reply to Tejun Heoidr_get_new*() and friends are about to be deprecated. Convert to the new idr_alloc() interface.
There are some peculiarities and possible bugs in the converted functions. This patch preserves those.
* drv_insert_node_res_element() returns -ENOMEM on alloc failure, -EFAULT if id space is exhausted. -EFAULT is at best misleading.
* drv_proc_insert_strm_res_element() is even weirder. It returns -EFAULT if kzalloc() fails, -ENOMEM if idr preloading fails and -EPERM if id space is exhausted. What's going on here?
* drv_proc_insert_strm_res_element() doesn't free *pstrm_res after failure.
Only compile tested.
--- drivers/staging/tidspbridge/rmgr/drv.c | 70 +++++++++++++--------------------- 1 file changed, 26 insertions(+), 44 deletions(-)
drivers/staging/tidspbridge/rmgr/drv.c +26 -44
@@ -76,37 +76,28 @@ int drv_insert_node_res_element(void *hnode, void *node_resource,struct node_res_object **node_res_obj = (struct node_res_object **)node_resource;struct process_context *ctxt = (struct process_context *)process_ctxt; -int status =0 ;int retval; *node_res_obj =kzalloc (sizeof (struct node_res_object ),GFP_KERNEL ); -if (!*node_res_obj) { - status = -ENOMEM ; - goto func_end; - } +if (!*node_res_obj) +return -ENOMEM ; (*node_res_obj)->node = hnode; - retval =idr_get_new (ctxt->node_id, *node_res_obj, - &(*node_res_obj)->id); -if (retval == -EAGAIN ) { -if (!idr_pre_get (ctxt->node_id,GFP_KERNEL )) { -pr_err ("%s: OUT OF MEMORY\n" , __func__); - status = -ENOMEM ; - goto func_end; - } - - retval =idr_get_new (ctxt->node_id, *node_res_obj, - &(*node_res_obj)->id); + retval =idr_alloc (ctxt->node_id, *node_res_obj,0 ,0 ,GFP_KERNEL ); +if (retval >=0 ) { + (*node_res_obj)->id = retval; +return 0 ; } -if (retval) { + +kfree (*node_res_obj); + +if (retval == -ENOSPC ) {pr_err ("%s: FAILED, IDR is FULL\n" , __func__); - status = -EFAULT ; +return -EFAULT ; + }else { +pr_err ("%s: OUT OF MEMORY\n" , __func__); +return -ENOMEM ; } -func_end: -if (status) -kfree (*node_res_obj); - -return status; }/* Release all Node resources and its context
@@ -201,35 +192,26 @@ int drv_proc_insert_strm_res_element(void *stream_obj,struct strm_res_object **pstrm_res = (struct strm_res_object **)strm_res;struct process_context *ctxt = (struct process_context *)process_ctxt; -int status =0 ;int retval; *pstrm_res =kzalloc (sizeof (struct strm_res_object ),GFP_KERNEL ); -if (*pstrm_res ==NULL ) { - status = -EFAULT ; - goto func_end; - } +if (*pstrm_res ==NULL ) +return -EFAULT ; (*pstrm_res)->stream = stream_obj; - retval =idr_get_new (ctxt->stream_id, *pstrm_res, - &(*pstrm_res)->id); -if (retval == -EAGAIN ) { -if (!idr_pre_get (ctxt->stream_id,GFP_KERNEL )) { -pr_err ("%s: OUT OF MEMORY\n" , __func__); - status = -ENOMEM ; - goto func_end; - } - - retval =idr_get_new (ctxt->stream_id, *pstrm_res, - &(*pstrm_res)->id); + retval =idr_alloc (ctxt->stream_id, *pstrm_res,0 ,0 ,GFP_KERNEL ); +if (retval >=0 ) { + (*pstrm_res)->id = retval; +return 0 ; } -if (retval) { + +if (retval == -ENOSPC ) {pr_err ("%s: FAILED, IDR is FULL\n" , __func__); - status = -EPERM ; +return -EPERM ; + }else { +pr_err ("%s: OUT OF MEMORY\n" , __func__); +return -ENOMEM ; } - -func_end: -return status; }static int drv_proc_free_strm_res (int id,void *p,void *process_ctxt)
Signature · 1 line
1.8.1.4
Re: [PATCH 6/7] tidspbridge: convert to idr_alloc()
Quoted 24 lines · Tejun Heo
idr_get_new*() and friends are about to be deprecated. Convert to the new
idr_alloc()interface.There are some peculiarities and possible bugs in the converted functions. This patch preserves those.
*
drv_insert_node_res_element()returns-ENOMEMon alloc failure,-EFAULTif id space is exhausted.-EFAULTis at best misleading.*
drv_proc_insert_strm_res_element()is even weirder. It returns-EFAULTifkzalloc()fails,-ENOMEMif idr preloading fails and-EPERMif id space is exhausted. What's going on here?*
drv_proc_insert_strm_res_element()doesn't free*pstrm_resafter failure.Only compile tested.
Signed-off-by Tejun Heo <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc Víctor Manuel Jáquez Leal <[email protected]>Cc Rene Sapiens <[email protected]>Cc Armando Uribe <[email protected]>Cc Omar Ramirez Luna <[email protected]>
Quoted 3 lines
--- drivers/staging/tidspbridge/rmgr/drv.c | 70 +++++++++++++--------------------- 1 file changed, 26 insertions(+), 44 deletions(-)
Tejun Heo
maintainerPATCH 7/7 idr: deprecate idr_pre_get() and idr_get_new[_above]()
In reply to Tejun HeoNow that all in-kernel users are converted to ues the new alloc interface, mark the old interface deprecated. We should be able to remove these in a few releases.
--- include/linux/idr.h | 66 ++++++++++++++++++++++++++++++++++++++++------------- lib/idr.c | 41 ++++----------------------------- 2 files changed, 55 insertions(+), 52 deletions(-)
include/linux/idr.h +50 -16
@@ -73,8 +73,6 @@ struct idr {*/ void *idr_find_slowpath (struct idr *idp,int id); -int idr_pre_get (struct idr *idp,gfp_t gfp_mask); -int idr_get_new_above (struct idr *idp,void *ptr,int starting_id,int *id);void idr_preload (gfp_t gfp_mask);int idr_alloc (struct idr *idp,void *ptr,int start,int end,gfp_t gfp_mask); int idr_for_each(struct idr *idp,
@@ -120,19 +118,6 @@ static inline void *idr_find(struct idr *idr, int id) }/** -* idr_get_new - allocate new idr entry -* @idp: idr handle -* @ptr: pointer you want associated with the id -* @id: pointer to the allocated handle -* -* Simple wrapper around idr_get_new_above() w/ @starting_id of zero. -*/ -static inline int idr_get_new (struct idr *idp,void *ptr,int *id) -{ -return idr_get_new_above (idp, ptr,0 , id); -} - -/** * idr_for_each_entry - iterate over an idr's elements of a given type * @idp: idr handle * @entry: the type * to use as cursor
@@ -143,7 +128,56 @@ static inline int idr_get_new(struct idr *idp, void *ptr, int *id) entry !=NULL ; \ ++id, entry = (typeof(entry))idr_get_next((idp), &(id))) -void __idr_remove_all (struct idr *idp);/* don't use */ +/* +* Don't use the following functions. These exist only to suppress +* deprecated warnings on EXPORT_SYMBOL()s. +*/ +int __idr_pre_get (struct idr *idp,gfp_t gfp_mask); +int __idr_get_new_above (struct idr *idp,void *ptr,int starting_id,int *id); +void __idr_remove_all (struct idr *idp); + +/** +* idr_pre_get - reserve resources for idr allocation +* @idp: idr handle +* @gfp_mask: memory allocation flags +* +* Part of old alloc interface. This is going away. Use +* idr_preload[_end]() and idr_alloc() instead. +*/ +static inline int __deprecated idr_pre_get (struct idr *idp,gfp_t gfp_mask) +{ +return __idr_pre_get (idp, gfp_mask); +} + +/** +* idr_get_new_above - allocate new idr entry above or equal to a start id +* @idp: idr handle +* @ptr: pointer you want associated with the id +* @starting_id: id to start search at +* @id: pointer to the allocated handle +* +* Part of old alloc interface. This is going away. Use +* idr_preload[_end]() and idr_alloc() instead. +*/ +static inline int __deprecated idr_get_new_above (struct idr *idp,void *ptr, +int starting_id,int *id) +{ +return __idr_get_new_above (idp, ptr, starting_id, id); +} + +/** +* idr_get_new - allocate new idr entry +* @idp: idr handle +* @ptr: pointer you want associated with the id +* @id: pointer to the allocated handle +* +* Part of old alloc interface. This is going away. Use +* idr_preload[_end]() and idr_alloc() instead. +*/ +static inline int __deprecated idr_get_new (struct idr *idp,void *ptr,int *id) +{ +return __idr_get_new_above (idp, ptr,0 , id); +}/** * idr_remove_all - remove all ids from the given idr tree
lib/idr.c +5 -36
71 lines not on this page · raw message
Signature · 1 line
1.8.1.4