summaryrefslogtreecommitdiffstats
path: root/xlators/features/locks/src
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/features/locks/src')
-rw-r--r--xlators/features/locks/src/entrylk.c52
-rw-r--r--xlators/features/locks/src/inodelk.c60
-rw-r--r--xlators/features/locks/src/posix.c11
3 files changed, 107 insertions, 16 deletions
diff --git a/xlators/features/locks/src/entrylk.c b/xlators/features/locks/src/entrylk.c
index dc86512be..8496d9d8d 100644
--- a/xlators/features/locks/src/entrylk.c
+++ b/xlators/features/locks/src/entrylk.c
@@ -715,15 +715,16 @@ pl_entrylk_client_cleanup (xlator_t *this, pl_ctx_t *ctx)
pl_inode_t *pinode = NULL;
struct list_head released;
+ struct list_head unwind;
INIT_LIST_HEAD (&released);
+ INIT_LIST_HEAD (&unwind);
pthread_mutex_lock (&ctx->lock);
{
list_for_each_entry_safe (l, tmp, &ctx->entrylk_lockers,
client_list) {
list_del_init (&l->client_list);
- list_add_tail (&l->client_list, &released);
pl_entrylk_log_cleanup (l);
@@ -731,25 +732,68 @@ pl_entrylk_client_cleanup (xlator_t *this, pl_ctx_t *ctx)
pthread_mutex_lock (&pinode->mutex);
{
- list_del_init (&l->domain_list);
+ /* If the entrylk object is part of granted list but not
+ * blocked list, then perform the following actions:
+ * i. delete the object from granted list;
+ * ii. grant other locks (from other clients) that may
+ * have been blocked on this entrylk; and
+ * iii. unref the object.
+ *
+ * If the entrylk object (L1) is part of both granted
+ * and blocked lists, then this means that a parallel
+ * unlock on another entrylk (L2 say) may have 'granted'
+ * L1 and added it to 'granted' list in
+ * __grant_blocked_entry_locks() (although using the
+ * 'blocked_locks' member). In that case, the cleanup
+ * codepath must try and grant other overlapping
+ * blocked entrylks from other clients, now that L1 is
+ * out of their way and then unref L1 in the end, and
+ * leave it to the other thread (the one executing
+ * unlock codepath) to unwind L1's frame, delete it from
+ * blocked_locks list, and perform the last unref on L1.
+ *
+ * If the entrylk object (L1) is part of blocked list
+ * only, the cleanup code path must:
+ * i. delete it from the blocked_locks list inside
+ * this critical section,
+ * ii. unwind its frame with EAGAIN,
+ * iii. try and grant blocked entry locks from other
+ * clients that were otherwise grantable, but were
+ * blocked to avoid leaving L1 to starve forever.
+ * iv. unref the object.
+ */
+ if (!list_empty (&l->domain_list)) {
+ list_del_init (&l->domain_list);
+ list_add_tail (&l->client_list,
+ &released);
+ } else {
+ list_del_init (&l->blocked_locks);
+ list_add_tail (&l->client_list,
+ &unwind);
+ }
}
pthread_mutex_unlock (&pinode->mutex);
}
}
pthread_mutex_unlock (&ctx->lock);
- list_for_each_entry_safe (l, tmp, &released, client_list) {
+ list_for_each_entry_safe (l, tmp, &unwind, client_list) {
list_del_init (&l->client_list);
if (l->frame)
STACK_UNWIND_STRICT (entrylk, l->frame, -1, EAGAIN,
NULL);
+ list_add_tail (&l->client_list, &released);
+ }
+
+ list_for_each_entry_safe (l, tmp, &released, client_list) {
+ list_del_init (&l->client_list);
pinode = l->pinode;
dom = get_domain (pinode, l->volume);
- grant_blocked_inode_locks (this, pinode, dom);
+ grant_blocked_entry_locks (this, pinode, dom);
pthread_mutex_lock (&pinode->mutex);
{
diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c
index e7093e60e..c76cb7f91 100644
--- a/xlators/features/locks/src/inodelk.c
+++ b/xlators/features/locks/src/inodelk.c
@@ -26,7 +26,7 @@
inline void
__delete_inode_lock (pl_inode_lock_t *lock)
{
- list_del (&lock->list);
+ list_del_init (&lock->list);
}
static inline void
@@ -35,7 +35,7 @@ __pl_inodelk_ref (pl_inode_lock_t *lock)
lock->ref++;
}
-void
+inline void
__pl_inodelk_unref (pl_inode_lock_t *lock)
{
lock->ref--;
@@ -404,7 +404,7 @@ pl_inodelk_log_cleanup (pl_inode_lock_t *lock)
}
-/* Release all entrylks from this client */
+/* Release all inodelks from this client */
int
pl_inodelk_client_cleanup (xlator_t *this, pl_ctx_t *ctx)
{
@@ -414,15 +414,16 @@ pl_inodelk_client_cleanup (xlator_t *this, pl_ctx_t *ctx)
pl_inode_t *pl_inode = NULL;
struct list_head released;
+ struct list_head unwind;
INIT_LIST_HEAD (&released);
+ INIT_LIST_HEAD (&unwind);
pthread_mutex_lock (&ctx->lock);
{
list_for_each_entry_safe (l, tmp, &ctx->inodelk_lockers,
client_list) {
list_del_init (&l->client_list);
- list_add_tail (&l->client_list, &released);
pl_inodelk_log_cleanup (l);
@@ -430,19 +431,64 @@ pl_inodelk_client_cleanup (xlator_t *this, pl_ctx_t *ctx)
pthread_mutex_lock (&pl_inode->mutex);
{
- __delete_inode_lock (l);
+ /* If the inodelk object is part of granted list but not
+ * blocked list, then perform the following actions:
+ * i. delete the object from granted list;
+ * ii. grant other locks (from other clients) that may
+ * have been blocked on this inodelk; and
+ * iii. unref the object.
+ *
+ * If the inodelk object (L1) is part of both granted
+ * and blocked lists, then this means that a parallel
+ * unlock on another inodelk (L2 say) may have 'granted'
+ * L1 and added it to 'granted' list in
+ * __grant_blocked_node_locks() (although using the
+ * 'blocked_locks' member). In that case, the cleanup
+ * codepath must try and grant other overlapping
+ * blocked inodelks from other clients, now that L1 is
+ * out of their way and then unref L1 in the end, and
+ * leave it to the other thread (the one executing
+ * unlock codepath) to unwind L1's frame, delete it from
+ * blocked_locks list, and perform the last unref on L1.
+ *
+ * If the inodelk object (L1) is part of blocked list
+ * only, the cleanup code path must:
+ * i. delete it from the blocked_locks list inside
+ * this critical section,
+ * ii. unwind its frame with EAGAIN,
+ * iii. try and grant blocked inode locks from other
+ * clients that were otherwise grantable, but just
+ * got blocked to avoid leaving L1 to starve
+ * forever.
+ * iv. unref the object.
+ */
+ if (!list_empty (&l->list)) {
+ __delete_inode_lock (l);
+ list_add_tail (&l->client_list,
+ &released);
+ } else {
+ list_del_init(&l->blocked_locks);
+ list_add_tail (&l->client_list,
+ &unwind);
+ }
}
pthread_mutex_unlock (&pl_inode->mutex);
}
}
pthread_mutex_unlock (&ctx->lock);
- list_for_each_entry_safe (l, tmp, &released, client_list) {
+ list_for_each_entry_safe (l, tmp, &unwind, client_list) {
list_del_init (&l->client_list);
- if (l->frame)
+ if (l->frame)
STACK_UNWIND_STRICT (inodelk, l->frame, -1, EAGAIN,
NULL);
+ list_add_tail (&l->client_list, &released);
+
+ }
+
+ list_for_each_entry_safe (l, tmp, &released, client_list) {
+ list_del_init (&l->client_list);
pl_inode = l->pl_inode;
diff --git a/xlators/features/locks/src/posix.c b/xlators/features/locks/src/posix.c
index 2db327687..337623d65 100644
--- a/xlators/features/locks/src/posix.c
+++ b/xlators/features/locks/src/posix.c
@@ -294,7 +294,7 @@ pl_locks_by_fd (pl_inode_t *pl_inode, fd_t *fd)
{
list_for_each_entry (l, &pl_inode->ext_list, list) {
- if ((l->fd_num == fd_to_fdnum(fd))) {
+ if (l->fd_num == fd_to_fdnum(fd)) {
found = 1;
break;
}
@@ -319,7 +319,7 @@ delete_locks_of_fd (xlator_t *this, pl_inode_t *pl_inode, fd_t *fd)
{
list_for_each_entry_safe (l, tmp, &pl_inode->ext_list, list) {
- if ((l->fd_num == fd_to_fdnum(fd))) {
+ if (l->fd_num == fd_to_fdnum(fd)) {
if (l->blocked) {
list_move_tail (&l->list, &blocked_list);
continue;
@@ -644,7 +644,8 @@ pl_fgetxattr_handle_lockinfo (xlator_t *this, fd_t *fd,
pl_inode_t *pl_inode = NULL;
char *key = NULL, *buf = NULL;
int32_t op_ret = 0;
- unsigned long fdnum = 0, len = 0;
+ unsigned long fdnum = 0;
+ int32_t len = 0;
dict_t *tmp = NULL;
pl_inode = pl_inode_get (this, fd->inode);
@@ -1340,7 +1341,7 @@ __fd_has_locks (pl_inode_t *pl_inode, fd_t *fd)
posix_lock_t *l = NULL;
list_for_each_entry (l, &pl_inode->ext_list, list) {
- if ((l->fd_num == fd_to_fdnum(fd))) {
+ if (l->fd_num == fd_to_fdnum(fd)) {
found = 1;
break;
}
@@ -1369,7 +1370,7 @@ __dup_locks_to_fdctx (pl_inode_t *pl_inode, fd_t *fd,
int ret = 0;
list_for_each_entry (l, &pl_inode->ext_list, list) {
- if ((l->fd_num == fd_to_fdnum(fd))) {
+ if (l->fd_num == fd_to_fdnum(fd)) {
duplock = lock_dup (l);
if (!duplock) {
ret = -1;