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>
16 #include <linux/version.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <asm/unistd.h>
21 #define DEBUG_SUBSYSTEM S_LDLM
23 #include <linux/obd_support.h>
24 #include <linux/obd_class.h>
25 #include <linux/lustre_dlm.h>
27 /* This function will be called to judge if the granted queue of another child
28 * (read: another extent) is conflicting and needs its granted queue walked to
31 * This helps to find conflicts between read and write locks on overlapping
33 int ldlm_extent_compat(struct ldlm_resource *child, struct ldlm_resource *new)
35 struct ldlm_extent *child_ex, *new_ex;
37 child_ex = ldlm_res2extent(child);
38 new_ex = ldlm_res2extent(new);
40 if (MAX(child_ex->start, new_ex->start) >
41 MIN(child_ex->end, new_ex->end))
47 /* The purpose of this function is to return:
48 * - the maximum extent
49 * - containing the requested extent
50 * - and not overlapping existing extents outside the requested one
52 * An alternative policy is to not shrink the new extent when conflicts exist.
54 * To reconstruct our formulas, take a deep breath. */
55 int ldlm_extent_policy(struct ldlm_resource *parent,
56 __u64 *res_id_in, __u64 *res_id_out,
57 ldlm_mode_t mode, void *data)
59 struct ldlm_extent *new_ex, *req_ex;
60 struct list_head *tmp;
62 req_ex = (struct ldlm_extent *)res_id_in;
64 new_ex = (struct ldlm_extent *)res_id_out;
68 list_for_each(tmp, &parent->lr_children) {
69 struct ldlm_resource *res;
70 struct ldlm_extent *res_ex;
71 res = list_entry(tmp, struct ldlm_resource, lr_childof);
73 res_ex = ldlm_res2extent(res);
75 if (res_ex->end < req_ex->start)
76 new_ex->start = MIN(res_ex->end, new_ex->start);
78 if (res_ex->start < req_ex->start)
79 /* Policy: minimize conflict overlap */
80 new_ex->start = req_ex->start;
82 if (res_ex->start > req_ex->end)
83 new_ex->end = MAX(res_ex->start, new_ex->end);
85 if (res_ex->end > req_ex->end)
86 /* Policy: minimize conflict overlap */
87 new_ex->end = req_ex->end;