summaryrefslogtreecommitdiffstats
path: root/xlators/features/locks/src/common.c
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kparthas@redhat.com>2013-01-31 10:29:20 +0530
committerAnand Avati <avati@redhat.com>2013-02-03 12:16:07 -0800
commit6b262d20940b088a1d72ad5518cc4908a7316b5a (patch)
treead82bf324c48f6e10c5bb8aa517327d70d75a4d2 /xlators/features/locks/src/common.c
parent67d0e72b16104911fef1cebb0b7a1b24d683e899 (diff)
locks: Protected racy (read) access of ext_list
Change-Id: Ibf639695ebd99c11c6960c9be82c0cee71b50744 BUG: 905864 Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-on: http://review.gluster.org/4458 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amarts@redhat.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'xlators/features/locks/src/common.c')
-rw-r--r--xlators/features/locks/src/common.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c
index cfba16ff735..9c21bddb9e0 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;
}
/*