diff options
author | Vikas Gorur <vikas@zresearch.com> | 2009-02-27 02:14:15 +0530 |
---|---|---|
committer | Anand V. Avati <avati@amp.gluster.com> | 2009-02-27 02:36:04 +0530 |
commit | 2dbcb3c79338dc4f4c45c21e4bf62e61e455ae19 (patch) | |
tree | 42ce3c02dc2f8adf741ee505ef21dae85a9f715a /xlators/features/locks/src/common.c | |
parent | f097e77ffb386dc73e3639af4a9cd57df0d3d40d (diff) |
reverting nested locks in posix-locks for inodelk
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'xlators/features/locks/src/common.c')
-rw-r--r-- | xlators/features/locks/src/common.c | 90 |
1 files changed, 44 insertions, 46 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index bdabb1511bb..d87aec229ed 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2006-2009 Z RESEARCH, Inc. <http://www.zresearch.com> + Copyright (c) 2006, 2007, 2008 Z RESEARCH, Inc. <http://www.zresearch.com> This file is part of GlusterFS. GlusterFS is free software; you can redistribute it and/or modify @@ -37,53 +37,51 @@ #include "locks.h" -int -pl_is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock, - gf_lk_domain_t dom); +static int +__is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock, + gf_lk_domain_t dom); static void __insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock, gf_lk_domain_t dom); +#define DOMAIN_HEAD(pl_inode, dom) (dom == GF_LOCK_POSIX \ + ? &pl_inode->ext_list \ + : &pl_inode->int_list) pl_inode_t * pl_inode_get (xlator_t *this, inode_t *inode) { - pl_inode_t *pl_inode = NULL; - mode_t st_mode = 0; - uint64_t tmp_pl_inode = 0; - int ret = 0; - - 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 out; - } + pl_inode_t *pl_inode = NULL; + mode_t st_mode = 0; + int ret = 0; + + ret = inode_ctx_get (inode, this, + (uint64_t *)(&pl_inode)); + if (ret == 0) + goto out; + + pl_inode = CALLOC (1, sizeof (*pl_inode)); + if (!pl_inode) { + gf_log (this->name, GF_LOG_ERROR, + "out of memory :("); + goto out; + } - pl_inode = CALLOC (1, sizeof (*pl_inode)); - if (!pl_inode) { - gf_log (this->name, GF_LOG_ERROR, - "out of memory :("); - goto out; - } + st_mode = inode->st_mode; + if ((st_mode & S_ISGID) && !(st_mode & S_IXGRP)) + pl_inode->mandatory = 1; - st_mode = inode->st_mode; - if ((st_mode & S_ISGID) && !(st_mode & S_IXGRP)) - pl_inode->mandatory = 1; + pthread_mutex_init (&pl_inode->mutex, NULL); - pthread_mutex_init (&pl_inode->mutex, NULL); - - INIT_LIST_HEAD (&pl_inode->dir_list); - INIT_LIST_HEAD (&pl_inode->ext_list); - INIT_LIST_HEAD (&pl_inode->int_list); - INIT_LIST_HEAD (&pl_inode->rw_list); + INIT_LIST_HEAD (&pl_inode->dir_list); + INIT_LIST_HEAD (&pl_inode->ext_list); + INIT_LIST_HEAD (&pl_inode->int_list); + INIT_LIST_HEAD (&pl_inode->rw_list); + + ret = inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode)); - ret = inode_ctx_put (inode, this, (uint64_t)(long)pl_inode); - } out: - UNLOCK (&inode->lock); return pl_inode; } @@ -148,8 +146,8 @@ posix_lock_to_flock (posix_lock_t *lock, struct flock *flock) /* Insert the lock into the inode's lock list */ -void -pl_insert_lock (pl_inode_t *pl_inode, posix_lock_t *lock, gf_lk_domain_t dom) +static void +__insert_lock (pl_inode_t *pl_inode, posix_lock_t *lock, gf_lk_domain_t dom) { list_add_tail (&lock->list, DOMAIN_HEAD (pl_inode, dom)); @@ -305,9 +303,9 @@ first_overlap (pl_inode_t *pl_inode, posix_lock_t *lock, /* Return true if lock is grantable */ -int -pl_is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock, - gf_lk_domain_t dom) +static int +__is_lock_grantable (pl_inode_t *pl_inode, posix_lock_t *lock, + gf_lk_domain_t dom) { posix_lock_t *l = NULL; int ret = 1; @@ -398,14 +396,14 @@ __insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock, } if ((conf->fl_type == F_RDLCK) && (lock->fl_type == F_RDLCK)) { - pl_insert_lock (pl_inode, lock, dom); + __insert_lock (pl_inode, lock, dom); return; } } /* no conflicts, so just insert */ if (lock->fl_type != F_UNLCK) { - pl_insert_lock (pl_inode, lock, dom); + __insert_lock (pl_inode, lock, dom); } else { __destroy_lock (lock); } @@ -437,12 +435,12 @@ __grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode, list_for_each_entry_safe (l, tmp, &tmp_list, list) { list_del_init (&l->list); - if (pl_is_lock_grantable (pl_inode, l, dom)) { + if (__is_lock_grantable (pl_inode, l, dom)) { conf = CALLOC (1, sizeof (*conf)); if (!conf) { l->blocked = 1; - pl_insert_lock (pl_inode, l, dom); + __insert_lock (pl_inode, l, dom); continue; } @@ -463,7 +461,7 @@ __grant_blocked_locks (xlator_t *this, pl_inode_t *pl_inode, list_add (&conf->list, granted); } else { l->blocked = 1; - pl_insert_lock (pl_inode, l, dom); + __insert_lock (pl_inode, l, dom); } } } @@ -506,7 +504,7 @@ pl_setlk (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock, pthread_mutex_lock (&pl_inode->mutex); { - if (pl_is_lock_grantable (pl_inode, lock, dom)) { + if (__is_lock_grantable (pl_inode, lock, dom)) { gf_log (this->name, GF_LOG_DEBUG, "%s (pid=%d) %"PRId64" - %"PRId64" => OK", lock->fl_type == F_UNLCK ? "Unlock" : "Lock", @@ -522,7 +520,7 @@ pl_setlk (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock, lock->user_flock.l_start, lock->user_flock.l_len); lock->blocked = 1; - pl_insert_lock (pl_inode, lock, dom); + __insert_lock (pl_inode, lock, dom); ret = -1; } else { gf_log (this->name, GF_LOG_DEBUG, |