staging: lustre: remove LPU64 define
[deliverable/linux.git] / drivers / staging / lustre / lustre / ldlm / ldlm_lock.c
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2010, 2012, Intel Corporation.
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 *
36 * lustre/ldlm/ldlm_lock.c
37 *
38 * Author: Peter Braam <braam@clusterfs.com>
39 * Author: Phil Schwan <phil@clusterfs.com>
40 */
41
42#define DEBUG_SUBSYSTEM S_LDLM
43
9fdaf8c0 44#include "../../include/linux/libcfs/libcfs.h"
e27db149
GKH
45#include "../include/linux/lustre_intent.h"
46#include "../include/obd_class.h"
d7e09d03
PT
47#include "ldlm_internal.h"
48
49/* lock types */
50char *ldlm_lockname[] = {
805e517a
EG
51 [0] = "--",
52 [LCK_EX] = "EX",
53 [LCK_PW] = "PW",
54 [LCK_PR] = "PR",
55 [LCK_CW] = "CW",
56 [LCK_CR] = "CR",
57 [LCK_NL] = "NL",
58 [LCK_GROUP] = "GROUP",
59 [LCK_COS] = "COS",
d7e09d03
PT
60};
61EXPORT_SYMBOL(ldlm_lockname);
62
63char *ldlm_typename[] = {
805e517a
EG
64 [LDLM_PLAIN] = "PLN",
65 [LDLM_EXTENT] = "EXT",
66 [LDLM_FLOCK] = "FLK",
67 [LDLM_IBITS] = "IBT",
d7e09d03
PT
68};
69EXPORT_SYMBOL(ldlm_typename);
70
71static ldlm_policy_wire_to_local_t ldlm_policy_wire18_to_local[] = {
805e517a
EG
72 [LDLM_PLAIN - LDLM_MIN_TYPE] = ldlm_plain_policy_wire_to_local,
73 [LDLM_EXTENT - LDLM_MIN_TYPE] = ldlm_extent_policy_wire_to_local,
74 [LDLM_FLOCK - LDLM_MIN_TYPE] = ldlm_flock_policy_wire18_to_local,
75 [LDLM_IBITS - LDLM_MIN_TYPE] = ldlm_ibits_policy_wire_to_local,
d7e09d03
PT
76};
77
78static ldlm_policy_wire_to_local_t ldlm_policy_wire21_to_local[] = {
805e517a
EG
79 [LDLM_PLAIN - LDLM_MIN_TYPE] = ldlm_plain_policy_wire_to_local,
80 [LDLM_EXTENT - LDLM_MIN_TYPE] = ldlm_extent_policy_wire_to_local,
81 [LDLM_FLOCK - LDLM_MIN_TYPE] = ldlm_flock_policy_wire21_to_local,
82 [LDLM_IBITS - LDLM_MIN_TYPE] = ldlm_ibits_policy_wire_to_local,
d7e09d03
PT
83};
84
85static ldlm_policy_local_to_wire_t ldlm_policy_local_to_wire[] = {
805e517a
EG
86 [LDLM_PLAIN - LDLM_MIN_TYPE] = ldlm_plain_policy_local_to_wire,
87 [LDLM_EXTENT - LDLM_MIN_TYPE] = ldlm_extent_policy_local_to_wire,
88 [LDLM_FLOCK - LDLM_MIN_TYPE] = ldlm_flock_policy_local_to_wire,
89 [LDLM_IBITS - LDLM_MIN_TYPE] = ldlm_ibits_policy_local_to_wire,
d7e09d03
PT
90};
91
92/**
93 * Converts lock policy from local format to on the wire lock_desc format
94 */
95void ldlm_convert_policy_to_wire(ldlm_type_t type,
96 const ldlm_policy_data_t *lpolicy,
97 ldlm_wire_policy_data_t *wpolicy)
98{
99 ldlm_policy_local_to_wire_t convert;
100
101 convert = ldlm_policy_local_to_wire[type - LDLM_MIN_TYPE];
102
103 convert(lpolicy, wpolicy);
104}
105
106/**
107 * Converts lock policy from on the wire lock_desc format to local format
108 */
109void ldlm_convert_policy_to_local(struct obd_export *exp, ldlm_type_t type,
110 const ldlm_wire_policy_data_t *wpolicy,
111 ldlm_policy_data_t *lpolicy)
112{
113 ldlm_policy_wire_to_local_t convert;
114 int new_client;
115
116 /** some badness for 2.0.0 clients, but 2.0.0 isn't supported */
117 new_client = (exp_connect_flags(exp) & OBD_CONNECT_FULL20) != 0;
118 if (new_client)
119 convert = ldlm_policy_wire21_to_local[type - LDLM_MIN_TYPE];
120 else
121 convert = ldlm_policy_wire18_to_local[type - LDLM_MIN_TYPE];
122
123 convert(wpolicy, lpolicy);
124}
125
126char *ldlm_it2str(int it)
127{
128 switch (it) {
129 case IT_OPEN:
130 return "open";
131 case IT_CREAT:
132 return "creat";
133 case (IT_OPEN | IT_CREAT):
134 return "open|creat";
135 case IT_READDIR:
136 return "readdir";
137 case IT_GETATTR:
138 return "getattr";
139 case IT_LOOKUP:
140 return "lookup";
141 case IT_UNLINK:
142 return "unlink";
143 case IT_GETXATTR:
144 return "getxattr";
145 case IT_LAYOUT:
146 return "layout";
147 default:
148 CERROR("Unknown intent %d\n", it);
149 return "UNKNOWN";
150 }
151}
152EXPORT_SYMBOL(ldlm_it2str);
153
154extern struct kmem_cache *ldlm_lock_slab;
155
156
157void ldlm_register_intent(struct ldlm_namespace *ns, ldlm_res_policy arg)
158{
159 ns->ns_policy = arg;
160}
161EXPORT_SYMBOL(ldlm_register_intent);
162
163/*
164 * REFCOUNTED LOCK OBJECTS
165 */
166
167
168/**
169 * Get a reference on a lock.
170 *
171 * Lock refcounts, during creation:
172 * - one special one for allocation, dec'd only once in destroy
173 * - one for being a lock that's in-use
174 * - one for the addref associated with a new lock
175 */
176struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock)
177{
178 atomic_inc(&lock->l_refc);
179 return lock;
180}
181EXPORT_SYMBOL(ldlm_lock_get);
182
183/**
184 * Release lock reference.
185 *
186 * Also frees the lock if it was last reference.
187 */
188void ldlm_lock_put(struct ldlm_lock *lock)
189{
d7e09d03
PT
190 LASSERT(lock->l_resource != LP_POISON);
191 LASSERT(atomic_read(&lock->l_refc) > 0);
192 if (atomic_dec_and_test(&lock->l_refc)) {
193 struct ldlm_resource *res;
194
195 LDLM_DEBUG(lock,
196 "final lock_put on destroyed lock, freeing it.");
197
198 res = lock->l_resource;
f2145eae 199 LASSERT(lock->l_flags & LDLM_FL_DESTROYED);
d7e09d03
PT
200 LASSERT(list_empty(&lock->l_res_link));
201 LASSERT(list_empty(&lock->l_pending_chain));
202
203 lprocfs_counter_decr(ldlm_res_to_ns(res)->ns_stats,
204 LDLM_NSS_LOCKS);
205 lu_ref_del(&res->lr_reference, "lock", lock);
206 ldlm_resource_putref(res);
207 lock->l_resource = NULL;
208 if (lock->l_export) {
209 class_export_lock_put(lock->l_export, lock);
210 lock->l_export = NULL;
211 }
212
213 if (lock->l_lvb_data != NULL)
214 OBD_FREE(lock->l_lvb_data, lock->l_lvb_len);
215
216 ldlm_interval_free(ldlm_interval_detach(lock));
217 lu_ref_fini(&lock->l_reference);
218 OBD_FREE_RCU(lock, sizeof(*lock), &lock->l_handle);
219 }
d7e09d03
PT
220}
221EXPORT_SYMBOL(ldlm_lock_put);
222
223/**
224 * Removes LDLM lock \a lock from LRU. Assumes LRU is already locked.
225 */
226int ldlm_lock_remove_from_lru_nolock(struct ldlm_lock *lock)
227{
228 int rc = 0;
229 if (!list_empty(&lock->l_lru)) {
230 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
231
232 LASSERT(lock->l_resource->lr_type != LDLM_FLOCK);
233 list_del_init(&lock->l_lru);
d7e09d03
PT
234 LASSERT(ns->ns_nr_unused > 0);
235 ns->ns_nr_unused--;
236 rc = 1;
237 }
238 return rc;
239}
240
241/**
242 * Removes LDLM lock \a lock from LRU. Obtains the LRU lock first.
243 */
244int ldlm_lock_remove_from_lru(struct ldlm_lock *lock)
245{
246 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
247 int rc;
248
f2145eae 249 if (lock->l_flags & LDLM_FL_NS_SRV) {
d7e09d03 250 LASSERT(list_empty(&lock->l_lru));
0a3bdb00 251 return 0;
d7e09d03
PT
252 }
253
254 spin_lock(&ns->ns_lock);
255 rc = ldlm_lock_remove_from_lru_nolock(lock);
256 spin_unlock(&ns->ns_lock);
d7e09d03
PT
257 return rc;
258}
259
260/**
261 * Adds LDLM lock \a lock to namespace LRU. Assumes LRU is already locked.
262 */
263void ldlm_lock_add_to_lru_nolock(struct ldlm_lock *lock)
264{
265 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
266
267 lock->l_last_used = cfs_time_current();
268 LASSERT(list_empty(&lock->l_lru));
269 LASSERT(lock->l_resource->lr_type != LDLM_FLOCK);
270 list_add_tail(&lock->l_lru, &ns->ns_unused_list);
88e4ff86
LX
271 if (lock->l_flags & LDLM_FL_SKIPPED)
272 lock->l_flags &= ~LDLM_FL_SKIPPED;
d7e09d03
PT
273 LASSERT(ns->ns_nr_unused >= 0);
274 ns->ns_nr_unused++;
275}
276
277/**
278 * Adds LDLM lock \a lock to namespace LRU. Obtains necessary LRU locks
279 * first.
280 */
281void ldlm_lock_add_to_lru(struct ldlm_lock *lock)
282{
283 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
284
d7e09d03
PT
285 spin_lock(&ns->ns_lock);
286 ldlm_lock_add_to_lru_nolock(lock);
287 spin_unlock(&ns->ns_lock);
d7e09d03
PT
288}
289
290/**
291 * Moves LDLM lock \a lock that is already in namespace LRU to the tail of
292 * the LRU. Performs necessary LRU locking
293 */
294void ldlm_lock_touch_in_lru(struct ldlm_lock *lock)
295{
296 struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
297
f2145eae 298 if (lock->l_flags & LDLM_FL_NS_SRV) {
d7e09d03 299 LASSERT(list_empty(&lock->l_lru));
d7e09d03
PT
300 return;
301 }
302
303 spin_lock(&ns->ns_lock);
304 if (!list_empty(&lock->l_lru)) {
305 ldlm_lock_remove_from_lru_nolock(lock);
306 ldlm_lock_add_to_lru_nolock(lock);
307 }
308 spin_unlock(&ns->ns_lock);
d7e09d03
PT
309}
310
311/**
312 * Helper to destroy a locked lock.
313 *
314 * Used by ldlm_lock_destroy and ldlm_lock_destroy_nolock
315 * Must be called with l_lock and lr_lock held.
316 *
317 * Does not actually free the lock data, but rather marks the lock as
318 * destroyed by setting l_destroyed field in the lock to 1. Destroys a
319 * handle->lock association too, so that the lock can no longer be found
320 * and removes the lock from LRU list. Actual lock freeing occurs when
321 * last lock reference goes away.
322 *
323 * Original comment (of some historical value):
324 * This used to have a 'strict' flag, which recovery would use to mark an
325 * in-use lock as needing-to-die. Lest I am ever tempted to put it back, I
326 * shall explain why it's gone: with the new hash table scheme, once you call
327 * ldlm_lock_destroy, you can never drop your final references on this lock.
328 * Because it's not in the hash table anymore. -phil
329 */
330int ldlm_lock_destroy_internal(struct ldlm_lock *lock)
331{
d7e09d03
PT
332 if (lock->l_readers || lock->l_writers) {
333 LDLM_ERROR(lock, "lock still has references");
334 LBUG();
335 }
336
337 if (!list_empty(&lock->l_res_link)) {
338 LDLM_ERROR(lock, "lock still on resource");
339 LBUG();
340 }
341
f2145eae 342 if (lock->l_flags & LDLM_FL_DESTROYED) {
d7e09d03 343 LASSERT(list_empty(&lock->l_lru));
d7e09d03
PT
344 return 0;
345 }
f2145eae 346 lock->l_flags |= LDLM_FL_DESTROYED;
d7e09d03
PT
347
348 if (lock->l_export && lock->l_export->exp_lock_hash) {
349 /* NB: it's safe to call cfs_hash_del() even lock isn't
350 * in exp_lock_hash. */
351 /* In the function below, .hs_keycmp resolves to
352 * ldlm_export_lock_keycmp() */
353 /* coverity[overrun-buffer-val] */
354 cfs_hash_del(lock->l_export->exp_lock_hash,
355 &lock->l_remote_handle, &lock->l_exp_hash);
356 }
357
358 ldlm_lock_remove_from_lru(lock);
359 class_handle_unhash(&lock->l_handle);
360
361#if 0
362 /* Wake anyone waiting for this lock */
363 /* FIXME: I should probably add yet another flag, instead of using
364 * l_export to only call this on clients */
365 if (lock->l_export)
366 class_export_put(lock->l_export);
367 lock->l_export = NULL;
368 if (lock->l_export && lock->l_completion_ast)
369 lock->l_completion_ast(lock, 0);
370#endif
d7e09d03
PT
371 return 1;
372}
373
374/**
375 * Destroys a LDLM lock \a lock. Performs necessary locking first.
376 */
377void ldlm_lock_destroy(struct ldlm_lock *lock)
378{
379 int first;
29aaf496 380
d7e09d03
PT
381 lock_res_and_lock(lock);
382 first = ldlm_lock_destroy_internal(lock);
383 unlock_res_and_lock(lock);
384
385 /* drop reference from hashtable only for first destroy */
386 if (first) {
387 lu_ref_del(&lock->l_reference, "hash", lock);
388 LDLM_LOCK_RELEASE(lock);
389 }
d7e09d03
PT
390}
391
392/**
393 * Destroys a LDLM lock \a lock that is already locked.
394 */
395void ldlm_lock_destroy_nolock(struct ldlm_lock *lock)
396{
397 int first;
29aaf496 398
d7e09d03
PT
399 first = ldlm_lock_destroy_internal(lock);
400 /* drop reference from hashtable only for first destroy */
401 if (first) {
402 lu_ref_del(&lock->l_reference, "hash", lock);
403 LDLM_LOCK_RELEASE(lock);
404 }
d7e09d03
PT
405}
406
407/* this is called by portals_handle2object with the handle lock taken */
408static void lock_handle_addref(void *lock)
409{
410 LDLM_LOCK_GET((struct ldlm_lock *)lock);
411}
412
413static void lock_handle_free(void *lock, int size)
414{
415 LASSERT(size == sizeof(struct ldlm_lock));
416 OBD_SLAB_FREE(lock, ldlm_lock_slab, size);
417}
418
419struct portals_handle_ops lock_handle_ops = {
420 .hop_addref = lock_handle_addref,
421 .hop_free = lock_handle_free,
422};
423
424/**
425 *
426 * Allocate and initialize new lock structure.
427 *
428 * usage: pass in a resource on which you have done ldlm_resource_get
429 * new lock will take over the refcount.
430 * returns: lock with refcount 2 - one for current caller and one for remote
431 */
432static struct ldlm_lock *ldlm_lock_new(struct ldlm_resource *resource)
433{
434 struct ldlm_lock *lock;
d7e09d03
PT
435
436 if (resource == NULL)
437 LBUG();
438
0be19afa 439 OBD_SLAB_ALLOC_PTR_GFP(lock, ldlm_lock_slab, GFP_NOFS);
d7e09d03 440 if (lock == NULL)
0a3bdb00 441 return NULL;
d7e09d03
PT
442
443 spin_lock_init(&lock->l_lock);
444 lock->l_resource = resource;
445 lu_ref_add(&resource->lr_reference, "lock", lock);
446
447 atomic_set(&lock->l_refc, 2);
448 INIT_LIST_HEAD(&lock->l_res_link);
449 INIT_LIST_HEAD(&lock->l_lru);
450 INIT_LIST_HEAD(&lock->l_pending_chain);
451 INIT_LIST_HEAD(&lock->l_bl_ast);
452 INIT_LIST_HEAD(&lock->l_cp_ast);
453 INIT_LIST_HEAD(&lock->l_rk_ast);
454 init_waitqueue_head(&lock->l_waitq);
455 lock->l_blocking_lock = NULL;
456 INIT_LIST_HEAD(&lock->l_sl_mode);
457 INIT_LIST_HEAD(&lock->l_sl_policy);
458 INIT_HLIST_NODE(&lock->l_exp_hash);
459 INIT_HLIST_NODE(&lock->l_exp_flock_hash);
460
461 lprocfs_counter_incr(ldlm_res_to_ns(resource)->ns_stats,
462 LDLM_NSS_LOCKS);
463 INIT_LIST_HEAD(&lock->l_handle.h_link);
464 class_handle_hash(&lock->l_handle, &lock_handle_ops);
465
466 lu_ref_init(&lock->l_reference);
467 lu_ref_add(&lock->l_reference, "hash", lock);
468 lock->l_callback_timeout = 0;
469
470#if LUSTRE_TRACKS_LOCK_EXP_REFS
471 INIT_LIST_HEAD(&lock->l_exp_refs_link);
472 lock->l_exp_refs_nr = 0;
473 lock->l_exp_refs_target = NULL;
474#endif
475 INIT_LIST_HEAD(&lock->l_exp_list);
476
0a3bdb00 477 return lock;
d7e09d03
PT
478}
479
480/**
481 * Moves LDLM lock \a lock to another resource.
482 * This is used on client when server returns some other lock than requested
483 * (typically as a result of intent operation)
484 */
485int ldlm_lock_change_resource(struct ldlm_namespace *ns, struct ldlm_lock *lock,
486 const struct ldlm_res_id *new_resid)
487{
488 struct ldlm_resource *oldres = lock->l_resource;
489 struct ldlm_resource *newres;
490 int type;
d7e09d03
PT
491
492 LASSERT(ns_is_client(ns));
493
494 lock_res_and_lock(lock);
495 if (memcmp(new_resid, &lock->l_resource->lr_name,
496 sizeof(lock->l_resource->lr_name)) == 0) {
497 /* Nothing to do */
498 unlock_res_and_lock(lock);
0a3bdb00 499 return 0;
d7e09d03
PT
500 }
501
502 LASSERT(new_resid->name[0] != 0);
503
504 /* This function assumes that the lock isn't on any lists */
505 LASSERT(list_empty(&lock->l_res_link));
506
507 type = oldres->lr_type;
508 unlock_res_and_lock(lock);
509
510 newres = ldlm_resource_get(ns, NULL, new_resid, type, 1);
511 if (newres == NULL)
0a3bdb00 512 return -ENOMEM;
d7e09d03
PT
513
514 lu_ref_add(&newres->lr_reference, "lock", lock);
515 /*
516 * To flip the lock from the old to the new resource, lock, oldres and
517 * newres have to be locked. Resource spin-locks are nested within
518 * lock->l_lock, and are taken in the memory address order to avoid
519 * dead-locks.
520 */
521 spin_lock(&lock->l_lock);
522 oldres = lock->l_resource;
523 if (oldres < newres) {
524 lock_res(oldres);
525 lock_res_nested(newres, LRT_NEW);
526 } else {
527 lock_res(newres);
528 lock_res_nested(oldres, LRT_NEW);
529 }
530 LASSERT(memcmp(new_resid, &oldres->lr_name,
ec83e611 531 sizeof(oldres->lr_name)) != 0);
d7e09d03
PT
532 lock->l_resource = newres;
533 unlock_res(oldres);
534 unlock_res_and_lock(lock);
535
536 /* ...and the flowers are still standing! */
537 lu_ref_del(&oldres->lr_reference, "lock", lock);
538 ldlm_resource_putref(oldres);
539
0a3bdb00 540 return 0;
d7e09d03
PT
541}
542EXPORT_SYMBOL(ldlm_lock_change_resource);
543
544/** \defgroup ldlm_handles LDLM HANDLES
545 * Ways to get hold of locks without any addresses.
546 * @{
547 */
548
549/**
550 * Fills in handle for LDLM lock \a lock into supplied \a lockh
551 * Does not take any references.
552 */
553void ldlm_lock2handle(const struct ldlm_lock *lock, struct lustre_handle *lockh)
554{
555 lockh->cookie = lock->l_handle.h_cookie;
556}
557EXPORT_SYMBOL(ldlm_lock2handle);
558
559/**
560 * Obtain a lock reference by handle.
561 *
562 * if \a flags: atomically get the lock and set the flags.
563 * Return NULL if flag already set
564 */
565struct ldlm_lock *__ldlm_handle2lock(const struct lustre_handle *handle,
566 __u64 flags)
567{
568 struct ldlm_lock *lock;
d7e09d03
PT
569
570 LASSERT(handle);
571
572 lock = class_handle2object(handle->cookie);
573 if (lock == NULL)
0a3bdb00 574 return NULL;
d7e09d03
PT
575
576 /* It's unlikely but possible that someone marked the lock as
577 * destroyed after we did handle2object on it */
f2145eae 578 if (flags == 0 && ((lock->l_flags & LDLM_FL_DESTROYED)== 0)) {
d7e09d03 579 lu_ref_add(&lock->l_reference, "handle", current);
0a3bdb00 580 return lock;
d7e09d03
PT
581 }
582
583 lock_res_and_lock(lock);
584
585 LASSERT(lock->l_resource != NULL);
586
587 lu_ref_add_atomic(&lock->l_reference, "handle", current);
f2145eae 588 if (unlikely(lock->l_flags & LDLM_FL_DESTROYED)) {
d7e09d03
PT
589 unlock_res_and_lock(lock);
590 CDEBUG(D_INFO, "lock already destroyed: lock %p\n", lock);
591 LDLM_LOCK_PUT(lock);
0a3bdb00 592 return NULL;
d7e09d03
PT
593 }
594
595 if (flags && (lock->l_flags & flags)) {
596 unlock_res_and_lock(lock);
597 LDLM_LOCK_PUT(lock);
0a3bdb00 598 return NULL;
d7e09d03
PT
599 }
600
601 if (flags)
602 lock->l_flags |= flags;
603
604 unlock_res_and_lock(lock);
0a3bdb00 605 return lock;
d7e09d03
PT
606}
607EXPORT_SYMBOL(__ldlm_handle2lock);
608/** @} ldlm_handles */
609
610/**
611 * Fill in "on the wire" representation for given LDLM lock into supplied
612 * lock descriptor \a desc structure.
613 */
614void ldlm_lock2desc(struct ldlm_lock *lock, struct ldlm_lock_desc *desc)
615{
616 struct obd_export *exp = lock->l_export ?: lock->l_conn_export;
617
618 /* INODEBITS_INTEROP: If the other side does not support
619 * inodebits, reply with a plain lock descriptor. */
620 if ((lock->l_resource->lr_type == LDLM_IBITS) &&
621 (exp && !(exp_connect_flags(exp) & OBD_CONNECT_IBITS))) {
622 /* Make sure all the right bits are set in this lock we
623 are going to pass to client */
624 LASSERTF(lock->l_policy_data.l_inodebits.bits ==
625 (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
626 MDS_INODELOCK_LAYOUT),
b0f5aad5 627 "Inappropriate inode lock bits during conversion %llu\n",
d7e09d03
PT
628 lock->l_policy_data.l_inodebits.bits);
629
630 ldlm_res2desc(lock->l_resource, &desc->l_resource);
631 desc->l_resource.lr_type = LDLM_PLAIN;
632
633 /* Convert "new" lock mode to something old client can
634 understand */
635 if ((lock->l_req_mode == LCK_CR) ||
636 (lock->l_req_mode == LCK_CW))
637 desc->l_req_mode = LCK_PR;
638 else
639 desc->l_req_mode = lock->l_req_mode;
640 if ((lock->l_granted_mode == LCK_CR) ||
641 (lock->l_granted_mode == LCK_CW)) {
642 desc->l_granted_mode = LCK_PR;
643 } else {
644 /* We never grant PW/EX locks to clients */
645 LASSERT((lock->l_granted_mode != LCK_PW) &&
646 (lock->l_granted_mode != LCK_EX));
647 desc->l_granted_mode = lock->l_granted_mode;
648 }
649
650 /* We do not copy policy here, because there is no
651 policy for plain locks */
652 } else {
653 ldlm_res2desc(lock->l_resource, &desc->l_resource);
654 desc->l_req_mode = lock->l_req_mode;
655 desc->l_granted_mode = lock->l_granted_mode;
656 ldlm_convert_policy_to_wire(lock->l_resource->lr_type,
657 &lock->l_policy_data,
658 &desc->l_policy_data);
659 }
660}
661EXPORT_SYMBOL(ldlm_lock2desc);
662
663/**
664 * Add a lock to list of conflicting locks to send AST to.
665 *
666 * Only add if we have not sent a blocking AST to the lock yet.
667 */
668void ldlm_add_bl_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
669 struct list_head *work_list)
670{
671 if ((lock->l_flags & LDLM_FL_AST_SENT) == 0) {
672 LDLM_DEBUG(lock, "lock incompatible; sending blocking AST.");
673 lock->l_flags |= LDLM_FL_AST_SENT;
674 /* If the enqueuing client said so, tell the AST recipient to
675 * discard dirty data, rather than writing back. */
f2145eae 676 if (new->l_flags & LDLM_FL_AST_DISCARD_DATA)
d7e09d03
PT
677 lock->l_flags |= LDLM_FL_DISCARD_DATA;
678 LASSERT(list_empty(&lock->l_bl_ast));
679 list_add(&lock->l_bl_ast, work_list);
680 LDLM_LOCK_GET(lock);
681 LASSERT(lock->l_blocking_lock == NULL);
682 lock->l_blocking_lock = LDLM_LOCK_GET(new);
683 }
684}
685
686/**
687 * Add a lock to list of just granted locks to send completion AST to.
688 */
689void ldlm_add_cp_work_item(struct ldlm_lock *lock, struct list_head *work_list)
690{
691 if ((lock->l_flags & LDLM_FL_CP_REQD) == 0) {
692 lock->l_flags |= LDLM_FL_CP_REQD;
693 LDLM_DEBUG(lock, "lock granted; sending completion AST.");
694 LASSERT(list_empty(&lock->l_cp_ast));
695 list_add(&lock->l_cp_ast, work_list);
696 LDLM_LOCK_GET(lock);
697 }
698}
699
700/**
701 * Aggregator function to add AST work items into a list. Determines
702 * what sort of an AST work needs to be done and calls the proper
703 * adding function.
704 * Must be called with lr_lock held.
705 */
706void ldlm_add_ast_work_item(struct ldlm_lock *lock, struct ldlm_lock *new,
707 struct list_head *work_list)
708{
d7e09d03
PT
709 check_res_locked(lock->l_resource);
710 if (new)
711 ldlm_add_bl_work_item(lock, new, work_list);
712 else
713 ldlm_add_cp_work_item(lock, work_list);
d7e09d03
PT
714}
715
716/**
717 * Add specified reader/writer reference to LDLM lock with handle \a lockh.
718 * r/w reference type is determined by \a mode
719 * Calls ldlm_lock_addref_internal.
720 */
721void ldlm_lock_addref(struct lustre_handle *lockh, __u32 mode)
722{
723 struct ldlm_lock *lock;
724
725 lock = ldlm_handle2lock(lockh);
726 LASSERT(lock != NULL);
727 ldlm_lock_addref_internal(lock, mode);
728 LDLM_LOCK_PUT(lock);
729}
730EXPORT_SYMBOL(ldlm_lock_addref);
731
732/**
733 * Helper function.
734 * Add specified reader/writer reference to LDLM lock \a lock.
735 * r/w reference type is determined by \a mode
736 * Removes lock from LRU if it is there.
737 * Assumes the LDLM lock is already locked.
738 */
739void ldlm_lock_addref_internal_nolock(struct ldlm_lock *lock, __u32 mode)
740{
741 ldlm_lock_remove_from_lru(lock);
742 if (mode & (LCK_NL | LCK_CR | LCK_PR)) {
743 lock->l_readers++;
744 lu_ref_add_atomic(&lock->l_reference, "reader", lock);
745 }
746 if (mode & (LCK_EX | LCK_CW | LCK_PW | LCK_GROUP | LCK_COS)) {
747 lock->l_writers++;
748 lu_ref_add_atomic(&lock->l_reference, "writer", lock);
749 }
750 LDLM_LOCK_GET(lock);
751 lu_ref_add_atomic(&lock->l_reference, "user", lock);
752 LDLM_DEBUG(lock, "ldlm_lock_addref(%s)", ldlm_lockname[mode]);
753}
754
755/**
756 * Attempts to add reader/writer reference to a lock with handle \a lockh, and
757 * fails if lock is already LDLM_FL_CBPENDING or destroyed.
758 *
759 * \retval 0 success, lock was addref-ed
760 *
761 * \retval -EAGAIN lock is being canceled.
762 */
763int ldlm_lock_addref_try(struct lustre_handle *lockh, __u32 mode)
764{
765 struct ldlm_lock *lock;
766 int result;
767
768 result = -EAGAIN;
769 lock = ldlm_handle2lock(lockh);
770 if (lock != NULL) {
771 lock_res_and_lock(lock);
772 if (lock->l_readers != 0 || lock->l_writers != 0 ||
773 !(lock->l_flags & LDLM_FL_CBPENDING)) {
774 ldlm_lock_addref_internal_nolock(lock, mode);
775 result = 0;
776 }
777 unlock_res_and_lock(lock);
778 LDLM_LOCK_PUT(lock);
779 }
780 return result;
781}
782EXPORT_SYMBOL(ldlm_lock_addref_try);
783
784/**
785 * Add specified reader/writer reference to LDLM lock \a lock.
786 * Locks LDLM lock and calls ldlm_lock_addref_internal_nolock to do the work.
787 * Only called for local locks.
788 */
789void ldlm_lock_addref_internal(struct ldlm_lock *lock, __u32 mode)
790{
791 lock_res_and_lock(lock);
792 ldlm_lock_addref_internal_nolock(lock, mode);
793 unlock_res_and_lock(lock);
794}
795
796/**
797 * Removes reader/writer reference for LDLM lock \a lock.
798 * Assumes LDLM lock is already locked.
799 * only called in ldlm_flock_destroy and for local locks.
6e3dd654 800 * Does NOT add lock to LRU if no r/w references left to accommodate flock locks
d7e09d03
PT
801 * that cannot be placed in LRU.
802 */
803void ldlm_lock_decref_internal_nolock(struct ldlm_lock *lock, __u32 mode)
804{
805 LDLM_DEBUG(lock, "ldlm_lock_decref(%s)", ldlm_lockname[mode]);
806 if (mode & (LCK_NL | LCK_CR | LCK_PR)) {
807 LASSERT(lock->l_readers > 0);
808 lu_ref_del(&lock->l_reference, "reader", lock);
809 lock->l_readers--;
810 }
811 if (mode & (LCK_EX | LCK_CW | LCK_PW | LCK_GROUP | LCK_COS)) {
812 LASSERT(lock->l_writers > 0);
813 lu_ref_del(&lock->l_reference, "writer", lock);
814 lock->l_writers--;
815 }
816
817 lu_ref_del(&lock->l_reference, "user", lock);
818 LDLM_LOCK_RELEASE(lock); /* matches the LDLM_LOCK_GET() in addref */
819}
820
821/**
822 * Removes reader/writer reference for LDLM lock \a lock.
823 * Locks LDLM lock first.
824 * If the lock is determined to be client lock on a client and r/w refcount
825 * drops to zero and the lock is not blocked, the lock is added to LRU lock
826 * on the namespace.
827 * For blocked LDLM locks if r/w count drops to zero, blocking_ast is called.
828 */
829void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
830{
831 struct ldlm_namespace *ns;
d7e09d03
PT
832
833 lock_res_and_lock(lock);
834
835 ns = ldlm_lock_to_ns(lock);
836
837 ldlm_lock_decref_internal_nolock(lock, mode);
838
d7e09d03
PT
839 if (lock->l_flags & LDLM_FL_LOCAL &&
840 !lock->l_readers && !lock->l_writers) {
841 /* If this is a local lock on a server namespace and this was
842 * the last reference, cancel the lock. */
843 CDEBUG(D_INFO, "forcing cancel of local lock\n");
844 lock->l_flags |= LDLM_FL_CBPENDING;
845 }
846
847 if (!lock->l_readers && !lock->l_writers &&
848 (lock->l_flags & LDLM_FL_CBPENDING)) {
849 /* If we received a blocked AST and this was the last reference,
850 * run the callback. */
f2145eae 851 if ((lock->l_flags & LDLM_FL_NS_SRV) && lock->l_export)
d7e09d03
PT
852 CERROR("FL_CBPENDING set on non-local lock--just a "
853 "warning\n");
854
855 LDLM_DEBUG(lock, "final decref done on cbpending lock");
856
857 LDLM_LOCK_GET(lock); /* dropped by bl thread */
858 ldlm_lock_remove_from_lru(lock);
859 unlock_res_and_lock(lock);
860
861 if (lock->l_flags & LDLM_FL_FAIL_LOC)
862 OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE);
863
864 if ((lock->l_flags & LDLM_FL_ATOMIC_CB) ||
865 ldlm_bl_to_thread_lock(ns, NULL, lock) != 0)
866 ldlm_handle_bl_callback(ns, NULL, lock);
867 } else if (ns_is_client(ns) &&
868 !lock->l_readers && !lock->l_writers &&
869 !(lock->l_flags & LDLM_FL_NO_LRU) &&
870 !(lock->l_flags & LDLM_FL_BL_AST)) {
871
872 LDLM_DEBUG(lock, "add lock into lru list");
873
874 /* If this is a client-side namespace and this was the last
875 * reference, put it on the LRU. */
876 ldlm_lock_add_to_lru(lock);
877 unlock_res_and_lock(lock);
878
879 if (lock->l_flags & LDLM_FL_FAIL_LOC)
880 OBD_RACE(OBD_FAIL_LDLM_CP_BL_RACE);
881
882 /* Call ldlm_cancel_lru() only if EARLY_CANCEL and LRU RESIZE
883 * are not supported by the server, otherwise, it is done on
884 * enqueue. */
885 if (!exp_connect_cancelset(lock->l_conn_export) &&
886 !ns_connect_lru_resize(ns))
887 ldlm_cancel_lru(ns, 0, LCF_ASYNC, 0);
888 } else {
889 LDLM_DEBUG(lock, "do not add lock into lru list");
890 unlock_res_and_lock(lock);
891 }
d7e09d03
PT
892}
893
894/**
895 * Decrease reader/writer refcount for LDLM lock with handle \a lockh
896 */
897void ldlm_lock_decref(struct lustre_handle *lockh, __u32 mode)
898{
899 struct ldlm_lock *lock = __ldlm_handle2lock(lockh, 0);
900 LASSERTF(lock != NULL, "Non-existing lock: "LPX64"\n", lockh->cookie);
901 ldlm_lock_decref_internal(lock, mode);
902 LDLM_LOCK_PUT(lock);
903}
904EXPORT_SYMBOL(ldlm_lock_decref);
905
906/**
907 * Decrease reader/writer refcount for LDLM lock with handle
908 * \a lockh and mark it for subsequent cancellation once r/w refcount
909 * drops to zero instead of putting into LRU.
910 *
911 * Typical usage is for GROUP locks which we cannot allow to be cached.
912 */
913void ldlm_lock_decref_and_cancel(struct lustre_handle *lockh, __u32 mode)
914{
915 struct ldlm_lock *lock = __ldlm_handle2lock(lockh, 0);
d7e09d03
PT
916
917 LASSERT(lock != NULL);
918
919 LDLM_DEBUG(lock, "ldlm_lock_decref(%s)", ldlm_lockname[mode]);
920 lock_res_and_lock(lock);
921 lock->l_flags |= LDLM_FL_CBPENDING;
922 unlock_res_and_lock(lock);
923 ldlm_lock_decref_internal(lock, mode);
924 LDLM_LOCK_PUT(lock);
925}
926EXPORT_SYMBOL(ldlm_lock_decref_and_cancel);
927
928struct sl_insert_point {
929 struct list_head *res_link;
930 struct list_head *mode_link;
931 struct list_head *policy_link;
932};
933
934/**
935 * Finds a position to insert the new lock into granted lock list.
936 *
937 * Used for locks eligible for skiplist optimization.
938 *
939 * Parameters:
940 * queue [input]: the granted list where search acts on;
941 * req [input]: the lock whose position to be located;
942 * prev [output]: positions within 3 lists to insert @req to
943 * Return Value:
944 * filled @prev
945 * NOTE: called by
946 * - ldlm_grant_lock_with_skiplist
947 */
948static void search_granted_lock(struct list_head *queue,
949 struct ldlm_lock *req,
950 struct sl_insert_point *prev)
951{
952 struct list_head *tmp;
953 struct ldlm_lock *lock, *mode_end, *policy_end;
d7e09d03
PT
954
955 list_for_each(tmp, queue) {
956 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
957
958 mode_end = list_entry(lock->l_sl_mode.prev,
959 struct ldlm_lock, l_sl_mode);
960
961 if (lock->l_req_mode != req->l_req_mode) {
962 /* jump to last lock of mode group */
963 tmp = &mode_end->l_res_link;
964 continue;
965 }
966
967 /* suitable mode group is found */
968 if (lock->l_resource->lr_type == LDLM_PLAIN) {
969 /* insert point is last lock of the mode group */
970 prev->res_link = &mode_end->l_res_link;
971 prev->mode_link = &mode_end->l_sl_mode;
972 prev->policy_link = &req->l_sl_policy;
d7e09d03
PT
973 return;
974 } else if (lock->l_resource->lr_type == LDLM_IBITS) {
975 for (;;) {
976 policy_end =
977 list_entry(lock->l_sl_policy.prev,
978 struct ldlm_lock,
979 l_sl_policy);
980
981 if (lock->l_policy_data.l_inodebits.bits ==
982 req->l_policy_data.l_inodebits.bits) {
983 /* insert point is last lock of
984 * the policy group */
985 prev->res_link =
986 &policy_end->l_res_link;
987 prev->mode_link =
988 &policy_end->l_sl_mode;
989 prev->policy_link =
990 &policy_end->l_sl_policy;
d7e09d03
PT
991 return;
992 }
993
994 if (policy_end == mode_end)
995 /* done with mode group */
996 break;
997
998 /* go to next policy group within mode group */
999 tmp = policy_end->l_res_link.next;
1000 lock = list_entry(tmp, struct ldlm_lock,
1001 l_res_link);
1002 } /* loop over policy groups within the mode group */
1003
1004 /* insert point is last lock of the mode group,
1005 * new policy group is started */
1006 prev->res_link = &mode_end->l_res_link;
1007 prev->mode_link = &mode_end->l_sl_mode;
1008 prev->policy_link = &req->l_sl_policy;
d7e09d03
PT
1009 return;
1010 } else {
1011 LDLM_ERROR(lock,"is not LDLM_PLAIN or LDLM_IBITS lock");
1012 LBUG();
1013 }
1014 }
1015
1016 /* insert point is last lock on the queue,
1017 * new mode group and new policy group are started */
1018 prev->res_link = queue->prev;
1019 prev->mode_link = &req->l_sl_mode;
1020 prev->policy_link = &req->l_sl_policy;
d7e09d03
PT
1021 return;
1022}
1023
1024/**
1025 * Add a lock into resource granted list after a position described by
1026 * \a prev.
1027 */
1028static void ldlm_granted_list_add_lock(struct ldlm_lock *lock,
1029 struct sl_insert_point *prev)
1030{
1031 struct ldlm_resource *res = lock->l_resource;
d7e09d03
PT
1032
1033 check_res_locked(res);
1034
1035 ldlm_resource_dump(D_INFO, res);
1036 LDLM_DEBUG(lock, "About to add lock:");
1037
f2145eae 1038 if (lock->l_flags & LDLM_FL_DESTROYED) {
d7e09d03
PT
1039 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
1040 return;
1041 }
1042
1043 LASSERT(list_empty(&lock->l_res_link));
1044 LASSERT(list_empty(&lock->l_sl_mode));
1045 LASSERT(list_empty(&lock->l_sl_policy));
1046
1047 /*
1048 * lock->link == prev->link means lock is first starting the group.
1049 * Don't re-add to itself to suppress kernel warnings.
1050 */
1051 if (&lock->l_res_link != prev->res_link)
1052 list_add(&lock->l_res_link, prev->res_link);
1053 if (&lock->l_sl_mode != prev->mode_link)
1054 list_add(&lock->l_sl_mode, prev->mode_link);
1055 if (&lock->l_sl_policy != prev->policy_link)
1056 list_add(&lock->l_sl_policy, prev->policy_link);
d7e09d03
PT
1057}
1058
1059/**
1060 * Add a lock to granted list on a resource maintaining skiplist
1061 * correctness.
1062 */
1063static void ldlm_grant_lock_with_skiplist(struct ldlm_lock *lock)
1064{
1065 struct sl_insert_point prev;
d7e09d03
PT
1066
1067 LASSERT(lock->l_req_mode == lock->l_granted_mode);
1068
1069 search_granted_lock(&lock->l_resource->lr_granted, lock, &prev);
1070 ldlm_granted_list_add_lock(lock, &prev);
d7e09d03
PT
1071}
1072
1073/**
1074 * Perform lock granting bookkeeping.
1075 *
1076 * Includes putting the lock into granted list and updating lock mode.
1077 * NOTE: called by
1078 * - ldlm_lock_enqueue
1079 * - ldlm_reprocess_queue
1080 * - ldlm_lock_convert
1081 *
1082 * must be called with lr_lock held
1083 */
1084void ldlm_grant_lock(struct ldlm_lock *lock, struct list_head *work_list)
1085{
1086 struct ldlm_resource *res = lock->l_resource;
d7e09d03
PT
1087
1088 check_res_locked(res);
1089
1090 lock->l_granted_mode = lock->l_req_mode;
1091 if (res->lr_type == LDLM_PLAIN || res->lr_type == LDLM_IBITS)
1092 ldlm_grant_lock_with_skiplist(lock);
1093 else if (res->lr_type == LDLM_EXTENT)
1094 ldlm_extent_add_lock(res, lock);
1095 else
1096 ldlm_resource_add_lock(res, &res->lr_granted, lock);
1097
1098 if (lock->l_granted_mode < res->lr_most_restr)
1099 res->lr_most_restr = lock->l_granted_mode;
1100
1101 if (work_list && lock->l_completion_ast != NULL)
1102 ldlm_add_ast_work_item(lock, NULL, work_list);
1103
1104 ldlm_pool_add(&ldlm_res_to_ns(res)->ns_pool, lock);
d7e09d03
PT
1105}
1106
1107/**
1108 * Search for a lock with given properties in a queue.
1109 *
1110 * \retval a referenced lock or NULL. See the flag descriptions below, in the
1111 * comment above ldlm_lock_match
1112 */
1113static struct ldlm_lock *search_queue(struct list_head *queue,
1114 ldlm_mode_t *mode,
1115 ldlm_policy_data_t *policy,
1116 struct ldlm_lock *old_lock,
1117 __u64 flags, int unref)
1118{
1119 struct ldlm_lock *lock;
1120 struct list_head *tmp;
1121
1122 list_for_each(tmp, queue) {
1123 ldlm_mode_t match;
1124
1125 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
1126
1127 if (lock == old_lock)
1128 break;
1129
d3a8a4e2
JX
1130 /* Check if this lock can be matched.
1131 * Used by LU-2919(exclusive open) for open lease lock */
1132 if (ldlm_is_excl(lock))
1133 continue;
1134
d7e09d03
PT
1135 /* llite sometimes wants to match locks that will be
1136 * canceled when their users drop, but we allow it to match
1137 * if it passes in CBPENDING and the lock still has users.
1138 * this is generally only going to be used by children
1139 * whose parents already hold a lock so forward progress
1140 * can still happen. */
1141 if (lock->l_flags & LDLM_FL_CBPENDING &&
1142 !(flags & LDLM_FL_CBPENDING))
1143 continue;
1144 if (!unref && lock->l_flags & LDLM_FL_CBPENDING &&
1145 lock->l_readers == 0 && lock->l_writers == 0)
1146 continue;
1147
1148 if (!(lock->l_req_mode & *mode))
1149 continue;
1150 match = lock->l_req_mode;
1151
1152 if (lock->l_resource->lr_type == LDLM_EXTENT &&
1153 (lock->l_policy_data.l_extent.start >
1154 policy->l_extent.start ||
1155 lock->l_policy_data.l_extent.end < policy->l_extent.end))
1156 continue;
1157
1158 if (unlikely(match == LCK_GROUP) &&
1159 lock->l_resource->lr_type == LDLM_EXTENT &&
1160 lock->l_policy_data.l_extent.gid != policy->l_extent.gid)
1161 continue;
1162
1163 /* We match if we have existing lock with same or wider set
1164 of bits. */
1165 if (lock->l_resource->lr_type == LDLM_IBITS &&
1166 ((lock->l_policy_data.l_inodebits.bits &
1167 policy->l_inodebits.bits) !=
1168 policy->l_inodebits.bits))
1169 continue;
1170
f2145eae 1171 if (!unref && (lock->l_flags & LDLM_FL_GONE_MASK))
d7e09d03
PT
1172 continue;
1173
1174 if ((flags & LDLM_FL_LOCAL_ONLY) &&
1175 !(lock->l_flags & LDLM_FL_LOCAL))
1176 continue;
1177
1178 if (flags & LDLM_FL_TEST_LOCK) {
1179 LDLM_LOCK_GET(lock);
1180 ldlm_lock_touch_in_lru(lock);
1181 } else {
1182 ldlm_lock_addref_internal_nolock(lock, match);
1183 }
1184 *mode = match;
1185 return lock;
1186 }
1187
1188 return NULL;
1189}
1190
1191void ldlm_lock_fail_match_locked(struct ldlm_lock *lock)
1192{
f2145eae
BK
1193 if ((lock->l_flags & LDLM_FL_FAIL_NOTIFIED) == 0) {
1194 lock->l_flags |= LDLM_FL_FAIL_NOTIFIED;
d7e09d03
PT
1195 wake_up_all(&lock->l_waitq);
1196 }
1197}
1198EXPORT_SYMBOL(ldlm_lock_fail_match_locked);
1199
1200void ldlm_lock_fail_match(struct ldlm_lock *lock)
1201{
1202 lock_res_and_lock(lock);
1203 ldlm_lock_fail_match_locked(lock);
1204 unlock_res_and_lock(lock);
1205}
1206EXPORT_SYMBOL(ldlm_lock_fail_match);
1207
1208/**
1209 * Mark lock as "matchable" by OST.
1210 *
1211 * Used to prevent certain races in LOV/OSC where the lock is granted, but LVB
1212 * is not yet valid.
1213 * Assumes LDLM lock is already locked.
1214 */
1215void ldlm_lock_allow_match_locked(struct ldlm_lock *lock)
1216{
1217 lock->l_flags |= LDLM_FL_LVB_READY;
1218 wake_up_all(&lock->l_waitq);
1219}
1220EXPORT_SYMBOL(ldlm_lock_allow_match_locked);
1221
1222/**
1223 * Mark lock as "matchable" by OST.
1224 * Locks the lock and then \see ldlm_lock_allow_match_locked
1225 */
1226void ldlm_lock_allow_match(struct ldlm_lock *lock)
1227{
1228 lock_res_and_lock(lock);
1229 ldlm_lock_allow_match_locked(lock);
1230 unlock_res_and_lock(lock);
1231}
1232EXPORT_SYMBOL(ldlm_lock_allow_match);
1233
1234/**
1235 * Attempt to find a lock with specified properties.
1236 *
1237 * Typically returns a reference to matched lock unless LDLM_FL_TEST_LOCK is
1238 * set in \a flags
1239 *
1240 * Can be called in two ways:
1241 *
1242 * If 'ns' is NULL, then lockh describes an existing lock that we want to look
1243 * for a duplicate of.
1244 *
1245 * Otherwise, all of the fields must be filled in, to match against.
1246 *
1247 * If 'flags' contains LDLM_FL_LOCAL_ONLY, then only match local locks on the
1248 * server (ie, connh is NULL)
1249 * If 'flags' contains LDLM_FL_BLOCK_GRANTED, then only locks on the granted
1250 * list will be considered
1251 * If 'flags' contains LDLM_FL_CBPENDING, then locks that have been marked
1252 * to be canceled can still be matched as long as they still have reader
6e3dd654 1253 * or writer referneces
d7e09d03
PT
1254 * If 'flags' contains LDLM_FL_TEST_LOCK, then don't actually reference a lock,
1255 * just tell us if we would have matched.
1256 *
1257 * \retval 1 if it finds an already-existing lock that is compatible; in this
1258 * case, lockh is filled in with a addref()ed lock
1259 *
1260 * We also check security context, and if that fails we simply return 0 (to
1261 * keep caller code unchanged), the context failure will be discovered by
1262 * caller sometime later.
1263 */
1264ldlm_mode_t ldlm_lock_match(struct ldlm_namespace *ns, __u64 flags,
1265 const struct ldlm_res_id *res_id, ldlm_type_t type,
1266 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1267 struct lustre_handle *lockh, int unref)
1268{
1269 struct ldlm_resource *res;
1270 struct ldlm_lock *lock, *old_lock = NULL;
1271 int rc = 0;
d7e09d03
PT
1272
1273 if (ns == NULL) {
1274 old_lock = ldlm_handle2lock(lockh);
1275 LASSERT(old_lock);
1276
1277 ns = ldlm_lock_to_ns(old_lock);
1278 res_id = &old_lock->l_resource->lr_name;
1279 type = old_lock->l_resource->lr_type;
1280 mode = old_lock->l_req_mode;
1281 }
1282
1283 res = ldlm_resource_get(ns, NULL, res_id, type, 0);
1284 if (res == NULL) {
1285 LASSERT(old_lock == NULL);
0a3bdb00 1286 return 0;
d7e09d03
PT
1287 }
1288
1289 LDLM_RESOURCE_ADDREF(res);
1290 lock_res(res);
1291
1292 lock = search_queue(&res->lr_granted, &mode, policy, old_lock,
1293 flags, unref);
1294 if (lock != NULL)
1295 GOTO(out, rc = 1);
1296 if (flags & LDLM_FL_BLOCK_GRANTED)
1297 GOTO(out, rc = 0);
1298 lock = search_queue(&res->lr_converting, &mode, policy, old_lock,
1299 flags, unref);
1300 if (lock != NULL)
1301 GOTO(out, rc = 1);
1302 lock = search_queue(&res->lr_waiting, &mode, policy, old_lock,
1303 flags, unref);
1304 if (lock != NULL)
1305 GOTO(out, rc = 1);
1306
d7e09d03
PT
1307 out:
1308 unlock_res(res);
1309 LDLM_RESOURCE_DELREF(res);
1310 ldlm_resource_putref(res);
1311
1312 if (lock) {
1313 ldlm_lock2handle(lock, lockh);
1314 if ((flags & LDLM_FL_LVB_READY) &&
1315 (!(lock->l_flags & LDLM_FL_LVB_READY))) {
f2145eae
BK
1316 __u64 wait_flags = LDLM_FL_LVB_READY |
1317 LDLM_FL_DESTROYED | LDLM_FL_FAIL_NOTIFIED;
d7e09d03
PT
1318 struct l_wait_info lwi;
1319 if (lock->l_completion_ast) {
1320 int err = lock->l_completion_ast(lock,
1321 LDLM_FL_WAIT_NOREPROC,
1322 NULL);
1323 if (err) {
1324 if (flags & LDLM_FL_TEST_LOCK)
1325 LDLM_LOCK_RELEASE(lock);
1326 else
1327 ldlm_lock_decref_internal(lock,
1328 mode);
1329 rc = 0;
1330 goto out2;
1331 }
1332 }
1333
1334 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(obd_timeout),
1335 NULL, LWI_ON_SIGNAL_NOOP, NULL);
1336
1337 /* XXX FIXME see comment on CAN_MATCH in lustre_dlm.h */
1338 l_wait_event(lock->l_waitq,
f2145eae 1339 lock->l_flags & wait_flags,
d7e09d03
PT
1340 &lwi);
1341 if (!(lock->l_flags & LDLM_FL_LVB_READY)) {
1342 if (flags & LDLM_FL_TEST_LOCK)
1343 LDLM_LOCK_RELEASE(lock);
1344 else
1345 ldlm_lock_decref_internal(lock, mode);
1346 rc = 0;
1347 }
1348 }
1349 }
1350 out2:
1351 if (rc) {
b0f5aad5 1352 LDLM_DEBUG(lock, "matched (%llu %llu)",
d7e09d03
PT
1353 (type == LDLM_PLAIN || type == LDLM_IBITS) ?
1354 res_id->name[2] : policy->l_extent.start,
1355 (type == LDLM_PLAIN || type == LDLM_IBITS) ?
1356 res_id->name[3] : policy->l_extent.end);
1357
1358 /* check user's security context */
1359 if (lock->l_conn_export &&
1360 sptlrpc_import_check_ctx(
1361 class_exp2cliimp(lock->l_conn_export))) {
1362 if (!(flags & LDLM_FL_TEST_LOCK))
1363 ldlm_lock_decref_internal(lock, mode);
1364 rc = 0;
1365 }
1366
1367 if (flags & LDLM_FL_TEST_LOCK)
1368 LDLM_LOCK_RELEASE(lock);
1369
1370 } else if (!(flags & LDLM_FL_TEST_LOCK)) {/*less verbose for test-only*/
b0f5aad5
GKH
1371 LDLM_DEBUG_NOLOCK("not matched ns %p type %u mode %u res %llu/%llu (%llu %llu)",
1372 ns, type, mode, res_id->name[0], res_id->name[1],
d7e09d03
PT
1373 (type == LDLM_PLAIN || type == LDLM_IBITS) ?
1374 res_id->name[2] :policy->l_extent.start,
1375 (type == LDLM_PLAIN || type == LDLM_IBITS) ?
1376 res_id->name[3] : policy->l_extent.end);
1377 }
1378 if (old_lock)
1379 LDLM_LOCK_PUT(old_lock);
1380
1381 return rc ? mode : 0;
1382}
1383EXPORT_SYMBOL(ldlm_lock_match);
1384
1385ldlm_mode_t ldlm_revalidate_lock_handle(struct lustre_handle *lockh,
1386 __u64 *bits)
1387{
1388 struct ldlm_lock *lock;
1389 ldlm_mode_t mode = 0;
d7e09d03
PT
1390
1391 lock = ldlm_handle2lock(lockh);
1392 if (lock != NULL) {
1393 lock_res_and_lock(lock);
f2145eae 1394 if (lock->l_flags & LDLM_FL_GONE_MASK)
d7e09d03
PT
1395 GOTO(out, mode);
1396
1397 if (lock->l_flags & LDLM_FL_CBPENDING &&
1398 lock->l_readers == 0 && lock->l_writers == 0)
1399 GOTO(out, mode);
1400
1401 if (bits)
1402 *bits = lock->l_policy_data.l_inodebits.bits;
1403 mode = lock->l_granted_mode;
1404 ldlm_lock_addref_internal_nolock(lock, mode);
1405 }
1406
d7e09d03
PT
1407out:
1408 if (lock != NULL) {
1409 unlock_res_and_lock(lock);
1410 LDLM_LOCK_PUT(lock);
1411 }
1412 return mode;
1413}
1414EXPORT_SYMBOL(ldlm_revalidate_lock_handle);
1415
1416/** The caller must guarantee that the buffer is large enough. */
1417int ldlm_fill_lvb(struct ldlm_lock *lock, struct req_capsule *pill,
1418 enum req_location loc, void *data, int size)
1419{
1420 void *lvb;
d7e09d03
PT
1421
1422 LASSERT(data != NULL);
1423 LASSERT(size >= 0);
1424
1425 switch (lock->l_lvb_type) {
1426 case LVB_T_OST:
1427 if (size == sizeof(struct ost_lvb)) {
1428 if (loc == RCL_CLIENT)
1429 lvb = req_capsule_client_swab_get(pill,
1430 &RMF_DLM_LVB,
1431 lustre_swab_ost_lvb);
1432 else
1433 lvb = req_capsule_server_swab_get(pill,
1434 &RMF_DLM_LVB,
1435 lustre_swab_ost_lvb);
1436 if (unlikely(lvb == NULL)) {
1437 LDLM_ERROR(lock, "no LVB");
0a3bdb00 1438 return -EPROTO;
d7e09d03
PT
1439 }
1440
1441 memcpy(data, lvb, size);
1442 } else if (size == sizeof(struct ost_lvb_v1)) {
1443 struct ost_lvb *olvb = data;
1444
1445 if (loc == RCL_CLIENT)
1446 lvb = req_capsule_client_swab_get(pill,
1447 &RMF_DLM_LVB,
1448 lustre_swab_ost_lvb_v1);
1449 else
1450 lvb = req_capsule_server_sized_swab_get(pill,
1451 &RMF_DLM_LVB, size,
1452 lustre_swab_ost_lvb_v1);
1453 if (unlikely(lvb == NULL)) {
1454 LDLM_ERROR(lock, "no LVB");
0a3bdb00 1455 return -EPROTO;
d7e09d03
PT
1456 }
1457
1458 memcpy(data, lvb, size);
1459 olvb->lvb_mtime_ns = 0;
1460 olvb->lvb_atime_ns = 0;
1461 olvb->lvb_ctime_ns = 0;
1462 } else {
1463 LDLM_ERROR(lock, "Replied unexpected ost LVB size %d",
1464 size);
0a3bdb00 1465 return -EINVAL;
d7e09d03
PT
1466 }
1467 break;
1468 case LVB_T_LQUOTA:
1469 if (size == sizeof(struct lquota_lvb)) {
1470 if (loc == RCL_CLIENT)
1471 lvb = req_capsule_client_swab_get(pill,
1472 &RMF_DLM_LVB,
1473 lustre_swab_lquota_lvb);
1474 else
1475 lvb = req_capsule_server_swab_get(pill,
1476 &RMF_DLM_LVB,
1477 lustre_swab_lquota_lvb);
1478 if (unlikely(lvb == NULL)) {
1479 LDLM_ERROR(lock, "no LVB");
0a3bdb00 1480 return -EPROTO;
d7e09d03
PT
1481 }
1482
1483 memcpy(data, lvb, size);
1484 } else {
1485 LDLM_ERROR(lock, "Replied unexpected lquota LVB size %d",
1486 size);
0a3bdb00 1487 return -EINVAL;
d7e09d03
PT
1488 }
1489 break;
1490 case LVB_T_LAYOUT:
1491 if (size == 0)
1492 break;
1493
1494 if (loc == RCL_CLIENT)
1495 lvb = req_capsule_client_get(pill, &RMF_DLM_LVB);
1496 else
1497 lvb = req_capsule_server_get(pill, &RMF_DLM_LVB);
1498 if (unlikely(lvb == NULL)) {
1499 LDLM_ERROR(lock, "no LVB");
0a3bdb00 1500 return -EPROTO;
d7e09d03
PT
1501 }
1502
1503 memcpy(data, lvb, size);
1504 break;
1505 default:
1506 LDLM_ERROR(lock, "Unknown LVB type: %d\n", lock->l_lvb_type);
5d4450c4 1507 dump_stack();
0a3bdb00 1508 return -EINVAL;
d7e09d03
PT
1509 }
1510
0a3bdb00 1511 return 0;
d7e09d03
PT
1512}
1513
1514/**
1515 * Create and fill in new LDLM lock with specified properties.
1516 * Returns a referenced lock
1517 */
1518struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
1519 const struct ldlm_res_id *res_id,
1520 ldlm_type_t type,
1521 ldlm_mode_t mode,
1522 const struct ldlm_callback_suite *cbs,
1523 void *data, __u32 lvb_len,
1524 enum lvb_type lvb_type)
1525{
1526 struct ldlm_lock *lock;
1527 struct ldlm_resource *res;
d7e09d03
PT
1528
1529 res = ldlm_resource_get(ns, NULL, res_id, type, 1);
1530 if (res == NULL)
0a3bdb00 1531 return NULL;
d7e09d03
PT
1532
1533 lock = ldlm_lock_new(res);
1534
1535 if (lock == NULL)
0a3bdb00 1536 return NULL;
d7e09d03
PT
1537
1538 lock->l_req_mode = mode;
1539 lock->l_ast_data = data;
1540 lock->l_pid = current_pid();
f2145eae
BK
1541 if (ns_is_server(ns))
1542 lock->l_flags |= LDLM_FL_NS_SRV;
d7e09d03
PT
1543 if (cbs) {
1544 lock->l_blocking_ast = cbs->lcs_blocking;
1545 lock->l_completion_ast = cbs->lcs_completion;
1546 lock->l_glimpse_ast = cbs->lcs_glimpse;
d7e09d03
PT
1547 }
1548
1549 lock->l_tree_node = NULL;
1550 /* if this is the extent lock, allocate the interval tree node */
1551 if (type == LDLM_EXTENT) {
1552 if (ldlm_interval_alloc(lock) == NULL)
1553 GOTO(out, 0);
1554 }
1555
1556 if (lvb_len) {
1557 lock->l_lvb_len = lvb_len;
1558 OBD_ALLOC(lock->l_lvb_data, lvb_len);
1559 if (lock->l_lvb_data == NULL)
1560 GOTO(out, 0);
1561 }
1562
1563 lock->l_lvb_type = lvb_type;
1564 if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_NEW_LOCK))
1565 GOTO(out, 0);
1566
0a3bdb00 1567 return lock;
d7e09d03
PT
1568
1569out:
1570 ldlm_lock_destroy(lock);
1571 LDLM_LOCK_RELEASE(lock);
1572 return NULL;
1573}
1574
1575/**
1576 * Enqueue (request) a lock.
1577 *
1578 * Does not block. As a result of enqueue the lock would be put
1579 * into granted or waiting list.
1580 *
1581 * If namespace has intent policy sent and the lock has LDLM_FL_HAS_INTENT flag
1582 * set, skip all the enqueueing and delegate lock processing to intent policy
1583 * function.
1584 */
1585ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
1586 struct ldlm_lock **lockp,
1587 void *cookie, __u64 *flags)
1588{
1589 struct ldlm_lock *lock = *lockp;
1590 struct ldlm_resource *res = lock->l_resource;
1591 int local = ns_is_client(ldlm_res_to_ns(res));
1592 ldlm_error_t rc = ELDLM_OK;
1593 struct ldlm_interval *node = NULL;
d7e09d03 1594
7264b8a5 1595 lock->l_last_activity = get_seconds();
d7e09d03
PT
1596 /* policies are not executed on the client or during replay */
1597 if ((*flags & (LDLM_FL_HAS_INTENT|LDLM_FL_REPLAY)) == LDLM_FL_HAS_INTENT
1598 && !local && ns->ns_policy) {
1599 rc = ns->ns_policy(ns, lockp, cookie, lock->l_req_mode, *flags,
1600 NULL);
1601 if (rc == ELDLM_LOCK_REPLACED) {
1602 /* The lock that was returned has already been granted,
1603 * and placed into lockp. If it's not the same as the
1604 * one we passed in, then destroy the old one and our
1605 * work here is done. */
1606 if (lock != *lockp) {
1607 ldlm_lock_destroy(lock);
1608 LDLM_LOCK_RELEASE(lock);
1609 }
1610 *flags |= LDLM_FL_LOCK_CHANGED;
0a3bdb00 1611 return 0;
d7e09d03
PT
1612 } else if (rc != ELDLM_OK ||
1613 (rc == ELDLM_OK && (*flags & LDLM_FL_INTENT_ONLY))) {
1614 ldlm_lock_destroy(lock);
0a3bdb00 1615 return rc;
d7e09d03
PT
1616 }
1617 }
1618
1619 /* For a replaying lock, it might be already in granted list. So
1620 * unlinking the lock will cause the interval node to be freed, we
1621 * have to allocate the interval node early otherwise we can't regrant
1622 * this lock in the future. - jay */
1623 if (!local && (*flags & LDLM_FL_REPLAY) && res->lr_type == LDLM_EXTENT)
0be19afa 1624 OBD_SLAB_ALLOC_PTR_GFP(node, ldlm_interval_slab, GFP_NOFS);
d7e09d03
PT
1625
1626 lock_res_and_lock(lock);
1627 if (local && lock->l_req_mode == lock->l_granted_mode) {
1628 /* The server returned a blocked lock, but it was granted
1629 * before we got a chance to actually enqueue it. We don't
1630 * need to do anything else. */
1631 *flags &= ~(LDLM_FL_BLOCK_GRANTED |
1632 LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_WAIT);
1633 GOTO(out, ELDLM_OK);
1634 }
1635
1636 ldlm_resource_unlink_lock(lock);
1637 if (res->lr_type == LDLM_EXTENT && lock->l_tree_node == NULL) {
1638 if (node == NULL) {
1639 ldlm_lock_destroy_nolock(lock);
1640 GOTO(out, rc = -ENOMEM);
1641 }
1642
1643 INIT_LIST_HEAD(&node->li_group);
1644 ldlm_interval_attach(node, lock);
1645 node = NULL;
1646 }
1647
1648 /* Some flags from the enqueue want to make it into the AST, via the
1649 * lock's l_flags. */
f2145eae 1650 lock->l_flags |= *flags & LDLM_FL_AST_DISCARD_DATA;
d7e09d03
PT
1651
1652 /* This distinction between local lock trees is very important; a client
1653 * namespace only has information about locks taken by that client, and
1654 * thus doesn't have enough information to decide for itself if it can
1655 * be granted (below). In this case, we do exactly what the server
1656 * tells us to do, as dictated by the 'flags'.
1657 *
1658 * We do exactly the same thing during recovery, when the server is
1659 * more or less trusting the clients not to lie.
1660 *
1661 * FIXME (bug 268): Detect obvious lies by checking compatibility in
1662 * granted/converting queues. */
1663 if (local) {
1664 if (*flags & LDLM_FL_BLOCK_CONV)
1665 ldlm_resource_add_lock(res, &res->lr_converting, lock);
1666 else if (*flags & (LDLM_FL_BLOCK_WAIT | LDLM_FL_BLOCK_GRANTED))
1667 ldlm_resource_add_lock(res, &res->lr_waiting, lock);
1668 else
1669 ldlm_grant_lock(lock, NULL);
1670 GOTO(out, ELDLM_OK);
1671 } else {
1672 CERROR("This is client-side-only module, cannot handle "
1673 "LDLM_NAMESPACE_SERVER resource type lock.\n");
1674 LBUG();
1675 }
1676
1677out:
1678 unlock_res_and_lock(lock);
1679 if (node)
1680 OBD_SLAB_FREE(node, ldlm_interval_slab, sizeof(*node));
1681 return rc;
1682}
1683
1684
1685/**
1686 * Process a call to blocking AST callback for a lock in ast_work list
1687 */
1688static int
1689ldlm_work_bl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1690{
1691 struct ldlm_cb_set_arg *arg = opaq;
1692 struct ldlm_lock_desc d;
1693 int rc;
1694 struct ldlm_lock *lock;
d7e09d03
PT
1695
1696 if (list_empty(arg->list))
0a3bdb00 1697 return -ENOENT;
d7e09d03
PT
1698
1699 lock = list_entry(arg->list->next, struct ldlm_lock, l_bl_ast);
1700
1701 /* nobody should touch l_bl_ast */
1702 lock_res_and_lock(lock);
1703 list_del_init(&lock->l_bl_ast);
1704
1705 LASSERT(lock->l_flags & LDLM_FL_AST_SENT);
1706 LASSERT(lock->l_bl_ast_run == 0);
1707 LASSERT(lock->l_blocking_lock);
1708 lock->l_bl_ast_run++;
1709 unlock_res_and_lock(lock);
1710
1711 ldlm_lock2desc(lock->l_blocking_lock, &d);
1712
1713 rc = lock->l_blocking_ast(lock, &d, (void *)arg, LDLM_CB_BLOCKING);
1714 LDLM_LOCK_RELEASE(lock->l_blocking_lock);
1715 lock->l_blocking_lock = NULL;
1716 LDLM_LOCK_RELEASE(lock);
1717
0a3bdb00 1718 return rc;
d7e09d03
PT
1719}
1720
1721/**
1722 * Process a call to completion AST callback for a lock in ast_work list
1723 */
1724static int
1725ldlm_work_cp_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1726{
1727 struct ldlm_cb_set_arg *arg = opaq;
1728 int rc = 0;
1729 struct ldlm_lock *lock;
1730 ldlm_completion_callback completion_callback;
d7e09d03
PT
1731
1732 if (list_empty(arg->list))
0a3bdb00 1733 return -ENOENT;
d7e09d03
PT
1734
1735 lock = list_entry(arg->list->next, struct ldlm_lock, l_cp_ast);
1736
1737 /* It's possible to receive a completion AST before we've set
1738 * the l_completion_ast pointer: either because the AST arrived
1739 * before the reply, or simply because there's a small race
1740 * window between receiving the reply and finishing the local
1741 * enqueue. (bug 842)
1742 *
1743 * This can't happen with the blocking_ast, however, because we
1744 * will never call the local blocking_ast until we drop our
1745 * reader/writer reference, which we won't do until we get the
1746 * reply and finish enqueueing. */
1747
1748 /* nobody should touch l_cp_ast */
1749 lock_res_and_lock(lock);
1750 list_del_init(&lock->l_cp_ast);
1751 LASSERT(lock->l_flags & LDLM_FL_CP_REQD);
1752 /* save l_completion_ast since it can be changed by
1753 * mds_intent_policy(), see bug 14225 */
1754 completion_callback = lock->l_completion_ast;
1755 lock->l_flags &= ~LDLM_FL_CP_REQD;
1756 unlock_res_and_lock(lock);
1757
1758 if (completion_callback != NULL)
1759 rc = completion_callback(lock, 0, (void *)arg);
1760 LDLM_LOCK_RELEASE(lock);
1761
0a3bdb00 1762 return rc;
d7e09d03
PT
1763}
1764
1765/**
1766 * Process a call to revocation AST callback for a lock in ast_work list
1767 */
1768static int
1769ldlm_work_revoke_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1770{
1771 struct ldlm_cb_set_arg *arg = opaq;
1772 struct ldlm_lock_desc desc;
1773 int rc;
1774 struct ldlm_lock *lock;
d7e09d03
PT
1775
1776 if (list_empty(arg->list))
0a3bdb00 1777 return -ENOENT;
d7e09d03
PT
1778
1779 lock = list_entry(arg->list->next, struct ldlm_lock, l_rk_ast);
1780 list_del_init(&lock->l_rk_ast);
1781
1782 /* the desc just pretend to exclusive */
1783 ldlm_lock2desc(lock, &desc);
1784 desc.l_req_mode = LCK_EX;
1785 desc.l_granted_mode = 0;
1786
1787 rc = lock->l_blocking_ast(lock, &desc, (void*)arg, LDLM_CB_BLOCKING);
1788 LDLM_LOCK_RELEASE(lock);
1789
0a3bdb00 1790 return rc;
d7e09d03
PT
1791}
1792
1793/**
1794 * Process a call to glimpse AST callback for a lock in ast_work list
1795 */
1796int ldlm_work_gl_ast_lock(struct ptlrpc_request_set *rqset, void *opaq)
1797{
1798 struct ldlm_cb_set_arg *arg = opaq;
1799 struct ldlm_glimpse_work *gl_work;
1800 struct ldlm_lock *lock;
1801 int rc = 0;
d7e09d03
PT
1802
1803 if (list_empty(arg->list))
0a3bdb00 1804 return -ENOENT;
d7e09d03
PT
1805
1806 gl_work = list_entry(arg->list->next, struct ldlm_glimpse_work,
1807 gl_list);
1808 list_del_init(&gl_work->gl_list);
1809
1810 lock = gl_work->gl_lock;
1811
1812 /* transfer the glimpse descriptor to ldlm_cb_set_arg */
1813 arg->gl_desc = gl_work->gl_desc;
1814
1815 /* invoke the actual glimpse callback */
1816 if (lock->l_glimpse_ast(lock, (void*)arg) == 0)
1817 rc = 1;
1818
1819 LDLM_LOCK_RELEASE(lock);
1820
1821 if ((gl_work->gl_flags & LDLM_GL_WORK_NOFREE) == 0)
1822 OBD_FREE_PTR(gl_work);
1823
0a3bdb00 1824 return rc;
d7e09d03
PT
1825}
1826
1827/**
1828 * Process list of locks in need of ASTs being sent.
1829 *
1830 * Used on server to send multiple ASTs together instead of sending one by
1831 * one.
1832 */
1833int ldlm_run_ast_work(struct ldlm_namespace *ns, struct list_head *rpc_list,
1834 ldlm_desc_ast_t ast_type)
1835{
1836 struct ldlm_cb_set_arg *arg;
1837 set_producer_func work_ast_lock;
1838 int rc;
1839
1840 if (list_empty(rpc_list))
0a3bdb00 1841 return 0;
d7e09d03
PT
1842
1843 OBD_ALLOC_PTR(arg);
1844 if (arg == NULL)
0a3bdb00 1845 return -ENOMEM;
d7e09d03
PT
1846
1847 atomic_set(&arg->restart, 0);
1848 arg->list = rpc_list;
1849
1850 switch (ast_type) {
1851 case LDLM_WORK_BL_AST:
1852 arg->type = LDLM_BL_CALLBACK;
1853 work_ast_lock = ldlm_work_bl_ast_lock;
1854 break;
1855 case LDLM_WORK_CP_AST:
1856 arg->type = LDLM_CP_CALLBACK;
1857 work_ast_lock = ldlm_work_cp_ast_lock;
1858 break;
1859 case LDLM_WORK_REVOKE_AST:
1860 arg->type = LDLM_BL_CALLBACK;
1861 work_ast_lock = ldlm_work_revoke_ast_lock;
1862 break;
1863 case LDLM_WORK_GL_AST:
1864 arg->type = LDLM_GL_CALLBACK;
1865 work_ast_lock = ldlm_work_gl_ast_lock;
1866 break;
1867 default:
1868 LBUG();
1869 }
1870
1871 /* We create a ptlrpc request set with flow control extension.
1872 * This request set will use the work_ast_lock function to produce new
1873 * requests and will send a new request each time one completes in order
1874 * to keep the number of requests in flight to ns_max_parallel_ast */
1875 arg->set = ptlrpc_prep_fcset(ns->ns_max_parallel_ast ? : UINT_MAX,
1876 work_ast_lock, arg);
1877 if (arg->set == NULL)
1878 GOTO(out, rc = -ENOMEM);
1879
1880 ptlrpc_set_wait(arg->set);
1881 ptlrpc_set_destroy(arg->set);
1882
1883 rc = atomic_read(&arg->restart) ? -ERESTART : 0;
1884 GOTO(out, rc);
1885out:
1886 OBD_FREE_PTR(arg);
1887 return rc;
1888}
1889
1890static int reprocess_one_queue(struct ldlm_resource *res, void *closure)
1891{
1892 ldlm_reprocess_all(res);
1893 return LDLM_ITER_CONTINUE;
1894}
1895
6da6eabe 1896static int ldlm_reprocess_res(struct cfs_hash *hs, struct cfs_hash_bd *bd,
d7e09d03
PT
1897 struct hlist_node *hnode, void *arg)
1898{
1899 struct ldlm_resource *res = cfs_hash_object(hs, hnode);
1900 int rc;
1901
1902 rc = reprocess_one_queue(res, arg);
1903
1904 return rc == LDLM_ITER_STOP;
1905}
1906
1907/**
1908 * Iterate through all resources on a namespace attempting to grant waiting
1909 * locks.
1910 */
1911void ldlm_reprocess_all_ns(struct ldlm_namespace *ns)
1912{
d7e09d03
PT
1913 if (ns != NULL) {
1914 cfs_hash_for_each_nolock(ns->ns_rs_hash,
1915 ldlm_reprocess_res, NULL);
1916 }
d7e09d03
PT
1917}
1918EXPORT_SYMBOL(ldlm_reprocess_all_ns);
1919
1920/**
1921 * Try to grant all waiting locks on a resource.
1922 *
1923 * Calls ldlm_reprocess_queue on converting and waiting queues.
1924 *
1925 * Typically called after some resource locks are cancelled to see
1926 * if anything could be granted as a result of the cancellation.
1927 */
1928void ldlm_reprocess_all(struct ldlm_resource *res)
1929{
1930 LIST_HEAD(rpc_list);
1931
d7e09d03
PT
1932 if (!ns_is_client(ldlm_res_to_ns(res))) {
1933 CERROR("This is client-side-only module, cannot handle "
1934 "LDLM_NAMESPACE_SERVER resource type lock.\n");
1935 LBUG();
1936 }
d7e09d03
PT
1937}
1938
1939/**
1940 * Helper function to call blocking AST for LDLM lock \a lock in a
1941 * "cancelling" mode.
1942 */
1943void ldlm_cancel_callback(struct ldlm_lock *lock)
1944{
1945 check_res_locked(lock->l_resource);
1946 if (!(lock->l_flags & LDLM_FL_CANCEL)) {
1947 lock->l_flags |= LDLM_FL_CANCEL;
1948 if (lock->l_blocking_ast) {
1949 unlock_res_and_lock(lock);
1950 lock->l_blocking_ast(lock, NULL, lock->l_ast_data,
1951 LDLM_CB_CANCELING);
1952 lock_res_and_lock(lock);
1953 } else {
1954 LDLM_DEBUG(lock, "no blocking ast");
1955 }
1956 }
1957 lock->l_flags |= LDLM_FL_BL_DONE;
1958}
1959
1960/**
1961 * Remove skiplist-enabled LDLM lock \a req from granted list
1962 */
1963void ldlm_unlink_lock_skiplist(struct ldlm_lock *req)
1964{
1965 if (req->l_resource->lr_type != LDLM_PLAIN &&
1966 req->l_resource->lr_type != LDLM_IBITS)
1967 return;
1968
1969 list_del_init(&req->l_sl_policy);
1970 list_del_init(&req->l_sl_mode);
1971}
1972
1973/**
1974 * Attempts to cancel LDLM lock \a lock that has no reader/writer references.
1975 */
1976void ldlm_lock_cancel(struct ldlm_lock *lock)
1977{
1978 struct ldlm_resource *res;
1979 struct ldlm_namespace *ns;
d7e09d03
PT
1980
1981 lock_res_and_lock(lock);
1982
1983 res = lock->l_resource;
1984 ns = ldlm_res_to_ns(res);
1985
1986 /* Please do not, no matter how tempting, remove this LBUG without
1987 * talking to me first. -phik */
1988 if (lock->l_readers || lock->l_writers) {
1989 LDLM_ERROR(lock, "lock still has references");
1990 LBUG();
1991 }
1992
f2145eae 1993 if (lock->l_flags & LDLM_FL_WAITED)
d7e09d03
PT
1994 ldlm_del_waiting_lock(lock);
1995
1996 /* Releases cancel callback. */
1997 ldlm_cancel_callback(lock);
1998
1999 /* Yes, second time, just in case it was added again while we were
f2145eae
BK
2000 * running with no res lock in ldlm_cancel_callback */
2001 if (lock->l_flags & LDLM_FL_WAITED)
d7e09d03
PT
2002 ldlm_del_waiting_lock(lock);
2003
2004 ldlm_resource_unlink_lock(lock);
2005 ldlm_lock_destroy_nolock(lock);
2006
2007 if (lock->l_granted_mode == lock->l_req_mode)
2008 ldlm_pool_del(&ns->ns_pool, lock);
2009
2010 /* Make sure we will not be called again for same lock what is possible
2011 * if not to zero out lock->l_granted_mode */
2012 lock->l_granted_mode = LCK_MINMODE;
2013 unlock_res_and_lock(lock);
d7e09d03
PT
2014}
2015EXPORT_SYMBOL(ldlm_lock_cancel);
2016
2017/**
2018 * Set opaque data into the lock that only makes sense to upper layer.
2019 */
2020int ldlm_lock_set_data(struct lustre_handle *lockh, void *data)
2021{
2022 struct ldlm_lock *lock = ldlm_handle2lock(lockh);
2023 int rc = -EINVAL;
d7e09d03
PT
2024
2025 if (lock) {
2026 if (lock->l_ast_data == NULL)
2027 lock->l_ast_data = data;
2028 if (lock->l_ast_data == data)
2029 rc = 0;
2030 LDLM_LOCK_PUT(lock);
2031 }
0a3bdb00 2032 return rc;
d7e09d03
PT
2033}
2034EXPORT_SYMBOL(ldlm_lock_set_data);
2035
2036struct export_cl_data {
2037 struct obd_export *ecl_exp;
2038 int ecl_loop;
2039};
2040
2041/**
2042 * Iterator function for ldlm_cancel_locks_for_export.
2043 * Cancels passed locks.
2044 */
6da6eabe 2045int ldlm_cancel_locks_for_export_cb(struct cfs_hash *hs, struct cfs_hash_bd *bd,
d7e09d03
PT
2046 struct hlist_node *hnode, void *data)
2047
2048{
2049 struct export_cl_data *ecl = (struct export_cl_data *)data;
2050 struct obd_export *exp = ecl->ecl_exp;
2051 struct ldlm_lock *lock = cfs_hash_object(hs, hnode);
2052 struct ldlm_resource *res;
2053
2054 res = ldlm_resource_getref(lock->l_resource);
2055 LDLM_LOCK_GET(lock);
2056
2057 LDLM_DEBUG(lock, "export %p", exp);
2058 ldlm_res_lvbo_update(res, NULL, 1);
2059 ldlm_lock_cancel(lock);
2060 ldlm_reprocess_all(res);
2061 ldlm_resource_putref(res);
2062 LDLM_LOCK_RELEASE(lock);
2063
2064 ecl->ecl_loop++;
2065 if ((ecl->ecl_loop & -ecl->ecl_loop) == ecl->ecl_loop) {
2066 CDEBUG(D_INFO,
2067 "Cancel lock %p for export %p (loop %d), still have "
2068 "%d locks left on hash table.\n",
2069 lock, exp, ecl->ecl_loop,
2070 atomic_read(&hs->hs_count));
2071 }
2072
2073 return 0;
2074}
2075
2076/**
2077 * Cancel all locks for given export.
2078 *
2079 * Typically called on client disconnection/eviction
2080 */
2081void ldlm_cancel_locks_for_export(struct obd_export *exp)
2082{
2083 struct export_cl_data ecl = {
2084 .ecl_exp = exp,
2085 .ecl_loop = 0,
2086 };
2087
2088 cfs_hash_for_each_empty(exp->exp_lock_hash,
2089 ldlm_cancel_locks_for_export_cb, &ecl);
2090}
2091
2092/**
2093 * Downgrade an exclusive lock.
2094 *
6e3dd654
MI
2095 * A fast variant of ldlm_lock_convert for conversion of exclusive
2096 * locks. The conversion is always successful.
d7e09d03
PT
2097 * Used by Commit on Sharing (COS) code.
2098 *
2099 * \param lock A lock to convert
2100 * \param new_mode new lock mode
2101 */
2102void ldlm_lock_downgrade(struct ldlm_lock *lock, int new_mode)
2103{
d7e09d03
PT
2104 LASSERT(lock->l_granted_mode & (LCK_PW | LCK_EX));
2105 LASSERT(new_mode == LCK_COS);
2106
2107 lock_res_and_lock(lock);
2108 ldlm_resource_unlink_lock(lock);
2109 /*
2110 * Remove the lock from pool as it will be added again in
2111 * ldlm_grant_lock() called below.
2112 */
2113 ldlm_pool_del(&ldlm_lock_to_ns(lock)->ns_pool, lock);
2114
2115 lock->l_req_mode = new_mode;
2116 ldlm_grant_lock(lock, NULL);
2117 unlock_res_and_lock(lock);
2118 ldlm_reprocess_all(lock->l_resource);
d7e09d03
PT
2119}
2120EXPORT_SYMBOL(ldlm_lock_downgrade);
2121
2122/**
2123 * Attempt to convert already granted lock to a different mode.
2124 *
2125 * While lock conversion is not currently used, future client-side
2126 * optimizations could take advantage of it to avoid discarding cached
2127 * pages on a file.
2128 */
2129struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
2130 __u32 *flags)
2131{
2132 LIST_HEAD(rpc_list);
2133 struct ldlm_resource *res;
2134 struct ldlm_namespace *ns;
2135 int granted = 0;
2136 struct ldlm_interval *node;
d7e09d03
PT
2137
2138 /* Just return if mode is unchanged. */
2139 if (new_mode == lock->l_granted_mode) {
2140 *flags |= LDLM_FL_BLOCK_GRANTED;
0a3bdb00 2141 return lock->l_resource;
d7e09d03
PT
2142 }
2143
2144 /* I can't check the type of lock here because the bitlock of lock
2145 * is not held here, so do the allocation blindly. -jay */
0be19afa 2146 OBD_SLAB_ALLOC_PTR_GFP(node, ldlm_interval_slab, GFP_NOFS);
2d58de78
LW
2147 if (node == NULL)
2148 /* Actually, this causes EDEADLOCK to be returned */
0a3bdb00 2149 return NULL;
d7e09d03
PT
2150
2151 LASSERTF((new_mode == LCK_PW && lock->l_granted_mode == LCK_PR),
2152 "new_mode %u, granted %u\n", new_mode, lock->l_granted_mode);
2153
2154 lock_res_and_lock(lock);
2155
2156 res = lock->l_resource;
2157 ns = ldlm_res_to_ns(res);
2158
2159 lock->l_req_mode = new_mode;
2160 if (res->lr_type == LDLM_PLAIN || res->lr_type == LDLM_IBITS) {
2161 ldlm_resource_unlink_lock(lock);
2162 } else {
2163 ldlm_resource_unlink_lock(lock);
2164 if (res->lr_type == LDLM_EXTENT) {
2165 /* FIXME: ugly code, I have to attach the lock to a
2166 * interval node again since perhaps it will be granted
2167 * soon */
2168 INIT_LIST_HEAD(&node->li_group);
2169 ldlm_interval_attach(node, lock);
2170 node = NULL;
2171 }
2172 }
2173
2174 /*
2175 * Remove old lock from the pool before adding the lock with new
2176 * mode below in ->policy()
2177 */
2178 ldlm_pool_del(&ns->ns_pool, lock);
2179
2180 /* If this is a local resource, put it on the appropriate list. */
2181 if (ns_is_client(ldlm_res_to_ns(res))) {
2182 if (*flags & (LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_GRANTED)) {
2183 ldlm_resource_add_lock(res, &res->lr_converting, lock);
2184 } else {
2185 /* This should never happen, because of the way the
2186 * server handles conversions. */
2187 LDLM_ERROR(lock, "Erroneous flags %x on local lock\n",
2188 *flags);
2189 LBUG();
2190
2191 ldlm_grant_lock(lock, &rpc_list);
2192 granted = 1;
2193 /* FIXME: completion handling not with lr_lock held ! */
2194 if (lock->l_completion_ast)
2195 lock->l_completion_ast(lock, 0, NULL);
2196 }
2197 } else {
2198 CERROR("This is client-side-only module, cannot handle "
2199 "LDLM_NAMESPACE_SERVER resource type lock.\n");
2200 LBUG();
2201 }
2202 unlock_res_and_lock(lock);
2203
2204 if (granted)
2205 ldlm_run_ast_work(ns, &rpc_list, LDLM_WORK_CP_AST);
2206 if (node)
2207 OBD_SLAB_FREE(node, ldlm_interval_slab, sizeof(*node));
0a3bdb00 2208 return res;
d7e09d03
PT
2209}
2210EXPORT_SYMBOL(ldlm_lock_convert);
2211
2212/**
2213 * Print lock with lock handle \a lockh description into debug log.
2214 *
2215 * Used when printing all locks on a resource for debug purposes.
2216 */
2217void ldlm_lock_dump_handle(int level, struct lustre_handle *lockh)
2218{
2219 struct ldlm_lock *lock;
2220
2221 if (!((libcfs_debug | D_ERROR) & level))
2222 return;
2223
2224 lock = ldlm_handle2lock(lockh);
2225 if (lock == NULL)
2226 return;
2227
2228 LDLM_DEBUG_LIMIT(level, lock, "###");
2229
2230 LDLM_LOCK_PUT(lock);
2231}
2232EXPORT_SYMBOL(ldlm_lock_dump_handle);
2233
2234/**
2235 * Print lock information with custom message into debug log.
2236 * Helper function.
2237 */
2238void _ldlm_lock_debug(struct ldlm_lock *lock,
2239 struct libcfs_debug_msg_data *msgdata,
2240 const char *fmt, ...)
2241{
2242 va_list args;
2243 struct obd_export *exp = lock->l_export;
2244 struct ldlm_resource *resource = lock->l_resource;
2245 char *nid = "local";
2246
2247 va_start(args, fmt);
2248
2249 if (exp && exp->exp_connection) {
2250 nid = libcfs_nid2str(exp->exp_connection->c_peer.nid);
2251 } else if (exp && exp->exp_obd != NULL) {
2252 struct obd_import *imp = exp->exp_obd->u.cli.cl_import;
2253 nid = libcfs_nid2str(imp->imp_connection->c_peer.nid);
2254 }
2255
2256 if (resource == NULL) {
2257 libcfs_debug_vmsg2(msgdata, fmt, args,
2258 " ns: \?\? lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
2259 "res: \?\? rrc=\?\? type: \?\?\? flags: "LPX64" nid: %s "
2260 "remote: "LPX64" expref: %d pid: %u timeout: %lu "
2261 "lvb_type: %d\n",
2262 lock,
2263 lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
2264 lock->l_readers, lock->l_writers,
2265 ldlm_lockname[lock->l_granted_mode],
2266 ldlm_lockname[lock->l_req_mode],
2267 lock->l_flags, nid, lock->l_remote_handle.cookie,
2268 exp ? atomic_read(&exp->exp_refcount) : -99,
2269 lock->l_pid, lock->l_callback_timeout, lock->l_lvb_type);
2270 va_end(args);
2271 return;
2272 }
2273
2274 switch (resource->lr_type) {
2275 case LDLM_EXTENT:
2276 libcfs_debug_vmsg2(msgdata, fmt, args,
ce74f92d 2277 " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
b0f5aad5
GKH
2278 "res: "DLDLMRES" rrc: %d type: %s [%llu->%llu] "
2279 "(req %llu->%llu) flags: "LPX64" nid: %s remote: "
ce74f92d
AD
2280 LPX64" expref: %d pid: %u timeout: %lu lvb_type: %d\n",
2281 ldlm_lock_to_ns_name(lock), lock,
2282 lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
2283 lock->l_readers, lock->l_writers,
2284 ldlm_lockname[lock->l_granted_mode],
2285 ldlm_lockname[lock->l_req_mode],
2286 PLDLMRES(resource),
2287 atomic_read(&resource->lr_refcount),
2288 ldlm_typename[resource->lr_type],
2289 lock->l_policy_data.l_extent.start,
2290 lock->l_policy_data.l_extent.end,
2291 lock->l_req_extent.start, lock->l_req_extent.end,
2292 lock->l_flags, nid, lock->l_remote_handle.cookie,
2293 exp ? atomic_read(&exp->exp_refcount) : -99,
2294 lock->l_pid, lock->l_callback_timeout,
2295 lock->l_lvb_type);
d7e09d03
PT
2296 break;
2297
2298 case LDLM_FLOCK:
2299 libcfs_debug_vmsg2(msgdata, fmt, args,
ce74f92d
AD
2300 " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
2301 "res: "DLDLMRES" rrc: %d type: %s pid: %d "
b0f5aad5 2302 "[%llu->%llu] flags: "LPX64" nid: %s "
ce74f92d
AD
2303 "remote: "LPX64" expref: %d pid: %u timeout: %lu\n",
2304 ldlm_lock_to_ns_name(lock), lock,
2305 lock->l_handle.h_cookie, atomic_read(&lock->l_refc),
2306 lock->l_readers, lock->l_writers,
2307 ldlm_lockname[lock->l_granted_mode],
2308 ldlm_lockname[lock->l_req_mode],
2309 PLDLMRES(resource),
2310 atomic_read(&resource->lr_refcount),
2311 ldlm_typename[resource->lr_type],
2312 lock->l_policy_data.l_flock.pid,
2313 lock->l_policy_data.l_flock.start,
2314 lock->l_policy_data.l_flock.end,
2315 lock->l_flags, nid, lock->l_remote_handle.cookie,
2316 exp ? atomic_read(&exp->exp_refcount) : -99,
2317 lock->l_pid, lock->l_callback_timeout);
d7e09d03
PT
2318 break;
2319
2320 case LDLM_IBITS:
2321 libcfs_debug_vmsg2(msgdata, fmt, args,
ce74f92d
AD
2322 " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
2323 "res: "DLDLMRES" bits "LPX64" rrc: %d type: %s "
2324 "flags: "LPX64" nid: %s remote: "LPX64" expref: %d "
2325 "pid: %u timeout: %lu lvb_type: %d\n",
2326 ldlm_lock_to_ns_name(lock),
2327 lock, lock->l_handle.h_cookie,
2328 atomic_read(&lock->l_refc),
2329 lock->l_readers, lock->l_writers,
2330 ldlm_lockname[lock->l_granted_mode],
2331 ldlm_lockname[lock->l_req_mode],
2332 PLDLMRES(resource),
2333 lock->l_policy_data.l_inodebits.bits,
2334 atomic_read(&resource->lr_refcount),
2335 ldlm_typename[resource->lr_type],
2336 lock->l_flags, nid, lock->l_remote_handle.cookie,
2337 exp ? atomic_read(&exp->exp_refcount) : -99,
2338 lock->l_pid, lock->l_callback_timeout,
2339 lock->l_lvb_type);
d7e09d03
PT
2340 break;
2341
2342 default:
2343 libcfs_debug_vmsg2(msgdata, fmt, args,
ce74f92d
AD
2344 " ns: %s lock: %p/"LPX64" lrc: %d/%d,%d mode: %s/%s "
2345 "res: "DLDLMRES" rrc: %d type: %s flags: "LPX64" "
2346 "nid: %s remote: "LPX64" expref: %d pid: %u "
2347 "timeout: %lu lvb_type: %d\n",
2348 ldlm_lock_to_ns_name(lock),
2349 lock, lock->l_handle.h_cookie,
2350 atomic_read(&lock->l_refc),
2351 lock->l_readers, lock->l_writers,
2352 ldlm_lockname[lock->l_granted_mode],
2353 ldlm_lockname[lock->l_req_mode],
2354 PLDLMRES(resource),
2355 atomic_read(&resource->lr_refcount),
2356 ldlm_typename[resource->lr_type],
2357 lock->l_flags, nid, lock->l_remote_handle.cookie,
2358 exp ? atomic_read(&exp->exp_refcount) : -99,
2359 lock->l_pid, lock->l_callback_timeout,
2360 lock->l_lvb_type);
d7e09d03
PT
2361 break;
2362 }
2363 va_end(args);
2364}
2365EXPORT_SYMBOL(_ldlm_lock_debug);
This page took 0.315051 seconds and 5 git commands to generate.