ldlm_inodebits_compat_queue(struct list_head *queue, struct ldlm_lock *req,
struct list_head *work_list)
{
- struct list_head *tmp, *tmp_tail;
+ struct list_head *tmp;
struct ldlm_lock *lock;
ldlm_mode_t req_mode = req->l_req_mode;
__u64 req_bits = req->l_policy_data.l_inodebits.bits;
LASSERT(req_bits); /* There is no sense in lock with no bits set,
I think. Also such a lock would be compatible
with any other bit lock */
+
list_for_each(tmp, queue) {
+ struct list_head *mode_tail;
+
lock = list_entry(tmp, struct ldlm_lock, l_res_link);
if (req == lock)
RETURN(compat);
+ /* last lock in mode group */
+ LASSERT(lock->l_sl_mode.prev != NULL);
+ mode_tail = &list_entry(lock->l_sl_mode.prev,
+ struct ldlm_lock,
+ l_sl_mode)->l_res_link;
+
/* locks are compatible, bits don't matter */
if (lockmode_compat(lock->l_req_mode, req_mode)) {
- /* jump to next mode group */
- if (LDLM_SL_HEAD(&lock->l_sl_mode))
- tmp = &list_entry(lock->l_sl_mode.next,
- struct ldlm_lock,
- l_sl_mode)->l_res_link;
+ /* jump to last lock in mode group */
+ tmp = mode_tail;
continue;
}
- tmp_tail = tmp;
- if (LDLM_SL_HEAD(&lock->l_sl_mode))
- tmp_tail = &list_entry(lock->l_sl_mode.next,
- struct ldlm_lock,
- l_sl_mode)->l_res_link;
for (;;) {
+ struct list_head *head;
+
+ /* last lock in policy group */
+ tmp = &list_entry(lock->l_sl_policy.prev,
+ struct ldlm_lock,
+ l_sl_policy)->l_res_link;
+
/* locks with bits overlapped are conflicting locks */
if (lock->l_policy_data.l_inodebits.bits & req_bits) {
/* conflicting policy */
RETURN(0);
compat = 0;
+
+ /* add locks of the policy group to
+ * @work_list as blocking locks for
+ * @req */
if (lock->l_blocking_ast)
- ldlm_add_ast_work_item(lock, req,
+ ldlm_add_ast_work_item(lock, req,
work_list);
- /* add all members of the policy group */
- if (LDLM_SL_HEAD(&lock->l_sl_policy)) {
- do {
- tmp = lock->l_res_link.next;
- lock = list_entry(tmp,
- struct ldlm_lock,
- l_res_link);
- if (lock->l_blocking_ast)
- ldlm_add_ast_work_item(
- lock,
- req,
- work_list);
- } while (!LDLM_SL_TAIL(&lock->l_sl_policy));
- }
- } else if (LDLM_SL_HEAD(&lock->l_sl_policy)) {
- /* jump to next policy group */
- tmp = &list_entry(lock->l_sl_policy.next,
- struct ldlm_lock,
- l_sl_policy)->l_res_link;
+ head = &lock->l_sl_policy;
+ list_for_each_entry(lock, head, l_sl_policy)
+ if (lock->l_blocking_ast)
+ ldlm_add_ast_work_item(lock, req,
+ work_list);
}
- if (tmp == tmp_tail)
+ if (tmp == mode_tail)
break;
- else
- tmp = tmp->next;
+
+ tmp = tmp->next;
lock = list_entry(tmp, struct ldlm_lock, l_res_link);
- } /* for locks in a mode group */
- } /* for each lock in the queue */
+ } /* loop over policy groups within one mode group */
+ } /* loop over mode groups within @queue */
RETURN(compat);
}