- struct ldlm_resource *res = lock->l_resource;
- CFS_LIST_HEAD(rpc_list);
- int rc;
- ENTRY;
-
- check_res_locked(res);
- LASSERT(cfs_list_empty(&res->lr_converting));
-
- if (!first_enq) {
- LASSERT(work_list != NULL);
- rc = ldlm_plain_compat_queue(&res->lr_granted, lock, NULL);
- if (!rc)
- RETURN(LDLM_ITER_STOP);
- rc = ldlm_plain_compat_queue(&res->lr_waiting, lock, NULL);
- if (!rc)
- RETURN(LDLM_ITER_STOP);
-
- ldlm_resource_unlink_lock(lock);
- ldlm_grant_lock(lock, work_list);
- RETURN(LDLM_ITER_CONTINUE);
- }
-
- restart:
- rc = ldlm_plain_compat_queue(&res->lr_granted, lock, &rpc_list);
- rc += ldlm_plain_compat_queue(&res->lr_waiting, lock, &rpc_list);
-
- if (rc != 2) {
- /* If either of the compat_queue()s returned 0, then we
- * have ASTs to send and must go onto the waiting list.
- *
- * bug 2322: we used to unlink and re-add here, which was a
- * terrible folly -- if we goto restart, we could get
- * re-ordered! Causes deadlock, because ASTs aren't sent! */
- if (cfs_list_empty(&lock->l_res_link))
- ldlm_resource_add_lock(res, &res->lr_waiting, lock);
- unlock_res(res);
- rc = ldlm_run_ast_work(&rpc_list, LDLM_WORK_BL_AST);
- lock_res(res);
- if (rc == -ERESTART)
- GOTO(restart, -ERESTART);
- *flags |= LDLM_FL_BLOCK_GRANTED;
- } else {
- ldlm_resource_unlink_lock(lock);
- ldlm_grant_lock(lock, NULL);
- }
- RETURN(0);