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