From 8217148c97a474a9eab4a309589ceb8ff281f5c6 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 21 Mar 2012 21:57:37 +0530 Subject: features/locks: Avoid race in pl_inode_get Change-Id: I6c7b878fb43863137aac6552ee66f091534a6296 BUG: 770080 Signed-off-by: Pranith Kumar K Reviewed-on: http://review.gluster.com/2998 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- xlators/features/locks/src/common.c | 46 ++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 643a7a80db2..b775fcca70b 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -437,32 +437,36 @@ pl_inode_get (xlator_t *this, inode_t *inode) pl_inode_t *pl_inode = NULL; int ret = 0; - ret = inode_ctx_get (inode, this,&tmp_pl_inode); - if (ret == 0) { - pl_inode = (pl_inode_t *)(long)tmp_pl_inode; - goto out; - } - pl_inode = GF_CALLOC (1, sizeof (*pl_inode), - gf_locks_mt_pl_inode_t); - if (!pl_inode) { - goto out; - } + LOCK (&inode->lock); + { + ret = __inode_ctx_get (inode, this, &tmp_pl_inode); + if (ret == 0) { + pl_inode = (pl_inode_t *)(long)tmp_pl_inode; + goto unlock; + } + pl_inode = GF_CALLOC (1, sizeof (*pl_inode), + gf_locks_mt_pl_inode_t); + if (!pl_inode) { + goto unlock; + } - gf_log (this->name, GF_LOG_TRACE, - "Allocating new pl inode"); + gf_log (this->name, GF_LOG_TRACE, + "Allocating new pl inode"); - pthread_mutex_init (&pl_inode->mutex, NULL); + pthread_mutex_init (&pl_inode->mutex, NULL); - INIT_LIST_HEAD (&pl_inode->dom_list); - INIT_LIST_HEAD (&pl_inode->ext_list); - INIT_LIST_HEAD (&pl_inode->rw_list); - INIT_LIST_HEAD (&pl_inode->reservelk_list); - INIT_LIST_HEAD (&pl_inode->blocked_reservelks); - INIT_LIST_HEAD (&pl_inode->blocked_calls); + INIT_LIST_HEAD (&pl_inode->dom_list); + INIT_LIST_HEAD (&pl_inode->ext_list); + INIT_LIST_HEAD (&pl_inode->rw_list); + INIT_LIST_HEAD (&pl_inode->reservelk_list); + INIT_LIST_HEAD (&pl_inode->blocked_reservelks); + INIT_LIST_HEAD (&pl_inode->blocked_calls); - inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode)); + __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode)); + } +unlock: + UNLOCK (&inode->lock); -out: return pl_inode; } -- cgit