1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5 * Author: Phil Schwan <phil@clusterfs.com>
6 * Author: Peter Braam <braam@clusterfs.com>
8 * This file is part of the Lustre file system, http://www.lustre.org
9 * Lustre is a trademark of Cluster File Systems, Inc.
11 * You may have signed or agreed to another license before downloading
12 * this software. If so, you are bound by the terms and conditions
13 * of that agreement, and the following does not apply to you. See the
14 * LICENSE file included with this distribution for more information.
16 * If you did not agree to a different license, then this copy of Lustre
17 * is open source software; you can redistribute it and/or modify it
18 * under the terms of version 2 of the GNU General Public License as
19 * published by the Free Software Foundation.
21 * In either case, Lustre is distributed in the hope that it will be
22 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * license text for more details.
27 #define DEBUG_SUBSYSTEM S_LDLM
29 # include <lustre_dlm.h>
31 # include <liblustre.h>
34 #include <obd_class.h>
35 #include "ldlm_internal.h"
37 cfs_mem_cache_t *ldlm_resource_slab, *ldlm_lock_slab;
39 struct semaphore ldlm_namespace_lock;
40 struct list_head ldlm_namespace_list = CFS_LIST_HEAD_INIT(ldlm_namespace_list);
41 cfs_proc_dir_entry_t *ldlm_type_proc_dir = NULL;
42 cfs_proc_dir_entry_t *ldlm_ns_proc_dir = NULL;
43 cfs_proc_dir_entry_t *ldlm_svc_proc_dir = NULL;
46 static int ldlm_proc_dump_ns(struct file *file, const char *buffer,
47 unsigned long count, void *data)
49 ldlm_dump_all_namespaces(D_DLMTRACE);
53 int ldlm_proc_setup(void)
56 struct lprocfs_vars list[] = {
57 { "dump_namespaces", NULL, ldlm_proc_dump_ns, NULL },
60 LASSERT(ldlm_ns_proc_dir == NULL);
62 ldlm_type_proc_dir = lprocfs_register(OBD_LDLM_DEVICENAME,
65 if (IS_ERR(ldlm_type_proc_dir)) {
66 CERROR("LProcFS failed in ldlm-init\n");
67 rc = PTR_ERR(ldlm_type_proc_dir);
71 ldlm_ns_proc_dir = lprocfs_register("namespaces",
74 if (IS_ERR(ldlm_ns_proc_dir)) {
75 CERROR("LProcFS failed in ldlm-init\n");
76 rc = PTR_ERR(ldlm_ns_proc_dir);
80 ldlm_svc_proc_dir = lprocfs_register("services",
83 if (IS_ERR(ldlm_svc_proc_dir)) {
84 CERROR("LProcFS failed in ldlm-init\n");
85 rc = PTR_ERR(ldlm_svc_proc_dir);
89 rc = lprocfs_add_vars(ldlm_type_proc_dir, list, NULL);
94 lprocfs_remove(&ldlm_ns_proc_dir);
96 lprocfs_remove(&ldlm_type_proc_dir);
98 ldlm_svc_proc_dir = NULL;
102 void ldlm_proc_cleanup(void)
104 if (ldlm_svc_proc_dir)
105 lprocfs_remove(&ldlm_svc_proc_dir);
107 if (ldlm_ns_proc_dir)
108 lprocfs_remove(&ldlm_ns_proc_dir);
110 if (ldlm_type_proc_dir)
111 lprocfs_remove(&ldlm_type_proc_dir);
114 static int lprocfs_uint_rd(char *page, char **start, off_t off,
115 int count, int *eof, void *data)
117 unsigned int *temp = (unsigned int *)data;
118 return snprintf(page, count, "%u\n", *temp);
121 #define MAX_STRING_SIZE 128
122 static int lprocfs_uint_wr(struct file *file, const char *buffer,
123 unsigned long count, void *data)
126 char dummy[MAX_STRING_SIZE + 1], *end;
129 dummy[MAX_STRING_SIZE] = '\0';
130 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
133 tmp = simple_strtoul(dummy, &end, 0);
137 *p = (unsigned int)tmp;
141 static int lprocfs_read_lru_size(char *page, char **start, off_t off,
142 int count, int *eof, void *data)
144 struct ldlm_namespace *ns = data;
145 return lprocfs_uint_rd(page, start, off, count, eof,
149 static int lprocfs_write_lru_size(struct file *file, const char *buffer,
150 unsigned long count, void *data)
152 struct ldlm_namespace *ns = data;
153 char dummy[MAX_STRING_SIZE + 1], *end;
156 dummy[MAX_STRING_SIZE] = '\0';
157 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
160 if (count == 6 && memcmp(dummy, "clear", 5) == 0) {
162 "dropping all unused locks from namespace %s\n",
164 tmp = ns->ns_max_unused;
165 ns->ns_max_unused = 0;
166 ldlm_cancel_lru(ns, LDLM_SYNC);
167 ns->ns_max_unused = tmp;
171 tmp = simple_strtoul(dummy, &end, 0);
172 if (tmp == 0 && *end) {
173 CERROR("invalid value written\n");
177 CDEBUG(D_DLMTRACE, "changing namespace %s max_unused from %u to %u\n",
178 ns->ns_name, ns->ns_max_unused, (unsigned int)tmp);
179 ns->ns_max_unused = (unsigned int)tmp;
181 ldlm_cancel_lru(ns, LDLM_ASYNC);
186 void ldlm_proc_namespace(struct ldlm_namespace *ns)
188 struct lprocfs_vars lock_vars[2];
189 char lock_name[MAX_STRING_SIZE + 1];
192 LASSERT(ns->ns_name != NULL);
194 lock_name[MAX_STRING_SIZE] = '\0';
196 memset(lock_vars, 0, sizeof(lock_vars));
197 lock_vars[0].name = lock_name;
199 snprintf(lock_name, MAX_STRING_SIZE, "%s/resource_count", ns->ns_name);
200 lock_vars[0].data = &ns->ns_refcount;
201 lock_vars[0].read_fptr = lprocfs_rd_atomic;
202 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
204 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_count", ns->ns_name);
205 lock_vars[0].data = &ns->ns_locks;
206 lock_vars[0].read_fptr = lprocfs_rd_atomic;
207 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
210 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_unused_count",
212 lock_vars[0].data = &ns->ns_nr_unused;
213 lock_vars[0].read_fptr = lprocfs_uint_rd;
214 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
216 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_size",
218 lock_vars[0].data = ns;
219 lock_vars[0].read_fptr = lprocfs_read_lru_size;
220 lock_vars[0].write_fptr = lprocfs_write_lru_size;
221 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
223 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_max_age",
225 lock_vars[0].data = &ns->ns_max_age;
226 lock_vars[0].read_fptr = lprocfs_uint_rd;
227 lock_vars[0].write_fptr = lprocfs_uint_wr;
228 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
231 #undef MAX_STRING_SIZE
233 #define ldlm_proc_namespace(ns) do {} while (0)
236 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
238 struct ldlm_namespace *ns = NULL;
239 struct list_head *bucket;
245 CERROR("ldlm_get_ref failed: %d\n", rc);
249 OBD_ALLOC(ns, sizeof(*ns));
253 OBD_VMALLOC(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
257 OBD_ALLOC(ns->ns_name, strlen(name) + 1);
259 GOTO(out_hash, NULL);
261 strcpy(ns->ns_name, name);
263 CFS_INIT_LIST_HEAD(&ns->ns_root_list);
265 ns->ns_client = client;
266 spin_lock_init(&ns->ns_hash_lock);
267 atomic_set(&ns->ns_locks, 0);
268 ns->ns_resources = 0;
269 cfs_waitq_init(&ns->ns_waitq);
271 for (bucket = ns->ns_hash + RES_HASH_SIZE - 1; bucket >= ns->ns_hash;
273 CFS_INIT_LIST_HEAD(bucket);
275 CFS_INIT_LIST_HEAD(&ns->ns_unused_list);
276 ns->ns_nr_unused = 0;
277 ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE;
278 ns->ns_max_age = LDLM_DEFAULT_MAX_ALIVE;
279 spin_lock_init(&ns->ns_unused_lock);
281 mutex_down(&ldlm_namespace_lock);
282 list_add(&ns->ns_list_chain, &ldlm_namespace_list);
283 mutex_up(&ldlm_namespace_lock);
284 ldlm_proc_namespace(ns);
288 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
289 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
291 OBD_FREE(ns, sizeof(*ns));
297 extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
299 /* If flags contains FL_LOCAL_ONLY, don't try to tell the server, just cleanup.
300 * This is currently only used for recovery, and we make certain assumptions
301 * as a result--notably, that we shouldn't cancel locks with refs. -phil
303 * Called with the ns_lock held. */
304 static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
307 struct list_head *tmp;
308 int rc = 0, client = res->lr_namespace->ns_client;
309 int local_only = (flags & LDLM_FL_LOCAL_ONLY);
314 struct ldlm_lock *lock = NULL;
316 /* first, we look for non-cleaned-yet lock
317 * all cleaned locks are marked by CLEANED flag */
319 list_for_each(tmp, q) {
320 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
321 if (lock->l_flags & LDLM_FL_CLEANED) {
326 lock->l_flags |= LDLM_FL_CLEANED;
335 /* Set CBPENDING so nothing in the cancellation path
336 * can match this lock */
337 lock->l_flags |= LDLM_FL_CBPENDING;
338 lock->l_flags |= LDLM_FL_FAILED;
339 lock->l_flags |= flags;
341 /* ... without sending a CANCEL message for local_only. */
343 lock->l_flags |= LDLM_FL_LOCAL_ONLY;
345 if (local_only && (lock->l_readers || lock->l_writers)) {
346 /* This is a little bit gross, but much better than the
347 * alternative: pretend that we got a blocking AST from
348 * the server, so that when the lock is decref'd, it
349 * will go away ... */
351 LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY");
352 if (lock->l_completion_ast)
353 lock->l_completion_ast(lock, 0, NULL);
359 struct lustre_handle lockh;
362 ldlm_lock2handle(lock, &lockh);
363 rc = ldlm_cli_cancel(&lockh);
365 CERROR("ldlm_cli_cancel: %d\n", rc);
367 ldlm_resource_unlink_lock(lock);
369 LDLM_DEBUG(lock, "Freeing a lock still held by a "
371 ldlm_lock_destroy(lock);
379 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags)
381 struct list_head *tmp;
385 CDEBUG(D_INFO, "NULL ns, skipping cleanup\n");
389 for (i = 0; i < RES_HASH_SIZE; i++) {
390 spin_lock(&ns->ns_hash_lock);
391 tmp = ns->ns_hash[i].next;
392 while (tmp != &(ns->ns_hash[i])) {
393 struct ldlm_resource *res;
394 res = list_entry(tmp, struct ldlm_resource, lr_hash);
395 ldlm_resource_getref(res);
396 spin_unlock(&ns->ns_hash_lock);
398 cleanup_resource(res, &res->lr_granted, flags);
399 cleanup_resource(res, &res->lr_converting, flags);
400 cleanup_resource(res, &res->lr_waiting, flags);
402 spin_lock(&ns->ns_hash_lock);
405 /* XXX: former stuff caused issues in case of race
406 * between ldlm_namespace_cleanup() and lockd() when
407 * client gets blocking ast when lock gets distracted by
408 * server. This is 1_4 branch solution, let's see how
410 if (!ldlm_resource_putref_locked(res))
412 "Namespace %s resource refcount nonzero "
413 "(%d) after lock cleanup; forcing cleanup.\n",
414 ns->ns_name, atomic_read(&res->lr_refcount));
416 spin_unlock(&ns->ns_hash_lock);
422 /* Cleanup, but also free, the namespace */
423 int ldlm_namespace_free(struct ldlm_namespace *ns, int force)
429 mutex_down(&ldlm_namespace_lock);
430 list_del(&ns->ns_list_chain);
431 mutex_up(&ldlm_namespace_lock);
433 /* At shutdown time, don't call the cancellation callback */
434 ldlm_namespace_cleanup(ns, 0);
438 struct proc_dir_entry *dir;
439 dir = lprocfs_srch(ldlm_ns_proc_dir, ns->ns_name);
441 CERROR("dlm namespace %s has no procfs dir?\n",
444 lprocfs_remove(&dir);
449 if (ns->ns_refcount > 0) {
450 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
453 "dlm namespace %s free waiting on refcount %d\n",
454 ns->ns_name, ns->ns_refcount);
455 rc = l_wait_event(ns->ns_waitq,
456 ns->ns_refcount == 0, &lwi);
458 LCONSOLE_ERROR_MSG(0x139, "Lock manager: wait for %s "
459 "namespace cleanup aborted with %d "
460 "resources in use. (%d)\nI'm going "
461 "to try to clean up anyway, but I "
462 "might need a reboot of this node.\n",
463 ns->ns_name, (int) ns->ns_refcount,
466 "dlm namespace %s free done waiting\n", ns->ns_name);
469 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
470 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
471 OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
472 OBD_FREE(ns, sizeof(*ns));
479 static __u32 ldlm_hash_fn(struct ldlm_resource *parent, struct ldlm_res_id name)
484 for (i = 0; i < RES_NAME_SIZE; i++)
485 hash += name.name[i];
487 hash += (__u32)((unsigned long)parent >> 4);
489 return (hash & RES_HASH_MASK);
492 static struct ldlm_resource *ldlm_resource_new(void)
494 struct ldlm_resource *res;
496 OBD_SLAB_ALLOC(res, ldlm_resource_slab, CFS_ALLOC_IO, sizeof *res);
500 memset(res, 0, sizeof(*res));
502 CFS_INIT_LIST_HEAD(&res->lr_children);
503 CFS_INIT_LIST_HEAD(&res->lr_childof);
504 CFS_INIT_LIST_HEAD(&res->lr_granted);
505 CFS_INIT_LIST_HEAD(&res->lr_converting);
506 CFS_INIT_LIST_HEAD(&res->lr_waiting);
507 atomic_set(&res->lr_refcount, 1);
508 spin_lock_init(&res->lr_lock);
510 /* one who creates the resource must unlock
511 * the semaphore after lvb initialization */
512 init_MUTEX_LOCKED(&res->lr_lvb_sem);
517 /* must be called with hash lock held */
518 static struct ldlm_resource *
519 ldlm_resource_find(struct ldlm_namespace *ns, struct ldlm_res_id name, __u32 hash)
521 struct list_head *bucket, *tmp;
522 struct ldlm_resource *res;
524 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
525 bucket = ns->ns_hash + hash;
527 list_for_each(tmp, bucket) {
528 res = list_entry(tmp, struct ldlm_resource, lr_hash);
529 if (memcmp(&res->lr_name, &name, sizeof(res->lr_name)) == 0)
536 /* Args: locked namespace
537 * Returns: newly-allocated, referenced, unlocked resource */
538 static struct ldlm_resource *
539 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
540 struct ldlm_res_id name, __u32 hash, ldlm_type_t type)
542 struct list_head *bucket;
543 struct ldlm_resource *res, *old_res;
546 LASSERTF(type >= LDLM_MIN_TYPE && type < LDLM_MAX_TYPE,
549 res = ldlm_resource_new();
554 res->lr_namespace = ns;
556 res->lr_most_restr = LCK_NL;
558 spin_lock(&ns->ns_hash_lock);
559 old_res = ldlm_resource_find(ns, name, hash);
561 /* someone won the race and added the resource before */
562 ldlm_resource_getref(old_res);
563 spin_unlock(&ns->ns_hash_lock);
564 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
565 /* synchronize WRT resource creation */
566 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
567 down(&old_res->lr_lvb_sem);
568 up(&old_res->lr_lvb_sem);
573 /* we won! let's add the resource */
574 bucket = ns->ns_hash + hash;
575 list_add(&res->lr_hash, bucket);
579 if (parent == NULL) {
580 list_add(&res->lr_childof, &ns->ns_root_list);
582 res->lr_parent = parent;
583 list_add(&res->lr_childof, &parent->lr_children);
585 spin_unlock(&ns->ns_hash_lock);
587 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
590 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
591 rc = ns->ns_lvbo->lvbo_init(res);
593 CERROR("lvbo_init failed for resource "
594 LPU64": rc %d\n", name.name[0], rc);
595 /* we create resource with locked lr_lvb_sem */
596 up(&res->lr_lvb_sem);
602 /* Args: unlocked namespace
603 * Locks: takes and releases ns->ns_lock and res->lr_lock
604 * Returns: referenced, unlocked ldlm_resource or NULL */
605 struct ldlm_resource *
606 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
607 struct ldlm_res_id name, ldlm_type_t type, int create)
609 __u32 hash = ldlm_hash_fn(parent, name);
610 struct ldlm_resource *res = NULL;
614 LASSERT(ns->ns_hash != NULL);
615 LASSERT(name.name[0] != 0);
617 spin_lock(&ns->ns_hash_lock);
618 res = ldlm_resource_find(ns, name, hash);
620 ldlm_resource_getref(res);
621 spin_unlock(&ns->ns_hash_lock);
622 /* synchronize WRT resource creation */
623 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
624 down(&res->lr_lvb_sem);
625 up(&res->lr_lvb_sem);
629 spin_unlock(&ns->ns_hash_lock);
634 res = ldlm_resource_add(ns, parent, name, hash, type);
638 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
640 LASSERT(res != NULL);
641 LASSERT(res != LP_POISON);
642 atomic_inc(&res->lr_refcount);
643 CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
644 atomic_read(&res->lr_refcount));
648 void __ldlm_resource_putref_final(struct ldlm_resource *res)
650 struct ldlm_namespace *ns = res->lr_namespace;
652 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
654 if (!list_empty(&res->lr_granted)) {
655 ldlm_resource_dump(D_ERROR, res);
659 if (!list_empty(&res->lr_converting)) {
660 ldlm_resource_dump(D_ERROR, res);
664 if (!list_empty(&res->lr_waiting)) {
665 ldlm_resource_dump(D_ERROR, res);
669 if (!list_empty(&res->lr_children)) {
670 ldlm_resource_dump(D_ERROR, res);
675 list_del_init(&res->lr_hash);
676 list_del_init(&res->lr_childof);
679 if (ns->ns_resources == 0)
680 wake_up(&ns->ns_waitq);
683 /* Returns 1 if the resource was freed, 0 if it remains. */
684 int ldlm_resource_putref(struct ldlm_resource *res)
686 struct ldlm_namespace *ns = res->lr_namespace;
690 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
691 atomic_read(&res->lr_refcount) - 1);
692 LASSERTF(atomic_read(&res->lr_refcount) > 0, "%d",
693 atomic_read(&res->lr_refcount));
694 LASSERTF(atomic_read(&res->lr_refcount) < LI_POISON, "%d",
695 atomic_read(&res->lr_refcount));
697 if (atomic_dec_and_lock(&res->lr_refcount, &ns->ns_hash_lock)) {
698 __ldlm_resource_putref_final(res);
699 spin_unlock(&ns->ns_hash_lock);
700 if (res->lr_lvb_data)
701 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
702 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
709 /* Returns 1 if the resource was freed, 0 if it remains. */
710 int ldlm_resource_putref_locked(struct ldlm_resource *res)
715 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
716 atomic_read(&res->lr_refcount) - 1);
717 LASSERT(atomic_read(&res->lr_refcount) > 0);
718 LASSERT(atomic_read(&res->lr_refcount) < LI_POISON);
720 LASSERT(atomic_read(&res->lr_refcount) >= 0);
721 if (atomic_dec_and_test(&res->lr_refcount)) {
722 __ldlm_resource_putref_final(res);
723 if (res->lr_lvb_data)
724 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
725 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
732 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
733 struct ldlm_lock *lock)
735 check_res_locked(res);
737 ldlm_resource_dump(D_OTHER, res);
738 CDEBUG(D_OTHER, "About to add this lock:\n");
739 ldlm_lock_dump(D_OTHER, lock, 0);
741 if (lock->l_destroyed) {
742 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
746 LASSERT(list_empty(&lock->l_res_link));
748 list_add_tail(&lock->l_res_link, head);
751 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
752 struct ldlm_lock *new)
754 struct ldlm_resource *res = original->l_resource;
756 check_res_locked(res);
758 ldlm_resource_dump(D_OTHER, res);
759 CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
760 ldlm_lock_dump(D_OTHER, new, 0);
762 if (new->l_destroyed) {
763 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
767 LASSERT(list_empty(&new->l_res_link));
769 list_add(&new->l_res_link, &original->l_res_link);
773 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
775 check_res_locked(lock->l_resource);
776 ldlm_unlink_lock_skiplist(lock);
777 list_del_init(&lock->l_res_link);
780 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
782 desc->lr_type = res->lr_type;
783 desc->lr_name = res->lr_name;
786 void ldlm_dump_all_namespaces(int level)
788 struct list_head *tmp;
790 if (!((libcfs_debug | D_ERROR) & level))
793 mutex_down(&ldlm_namespace_lock);
795 list_for_each(tmp, &ldlm_namespace_list) {
796 struct ldlm_namespace *ns;
797 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
798 ldlm_namespace_dump(level, ns);
801 mutex_up(&ldlm_namespace_lock);
804 void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
806 struct list_head *tmp;
808 if (!((libcfs_debug | D_ERROR) & level))
811 CDEBUG(level, "--- Namespace: %s (rc: %d, client: %d)\n",
812 ns->ns_name, ns->ns_refcount, ns->ns_client);
814 if (cfs_time_before(cfs_time_current(), ns->ns_next_dump))
817 spin_lock(&ns->ns_hash_lock);
818 tmp = ns->ns_root_list.next;
819 while (tmp != &ns->ns_root_list) {
820 struct ldlm_resource *res;
821 res = list_entry(tmp, struct ldlm_resource, lr_childof);
823 ldlm_resource_getref(res);
824 spin_unlock(&ns->ns_hash_lock);
827 ldlm_resource_dump(level, res);
830 spin_lock(&ns->ns_hash_lock);
832 ldlm_resource_putref_locked(res);
834 ns->ns_next_dump = cfs_time_shift(10);
835 spin_unlock(&ns->ns_hash_lock);
838 void ldlm_resource_dump(int level, struct ldlm_resource *res)
840 struct list_head *tmp;
843 CLASSERT(RES_NAME_SIZE == 4);
845 if (!((libcfs_debug | D_ERROR) & level))
848 CDEBUG(level, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
849 ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
850 res->lr_name.name[2], res->lr_name.name[3],
851 atomic_read(&res->lr_refcount));
853 if (!list_empty(&res->lr_granted)) {
855 CDEBUG(level, "Granted locks:\n");
856 list_for_each(tmp, &res->lr_granted) {
857 struct ldlm_lock *lock;
858 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
859 ldlm_lock_dump(level, lock, ++pos);
862 if (!list_empty(&res->lr_converting)) {
864 CDEBUG(level, "Converting locks:\n");
865 list_for_each(tmp, &res->lr_converting) {
866 struct ldlm_lock *lock;
867 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
868 ldlm_lock_dump(level, lock, ++pos);
871 if (!list_empty(&res->lr_waiting)) {
873 CDEBUG(level, "Waiting locks:\n");
874 list_for_each(tmp, &res->lr_waiting) {
875 struct ldlm_lock *lock;
876 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
877 ldlm_lock_dump(level, lock, ++pos);