#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.
+ */
+static bool ldlm_should_run_bl_ast(const struct ldlm_lock *lock,
+ const struct ldlm_lock *req)
+{
+ /* no blocking ast */
+ if (!lock->l_blocking_ast)
+ return false;
+
+ /* not local lock */
+ if (!ldlm_is_local(lock))
+ return true;
+
+ /* should trigger Commit-on-Sharing */
+ if ((lock->l_req_mode & LCK_COS))
+ return true;
+
+ /* local read lock will be canceld after use */
+ if (!(lock->l_req_mode & (LCK_PW | LCK_EX)))
+ return false;
+
+ /* 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;
+
+ /* check if @req is COS incompatible */
+ if (ldlm_is_cos_incompat(req))
+ return true;
+
+ return false;
+}
+
/**
* Determine if the lock is compatible with all locks on the queue.
*
/* Add locks of the policy group to @work_list
* as blocking locks for @req */
- if (lock->l_blocking_ast)
+ if (ldlm_should_run_bl_ast(lock, req))
ldlm_add_ast_work_item(lock, req,
work_list);
head = &lock->l_sl_policy;
list_for_each_entry(lock, head, l_sl_policy)
- if (lock->l_blocking_ast)
+ if (ldlm_should_run_bl_ast(lock, req))
ldlm_add_ast_work_item(lock,
req, work_list);
}
/* Just return if there are no conflicting bits */
if ((lock->l_policy_data.l_inodebits.bits & to_drop) == 0) {
- LDLM_WARN(lock, "try to drop unset bits %#llx/%#llx\n",
+ LDLM_WARN(lock, "try to drop unset bits %#llx/%#llx",
lock->l_policy_data.l_inodebits.bits, to_drop);
/* nothing to do */
RETURN(0);
ldlm_lock2handle(lock, &lockh);
lock_res_and_lock(lock);
- /* check if all bits are cancelled */
+ /* check if all bits are blocked */
if (!(lock->l_policy_data.l_inodebits.bits & ~drop_bits)) {
unlock_res_and_lock(lock);
/* return error to continue with cancel */
GOTO(exit, rc = -EINVAL);
}
+ /* check if no common bits, consider this as successful convert */
+ if (!(lock->l_policy_data.l_inodebits.bits & drop_bits)) {
+ unlock_res_and_lock(lock);
+ GOTO(exit, rc = 0);
+ }
+
/* check if there is race with cancel */
if (ldlm_is_canceling(lock) || ldlm_is_cancel(lock)) {
unlock_res_and_lock(lock);
rc = ldlm_cli_convert(lock, &flags);
if (rc) {
lock_res_and_lock(lock);
- ldlm_clear_converting(lock);
- ldlm_set_cbpending(lock);
- ldlm_set_bl_ast(lock);
+ if (ldlm_is_converting(lock)) {
+ ldlm_clear_converting(lock);
+ ldlm_set_cbpending(lock);
+ ldlm_set_bl_ast(lock);
+ }
unlock_res_and_lock(lock);
- LASSERT(list_empty(&lock->l_lru));
GOTO(exit, rc);
}
EXIT;