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_type_proc_dir = NULL;
99 ldlm_ns_proc_dir = NULL;
100 ldlm_svc_proc_dir = NULL;
104 void ldlm_proc_cleanup(void)
106 if (ldlm_svc_proc_dir) {
107 lprocfs_remove(ldlm_svc_proc_dir);
108 ldlm_svc_proc_dir = NULL;
111 if (ldlm_ns_proc_dir) {
112 lprocfs_remove(ldlm_ns_proc_dir);
113 ldlm_ns_proc_dir = NULL;
116 if (ldlm_type_proc_dir) {
117 lprocfs_remove(ldlm_type_proc_dir);
118 ldlm_type_proc_dir = NULL;
122 static int lprocfs_uint_rd(char *page, char **start, off_t off,
123 int count, int *eof, void *data)
125 unsigned int *temp = (unsigned int *)data;
126 return snprintf(page, count, "%u\n", *temp);
129 static int lprocfs_read_lru_size(char *page, char **start, off_t off,
130 int count, int *eof, void *data)
132 struct ldlm_namespace *ns = data;
133 return lprocfs_uint_rd(page, start, off, count, eof,
137 #define MAX_STRING_SIZE 128
138 static int lprocfs_write_lru_size(struct file *file, const char *buffer,
139 unsigned long count, void *data)
141 struct ldlm_namespace *ns = data;
142 char dummy[MAX_STRING_SIZE + 1], *end;
145 dummy[MAX_STRING_SIZE] = '\0';
146 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
149 if (count == 6 && memcmp(dummy, "clear", 5) == 0) {
151 "dropping all unused locks from namespace %s\n",
153 tmp = ns->ns_max_unused;
154 ns->ns_max_unused = 0;
155 ldlm_cancel_lru(ns, LDLM_SYNC);
156 ns->ns_max_unused = tmp;
160 tmp = simple_strtoul(dummy, &end, 0);
161 if (tmp == 0 && *end) {
162 CERROR("invalid value written\n");
166 CDEBUG(D_DLMTRACE, "changing namespace %s max_unused from %u to %u\n",
167 ns->ns_name, ns->ns_max_unused, (unsigned int)tmp);
168 ns->ns_max_unused = (unsigned int)tmp;
170 ldlm_cancel_lru(ns, LDLM_ASYNC);
175 void ldlm_proc_namespace(struct ldlm_namespace *ns)
177 struct lprocfs_vars lock_vars[2];
178 char lock_name[MAX_STRING_SIZE + 1];
181 LASSERT(ns->ns_name != NULL);
183 lock_name[MAX_STRING_SIZE] = '\0';
185 memset(lock_vars, 0, sizeof(lock_vars));
186 lock_vars[0].name = lock_name;
188 snprintf(lock_name, MAX_STRING_SIZE, "%s/resource_count", ns->ns_name);
189 lock_vars[0].data = &ns->ns_refcount;
190 lock_vars[0].read_fptr = lprocfs_rd_atomic;
191 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
193 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_count", ns->ns_name);
194 lock_vars[0].data = &ns->ns_locks;
195 lock_vars[0].read_fptr = lprocfs_rd_u64;
196 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
199 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_unused_count",
201 lock_vars[0].data = &ns->ns_nr_unused;
202 lock_vars[0].read_fptr = lprocfs_uint_rd;
203 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
205 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_size",
207 lock_vars[0].data = ns;
208 lock_vars[0].read_fptr = lprocfs_read_lru_size;
209 lock_vars[0].write_fptr = lprocfs_write_lru_size;
210 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
213 #undef MAX_STRING_SIZE
215 #define ldlm_proc_namespace(ns) do {} while (0)
218 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
220 struct ldlm_namespace *ns = NULL;
221 struct list_head *bucket;
227 CERROR("ldlm_get_ref failed: %d\n", rc);
231 OBD_ALLOC(ns, sizeof(*ns));
235 OBD_VMALLOC(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
239 OBD_ALLOC(ns->ns_name, strlen(name) + 1);
241 GOTO(out_hash, NULL);
243 strcpy(ns->ns_name, name);
245 CFS_INIT_LIST_HEAD(&ns->ns_root_list);
247 ns->ns_client = client;
248 spin_lock_init(&ns->ns_hash_lock);
249 atomic_set(&ns->ns_locks, 0);
250 ns->ns_resources = 0;
251 cfs_waitq_init(&ns->ns_waitq);
253 for (bucket = ns->ns_hash + RES_HASH_SIZE - 1; bucket >= ns->ns_hash;
255 CFS_INIT_LIST_HEAD(bucket);
257 CFS_INIT_LIST_HEAD(&ns->ns_unused_list);
258 ns->ns_nr_unused = 0;
259 ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE;
260 spin_lock_init(&ns->ns_unused_lock);
262 mutex_down(&ldlm_namespace_lock);
263 list_add(&ns->ns_list_chain, &ldlm_namespace_list);
264 mutex_up(&ldlm_namespace_lock);
265 ldlm_proc_namespace(ns);
269 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
270 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
272 OBD_FREE(ns, sizeof(*ns));
278 extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
280 /* If flags contains FL_LOCAL_ONLY, don't try to tell the server, just cleanup.
281 * This is currently only used for recovery, and we make certain assumptions
282 * as a result--notably, that we shouldn't cancel locks with refs. -phil
284 * Called with the ns_lock held. */
285 static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
288 struct list_head *tmp;
289 int rc = 0, client = res->lr_namespace->ns_client;
290 int local_only = (flags & LDLM_FL_LOCAL_ONLY);
295 struct ldlm_lock *lock = NULL;
297 /* first, we look for non-cleaned-yet lock
298 * all cleaned locks are marked by CLEANED flag */
300 list_for_each(tmp, q) {
301 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
302 if (lock->l_flags & LDLM_FL_CLEANED) {
307 lock->l_flags |= LDLM_FL_CLEANED;
316 /* Set CBPENDING so nothing in the cancellation path
317 * can match this lock */
318 lock->l_flags |= LDLM_FL_CBPENDING;
319 lock->l_flags |= LDLM_FL_FAILED;
320 lock->l_flags |= flags;
322 if (local_only && (lock->l_readers || lock->l_writers)) {
323 /* This is a little bit gross, but much better than the
324 * alternative: pretend that we got a blocking AST from
325 * the server, so that when the lock is decref'd, it
326 * will go away ... */
327 /* ... without sending a CANCEL message. */
328 lock->l_flags |= LDLM_FL_LOCAL_ONLY;
330 LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY");
331 if (lock->l_completion_ast)
332 lock->l_completion_ast(lock, 0, NULL);
338 struct lustre_handle lockh;
341 ldlm_lock2handle(lock, &lockh);
343 rc = ldlm_cli_cancel(&lockh);
345 CERROR("ldlm_cli_cancel: %d\n", rc);
347 /* Force local cleanup on errors, too. */
348 if (local_only || rc != ELDLM_OK)
349 ldlm_lock_cancel(lock);
351 ldlm_resource_unlink_lock(lock);
353 LDLM_DEBUG(lock, "Freeing a lock still held by a "
355 ldlm_lock_destroy(lock);
363 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags)
365 struct list_head *tmp;
369 CDEBUG(D_INFO, "NULL ns, skipping cleanup\n");
373 for (i = 0; i < RES_HASH_SIZE; i++) {
374 spin_lock(&ns->ns_hash_lock);
375 tmp = ns->ns_hash[i].next;
376 while (tmp != &(ns->ns_hash[i])) {
377 struct ldlm_resource *res;
378 res = list_entry(tmp, struct ldlm_resource, lr_hash);
379 ldlm_resource_getref(res);
380 spin_unlock(&ns->ns_hash_lock);
382 cleanup_resource(res, &res->lr_granted, flags);
383 cleanup_resource(res, &res->lr_converting, flags);
384 cleanup_resource(res, &res->lr_waiting, flags);
386 spin_lock(&ns->ns_hash_lock);
389 /* XXX: former stuff caused issues in case of race
390 * between ldlm_namespace_cleanup() and lockd() when
391 * client gets blocking ast when lock gets distracted by
392 * server. This is 1_4 branch solution, let's see how
394 if (!ldlm_resource_putref_locked(res))
396 "Namespace %s resource refcount nonzero "
397 "(%d) after lock cleanup; forcing cleanup.\n",
398 ns->ns_name, atomic_read(&res->lr_refcount));
400 spin_unlock(&ns->ns_hash_lock);
406 /* Cleanup, but also free, the namespace */
407 int ldlm_namespace_free(struct ldlm_namespace *ns, int force)
413 mutex_down(&ldlm_namespace_lock);
414 list_del(&ns->ns_list_chain);
415 mutex_up(&ldlm_namespace_lock);
417 /* At shutdown time, don't call the cancellation callback */
418 ldlm_namespace_cleanup(ns, 0);
422 struct proc_dir_entry *dir;
423 dir = lprocfs_srch(ldlm_ns_proc_dir, ns->ns_name);
425 CERROR("dlm namespace %s has no procfs dir?\n",
433 if (ns->ns_refcount > 0) {
434 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
437 "dlm namespace %s free waiting on refcount %d\n",
438 ns->ns_name, ns->ns_refcount);
439 rc = l_wait_event(ns->ns_waitq,
440 ns->ns_refcount == 0, &lwi);
442 LCONSOLE_ERROR("Lock manager: wait for %s namespace "
443 "cleanup aborted with %d resources in "
444 "use. (%d)\nI'm going to try to clean "
445 "up anyway, but I might need a reboot "
446 "of this node.\n", ns->ns_name,
447 (int) ns->ns_refcount, rc);
449 "dlm namespace %s free done waiting\n", ns->ns_name);
452 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
453 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
454 OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
455 OBD_FREE(ns, sizeof(*ns));
462 static __u32 ldlm_hash_fn(struct ldlm_resource *parent, struct ldlm_res_id name)
467 for (i = 0; i < RES_NAME_SIZE; i++)
468 hash += name.name[i];
470 hash += (__u32)((unsigned long)parent >> 4);
472 return (hash & RES_HASH_MASK);
475 static struct ldlm_resource *ldlm_resource_new(void)
477 struct ldlm_resource *res;
479 OBD_SLAB_ALLOC(res, ldlm_resource_slab, CFS_ALLOC_IO, sizeof *res);
483 memset(res, 0, sizeof(*res));
485 CFS_INIT_LIST_HEAD(&res->lr_children);
486 CFS_INIT_LIST_HEAD(&res->lr_childof);
487 CFS_INIT_LIST_HEAD(&res->lr_granted);
488 CFS_INIT_LIST_HEAD(&res->lr_converting);
489 CFS_INIT_LIST_HEAD(&res->lr_waiting);
490 atomic_set(&res->lr_refcount, 1);
491 spin_lock_init(&res->lr_lock);
493 /* one who creates the resource must unlock
494 * the semaphore after lvb initialization */
495 init_MUTEX_LOCKED(&res->lr_lvb_sem);
500 /* must be called with hash lock held */
501 static struct ldlm_resource *
502 ldlm_resource_find(struct ldlm_namespace *ns, struct ldlm_res_id name, __u32 hash)
504 struct list_head *bucket, *tmp;
505 struct ldlm_resource *res;
507 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
508 bucket = ns->ns_hash + hash;
510 list_for_each(tmp, bucket) {
511 res = list_entry(tmp, struct ldlm_resource, lr_hash);
512 if (memcmp(&res->lr_name, &name, sizeof(res->lr_name)) == 0)
519 /* Args: locked namespace
520 * Returns: newly-allocated, referenced, unlocked resource */
521 static struct ldlm_resource *
522 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
523 struct ldlm_res_id name, __u32 hash, ldlm_type_t type)
525 struct list_head *bucket;
526 struct ldlm_resource *res, *old_res;
529 LASSERTF(type >= LDLM_MIN_TYPE && type < LDLM_MAX_TYPE,
532 res = ldlm_resource_new();
537 res->lr_namespace = ns;
539 res->lr_most_restr = LCK_NL;
541 spin_lock(&ns->ns_hash_lock);
542 old_res = ldlm_resource_find(ns, name, hash);
544 /* someone won the race and added the resource before */
545 ldlm_resource_getref(old_res);
546 spin_unlock(&ns->ns_hash_lock);
547 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
548 /* synchronize WRT resource creation */
549 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
550 down(&old_res->lr_lvb_sem);
551 up(&old_res->lr_lvb_sem);
556 /* we won! let's add the resource */
557 bucket = ns->ns_hash + hash;
558 list_add(&res->lr_hash, bucket);
562 if (parent == NULL) {
563 list_add(&res->lr_childof, &ns->ns_root_list);
565 res->lr_parent = parent;
566 list_add(&res->lr_childof, &parent->lr_children);
568 spin_unlock(&ns->ns_hash_lock);
570 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
573 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
574 rc = ns->ns_lvbo->lvbo_init(res);
576 CERROR("lvbo_init failed for resource "
577 LPU64": rc %d\n", name.name[0], rc);
578 /* we create resource with locked lr_lvb_sem */
579 up(&res->lr_lvb_sem);
585 /* Args: unlocked namespace
586 * Locks: takes and releases ns->ns_lock and res->lr_lock
587 * Returns: referenced, unlocked ldlm_resource or NULL */
588 struct ldlm_resource *
589 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
590 struct ldlm_res_id name, ldlm_type_t type, int create)
592 __u32 hash = ldlm_hash_fn(parent, name);
593 struct ldlm_resource *res = NULL;
597 LASSERT(ns->ns_hash != NULL);
598 LASSERT(name.name[0] != 0);
600 spin_lock(&ns->ns_hash_lock);
601 res = ldlm_resource_find(ns, name, hash);
603 ldlm_resource_getref(res);
604 spin_unlock(&ns->ns_hash_lock);
605 /* synchronize WRT resource creation */
606 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
607 down(&res->lr_lvb_sem);
608 up(&res->lr_lvb_sem);
612 spin_unlock(&ns->ns_hash_lock);
617 res = ldlm_resource_add(ns, parent, name, hash, type);
621 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
623 LASSERT(res != NULL);
624 LASSERT(res != LP_POISON);
625 atomic_inc(&res->lr_refcount);
626 CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
627 atomic_read(&res->lr_refcount));
631 void __ldlm_resource_putref_final(struct ldlm_resource *res)
633 struct ldlm_namespace *ns = res->lr_namespace;
635 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
637 if (!list_empty(&res->lr_granted)) {
638 ldlm_resource_dump(D_ERROR, res);
642 if (!list_empty(&res->lr_converting)) {
643 ldlm_resource_dump(D_ERROR, res);
647 if (!list_empty(&res->lr_waiting)) {
648 ldlm_resource_dump(D_ERROR, res);
652 if (!list_empty(&res->lr_children)) {
653 ldlm_resource_dump(D_ERROR, res);
658 list_del_init(&res->lr_hash);
659 list_del_init(&res->lr_childof);
662 if (ns->ns_resources == 0)
663 wake_up(&ns->ns_waitq);
666 /* Returns 1 if the resource was freed, 0 if it remains. */
667 int ldlm_resource_putref(struct ldlm_resource *res)
669 struct ldlm_namespace *ns = res->lr_namespace;
673 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
674 atomic_read(&res->lr_refcount) - 1);
675 LASSERT(atomic_read(&res->lr_refcount) > 0);
676 LASSERT(atomic_read(&res->lr_refcount) < LI_POISON);
678 LASSERT(atomic_read(&res->lr_refcount) >= 0);
679 if (atomic_dec_and_lock(&res->lr_refcount, &ns->ns_hash_lock)) {
680 __ldlm_resource_putref_final(res);
681 spin_unlock(&ns->ns_hash_lock);
682 if (res->lr_lvb_data)
683 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
684 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
691 /* Returns 1 if the resource was freed, 0 if it remains. */
692 int ldlm_resource_putref_locked(struct ldlm_resource *res)
697 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
698 atomic_read(&res->lr_refcount) - 1);
699 LASSERT(atomic_read(&res->lr_refcount) > 0);
700 LASSERT(atomic_read(&res->lr_refcount) < LI_POISON);
702 LASSERT(atomic_read(&res->lr_refcount) >= 0);
703 if (atomic_dec_and_test(&res->lr_refcount)) {
704 __ldlm_resource_putref_final(res);
705 if (res->lr_lvb_data)
706 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
707 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
714 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
715 struct ldlm_lock *lock)
717 check_res_locked(res);
719 ldlm_resource_dump(D_OTHER, res);
720 CDEBUG(D_OTHER, "About to add this lock:\n");
721 ldlm_lock_dump(D_OTHER, lock, 0);
723 if (lock->l_destroyed) {
724 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
728 LASSERT(list_empty(&lock->l_res_link));
730 list_add_tail(&lock->l_res_link, head);
733 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
734 struct ldlm_lock *new)
736 struct ldlm_resource *res = original->l_resource;
738 check_res_locked(res);
740 ldlm_resource_dump(D_OTHER, res);
741 CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
742 ldlm_lock_dump(D_OTHER, new, 0);
744 if (new->l_destroyed) {
745 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
749 LASSERT(list_empty(&new->l_res_link));
751 list_add(&new->l_res_link, &original->l_res_link);
755 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
757 check_res_locked(lock->l_resource);
758 list_del_init(&lock->l_res_link);
761 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
763 desc->lr_type = res->lr_type;
764 desc->lr_name = res->lr_name;
767 void ldlm_dump_all_namespaces(int level)
769 struct list_head *tmp;
771 mutex_down(&ldlm_namespace_lock);
773 list_for_each(tmp, &ldlm_namespace_list) {
774 struct ldlm_namespace *ns;
775 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
776 ldlm_namespace_dump(level, ns);
779 mutex_up(&ldlm_namespace_lock);
782 void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
784 struct list_head *tmp;
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 if (RES_NAME_SIZE != 4)
821 CDEBUG(level, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
822 ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
823 res->lr_name.name[2], res->lr_name.name[3],
824 atomic_read(&res->lr_refcount));
826 if (!list_empty(&res->lr_granted)) {
828 CDEBUG(level, "Granted locks:\n");
829 list_for_each(tmp, &res->lr_granted) {
830 struct ldlm_lock *lock;
831 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
832 ldlm_lock_dump(level, lock, ++pos);
835 if (!list_empty(&res->lr_converting)) {
837 CDEBUG(level, "Converting locks:\n");
838 list_for_each(tmp, &res->lr_converting) {
839 struct ldlm_lock *lock;
840 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
841 ldlm_lock_dump(level, lock, ++pos);
844 if (!list_empty(&res->lr_waiting)) {
846 CDEBUG(level, "Waiting locks:\n");
847 list_for_each(tmp, &res->lr_waiting) {
848 struct ldlm_lock *lock;
849 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
850 ldlm_lock_dump(level, lock, ++pos);