diff options
Diffstat (limited to 'xlators/features/locks/src/inodelk.c')
-rw-r--r-- | xlators/features/locks/src/inodelk.c | 444 |
1 files changed, 222 insertions, 222 deletions
diff --git a/xlators/features/locks/src/inodelk.c b/xlators/features/locks/src/inodelk.c index bbbd03398fe..851eeb08839 100644 --- a/xlators/features/locks/src/inodelk.c +++ b/xlators/features/locks/src/inodelk.c @@ -36,23 +36,23 @@ void __delete_inode_lock (pl_inode_lock_t *lock) { - list_del (&lock->list); + list_del (&lock->list); } void __destroy_inode_lock (pl_inode_lock_t *lock) { - GF_FREE (lock); + GF_FREE (lock); } /* Check if 2 inodelks are conflicting on type. Only 2 shared locks don't conflict */ static int inodelk_type_conflict (pl_inode_lock_t *l1, pl_inode_lock_t *l2) { - if (l2->fl_type == F_WRLCK || l1->fl_type == F_WRLCK) - return 1; + if (l2->fl_type == F_WRLCK || l1->fl_type == F_WRLCK) + return 1; - return 0; + return 0; } void @@ -115,14 +115,14 @@ pl_print_inodelk (char *str, int size, int cmd, struct gf_flock *flock, const ch static int inodelk_overlap (pl_inode_lock_t *l1, pl_inode_lock_t *l2) { - return ((l1->fl_end >= l2->fl_start) && - (l2->fl_end >= l1->fl_start)); + return ((l1->fl_end >= l2->fl_start) && + (l2->fl_end >= l1->fl_start)); } /* Returns true if the 2 inodelks have the same owner */ static int same_inodelk_owner (pl_inode_lock_t *l1, pl_inode_lock_t *l2) { - return ((l1->owner == l2->owner) && + return ((l1->owner == l2->owner) && (l1->transport == l2->transport)); } @@ -138,18 +138,18 @@ inodelk_conflict (pl_inode_lock_t *l1, pl_inode_lock_t *l2) static pl_inode_lock_t * __inodelk_grantable (pl_dom_list_t *dom, pl_inode_lock_t *lock) { - pl_inode_lock_t *l = NULL; - pl_inode_lock_t *ret = NULL; - if (list_empty (&dom->inodelk_list)) - goto out; - list_for_each_entry (l, &dom->inodelk_list, list){ - if (inodelk_conflict (lock, l)) { - ret = l; - goto out; - } - } + pl_inode_lock_t *l = NULL; + pl_inode_lock_t *ret = NULL; + if (list_empty (&dom->inodelk_list)) + goto out; + list_for_each_entry (l, &dom->inodelk_list, list){ + if (inodelk_conflict (lock, l)) { + ret = l; + goto out; + } + } out: - return ret; + return ret; } static pl_inode_lock_t * @@ -158,18 +158,18 @@ __blocked_lock_conflict (pl_dom_list_t *dom, pl_inode_lock_t *lock) pl_inode_lock_t *l = NULL; pl_inode_lock_t *ret = NULL; - if (list_empty (&dom->blocked_entrylks)) - return NULL; + if (list_empty (&dom->blocked_entrylks)) + return NULL; - list_for_each_entry (l, &dom->blocked_inodelks, blocked_locks) { - if (inodelk_conflict (lock, l)) { - ret = l; - goto out; + list_for_each_entry (l, &dom->blocked_inodelks, blocked_locks) { + if (inodelk_conflict (lock, l)) { + ret = l; + goto out; } - } + } out: - return ret; + return ret; } static int @@ -177,17 +177,17 @@ __owner_has_lock (pl_dom_list_t *dom, pl_inode_lock_t *newlock) { pl_inode_lock_t *lock = NULL; - list_for_each_entry (lock, &dom->entrylk_list, list) { - if (same_inodelk_owner (lock, newlock)) - return 1; - } + list_for_each_entry (lock, &dom->entrylk_list, list) { + if (same_inodelk_owner (lock, newlock)) + return 1; + } - list_for_each_entry (lock, &dom->blocked_entrylks, blocked_locks) { - if (same_inodelk_owner (lock, newlock)) - return 1; - } + list_for_each_entry (lock, &dom->blocked_entrylks, blocked_locks) { + if (same_inodelk_owner (lock, newlock)) + return 1; + } - return 0; + return 0; } @@ -196,18 +196,18 @@ __owner_has_lock (pl_dom_list_t *dom, pl_inode_lock_t *newlock) */ static int __lock_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock, - int can_block, pl_dom_list_t *dom) + int can_block, pl_dom_list_t *dom) { - pl_inode_lock_t *conf = NULL; - int ret = -EINVAL; + pl_inode_lock_t *conf = NULL; + int ret = -EINVAL; - conf = __inodelk_grantable (dom, lock); - if (conf){ - ret = -EAGAIN; - if (can_block == 0) - goto out; + conf = __inodelk_grantable (dom, lock); + if (conf){ + ret = -EAGAIN; + if (can_block == 0) + goto out; - list_add_tail (&lock->blocked_locks, &dom->blocked_inodelks); + list_add_tail (&lock->blocked_locks, &dom->blocked_inodelks); gf_log (this->name, GF_LOG_TRACE, "%s (pid=%d) lk-owner:%"PRIu64" %"PRId64" - %"PRId64" => Blocked", @@ -218,8 +218,8 @@ __lock_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock, lock->user_flock.l_len); - goto out; - } + goto out; + } if (__blocked_lock_conflict (dom, lock) && !(__owner_has_lock (dom, lock))) { ret = -EAGAIN; @@ -230,7 +230,7 @@ __lock_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock, gf_log (this->name, GF_LOG_TRACE, "Lock is grantable, but blocking to prevent starvation"); - gf_log (this->name, GF_LOG_TRACE, + gf_log (this->name, GF_LOG_TRACE, "%s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" => Blocked", lock->fl_type == F_UNLCK ? "Unlock" : "Lock", lock->client_pid, @@ -239,38 +239,38 @@ __lock_inodelk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock, lock->user_flock.l_len); - goto out; + goto out; } - list_add (&lock->list, &dom->inodelk_list); + list_add (&lock->list, &dom->inodelk_list); - ret = 0; + ret = 0; out: - return ret; + return ret; } /* Return true if the two inodelks have exactly same lock boundaries */ static int inodelks_equal (pl_inode_lock_t *l1, pl_inode_lock_t *l2) { - if ((l1->fl_start == l2->fl_start) && - (l1->fl_end == l2->fl_end)) - return 1; + if ((l1->fl_start == l2->fl_start) && + (l1->fl_end == l2->fl_end)) + return 1; - return 0; + return 0; } static pl_inode_lock_t * find_matching_inodelk (pl_inode_lock_t *lock, pl_dom_list_t *dom) { - pl_inode_lock_t *l = NULL; - list_for_each_entry (l, &dom->inodelk_list, list) { - if (inodelks_equal (l, lock) && + pl_inode_lock_t *l = NULL; + list_for_each_entry (l, &dom->inodelk_list, list) { + if (inodelks_equal (l, lock) && same_inodelk_owner (l, lock)) - return l; - } - return NULL; + return l; + } + return NULL; } /* Set F_UNLCK removes a lock which has the exact same lock boundaries @@ -280,60 +280,60 @@ static pl_inode_lock_t * __inode_unlock_lock (xlator_t *this, pl_inode_lock_t *lock, pl_dom_list_t *dom) { - pl_inode_lock_t *conf = NULL; + pl_inode_lock_t *conf = NULL; - conf = find_matching_inodelk (lock, dom); - if (!conf) { + conf = find_matching_inodelk (lock, dom); + if (!conf) { gf_log (this->name, GF_LOG_DEBUG, " Matching lock not found for unlock"); - goto out; + goto out; } - __delete_inode_lock (conf); + __delete_inode_lock (conf); gf_log (this->name, GF_LOG_DEBUG, " Matching lock found for unlock"); __destroy_inode_lock (lock); out: - return conf; + return conf; } static void -__grant_blocked_inode_locks (xlator_t *this, pl_inode_t *pl_inode, - struct list_head *granted, pl_dom_list_t *dom) +__grant_blocked_inode_locks (xlator_t *this, pl_inode_t *pl_inode, + struct list_head *granted, pl_dom_list_t *dom) { - int bl_ret = 0; - pl_inode_lock_t *bl = NULL; - pl_inode_lock_t *tmp = NULL; + int bl_ret = 0; + pl_inode_lock_t *bl = NULL; + pl_inode_lock_t *tmp = NULL; struct list_head blocked_list; INIT_LIST_HEAD (&blocked_list); list_splice_init (&dom->blocked_inodelks, &blocked_list); - list_for_each_entry_safe (bl, tmp, &blocked_list, blocked_locks) { + list_for_each_entry_safe (bl, tmp, &blocked_list, blocked_locks) { - list_del_init (&bl->blocked_locks); + list_del_init (&bl->blocked_locks); - bl_ret = __lock_inodelk (this, pl_inode, bl, 1, dom); + bl_ret = __lock_inodelk (this, pl_inode, bl, 1, dom); - if (bl_ret == 0) { - list_add (&bl->blocked_locks, granted); + if (bl_ret == 0) { + list_add (&bl->blocked_locks, granted); } } - return; + return; } /* Grant all inodelks blocked on a lock */ void grant_blocked_inode_locks (xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t *dom) { - struct list_head granted; - pl_inode_lock_t *lock; - pl_inode_lock_t *tmp; + struct list_head granted; + pl_inode_lock_t *lock; + pl_inode_lock_t *tmp; - INIT_LIST_HEAD (&granted); + INIT_LIST_HEAD (&granted); if (list_empty (&dom->blocked_inodelks)) { gf_log (this->name, GF_LOG_TRACE, @@ -341,25 +341,25 @@ grant_blocked_inode_locks (xlator_t *this, pl_inode_t *pl_inode, pl_dom_list_t * } pthread_mutex_lock (&pl_inode->mutex); - { - __grant_blocked_inode_locks (this, pl_inode, &granted, dom); - } + { + __grant_blocked_inode_locks (this, pl_inode, &granted, dom); + } pthread_mutex_unlock (&pl_inode->mutex); - list_for_each_entry_safe (lock, tmp, &granted, blocked_locks) { + list_for_each_entry_safe (lock, tmp, &granted, blocked_locks) { gf_log (this->name, GF_LOG_TRACE, - "%s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" => Granted", - lock->fl_type == F_UNLCK ? "Unlock" : "Lock", - lock->client_pid, - lock->owner, - lock->user_flock.l_start, - lock->user_flock.l_len); + "%s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" => Granted", + lock->fl_type == F_UNLCK ? "Unlock" : "Lock", + lock->client_pid, + lock->owner, + lock->user_flock.l_start, + lock->user_flock.l_len); - pl_trace_out (this, lock->frame, NULL, NULL, F_SETLKW, - &lock->user_flock, 0, 0, lock->volume); + pl_trace_out (this, lock->frame, NULL, NULL, F_SETLKW, + &lock->user_flock, 0, 0, lock->volume); - STACK_UNWIND_STRICT (inodelk, lock->frame, 0, 0); - } + STACK_UNWIND_STRICT (inodelk, lock->frame, 0, 0); + } } @@ -368,8 +368,8 @@ static int release_inode_locks_of_transport (xlator_t *this, pl_dom_list_t *dom, inode_t *inode, void *trans) { - pl_inode_lock_t *tmp = NULL; - pl_inode_lock_t *l = NULL; + pl_inode_lock_t *tmp = NULL; + pl_inode_lock_t *l = NULL; pl_inode_t * pinode = NULL; @@ -414,7 +414,7 @@ release_inode_locks_of_transport (xlator_t *this, pl_dom_list_t *dom, continue; __delete_inode_lock (l); - __destroy_inode_lock (l); + __destroy_inode_lock (l); if (inode_path (inode, NULL, &path) < 0) { @@ -446,24 +446,24 @@ unlock: GF_FREE (l); } - grant_blocked_inode_locks (this, pinode, dom); - return 0; + grant_blocked_inode_locks (this, pinode, dom); + return 0; } static int pl_inode_setlk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock, - int can_block, pl_dom_list_t *dom) + int can_block, pl_dom_list_t *dom) { - int ret = -EINVAL; + int ret = -EINVAL; pl_inode_lock_t *retlock = NULL; - pthread_mutex_lock (&pl_inode->mutex); - { - if (lock->fl_type != F_UNLCK) { - ret = __lock_inodelk (this, pl_inode, lock, can_block, dom); - if (ret == 0) - gf_log (this->name, GF_LOG_TRACE, + pthread_mutex_lock (&pl_inode->mutex); + { + if (lock->fl_type != F_UNLCK) { + ret = __lock_inodelk (this, pl_inode, lock, can_block, dom); + if (ret == 0) + gf_log (this->name, GF_LOG_TRACE, "%s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" => OK", lock->fl_type == F_UNLCK ? "Unlock" : "Lock", lock->client_pid, @@ -471,35 +471,35 @@ pl_inode_setlk (xlator_t *this, pl_inode_t *pl_inode, pl_inode_lock_t *lock, lock->fl_start, lock->fl_end); - if (ret == -EAGAIN) - gf_log (this->name, GF_LOG_TRACE, + if (ret == -EAGAIN) + gf_log (this->name, GF_LOG_TRACE, "%s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" => NOK", - lock->fl_type == F_UNLCK ? "Unlock" : "Lock", - lock->client_pid, + lock->fl_type == F_UNLCK ? "Unlock" : "Lock", + lock->client_pid, lock->owner, - lock->user_flock.l_start, - lock->user_flock.l_len); + lock->user_flock.l_start, + lock->user_flock.l_len); - goto out; - } + goto out; + } - retlock = __inode_unlock_lock (this, lock, dom); - if (!retlock) { - gf_log (this->name, GF_LOG_DEBUG, - "Bad Unlock issued on Inode lock"); + retlock = __inode_unlock_lock (this, lock, dom); + if (!retlock) { + gf_log (this->name, GF_LOG_DEBUG, + "Bad Unlock issued on Inode lock"); ret = -EINVAL; goto out; } - __destroy_inode_lock (retlock); + __destroy_inode_lock (retlock); ret = 0; - } + } out: - pthread_mutex_unlock (&pl_inode->mutex); - grant_blocked_inode_locks (this, pl_inode, dom); + pthread_mutex_unlock (&pl_inode->mutex); + grant_blocked_inode_locks (this, pl_inode, dom); return ret; } @@ -509,31 +509,31 @@ new_inode_lock (struct gf_flock *flock, void *transport, pid_t client_pid, uint64_t owner, const char *volume) { - pl_inode_lock_t *lock = NULL; + pl_inode_lock_t *lock = NULL; - lock = GF_CALLOC (1, sizeof (*lock), + lock = GF_CALLOC (1, sizeof (*lock), gf_locks_mt_pl_inode_lock_t); - if (!lock) { - return NULL; - } + if (!lock) { + return NULL; + } - lock->fl_start = flock->l_start; - lock->fl_type = flock->l_type; + lock->fl_start = flock->l_start; + lock->fl_type = flock->l_type; - if (flock->l_len == 0) - lock->fl_end = LLONG_MAX; - else - lock->fl_end = flock->l_start + flock->l_len - 1; + if (flock->l_len == 0) + lock->fl_end = LLONG_MAX; + else + lock->fl_end = flock->l_start + flock->l_len - 1; - lock->transport = transport; - lock->client_pid = client_pid; + lock->transport = transport; + lock->client_pid = client_pid; lock->owner = owner; - lock->volume = volume; + lock->volume = volume; - INIT_LIST_HEAD (&lock->list); - INIT_LIST_HEAD (&lock->blocked_locks); + INIT_LIST_HEAD (&lock->list); + INIT_LIST_HEAD (&lock->blocked_locks); - return lock; + return lock; } /* Common inodelk code called from pl_inodelk and pl_finodelk */ @@ -542,96 +542,96 @@ pl_common_inodelk (call_frame_t *frame, xlator_t *this, const char *volume, inode_t *inode, int32_t cmd, struct gf_flock *flock, loc_t *loc, fd_t *fd) { - int32_t op_ret = -1; - int32_t op_errno = 0; - int ret = -1; - int can_block = 0; - void * transport = NULL; - pid_t client_pid = -1; + int32_t op_ret = -1; + int32_t op_errno = 0; + int ret = -1; + int can_block = 0; + void * transport = NULL; + pid_t client_pid = -1; uint64_t owner = -1; - pl_inode_t * pinode = NULL; - pl_inode_lock_t * reqlock = NULL; - pl_dom_list_t * dom = NULL; + pl_inode_t * pinode = NULL; + pl_inode_lock_t * reqlock = NULL; + pl_dom_list_t * dom = NULL; - VALIDATE_OR_GOTO (frame, out); - VALIDATE_OR_GOTO (inode, unwind); - VALIDATE_OR_GOTO (flock, unwind); + VALIDATE_OR_GOTO (frame, out); + VALIDATE_OR_GOTO (inode, unwind); + VALIDATE_OR_GOTO (flock, unwind); - if ((flock->l_start < 0) || (flock->l_len < 0)) { - op_errno = EINVAL; - goto unwind; - } + if ((flock->l_start < 0) || (flock->l_len < 0)) { + op_errno = EINVAL; + goto unwind; + } pl_trace_in (this, frame, fd, loc, cmd, flock, volume); - transport = frame->root->trans; - client_pid = frame->root->pid; + transport = frame->root->trans; + client_pid = frame->root->pid; owner = frame->root->lk_owner; - pinode = pl_inode_get (this, inode); - if (!pinode) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory."); - op_errno = ENOMEM; - goto unwind; - } + pinode = pl_inode_get (this, inode); + if (!pinode) { + gf_log (this->name, GF_LOG_ERROR, + "Out of memory."); + op_errno = ENOMEM; + goto unwind; + } - dom = get_domain (pinode, volume); + dom = get_domain (pinode, volume); - if (owner == 0) { - /* + if (owner == 0) { + /* special case: this means release all locks from this transport - */ - gf_log (this->name, GF_LOG_TRACE, - "Releasing all locks from transport %p", transport); + */ + gf_log (this->name, GF_LOG_TRACE, + "Releasing all locks from transport %p", transport); - release_inode_locks_of_transport (this, dom, inode, transport); - goto unwind; - } + release_inode_locks_of_transport (this, dom, inode, transport); + goto unwind; + } - reqlock = new_inode_lock (flock, transport, client_pid, owner, volume); + reqlock = new_inode_lock (flock, transport, client_pid, owner, volume); - if (!reqlock) { - gf_log (this->name, GF_LOG_ERROR, - "Out of memory."); - op_ret = -1; - op_errno = ENOMEM; - goto unwind; - } + if (!reqlock) { + gf_log (this->name, GF_LOG_ERROR, + "Out of memory."); + op_ret = -1; + op_errno = ENOMEM; + goto unwind; + } reqlock->frame = frame; reqlock->this = this; - switch (cmd) { - case F_SETLKW: - can_block = 1; - reqlock->frame = frame; - reqlock->this = this; + switch (cmd) { + case F_SETLKW: + can_block = 1; + reqlock->frame = frame; + reqlock->this = this; - /* fall through */ + /* fall through */ - case F_SETLK: - memcpy (&reqlock->user_flock, flock, sizeof (struct gf_flock)); - ret = pl_inode_setlk (this, pinode, reqlock, + case F_SETLK: + memcpy (&reqlock->user_flock, flock, sizeof (struct gf_flock)); + ret = pl_inode_setlk (this, pinode, reqlock, can_block, dom); - if (ret < 0) { + if (ret < 0) { if (can_block) { pl_trace_block (this, frame, fd, loc, cmd, flock, volume); - goto out; + goto out; } - gf_log (this->name, GF_LOG_TRACE, "returning EAGAIN"); - op_errno = -ret; - __destroy_inode_lock (reqlock); - goto unwind; - } - break; - - default: - op_errno = ENOTSUP; - gf_log (this->name, GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_TRACE, "returning EAGAIN"); + op_errno = -ret; + __destroy_inode_lock (reqlock); + goto unwind; + } + break; + + default: + op_errno = ENOTSUP; + gf_log (this->name, GF_LOG_DEBUG, "Lock command F_GETLK not supported for [f]inodelk " "(cmd=%d)", cmd); @@ -641,10 +641,10 @@ pl_common_inodelk (call_frame_t *frame, xlator_t *this, op_ret = 0; unwind: - if ((inode != NULL) && (flock !=NULL)) { - pl_update_refkeeper (this, inode); - pl_trace_out (this, frame, fd, loc, cmd, flock, op_ret, op_errno, volume); - } + if ((inode != NULL) && (flock !=NULL)) { + pl_update_refkeeper (this, inode); + pl_trace_out (this, frame, fd, loc, cmd, flock, op_ret, op_errno, volume); + } STACK_UNWIND_STRICT (inodelk, frame, op_ret, op_errno); out: @@ -683,32 +683,32 @@ __get_inodelk_count (xlator_t *this, pl_inode_t *pl_inode) list_for_each_entry (dom, &pl_inode->dom_list, inode_list) { list_for_each_entry (lock, &dom->inodelk_list, list) { - gf_log (this->name, GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_DEBUG, " XATTR DEBUG" - " domain: %s %s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" " + " domain: %s %s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" " "state = Active", dom->domain, - lock->fl_type == F_UNLCK ? "Unlock" : "Lock", - lock->client_pid, + lock->fl_type == F_UNLCK ? "Unlock" : "Lock", + lock->client_pid, lock->owner, - lock->user_flock.l_start, - lock->user_flock.l_len); + lock->user_flock.l_start, + lock->user_flock.l_len); count++; } list_for_each_entry (lock, &dom->blocked_inodelks, blocked_locks) { - gf_log (this->name, GF_LOG_DEBUG, + gf_log (this->name, GF_LOG_DEBUG, " XATTR DEBUG" - " domain: %s %s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" " + " domain: %s %s (pid=%d) (lk-owner=%"PRIu64") %"PRId64" - %"PRId64" " "state = Blocked", dom->domain, - lock->fl_type == F_UNLCK ? "Unlock" : "Lock", - lock->client_pid, + lock->fl_type == F_UNLCK ? "Unlock" : "Lock", + lock->client_pid, lock->owner, - lock->user_flock.l_start, - lock->user_flock.l_len); + lock->user_flock.l_start, + lock->user_flock.l_len); count++; } |