diff options
Diffstat (limited to 'xlators/features/locks/src/common.c')
-rw-r--r-- | xlators/features/locks/src/common.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/xlators/features/locks/src/common.c b/xlators/features/locks/src/common.c index facb078612f..d56a7aca2be 100644 --- a/xlators/features/locks/src/common.c +++ b/xlators/features/locks/src/common.c @@ -432,6 +432,8 @@ pl_inode_get (xlator_t *this, inode_t *inode) INIT_LIST_HEAD (&pl_inode->reservelk_list); INIT_LIST_HEAD (&pl_inode->blocked_reservelks); INIT_LIST_HEAD (&pl_inode->blocked_calls); + INIT_LIST_HEAD (&pl_inode->metalk_list); + INIT_LIST_HEAD (&pl_inode->queued_locks); gf_uuid_copy (pl_inode->gfid, inode->gfid); __inode_ctx_put (inode, this, (uint64_t)(long)(pl_inode)); @@ -446,7 +448,7 @@ unlock: /* Create a new posix_lock_t */ posix_lock_t * new_posix_lock (struct gf_flock *flock, client_t *client, pid_t client_pid, - gf_lkowner_t *owner, fd_t *fd, uint32_t lk_flags) + gf_lkowner_t *owner, fd_t *fd, uint32_t lk_flags, int blocking) { posix_lock_t *lock = NULL; @@ -482,6 +484,8 @@ new_posix_lock (struct gf_flock *flock, client_t *client, pid_t client_pid, lock->owner = *owner; lock->lk_flags = lk_flags; + lock->blocking = blocking; + INIT_LIST_HEAD (&lock->list); out: @@ -992,7 +996,7 @@ pl_send_prelock_unlock (xlator_t *this, pl_inode_t *pl_inode, unlock_lock = new_posix_lock (&flock, old_lock->client, old_lock->client_pid, &old_lock->owner, - old_lock->fd, old_lock->lk_flags); + old_lock->fd, old_lock->lk_flags, 0); GF_VALIDATE_OR_GOTO (this->name, unlock_lock, out); ret = 0; @@ -1044,6 +1048,12 @@ pl_setlk (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock, } if (__is_lock_grantable (pl_inode, lock)) { + if (pl_metalock_is_active (pl_inode)) { + __pl_queue_lock (pl_inode, lock, can_block); + pthread_mutex_unlock (&pl_inode->mutex); + ret = -2; + goto out; + } gf_log (this->name, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"PRId64" - %"PRId64" => OK", lock->fl_type == F_UNLCK ? "Unlock" : "Lock", @@ -1053,6 +1063,12 @@ pl_setlk (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock, lock->user_flock.l_len); __insert_and_merge (pl_inode, lock); } else if (can_block) { + if (pl_metalock_is_active (pl_inode)) { + __pl_queue_lock (pl_inode, lock, can_block); + pthread_mutex_unlock (&pl_inode->mutex); + ret = -2; + goto out; + } gf_log (this->name, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%s %"PRId64" - %"PRId64" => Blocked", lock->fl_type == F_UNLCK ? "Unlock" : "Lock", @@ -1081,6 +1097,7 @@ pl_setlk (xlator_t *this, pl_inode_t *pl_inode, posix_lock_t *lock, do_blocked_rw (pl_inode); +out: return ret; } @@ -1099,4 +1116,3 @@ pl_getlk (pl_inode_t *pl_inode, posix_lock_t *lock) return conf; } - |