Whamcloud - gitweb
- CROW (CReate On Write) (precreation is removed)
[fs/lustre-release.git] / lustre / ldlm / ldlm_lock.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
5  *   Author: Peter Braam <braam@clusterfs.com>
6  *   Author: Phil Schwan <phil@clusterfs.com>
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #define DEBUG_SUBSYSTEM S_LDLM
25
26 #ifdef __KERNEL__
27 # include <linux/slab.h>
28 # include <linux/dcache.h>
29 # include <linux/namei.h>
30 # include <linux/module.h>
31 # include <linux/lustre_dlm.h>
32 #else
33 # include <liblustre.h>
34 # include <libcfs/kp30.h>
35 #endif
36
37 #include <linux/obd_class.h>
38 #include "ldlm_internal.h"
39
40 //struct lustre_lock ldlm_everything_lock;
41
42 /* lock types */
43 char *ldlm_lockname[] = {
44         [0] "--",
45         [LCK_EX] "EX",
46         [LCK_PW] "PW",
47         [LCK_PR] "PR",
48         [LCK_CW] "CW",
49         [LCK_CR] "CR",
50         [LCK_NL] "NL",
51         [LCK_GROUP] "GROUP"
52 };
53 char *ldlm_typename[] = {
54         [LDLM_PLAIN] "PLN",
55         [LDLM_EXTENT] "EXT",
56         [LDLM_FLOCK] "FLK",
57         [LDLM_IBITS] "IBT",
58 };
59
60 char *ldlm_it2str(int it)
61 {
62         switch (it) {
63         case IT_OPEN:
64                 return "open";
65         case IT_CREAT:
66                 return "creat";
67         case (IT_OPEN | IT_CREAT):
68                 return "open|creat";
69         case IT_READDIR:
70                 return "readdir";
71         case IT_GETATTR:
72                 return "getattr";
73         case IT_LOOKUP:
74                 return "lookup";
75         case IT_UNLINK:
76                 return "unlink";
77         case IT_GETXATTR:
78                 return "getxattr";
79         case IT_CHDIR:
80                 return "chdir";
81         default:
82                 CERROR("Unknown intent %d\n", it);
83                 return "UNKNOWN";
84         }
85 }
86
87 extern kmem_cache_t *ldlm_lock_slab;
88 struct lustre_lock ldlm_handle_lock;
89
90 static ldlm_processing_policy ldlm_processing_policy_table[] = {
91         [LDLM_PLAIN] ldlm_process_plain_lock,
92         [LDLM_EXTENT] ldlm_process_extent_lock,
93 #ifdef __KERNEL__
94         [LDLM_FLOCK] ldlm_process_flock_lock,
95 #endif
96         [LDLM_IBITS] ldlm_process_inodebits_lock,
97 };
98
99 ldlm_processing_policy ldlm_get_processing_policy(struct ldlm_resource *res)
100 {
101         return ldlm_processing_policy_table[res->lr_type];
102 }
103
104 void ldlm_register_intent(struct ldlm_namespace *ns, ldlm_res_policy arg)
105 {
106         ns->ns_policy = arg;
107 }
108
109 /*
110  * REFCOUNTED LOCK OBJECTS
111  */
112
113
114 /*
115  * Lock refcounts, during creation:
116  *   - one special one for allocation, dec'd only once in destroy
117  *   - one for being a lock that's in-use
118  *   - one for the addref associated with a new lock
119  */
120 struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock)
121 {
122         atomic_inc(&lock->l_refc);
123         return lock;
124 }
125
126 void ldlm_lock_put(struct ldlm_lock *lock)
127 {
128         ENTRY;
129
130         if (atomic_dec_and_test(&lock->l_refc)) {
131                 struct ldlm_namespace *ns = lock->l_resource->lr_namespace;
132
133                 l_lock(&ns->ns_lock);
134                 LDLM_DEBUG(lock, "final lock_put on destroyed lock, freeing");
135                 LASSERT(lock->l_destroyed);
136                 LASSERT(list_empty(&lock->l_res_link));
137
138                 spin_lock(&ns->ns_counter_lock);
139                 ns->ns_locks--;
140                 spin_unlock(&ns->ns_counter_lock);
141
142                 ldlm_resource_putref(lock->l_resource);
143                 lock->l_resource = NULL;
144                 if (lock->l_export)
145                         class_export_put(lock->l_export);
146
147                 if (lock->l_parent)
148                         LDLM_LOCK_PUT(lock->l_parent);
149
150                 if (lock->l_lvb_data != NULL)
151                         OBD_FREE(lock->l_lvb_data, lock->l_lvb_len);
152
153                 OBD_SLAB_FREE(lock, ldlm_lock_slab, sizeof(*lock));
154                 l_unlock(&ns->ns_lock);
155         }
156
157         EXIT;
158 }
159
160 void ldlm_lock_remove_from_lru(struct ldlm_lock *lock)
161 {
162         ENTRY;
163         l_lock(&lock->l_resource->lr_namespace->ns_lock);
164         if (!list_empty(&lock->l_lru)) {
165                 LASSERT(lock->l_resource->lr_type != LDLM_FLOCK);
166                 list_del_init(&lock->l_lru);
167                 lock->l_resource->lr_namespace->ns_nr_unused--;
168                 LASSERT(lock->l_resource->lr_namespace->ns_nr_unused >= 0);
169         }
170         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
171         EXIT;
172 }
173
174 /* This used to have a 'strict' flact, which recovery would use to mark an
175  * in-use lock as needing-to-die.  Lest I am ever tempted to put it back, I
176  * shall explain why it's gone: with the new hash table scheme, once you call
177  * ldlm_lock_destroy, you can never drop your final references on this lock.
178  * Because it's not in the hash table anymore.  -phil */
179 void ldlm_lock_destroy(struct ldlm_lock *lock)
180 {
181         ENTRY;
182         l_lock(&lock->l_resource->lr_namespace->ns_lock);
183
184         if (!list_empty(&lock->l_children)) {
185                 LDLM_ERROR(lock, "still has children (%p)!",
186                            lock->l_children.next);
187                 ldlm_lock_dump(D_ERROR, lock, 0);
188                 LBUG();
189         }
190         if (lock->l_readers || lock->l_writers) {
191                 LDLM_ERROR(lock, "lock still has references");
192                 ldlm_lock_dump(D_ERROR, lock, 0);
193                 LBUG();
194         }
195
196         if (!list_empty(&lock->l_res_link)) {
197                 LDLM_ERROR(lock, "lock still on resource");
198                 ldlm_lock_dump(D_ERROR, lock, 0);
199                 LBUG();
200         }
201
202         if (lock->l_destroyed) {
203                 LASSERT(list_empty(&lock->l_lru));
204                 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
205                 EXIT;
206                 return;
207         }
208         lock->l_destroyed = 1;
209
210         list_del_init(&lock->l_export_chain);
211         ldlm_lock_remove_from_lru(lock);
212         class_handle_unhash(&lock->l_handle);
213
214 #if 0
215         /* Wake anyone waiting for this lock */
216         /* FIXME: I should probably add yet another flag, instead of using
217          * l_export to only call this on clients */
218         if (lock->l_export)
219                 class_export_put(lock->l_export);
220         lock->l_export = NULL;
221         if (lock->l_export && lock->l_completion_ast)
222                 lock->l_completion_ast(lock, 0);
223 #endif
224
225         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
226         LDLM_LOCK_PUT(lock);
227         EXIT;
228 }
229
230 /* this is called by portals_handle2object with the handle lock taken */
231 static void lock_handle_addref(void *lock)
232 {
233         LDLM_LOCK_GET((struct ldlm_lock *)lock);
234 }
235
236 /*
237  * usage: pass in a resource on which you have done ldlm_resource_get
238  *        pass in a parent lock on which you have done a ldlm_lock_get
239  *        after return, ldlm_*_put the resource and parent
240  * returns: lock with refcount 2 - one for current caller and one for remote
241  */
242 static struct ldlm_lock *ldlm_lock_new(struct ldlm_lock *parent,
243                                        struct ldlm_resource *resource)
244 {
245         struct ldlm_lock *lock;
246         ENTRY;
247
248         if (resource == NULL)
249                 LBUG();
250
251         OBD_SLAB_ALLOC(lock, ldlm_lock_slab, SLAB_NOFS, sizeof(*lock));
252         if (lock == NULL)
253                 RETURN(NULL);
254
255         lock->l_resource = ldlm_resource_getref(resource);
256
257         atomic_set(&lock->l_refc, 2);
258         INIT_LIST_HEAD(&lock->l_children);
259         INIT_LIST_HEAD(&lock->l_res_link);
260         INIT_LIST_HEAD(&lock->l_lru);
261         INIT_LIST_HEAD(&lock->l_export_chain);
262         INIT_LIST_HEAD(&lock->l_pending_chain);
263         INIT_LIST_HEAD(&lock->l_tmp);
264         init_waitqueue_head(&lock->l_waitq);
265
266         spin_lock(&resource->lr_namespace->ns_counter_lock);
267         resource->lr_namespace->ns_locks++;
268         spin_unlock(&resource->lr_namespace->ns_counter_lock);
269
270         if (parent != NULL) {
271                 l_lock(&parent->l_resource->lr_namespace->ns_lock);
272                 lock->l_parent = LDLM_LOCK_GET(parent);
273                 list_add(&lock->l_childof, &parent->l_children);
274                 l_unlock(&parent->l_resource->lr_namespace->ns_lock);
275         }
276
277         INIT_LIST_HEAD(&lock->l_handle.h_link);
278         class_handle_hash(&lock->l_handle, lock_handle_addref);
279
280         RETURN(lock);
281 }
282
283 int ldlm_lock_change_resource(struct ldlm_namespace *ns, struct ldlm_lock *lock,
284                               struct ldlm_res_id new_resid)
285 {
286         struct ldlm_resource *oldres = lock->l_resource;
287         ENTRY;
288
289         l_lock(&ns->ns_lock);
290         if (memcmp(&new_resid, &lock->l_resource->lr_name,
291                    sizeof(lock->l_resource->lr_name)) == 0) {
292                 /* Nothing to do */
293                 l_unlock(&ns->ns_lock);
294                 RETURN(0);
295         }
296
297         LASSERT(new_resid.name[0] != 0);
298
299         /* This function assumes that the lock isn't on any lists */
300         LASSERT(list_empty(&lock->l_res_link));
301
302         lock->l_resource = ldlm_resource_get(ns, NULL, new_resid,
303                                              lock->l_resource->lr_type, 
304                                              1);
305         if (lock->l_resource == NULL) {
306                 LBUG();
307                 RETURN(-ENOMEM);
308         }
309
310         /* ...and the flowers are still standing! */
311         ldlm_resource_putref(oldres);
312
313         l_unlock(&ns->ns_lock);
314         RETURN(0);
315 }
316
317 /*
318  *  HANDLES
319  */
320
321 void ldlm_lock2handle(struct ldlm_lock *lock, struct lustre_handle *lockh)
322 {
323         lockh->cookie = lock->l_handle.h_cookie;
324 }
325
326 /* if flags: atomically get the lock and set the flags.
327  *           Return NULL if flag already set
328  */
329
330 struct ldlm_lock *__ldlm_handle2lock(struct lustre_handle *handle, int flags)
331 {
332         struct ldlm_namespace *ns;
333         struct ldlm_lock *lock = NULL, *retval = NULL;
334         ENTRY;
335
336         LASSERT(handle);
337
338         lock = class_handle2object(handle->cookie);
339         if (lock == NULL)
340                 RETURN(NULL);
341
342         LASSERT(lock->l_resource != NULL);
343         ns = lock->l_resource->lr_namespace;
344         LASSERT(ns != NULL);
345
346         l_lock(&ns->ns_lock);
347
348         /* It's unlikely but possible that someone marked the lock as
349          * destroyed after we did handle2object on it */
350         if (lock->l_destroyed) {
351                 CDEBUG(D_INFO, "lock already destroyed: lock %p\n", lock);
352                 LDLM_LOCK_PUT(lock);
353                 GOTO(out, retval);
354         }
355
356         if (flags && (lock->l_flags & flags)) {
357                 LDLM_LOCK_PUT(lock);
358                 GOTO(out, retval);
359         }
360
361         if (flags)
362                 lock->l_flags |= flags;
363
364         retval = lock;
365         EXIT;
366  out:
367         l_unlock(&ns->ns_lock);
368         return retval;
369 }
370
371 struct ldlm_lock *ldlm_handle2lock_ns(struct ldlm_namespace *ns,
372                                       struct lustre_handle *handle)
373 {
374         struct ldlm_lock *retval = NULL;
375
376         l_lock(&ns->ns_lock);
377         retval = __ldlm_handle2lock(handle, 0);
378         l_unlock(&ns->ns_lock);
379
380         return retval;
381 }
382
383 void ldlm_lock2desc(struct ldlm_lock *lock, struct ldlm_lock_desc *desc)
384 {
385         ldlm_res2desc(lock->l_resource, &desc->l_resource);
386         desc->l_req_mode = lock->l_req_mode;
387         desc->l_granted_mode = lock->l_granted_mode;
388         memcpy(&desc->l_policy_data, &lock->l_policy_data,
389                sizeof(desc->l_policy_data));
390 }
391
392 void ldlm_add_ast_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
393                             void *data, int datalen)
394 {
395         struct ldlm_ast_work *w;
396         ENTRY;
397
398         l_lock(&lock->l_resource->lr_namespace->ns_lock);
399         if (new && (lock->l_flags & LDLM_FL_AST_SENT))
400                 GOTO(out, 0);
401
402         CDEBUG(D_OTHER, "lock %p incompatible; sending blocking AST.\n", lock);
403
404         OBD_ALLOC(w, sizeof(*w));
405         if (!w) {
406                 LBUG();
407                 GOTO(out, 0);
408         }
409
410         w->w_data = data;
411         w->w_datalen = datalen;
412         if (new) {
413                 LDLM_DEBUG(lock, "lock incompatible; sending blocking AST.");
414                 lock->l_flags |= LDLM_FL_AST_SENT;
415                 /* If the enqueuing client said so, tell the AST recipient to
416                  * discard dirty data, rather than writing back. */
417                 if (new->l_flags & LDLM_AST_DISCARD_DATA)
418                         lock->l_flags |= LDLM_FL_DISCARD_DATA;
419                 w->w_blocking = 1;
420                 ldlm_lock2desc(new, &w->w_desc);
421         }
422
423         w->w_lock = LDLM_LOCK_GET(lock);
424         list_add(&w->w_list, lock->l_resource->lr_tmp);
425         EXIT;
426  out:
427         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
428 }
429
430 void ldlm_lock_addref(struct lustre_handle *lockh, __u32 mode)
431 {
432         struct ldlm_lock *lock;
433
434         lock = ldlm_handle2lock(lockh);
435         ldlm_lock_addref_internal(lock, mode);
436         LDLM_LOCK_PUT(lock);
437 }
438
439 /* only called for local locks */
440 void ldlm_lock_addref_internal(struct ldlm_lock *lock, __u32 mode)
441 {
442         l_lock(&lock->l_resource->lr_namespace->ns_lock);
443         ldlm_lock_remove_from_lru(lock);
444         if (mode & (LCK_NL | LCK_CR | LCK_PR))
445                 lock->l_readers++;
446         if (mode & (LCK_EX | LCK_CW | LCK_PW | LCK_GROUP))
447                 lock->l_writers++;
448         lock->l_last_used = jiffies;
449         LDLM_LOCK_GET(lock);
450         LDLM_DEBUG(lock, "ldlm_lock_addref(%s)", ldlm_lockname[mode]);
451         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
452 }
453
454 void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
455 {
456         struct ldlm_namespace *ns;
457         ENTRY;
458
459         ns = lock->l_resource->lr_namespace;
460
461         l_lock(&ns->ns_lock);
462         LDLM_DEBUG(lock, "ldlm_lock_decref(%s)", ldlm_lockname[mode]);
463         if (mode & (LCK_NL | LCK_CR | LCK_PR)) {
464                 LASSERT(lock->l_readers > 0);
465                 lock->l_readers--;
466         }
467         if (mode & (LCK_EX | LCK_CW | LCK_PW | LCK_GROUP)) {
468                 LASSERT(lock->l_writers > 0);
469                 lock->l_writers--;
470         }
471
472         if (lock->l_flags & LDLM_FL_LOCAL &&
473             !lock->l_readers && !lock->l_writers) {
474                 /* If this is a local lock on a server namespace and this was
475                  * the last reference, cancel the lock. */
476                 CDEBUG(D_INFO, "forcing cancel of local lock\n");
477                 lock->l_flags |= LDLM_FL_CBPENDING;
478         }
479
480         if (!lock->l_readers && !lock->l_writers &&
481             (lock->l_flags & LDLM_FL_CBPENDING)) {
482                 /* If we received a blocked AST and this was the last reference,
483                  * run the callback. */
484                 if (ns->ns_client == LDLM_NAMESPACE_SERVER && lock->l_export)
485                         CERROR("FL_CBPENDING set on non-local lock--just a "
486                                "warning\n");
487
488                 LDLM_DEBUG(lock, "final decref done on cbpending lock");
489
490                 LDLM_LOCK_GET(lock); /* dropped by bl thread */
491                 ldlm_lock_remove_from_lru(lock);
492                 l_unlock(&ns->ns_lock);
493                 if (ldlm_bl_to_thread(ns, NULL, lock) != 0)
494                         ldlm_handle_bl_callback(ns, NULL, lock);
495         } else if (ns->ns_client == LDLM_NAMESPACE_CLIENT &&
496                    !lock->l_readers && !lock->l_writers) {
497                 /* If this is a client-side namespace and this was the last
498                  * reference, put it on the LRU. */
499                 LASSERT(list_empty(&lock->l_lru));
500                 LASSERT(ns->ns_nr_unused >= 0);
501                 list_add_tail(&lock->l_lru, &ns->ns_unused_list);
502                 ns->ns_nr_unused++;
503                 l_unlock(&ns->ns_lock);
504                 ldlm_cancel_lru(ns, LDLM_ASYNC);
505         } else {
506                 l_unlock(&ns->ns_lock);
507         }
508
509         LDLM_LOCK_PUT(lock);    /* matches the ldlm_lock_get in addref */
510
511         EXIT;
512 }
513
514 void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode)
515 {
516         struct ldlm_lock *lock = __ldlm_handle2lock(lockh, 0);
517         LASSERT(lock != NULL);
518         ldlm_lock_decref_internal(lock, mode);
519         LDLM_LOCK_PUT(lock);
520 }
521
522 /* This will drop a lock reference and mark it for destruction, but will not
523  * necessarily cancel the lock before returning. */
524 void ldlm_lock_decref_and_cancel(struct lustre_handle *lockh, __u32 mode)
525 {
526         struct ldlm_lock *lock = __ldlm_handle2lock(lockh, 0);
527         ENTRY;
528
529         LASSERT(lock != NULL);
530
531         LDLM_DEBUG(lock, "ldlm_lock_decref(%s)", ldlm_lockname[mode]);
532         l_lock(&lock->l_resource->lr_namespace->ns_lock);
533         lock->l_flags |= LDLM_FL_CBPENDING;
534         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
535         ldlm_lock_decref_internal(lock, mode);
536         LDLM_LOCK_PUT(lock);
537 }
538
539 /* NOTE: called by
540  *  - ldlm_lock_enqueue
541  *  - ldlm_reprocess_queue
542  *  - ldlm_lock_convert
543  */
544 void ldlm_grant_lock(struct ldlm_lock *lock, void *data, int datalen,
545                      int run_ast)
546 {
547         struct ldlm_resource *res = lock->l_resource;
548         ENTRY;
549
550         l_lock(&lock->l_resource->lr_namespace->ns_lock);
551         lock->l_granted_mode = lock->l_req_mode;
552         ldlm_resource_add_lock(res, &res->lr_granted, lock);
553
554         if (lock->l_granted_mode < res->lr_most_restr)
555                 res->lr_most_restr = lock->l_granted_mode;
556
557         if (run_ast && lock->l_completion_ast != NULL)
558                 ldlm_add_ast_work_item(lock, NULL, data, datalen);
559
560         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
561         EXIT;
562 }
563
564 /* returns a referenced lock or NULL.  See the flag descriptions below, in the
565  * comment above ldlm_lock_match */
566 static struct ldlm_lock *search_queue(struct list_head *queue, ldlm_mode_t mode,
567                                       ldlm_policy_data_t *policy,
568                                       struct ldlm_lock *old_lock, int flags)
569 {
570         struct ldlm_lock *lock;
571         struct list_head *tmp;
572
573         list_for_each(tmp, queue) {
574                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
575
576                 if (lock == old_lock)
577                         break;
578
579                 /* llite sometimes wants to match locks that will be
580                  * canceled when their users drop, but we allow it to match
581                  * if it passes in CBPENDING and the lock still has users.
582                  * this is generally only going to be used by children 
583                  * whose parents already hold a lock so forward progress
584                  * can still happen. */
585                 if (lock->l_flags & LDLM_FL_CBPENDING &&
586                     !(flags & LDLM_FL_CBPENDING))
587                         continue;
588                 if (lock->l_flags & LDLM_FL_CBPENDING &&
589                     lock->l_readers == 0 && lock->l_writers == 0)
590                         continue;
591
592                 if (!(lock->l_req_mode & mode))
593                         continue;
594
595                 if (lock->l_resource->lr_type == LDLM_EXTENT &&
596                     (lock->l_policy_data.l_extent.start >
597                      policy->l_extent.start ||
598                      lock->l_policy_data.l_extent.end < policy->l_extent.end))
599                         continue;
600
601                 if (lock->l_resource->lr_type == LDLM_EXTENT &&
602                     mode == LCK_GROUP &&
603                     lock->l_policy_data.l_extent.gid != policy->l_extent.gid)
604                         continue;
605
606                 /* We match if we have existing lock with same or wider set
607                    of bits. */
608                 if (lock->l_resource->lr_type == LDLM_IBITS &&
609                      ((lock->l_policy_data.l_inodebits.bits &
610                       policy->l_inodebits.bits) !=
611                       policy->l_inodebits.bits))
612                         continue;
613
614                 if (lock->l_destroyed || (lock->l_flags & LDLM_FL_FAILED))
615                         continue;
616
617                 if ((flags & LDLM_FL_LOCAL_ONLY) &&
618                     !(lock->l_flags & LDLM_FL_LOCAL))
619                         continue;
620
621                 if (flags & LDLM_FL_TEST_LOCK)
622                         LDLM_LOCK_GET(lock);
623                 else
624                         ldlm_lock_addref_internal(lock, mode);
625                 return lock;
626         }
627
628         return NULL;
629 }
630
631 void ldlm_lock_allow_match(struct ldlm_lock *lock)
632 {
633         l_lock(&lock->l_resource->lr_namespace->ns_lock);
634         lock->l_flags |= LDLM_FL_CAN_MATCH;
635         wake_up(&lock->l_waitq);
636         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
637 }
638
639 /* Can be called in two ways:
640  *
641  * If 'ns' is NULL, then lockh describes an existing lock that we want to look
642  * for a duplicate of.
643  *
644  * Otherwise, all of the fields must be filled in, to match against.
645  *
646  * If 'flags' contains LDLM_FL_LOCAL_ONLY, then only match local locks on the
647  *     server (ie, connh is NULL)
648  * If 'flags' contains LDLM_FL_BLOCK_GRANTED, then only locks on the granted
649  *     list will be considered
650  * If 'flags' contains LDLM_FL_CBPENDING, then locks that have been marked
651  *     to be canceled can still be matched as long as they still have reader
652  *     or writer refernces
653  * If 'flags' contains LDLM_FL_TEST_LOCK, then don't actually reference a lock,
654  *     just tell us if we would have matched.
655  *
656  * Returns 1 if it finds an already-existing lock that is compatible; in this
657  * case, lockh is filled in with a addref()ed lock
658  */
659 int ldlm_lock_match(struct ldlm_namespace *ns, int flags,
660                     struct ldlm_res_id *res_id, __u32 type,
661                     ldlm_policy_data_t *policy, ldlm_mode_t mode,
662                     struct lustre_handle *lockh)
663 {
664         struct ldlm_resource *res;
665         struct ldlm_lock *lock, *old_lock = NULL;
666         int rc = 0;
667         ENTRY;
668
669         if (ns == NULL) {
670                 old_lock = ldlm_handle2lock(lockh);
671                 LASSERT(old_lock);
672
673                 ns = old_lock->l_resource->lr_namespace;
674                 res_id = &old_lock->l_resource->lr_name;
675                 type = old_lock->l_resource->lr_type;
676                 mode = old_lock->l_req_mode;
677         }
678
679         res = ldlm_resource_get(ns, NULL, *res_id, type, 0);
680         if (res == NULL) {
681                 LASSERT(old_lock == NULL);
682                 RETURN(0);
683         }
684
685         l_lock(&ns->ns_lock);
686
687         lock = search_queue(&res->lr_granted, mode, policy, old_lock, flags);
688         if (lock != NULL)
689                 GOTO(out, rc = 1);
690         if (flags & LDLM_FL_BLOCK_GRANTED)
691                 GOTO(out, rc = 0);
692         lock = search_queue(&res->lr_converting, mode, policy, old_lock, flags);
693         if (lock != NULL)
694                 GOTO(out, rc = 1);
695         lock = search_queue(&res->lr_waiting, mode, policy, old_lock, flags);
696         if (lock != NULL)
697                 GOTO(out, rc = 1);
698
699         EXIT;
700  out:
701         ldlm_resource_putref(res);
702         l_unlock(&ns->ns_lock);
703
704         if (lock) {
705                 ldlm_lock2handle(lock, lockh);
706                 if (!(lock->l_flags & LDLM_FL_CAN_MATCH)) {
707                         struct l_wait_info lwi;
708                         if (lock->l_completion_ast) {
709                                 int err = lock->l_completion_ast(lock,
710                                                                  LDLM_FL_WAIT_NOREPROC,
711                                                                  NULL);
712                                 if (err) {
713                                         rc = 0;
714                                         goto out2;
715                                 }
716                         }
717
718                         lwi = LWI_TIMEOUT_INTR(obd_timeout*HZ, NULL,NULL,NULL);
719
720                         /* XXX FIXME see comment on CAN_MATCH in lustre_dlm.h */
721                         l_wait_event(lock->l_waitq,
722                                      (lock->l_flags & LDLM_FL_CAN_MATCH), &lwi);
723                 }
724         }
725
726 out2:
727         if (rc) {
728                 l_lock(&ns->ns_lock);
729                 LDLM_DEBUG(lock, "matched ("LPU64" "LPU64")",
730                            type == LDLM_PLAIN ? res_id->name[2] :
731                                 policy->l_extent.start,
732                            type == LDLM_PLAIN ? res_id->name[3] :
733                            policy->l_extent.end);
734                 l_unlock(&ns->ns_lock);
735         } else if (!(flags & LDLM_FL_TEST_LOCK)) {/* less verbose for test-only */
736                 LDLM_DEBUG_NOLOCK("not matched ns %p type %u mode %u res "
737                                   LPU64"/"LPU64" ("LPU64" "LPU64")", ns,
738                                   type, mode, res_id->name[0], res_id->name[1],
739                                   type == LDLM_PLAIN ? res_id->name[2] :
740                                   policy->l_extent.start,
741                                   type == LDLM_PLAIN ? res_id->name[3] :
742                                   policy->l_extent.end);
743         }
744
745         if (old_lock)
746                 LDLM_LOCK_PUT(old_lock);
747         if (flags & LDLM_FL_TEST_LOCK && rc)
748                 LDLM_LOCK_PUT(lock);
749
750         return rc;
751 }
752
753 /* Returns a referenced lock */
754 struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
755                                    struct lustre_handle *parent_lock_handle,
756                                    struct ldlm_res_id res_id, __u32 type,
757                                    ldlm_mode_t mode,
758                                    ldlm_blocking_callback blocking,
759                                    ldlm_completion_callback completion,
760                                    ldlm_glimpse_callback glimpse,
761                                    void *data, __u32 lvb_len)
762 {
763         struct ldlm_resource *res, *parent_res = NULL;
764         struct ldlm_lock *lock, *parent_lock = NULL;
765         ENTRY;
766
767         if (parent_lock_handle) {
768                 parent_lock = ldlm_handle2lock(parent_lock_handle);
769                 if (parent_lock)
770                         parent_res = parent_lock->l_resource;
771         }
772
773         res = ldlm_resource_get(ns, parent_res, res_id,
774                                 type, 1);
775         if (res == NULL)
776                 RETURN(NULL);
777
778         lock = ldlm_lock_new(parent_lock, res);
779         ldlm_resource_putref(res);
780         if (parent_lock != NULL)
781                 LDLM_LOCK_PUT(parent_lock);
782
783         if (lock == NULL)
784                 RETURN(NULL);
785
786         lock->l_req_mode = mode;
787         lock->l_ast_data = data;
788         lock->l_blocking_ast = blocking;
789         lock->l_completion_ast = completion;
790         lock->l_glimpse_ast = glimpse;
791         lock->l_pid = current->pid;
792
793         if (lvb_len) {
794                 lock->l_lvb_len = lvb_len;
795                 OBD_ALLOC(lock->l_lvb_data, lvb_len);
796                 if (lock->l_lvb_data == NULL) {
797                         OBD_SLAB_FREE(lock, ldlm_lock_slab, sizeof(*lock));
798                         RETURN(NULL);
799                 }
800         }
801
802         RETURN(lock);
803 }
804
805 ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
806                                struct ldlm_lock **lockp,
807                                void *cookie, int *flags)
808 {
809         struct ldlm_lock *lock = *lockp;
810         struct ldlm_resource *res = lock->l_resource;
811         int local = res->lr_namespace->ns_client;
812         ldlm_processing_policy policy;
813         ldlm_error_t rc = ELDLM_OK;
814         ENTRY;
815
816         /* policies are not executed on the client or during replay */
817         if ((*flags & (LDLM_FL_HAS_INTENT|LDLM_FL_REPLAY)) == LDLM_FL_HAS_INTENT
818             && !local && ns->ns_policy) {
819                 rc = ns->ns_policy(ns, lockp, cookie, lock->l_req_mode, *flags,
820                                    NULL);
821                 if (rc == ELDLM_LOCK_REPLACED) {
822                         /* The lock that was returned has already been granted,
823                          * and placed into lockp.  If it's not the same as the
824                          * one we passed in, then destroy the old one and our
825                          * work here is done. */
826                         if (lock != *lockp) {
827                                 ldlm_lock_destroy(lock);
828                                 LDLM_LOCK_PUT(lock);
829                         }
830                         *flags |= LDLM_FL_LOCK_CHANGED;
831                         RETURN(0);
832                 } else if (rc == ELDLM_LOCK_ABORTED ||
833                            (rc == 0 && (*flags & LDLM_FL_INTENT_ONLY))) {
834                         ldlm_lock_destroy(lock);
835                         RETURN(rc);
836                 }
837                 LASSERT(rc == ELDLM_OK);
838         }
839
840         l_lock(&ns->ns_lock);
841         if (local && lock->l_req_mode == lock->l_granted_mode) {
842                 /* The server returned a blocked lock, but it was granted before
843                  * we got a chance to actually enqueue it.  We don't need to do
844                  * anything else. */
845                 *flags &= ~(LDLM_FL_BLOCK_GRANTED |
846                             LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_WAIT);
847                 GOTO(out, ELDLM_OK);
848         }
849
850         /* Some flags from the enqueue want to make it into the AST, via the
851          * lock's l_flags. */
852         lock->l_flags |= (*flags & LDLM_AST_DISCARD_DATA);
853
854         /* This distinction between local lock trees is very important; a client
855          * namespace only has information about locks taken by that client, and
856          * thus doesn't have enough information to decide for itself if it can
857          * be granted (below).  In this case, we do exactly what the server
858          * tells us to do, as dictated by the 'flags'.
859          *
860          * We do exactly the same thing during recovery, when the server is
861          * more or less trusting the clients not to lie.
862          *
863          * FIXME (bug 268): Detect obvious lies by checking compatibility in
864          * granted/converting queues. */
865         ldlm_resource_unlink_lock(lock);
866         if (local) {
867                 if (*flags & LDLM_FL_BLOCK_CONV)
868                         ldlm_resource_add_lock(res, &res->lr_converting, lock);
869                 else if (*flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED))
870                         ldlm_resource_add_lock(res, &res->lr_waiting, lock);
871                 else
872                         ldlm_grant_lock(lock, NULL, 0, 0);
873                 GOTO(out, ELDLM_OK);
874         } else if (*flags & LDLM_FL_REPLAY) {
875                 if (*flags & LDLM_FL_BLOCK_CONV) {
876                         ldlm_resource_add_lock(res, &res->lr_converting, lock);
877                         GOTO(out, ELDLM_OK);
878                 } else if (*flags & LDLM_FL_BLOCK_WAIT) {
879                         ldlm_resource_add_lock(res, &res->lr_waiting, lock);
880                         GOTO(out, ELDLM_OK);
881                 } else if (*flags & LDLM_FL_BLOCK_GRANTED) {
882                         ldlm_grant_lock(lock, NULL, 0, 0);
883                         GOTO(out, ELDLM_OK);
884                 }
885                 /* If no flags, fall through to normal enqueue path. */
886         }
887
888         policy = ldlm_processing_policy_table[res->lr_type];
889         policy(lock, flags, 1, &rc);
890         EXIT;
891 out:
892         l_unlock(&ns->ns_lock);
893         return rc;
894 }
895
896 /* Must be called with namespace taken: queue is waiting or converting. */
897 int ldlm_reprocess_queue(struct ldlm_resource *res, struct list_head *queue)
898 {
899         struct list_head *tmp, *pos;
900         ldlm_processing_policy policy;
901         int flags;
902         int rc = LDLM_ITER_CONTINUE;
903         ldlm_error_t err;
904         ENTRY;
905
906         policy = ldlm_processing_policy_table[res->lr_type];
907         LASSERT(policy);
908
909         list_for_each_safe(tmp, pos, queue) {
910                 struct ldlm_lock *pending;
911                 pending = list_entry(tmp, struct ldlm_lock, l_res_link);
912
913                 CDEBUG(D_INFO, "Reprocessing lock %p\n", pending);
914
915                 flags = 0;
916                 rc = policy(pending, &flags, 0, &err);
917                 if (rc != LDLM_ITER_CONTINUE)
918                         break;
919         }
920
921         RETURN(rc);
922 }
923
924 int ldlm_run_ast_work(struct ldlm_namespace *ns, struct list_head *rpc_list)
925 {
926         struct list_head *tmp, *pos;
927         int rc, retval = 0;
928         ENTRY;
929
930         l_check_no_ns_lock(ns);
931
932         list_for_each_safe(tmp, pos, rpc_list) {
933                 struct ldlm_ast_work *w =
934                         list_entry(tmp, struct ldlm_ast_work, w_list);
935
936                 /* It's possible to receive a completion AST before we've set
937                  * the l_completion_ast pointer: either because the AST arrived
938                  * before the reply, or simply because there's a small race
939                  * window between receiving the reply and finishing the local
940                  * enqueue. (bug 842)
941                  *
942                  * This can't happen with the blocking_ast, however, because we
943                  * will never call the local blocking_ast until we drop our
944                  * reader/writer reference, which we won't do until we get the
945                  * reply and finish enqueueing. */
946                 LASSERT(w->w_lock != NULL);
947                 if (w->w_blocking) {
948                         LASSERT(w->w_lock->l_blocking_ast != NULL);
949                         rc = w->w_lock->l_blocking_ast
950                                 (w->w_lock, &w->w_desc, w->w_data,
951                                  LDLM_CB_BLOCKING);
952                 } else if (w->w_lock->l_completion_ast != NULL) {
953                         LASSERT(w->w_lock->l_completion_ast != NULL);
954                         rc = w->w_lock->l_completion_ast(w->w_lock, w->w_flags,
955                                                          w->w_data);
956                 } else {
957                         rc = 0;
958                 }
959                 if (rc == -ERESTART)
960                         retval = rc;
961                 else if (rc)
962                         CDEBUG(D_DLMTRACE, "Failed AST - should clean & "
963                                "disconnect client\n");
964                 LDLM_LOCK_PUT(w->w_lock);
965                 list_del(&w->w_list);
966                 OBD_FREE(w, sizeof(*w));
967         }
968         RETURN(retval);
969 }
970
971 static int reprocess_one_queue(struct ldlm_resource *res, void *closure)
972 {
973         ldlm_reprocess_all(res);
974         return LDLM_ITER_CONTINUE;
975 }
976
977 void ldlm_reprocess_all_ns(struct ldlm_namespace *ns)
978 {
979         int i, rc;
980
981         l_lock(&ns->ns_lock);
982         for (i = 0; i < RES_HASH_SIZE; i++) {
983                 struct list_head *tmp, *next;
984                 list_for_each_safe(tmp, next, &(ns->ns_hash[i])) {
985                         struct ldlm_resource *res =
986                                 list_entry(tmp, struct ldlm_resource, lr_hash);
987
988                         ldlm_resource_getref(res);
989                         l_unlock(&ns->ns_lock);
990                         rc = reprocess_one_queue(res, NULL);
991                         l_lock(&ns->ns_lock);
992                         next = tmp->next;
993                         ldlm_resource_putref(res);
994                         if (rc == LDLM_ITER_STOP)
995                                 GOTO(out, rc);
996                 }
997         }
998  out:
999         l_unlock(&ns->ns_lock);
1000         EXIT;
1001 }
1002
1003 void ldlm_reprocess_all(struct ldlm_resource *res)
1004 {
1005         struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
1006         int rc;
1007         ENTRY;
1008
1009         /* Local lock trees don't get reprocessed. */
1010         if (res->lr_namespace->ns_client) {
1011                 EXIT;
1012                 return;
1013         }
1014
1015  restart:
1016         l_lock(&res->lr_namespace->ns_lock);
1017         res->lr_tmp = &rpc_list;
1018
1019         rc = ldlm_reprocess_queue(res, &res->lr_converting);
1020         if (rc == LDLM_ITER_CONTINUE)
1021                 ldlm_reprocess_queue(res, &res->lr_waiting);
1022
1023         res->lr_tmp = NULL;
1024         l_unlock(&res->lr_namespace->ns_lock);
1025
1026         rc = ldlm_run_ast_work(res->lr_namespace, &rpc_list);
1027         if (rc == -ERESTART) {
1028                 LASSERT(list_empty(&rpc_list));
1029                 goto restart;
1030         }
1031         EXIT;
1032 }
1033
1034 void ldlm_cancel_callback(struct ldlm_lock *lock)
1035 {
1036         l_lock(&lock->l_resource->lr_namespace->ns_lock);
1037         if (!(lock->l_flags & LDLM_FL_CANCEL)) {
1038                 lock->l_flags |= LDLM_FL_CANCEL;
1039                 if (lock->l_blocking_ast) {
1040                         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
1041                         // l_check_no_ns_lock(lock->l_resource->lr_namespace);
1042                         lock->l_blocking_ast(lock, NULL, lock->l_ast_data,
1043                                              LDLM_CB_CANCELING);
1044                         return;
1045                 } else {
1046                         LDLM_DEBUG(lock, "no blocking ast");
1047                 }
1048         }
1049         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
1050 }
1051
1052 void ldlm_lock_cancel(struct ldlm_lock *lock)
1053 {
1054         struct ldlm_resource *res;
1055         struct ldlm_namespace *ns;
1056         ENTRY;
1057
1058         res = lock->l_resource;
1059         ns = res->lr_namespace;
1060
1061         l_lock(&ns->ns_lock);
1062         ldlm_del_waiting_lock(lock);
1063
1064         /* Please do not, no matter how tempting, remove this LBUG without
1065          * talking to me first. -phik */
1066         if (lock->l_readers || lock->l_writers) {
1067                 LDLM_ERROR(lock, "lock still has references");
1068                 LBUG();
1069         }
1070
1071         ldlm_cancel_callback(lock);
1072
1073         ldlm_resource_unlink_lock(lock);
1074         ldlm_lock_destroy(lock);
1075         l_unlock(&ns->ns_lock);
1076         EXIT;
1077 }
1078
1079 int ldlm_lock_set_data(struct lustre_handle *lockh, void *data)
1080 {
1081         struct ldlm_lock *lock = ldlm_handle2lock(lockh);
1082         ENTRY;
1083
1084         if (lock == NULL)
1085                 RETURN(-EINVAL);
1086
1087         lock->l_ast_data = data;
1088         LDLM_LOCK_PUT(lock);
1089         RETURN(0);
1090 }
1091
1092 void ldlm_cancel_locks_for_export(struct obd_export *exp)
1093 {
1094         struct ldlm_namespace *ns = exp->exp_obd->obd_namespace;
1095         struct ldlm_lock *lock;
1096         struct ldlm_resource *res;
1097
1098         l_lock(&ns->ns_lock);
1099         while(!list_empty(&exp->exp_ldlm_data.led_held_locks)) { 
1100                 lock = list_entry(exp->exp_ldlm_data.led_held_locks.next,
1101                                   struct ldlm_lock, l_export_chain);
1102                 res = ldlm_resource_getref(lock->l_resource);
1103                 LDLM_DEBUG(lock, "export %p", exp);
1104                 ldlm_lock_cancel(lock);
1105                 l_unlock(&ns->ns_lock);
1106                 ldlm_reprocess_all(res);
1107                 ldlm_resource_putref(res);
1108                 l_lock(&ns->ns_lock);
1109         }
1110         l_unlock(&ns->ns_lock);
1111 }
1112
1113 struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
1114                                         int *flags)
1115 {
1116         struct list_head rpc_list = LIST_HEAD_INIT(rpc_list);
1117         struct ldlm_resource *res;
1118         struct ldlm_namespace *ns;
1119         int granted = 0;
1120         int old_mode, rc;
1121         ldlm_error_t err;
1122         ENTRY;
1123
1124         if (new_mode == lock->l_granted_mode) { // No changes? Just return.
1125                 *flags |= LDLM_FL_BLOCK_GRANTED;
1126                 RETURN(lock->l_resource);
1127         }
1128
1129         LASSERTF(new_mode == LCK_PW && lock->l_granted_mode == LCK_PR,
1130                  "new_mode %u, granted %u\n", new_mode, lock->l_granted_mode);
1131
1132         res = lock->l_resource;
1133         ns = res->lr_namespace;
1134
1135         l_lock(&ns->ns_lock);
1136
1137         old_mode = lock->l_req_mode;
1138         lock->l_req_mode = new_mode;
1139         ldlm_resource_unlink_lock(lock);
1140
1141         /* If this is a local resource, put it on the appropriate list. */
1142         if (res->lr_namespace->ns_client) {
1143                 if (*flags & (LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_GRANTED)) {
1144                         ldlm_resource_add_lock(res, &res->lr_converting, lock);
1145                 } else {
1146                         /* This should never happen, because of the way the
1147                          * server handles conversions. */
1148                         LDLM_ERROR(lock, "Erroneous flags %d on local lock\n",
1149                                    *flags);
1150                         LBUG();
1151
1152                         res->lr_tmp = &rpc_list;
1153                         ldlm_grant_lock(lock, NULL, 0, 0);
1154                         res->lr_tmp = NULL;
1155                         granted = 1;
1156                         /* FIXME: completion handling not with ns_lock held ! */
1157                         if (lock->l_completion_ast)
1158                                 lock->l_completion_ast(lock, 0, NULL);
1159                 }
1160         } else {
1161                 int pflags = 0;
1162                 ldlm_processing_policy policy;
1163                 policy = ldlm_processing_policy_table[res->lr_type];
1164                 res->lr_tmp = &rpc_list;
1165                 rc = policy(lock, &pflags, 0, &err);
1166                 res->lr_tmp = NULL;
1167                 if (rc == LDLM_ITER_STOP) {
1168                         lock->l_req_mode = old_mode;
1169                         ldlm_resource_add_lock(res, &res->lr_granted, lock);
1170                         res = NULL;
1171                 } else {
1172                         *flags |= LDLM_FL_BLOCK_GRANTED;
1173                         granted = 1;
1174                 }
1175         }
1176
1177         l_unlock(&ns->ns_lock);
1178
1179         if (granted)
1180                 ldlm_run_ast_work(ns, &rpc_list);
1181         RETURN(res);
1182 }
1183
1184 void ldlm_lock_dump(int level, struct ldlm_lock *lock, int pos)
1185 {
1186         char str[PTL_NALFMT_SIZE];
1187         struct obd_device *obd = NULL;
1188
1189         if (!((portal_debug | D_ERROR) & level))
1190                 return;
1191
1192         if (!lock) {
1193                 CDEBUG(level, "  NULL LDLM lock\n");
1194                 return;
1195         }
1196
1197         CDEBUG(level, "  -- Lock dump: %p/"LPX64" (rc: %d) (pos: %d) (pid: %d)\n",
1198                lock, lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
1199                pos, lock->l_pid);
1200         if (lock->l_conn_export != NULL)
1201                 obd = lock->l_conn_export->exp_obd;
1202         if (lock->l_export && lock->l_export->exp_connection) {
1203                 CDEBUG(level, "  Node: NID %s on %s (rhandle: "LPX64")\n",
1204                        ptlrpc_peernid2str(&lock->l_export->exp_connection->c_peer, str),
1205                        lock->l_export->exp_connection->c_peer.peer_ni->pni_name,
1206                        lock->l_remote_handle.cookie);
1207         } else if (obd == NULL) {
1208                 CDEBUG(level, "  Node: local\n");
1209         } else {
1210                 struct obd_import *imp = obd->u.cli.cl_import;
1211                 CDEBUG(level, "  Node: NID %s on %s (rhandle: "LPX64")\n",
1212                        ptlrpc_peernid2str(&imp->imp_connection->c_peer, str),
1213                        imp->imp_connection->c_peer.peer_ni->pni_name,
1214                        lock->l_remote_handle.cookie);
1215         }
1216         CDEBUG(level, "  Resource: %p ("LPU64"/"LPU64")\n", lock->l_resource,
1217                lock->l_resource->lr_name.name[0],
1218                lock->l_resource->lr_name.name[1]);
1219         CDEBUG(level, "  Req mode: %s, grant mode: %s, rc: %u, read: %d, "
1220                "write: %d\n", ldlm_lockname[lock->l_req_mode],
1221                ldlm_lockname[lock->l_granted_mode],
1222                atomic_read(&lock->l_refc), lock->l_readers, lock->l_writers);
1223         if (lock->l_resource->lr_type == LDLM_EXTENT)
1224                 CDEBUG(level, "  Extent: "LPU64" -> "LPU64
1225                        " (req "LPU64"-"LPU64")\n",
1226                        lock->l_policy_data.l_extent.start,
1227                        lock->l_policy_data.l_extent.end,
1228                        lock->l_req_extent.start, lock->l_req_extent.end);
1229         else if (lock->l_resource->lr_type == LDLM_FLOCK)
1230                 CDEBUG(level, "  Pid: "LPU64" Extent: "LPU64" -> "LPU64"\n",
1231                        lock->l_policy_data.l_flock.pid,
1232                        lock->l_policy_data.l_flock.start,
1233                        lock->l_policy_data.l_flock.end);
1234         else if (lock->l_resource->lr_type == LDLM_IBITS)
1235                 CDEBUG(level, " Bits: "LPX64"\n",
1236                        lock->l_policy_data.l_inodebits.bits);
1237 }
1238
1239 void ldlm_lock_dump_handle(int level, struct lustre_handle *lockh)
1240 {
1241         struct ldlm_lock *lock;
1242
1243         lock = ldlm_handle2lock(lockh);
1244         if (lock == NULL)
1245                 return;
1246
1247         ldlm_lock_dump(D_OTHER, lock, 0);
1248
1249         LDLM_LOCK_PUT(lock);
1250 }