From: Wang Wensheng wangwensheng4@huawei.com
Split function xshmem_pool_create().
Signed-off-by: Wang Wensheng wangwensheng4@huawei.com --- lib/xshmem/xshmem_framework.c | 50 ++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 17 deletions(-)
diff --git a/lib/xshmem/xshmem_framework.c b/lib/xshmem/xshmem_framework.c index 9966b48..392abaa 100644 --- a/lib/xshmem/xshmem_framework.c +++ b/lib/xshmem/xshmem_framework.c @@ -246,32 +246,20 @@ static int xshmem_pool_detach(struct xshm_task *task, struct xshm_pool *xp) }
/* - * get the POOL specified by key, create one if it not exist. + * The caller must hold xshmem_mutex and this function would unlock xshmem_mutex on failure. */ -static struct xshm_pool *xshmem_pool_create(struct xshm_pool_algo *algo, struct xshm_reg_arg *arg) +static struct xshm_pool *xshmem_pool_create(struct xshm_pool_algo *algo, struct xshm_reg_arg *arg, + struct hlist_head *bucket) { int id, ret; struct xshm_pool *xp; - struct hlist_head *bucket; char *key = arg->key; unsigned int key_len = arg->key_len;
- bucket = hash_bucket(key, key_len); - - mutex_lock(&xshmem_mutex); - hlist_for_each_entry(xp, bucket, hnode) - if (key_len == xp->key_len && !strncmp(key, xp->key, key_len)) { - if (xp->algo != algo || !algo->xshm_pool_same(xp, arg)) { - mutex_unlock(&xshmem_mutex); - pr_err("the pool reg arg check failed\n"); - return ERR_PTR(-EINVAL); - } else - goto exist; - } - xp = kmalloc(sizeof(*xp) + key_len + 1, GFP_KERNEL); if (unlikely(!xp)) { mutex_unlock(&xshmem_mutex); + pr_err("alloc pool memory failed\n"); return ERR_PTR(-ENOMEM); }
@@ -313,6 +301,34 @@ static struct xshm_pool *xshmem_pool_create(struct xshm_pool_algo *algo, struct
hlist_add_head(&xp->hnode, bucket);
+ return xp; +} + +/* + * get the POOL specified by key, create one if it not exist. + */ +static struct xshm_pool *xshmem_pool_register(struct xshm_pool_algo *algo, struct xshm_reg_arg *arg) +{ + struct xshm_pool *xp; + struct hlist_head *bucket; + + bucket = hash_bucket(arg->key, arg->key_len); + + mutex_lock(&xshmem_mutex); + hlist_for_each_entry(xp, bucket, hnode) + if (arg->key_len == xp->key_len && !strncmp(arg->key, xp->key, arg->key_len)) { + if (xp->algo != algo || !algo->xshm_pool_same(xp, arg)) { + mutex_unlock(&xshmem_mutex); + pr_err("the pool reg arg check failed\n"); + return ERR_PTR(-EINVAL); + } else + goto exist; + } + + xp = xshmem_pool_create(algo, arg, bucket); + if (IS_ERR(xp)) + return xp; + exist: /* * Here increase the POOL's refcnt by one, one for the convenience of fallback in @@ -390,7 +406,7 @@ static int ioctl_xshmem_pool_register(struct xshm_task *task, unsigned long arg) }
reg_arg.key = key; - xp = xshmem_pool_create(algo, ®_arg); + xp = xshmem_pool_register(algo, ®_arg); if (IS_ERR(xp)) return PTR_ERR(xp);