From 6b262d20940b088a1d72ad5518cc4908a7316b5a Mon Sep 17 00:00:00 2001 From: Krishnan Parthasarathi Date: Thu, 31 Jan 2013 10:29:20 +0530 Subject: locks: Protected racy (read) access of ext_list Change-Id: Ibf639695ebd99c11c6960c9be82c0cee71b50744 BUG: 905864 Signed-off-by: Krishnan Parthasarathi Reviewed-on: http://review.gluster.org/4458 Tested-by: Gluster Build System Reviewed-by: Amar Tumballi Reviewed-by: Anand Avati --- xlators/features/locks/src/common.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'xlators/features') diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index cfba16ff7..9c21bddb9 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -718,22 +718,30 @@ static posix_lock_t * first_conflicting_overlap (pl_inode_t *pl_inode, posix_lock_t *lock) { posix_lock_t *l = NULL; + posix_lock_t *conf = NULL; - list_for_each_entry (l, &pl_inode->ext_list, list) { - if (l->blocked) - continue; - - if (locks_overlap (l, lock)) { - if (same_owner (l, lock)) + pthread_mutex_lock (&pl_inode->mutex); + { + list_for_each_entry (l, &pl_inode->ext_list, list) { + if (l->blocked) continue; - if ((l->fl_type == F_WRLCK) || - (lock->fl_type == F_WRLCK)) - return l; + if (locks_overlap (l, lock)) { + if (same_owner (l, lock)) + continue; + + if ((l->fl_type == F_WRLCK) || + (lock->fl_type == F_WRLCK)) { + conf = l; + goto unlock; + } + } } } +unlock: + pthread_mutex_unlock (&pl_inode->mutex); - return NULL; + return conf; } /* -- cgit