Whamcloud - gitweb
Removes all traces of mds_req, mds_rep, ost_req, and ost_rep. All subsystems
[fs/lustre-release.git] / lustre / include / linux / lustre_dlm.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 #ifndef _LUSTRE_DLM_H__
6 #define _LUSTRE_DLM_H__
7
8 #include <linux/kp30.h>
9 #include <linux/list.h>
10
11 #include <linux/obd_class.h>
12
13 #ifdef __KERNEL__
14
15 #define OBD_LDLM_DEVICENAME  "ldlm"
16
17 typedef  int cluster_host;
18 typedef  int cluster_pid;
19
20 typedef enum {
21         ELDLM_OK = 0,
22         ELDLM_BLOCK_GRANTED = 600,
23         ELDLM_BLOCK_CONV,
24         ELDLM_BLOCK_WAIT,
25         ELDLM_BAD_NAMESPACE,
26         ELDLM_LOCK_CHANGED
27 } ldlm_error_t;
28
29 #define LDLM_FL_LOCK_CHANGED   (1 << 0)
30 #define LDLM_FL_COMPLETION_AST (1 << 1)
31 #define LDLM_FL_BLOCKING_AST   (1 << 2)
32
33 #define L2B(c) (1 << c)
34
35 /* compatibility matrix */
36 #define LCK_COMPAT_EX  L2B(LCK_NL)
37 #define LCK_COMPAT_PW  (LCK_COMPAT_EX | L2B(LCK_CR))
38 #define LCK_COMPAT_PR  (LCK_COMPAT_PW | L2B(LCK_PR))
39 #define LCK_COMPAT_CW  (LCK_COMPAT_PW | L2B(LCK_CW))
40 #define LCK_COMPAT_CR  (LCK_COMPAT_CW | L2B(LCK_PR) | L2B(LCK_PW))
41 #define LCK_COMPAT_NL  (LCK_COMPAT_CR | L2B(LCK_EX))
42
43 static ldlm_mode_t lck_compat_array[] = {
44         [LCK_EX] LCK_COMPAT_EX,
45         [LCK_PW] LCK_COMPAT_PW,
46         [LCK_PR] LCK_COMPAT_PR,
47         [LCK_CW] LCK_COMPAT_CW,
48         [LCK_CR] LCK_COMPAT_CR,
49         [LCK_NL] LCK_COMPAT_NL
50 };
51
52 static inline int lockmode_compat(ldlm_mode_t exist, ldlm_mode_t new)
53 {
54        if (exist < LCK_EX || exist > LCK_NL)
55               LBUG();
56        if (new < LCK_EX || new > LCK_NL)
57               LBUG();
58
59        return (lck_compat_array[exist] & L2B(new));
60 }
61
62 /* 
63  * 
64  * cluster name spaces 
65  *
66  */
67
68 #define DLM_OST_NAMESPACE 1
69 #define DLM_MDS_NAMESPACE 2
70
71 /* XXX 
72    - do we just separate this by security domains and use a prefix for 
73      multiple namespaces in the same domain? 
74    - 
75 */
76
77 struct ldlm_namespace {
78         struct list_head      ns_link;      /* in the list of ns's */
79         __u32                 ns_id;        /* identifier of ns */
80         struct list_head     *ns_hash;      /* hash table for ns */
81         atomic_t              ns_refcount;  /* count of resources in the hash */
82         struct list_head      ns_root_list; /* all root resources in ns */
83         struct obd_device    *ns_obddev;
84 };
85
86 /* 
87  * 
88  * Resource hash table 
89  *
90  */
91
92 #define RES_HASH_BITS 14
93 #define RES_HASH_SIZE (1UL << RES_HASH_BITS)
94 #define RES_HASH_MASK (RES_HASH_SIZE - 1)
95
96 struct ldlm_lock;
97
98 typedef int (*ldlm_lock_callback)(struct ldlm_lock *lock, struct ldlm_lock *new,
99                                   void *data, __u32 data_len);
100
101 struct ldlm_lock {
102         struct ldlm_resource *l_resource;
103         struct ldlm_lock     *l_parent;
104         struct list_head      l_children;
105         struct list_head      l_childof;
106         struct list_head      l_res_link; /*position in one of three res lists*/
107         ldlm_mode_t           l_req_mode;
108         ldlm_mode_t           l_granted_mode;
109         ldlm_lock_callback    l_completion_ast;
110         ldlm_lock_callback    l_blocking_ast;
111         struct lustre_peer   *l_peer;
112         void                 *l_data;
113         __u32                 l_data_len;
114         struct ldlm_extent    l_extent;
115         //void                 *l_event;
116         //XXX cluster_host    l_holder;
117         __u32                 l_version[RES_VERSION_SIZE];
118 };
119
120 typedef int (*ldlm_res_compat)(struct ldlm_lock *child, struct ldlm_lock *new);
121 typedef int (*ldlm_res_policy)(struct ldlm_resource *parent,
122                                struct ldlm_extent *req_ex,
123                                struct ldlm_extent *new_ex,
124                                ldlm_mode_t mode, void *data);
125
126 #define LDLM_PLAIN       0x0
127 #define LDLM_EXTENT      0x1
128 #define LDLM_MDSINTENT   0x2
129
130 #define LDLM_MAX_TYPE    0x2
131 extern ldlm_res_compat ldlm_res_compat_table []; 
132 extern ldlm_res_policy ldlm_res_policy_table []; 
133
134 struct ldlm_resource {
135         struct ldlm_namespace *lr_namespace;
136         struct list_head       lr_hash;
137         struct list_head       lr_rootlink; /* link all root resources in NS */
138         struct ldlm_resource  *lr_parent;   /* 0 for a root resource */
139         struct list_head       lr_children; /* list head for child resources */
140         struct list_head       lr_childof;  /* part of child list of parent */
141
142         struct list_head       lr_granted;
143         struct list_head       lr_converting;
144         struct list_head       lr_waiting;
145         ldlm_mode_t            lr_most_restr;
146         atomic_t               lr_refcount;
147         __u32                  lr_type; /* PLAIN, EXTENT, or MDSINTENT */
148         struct ldlm_resource  *lr_root;
149         //XXX cluster_host          lr_master;
150         __u64                  lr_name[RES_NAME_SIZE];
151         __u32                  lr_version[RES_VERSION_SIZE];
152         spinlock_t             lr_lock;
153 };
154
155 static inline struct ldlm_extent *ldlm_res2extent(struct ldlm_resource *res)
156 {
157         return (struct ldlm_extent *)(res->lr_name);
158 }
159
160 static inline void *ldlm_handle2object(struct ldlm_handle *handle)
161 {
162         if (handle) 
163                 return (void *)(unsigned long)(handle->addr);
164         return NULL; 
165 }
166
167 static inline void ldlm_object2handle(void *object, struct ldlm_handle *handle)
168 {
169         handle->addr = (__u64)(unsigned long)object;
170 }
171
172 static inline void ldlm_lock(struct obd_device *obddev)
173 {
174         spin_lock(&obddev->u.ldlm.ldlm_lock);
175 }
176
177 static inline void ldlm_unlock(struct obd_device *obddev)
178 {
179         spin_unlock(&obddev->u.ldlm.ldlm_lock);
180 }
181
182 extern struct obd_ops ldlm_obd_ops;
183
184 /* ldlm_extent.c */
185 int ldlm_extent_compat(struct ldlm_lock *, struct ldlm_lock *);
186 int ldlm_extent_policy(struct ldlm_resource *, struct ldlm_extent *,
187                        struct ldlm_extent *, ldlm_mode_t, void *);
188
189 /* ldlm_lock.c */
190 void ldlm_lock_free(struct ldlm_lock *lock);
191 ldlm_error_t ldlm_local_lock_enqueue(struct obd_device *obddev,
192                                      __u32 ns_id,
193                                      struct ldlm_handle *parent_lock_handle,
194                                      __u64 *res_id,
195                                      __u32 type,
196                                      struct ldlm_extent *req_ex,
197                                      ldlm_mode_t mode,
198                                      int *flags,
199                                      ldlm_lock_callback completion,
200                                      ldlm_lock_callback blocking,
201                                      void *data,
202                                      __u32 data_len,
203                                      struct ldlm_handle *lockh);
204 ldlm_error_t ldlm_local_lock_convert(struct obd_device *obddev,
205                                      struct ldlm_handle *lockh,
206                                      int new_mode, int *flags);
207 ldlm_error_t ldlm_local_lock_cancel(struct obd_device *obddev,
208                                     struct ldlm_handle *lockh);
209 void ldlm_lock_dump(struct ldlm_lock *lock);
210
211 /* ldlm_test.c */
212 int ldlm_test(struct obd_device *device);
213
214 /* resource.c */
215 struct ldlm_namespace *ldlm_namespace_find(struct obd_device *, __u32 id);
216 struct ldlm_namespace *ldlm_namespace_new(struct obd_device *, __u32 id);
217 int ldlm_namespace_free(struct ldlm_namespace *ns);
218 void ldlm_resource_dump(struct ldlm_resource *res);
219 struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
220                                         struct ldlm_resource *parent,
221                                         __u64 *name, __u32 type, int create);
222 int ldlm_resource_put(struct ldlm_resource *res);
223 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
224                             struct ldlm_lock *lock);
225 void ldlm_resource_del_lock(struct ldlm_lock *lock);
226
227 #endif /* __KERNEL__ */
228
229 /* ioctls for trying requests */
230 #define IOC_LDLM_TYPE                   'f'
231 #define IOC_LDLM_MIN_NR                 40
232
233 #define IOC_LDLM_TEST                   _IOWR('f', 40, long)
234 #define IOC_LDLM_MAX_NR                 41
235
236 #endif