Whamcloud - gitweb
- Don't abort if fig2dev doesn't exist
[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_lock *a, struct ldlm_lock *b)
34 {
35         if (MAX(a->l_extent.start, b->l_extent.start) <=
36             MIN(a->l_extent.end, b->l_extent.end))
37                 return 0;
38
39         return 1;
40 }
41
42 static void policy_internal(struct list_head *queue, struct ldlm_extent *req_ex,
43                             struct ldlm_extent *new_ex, ldlm_mode_t mode)
44 {
45         struct list_head *tmp;
46
47         list_for_each(tmp, queue) {
48                 struct ldlm_lock *lock;
49                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
50
51                 if (lock->l_extent.end < req_ex->start)
52                         new_ex->start = MIN(lock->l_extent.end, new_ex->start);
53                 else {
54                         if (lock->l_extent.start < req_ex->start &&
55                             !lockmode_compat(lock->l_req_mode, mode))
56                                 /* Policy: minimize conflict overlap */
57                                 new_ex->start = req_ex->start;
58                 }
59                 if (lock->l_extent.start > req_ex->end)
60                         new_ex->end = MAX(lock->l_extent.start, new_ex->end);
61                 else {
62                         if (lock->l_extent.end > req_ex->end &&
63                             !lockmode_compat(lock->l_req_mode, mode))
64                                 /* Policy: minimize conflict overlap */
65                                 new_ex->end = req_ex->end;
66                 }
67         }
68 }
69
70 /* The purpose of this function is to return:
71  * - the maximum extent
72  * - containing the requested extent
73  * - and not overlapping existing extents outside the requested one
74  *
75  * An alternative policy is to not shrink the new extent when conflicts exist.
76  *
77  * To reconstruct our formulas, take a deep breath. */
78 int ldlm_extent_policy(struct ldlm_resource *res, struct ldlm_extent *req_ex,
79                        struct ldlm_extent *new_ex, ldlm_mode_t mode, void *data)
80 {
81         new_ex->start = 0;
82         new_ex->end = ~0;
83
84         if (!res)
85                 LBUG();
86
87         policy_internal(&res->lr_granted, req_ex, new_ex, mode);
88         policy_internal(&res->lr_converting, req_ex, new_ex, mode);
89         policy_internal(&res->lr_waiting, req_ex, new_ex, mode);
90
91         if (new_ex->end != req_ex->end || new_ex->start != req_ex->start)
92                 return ELDLM_LOCK_CHANGED;
93         return 0;
94 }