From 7bf78408ffec1efbceed17ed2e540d7d0af19763 Mon Sep 17 00:00:00 2001 From: Anand Avati Date: Fri, 16 Oct 2009 09:12:57 +0000 Subject: 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 BUG: 315 (generation number support) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=315 --- xlators/features/locks/src/common.c | 53 ++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'xlators/features/locks/src/common.c') diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index 08dc451e1..b9037688a 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 @@ -43,7 +44,7 @@ static void __insert_and_merge (pl_inode_t *pl_inode, posix_lock_t *lock); static pl_dom_list_t * -allocate_domain(const char *volume) +allocate_domain (const char *volume) { pl_dom_list_t *dom = NULL; @@ -95,6 +96,56 @@ found: return dom; } + +int +__pl_inode_is_empty (pl_inode_t *pl_inode) +{ + pl_dom_list_t *dom = NULL; + int is_empty = 1; + + if (!list_empty (&pl_inode->ext_list)) + is_empty = 0; + + list_for_each_entry (dom, &pl_inode->dom_list, inode_list) { + if (!list_empty (&dom->entrylk_list)) + is_empty = 0; + + if (!list_empty (&dom->inodelk_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) { -- cgit