Whamcloud - gitweb
- updated documentation (introduction)
[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,
23         ELDLM_BLOCK_CONV,
24         ELDLM_BLOCK_WAIT
25 } ldlm_error_t;
26
27 /* lock types */
28 typedef enum {
29         LCK_EX = 1,
30         LCK_PW,
31         LCK_PR,
32         LCK_CW,
33         LCK_CR,
34         LCK_NL
35 } ldlm_mode_t;
36
37 #define L2B(c) (1 << c)
38
39 /* compatibility matrix */
40 #define LCK_COMPAT_EX  L2B(LCK_NL)
41 #define LCK_COMPAT_PW  (LCK_COMPAT_EX | L2B(LCK_CR))
42 #define LCK_COMPAT_PR  (LCK_COMPAT_PW | L2B(LCK_PR))
43 #define LCK_COMPAT_CW  (LCK_COMPAT_PW | L2B(LCK_CW))
44 #define LCK_COMPAT_CR  (LCK_COMPAT_CW | L2B(LCK_PR) | L2B(LCK_PW))
45 #define LCK_COMPAT_NL  (LCK_COMPAT_CR | L2B(LCK_EX))
46
47 static ldlm_mode_t lck_compat_array[] = {
48         [LCK_EX] LCK_COMPAT_EX,
49         [LCK_PW] LCK_COMPAT_PW,
50         [LCK_PR] LCK_COMPAT_PR,
51         [LCK_CW] LCK_COMPAT_CW,
52         [LCK_CR] LCK_COMPAT_CR,
53         [LCK_NL] LCK_COMPAT_NL
54 };
55
56 static inline int lockmode_compat(ldlm_mode_t exist, ldlm_mode_t new)
57 {
58        if (exist < LCK_EX || exist > LCK_NL)
59               BUG();
60        if (new < LCK_EX || new > LCK_NL)
61               BUG();
62
63        return (lck_compat_array[exist] & L2B(new));
64 }
65
66 /* 
67  * 
68  * cluster name spaces 
69  *
70  */
71
72 #define DLM_OST_NAMESPACE 1
73 #define DLM_MDS_NAMESPACE 2
74
75 /* XXX 
76    - do we just separate this by security domains and use a prefix for 
77      multiple namespaces in the same domain? 
78    - 
79 */
80
81 struct ldlm_namespace {
82         struct list_head      ns_link;      /* in the list of ns's */
83         __u32                 ns_id;        /* identifier of ns */
84         struct list_head     *ns_hash;      /* hash table for ns */
85         struct list_head      ns_root_list; /* all root resources in ns */
86         struct obd_device    *ns_obddev;
87 };
88
89 /* 
90  * 
91  * Resource hash table 
92  *
93  */
94
95 #define RES_HASH_BITS 14
96 #define RES_HASH_SIZE (1UL << RES_HASH_BITS)
97 #define RES_HASH_MASK (RES_HASH_SIZE - 1)
98
99 #define RES_NAME_SIZE 6
100 #define RES_VERSION_SIZE 4
101
102 struct ldlm_lock {
103         struct ldlm_resource *l_resource;
104         struct ldlm_lock     *l_parent;
105         struct list_head      l_children;
106         struct list_head      l_childof;
107         struct list_head      l_res_link; /*position in one of three res lists*/
108         ldlm_mode_t           l_req_mode;
109         ldlm_mode_t           l_granted_mode;
110         void                 *l_completion_ast;
111         void                 *l_blocking_ast;
112         void                 *l_event;
113         //XXX cluster_host    l_holder;
114         __u32                 l_version[RES_VERSION_SIZE];
115 };
116
117 struct ldlm_resource {
118         struct ldlm_namespace *lr_namespace;
119         struct list_head       lr_hash;
120         struct list_head       lr_rootlink; /* link all root resources in NS */
121         struct ldlm_resource  *lr_parent;   /* 0 for a root resource */
122         struct list_head       lr_children; /* list head for child resources */
123         struct list_head       lr_childof;  /* part of child list of parent */
124
125         struct list_head       lr_granted;
126         struct list_head       lr_converting;
127         struct list_head       lr_waiting;
128         ldlm_mode_t            lr_most_restr;
129         atomic_t               lr_refcount;
130         struct ldlm_resource  *lr_root;
131         //XXX cluster_host          lr_master;
132         __u32                  lr_name[RES_NAME_SIZE];
133         __u32                  lr_version[RES_VERSION_SIZE];
134         spinlock_t             lr_lock;
135
136         void (*lr_blocking)(struct ldlm_lock *lock, struct ldlm_lock *new);
137 };
138
139 struct ldlm_handle {
140         __u64 addr;
141         __u64 cookie;
142 };
143
144 static inline void ldlm_lock(struct obd_device *obddev)
145 {
146         spin_lock(&obddev->u.ldlm.ldlm_lock);
147 }
148
149 static inline void ldlm_unlock(struct obd_device *obddev)
150 {
151         spin_unlock(&obddev->u.ldlm.ldlm_lock);
152 }
153
154 extern struct obd_ops ldlm_obd_ops;
155
156 /* ldlm_lock.c */
157 ldlm_error_t ldlm_local_lock_enqueue(struct obd_device *obbdev, __u32 ns_id,
158                                      struct ldlm_resource *parent_res,
159                                      struct ldlm_lock *parent_lock,
160                                      __u32 *res_id, ldlm_mode_t mode, 
161                                      struct ldlm_handle *);
162 void ldlm_lock_dump(struct ldlm_lock *lock);
163
164 /* ldlm_test.c */
165 int ldlm_test(struct obd_device *device);
166
167 /* resource.c */
168 struct ldlm_namespace *ldlm_namespace_find(struct obd_device *obddev, __u32 id);
169 struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obddev, __u32 id);
170 void ldlm_resource_dump(struct ldlm_resource *res);
171 struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
172                                         struct ldlm_resource *parent,
173                                         __u32 *name, int create);
174 int ldlm_resource_put(struct ldlm_resource *res);
175
176 #endif /* __KERNEL__ */
177
178 /* ioctls for trying requests */
179 #define IOC_LDLM_TYPE                   'f'
180 #define IOC_LDLM_MIN_NR                 40
181
182 #define IOC_LDLM_TEST                   _IOWR('f', 40, long)
183 #define IOC_LDLM_MAX_NR                 41
184
185 #endif