Whamcloud - gitweb
LU-2177 ldlm: flock completion fixes.
[fs/lustre-release.git] / lustre / ldlm / ldlm_lock.c
index 33ada0a..e43f5c1 100644 (file)
@@ -1148,6 +1148,21 @@ void ldlm_grant_lock(struct ldlm_lock *lock, cfs_list_t *work_list)
         check_res_locked(res);
 
         lock->l_granted_mode = lock->l_req_mode;
+
+       if (work_list && lock->l_completion_ast != NULL)
+               ldlm_add_ast_work_item(lock, NULL, work_list);
+
+       /* We should not add locks to granted list in the following cases:
+        * - this is an UNLOCK but not a real lock;
+        * - this is a TEST lock;
+        * - this is a F_CANCELLK lock (async flock has req_mode == 0)
+        * - this is a deadlock (flock cannot be granted) */
+       if (lock->l_req_mode == 0 ||
+           lock->l_req_mode == LCK_NL ||
+           ldlm_is_test_lock(lock) ||
+           ldlm_is_flock_deadlock(lock))
+               RETURN_EXIT;
+
         if (res->lr_type == LDLM_PLAIN || res->lr_type == LDLM_IBITS)
                 ldlm_grant_lock_with_skiplist(lock);
         else if (res->lr_type == LDLM_EXTENT)
@@ -1158,9 +1173,6 @@ void ldlm_grant_lock(struct ldlm_lock *lock, cfs_list_t *work_list)
         if (lock->l_granted_mode < res->lr_most_restr)
                 res->lr_most_restr = lock->l_granted_mode;
 
-        if (work_list && lock->l_completion_ast != NULL)
-                ldlm_add_ast_work_item(lock, NULL, work_list);
-
         ldlm_pool_add(&ldlm_res_to_ns(res)->ns_pool, lock);
         EXIT;
 }
@@ -1722,6 +1734,8 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
         * lock's l_flags. */
        if (*flags & LDLM_FL_AST_DISCARD_DATA)
                ldlm_set_ast_discard_data(lock);
+       if (*flags & LDLM_FL_TEST_LOCK)
+               ldlm_set_test_lock(lock);
 
        /* This distinction between local lock trees is very important; a client
         * namespace only has information about locks taken by that client, and