Whamcloud - gitweb
- landed b_hd_mdref (mostly WB cache fixes)
[fs/lustre-release.git] / lustre / include / linux / lustre_dlm.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * (visit-tags-table FILE)
3  * vim:expandtab:shiftwidth=8:tabstop=8:
4  */
5
6 #ifndef _LUSTRE_DLM_H__
7 #define _LUSTRE_DLM_H__
8
9 #ifdef __KERNEL__
10 # include <linux/proc_fs.h>
11 #endif
12
13 #include <linux/lustre_lib.h>
14 #include <linux/lustre_net.h>
15 #include <linux/lustre_import.h>
16 #include <linux/lustre_handles.h>
17 #include <linux/lustre_export.h> /* for obd_export, for LDLM_DEBUG */
18
19 struct obd_ops;
20 struct obd_device;
21
22 #define LDLM_DEFAULT_LRU_SIZE 100
23
24 typedef enum {
25         ELDLM_OK = 0,
26
27         ELDLM_LOCK_CHANGED = 300,
28         ELDLM_LOCK_ABORTED = 301,
29         ELDLM_LOCK_REPLACED = 302,
30         ELDLM_NO_LOCK_DATA = 303,
31
32         ELDLM_NAMESPACE_EXISTS = 400,
33         ELDLM_BAD_NAMESPACE    = 401
34 } ldlm_error_t;
35
36 #define LDLM_NAMESPACE_SERVER 0
37 #define LDLM_NAMESPACE_CLIENT 1
38
39 #define LDLM_FL_LOCK_CHANGED   0x000001 /* extent, mode, or resource changed */
40
41 /* If the server returns one of these flags, then the lock was put on that list.
42  * If the client sends one of these flags (during recovery ONLY!), it wants the
43  * lock added to the specified list, no questions asked. -p */
44 #define LDLM_FL_BLOCK_GRANTED  0x000002
45 #define LDLM_FL_BLOCK_CONV     0x000004
46 #define LDLM_FL_BLOCK_WAIT     0x000008
47
48 #define LDLM_FL_CBPENDING      0x000010 /* this lock is being destroyed */
49 #define LDLM_FL_AST_SENT       0x000020 /* blocking or cancel packet was sent */
50 #define LDLM_FL_WAIT_NOREPROC  0x000040 /* not a real flag, not saved in lock */
51 #define LDLM_FL_CANCEL         0x000080 /* cancellation callback already run */
52
53 /* Lock is being replayed.  This could probably be implied by the fact that one
54  * of BLOCK_{GRANTED,CONV,WAIT} is set, but that is pretty dangerous. */
55 #define LDLM_FL_REPLAY         0x000100
56
57 #define LDLM_FL_INTENT_ONLY    0x000200 /* don't grant lock, just do intent */
58 #define LDLM_FL_LOCAL_ONLY     0x000400 /* see ldlm_cli_cancel_unused */
59
60 /* don't run the cancel callback under ldlm_cli_cancel_unused */
61 #define LDLM_FL_FAILED         0x000800
62
63 #define LDLM_FL_HAS_INTENT     0x001000 /* lock request has intent */
64 #define LDLM_FL_CANCELING      0x002000 /* lock cancel has already been sent */
65 #define LDLM_FL_LOCAL          0x004000 /* local lock (ie, no srv/cli split) */
66 #define LDLM_FL_WARN           0x008000 /* see ldlm_cli_cancel_unused */
67 #define LDLM_FL_DISCARD_DATA   0x010000 /* discard (no writeback) on cancel */
68 #define LDLM_FL_CONFIG_CHANGE  0x020000 /* see ldlm_cli_cancel_unused */
69
70 #define LDLM_FL_NO_TIMEOUT     0x020000 /* Blocked by group lock - wait
71                                          * indefinitely */
72
73 /* file & record locking */
74 #define LDLM_FL_BLOCK_NOWAIT   0x040000 /* server told not to wait if blocked */
75 #define LDLM_FL_TEST_LOCK      0x080000 /* return blocking lock */
76
77 /* These are flags that are mapped into the flags and ASTs of blocking locks */
78 #define LDLM_AST_DISCARD_DATA  0x80000000 /* Add FL_DISCARD to blocking ASTs */
79 /* Flags sent in AST lock_flags to be mapped into the receiving lock. */
80 #define LDLM_AST_FLAGS         (LDLM_FL_DISCARD_DATA)
81
82 /* XXX FIXME: This is being added to b_size as a low-risk fix to the fact that
83  * the LVB filling happens _after_ the lock has been granted, so another thread
84  * can match before the LVB has been updated.  As a dirty hack, we set
85  * LDLM_FL_CAN_MATCH only after we've done the LVB poop.
86  *
87  * The proper fix is to do the granting inside of the completion AST, which can
88  * be replaced with a LVB-aware wrapping function for OSC locks.  That change is
89  * pretty high-risk, though, and would need a lot more testing. */
90 #define LDLM_FL_CAN_MATCH      0x100000
91
92 /* A lock contributes to the kms calculation until it has finished the part
93  * of it's cancelation that performs write back on its dirty pages.  It
94  * can remain on the granted list during this whole time.  Threads racing
95  * to update the kms after performing their writeback need to know to
96  * exclude each others locks from the calculation as they walk the granted
97  * list. */
98 #define LDLM_FL_KMS_IGNORE     0x200000
99
100 /* completion ast to be executed */
101 #define LDLM_FL_CP_REQD        0x400000
102
103 /* cleanup_resource has already handled the lock */
104 #define LDLM_FL_CLEANED        0x800000
105
106 /* optimization hint: LDLM can run blocking callback from current context
107  * w/o involving separate thread. in order to decrease cs rate */
108 #define LDLM_FL_ATOMIC_CB      0x1000000
109
110 /* while this flag is set, the lock can't change resource */
111 #define LDLM_FL_LOCK_PROTECT   0x4000000
112 #define LDLM_FL_LOCK_PROTECT_BIT  26
113
114 /* The blocking callback is overloaded to perform two functions.  These flags
115  * indicate which operation should be performed. */
116 #define LDLM_CB_BLOCKING    1
117 #define LDLM_CB_CANCELING   2
118
119 /* compatibility matrix */
120 #define LCK_COMPAT_EX  LCK_NL
121 #define LCK_COMPAT_PW  (LCK_COMPAT_EX | LCK_CR)
122 #define LCK_COMPAT_PR  (LCK_COMPAT_PW | LCK_PR)
123 #define LCK_COMPAT_CW  (LCK_COMPAT_PW | LCK_CW)
124 #define LCK_COMPAT_CR  (LCK_COMPAT_CW | LCK_PR | LCK_PW)
125 #define LCK_COMPAT_NL  (LCK_COMPAT_CR | LCK_EX)
126 #define LCK_COMPAT_GROUP  (LCK_GROUP | LCK_NL)
127
128 static ldlm_mode_t lck_compat_array[] = {
129         [LCK_EX] LCK_COMPAT_EX,
130         [LCK_PW] LCK_COMPAT_PW,
131         [LCK_PR] LCK_COMPAT_PR,
132         [LCK_CW] LCK_COMPAT_CW,
133         [LCK_CR] LCK_COMPAT_CR,
134         [LCK_NL] LCK_COMPAT_NL,
135         [LCK_GROUP] LCK_COMPAT_GROUP
136 };
137
138 static inline void lockmode_verify(ldlm_mode_t mode)
139 {
140        LASSERT(mode >= LCK_EX && mode <= LCK_GROUP);
141 }
142
143 static inline int lockmode_compat(ldlm_mode_t exist, ldlm_mode_t new)
144 {
145        return (lck_compat_array[exist] & new);
146 }
147
148 /*
149  *
150  * cluster name spaces
151  *
152  */
153
154 #define DLM_OST_NAMESPACE 1
155 #define DLM_MDS_NAMESPACE 2
156
157 /* XXX
158    - do we just separate this by security domains and use a prefix for
159      multiple namespaces in the same domain?
160    -
161 */
162
163 /*
164  * Locking rules:
165  *
166  * lr_lock
167  *
168  * lr_lock
169  *     waiting_locks_spinlock
170  *
171  * lr_lock
172  *     led_lock
173  *
174  * lr_lock
175  *     ns_unused_lock
176  *
177  * lr_lvb_sem
178  *     lr_lock
179  *
180  */
181
182 struct ldlm_lock;
183 struct ldlm_resource;
184 struct ldlm_namespace;
185
186 typedef int (*ldlm_res_policy)(struct ldlm_namespace *, struct ldlm_lock **,
187                                void *req_cookie, ldlm_mode_t mode, int flags,
188                                void *data);
189
190 struct ldlm_valblock_ops {
191         int (*lvbo_init)(struct ldlm_resource *res);
192         
193         int (*lvbo_update)(struct ldlm_resource *res,
194                            struct lustre_msg *m,
195                            int buf_idx, int increase);
196 };
197
198 struct ldlm_namespace {
199         char                  *ns_name;
200         __u32                  ns_client; /* is this a client-side lock tree? */
201         struct list_head      *ns_hash; /* hash table for ns */
202         spinlock_t             ns_hash_lock;
203         __u32                  ns_refcount; /* count of resources in the hash */
204         struct list_head       ns_root_list; /* all root resources in ns */
205         struct list_head       ns_list_chain; /* position in global NS list */
206         /*
207         struct proc_dir_entry *ns_proc_dir;
208         */
209
210         struct list_head       ns_unused_list; /* all root resources in ns */
211         int                    ns_nr_unused;
212         spinlock_t             ns_unused_lock;
213
214         unsigned int           ns_max_unused;
215         unsigned long          ns_next_dump;   /* next dump time */
216
217         atomic_t               ns_locks;
218         __u64                  ns_resources;
219         ldlm_res_policy        ns_policy;
220         struct ldlm_valblock_ops *ns_lvbo;
221         void                  *ns_lvbp;
222         wait_queue_head_t      ns_waitq;
223 };
224
225 /*
226  *
227  * Resource hash table
228  *
229  */
230
231 #define RES_HASH_BITS 10
232 #define RES_HASH_SIZE (1UL << RES_HASH_BITS)
233 #define RES_HASH_MASK (RES_HASH_SIZE - 1)
234
235 struct ldlm_lock;
236
237 typedef int (*ldlm_blocking_callback)(struct ldlm_lock *lock,
238                                       struct ldlm_lock_desc *new, void *data,
239                                       int flag);
240 typedef int (*ldlm_completion_callback)(struct ldlm_lock *lock, int flags,
241                                         void *data);
242 typedef int (*ldlm_glimpse_callback)(struct ldlm_lock *lock, void *data);
243
244 struct ldlm_lock {
245         struct portals_handle l_handle; // must be first in the structure
246         atomic_t              l_refc;
247
248         /* ldlm_lock_change_resource() can change this */
249         struct ldlm_resource *l_resource;
250
251         /* set once, no need to protect it */
252         struct ldlm_lock     *l_parent;
253
254         /* protected by ns_hash_lock */
255         struct list_head      l_children;
256         struct list_head      l_childof;
257
258         /* protected by ns_hash_lock. FIXME */
259         struct list_head      l_lru;
260
261         /* protected by lr_lock */
262         struct list_head      l_res_link; // position in one of three res lists
263
264         /* protected by led_lock */
265         struct list_head      l_export_chain; // per-export chain of locks
266
267         /* protected by lr_lock */
268         ldlm_mode_t           l_req_mode;
269         ldlm_mode_t           l_granted_mode;
270
271         ldlm_completion_callback l_completion_ast;
272         ldlm_blocking_callback   l_blocking_ast;
273         ldlm_glimpse_callback    l_glimpse_ast;
274
275         struct obd_export    *l_export;
276         struct obd_export    *l_conn_export;
277
278         /* protected by lr_lock */
279         __u32                 l_flags;
280
281         struct lustre_handle  l_remote_handle;
282         ldlm_policy_data_t    l_policy_data;
283
284         /* protected by lr_lock */
285         __u32                 l_readers;
286         __u32                 l_writers;
287         __u8                  l_destroyed;
288
289         /* If the lock is granted, a process sleeps on this waitq to learn when
290          * it's no longer in use.  If the lock is not granted, a process sleeps
291          * on this waitq to learn when it becomes granted. */
292         wait_queue_head_t     l_waitq;
293         struct timeval        l_enqueued_time;
294
295         unsigned long         l_last_used;      /* jiffies */
296         struct ldlm_extent    l_req_extent;
297
298         /* Client-side-only members */
299         __u32                 l_lvb_len;        /* temporary storage for */
300         void                 *l_lvb_data;       /* an LVB received during */
301         void                 *l_lvb_swabber;    /* an enqueue */
302         void                 *l_ast_data;
303
304         /* Server-side-only members */
305
306         /* protected by elt_lock */
307         struct list_head      l_pending_chain;  /* callbacks pending */
308         unsigned long         l_callback_timeout;
309
310         __u32                 l_pid;            /* pid which created this lock */
311         __u32                 l_pidb;           /* who holds LOCK_PROTECT_BIT */
312
313         struct list_head      l_tmp;
314
315         /* for ldlm_add_ast_work_item() */
316         struct list_head      l_bl_ast;
317         struct list_head      l_cp_ast;
318         struct ldlm_lock     *l_blocking_lock; 
319         int                   l_bl_ast_run;
320 };
321
322 #define LDLM_PLAIN       10
323 #define LDLM_EXTENT      11
324 #define LDLM_FLOCK       12
325 #define LDLM_IBITS       13
326
327 #define LDLM_MIN_TYPE 10
328 #define LDLM_MAX_TYPE 14
329
330 struct ldlm_resource {
331         struct ldlm_namespace *lr_namespace;
332
333         /* protected by ns_hash_lock */
334         struct list_head       lr_hash;
335         struct ldlm_resource  *lr_parent;   /* 0 for a root resource */
336         struct list_head       lr_children; /* list head for child resources */
337         struct list_head       lr_childof;  /* part of ns_root_list if root res,
338                                              * part of lr_children if child */
339         spinlock_t             lr_lock;
340
341         /* protected by lr_lock */
342         struct list_head       lr_granted;
343         struct list_head       lr_converting;
344         struct list_head       lr_waiting;
345         ldlm_mode_t            lr_most_restr;
346         __u32                  lr_type; /* LDLM_PLAIN or LDLM_EXTENT */
347         struct ldlm_res_id     lr_name;
348         atomic_t               lr_refcount;
349
350         /* Server-side-only lock value block elements */
351         struct semaphore       lr_lvb_sem;
352         __u32                  lr_lvb_len;
353         void                  *lr_lvb_data;
354
355         /* lr_tmp holds a list head temporarily, during the building of a work
356          * queue.  see ldlm_add_ast_work_item and ldlm_run_ast_work */
357         void                  *lr_tmp;
358 };
359
360 struct ldlm_ast_work {
361         struct ldlm_lock *w_lock;
362         int               w_blocking;
363         struct ldlm_lock_desc w_desc;
364         struct list_head   w_list;
365         int w_flags;
366         void *w_data;
367         int w_datalen;
368 };
369
370 extern struct obd_ops ldlm_obd_ops;
371
372 extern char *ldlm_lockname[];
373 extern char *ldlm_typename[];
374 extern char *ldlm_it2str(int it);
375
376 #define __LDLM_DEBUG(level, lock, format, a...)                               \
377 do {                                                                          \
378         if (lock->l_resource == NULL) {                                       \
379                 CDEBUG(level, "### " format                                   \
380                        " ns: \?\? lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "\
381                        "res: \?\? rrc=\?\? type: \?\?\? flags: %x remote: "   \
382                        LPX64" expref: %d pid: %u\n" , ## a, lock,             \
383                        lock->l_handle.h_cookie, atomic_read(&lock->l_refc),   \
384                        lock->l_readers, lock->l_writers,                      \
385                        ldlm_lockname[lock->l_granted_mode],                   \
386                        ldlm_lockname[lock->l_req_mode],                       \
387                        lock->l_flags, lock->l_remote_handle.cookie,           \
388                        lock->l_export ?                                       \
389                        atomic_read(&lock->l_export->exp_refcount) : -99,      \
390                        lock->l_pid);                                          \
391                 break;                                                        \
392         }                                                                     \
393         if (lock->l_resource->lr_type == LDLM_EXTENT) {                       \
394                 CDEBUG(level, "### " format                                   \
395                        " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "  \
396                        "res: "LPU64"/"LPU64"/"LPU64" rrc: %d type: %s ["LPU64 \
397                        "->"LPU64"] (req "LPU64"->"LPU64") flags: %x remote: " \
398                        LPX64" expref: %d pid: %u\n" , ## a,                   \
399                        lock->l_resource->lr_namespace->ns_name, lock,         \
400                        lock->l_handle.h_cookie, atomic_read(&lock->l_refc),   \
401                        lock->l_readers, lock->l_writers,                      \
402                        ldlm_lockname[lock->l_granted_mode],                   \
403                        ldlm_lockname[lock->l_req_mode],                       \
404                        lock->l_resource->lr_name.name[0],                     \
405                        lock->l_resource->lr_name.name[1],                     \
406                        lock->l_resource->lr_name.name[2],                     \
407                        atomic_read(&lock->l_resource->lr_refcount),           \
408                        ldlm_typename[lock->l_resource->lr_type],              \
409                        lock->l_policy_data.l_extent.start,                    \
410                        lock->l_policy_data.l_extent.end,                      \
411                        lock->l_req_extent.start, lock->l_req_extent.end,      \
412                        lock->l_flags, lock->l_remote_handle.cookie,           \
413                        lock->l_export ?                                       \
414                        atomic_read(&lock->l_export->exp_refcount) : -99,      \
415                        lock->l_pid);                                          \
416                 break;                                                        \
417         }                                                                     \
418         if (lock->l_resource->lr_type == LDLM_FLOCK) {                        \
419                 CDEBUG(level, "### " format                                   \
420                        " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "  \
421                        "res: "LPU64"/"LPU64"/"LPU64" rrc: %d type: %s pid: "  \
422                        LPU64" " "["LPU64"->"LPU64"] flags: %x remote: "LPX64  \
423                        " expref: %d pid: %u\n" , ## a,                        \
424                        lock->l_resource->lr_namespace->ns_name, lock,         \
425                        lock->l_handle.h_cookie, atomic_read(&lock->l_refc),   \
426                        lock->l_readers, lock->l_writers,                      \
427                        ldlm_lockname[lock->l_granted_mode],                   \
428                        ldlm_lockname[lock->l_req_mode],                       \
429                        lock->l_resource->lr_name.name[0],                     \
430                        lock->l_resource->lr_name.name[1],                     \
431                        lock->l_resource->lr_name.name[2],                     \
432                        atomic_read(&lock->l_resource->lr_refcount),           \
433                        ldlm_typename[lock->l_resource->lr_type],              \
434                        lock->l_policy_data.l_flock.pid,                       \
435                        lock->l_policy_data.l_flock.start,                     \
436                        lock->l_policy_data.l_flock.end,                       \
437                        lock->l_flags, lock->l_remote_handle.cookie,           \
438                        lock->l_export ?                                       \
439                        atomic_read(&lock->l_export->exp_refcount) : -99,      \
440                        lock->l_pid);                                          \
441                 break;                                                        \
442         }                                                                     \
443         if (lock->l_resource->lr_type == LDLM_IBITS) {                        \
444                 CDEBUG(level, "### " format                                   \
445                        " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "  \
446                        "res: "LPU64"/"LPU64"/"LPU64" bits "LPX64" rrc: %d "   \
447                        "type: %s flags: %x remote: "LPX64" expref: %d "       \
448                        "pid %u\n" , ## a,                                     \
449                        lock->l_resource->lr_namespace->ns_name,               \
450                        lock, lock->l_handle.h_cookie,                         \
451                        atomic_read (&lock->l_refc),                           \
452                        lock->l_readers, lock->l_writers,                      \
453                        ldlm_lockname[lock->l_granted_mode],                   \
454                        ldlm_lockname[lock->l_req_mode],                       \
455                        lock->l_resource->lr_name.name[0],                     \
456                        lock->l_resource->lr_name.name[1],                     \
457                        lock->l_resource->lr_name.name[2],                     \
458                        lock->l_policy_data.l_inodebits.bits,                  \
459                        atomic_read(&lock->l_resource->lr_refcount),           \
460                        ldlm_typename[lock->l_resource->lr_type],              \
461                        lock->l_flags, lock->l_remote_handle.cookie,           \
462                        lock->l_export ?                                       \
463                        atomic_read(&lock->l_export->exp_refcount) : -99,      \
464                        lock->l_pid);                                          \
465                 break;                                                        \
466         }                                                                     \
467         {                                                                     \
468                 CDEBUG(level, "### " format                                   \
469                        " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "  \
470                        "res: "LPU64"/"LPU64"/"LPU64"/"LPU64" rrc: %d type: %s " \
471                        "flags: %x remote: "LPX64" expref: %d "                \
472                        "pid: %u\n" , ## a,                                    \
473                        lock->l_resource->lr_namespace->ns_name,               \
474                        lock, lock->l_handle.h_cookie,                         \
475                        atomic_read (&lock->l_refc),                           \
476                        lock->l_readers, lock->l_writers,                      \
477                        ldlm_lockname[lock->l_granted_mode],                   \
478                        ldlm_lockname[lock->l_req_mode],                       \
479                        lock->l_resource->lr_name.name[0],                     \
480                        lock->l_resource->lr_name.name[1],                     \
481                        lock->l_resource->lr_name.name[2],                     \
482                        lock->l_resource->lr_name.name[3],                     \
483                        atomic_read(&lock->l_resource->lr_refcount),           \
484                        ldlm_typename[lock->l_resource->lr_type],              \
485                        lock->l_flags, lock->l_remote_handle.cookie,           \
486                        lock->l_export ?                                       \
487                        atomic_read(&lock->l_export->exp_refcount) : -99,      \
488                        lock->l_pid);                                          \
489         }                                                                     \
490 } while (0)
491
492 #define LDLM_DEBUG(lock, format, a...) __LDLM_DEBUG(D_DLMTRACE, lock, \
493                                                     format, ## a)
494 #define LDLM_ERROR(lock, format, a...) __LDLM_DEBUG(D_ERROR, lock, format, ## a)
495
496 #define LDLM_DEBUG_NOLOCK(format, a...)                 \
497         CDEBUG(D_DLMTRACE, "### " format "\n" , ## a)
498
499 typedef int (*ldlm_processing_policy)(struct ldlm_lock *lock, int *flags,
500                                       int first_enq, ldlm_error_t *err,
501                                       struct list_head *work_list);
502
503 /*
504  * Iterators.
505  */
506
507 #define LDLM_ITER_CONTINUE 1 /* keep iterating */
508 #define LDLM_ITER_STOP     2 /* stop iterating */
509
510 typedef int (*ldlm_iterator_t)(struct ldlm_lock *, void *);
511 typedef int (*ldlm_res_iterator_t)(struct ldlm_resource *, void *);
512
513 int ldlm_resource_foreach(struct ldlm_resource *res, ldlm_iterator_t iter,
514                           void *closure);
515 int ldlm_namespace_foreach(struct ldlm_namespace *ns, ldlm_iterator_t iter,
516                            void *closure);
517 int ldlm_namespace_foreach_res(struct ldlm_namespace *ns,
518                                ldlm_res_iterator_t iter, void *closure);
519
520 int ldlm_replay_locks(struct obd_import *imp);
521 void ldlm_change_cbdata(struct ldlm_namespace *, struct ldlm_res_id *,
522                         ldlm_iterator_t iter, void *data);
523
524 /* ldlm_flock.c */
525 int ldlm_flock_completion_ast(struct ldlm_lock *lock, int flags, void *data);
526
527 /* ldlm_extent.c */
528 __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms);
529
530
531 /* ldlm_lockd.c */
532 int ldlm_server_blocking_ast(struct ldlm_lock *, struct ldlm_lock_desc *,
533                              void *data, int flag);
534 int ldlm_server_completion_ast(struct ldlm_lock *lock, int flags, void *data);
535 int ldlm_server_glimpse_ast(struct ldlm_lock *lock, void *data);
536 int ldlm_handle_enqueue(struct ptlrpc_request *req, ldlm_completion_callback,
537                         ldlm_blocking_callback, ldlm_glimpse_callback);
538 int ldlm_handle_convert(struct ptlrpc_request *req);
539 int ldlm_handle_cancel(struct ptlrpc_request *req);
540 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
541 int ldlm_get_ref(void);
542 void ldlm_put_ref(int force);
543
544 /* ldlm_lock.c */
545 ldlm_processing_policy ldlm_get_processing_policy(struct ldlm_resource *res);
546 void ldlm_register_intent(struct ldlm_namespace *ns, ldlm_res_policy arg);
547 void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh);
548 struct ldlm_lock *__ldlm_handle2lock(struct lustre_handle *, int flags);
549 void ldlm_cancel_callback(struct ldlm_lock *);
550 int ldlm_lock_set_data(struct lustre_handle *, void *data);
551 void ldlm_lock_remove_from_lru(struct ldlm_lock *);
552 struct ldlm_lock *ldlm_handle2lock_ns(struct ldlm_namespace *,
553                                       struct lustre_handle *);
554
555 static inline struct ldlm_lock *ldlm_handle2lock(struct lustre_handle *h)
556 {
557         return __ldlm_handle2lock(h, 0);
558 }
559
560 #define LDLM_LOCK_PUT(lock)                     \
561 do {                                            \
562         /*LDLM_DEBUG((lock), "put");*/          \
563         ldlm_lock_put(lock);                    \
564 } while (0)
565
566 #define LDLM_LOCK_GET(lock)                     \
567 ({                                              \
568         ldlm_lock_get(lock);                    \
569         /*LDLM_DEBUG((lock), "get");*/          \
570         lock;                                   \
571 })
572
573 struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
574 void ldlm_lock_put(struct ldlm_lock *lock);
575 void ldlm_lock_destroy(struct ldlm_lock *lock);
576 void ldlm_lock2desc(struct ldlm_lock *lock, struct ldlm_lock_desc *desc);
577 void ldlm_lock_addref(struct lustre_handle *lockh, __u32 mode);
578 void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode);
579 void ldlm_lock_decref_and_cancel(struct lustre_handle *lockh, __u32 mode);
580 void ldlm_lock_allow_match(struct ldlm_lock *lock);
581 int ldlm_lock_match(struct ldlm_namespace *ns, int flags, struct ldlm_res_id *,
582                     __u32 type, ldlm_policy_data_t *, ldlm_mode_t mode,
583                     struct lustre_handle *);
584 struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
585                                         int *flags);
586 void ldlm_lock_cancel(struct ldlm_lock *lock);
587 void ldlm_cancel_locks_for_export(struct obd_export *export);
588 void ldlm_reprocess_all(struct ldlm_resource *res);
589 void ldlm_reprocess_all_ns(struct ldlm_namespace *ns);
590 void ldlm_lock_dump(int level, struct ldlm_lock *lock, int pos);
591 void ldlm_lock_dump_handle(int level, struct lustre_handle *);
592
593 /* ldlm_test.c */
594 int ldlm_test(struct obd_device *device, struct lustre_handle *connh);
595 int ldlm_regression_start(struct obd_device *obddev,
596                           struct lustre_handle *connh,
597                           unsigned int threads, unsigned int max_locks_in,
598                           unsigned int num_resources_in,
599                           unsigned int num_extents_in);
600 int ldlm_regression_stop(void);
601
602
603 /* resource.c */
604 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 local);
605 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags);
606 int ldlm_namespace_free(struct ldlm_namespace *ns, int force);
607 int ldlm_proc_setup(void);
608 void ldlm_proc_cleanup(void);
609
610 /* resource.c - internal */
611 struct ldlm_resource *ldlm_resource_get(struct ldlm_namespace *ns,
612                                         struct ldlm_resource *parent,
613                                         struct ldlm_res_id, __u32 type,
614                                         int create);
615 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res);
616 int ldlm_resource_putref(struct ldlm_resource *res);
617 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
618                             struct ldlm_lock *lock);
619 void ldlm_resource_unlink_lock(struct ldlm_lock *lock);
620 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc);
621 void ldlm_dump_all_namespaces(int level);
622 void ldlm_namespace_dump(int level, struct ldlm_namespace *);
623 void ldlm_resource_dump(int level, struct ldlm_resource *);
624 int ldlm_lock_change_resource(struct ldlm_namespace *, struct ldlm_lock *,
625                               struct ldlm_res_id);
626
627 /* ldlm_request.c */
628 int ldlm_expired_completion_wait(void *data);
629 int ldlm_completion_ast(struct ldlm_lock *lock, int flags, void *data);
630 int ldlm_cli_enqueue(struct obd_export *exp,
631                      struct ptlrpc_request *req,
632                      struct ldlm_namespace *ns,
633                      struct ldlm_res_id,
634                      __u32 type,
635                      ldlm_policy_data_t *,
636                      ldlm_mode_t mode,
637                      int *flags,
638                      ldlm_blocking_callback blocking,
639                      ldlm_completion_callback completion,
640                      ldlm_glimpse_callback glimpse,
641                      void *data,
642                      void *lvb,
643                      __u32 lvb_len,
644                      void *lvb_swabber,
645                      struct lustre_handle *lockh);
646 int ldlm_server_ast(struct lustre_handle *lockh, struct ldlm_lock_desc *new,
647                     void *data, __u32 data_len);
648 int ldlm_cli_convert(struct lustre_handle *, int new_mode, int *flags);
649 int ldlm_cli_cancel(struct lustre_handle *lockh);
650 int ldlm_cli_cancel_unused(struct ldlm_namespace *, struct ldlm_res_id *,
651                            int flags, void *opaque);
652
653 /* mds/handler.c */
654 /* This has to be here because recursive inclusion sucks. */
655 int intent_disposition(struct ldlm_reply *rep, int flag);
656 void intent_set_disposition(struct ldlm_reply *rep, int flag);
657 int mds_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
658                      void *data, int flag);
659
660
661 /* ioctls for trying requests */
662 #define IOC_LDLM_TYPE                   'f'
663 #define IOC_LDLM_MIN_NR                 40
664
665 #define IOC_LDLM_TEST                   _IOWR('f', 40, long)
666 #define IOC_LDLM_DUMP                   _IOWR('f', 41, long)
667 #define IOC_LDLM_REGRESS_START          _IOWR('f', 42, long)
668 #define IOC_LDLM_REGRESS_STOP           _IOWR('f', 43, long)
669 #define IOC_LDLM_MAX_NR                 43
670
671 static inline void lock_res(struct ldlm_resource *res)
672 {
673         spin_lock(&res->lr_lock);
674 }
675
676 static inline void unlock_res(struct ldlm_resource *res)
677 {
678         spin_unlock(&res->lr_lock);
679 }
680
681 static inline void check_res_locked(struct ldlm_resource *res)
682 {
683         LASSERT_SPIN_LOCKED(&res->lr_lock);
684 }
685
686 struct ldlm_resource * lock_res_and_lock(struct ldlm_lock *lock);
687 void unlock_res_and_lock(struct ldlm_lock *lock);
688
689 #endif