1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
9 * by Cluster File Systems, Inc.
10 * authors, Peter Braam <braam@clusterfs.com> &
11 * Phil Schwan <phil@clusterfs.com>
15 #define DEBUG_SUBSYSTEM S_LDLM
17 #include <linux/lustre_dlm.h>
19 /* This function will be called to judge if the granted queue of another child
20 * (read: another extent) is conflicting and needs its granted queue walked to
23 * This helps to find conflicts between read and write locks on overlapping
25 int ldlm_extent_compat(struct ldlm_lock *a, struct ldlm_lock *b)
27 if (MAX(a->l_extent.start, b->l_extent.start) <=
28 MIN(a->l_extent.end, b->l_extent.end))
34 static void policy_internal(struct list_head *queue, struct ldlm_extent *req_ex,
35 struct ldlm_extent *new_ex, ldlm_mode_t mode)
37 struct list_head *tmp;
39 list_for_each(tmp, queue) {
40 struct ldlm_lock *lock;
41 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
43 if (lock->l_extent.end < req_ex->start)
44 new_ex->start = MIN(lock->l_extent.end, new_ex->start);
46 if (lock->l_extent.start < req_ex->start &&
47 !lockmode_compat(lock->l_req_mode, mode))
48 /* Policy: minimize conflict overlap */
49 new_ex->start = req_ex->start;
51 if (lock->l_extent.start > req_ex->end)
52 new_ex->end = MAX(lock->l_extent.start, new_ex->end);
54 if (lock->l_extent.end > req_ex->end &&
55 !lockmode_compat(lock->l_req_mode, mode))
56 /* Policy: minimize conflict overlap */
57 new_ex->end = req_ex->end;
62 /* The purpose of this function is to return:
63 * - the maximum extent
64 * - containing the requested extent
65 * - and not overlapping existing extents outside the requested one
67 * An alternative policy is to not shrink the new extent when conflicts exist.
69 * To reconstruct our formulas, take a deep breath. */
70 int ldlm_extent_policy(struct ldlm_resource *res, struct ldlm_extent *req_ex,
71 struct ldlm_extent *new_ex, ldlm_mode_t mode, void *data)
79 policy_internal(&res->lr_granted, req_ex, new_ex, mode);
80 policy_internal(&res->lr_converting, req_ex, new_ex, mode);
81 policy_internal(&res->lr_waiting, req_ex, new_ex, mode);
83 if (new_ex->end != req_ex->end || new_ex->start != req_ex->start)
84 return ELDLM_LOCK_CHANGED;