diff options
| author | Anand Avati <avati@gluster.com> | 2009-10-15 19:36:47 +0000 |
|---|---|---|
| committer | Anand V. Avati <avati@dev.gluster.com> | 2009-10-16 05:13:01 -0700 |
| commit | c8f39bea04c6021243d1ab2bcea450a0f067aabc (patch) | |
| tree | fdfcc4c0bc7f852184476a274060c2144ad3c691 /xlators/features/locks/src/common.c | |
| parent | d3722f7546bdcfeed7cf3c2745c1bfafa7fa79a4 (diff) | |
locks: keep ref on the inode while locks are held
keeping refs on the inode while there are held locks prevents the
inode from getting pruned away
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 112 (parallel deletion of files mounted by different clients on the same back-end hangs and/or does not completely delete)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=112
Diffstat (limited to 'xlators/features/locks/src/common.c')
| -rw-r--r-- | xlators/features/locks/src/common.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 5f115f6fa53..11841e92d07 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -35,6 +35,7 @@ #include "common-utils.h" #include "locks.h" +#include "common.h" static int @@ -48,6 +49,53 @@ __insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock, ? &pl_inode->ext_list \ : &pl_inode->int_list) + +int +__pl_inode_is_empty (pl_inode_t *pl_inode) +{ + int is_empty = 1; + + if (!list_empty (&pl_inode->ext_list)) + is_empty = 0; + + if (!list_empty (&pl_inode->int_list)) + is_empty = 0; + + if (!list_empty (&pl_inode->dir_list)) + is_empty = 0; + + return is_empty; +} + +void +pl_update_refkeeper (xlator_t *this, inode_t *inode) +{ + pl_inode_t *pl_inode = NULL; + int is_empty = 0; + int need_unref = 0; + + pl_inode = pl_inode_get (this, inode); + + pthread_mutex_lock (&pl_inode->mutex); + { + is_empty = __pl_inode_is_empty (pl_inode); + + if (is_empty && pl_inode->refkeeper) { + need_unref = 1; + pl_inode->refkeeper = NULL; + } + + if (!is_empty && !pl_inode->refkeeper) { + pl_inode->refkeeper = inode_ref (inode); + } + } + pthread_mutex_unlock (&pl_inode->mutex); + + if (need_unref) + inode_unref (inode); +} + + pl_inode_t * pl_inode_get (xlator_t *this, inode_t *inode) { |
