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 static int lprocfs_read_lru_size(char *page, char **start, off_t off,
122 int count, int *eof, void *data)
124 struct ldlm_namespace *ns = data;
125 return lprocfs_uint_rd(page, start, off, count, eof,
129 #define MAX_STRING_SIZE 128
130 static int lprocfs_write_lru_size(struct file *file, const char *buffer,
131 unsigned long count, void *data)
133 struct ldlm_namespace *ns = data;
134 char dummy[MAX_STRING_SIZE + 1], *end;
137 dummy[MAX_STRING_SIZE] = '\0';
138 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
141 if (count == 6 && memcmp(dummy, "clear", 5) == 0) {
143 "dropping all unused locks from namespace %s\n",
145 tmp = ns->ns_max_unused;
146 ns->ns_max_unused = 0;
147 ldlm_cancel_lru(ns, LDLM_SYNC);
148 ns->ns_max_unused = tmp;
152 tmp = simple_strtoul(dummy, &end, 0);
153 if (tmp == 0 && *end) {
154 CERROR("invalid value written\n");
158 CDEBUG(D_DLMTRACE, "changing namespace %s max_unused from %u to %u\n",
159 ns->ns_name, ns->ns_max_unused, (unsigned int)tmp);
160 ns->ns_max_unused = (unsigned int)tmp;
162 ldlm_cancel_lru(ns, LDLM_ASYNC);
167 void ldlm_proc_namespace(struct ldlm_namespace *ns)
169 struct lprocfs_vars lock_vars[2];
170 char lock_name[MAX_STRING_SIZE + 1];
173 LASSERT(ns->ns_name != NULL);
175 lock_name[MAX_STRING_SIZE] = '\0';
177 memset(lock_vars, 0, sizeof(lock_vars));
178 lock_vars[0].name = lock_name;
180 snprintf(lock_name, MAX_STRING_SIZE, "%s/resource_count", ns->ns_name);
181 lock_vars[0].data = &ns->ns_refcount;
182 lock_vars[0].read_fptr = lprocfs_rd_atomic;
183 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
185 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_count", ns->ns_name);
186 lock_vars[0].data = &ns->ns_locks;
187 lock_vars[0].read_fptr = lprocfs_rd_atomic;
188 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
191 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_unused_count",
193 lock_vars[0].data = &ns->ns_nr_unused;
194 lock_vars[0].read_fptr = lprocfs_uint_rd;
195 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
197 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_size",
199 lock_vars[0].data = ns;
200 lock_vars[0].read_fptr = lprocfs_read_lru_size;
201 lock_vars[0].write_fptr = lprocfs_write_lru_size;
202 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
205 #undef MAX_STRING_SIZE
207 #define ldlm_proc_namespace(ns) do {} while (0)
210 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
212 struct ldlm_namespace *ns = NULL;
213 struct list_head *bucket;
219 CERROR("ldlm_get_ref failed: %d\n", rc);
223 OBD_ALLOC(ns, sizeof(*ns));
227 OBD_VMALLOC(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
231 OBD_ALLOC(ns->ns_name, strlen(name) + 1);
233 GOTO(out_hash, NULL);
235 strcpy(ns->ns_name, name);
237 CFS_INIT_LIST_HEAD(&ns->ns_root_list);
239 ns->ns_client = client;
240 spin_lock_init(&ns->ns_hash_lock);
241 atomic_set(&ns->ns_locks, 0);
242 ns->ns_resources = 0;
243 cfs_waitq_init(&ns->ns_waitq);
245 for (bucket = ns->ns_hash + RES_HASH_SIZE - 1; bucket >= ns->ns_hash;
247 CFS_INIT_LIST_HEAD(bucket);
249 CFS_INIT_LIST_HEAD(&ns->ns_unused_list);
250 ns->ns_nr_unused = 0;
251 ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE;
252 spin_lock_init(&ns->ns_unused_lock);
254 mutex_down(&ldlm_namespace_lock);
255 list_add(&ns->ns_list_chain, &ldlm_namespace_list);
256 mutex_up(&ldlm_namespace_lock);
257 ldlm_proc_namespace(ns);
261 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
262 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
264 OBD_FREE(ns, sizeof(*ns));
270 extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
272 /* If flags contains FL_LOCAL_ONLY, don't try to tell the server, just cleanup.
273 * This is currently only used for recovery, and we make certain assumptions
274 * as a result--notably, that we shouldn't cancel locks with refs. -phil
276 * Called with the ns_lock held. */
277 static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
280 struct list_head *tmp;
281 int rc = 0, client = res->lr_namespace->ns_client;
282 int local_only = (flags & LDLM_FL_LOCAL_ONLY);
287 struct ldlm_lock *lock = NULL;
289 /* first, we look for non-cleaned-yet lock
290 * all cleaned locks are marked by CLEANED flag */
292 list_for_each(tmp, q) {
293 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
294 if (lock->l_flags & LDLM_FL_CLEANED) {
299 lock->l_flags |= LDLM_FL_CLEANED;
308 /* Set CBPENDING so nothing in the cancellation path
309 * can match this lock */
310 lock->l_flags |= LDLM_FL_CBPENDING;
311 lock->l_flags |= LDLM_FL_FAILED;
312 lock->l_flags |= flags;
314 if (local_only && (lock->l_readers || lock->l_writers)) {
315 /* This is a little bit gross, but much better than the
316 * alternative: pretend that we got a blocking AST from
317 * the server, so that when the lock is decref'd, it
318 * will go away ... */
319 /* ... without sending a CANCEL message. */
320 lock->l_flags |= LDLM_FL_LOCAL_ONLY;
322 LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY");
323 if (lock->l_completion_ast)
324 lock->l_completion_ast(lock, 0, NULL);
330 struct lustre_handle lockh;
333 ldlm_lock2handle(lock, &lockh);
335 rc = ldlm_cli_cancel(&lockh);
337 CERROR("ldlm_cli_cancel: %d\n", rc);
339 /* Force local cleanup on errors, too. */
340 if (local_only || rc != ELDLM_OK)
341 ldlm_lock_cancel(lock);
343 ldlm_resource_unlink_lock(lock);
345 LDLM_DEBUG(lock, "Freeing a lock still held by a "
347 ldlm_lock_destroy(lock);
355 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags)
357 struct list_head *tmp;
361 CDEBUG(D_INFO, "NULL ns, skipping cleanup\n");
365 for (i = 0; i < RES_HASH_SIZE; i++) {
366 spin_lock(&ns->ns_hash_lock);
367 tmp = ns->ns_hash[i].next;
368 while (tmp != &(ns->ns_hash[i])) {
369 struct ldlm_resource *res;
370 res = list_entry(tmp, struct ldlm_resource, lr_hash);
371 ldlm_resource_getref(res);
372 spin_unlock(&ns->ns_hash_lock);
374 cleanup_resource(res, &res->lr_granted, flags);
375 cleanup_resource(res, &res->lr_converting, flags);
376 cleanup_resource(res, &res->lr_waiting, flags);
378 spin_lock(&ns->ns_hash_lock);
381 /* XXX: former stuff caused issues in case of race
382 * between ldlm_namespace_cleanup() and lockd() when
383 * client gets blocking ast when lock gets distracted by
384 * server. This is 1_4 branch solution, let's see how
386 if (!ldlm_resource_putref_locked(res))
388 "Namespace %s resource refcount nonzero "
389 "(%d) after lock cleanup; forcing cleanup.\n",
390 ns->ns_name, atomic_read(&res->lr_refcount));
392 spin_unlock(&ns->ns_hash_lock);
398 /* Cleanup, but also free, the namespace */
399 int ldlm_namespace_free(struct ldlm_namespace *ns, int force)
405 mutex_down(&ldlm_namespace_lock);
406 list_del(&ns->ns_list_chain);
407 mutex_up(&ldlm_namespace_lock);
409 /* At shutdown time, don't call the cancellation callback */
410 ldlm_namespace_cleanup(ns, 0);
414 struct proc_dir_entry *dir;
415 dir = lprocfs_srch(ldlm_ns_proc_dir, ns->ns_name);
417 CERROR("dlm namespace %s has no procfs dir?\n",
420 lprocfs_remove(&dir);
425 if (ns->ns_refcount > 0) {
426 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
429 "dlm namespace %s free waiting on refcount %d\n",
430 ns->ns_name, ns->ns_refcount);
431 rc = l_wait_event(ns->ns_waitq,
432 ns->ns_refcount == 0, &lwi);
434 LCONSOLE_ERROR_MSG(0x139, "Lock manager: wait for %s "
435 "namespace cleanup aborted with %d "
436 "resources in use. (%d)\nI'm going "
437 "to try to clean up anyway, but I "
438 "might need a reboot of this node.\n",
439 ns->ns_name, (int) ns->ns_refcount,
442 "dlm namespace %s free done waiting\n", ns->ns_name);
445 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
446 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
447 OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
448 OBD_FREE(ns, sizeof(*ns));
455 static __u32 ldlm_hash_fn(struct ldlm_resource *parent, struct ldlm_res_id name)
460 for (i = 0; i < RES_NAME_SIZE; i++)
461 hash += name.name[i];
463 hash += (__u32)((unsigned long)parent >> 4);
465 return (hash & RES_HASH_MASK);
468 static struct ldlm_resource *ldlm_resource_new(void)
470 struct ldlm_resource *res;
472 OBD_SLAB_ALLOC(res, ldlm_resource_slab, CFS_ALLOC_IO, sizeof *res);
476 memset(res, 0, sizeof(*res));
478 CFS_INIT_LIST_HEAD(&res->lr_children);
479 CFS_INIT_LIST_HEAD(&res->lr_childof);
480 CFS_INIT_LIST_HEAD(&res->lr_granted);
481 CFS_INIT_LIST_HEAD(&res->lr_converting);
482 CFS_INIT_LIST_HEAD(&res->lr_waiting);
483 atomic_set(&res->lr_refcount, 1);
484 spin_lock_init(&res->lr_lock);
486 /* one who creates the resource must unlock
487 * the semaphore after lvb initialization */
488 init_MUTEX_LOCKED(&res->lr_lvb_sem);
493 /* must be called with hash lock held */
494 static struct ldlm_resource *
495 ldlm_resource_find(struct ldlm_namespace *ns, struct ldlm_res_id name, __u32 hash)
497 struct list_head *bucket, *tmp;
498 struct ldlm_resource *res;
500 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
501 bucket = ns->ns_hash + hash;
503 list_for_each(tmp, bucket) {
504 res = list_entry(tmp, struct ldlm_resource, lr_hash);
505 if (memcmp(&res->lr_name, &name, sizeof(res->lr_name)) == 0)
512 /* Args: locked namespace
513 * Returns: newly-allocated, referenced, unlocked resource */
514 static struct ldlm_resource *
515 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
516 struct ldlm_res_id name, __u32 hash, ldlm_type_t type)
518 struct list_head *bucket;
519 struct ldlm_resource *res, *old_res;
522 LASSERTF(type >= LDLM_MIN_TYPE && type < LDLM_MAX_TYPE,
525 res = ldlm_resource_new();
530 res->lr_namespace = ns;
532 res->lr_most_restr = LCK_NL;
534 spin_lock(&ns->ns_hash_lock);
535 old_res = ldlm_resource_find(ns, name, hash);
537 /* someone won the race and added the resource before */
538 ldlm_resource_getref(old_res);
539 spin_unlock(&ns->ns_hash_lock);
540 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
541 /* synchronize WRT resource creation */
542 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
543 down(&old_res->lr_lvb_sem);
544 up(&old_res->lr_lvb_sem);
549 /* we won! let's add the resource */
550 bucket = ns->ns_hash + hash;
551 list_add(&res->lr_hash, bucket);
555 if (parent == NULL) {
556 list_add(&res->lr_childof, &ns->ns_root_list);
558 res->lr_parent = parent;
559 list_add(&res->lr_childof, &parent->lr_children);
561 spin_unlock(&ns->ns_hash_lock);
563 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
566 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
567 rc = ns->ns_lvbo->lvbo_init(res);
569 CERROR("lvbo_init failed for resource "
570 LPU64": rc %d\n", name.name[0], rc);
571 /* we create resource with locked lr_lvb_sem */
572 up(&res->lr_lvb_sem);
578 /* Args: unlocked namespace
579 * Locks: takes and releases ns->ns_lock and res->lr_lock
580 * Returns: referenced, unlocked ldlm_resource or NULL */
581 struct ldlm_resource *
582 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
583 struct ldlm_res_id name, ldlm_type_t type, int create)
585 __u32 hash = ldlm_hash_fn(parent, name);
586 struct ldlm_resource *res = NULL;
590 LASSERT(ns->ns_hash != NULL);
591 LASSERT(name.name[0] != 0);
593 spin_lock(&ns->ns_hash_lock);
594 res = ldlm_resource_find(ns, name, hash);
596 ldlm_resource_getref(res);
597 spin_unlock(&ns->ns_hash_lock);
598 /* synchronize WRT resource creation */
599 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
600 down(&res->lr_lvb_sem);
601 up(&res->lr_lvb_sem);
605 spin_unlock(&ns->ns_hash_lock);
610 res = ldlm_resource_add(ns, parent, name, hash, type);
614 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
616 LASSERT(res != NULL);
617 LASSERT(res != LP_POISON);
618 atomic_inc(&res->lr_refcount);
619 CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
620 atomic_read(&res->lr_refcount));
624 void __ldlm_resource_putref_final(struct ldlm_resource *res)
626 struct ldlm_namespace *ns = res->lr_namespace;
628 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
630 if (!list_empty(&res->lr_granted)) {
631 ldlm_resource_dump(D_ERROR, res);
635 if (!list_empty(&res->lr_converting)) {
636 ldlm_resource_dump(D_ERROR, res);
640 if (!list_empty(&res->lr_waiting)) {
641 ldlm_resource_dump(D_ERROR, res);
645 if (!list_empty(&res->lr_children)) {
646 ldlm_resource_dump(D_ERROR, res);
651 list_del_init(&res->lr_hash);
652 list_del_init(&res->lr_childof);
655 if (ns->ns_resources == 0)
656 wake_up(&ns->ns_waitq);
659 /* Returns 1 if the resource was freed, 0 if it remains. */
660 int ldlm_resource_putref(struct ldlm_resource *res)
662 struct ldlm_namespace *ns = res->lr_namespace;
666 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
667 atomic_read(&res->lr_refcount) - 1);
668 LASSERTF(atomic_read(&res->lr_refcount) > 0, "%d",
669 atomic_read(&res->lr_refcount));
670 LASSERTF(atomic_read(&res->lr_refcount) < LI_POISON, "%d",
671 atomic_read(&res->lr_refcount));
673 if (atomic_dec_and_lock(&res->lr_refcount, &ns->ns_hash_lock)) {
674 __ldlm_resource_putref_final(res);
675 spin_unlock(&ns->ns_hash_lock);
676 if (res->lr_lvb_data)
677 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
678 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
685 /* Returns 1 if the resource was freed, 0 if it remains. */
686 int ldlm_resource_putref_locked(struct ldlm_resource *res)
691 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
692 atomic_read(&res->lr_refcount) - 1);
693 LASSERT(atomic_read(&res->lr_refcount) > 0);
694 LASSERT(atomic_read(&res->lr_refcount) < LI_POISON);
696 LASSERT(atomic_read(&res->lr_refcount) >= 0);
697 if (atomic_dec_and_test(&res->lr_refcount)) {
698 __ldlm_resource_putref_final(res);
699 if (res->lr_lvb_data)
700 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
701 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
708 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
709 struct ldlm_lock *lock)
711 check_res_locked(res);
713 ldlm_resource_dump(D_OTHER, res);
714 CDEBUG(D_OTHER, "About to add this lock:\n");
715 ldlm_lock_dump(D_OTHER, lock, 0);
717 if (lock->l_destroyed) {
718 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
722 LASSERT(list_empty(&lock->l_res_link));
724 list_add_tail(&lock->l_res_link, head);
727 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
728 struct ldlm_lock *new)
730 struct ldlm_resource *res = original->l_resource;
732 check_res_locked(res);
734 ldlm_resource_dump(D_OTHER, res);
735 CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
736 ldlm_lock_dump(D_OTHER, new, 0);
738 if (new->l_destroyed) {
739 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
743 LASSERT(list_empty(&new->l_res_link));
745 list_add(&new->l_res_link, &original->l_res_link);
749 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
751 check_res_locked(lock->l_resource);
752 list_del_init(&lock->l_res_link);
755 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
757 desc->lr_type = res->lr_type;
758 desc->lr_name = res->lr_name;
761 void ldlm_dump_all_namespaces(int level)
763 struct list_head *tmp;
765 if (!((libcfs_debug | D_ERROR) & level))
768 mutex_down(&ldlm_namespace_lock);
770 list_for_each(tmp, &ldlm_namespace_list) {
771 struct ldlm_namespace *ns;
772 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
773 ldlm_namespace_dump(level, ns);
776 mutex_up(&ldlm_namespace_lock);
779 void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
781 struct list_head *tmp;
783 if (!((libcfs_debug | D_ERROR) & level))
786 CDEBUG(level, "--- Namespace: %s (rc: %d, client: %d)\n",
787 ns->ns_name, ns->ns_refcount, ns->ns_client);
789 if (cfs_time_before(cfs_time_current(), ns->ns_next_dump))
792 spin_lock(&ns->ns_hash_lock);
793 tmp = ns->ns_root_list.next;
794 while (tmp != &ns->ns_root_list) {
795 struct ldlm_resource *res;
796 res = list_entry(tmp, struct ldlm_resource, lr_childof);
798 ldlm_resource_getref(res);
799 spin_unlock(&ns->ns_hash_lock);
802 ldlm_resource_dump(level, res);
805 spin_lock(&ns->ns_hash_lock);
807 ldlm_resource_putref_locked(res);
809 ns->ns_next_dump = cfs_time_shift(10);
810 spin_unlock(&ns->ns_hash_lock);
813 void ldlm_resource_dump(int level, struct ldlm_resource *res)
815 struct list_head *tmp;
818 CLASSERT(RES_NAME_SIZE == 4);
820 if (!((libcfs_debug | D_ERROR) & level))
823 CDEBUG(level, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
824 ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
825 res->lr_name.name[2], res->lr_name.name[3],
826 atomic_read(&res->lr_refcount));
828 if (!list_empty(&res->lr_granted)) {
830 CDEBUG(level, "Granted locks:\n");
831 list_for_each(tmp, &res->lr_granted) {
832 struct ldlm_lock *lock;
833 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
834 ldlm_lock_dump(level, lock, ++pos);
837 if (!list_empty(&res->lr_converting)) {
839 CDEBUG(level, "Converting locks:\n");
840 list_for_each(tmp, &res->lr_converting) {
841 struct ldlm_lock *lock;
842 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
843 ldlm_lock_dump(level, lock, ++pos);
846 if (!list_empty(&res->lr_waiting)) {
848 CDEBUG(level, "Waiting locks:\n");
849 list_for_each(tmp, &res->lr_waiting) {
850 struct ldlm_lock *lock;
851 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
852 ldlm_lock_dump(level, lock, ++pos);