#include "ldlm_internal.h"
#ifdef HAVE_SERVER_SUPPORT
-/*
- * local lock will be canceled after use, and it should run blocking ast only
- * when it should trigger Commit-on-Sharing, otherwise if the blocking ast
- * is run and does nothing, it will prevent subsequent operations to trigger
- * Commit-on-Sharing, see LU-11102.
+
+/**
+ * It should iterate through all waiting locks on a given resource queue and
+ * attempt to grant them. An optimization is to check only heads waitintg
+ * locks for each inodebit type.
+ *
+ * Must be called with resource lock held.
*/
-static bool ldlm_should_run_bl_ast(const struct ldlm_lock *lock,
- const struct ldlm_lock *req)
+int ldlm_reprocess_inodebits_queue(struct ldlm_resource *res,
+ struct list_head *queue,
+ struct list_head *work_list,
+ enum ldlm_process_intention intention,
+ struct ldlm_lock *hint)
{
- /* no blocking ast */
- if (!lock->l_blocking_ast)
- return false;
+ __u64 flags;
+ int rc = LDLM_ITER_CONTINUE;
+ enum ldlm_error err;
+ struct list_head bl_ast_list = LIST_HEAD_INIT(bl_ast_list);
+ struct ldlm_ibits_queues *queues = res->lr_ibits_queues;
+ int i;
+
+ ENTRY;
+
+ check_res_locked(res);
+
+ LASSERT(res->lr_type == LDLM_IBITS);
+ LASSERT(intention == LDLM_PROCESS_RESCAN ||
+ intention == LDLM_PROCESS_RECOVERY);
+
+ if (intention == LDLM_PROCESS_RECOVERY)
+ return ldlm_reprocess_queue(res, queue, work_list, intention,
+ NULL);
- /* not local lock */
- if (!ldlm_is_local(lock))
- return true;
+restart:
+ CDEBUG(D_DLMTRACE, "--- Reprocess resource "DLDLMRES" (%p)\n",
+ PLDLMRES(res), res);
- /* should trigger Commit-on-Sharing */
- if ((lock->l_req_mode & LCK_COS))
- return true;
+ for (i = 0; i < MDS_INODELOCK_NUMBITS; i++) {
+ struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
+ struct list_head *head = &queues->liq_waiting[i];
+ struct ldlm_lock *pending;
+ struct ldlm_ibits_node *node;
- /* local read lock will be canceld after use */
- if (!(lock->l_req_mode & (LCK_PW | LCK_EX)))
- return false;
+ if (list_empty(head))
+ continue;
+ if (hint && !(hint->l_policy_data.l_inodebits.bits & (1 << i)))
+ continue;
+
+ node = list_entry(head->next, struct ldlm_ibits_node,
+ lin_link[i]);
+
+ pending = node->lock;
+ LDLM_DEBUG(pending, "Reprocessing lock from queue %d", i);
+
+ flags = 0;
+ rc = ldlm_process_inodebits_lock(pending, &flags, intention,
+ &err, &rpc_list);
+ if (ldlm_is_granted(pending)) {
+ list_splice(&rpc_list, work_list);
+ /* Try to grant more locks from current queue */
+ i--;
+ } else {
+ list_splice(&rpc_list, &bl_ast_list);
+ }
+ }
- /* if CoS enabled, check if @req is from different client */
- if (ldlm_is_cos_enabled(req))
- return lock->l_client_cookie != req->l_client_cookie;
+ if (!list_empty(&bl_ast_list)) {
+ unlock_res(res);
- /* check if @req is COS incompatible */
- if (ldlm_is_cos_incompat(req))
- return true;
+ rc = ldlm_run_ast_work(ldlm_res_to_ns(res), &bl_ast_list,
+ LDLM_WORK_BL_AST);
+
+ lock_res(res);
+ if (rc == -ERESTART)
+ GOTO(restart, rc);
+ }
- return false;
+ if (!list_empty(&bl_ast_list))
+ ldlm_discard_bl_list(&bl_ast_list);
+
+ RETURN(rc);
}
/**
/* Add locks of the policy group to @work_list
* as blocking locks for @req */
- if (ldlm_should_run_bl_ast(lock, req))
+ if (lock->l_blocking_ast)
ldlm_add_ast_work_item(lock, req,
work_list);
head = &lock->l_sl_policy;
list_for_each_entry(lock, head, l_sl_policy)
- if (ldlm_should_run_bl_ast(lock, req))
+ if (lock->l_blocking_ast)
ldlm_add_ast_work_item(lock,
req, work_list);
}
ENTRY;
- LASSERT(lock->l_granted_mode != lock->l_req_mode);
+ LASSERT(!ldlm_is_granted(lock));
check_res_locked(res);
if (intention == LDLM_PROCESS_RESCAN) {
LDLM_DEBUG(lock, "client lock convert END");
return rc;
}
+
+
+int ldlm_inodebits_alloc_lock(struct ldlm_lock *lock)
+{
+ if (ldlm_is_ns_srv(lock)) {
+ int i;
+
+ OBD_SLAB_ALLOC_PTR(lock->l_ibits_node, ldlm_inodebits_slab);
+ if (lock->l_ibits_node == NULL)
+ return -ENOMEM;
+ for (i = 0; i < MDS_INODELOCK_NUMBITS; i++)
+ INIT_LIST_HEAD(&lock->l_ibits_node->lin_link[i]);
+ lock->l_ibits_node->lock = lock;
+ } else {
+ lock->l_ibits_node = NULL;
+ }
+ return 0;
+}
+
+void ldlm_inodebits_add_lock(struct ldlm_resource *res, struct list_head *head,
+ struct ldlm_lock *lock)
+{
+ int i;
+
+ if (!ldlm_is_ns_srv(lock))
+ return;
+
+ if (head == &res->lr_waiting) {
+ for (i = 0; i < MDS_INODELOCK_NUMBITS; i++) {
+ if (lock->l_policy_data.l_inodebits.bits & (1 << i))
+ list_add_tail(&lock->l_ibits_node->lin_link[i],
+ &res->lr_ibits_queues->liq_waiting[i]);
+ }
+ } else if (head == &res->lr_granted && lock->l_ibits_node != NULL) {
+ for (i = 0; i < MDS_INODELOCK_NUMBITS; i++)
+ LASSERT(list_empty(&lock->l_ibits_node->lin_link[i]));
+ OBD_SLAB_FREE_PTR(lock->l_ibits_node, ldlm_inodebits_slab);
+ lock->l_ibits_node = NULL;
+ }
+}
+
+void ldlm_inodebits_unlink_lock(struct ldlm_lock *lock)
+{
+ int i;
+
+ ldlm_unlink_lock_skiplist(lock);
+ if (!ldlm_is_ns_srv(lock))
+ return;
+
+ for (i = 0; i < MDS_INODELOCK_NUMBITS; i++)
+ list_del_init(&lock->l_ibits_node->lin_link[i]);
+}