1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/ldlm/ldlm_plain.c
40 * Author: Peter Braam <braam@clusterfs.com>
41 * Author: Phil Schwan <phil@clusterfs.com>
44 #define DEBUG_SUBSYSTEM S_LDLM
47 #include <lustre_dlm.h>
48 #include <obd_support.h>
49 #include <lustre_lib.h>
51 #include <liblustre.h>
54 #include "ldlm_internal.h"
57 ldlm_plain_compat_queue(cfs_list_t *queue, struct ldlm_lock *req,
58 cfs_list_t *work_list)
61 struct ldlm_lock *lock;
62 ldlm_mode_t req_mode = req->l_req_mode;
66 lockmode_verify(req_mode);
68 cfs_list_for_each(tmp, queue) {
69 lock = cfs_list_entry(tmp, struct ldlm_lock, l_res_link);
74 /* last lock in mode group */
75 tmp = &cfs_list_entry(lock->l_sl_mode.prev,
77 l_sl_mode)->l_res_link;
79 if (lockmode_compat(lock->l_req_mode, req_mode))
87 /* add locks of the mode group to @work_list as
88 * blocking locks for @req */
89 if (lock->l_blocking_ast)
90 ldlm_add_ast_work_item(lock, req, work_list);
95 head = &lock->l_sl_mode;
96 cfs_list_for_each_entry(lock, head, l_sl_mode)
97 if (lock->l_blocking_ast)
98 ldlm_add_ast_work_item(lock, req,
106 /* If first_enq is 0 (ie, called from ldlm_reprocess_queue):
107 * - blocking ASTs have already been sent
108 * - must call this function with the resource lock held
110 * If first_enq is 1 (ie, called from ldlm_lock_enqueue):
111 * - blocking ASTs have not been sent
112 * - must call this function with the resource lock held */
113 int ldlm_process_plain_lock(struct ldlm_lock *lock, int *flags, int first_enq,
114 ldlm_error_t *err, cfs_list_t *work_list)
116 struct ldlm_resource *res = lock->l_resource;
117 CFS_LIST_HEAD(rpc_list);
121 check_res_locked(res);
122 LASSERT(cfs_list_empty(&res->lr_converting));
125 LASSERT(work_list != NULL);
126 rc = ldlm_plain_compat_queue(&res->lr_granted, lock, NULL);
128 RETURN(LDLM_ITER_STOP);
129 rc = ldlm_plain_compat_queue(&res->lr_waiting, lock, NULL);
131 RETURN(LDLM_ITER_STOP);
133 ldlm_resource_unlink_lock(lock);
134 ldlm_grant_lock(lock, work_list);
135 RETURN(LDLM_ITER_CONTINUE);
139 rc = ldlm_plain_compat_queue(&res->lr_granted, lock, &rpc_list);
140 rc += ldlm_plain_compat_queue(&res->lr_waiting, lock, &rpc_list);
143 /* If either of the compat_queue()s returned 0, then we
144 * have ASTs to send and must go onto the waiting list.
146 * bug 2322: we used to unlink and re-add here, which was a
147 * terrible folly -- if we goto restart, we could get
148 * re-ordered! Causes deadlock, because ASTs aren't sent! */
149 if (cfs_list_empty(&lock->l_res_link))
150 ldlm_resource_add_lock(res, &res->lr_waiting, lock);
152 rc = ldlm_run_ast_work(ldlm_res_to_ns(res), &rpc_list,
156 GOTO(restart, -ERESTART);
157 *flags |= LDLM_FL_BLOCK_GRANTED;
159 ldlm_resource_unlink_lock(lock);
160 ldlm_grant_lock(lock, NULL);
165 void ldlm_plain_policy_wire_to_local(const ldlm_wire_policy_data_t *wpolicy,
166 ldlm_policy_data_t *lpolicy)
168 /* No policy for plain locks */
171 void ldlm_plain_policy_local_to_wire(const ldlm_policy_data_t *lpolicy,
172 ldlm_wire_policy_data_t *wpolicy)
174 /* No policy for plain locks */