Whamcloud - gitweb
*** empty log message ***
[fs/lustre-release.git] / lustre / ldlm / ldlm_extent.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  *
9  * by Cluster File Systems, Inc.
10  * authors, Peter Braam <braam@clusterfs.com> & 
11  * Phil Schwan <phil@clusterfs.com>
12  */
13
14 #define EXPORT_SYMTAB
15
16 #include <linux/version.h>
17 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <asm/unistd.h>
20
21 #define DEBUG_SUBSYSTEM S_LDLM
22
23 #include <linux/obd_support.h>
24 #include <linux/obd_class.h>
25 #include <linux/lustre_dlm.h>
26
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
29  * issue callbacks.
30  *
31  * This helps to find conflicts between read and write locks on overlapping
32  * extents. */
33 int ldlm_extent_compat(struct ldlm_resource *child, struct ldlm_resource *new)
34 {
35         struct ldlm_extent *child_ex, *new_ex;
36
37         child_ex = ldlm_res2extent(child);
38         new_ex = ldlm_res2extent(new);
39
40         if (MAX(child_ex->start, new_ex->start) >
41             MIN(child_ex->end, new_ex->end))
42                 return 0;
43
44         return 1;
45 }
46
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
51  *
52  * An alternative policy is to not shrink the new extent when conflicts exist.
53  *
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)
58 {
59         struct ldlm_extent *new_ex, *req_ex;
60         struct list_head *tmp;
61
62         req_ex = (struct ldlm_extent *)res_id_in;
63
64         new_ex = (struct ldlm_extent *)res_id_out;
65         new_ex->start = 0;
66         new_ex->end = ~0;
67
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);
72
73                 res_ex = ldlm_res2extent(res);
74
75                 if (res_ex->end < req_ex->start)
76                         new_ex->start = MIN(res_ex->end, new_ex->start);
77                 else {
78                         if (res_ex->start < req_ex->start)
79                                 /* Policy: minimize conflict overlap */
80                                 new_ex->start = req_ex->start;
81                 }
82                 if (res_ex->start > req_ex->end)
83                         new_ex->end = MAX(res_ex->start, new_ex->end);
84                 else {
85                         if (res_ex->end > req_ex->end)
86                                 /* Policy: minimize conflict overlap */
87                                 new_ex->end = req_ex->end;
88                 }
89         }
90
91         return 0;
92 }
93