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("Lock manager: wait for %s namespace "
435 "cleanup aborted with %d resources in "
436 "use. (%d)\nI'm going to try to clean "
437 "up anyway, but I might need a reboot "
438 "of this node.\n", ns->ns_name,
439 (int) ns->ns_refcount, rc);
441 "dlm namespace %s free done waiting\n", ns->ns_name);
444 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
445 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
446 OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
447 OBD_FREE(ns, sizeof(*ns));
454 static __u32 ldlm_hash_fn(struct ldlm_resource *parent, struct ldlm_res_id name)
459 for (i = 0; i < RES_NAME_SIZE; i++)
460 hash += name.name[i];
462 hash += (__u32)((unsigned long)parent >> 4);
464 return (hash & RES_HASH_MASK);
467 static struct ldlm_resource *ldlm_resource_new(void)
469 struct ldlm_resource *res;
471 OBD_SLAB_ALLOC(res, ldlm_resource_slab, CFS_ALLOC_IO, sizeof *res);
475 memset(res, 0, sizeof(*res));
477 CFS_INIT_LIST_HEAD(&res->lr_children);
478 CFS_INIT_LIST_HEAD(&res->lr_childof);
479 CFS_INIT_LIST_HEAD(&res->lr_granted);
480 CFS_INIT_LIST_HEAD(&res->lr_converting);
481 CFS_INIT_LIST_HEAD(&res->lr_waiting);
482 atomic_set(&res->lr_refcount, 1);
483 spin_lock_init(&res->lr_lock);
485 /* one who creates the resource must unlock
486 * the semaphore after lvb initialization */
487 init_MUTEX_LOCKED(&res->lr_lvb_sem);
492 /* must be called with hash lock held */
493 static struct ldlm_resource *
494 ldlm_resource_find(struct ldlm_namespace *ns, struct ldlm_res_id name, __u32 hash)
496 struct list_head *bucket, *tmp;
497 struct ldlm_resource *res;
499 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
500 bucket = ns->ns_hash + hash;
502 list_for_each(tmp, bucket) {
503 res = list_entry(tmp, struct ldlm_resource, lr_hash);
504 if (memcmp(&res->lr_name, &name, sizeof(res->lr_name)) == 0)
511 /* Args: locked namespace
512 * Returns: newly-allocated, referenced, unlocked resource */
513 static struct ldlm_resource *
514 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
515 struct ldlm_res_id name, __u32 hash, ldlm_type_t type)
517 struct list_head *bucket;
518 struct ldlm_resource *res, *old_res;
521 LASSERTF(type >= LDLM_MIN_TYPE && type < LDLM_MAX_TYPE,
524 res = ldlm_resource_new();
529 res->lr_namespace = ns;
531 res->lr_most_restr = LCK_NL;
533 spin_lock(&ns->ns_hash_lock);
534 old_res = ldlm_resource_find(ns, name, hash);
536 /* someone won the race and added the resource before */
537 ldlm_resource_getref(old_res);
538 spin_unlock(&ns->ns_hash_lock);
539 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
540 /* synchronize WRT resource creation */
541 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
542 down(&old_res->lr_lvb_sem);
543 up(&old_res->lr_lvb_sem);
548 /* we won! let's add the resource */
549 bucket = ns->ns_hash + hash;
550 list_add(&res->lr_hash, bucket);
554 if (parent == NULL) {
555 list_add(&res->lr_childof, &ns->ns_root_list);
557 res->lr_parent = parent;
558 list_add(&res->lr_childof, &parent->lr_children);
560 spin_unlock(&ns->ns_hash_lock);
562 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
565 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
566 rc = ns->ns_lvbo->lvbo_init(res);
568 CERROR("lvbo_init failed for resource "
569 LPU64": rc %d\n", name.name[0], rc);
570 /* we create resource with locked lr_lvb_sem */
571 up(&res->lr_lvb_sem);
577 /* Args: unlocked namespace
578 * Locks: takes and releases ns->ns_lock and res->lr_lock
579 * Returns: referenced, unlocked ldlm_resource or NULL */
580 struct ldlm_resource *
581 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
582 struct ldlm_res_id name, ldlm_type_t type, int create)
584 __u32 hash = ldlm_hash_fn(parent, name);
585 struct ldlm_resource *res = NULL;
589 LASSERT(ns->ns_hash != NULL);
590 LASSERT(name.name[0] != 0);
592 spin_lock(&ns->ns_hash_lock);
593 res = ldlm_resource_find(ns, name, hash);
595 ldlm_resource_getref(res);
596 spin_unlock(&ns->ns_hash_lock);
597 /* synchronize WRT resource creation */
598 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
599 down(&res->lr_lvb_sem);
600 up(&res->lr_lvb_sem);
604 spin_unlock(&ns->ns_hash_lock);
609 res = ldlm_resource_add(ns, parent, name, hash, type);
613 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
615 LASSERT(res != NULL);
616 LASSERT(res != LP_POISON);
617 atomic_inc(&res->lr_refcount);
618 CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
619 atomic_read(&res->lr_refcount));
623 void __ldlm_resource_putref_final(struct ldlm_resource *res)
625 struct ldlm_namespace *ns = res->lr_namespace;
627 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
629 if (!list_empty(&res->lr_granted)) {
630 ldlm_resource_dump(D_ERROR, res);
634 if (!list_empty(&res->lr_converting)) {
635 ldlm_resource_dump(D_ERROR, res);
639 if (!list_empty(&res->lr_waiting)) {
640 ldlm_resource_dump(D_ERROR, res);
644 if (!list_empty(&res->lr_children)) {
645 ldlm_resource_dump(D_ERROR, res);
650 list_del_init(&res->lr_hash);
651 list_del_init(&res->lr_childof);
654 if (ns->ns_resources == 0)
655 wake_up(&ns->ns_waitq);
658 /* Returns 1 if the resource was freed, 0 if it remains. */
659 int ldlm_resource_putref(struct ldlm_resource *res)
661 struct ldlm_namespace *ns = res->lr_namespace;
665 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
666 atomic_read(&res->lr_refcount) - 1);
667 LASSERTF(atomic_read(&res->lr_refcount) > 0, "%d",
668 atomic_read(&res->lr_refcount));
669 LASSERTF(atomic_read(&res->lr_refcount) < LI_POISON, "%d",
670 atomic_read(&res->lr_refcount));
672 if (atomic_dec_and_lock(&res->lr_refcount, &ns->ns_hash_lock)) {
673 __ldlm_resource_putref_final(res);
674 spin_unlock(&ns->ns_hash_lock);
675 if (res->lr_lvb_data)
676 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
677 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
684 /* Returns 1 if the resource was freed, 0 if it remains. */
685 int ldlm_resource_putref_locked(struct ldlm_resource *res)
690 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
691 atomic_read(&res->lr_refcount) - 1);
692 LASSERT(atomic_read(&res->lr_refcount) > 0);
693 LASSERT(atomic_read(&res->lr_refcount) < LI_POISON);
695 LASSERT(atomic_read(&res->lr_refcount) >= 0);
696 if (atomic_dec_and_test(&res->lr_refcount)) {
697 __ldlm_resource_putref_final(res);
698 if (res->lr_lvb_data)
699 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
700 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
707 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
708 struct ldlm_lock *lock)
710 check_res_locked(res);
712 ldlm_resource_dump(D_OTHER, res);
713 CDEBUG(D_OTHER, "About to add this lock:\n");
714 ldlm_lock_dump(D_OTHER, lock, 0);
716 if (lock->l_destroyed) {
717 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
721 LASSERT(list_empty(&lock->l_res_link));
723 list_add_tail(&lock->l_res_link, head);
726 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
727 struct ldlm_lock *new)
729 struct ldlm_resource *res = original->l_resource;
731 check_res_locked(res);
733 ldlm_resource_dump(D_OTHER, res);
734 CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
735 ldlm_lock_dump(D_OTHER, new, 0);
737 if (new->l_destroyed) {
738 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
742 LASSERT(list_empty(&new->l_res_link));
744 list_add(&new->l_res_link, &original->l_res_link);
748 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
750 check_res_locked(lock->l_resource);
751 list_del_init(&lock->l_res_link);
754 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
756 desc->lr_type = res->lr_type;
757 desc->lr_name = res->lr_name;
760 void ldlm_dump_all_namespaces(int level)
762 struct list_head *tmp;
764 if (!((libcfs_debug | D_ERROR) & level))
767 mutex_down(&ldlm_namespace_lock);
769 list_for_each(tmp, &ldlm_namespace_list) {
770 struct ldlm_namespace *ns;
771 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
772 ldlm_namespace_dump(level, ns);
775 mutex_up(&ldlm_namespace_lock);
778 void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
780 struct list_head *tmp;
782 if (!((libcfs_debug | D_ERROR) & level))
785 CDEBUG(level, "--- Namespace: %s (rc: %d, client: %d)\n",
786 ns->ns_name, ns->ns_refcount, ns->ns_client);
788 if (cfs_time_before(cfs_time_current(), ns->ns_next_dump))
791 spin_lock(&ns->ns_hash_lock);
792 tmp = ns->ns_root_list.next;
793 while (tmp != &ns->ns_root_list) {
794 struct ldlm_resource *res;
795 res = list_entry(tmp, struct ldlm_resource, lr_childof);
797 ldlm_resource_getref(res);
798 spin_unlock(&ns->ns_hash_lock);
801 ldlm_resource_dump(level, res);
804 spin_lock(&ns->ns_hash_lock);
806 ldlm_resource_putref_locked(res);
808 ns->ns_next_dump = cfs_time_shift(10);
809 spin_unlock(&ns->ns_hash_lock);
812 void ldlm_resource_dump(int level, struct ldlm_resource *res)
814 struct list_head *tmp;
817 CLASSERT(RES_NAME_SIZE == 4);
819 if (!((libcfs_debug | D_ERROR) & level))
822 CDEBUG(level, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
823 ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
824 res->lr_name.name[2], res->lr_name.name[3],
825 atomic_read(&res->lr_refcount));
827 if (!list_empty(&res->lr_granted)) {
829 CDEBUG(level, "Granted locks:\n");
830 list_for_each(tmp, &res->lr_granted) {
831 struct ldlm_lock *lock;
832 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
833 ldlm_lock_dump(level, lock, ++pos);
836 if (!list_empty(&res->lr_converting)) {
838 CDEBUG(level, "Converting locks:\n");
839 list_for_each(tmp, &res->lr_converting) {
840 struct ldlm_lock *lock;
841 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
842 ldlm_lock_dump(level, lock, ++pos);
845 if (!list_empty(&res->lr_waiting)) {
847 CDEBUG(level, "Waiting locks:\n");
848 list_for_each(tmp, &res->lr_waiting) {
849 struct ldlm_lock *lock;
850 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
851 ldlm_lock_dump(level, lock, ++pos);