Whamcloud - gitweb
b=23428 Fix lustre built with --enable-lu_ref
[fs/lustre-release.git] / lustre / ldlm / ldlm_resource.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
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_resource.c
37  *
38  * Author: Phil Schwan <phil@clusterfs.com>
39  * Author: Peter Braam <braam@clusterfs.com>
40  */
41
42 #define DEBUG_SUBSYSTEM S_LDLM
43 #ifdef __KERNEL__
44 # include <lustre_dlm.h>
45 #else
46 # include <liblustre.h>
47 #endif
48
49 #include <obd_class.h>
50 #include "ldlm_internal.h"
51
52 cfs_mem_cache_t *ldlm_resource_slab, *ldlm_lock_slab;
53
54 cfs_atomic_t ldlm_srv_namespace_nr = CFS_ATOMIC_INIT(0);
55 cfs_atomic_t ldlm_cli_namespace_nr = CFS_ATOMIC_INIT(0);
56
57 cfs_semaphore_t ldlm_srv_namespace_lock;
58 CFS_LIST_HEAD(ldlm_srv_namespace_list);
59
60 cfs_semaphore_t ldlm_cli_namespace_lock;
61 CFS_LIST_HEAD(ldlm_cli_namespace_list);
62
63 cfs_proc_dir_entry_t *ldlm_type_proc_dir = NULL;
64 cfs_proc_dir_entry_t *ldlm_ns_proc_dir = NULL;
65 cfs_proc_dir_entry_t *ldlm_svc_proc_dir = NULL;
66
67 #ifdef LPROCFS
68 static int ldlm_proc_dump_ns(struct file *file, const char *buffer,
69                              unsigned long count, void *data)
70 {
71         ldlm_dump_all_namespaces(LDLM_NAMESPACE_SERVER, D_DLMTRACE);
72         ldlm_dump_all_namespaces(LDLM_NAMESPACE_CLIENT, D_DLMTRACE);
73         RETURN(count);
74 }
75
76 int ldlm_proc_setup(void)
77 {
78         int rc;
79         struct lprocfs_vars list[] = {
80                 { "dump_namespaces", NULL, ldlm_proc_dump_ns, NULL },
81                 { NULL }};
82         ENTRY;
83         LASSERT(ldlm_ns_proc_dir == NULL);
84
85         ldlm_type_proc_dir = lprocfs_register(OBD_LDLM_DEVICENAME,
86                                               proc_lustre_root,
87                                               NULL, NULL);
88         if (IS_ERR(ldlm_type_proc_dir)) {
89                 CERROR("LProcFS failed in ldlm-init\n");
90                 rc = PTR_ERR(ldlm_type_proc_dir);
91                 GOTO(err, rc);
92         }
93
94         ldlm_ns_proc_dir = lprocfs_register("namespaces",
95                                             ldlm_type_proc_dir,
96                                             NULL, NULL);
97         if (IS_ERR(ldlm_ns_proc_dir)) {
98                 CERROR("LProcFS failed in ldlm-init\n");
99                 rc = PTR_ERR(ldlm_ns_proc_dir);
100                 GOTO(err_type, rc);
101         }
102
103         ldlm_svc_proc_dir = lprocfs_register("services",
104                                             ldlm_type_proc_dir,
105                                             NULL, NULL);
106         if (IS_ERR(ldlm_svc_proc_dir)) {
107                 CERROR("LProcFS failed in ldlm-init\n");
108                 rc = PTR_ERR(ldlm_svc_proc_dir);
109                 GOTO(err_ns, rc);
110         }
111
112         rc = lprocfs_add_vars(ldlm_type_proc_dir, list, NULL);
113
114         RETURN(0);
115
116 err_ns:
117         lprocfs_remove(&ldlm_ns_proc_dir);
118 err_type:
119         lprocfs_remove(&ldlm_type_proc_dir);
120 err:
121         ldlm_svc_proc_dir = NULL;
122         RETURN(rc);
123 }
124
125 void ldlm_proc_cleanup(void)
126 {
127         if (ldlm_svc_proc_dir)
128                 lprocfs_remove(&ldlm_svc_proc_dir);
129
130         if (ldlm_ns_proc_dir)
131                 lprocfs_remove(&ldlm_ns_proc_dir);
132
133         if (ldlm_type_proc_dir)
134                 lprocfs_remove(&ldlm_type_proc_dir);
135 }
136
137 static int lprocfs_rd_lru_size(char *page, char **start, off_t off,
138                                int count, int *eof, void *data)
139 {
140         struct ldlm_namespace *ns = data;
141         __u32 *nr = &ns->ns_max_unused;
142
143         if (ns_connect_lru_resize(ns))
144                 nr = &ns->ns_nr_unused;
145         return lprocfs_rd_uint(page, start, off, count, eof, nr);
146 }
147
148 static int lprocfs_wr_lru_size(struct file *file, const char *buffer,
149                                unsigned long count, void *data)
150 {
151         struct ldlm_namespace *ns = data;
152         char dummy[MAX_STRING_SIZE + 1], *end;
153         unsigned long tmp;
154         int lru_resize;
155
156         dummy[MAX_STRING_SIZE] = '\0';
157         if (cfs_copy_from_user(dummy, buffer, MAX_STRING_SIZE))
158                 return -EFAULT;
159
160         if (strncmp(dummy, "clear", 5) == 0) {
161                 CDEBUG(D_DLMTRACE,
162                        "dropping all unused locks from namespace %s\n",
163                        ns->ns_name);
164                 if (ns_connect_lru_resize(ns)) {
165                         int canceled, unused  = ns->ns_nr_unused;
166
167                         /* Try to cancel all @ns_nr_unused locks. */
168                         canceled = ldlm_cancel_lru(ns, unused, LDLM_SYNC,
169                                                    LDLM_CANCEL_PASSED);
170                         if (canceled < unused) {
171                                 CDEBUG(D_DLMTRACE,
172                                        "not all requested locks are canceled, "
173                                        "requested: %d, canceled: %d\n", unused,
174                                        canceled);
175                                 return -EINVAL;
176                         }
177                 } else {
178                         tmp = ns->ns_max_unused;
179                         ns->ns_max_unused = 0;
180                         ldlm_cancel_lru(ns, 0, LDLM_SYNC, LDLM_CANCEL_PASSED);
181                         ns->ns_max_unused = tmp;
182                 }
183                 return count;
184         }
185
186         tmp = simple_strtoul(dummy, &end, 0);
187         if (dummy == end) {
188                 CERROR("invalid value written\n");
189                 return -EINVAL;
190         }
191         lru_resize = (tmp == 0);
192
193         if (ns_connect_lru_resize(ns)) {
194                 if (!lru_resize)
195                         ns->ns_max_unused = (unsigned int)tmp;
196
197                 if (tmp > ns->ns_nr_unused)
198                         tmp = ns->ns_nr_unused;
199                 tmp = ns->ns_nr_unused - tmp;
200
201                 CDEBUG(D_DLMTRACE,
202                        "changing namespace %s unused locks from %u to %u\n",
203                        ns->ns_name, ns->ns_nr_unused, (unsigned int)tmp);
204                 ldlm_cancel_lru(ns, tmp, LDLM_ASYNC, LDLM_CANCEL_PASSED);
205
206                 if (!lru_resize) {
207                         CDEBUG(D_DLMTRACE,
208                                "disable lru_resize for namespace %s\n",
209                                ns->ns_name);
210                         ns->ns_connect_flags &= ~OBD_CONNECT_LRU_RESIZE;
211                 }
212         } else {
213                 CDEBUG(D_DLMTRACE,
214                        "changing namespace %s max_unused from %u to %u\n",
215                        ns->ns_name, ns->ns_max_unused, (unsigned int)tmp);
216                 ns->ns_max_unused = (unsigned int)tmp;
217                 ldlm_cancel_lru(ns, 0, LDLM_ASYNC, LDLM_CANCEL_PASSED);
218
219                 /* Make sure that originally lru resize was supported before
220                  * turning it on here. */
221                 if (lru_resize &&
222                     (ns->ns_orig_connect_flags & OBD_CONNECT_LRU_RESIZE)) {
223                         CDEBUG(D_DLMTRACE,
224                                "enable lru_resize for namespace %s\n",
225                                ns->ns_name);
226                         ns->ns_connect_flags |= OBD_CONNECT_LRU_RESIZE;
227                 }
228         }
229
230         return count;
231 }
232
233 void ldlm_proc_namespace(struct ldlm_namespace *ns)
234 {
235         struct lprocfs_vars lock_vars[2];
236         char lock_name[MAX_STRING_SIZE + 1];
237
238         LASSERT(ns != NULL);
239         LASSERT(ns->ns_name != NULL);
240
241         lock_name[MAX_STRING_SIZE] = '\0';
242
243         memset(lock_vars, 0, sizeof(lock_vars));
244         lock_vars[0].name = lock_name;
245
246         snprintf(lock_name, MAX_STRING_SIZE, "%s/resource_count", ns->ns_name);
247         lock_vars[0].data = &ns->ns_refcount;
248         lock_vars[0].read_fptr = lprocfs_rd_atomic;
249         lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
250
251         snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_count", ns->ns_name);
252         lock_vars[0].data = &ns->ns_locks;
253         lock_vars[0].read_fptr = lprocfs_rd_atomic;
254         lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
255
256         if (ns_is_client(ns)) {
257                 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_unused_count",
258                          ns->ns_name);
259                 lock_vars[0].data = &ns->ns_nr_unused;
260                 lock_vars[0].read_fptr = lprocfs_rd_uint;
261                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
262
263                 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_size",
264                          ns->ns_name);
265                 lock_vars[0].data = ns;
266                 lock_vars[0].read_fptr = lprocfs_rd_lru_size;
267                 lock_vars[0].write_fptr = lprocfs_wr_lru_size;
268                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
269
270                 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_max_age",
271                          ns->ns_name);
272                 lock_vars[0].data = &ns->ns_max_age;
273                 lock_vars[0].read_fptr = lprocfs_rd_uint;
274                 lock_vars[0].write_fptr = lprocfs_wr_uint;
275                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
276         } else {
277                 snprintf(lock_name, MAX_STRING_SIZE, "%s/ctime_age_limit",
278                          ns->ns_name);
279                 lock_vars[0].data = &ns->ns_ctime_age_limit;
280                 lock_vars[0].read_fptr = lprocfs_rd_uint;
281                 lock_vars[0].write_fptr = lprocfs_wr_uint;
282                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
283
284                 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_timeouts",
285                          ns->ns_name);
286                 lock_vars[0].data = &ns->ns_timeouts;
287                 lock_vars[0].read_fptr = lprocfs_rd_uint;
288                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
289
290                 snprintf(lock_name, MAX_STRING_SIZE, "%s/max_nolock_bytes",
291                          ns->ns_name);
292                 lock_vars[0].data = &ns->ns_max_nolock_size;
293                 lock_vars[0].read_fptr = lprocfs_rd_uint;
294                 lock_vars[0].write_fptr = lprocfs_wr_uint;
295                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
296
297                 snprintf(lock_name, MAX_STRING_SIZE, "%s/contention_seconds",
298                          ns->ns_name);
299                 lock_vars[0].data = &ns->ns_contention_time;
300                 lock_vars[0].read_fptr = lprocfs_rd_uint;
301                 lock_vars[0].write_fptr = lprocfs_wr_uint;
302                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
303
304                 snprintf(lock_name, MAX_STRING_SIZE, "%s/contended_locks",
305                          ns->ns_name);
306                 lock_vars[0].data = &ns->ns_contended_locks;
307                 lock_vars[0].read_fptr = lprocfs_rd_uint;
308                 lock_vars[0].write_fptr = lprocfs_wr_uint;
309                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
310         }
311 }
312 #undef MAX_STRING_SIZE
313 #else
314 #define ldlm_proc_namespace(ns) do {} while (0)
315 #endif /* LPROCFS */
316
317 struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name,
318                                           ldlm_side_t client, ldlm_appetite_t apt)
319 {
320         struct ldlm_namespace *ns = NULL;
321         cfs_list_t *bucket;
322         int rc, idx, namelen;
323         ENTRY;
324
325         rc = ldlm_get_ref();
326         if (rc) {
327                 CERROR("ldlm_get_ref failed: %d\n", rc);
328                 RETURN(NULL);
329         }
330
331         OBD_ALLOC_PTR(ns);
332         if (!ns)
333                 GOTO(out_ref, NULL);
334
335         OBD_VMALLOC(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
336         if (!ns->ns_hash)
337                 GOTO(out_ns, NULL);
338
339         ns->ns_appetite = apt;
340
341         LASSERT(obd != NULL);
342         ns->ns_obd = obd;
343
344         namelen = strlen(name);
345         OBD_ALLOC(ns->ns_name, namelen + 1);
346         if (!ns->ns_name)
347                 GOTO(out_hash, NULL);
348
349         strcpy(ns->ns_name, name);
350
351         CFS_INIT_LIST_HEAD(&ns->ns_root_list);
352         CFS_INIT_LIST_HEAD(&ns->ns_list_chain);
353         ns->ns_refcount = 0;
354         ns->ns_client = client;
355         cfs_spin_lock_init(&ns->ns_hash_lock);
356         cfs_atomic_set(&ns->ns_locks, 0);
357         ns->ns_resources = 0;
358         cfs_waitq_init(&ns->ns_waitq);
359         ns->ns_max_nolock_size = NS_DEFAULT_MAX_NOLOCK_BYTES;
360         ns->ns_contention_time = NS_DEFAULT_CONTENTION_SECONDS;
361         ns->ns_contended_locks = NS_DEFAULT_CONTENDED_LOCKS;
362
363         for (bucket = ns->ns_hash + RES_HASH_SIZE - 1; bucket >= ns->ns_hash;
364              bucket--)
365                 CFS_INIT_LIST_HEAD(bucket);
366
367         CFS_INIT_LIST_HEAD(&ns->ns_unused_list);
368         ns->ns_nr_unused = 0;
369         ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE;
370         ns->ns_max_age = LDLM_DEFAULT_MAX_ALIVE;
371         ns->ns_ctime_age_limit = LDLM_CTIME_AGE_LIMIT;
372         ns->ns_timeouts = 0;
373         cfs_spin_lock_init(&ns->ns_unused_lock);
374         ns->ns_orig_connect_flags = 0;
375         ns->ns_connect_flags = 0;
376         ldlm_proc_namespace(ns);
377
378         idx = cfs_atomic_read(ldlm_namespace_nr(client));
379         rc = ldlm_pool_init(&ns->ns_pool, ns, idx, client);
380         if (rc) {
381                 CERROR("Can't initialize lock pool, rc %d\n", rc);
382                 GOTO(out_proc, rc);
383         }
384
385         at_init(&ns->ns_at_estimate, ldlm_enqueue_min, 0);
386
387         ldlm_namespace_register(ns, client);
388         RETURN(ns);
389 out_proc:
390         ldlm_namespace_cleanup(ns, 0);
391         OBD_FREE(ns->ns_name, namelen + 1);
392 out_hash:
393         OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
394 out_ns:
395         OBD_FREE_PTR(ns);
396 out_ref:
397         ldlm_put_ref();
398         RETURN(NULL);
399 }
400
401 extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
402
403 /* If flags contains FL_LOCAL_ONLY, don't try to tell the server, just cleanup.
404  * This is currently only used for recovery, and we make certain assumptions
405  * as a result--notably, that we shouldn't cancel locks with refs. -phil
406  *
407  * Called with the ns_lock held. */
408 static void cleanup_resource(struct ldlm_resource *res, cfs_list_t *q,
409                              int flags)
410 {
411         cfs_list_t *tmp;
412         int rc = 0, client = ns_is_client(res->lr_namespace);
413         int local_only = (flags & LDLM_FL_LOCAL_ONLY);
414         ENTRY;
415
416
417         do {
418                 struct ldlm_lock *lock = NULL;
419
420                 /* first, we look for non-cleaned-yet lock
421                  * all cleaned locks are marked by CLEANED flag */
422                 lock_res(res);
423                 cfs_list_for_each(tmp, q) {
424                         lock = cfs_list_entry(tmp, struct ldlm_lock,
425                                               l_res_link);
426                         if (lock->l_flags & LDLM_FL_CLEANED) {
427                                 lock = NULL;
428                                 continue;
429                         }
430                         LDLM_LOCK_GET(lock);
431                         lock->l_flags |= LDLM_FL_CLEANED;
432                         break;
433                 }
434
435                 if (lock == NULL) {
436                         unlock_res(res);
437                         break;
438                 }
439
440                 /* Set CBPENDING so nothing in the cancellation path
441                  * can match this lock */
442                 lock->l_flags |= LDLM_FL_CBPENDING;
443                 lock->l_flags |= LDLM_FL_FAILED;
444                 lock->l_flags |= flags;
445
446                 /* ... without sending a CANCEL message for local_only. */
447                 if (local_only)
448                         lock->l_flags |= LDLM_FL_LOCAL_ONLY;
449
450                 if (local_only && (lock->l_readers || lock->l_writers)) {
451                         /* This is a little bit gross, but much better than the
452                          * alternative: pretend that we got a blocking AST from
453                          * the server, so that when the lock is decref'd, it
454                          * will go away ... */
455                         unlock_res(res);
456                         LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY");
457                         if (lock->l_completion_ast)
458                                 lock->l_completion_ast(lock, 0, NULL);
459                         LDLM_LOCK_RELEASE(lock);
460                         continue;
461                 }
462
463                 if (client) {
464                         struct lustre_handle lockh;
465
466                         unlock_res(res);
467                         ldlm_lock2handle(lock, &lockh);
468                         rc = ldlm_cli_cancel(&lockh);
469                         if (rc)
470                                 CERROR("ldlm_cli_cancel: %d\n", rc);
471                 } else {
472                         ldlm_resource_unlink_lock(lock);
473                         unlock_res(res);
474                         LDLM_DEBUG(lock, "Freeing a lock still held by a "
475                                    "client node");
476                         ldlm_lock_destroy(lock);
477                 }
478                 LDLM_LOCK_RELEASE(lock);
479         } while (1);
480
481         EXIT;
482 }
483
484 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags)
485 {
486         cfs_list_t *tmp;
487         int i;
488
489         if (ns == NULL) {
490                 CDEBUG(D_INFO, "NULL ns, skipping cleanup\n");
491                 return ELDLM_OK;
492         }
493
494         for (i = 0; i < RES_HASH_SIZE; i++) {
495                 cfs_spin_lock(&ns->ns_hash_lock);
496                 tmp = ns->ns_hash[i].next;
497                 while (tmp != &(ns->ns_hash[i])) {
498                         struct ldlm_resource *res;
499                         res = cfs_list_entry(tmp, struct ldlm_resource,
500                                              lr_hash);
501                         ldlm_resource_getref(res);
502                         cfs_spin_unlock(&ns->ns_hash_lock);
503                         LDLM_RESOURCE_ADDREF(res);
504
505                         cleanup_resource(res, &res->lr_granted, flags);
506                         cleanup_resource(res, &res->lr_converting, flags);
507                         cleanup_resource(res, &res->lr_waiting, flags);
508
509                         cfs_spin_lock(&ns->ns_hash_lock);
510                         tmp = tmp->next;
511
512                         /* XXX: former stuff caused issues in case of race
513                          * between ldlm_namespace_cleanup() and lockd() when
514                          * client gets blocking ast when lock gets distracted by
515                          * server. This is 1_4 branch solution, let's see how
516                          * will it behave. */
517                         LDLM_RESOURCE_DELREF(res);
518                         if (!ldlm_resource_putref_locked(res)) {
519                                 CERROR("Namespace %s resource refcount nonzero "
520                                        "(%d) after lock cleanup; forcing "
521                                        "cleanup.\n",
522                                        ns->ns_name,
523                                        cfs_atomic_read(&res->lr_refcount));
524                                 CERROR("Resource: %p ("LPU64"/"LPU64"/"LPU64"/"
525                                        LPU64") (rc: %d)\n", res,
526                                        res->lr_name.name[0],
527                                        res->lr_name.name[1],
528                                        res->lr_name.name[2],
529                                        res->lr_name.name[3],
530                                        cfs_atomic_read(&res->lr_refcount));
531                         }
532                 }
533                 cfs_spin_unlock(&ns->ns_hash_lock);
534         }
535
536         return ELDLM_OK;
537 }
538
539 static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force)
540 {
541         ENTRY;
542
543         /* At shutdown time, don't call the cancellation callback */
544         ldlm_namespace_cleanup(ns, force ? LDLM_FL_LOCAL_ONLY : 0);
545
546         if (ns->ns_refcount > 0) {
547                 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
548                 int rc;
549                 CDEBUG(D_DLMTRACE,
550                        "dlm namespace %s free waiting on refcount %d\n",
551                        ns->ns_name, ns->ns_refcount);
552 force_wait:
553                 if (force)
554                         lwi = LWI_TIMEOUT(obd_timeout * CFS_HZ / 4, NULL, NULL);
555
556                 rc = l_wait_event(ns->ns_waitq,
557                                   ns->ns_refcount == 0, &lwi);
558
559                 /* Forced cleanups should be able to reclaim all references,
560                  * so it's safe to wait forever... we can't leak locks... */
561                 if (force && rc == -ETIMEDOUT) {
562                         LCONSOLE_ERROR("Forced cleanup waiting for %s "
563                                        "namespace with %d resources in use, "
564                                        "(rc=%d)\n", ns->ns_name,
565                                        ns->ns_refcount, rc);
566                         GOTO(force_wait, rc);
567                 }
568
569                 if (ns->ns_refcount) {
570                         LCONSOLE_ERROR("Cleanup waiting for %s namespace "
571                                        "with %d resources in use, (rc=%d)\n",
572                                        ns->ns_name,
573                                        ns->ns_refcount, rc);
574                         RETURN(ELDLM_NAMESPACE_EXISTS);
575                 }
576                 CDEBUG(D_DLMTRACE,
577                        "dlm namespace %s free done waiting\n", ns->ns_name);
578         }
579
580         RETURN(ELDLM_OK);
581 }
582
583 /**
584  * Performs various cleanups for passed \a ns to make it drop refc and be ready
585  * for freeing. Waits for refc == 0.
586  *
587  * The following is done:
588  * (0) Unregister \a ns from its list to make inaccessible for potential users
589  * like pools thread and others;
590  * (1) Clear all locks in \a ns.
591  */
592 void ldlm_namespace_free_prior(struct ldlm_namespace *ns,
593                                struct obd_import *imp,
594                                int force)
595 {
596         int rc;
597         ENTRY;
598         if (!ns) {
599                 EXIT;
600                 return;
601         }
602
603
604         /*
605          * Can fail with -EINTR when force == 0 in which case try harder.
606          */
607         rc = __ldlm_namespace_free(ns, force);
608         if (rc != ELDLM_OK) {
609                 if (imp) {
610                         ptlrpc_disconnect_import(imp, 0);
611                         ptlrpc_invalidate_import(imp);
612                 }
613
614                 /*
615                  * With all requests dropped and the import inactive
616                  * we are gaurenteed all reference will be dropped.
617                  */
618                 rc = __ldlm_namespace_free(ns, 1);
619                 LASSERT(rc == 0);
620         }
621         EXIT;
622 }
623
624 /**
625  * Performs freeing memory structures related to \a ns. This is only done when
626  * ldlm_namespce_free_prior() successfully removed all resources referencing
627  * \a ns and its refc == 0.
628  */
629 void ldlm_namespace_free_post(struct ldlm_namespace *ns)
630 {
631         ENTRY;
632         if (!ns) {
633                 EXIT;
634                 return;
635         }
636
637
638         /*
639          * Make sure that nobody can find this ns in its list.
640          */
641         ldlm_namespace_unregister(ns, ns->ns_client);
642         /*
643          * Fini pool _before_ parent proc dir is removed. This is important as
644          * ldlm_pool_fini() removes own proc dir which is child to @dir. Removing
645          * it after @dir may cause oops.
646          */
647         ldlm_pool_fini(&ns->ns_pool);
648
649 #ifdef LPROCFS
650         {
651                 struct proc_dir_entry *dir;
652                 dir = lprocfs_srch(ldlm_ns_proc_dir, ns->ns_name);
653                 if (dir == NULL) {
654                         CERROR("dlm namespace %s has no procfs dir?\n",
655                                ns->ns_name);
656                 } else {
657                         lprocfs_remove(&dir);
658                 }
659         }
660 #endif
661
662         OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
663         OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
664
665         /*
666          * Namespace \a ns should be not on list in this time, otherwise this
667          * will cause issues realted to using freed \a ns in pools thread.
668          */
669         LASSERT(cfs_list_empty(&ns->ns_list_chain));
670         OBD_FREE_PTR(ns);
671         ldlm_put_ref();
672         EXIT;
673 }
674
675
676 /* Cleanup the resource, and free namespace.
677  * bug 12864:
678  * Deadlock issue:
679  * proc1: destroy import
680  *        class_disconnect_export(grab cl_sem) ->
681  *              -> ldlm_namespace_free ->
682  *              -> lprocfs_remove(grab _lprocfs_lock).
683  * proc2: read proc info
684  *        lprocfs_fops_read(grab _lprocfs_lock) ->
685  *              -> osc_rd_active, etc(grab cl_sem).
686  *
687  * So that I have to split the ldlm_namespace_free into two parts - the first
688  * part ldlm_namespace_free_prior is used to cleanup the resource which is
689  * being used; the 2nd part ldlm_namespace_free_post is used to unregister the
690  * lprocfs entries, and then free memory. It will be called w/o cli->cl_sem
691  * held.
692  */
693 void ldlm_namespace_free(struct ldlm_namespace *ns,
694                          struct obd_import *imp,
695                          int force)
696 {
697         ldlm_namespace_free_prior(ns, imp, force);
698         ldlm_namespace_free_post(ns);
699 }
700
701
702 void ldlm_namespace_get_locked(struct ldlm_namespace *ns)
703 {
704         ns->ns_refcount++;
705 }
706
707 void ldlm_namespace_get(struct ldlm_namespace *ns)
708 {
709         cfs_spin_lock(&ns->ns_hash_lock);
710         ldlm_namespace_get_locked(ns);
711         cfs_spin_unlock(&ns->ns_hash_lock);
712 }
713
714 void ldlm_namespace_put_locked(struct ldlm_namespace *ns, int wakeup)
715 {
716         LASSERT(ns->ns_refcount > 0);
717         ns->ns_refcount--;
718         if (ns->ns_refcount == 0 && wakeup)
719                 cfs_waitq_signal(&ns->ns_waitq);
720 }
721
722 void ldlm_namespace_put(struct ldlm_namespace *ns, int wakeup)
723 {
724         cfs_spin_lock(&ns->ns_hash_lock);
725         ldlm_namespace_put_locked(ns, wakeup);
726         cfs_spin_unlock(&ns->ns_hash_lock);
727 }
728
729 /* Register @ns in the list of namespaces */
730 void ldlm_namespace_register(struct ldlm_namespace *ns, ldlm_side_t client)
731 {
732         cfs_mutex_down(ldlm_namespace_lock(client));
733         LASSERT(cfs_list_empty(&ns->ns_list_chain));
734         cfs_list_add(&ns->ns_list_chain, ldlm_namespace_list(client));
735         cfs_atomic_inc(ldlm_namespace_nr(client));
736         cfs_mutex_up(ldlm_namespace_lock(client));
737 }
738
739 /* Unregister @ns from the list of namespaces */
740 void ldlm_namespace_unregister(struct ldlm_namespace *ns, ldlm_side_t client)
741 {
742         cfs_mutex_down(ldlm_namespace_lock(client));
743         LASSERT(!cfs_list_empty(&ns->ns_list_chain));
744         /*
745          * Some asserts and possibly other parts of code still using
746          * list_empty(&ns->ns_list_chain). This is why it is important
747          * to use list_del_init() here.
748          */
749         cfs_list_del_init(&ns->ns_list_chain);
750         cfs_atomic_dec(ldlm_namespace_nr(client));
751         cfs_mutex_up(ldlm_namespace_lock(client));
752 }
753
754 /* Should be called under ldlm_namespace_lock(client) taken */
755 void ldlm_namespace_move_locked(struct ldlm_namespace *ns, ldlm_side_t client)
756 {
757         LASSERT(!cfs_list_empty(&ns->ns_list_chain));
758         LASSERT_SEM_LOCKED(ldlm_namespace_lock(client));
759         cfs_list_move_tail(&ns->ns_list_chain, ldlm_namespace_list(client));
760 }
761
762 /* Should be called under ldlm_namespace_lock(client) taken */
763 struct ldlm_namespace *ldlm_namespace_first_locked(ldlm_side_t client)
764 {
765         LASSERT_SEM_LOCKED(ldlm_namespace_lock(client));
766         LASSERT(!cfs_list_empty(ldlm_namespace_list(client)));
767         return container_of(ldlm_namespace_list(client)->next,
768                 struct ldlm_namespace, ns_list_chain);
769 }
770 static __u32 ldlm_hash_fn(struct ldlm_resource *parent,
771                           const struct ldlm_res_id *name)
772 {
773         __u32 hash = 0;
774         int i;
775
776         for (i = 0; i < RES_NAME_SIZE; i++)
777                 hash += name->name[i];
778
779         hash += (__u32)((unsigned long)parent >> 4);
780
781         return (hash & RES_HASH_MASK);
782 }
783
784 static struct ldlm_resource *ldlm_resource_new(void)
785 {
786         struct ldlm_resource *res;
787         int idx;
788
789         OBD_SLAB_ALLOC_PTR_GFP(res, ldlm_resource_slab, CFS_ALLOC_IO);
790         if (res == NULL)
791                 return NULL;
792
793         memset(res, 0, sizeof(*res));
794
795         CFS_INIT_LIST_HEAD(&res->lr_children);
796         CFS_INIT_LIST_HEAD(&res->lr_childof);
797         CFS_INIT_LIST_HEAD(&res->lr_granted);
798         CFS_INIT_LIST_HEAD(&res->lr_converting);
799         CFS_INIT_LIST_HEAD(&res->lr_waiting);
800
801         /* initialize interval trees for each lock mode*/
802         for (idx = 0; idx < LCK_MODE_NUM; idx++) {
803                 res->lr_itree[idx].lit_size = 0;
804                 res->lr_itree[idx].lit_mode = 1 << idx;
805                 res->lr_itree[idx].lit_root = NULL;
806         }
807
808         cfs_atomic_set(&res->lr_refcount, 1);
809         cfs_spin_lock_init(&res->lr_lock);
810         lu_ref_init(&res->lr_reference);
811
812         /* one who creates the resource must unlock
813          * the semaphore after lvb initialization */
814         cfs_init_mutex_locked(&res->lr_lvb_sem);
815
816         return res;
817 }
818
819 /* must be called with hash lock held */
820 static struct ldlm_resource *
821 ldlm_resource_find(struct ldlm_namespace *ns, const struct ldlm_res_id *name,
822                    __u32 hash)
823 {
824         cfs_list_t *bucket, *tmp;
825         struct ldlm_resource *res;
826
827         LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
828         bucket = ns->ns_hash + hash;
829
830         cfs_list_for_each(tmp, bucket) {
831                 res = cfs_list_entry(tmp, struct ldlm_resource, lr_hash);
832                 if (memcmp(&res->lr_name, name, sizeof(res->lr_name)) == 0)
833                         return res;
834         }
835
836         return NULL;
837 }
838
839 /* Args: locked namespace
840  * Returns: newly-allocated, referenced, unlocked resource */
841 static struct ldlm_resource *
842 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
843                   const struct ldlm_res_id *name, __u32 hash, ldlm_type_t type)
844 {
845         cfs_list_t *bucket;
846         struct ldlm_resource *res, *old_res;
847         ENTRY;
848
849         LASSERTF(type >= LDLM_MIN_TYPE && type < LDLM_MAX_TYPE,
850                  "type: %d\n", type);
851
852         res = ldlm_resource_new();
853         if (!res)
854                 RETURN(NULL);
855
856         res->lr_name = *name;
857         res->lr_namespace = ns;
858         res->lr_type = type;
859         res->lr_most_restr = LCK_NL;
860
861         cfs_spin_lock(&ns->ns_hash_lock);
862         old_res = ldlm_resource_find(ns, name, hash);
863         if (old_res) {
864                 /* someone won the race and added the resource before */
865                 ldlm_resource_getref(old_res);
866                 cfs_spin_unlock(&ns->ns_hash_lock);
867                 /* clean lu_ref for failed resource */
868                 lu_ref_fini(&res->lr_reference);
869                 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
870                 /* synchronize WRT resource creation */
871                 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
872                         cfs_down(&old_res->lr_lvb_sem);
873                         cfs_up(&old_res->lr_lvb_sem);
874                 }
875                 RETURN(old_res);
876         }
877
878         /* we won! let's add the resource */
879         bucket = ns->ns_hash + hash;
880         cfs_list_add(&res->lr_hash, bucket);
881         ns->ns_resources++;
882         ldlm_namespace_get_locked(ns);
883
884         if (parent == NULL) {
885                 cfs_list_add(&res->lr_childof, &ns->ns_root_list);
886         } else {
887                 res->lr_parent = parent;
888                 cfs_list_add(&res->lr_childof, &parent->lr_children);
889         }
890         cfs_spin_unlock(&ns->ns_hash_lock);
891
892         if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
893                 int rc;
894
895                 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
896                 rc = ns->ns_lvbo->lvbo_init(res);
897                 if (rc)
898                         CERROR("lvbo_init failed for resource "
899                                LPU64": rc %d\n", name->name[0], rc);
900                 /* we create resource with locked lr_lvb_sem */
901                 cfs_up(&res->lr_lvb_sem);
902         }
903
904         RETURN(res);
905 }
906
907 /* Args: unlocked namespace
908  * Locks: takes and releases ns->ns_lock and res->lr_lock
909  * Returns: referenced, unlocked ldlm_resource or NULL */
910 struct ldlm_resource *
911 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
912                   const struct ldlm_res_id *name, ldlm_type_t type, int create)
913 {
914         __u32 hash = ldlm_hash_fn(parent, name);
915         struct ldlm_resource *res = NULL;
916         ENTRY;
917
918         LASSERT(ns != NULL);
919         LASSERT(ns->ns_hash != NULL);
920         LASSERT(name->name[0] != 0);
921
922         cfs_spin_lock(&ns->ns_hash_lock);
923         res = ldlm_resource_find(ns, name, hash);
924         if (res) {
925                 ldlm_resource_getref(res);
926                 cfs_spin_unlock(&ns->ns_hash_lock);
927                 /* synchronize WRT resource creation */
928                 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
929                         cfs_down(&res->lr_lvb_sem);
930                         cfs_up(&res->lr_lvb_sem);
931                 }
932                 RETURN(res);
933         }
934         cfs_spin_unlock(&ns->ns_hash_lock);
935
936         if (create == 0)
937                 RETURN(NULL);
938
939         res = ldlm_resource_add(ns, parent, name, hash, type);
940         RETURN(res);
941 }
942
943 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
944 {
945         LASSERT(res != NULL);
946         LASSERT(res != LP_POISON);
947         cfs_atomic_inc(&res->lr_refcount);
948         CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
949                cfs_atomic_read(&res->lr_refcount));
950         return res;
951 }
952
953 void __ldlm_resource_putref_final(struct ldlm_resource *res)
954 {
955         struct ldlm_namespace *ns = res->lr_namespace;
956
957         LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
958
959         if (!cfs_list_empty(&res->lr_granted)) {
960                 ldlm_resource_dump(D_ERROR, res);
961                 LBUG();
962         }
963
964         if (!cfs_list_empty(&res->lr_converting)) {
965                 ldlm_resource_dump(D_ERROR, res);
966                 LBUG();
967         }
968
969         if (!cfs_list_empty(&res->lr_waiting)) {
970                 ldlm_resource_dump(D_ERROR, res);
971                 LBUG();
972         }
973
974         if (!cfs_list_empty(&res->lr_children)) {
975                 ldlm_resource_dump(D_ERROR, res);
976                 LBUG();
977         }
978
979         /* Pass 0 here to not wake ->ns_waitq up yet, we will do it few
980          * lines below when all children are freed. */
981         ldlm_namespace_put_locked(ns, 0);
982         cfs_list_del_init(&res->lr_hash);
983         cfs_list_del_init(&res->lr_childof);
984         lu_ref_fini(&res->lr_reference);
985
986         ns->ns_resources--;
987         if (ns->ns_resources == 0)
988                 cfs_waitq_signal(&ns->ns_waitq);
989 }
990
991 /* Returns 1 if the resource was freed, 0 if it remains. */
992 int ldlm_resource_putref(struct ldlm_resource *res)
993 {
994         struct ldlm_namespace *ns = res->lr_namespace;
995         int rc = 0;
996         ENTRY;
997
998         CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
999                cfs_atomic_read(&res->lr_refcount) - 1);
1000         LASSERTF(cfs_atomic_read(&res->lr_refcount) > 0, "%d",
1001                  cfs_atomic_read(&res->lr_refcount));
1002         LASSERTF(cfs_atomic_read(&res->lr_refcount) < LI_POISON, "%d",
1003                  cfs_atomic_read(&res->lr_refcount));
1004
1005         if (cfs_atomic_dec_and_lock(&res->lr_refcount, &ns->ns_hash_lock)) {
1006                 __ldlm_resource_putref_final(res);
1007                 cfs_spin_unlock(&ns->ns_hash_lock);
1008                 if (res->lr_lvb_data)
1009                         OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
1010                 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
1011                 rc = 1;
1012         }
1013
1014         RETURN(rc);
1015 }
1016
1017 /* Returns 1 if the resource was freed, 0 if it remains. */
1018 int ldlm_resource_putref_locked(struct ldlm_resource *res)
1019 {
1020         int rc = 0;
1021         ENTRY;
1022
1023         CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
1024                cfs_atomic_read(&res->lr_refcount) - 1);
1025         LASSERT(cfs_atomic_read(&res->lr_refcount) > 0);
1026         LASSERT(cfs_atomic_read(&res->lr_refcount) < LI_POISON);
1027
1028         LASSERT(cfs_atomic_read(&res->lr_refcount) >= 0);
1029         if (cfs_atomic_dec_and_test(&res->lr_refcount)) {
1030                 __ldlm_resource_putref_final(res);
1031                 if (res->lr_lvb_data)
1032                         OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
1033                 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
1034                 rc = 1;
1035         }
1036
1037         RETURN(rc);
1038 }
1039
1040 void ldlm_resource_add_lock(struct ldlm_resource *res, cfs_list_t *head,
1041                             struct ldlm_lock *lock)
1042 {
1043         check_res_locked(res);
1044
1045         ldlm_resource_dump(D_INFO, res);
1046         CDEBUG(D_OTHER, "About to add this lock:\n");
1047         ldlm_lock_dump(D_OTHER, lock, 0);
1048
1049         if (lock->l_destroyed) {
1050                 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
1051                 return;
1052         }
1053
1054         LASSERT(cfs_list_empty(&lock->l_res_link));
1055
1056         cfs_list_add_tail(&lock->l_res_link, head);
1057 }
1058
1059 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
1060                                      struct ldlm_lock *new)
1061 {
1062         struct ldlm_resource *res = original->l_resource;
1063
1064         check_res_locked(res);
1065
1066         ldlm_resource_dump(D_INFO, res);
1067         CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
1068         ldlm_lock_dump(D_OTHER, new, 0);
1069
1070         if (new->l_destroyed) {
1071                 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
1072                 goto out;
1073         }
1074
1075         LASSERT(cfs_list_empty(&new->l_res_link));
1076
1077         cfs_list_add(&new->l_res_link, &original->l_res_link);
1078  out:;
1079 }
1080
1081 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
1082 {
1083         int type = lock->l_resource->lr_type;
1084
1085         check_res_locked(lock->l_resource);
1086         if (type == LDLM_IBITS || type == LDLM_PLAIN)
1087                 ldlm_unlink_lock_skiplist(lock);
1088         else if (type == LDLM_EXTENT)
1089                 ldlm_extent_unlink_lock(lock);
1090         cfs_list_del_init(&lock->l_res_link);
1091 }
1092
1093 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
1094 {
1095         desc->lr_type = res->lr_type;
1096         desc->lr_name = res->lr_name;
1097 }
1098
1099 void ldlm_dump_all_namespaces(ldlm_side_t client, int level)
1100 {
1101         cfs_list_t *tmp;
1102
1103         if (!((libcfs_debug | D_ERROR) & level))
1104                 return;
1105
1106         cfs_mutex_down(ldlm_namespace_lock(client));
1107
1108         cfs_list_for_each(tmp, ldlm_namespace_list(client)) {
1109                 struct ldlm_namespace *ns;
1110                 ns = cfs_list_entry(tmp, struct ldlm_namespace, ns_list_chain);
1111                 ldlm_namespace_dump(level, ns);
1112         }
1113
1114         cfs_mutex_up(ldlm_namespace_lock(client));
1115 }
1116
1117 void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
1118 {
1119         cfs_list_t *tmp;
1120
1121         if (!((libcfs_debug | D_ERROR) & level))
1122                 return;
1123
1124         CDEBUG(level, "--- Namespace: %s (rc: %d, side: %s)\n",
1125                ns->ns_name, ns->ns_refcount,
1126                ns_is_client(ns) ? "client" : "server");
1127
1128         if (cfs_time_before(cfs_time_current(), ns->ns_next_dump))
1129                 return;
1130
1131         cfs_spin_lock(&ns->ns_hash_lock);
1132         tmp = ns->ns_root_list.next;
1133         while (tmp != &ns->ns_root_list) {
1134                 struct ldlm_resource *res;
1135                 res = cfs_list_entry(tmp, struct ldlm_resource, lr_childof);
1136
1137                 ldlm_resource_getref(res);
1138                 cfs_spin_unlock(&ns->ns_hash_lock);
1139                 LDLM_RESOURCE_ADDREF(res);
1140
1141                 lock_res(res);
1142                 ldlm_resource_dump(level, res);
1143                 unlock_res(res);
1144
1145                 LDLM_RESOURCE_DELREF(res);
1146                 cfs_spin_lock(&ns->ns_hash_lock);
1147                 tmp = tmp->next;
1148                 ldlm_resource_putref_locked(res);
1149         }
1150         ns->ns_next_dump = cfs_time_shift(10);
1151         cfs_spin_unlock(&ns->ns_hash_lock);
1152 }
1153
1154 void ldlm_resource_dump(int level, struct ldlm_resource *res)
1155 {
1156         cfs_list_t *tmp;
1157         int pos;
1158
1159         CLASSERT(RES_NAME_SIZE == 4);
1160
1161         if (!((libcfs_debug | D_ERROR) & level))
1162                 return;
1163
1164         CDEBUG(level, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
1165                ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
1166                res->lr_name.name[2], res->lr_name.name[3],
1167                cfs_atomic_read(&res->lr_refcount));
1168
1169         if (!cfs_list_empty(&res->lr_granted)) {
1170                 pos = 0;
1171                 CDEBUG(level, "Granted locks:\n");
1172                 cfs_list_for_each(tmp, &res->lr_granted) {
1173                         struct ldlm_lock *lock;
1174                         lock = cfs_list_entry(tmp, struct ldlm_lock,
1175                                               l_res_link);
1176                         ldlm_lock_dump(level, lock, ++pos);
1177                 }
1178         }
1179         if (!cfs_list_empty(&res->lr_converting)) {
1180                 pos = 0;
1181                 CDEBUG(level, "Converting locks:\n");
1182                 cfs_list_for_each(tmp, &res->lr_converting) {
1183                         struct ldlm_lock *lock;
1184                         lock = cfs_list_entry(tmp, struct ldlm_lock,
1185                                               l_res_link);
1186                         ldlm_lock_dump(level, lock, ++pos);
1187                 }
1188         }
1189         if (!cfs_list_empty(&res->lr_waiting)) {
1190                 pos = 0;
1191                 CDEBUG(level, "Waiting locks:\n");
1192                 cfs_list_for_each(tmp, &res->lr_waiting) {
1193                         struct ldlm_lock *lock;
1194                         lock = cfs_list_entry(tmp, struct ldlm_lock,
1195                                               l_res_link);
1196                         ldlm_lock_dump(level, lock, ++pos);
1197                 }
1198         }
1199 }