1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Peter Braam <braam@clusterfs.com>
6 * Author: Phil Schwan <phil@clusterfs.com>
8 * This file is part of the Lustre file system, http://www.lustre.org
9 * Lustre is a trademark of Cluster File Systems, Inc.
11 * You may have signed or agreed to another license before downloading
12 * this software. If so, you are bound by the terms and conditions
13 * of that agreement, and the following does not apply to you. See the
14 * LICENSE file included with this distribution for more information.
16 * If you did not agree to a different license, then this copy of Lustre
17 * is open source software; you can redistribute it and/or modify it
18 * under the terms of version 2 of the GNU General Public License as
19 * published by the Free Software Foundation.
21 * In either case, Lustre is distributed in the hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * license text for more details.
27 #define DEBUG_SUBSYSTEM S_LDLM
30 #include <lustre_dlm.h>
31 #include <obd_support.h>
32 #include <lustre_lib.h>
34 #include <liblustre.h>
37 #include "ldlm_internal.h"
40 ldlm_plain_compat_queue(struct list_head *queue, struct ldlm_lock *req,
41 struct list_head *work_list)
43 struct list_head *tmp;
44 struct ldlm_lock *lock;
45 ldlm_mode_t req_mode = req->l_req_mode;
49 lockmode_verify(req_mode);
51 list_for_each(tmp, queue) {
52 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
57 if (lockmode_compat(lock->l_req_mode, req_mode)) {
58 /* jump to next mode group */
59 if (LDLM_SL_HEAD(&lock->l_sl_mode))
60 tmp = &list_entry(lock->l_sl_mode.next,
62 l_sl_mode)->l_res_link;
70 if (lock->l_blocking_ast)
71 ldlm_add_ast_work_item(lock, req, work_list);
72 if (LDLM_SL_HEAD(&lock->l_sl_mode)) {
73 /* add all members of the mode group */
75 tmp = lock->l_res_link.next;
76 lock = list_entry(tmp, struct ldlm_lock,
78 if (lock->l_blocking_ast)
79 ldlm_add_ast_work_item(
80 lock, req, work_list);
81 } while (!LDLM_SL_TAIL(&lock->l_sl_mode));
88 /* If first_enq is 0 (ie, called from ldlm_reprocess_queue):
89 * - blocking ASTs have already been sent
90 * - the caller has already initialized req->lr_tmp
91 * - must call this function with the resource lock held
93 * If first_enq is 1 (ie, called from ldlm_lock_enqueue):
94 * - blocking ASTs have not been sent
95 * - the caller has NOT initialized req->lr_tmp, so we must
96 * - must call this function with the resource lock held */
97 int ldlm_process_plain_lock(struct ldlm_lock *lock, int *flags, int first_enq,
98 ldlm_error_t *err, struct list_head *work_list)
100 struct ldlm_resource *res = lock->l_resource;
101 struct list_head rpc_list = CFS_LIST_HEAD_INIT(rpc_list);
105 check_res_locked(res);
106 LASSERT(list_empty(&res->lr_converting));
109 LASSERT(work_list != NULL);
110 rc = ldlm_plain_compat_queue(&res->lr_granted, lock, NULL);
112 RETURN(LDLM_ITER_STOP);
113 rc = ldlm_plain_compat_queue(&res->lr_waiting, lock, NULL);
115 RETURN(LDLM_ITER_STOP);
117 ldlm_resource_unlink_lock(lock);
118 ldlm_grant_lock(lock, work_list);
119 RETURN(LDLM_ITER_CONTINUE);
123 rc = ldlm_plain_compat_queue(&res->lr_granted, lock, &rpc_list);
124 rc += ldlm_plain_compat_queue(&res->lr_waiting, lock, &rpc_list);
127 /* If either of the compat_queue()s returned 0, then we
128 * have ASTs to send and must go onto the waiting list.
130 * bug 2322: we used to unlink and re-add here, which was a
131 * terrible folly -- if we goto restart, we could get
132 * re-ordered! Causes deadlock, because ASTs aren't sent! */
133 if (list_empty(&lock->l_res_link))
134 ldlm_resource_add_lock(res, &res->lr_waiting, lock);
136 rc = ldlm_run_bl_ast_work(&rpc_list);
139 GOTO(restart, -ERESTART);
140 *flags |= LDLM_FL_BLOCK_GRANTED;
142 ldlm_resource_unlink_lock(lock);
143 ldlm_grant_lock(lock, NULL);