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