Whamcloud - gitweb
b=2321
[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  * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *   Author: Phil Schwan <phil@clusterfs.com>
6  *   Author: Peter Braam <braam@clusterfs.com>
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #define DEBUG_SUBSYSTEM S_LDLM
25 #ifdef __KERNEL__
26 # include <linux/lustre_dlm.h>
27 #else
28 # include <liblustre.h>
29 #endif
30
31 #include <linux/obd_class.h>
32 #include "ldlm_internal.h"
33
34 kmem_cache_t *ldlm_resource_slab, *ldlm_lock_slab;
35
36 spinlock_t ldlm_namespace_lock = SPIN_LOCK_UNLOCKED;
37 struct list_head ldlm_namespace_list = LIST_HEAD_INIT(ldlm_namespace_list);
38 struct proc_dir_entry *ldlm_type_proc_dir = NULL;
39 struct proc_dir_entry *ldlm_ns_proc_dir = NULL;
40 struct proc_dir_entry *ldlm_svc_proc_dir = NULL;
41
42 #ifdef __KERNEL__
43 static int ldlm_proc_dump_ns(struct file *file, const char *buffer, unsigned long count, void *data)
44 {
45         ldlm_dump_all_namespaces();
46         RETURN(count);
47 }
48
49 int ldlm_proc_setup(void)
50 {
51         int rc;
52         struct lprocfs_vars list[] = { 
53                 { "dump_namespaces", NULL, ldlm_proc_dump_ns, NULL },
54                 { NULL }};
55         ENTRY;
56         LASSERT(ldlm_ns_proc_dir == NULL);
57
58         ldlm_type_proc_dir = lprocfs_register(OBD_LDLM_DEVICENAME,
59                                                proc_lustre_root,
60                                                NULL, NULL);
61         if (IS_ERR(ldlm_type_proc_dir)) {
62                 CERROR("LProcFS failed in ldlm-init\n");
63                 rc = PTR_ERR(ldlm_type_proc_dir);
64                 GOTO(err, rc);
65         }
66
67         ldlm_ns_proc_dir = lprocfs_register("namespaces",
68                                             ldlm_type_proc_dir,
69                                             NULL, NULL);
70         if (IS_ERR(ldlm_ns_proc_dir)) {
71                 CERROR("LProcFS failed in ldlm-init\n");
72                 rc = PTR_ERR(ldlm_ns_proc_dir);
73                 GOTO(err_type, rc);
74         }
75
76         ldlm_svc_proc_dir = lprocfs_register("services",
77                                             ldlm_type_proc_dir,
78                                             NULL, NULL);
79         if (IS_ERR(ldlm_svc_proc_dir)) {
80                 CERROR("LProcFS failed in ldlm-init\n");
81                 rc = PTR_ERR(ldlm_svc_proc_dir);
82                 GOTO(err_ns, rc);
83         }
84
85         rc = lprocfs_add_vars(ldlm_type_proc_dir, list, NULL);
86
87         RETURN(0);
88
89 err_ns:        
90         lprocfs_remove(ldlm_ns_proc_dir);
91 err_type:        
92         lprocfs_remove(ldlm_type_proc_dir);
93 err:
94         ldlm_type_proc_dir = NULL;
95         ldlm_ns_proc_dir = NULL;
96         ldlm_svc_proc_dir = NULL;
97         RETURN(rc);
98 }
99
100 void ldlm_proc_cleanup(void)
101 {
102         if (ldlm_svc_proc_dir) {
103                 lprocfs_remove(ldlm_svc_proc_dir);
104                 ldlm_svc_proc_dir = NULL;
105         }
106
107         if (ldlm_ns_proc_dir) {
108                 lprocfs_remove(ldlm_ns_proc_dir);
109                 ldlm_ns_proc_dir = NULL;
110         }
111
112         if (ldlm_type_proc_dir) {
113                 lprocfs_remove(ldlm_type_proc_dir);
114                 ldlm_type_proc_dir = NULL;
115         }
116 }
117
118 static int lprocfs_uint_rd(char *page, char **start, off_t off,
119                            int count, int *eof, void *data)
120 {
121         unsigned int *temp = (unsigned int *)data;
122         return snprintf(page, count, "%u\n", *temp);
123 }
124
125 static int lprocfs_read_lru_size(char *page, char **start, off_t off,
126                                  int count, int *eof, void *data)
127 {
128         struct ldlm_namespace *ns = data;
129         return lprocfs_uint_rd(page, start, off, count, eof,
130                                &ns->ns_max_unused);
131 }
132
133 #define MAX_STRING_SIZE 128
134 static int lprocfs_write_lru_size(struct file *file, const char *buffer,
135                                   unsigned long count, void *data)
136 {
137         struct ldlm_namespace *ns = data;
138         char dummy[MAX_STRING_SIZE + 1];
139         unsigned long tmp;
140
141         dummy[MAX_STRING_SIZE] = '\0';
142         copy_from_user(dummy, buffer, MAX_STRING_SIZE);
143
144         if (count == 6 && memcmp(dummy, "clear", 5) == 0) {
145                 CDEBUG(D_DLMTRACE,
146                        "dropping all unused locks from namespace %s\n",
147                        ns->ns_name);
148                 tmp = ns->ns_max_unused;
149                 ns->ns_max_unused = 0;
150                 ldlm_cancel_lru(ns);
151                 ns->ns_max_unused = tmp;
152                 return count;
153         }
154
155         tmp = simple_strtoul(dummy, NULL, 0);
156         CDEBUG(D_DLMTRACE, "changing namespace %s max_unused from %u to %u\n",
157                ns->ns_name, ns->ns_max_unused, (unsigned int)tmp);
158         ns->ns_max_unused = (unsigned int)tmp;
159
160         ldlm_cancel_lru(ns);
161
162         return count;
163 }
164
165 void ldlm_proc_namespace(struct ldlm_namespace *ns)
166 {
167         struct lprocfs_vars lock_vars[2];
168         char lock_name[MAX_STRING_SIZE + 1];
169
170         LASSERT(ns != NULL);
171         LASSERT(ns->ns_name != NULL);
172
173         lock_name[MAX_STRING_SIZE] = '\0';
174
175         memset(lock_vars, 0, sizeof(lock_vars));
176         lock_vars[0].read_fptr = lprocfs_rd_u64;
177         lock_vars[0].name = lock_name;
178
179         snprintf(lock_name, MAX_STRING_SIZE, "%s/resource_count", ns->ns_name);
180         lock_vars[0].data = &ns->ns_resources;
181         lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
182
183         snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_count", ns->ns_name);
184         lock_vars[0].data = &ns->ns_locks;
185         lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
186
187         if (ns->ns_client) {
188                 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_unused_count",
189                          ns->ns_name);
190                 lock_vars[0].data = &ns->ns_nr_unused;
191                 lock_vars[0].read_fptr = lprocfs_uint_rd;
192                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
193
194                 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_size",
195                          ns->ns_name);
196                 lock_vars[0].data = ns;
197                 lock_vars[0].read_fptr = lprocfs_read_lru_size;
198                 lock_vars[0].write_fptr = lprocfs_write_lru_size;
199                 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
200         }
201 }
202 #endif
203 #undef MAX_STRING_SIZE
204
205 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
206 {
207         struct ldlm_namespace *ns = NULL;
208         struct list_head *bucket;
209         int rc;
210         ENTRY;
211
212         rc = ldlm_get_ref();
213         if (rc) {
214                 CERROR("ldlm_get_ref failed: %d\n", rc);
215                 RETURN(NULL);
216         }
217
218         OBD_ALLOC(ns, sizeof(*ns));
219         if (!ns)
220                 GOTO(out_ref, NULL);
221
222         OBD_VMALLOC(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
223         if (!ns->ns_hash)
224                 GOTO(out_ns, NULL);
225
226         OBD_ALLOC(ns->ns_name, strlen(name) + 1);
227         if (!ns->ns_name)
228                 GOTO(out_hash, NULL);
229
230         strcpy(ns->ns_name, name);
231
232         INIT_LIST_HEAD(&ns->ns_root_list);
233         l_lock_init(&ns->ns_lock);
234         ns->ns_refcount = 0;
235         ns->ns_client = client;
236         spin_lock_init(&ns->ns_counter_lock);
237         ns->ns_locks = 0;
238         ns->ns_resources = 0;
239
240         for (bucket = ns->ns_hash + RES_HASH_SIZE - 1; bucket >= ns->ns_hash;
241              bucket--)
242                 INIT_LIST_HEAD(bucket);
243
244         INIT_LIST_HEAD(&ns->ns_unused_list);
245         ns->ns_nr_unused = 0;
246         ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE;
247
248         spin_lock(&ldlm_namespace_lock);
249         list_add(&ns->ns_list_chain, &ldlm_namespace_list);
250         spin_unlock(&ldlm_namespace_lock);
251 #ifdef __KERNEL__
252         ldlm_proc_namespace(ns);
253 #endif
254         RETURN(ns);
255
256 out_hash:
257         POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
258         OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
259 out_ns:
260         OBD_FREE(ns, sizeof(*ns));
261 out_ref:
262         ldlm_put_ref(0);
263         RETURN(NULL);
264 }
265
266 extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
267
268 /* If flags contains FL_LOCAL_ONLY, don't try to tell the server, just cleanup.
269  * This is currently only used for recovery, and we make certain assumptions
270  * as a result--notably, that we shouldn't cancel locks with refs. -phil
271  *
272  * Called with the ns_lock held. */
273 static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
274                              int flags)
275 {
276         struct list_head *tmp, *pos;
277         int rc = 0, client = res->lr_namespace->ns_client;
278         int local_only = (flags & LDLM_FL_LOCAL_ONLY);
279         ENTRY;
280
281         list_for_each_safe(tmp, pos, q) {
282                 struct ldlm_lock *lock;
283                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
284                 LDLM_LOCK_GET(lock);
285
286                 if (local_only && (lock->l_readers || lock->l_writers)) {
287                         /* This is a little bit gross, but much better than the
288                          * alternative: pretend that we got a blocking AST from
289                          * the server, so that when the lock is decref'd, it
290                          * will go away ... */
291                         lock->l_flags |= LDLM_FL_CBPENDING;
292                         /* ... without sending a CANCEL message. */
293                         lock->l_flags |= LDLM_FL_LOCAL_ONLY;
294                         /* caller may also specify additional flags */
295                         lock->l_flags |= flags;
296                         LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY");
297                         LDLM_LOCK_PUT(lock);
298                         continue;
299                 }
300
301  
302                 lock->l_flags |= flags;
303
304                 if (client) {
305                         struct lustre_handle lockh;
306                         ldlm_lock2handle(lock, &lockh);
307                         if (!local_only) {
308                                 rc = ldlm_cli_cancel(&lockh);
309                                 if (rc)
310                                         CERROR("ldlm_cli_cancel: %d\n", rc);
311                         }
312                         /* Force local cleanup on errors, too. */
313                         if (local_only || rc != ELDLM_OK)
314                                 ldlm_lock_cancel(lock);
315                 } else {
316                         LDLM_DEBUG(lock, "Freeing a lock still held by a "
317                                    "client node");
318
319                         ldlm_resource_unlink_lock(lock);
320                         ldlm_lock_destroy(lock);
321                 }
322                 LDLM_LOCK_PUT(lock);
323         }
324         EXIT;
325 }
326
327 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags)
328 {
329         int i;
330
331         if (ns == NULL) {
332                 CDEBUG(D_INFO, "NULL ns, skipping cleanup\n");
333                 return ELDLM_OK;
334         }
335
336         l_lock(&ns->ns_lock);
337         for (i = 0; i < RES_HASH_SIZE; i++) {
338                 struct list_head *tmp, *pos;
339                 list_for_each_safe(tmp, pos, &(ns->ns_hash[i])) {
340                         struct ldlm_resource *res;
341                         res = list_entry(tmp, struct ldlm_resource, lr_hash);
342                         ldlm_resource_getref(res);
343
344                         cleanup_resource(res, &res->lr_granted, flags);
345                         cleanup_resource(res, &res->lr_converting, flags);
346                         cleanup_resource(res, &res->lr_waiting, flags);
347
348                         /* XXX what a mess: don't force cleanup if we're
349                          * local_only (which is only used by recovery).  In that
350                          * case, we probably still have outstanding lock refs
351                          * which reference these resources. -phil */
352                         if (!ldlm_resource_putref(res) &&
353                             !(flags & LDLM_FL_LOCAL_ONLY)) {
354                                 CERROR("Resource refcount nonzero (%d) after "
355                                        "lock cleanup; forcing cleanup.\n",
356                                        atomic_read(&res->lr_refcount));
357                                 ldlm_resource_dump(res);
358                                 atomic_set(&res->lr_refcount, 1);
359                                 ldlm_resource_putref(res);
360                         }
361                 }
362         }
363         l_unlock(&ns->ns_lock);
364
365         return ELDLM_OK;
366 }
367
368 /* Cleanup, but also free, the namespace */
369 int ldlm_namespace_free(struct ldlm_namespace *ns, int force)
370 {
371         if (!ns)
372                 RETURN(ELDLM_OK);
373
374         spin_lock(&ldlm_namespace_lock);
375         list_del(&ns->ns_list_chain);
376
377         spin_unlock(&ldlm_namespace_lock);
378
379         /* At shutdown time, don't call the cancellation callback */
380         ldlm_namespace_cleanup(ns, LDLM_FL_CANCEL);
381
382 #ifdef __KERNEL__
383         {
384                 struct proc_dir_entry *dir;
385                 dir = lprocfs_srch(ldlm_ns_proc_dir, ns->ns_name);
386                 if (dir == NULL) {
387                         CERROR("dlm namespace %s has no procfs dir?\n",
388                                ns->ns_name);
389                 } else {
390                         lprocfs_remove(dir);
391                 }
392         }
393 #endif
394
395         POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
396         OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
397         OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
398         OBD_FREE(ns, sizeof(*ns));
399
400         ldlm_put_ref(force);
401
402         return ELDLM_OK;
403 }
404
405 static __u32 ldlm_hash_fn(struct ldlm_resource *parent, struct ldlm_res_id name)
406 {
407         __u32 hash = 0;
408         int i;
409
410         for (i = 0; i < RES_NAME_SIZE; i++)
411                 hash += name.name[i];
412
413         hash += (__u32)((unsigned long)parent >> 4);
414
415         return (hash & RES_HASH_MASK);
416 }
417
418 static struct ldlm_resource *ldlm_resource_new(void)
419 {
420         struct ldlm_resource *res;
421
422         OBD_SLAB_ALLOC(res, ldlm_resource_slab, SLAB_KERNEL, sizeof *res);
423         if (res == NULL) {
424                 LBUG();
425                 return NULL;
426         }
427         memset(res, 0, sizeof(*res));
428
429         INIT_LIST_HEAD(&res->lr_children);
430         INIT_LIST_HEAD(&res->lr_childof);
431         INIT_LIST_HEAD(&res->lr_granted);
432         INIT_LIST_HEAD(&res->lr_converting);
433         INIT_LIST_HEAD(&res->lr_waiting);
434
435         atomic_set(&res->lr_refcount, 1);
436
437         return res;
438 }
439
440 /* Args: locked namespace
441  * Returns: newly-allocated, referenced, unlocked resource */
442 static struct ldlm_resource *
443 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
444                   struct ldlm_res_id name, __u32 type)
445 {
446         struct list_head *bucket;
447         struct ldlm_resource *res;
448         ENTRY;
449
450         if (type < LDLM_MIN_TYPE || type > LDLM_MAX_TYPE) {
451                 LBUG();
452                 RETURN(NULL);
453         }
454
455         res = ldlm_resource_new();
456         if (!res) {
457                 LBUG();
458                 RETURN(NULL);
459         }
460
461         spin_lock(&ns->ns_counter_lock);
462         ns->ns_resources++;
463         spin_unlock(&ns->ns_counter_lock);
464
465         l_lock(&ns->ns_lock);
466         memcpy(&res->lr_name, &name, sizeof(res->lr_name));
467         res->lr_namespace = ns;
468         ns->ns_refcount++;
469
470         res->lr_type = type;
471         res->lr_most_restr = LCK_NL;
472
473         bucket = ns->ns_hash + ldlm_hash_fn(parent, name);
474         list_add(&res->lr_hash, bucket);
475
476         if (parent == NULL) {
477                 list_add(&res->lr_childof, &ns->ns_root_list);
478         } else {
479                 res->lr_parent = parent;
480                 list_add(&res->lr_childof, &parent->lr_children);
481         }
482         l_unlock(&ns->ns_lock);
483
484         RETURN(res);
485 }
486
487 /* Args: unlocked namespace
488  * Locks: takes and releases ns->ns_lock and res->lr_lock
489  * Returns: referenced, unlocked ldlm_resource or NULL */
490 struct ldlm_resource *
491 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
492                   struct ldlm_res_id name, __u32 type, int create)
493 {
494         struct list_head *bucket, *tmp;
495         struct ldlm_resource *res = NULL;
496         ENTRY;
497
498         LASSERT(ns != NULL);
499         LASSERT(ns->ns_hash != NULL);
500         LASSERT(name.name[0] != 0);
501
502         l_lock(&ns->ns_lock);
503         bucket = ns->ns_hash + ldlm_hash_fn(parent, name);
504
505         list_for_each(tmp, bucket) {
506                 res = list_entry(tmp, struct ldlm_resource, lr_hash);
507
508                 if (memcmp(&res->lr_name, &name, sizeof(res->lr_name)) == 0) {
509                         ldlm_resource_getref(res);
510                         l_unlock(&ns->ns_lock);
511                         RETURN(res);
512                 }
513         }
514
515         if (create)
516                 res = ldlm_resource_add(ns, parent, name, type);
517         else
518                 res = NULL;
519
520         l_unlock(&ns->ns_lock);
521
522         RETURN(res);
523 }
524
525 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
526 {
527         LASSERT(res != NULL);
528         LASSERT(res != (void *)0x5a5a5a5a);
529         atomic_inc(&res->lr_refcount);
530         CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
531                atomic_read(&res->lr_refcount));
532         return res;
533 }
534
535 /* Returns 1 if the resource was freed, 0 if it remains. */
536 int ldlm_resource_putref(struct ldlm_resource *res)
537 {
538         int rc = 0;
539         ENTRY;
540
541         CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
542                atomic_read(&res->lr_refcount) - 1);
543         LASSERT(atomic_read(&res->lr_refcount) > 0);
544         LASSERT(atomic_read(&res->lr_refcount) < 0x5a5a5a5a);
545
546         if (atomic_dec_and_test(&res->lr_refcount)) {
547                 struct ldlm_namespace *ns = res->lr_namespace;
548                 ENTRY;
549
550                 l_lock(&ns->ns_lock);
551
552                 if (atomic_read(&res->lr_refcount) != 0) {
553                         /* We lost the race. */
554                         l_unlock(&ns->ns_lock);
555                         RETURN(rc);
556                 }
557
558                 if (!list_empty(&res->lr_granted)) {
559                         ldlm_resource_dump(res);
560                         LBUG();
561                 }
562
563                 if (!list_empty(&res->lr_converting)) {
564                         ldlm_resource_dump(res);
565                         LBUG();
566                 }
567
568                 if (!list_empty(&res->lr_waiting)) {
569                         ldlm_resource_dump(res);
570                         LBUG();
571                 }
572
573                 if (!list_empty(&res->lr_children)) {
574                         ldlm_resource_dump(res);
575                         LBUG();
576                 }
577
578                 ns->ns_refcount--;
579                 list_del_init(&res->lr_hash);
580                 list_del_init(&res->lr_childof);
581                 l_unlock(&ns->ns_lock);
582
583                 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
584
585                 spin_lock(&ns->ns_counter_lock);
586                 ns->ns_resources--;
587                 spin_unlock(&ns->ns_counter_lock);
588
589                 rc = 1;
590                 EXIT;
591         }
592
593         RETURN(rc);
594 }
595
596 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
597                             struct ldlm_lock *lock)
598 {
599         l_lock(&res->lr_namespace->ns_lock);
600
601         ldlm_resource_dump(res);
602         CDEBUG(D_OTHER, "About to add this lock:\n");
603         ldlm_lock_dump(D_OTHER, lock, 0);
604
605         if (lock->l_destroyed) {
606                 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
607                 goto out;
608         }
609
610         LASSERT(list_empty(&lock->l_res_link));
611
612         list_add_tail(&lock->l_res_link, head);
613  out:
614         l_unlock(&res->lr_namespace->ns_lock);
615 }
616
617 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
618 {
619         l_lock(&lock->l_resource->lr_namespace->ns_lock);
620         list_del_init(&lock->l_res_link);
621         l_unlock(&lock->l_resource->lr_namespace->ns_lock);
622 }
623
624 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
625 {
626         desc->lr_type = res->lr_type;
627         memcpy(&desc->lr_name, &res->lr_name, sizeof(desc->lr_name));
628         memcpy(desc->lr_version, res->lr_version, sizeof(desc->lr_version));
629 }
630
631 void ldlm_dump_all_namespaces(void)
632 {
633         struct list_head *tmp;
634
635         spin_lock(&ldlm_namespace_lock);
636
637         list_for_each(tmp, &ldlm_namespace_list) {
638                 struct ldlm_namespace *ns;
639                 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
640                 ldlm_namespace_dump(ns);
641         }
642
643         spin_unlock(&ldlm_namespace_lock);
644 }
645
646 void ldlm_namespace_dump(struct ldlm_namespace *ns)
647 {
648         struct list_head *tmp;
649
650         l_lock(&ns->ns_lock);
651         CDEBUG(D_OTHER, "--- Namespace: %s (rc: %d, client: %d)\n", ns->ns_name,
652                ns->ns_refcount, ns->ns_client);
653
654         list_for_each(tmp, &ns->ns_root_list) {
655                 struct ldlm_resource *res;
656                 res = list_entry(tmp, struct ldlm_resource, lr_childof);
657
658                 /* Once we have resources with children, this should really dump
659                  * them recursively. */
660                 ldlm_resource_dump(res);
661         }
662         l_unlock(&ns->ns_lock);
663 }
664
665 void ldlm_resource_dump(struct ldlm_resource *res)
666 {
667         struct list_head *tmp;
668         int pos;
669
670         if (RES_NAME_SIZE != 4)
671                 LBUG();
672
673         CDEBUG(D_OTHER, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
674                ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
675                res->lr_name.name[2], res->lr_name.name[3],
676                atomic_read(&res->lr_refcount));
677         CDEBUG(D_OTHER, "Namespace: %p (%s)\n", res->lr_namespace,
678                res->lr_namespace->ns_name);
679         CDEBUG(D_OTHER, "Parent: %p, root: %p\n", res->lr_parent, res->lr_root);
680
681         CDEBUG(D_OTHER, "Granted locks:\n");
682         pos = 0;
683         list_for_each(tmp, &res->lr_granted) {
684                 struct ldlm_lock *lock;
685                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
686                 ldlm_lock_dump(D_OTHER, lock, ++pos);
687         }
688         pos = 0;
689         CDEBUG(D_OTHER, "Converting locks:\n");
690         list_for_each(tmp, &res->lr_converting) {
691                 struct ldlm_lock *lock;
692                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
693                 ldlm_lock_dump(D_OTHER, lock, ++pos);
694         }
695         pos = 0;
696         CDEBUG(D_OTHER, "Waiting locks:\n");
697         list_for_each(tmp, &res->lr_waiting) {
698                 struct ldlm_lock *lock;
699                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
700                 ldlm_lock_dump(D_OTHER, lock, ++pos);
701         }
702 }