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 snprintf(page, count, "%u\n", ns->ns_max_unused);
128 #define MAX_STRING_SIZE 128
129 static int lprocfs_write_lru_size(struct file *file, const char *buffer,
130 unsigned long count, void *data)
132 struct ldlm_namespace *ns = data;
133 char dummy[MAX_STRING_SIZE + 1], *end;
136 dummy[MAX_STRING_SIZE] = '\0';
137 if (copy_from_user(dummy, buffer, MAX_STRING_SIZE))
140 if (count == 6 && memcmp(dummy, "clear", 5) == 0) {
142 "dropping all unused locks from namespace %s\n",
144 tmp = ns->ns_max_unused;
145 ns->ns_max_unused = 0;
146 ldlm_cancel_lru(ns, LDLM_SYNC);
147 ns->ns_max_unused = tmp;
151 tmp = simple_strtoul(dummy, &end, 0);
152 if (tmp == 0 && *end) {
153 CERROR("invalid value written\n");
157 CDEBUG(D_DLMTRACE, "changing namespace %s max_unused from %u to %u\n",
158 ns->ns_name, ns->ns_max_unused, (unsigned int)tmp);
159 ns->ns_max_unused = (unsigned int)tmp;
161 ldlm_cancel_lru(ns, LDLM_ASYNC);
166 void ldlm_proc_namespace(struct ldlm_namespace *ns)
168 struct lprocfs_vars lock_vars[2];
169 char lock_name[MAX_STRING_SIZE + 1];
172 LASSERT(ns->ns_name != NULL);
174 lock_name[MAX_STRING_SIZE] = '\0';
176 memset(lock_vars, 0, sizeof(lock_vars));
177 lock_vars[0].name = lock_name;
179 snprintf(lock_name, MAX_STRING_SIZE, "%s/resource_count", ns->ns_name);
180 lock_vars[0].data = &ns->ns_refcount;
181 lock_vars[0].read_fptr = lprocfs_rd_atomic;
182 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
184 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_count", ns->ns_name);
185 lock_vars[0].data = &ns->ns_locks;
186 lock_vars[0].read_fptr = lprocfs_rd_atomic;
187 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
190 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_unused_count",
192 lock_vars[0].data = &ns->ns_nr_unused;
193 lock_vars[0].read_fptr = lprocfs_uint_rd;
194 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
196 snprintf(lock_name, MAX_STRING_SIZE, "%s/lru_size",
198 lock_vars[0].data = ns;
199 lock_vars[0].read_fptr = lprocfs_read_lru_size;
200 lock_vars[0].write_fptr = lprocfs_write_lru_size;
201 lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
204 #undef MAX_STRING_SIZE
206 #define ldlm_proc_namespace(ns) do {} while (0)
209 struct ldlm_namespace *ldlm_namespace_new(char *name, __u32 client)
211 struct ldlm_namespace *ns = NULL;
212 struct list_head *bucket;
218 CERROR("ldlm_get_ref failed: %d\n", rc);
222 OBD_ALLOC(ns, sizeof(*ns));
226 OBD_VMALLOC(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
230 OBD_ALLOC(ns->ns_name, strlen(name) + 1);
232 GOTO(out_hash, NULL);
234 strcpy(ns->ns_name, name);
236 CFS_INIT_LIST_HEAD(&ns->ns_root_list);
238 ns->ns_client = client;
239 spin_lock_init(&ns->ns_hash_lock);
240 atomic_set(&ns->ns_locks, 0);
241 ns->ns_resources = 0;
242 cfs_waitq_init(&ns->ns_waitq);
244 for (bucket = ns->ns_hash + RES_HASH_SIZE - 1; bucket >= ns->ns_hash;
246 CFS_INIT_LIST_HEAD(bucket);
248 CFS_INIT_LIST_HEAD(&ns->ns_unused_list);
249 ns->ns_nr_unused = 0;
250 ns->ns_max_unused = LDLM_DEFAULT_LRU_SIZE;
251 spin_lock_init(&ns->ns_unused_lock);
253 mutex_down(&ldlm_namespace_lock);
254 list_add(&ns->ns_list_chain, &ldlm_namespace_list);
255 mutex_up(&ldlm_namespace_lock);
256 ldlm_proc_namespace(ns);
260 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
261 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
263 OBD_FREE(ns, sizeof(*ns));
269 extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
271 /* If flags contains FL_LOCAL_ONLY, don't try to tell the server, just cleanup.
272 * This is currently only used for recovery, and we make certain assumptions
273 * as a result--notably, that we shouldn't cancel locks with refs. -phil
275 * Called with the ns_lock held. */
276 static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
279 struct list_head *tmp;
280 int rc = 0, client = res->lr_namespace->ns_client;
281 int local_only = (flags & LDLM_FL_LOCAL_ONLY);
286 struct ldlm_lock *lock = NULL;
288 /* first, we look for non-cleaned-yet lock
289 * all cleaned locks are marked by CLEANED flag */
291 list_for_each(tmp, q) {
292 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
293 if (lock->l_flags & LDLM_FL_CLEANED) {
298 lock->l_flags |= LDLM_FL_CLEANED;
307 /* Set CBPENDING so nothing in the cancellation path
308 * can match this lock */
309 lock->l_flags |= LDLM_FL_CBPENDING;
310 lock->l_flags |= LDLM_FL_FAILED;
311 lock->l_flags |= flags;
313 if (local_only && (lock->l_readers || lock->l_writers)) {
314 /* This is a little bit gross, but much better than the
315 * alternative: pretend that we got a blocking AST from
316 * the server, so that when the lock is decref'd, it
317 * will go away ... */
318 /* ... without sending a CANCEL message. */
319 lock->l_flags |= LDLM_FL_LOCAL_ONLY;
321 LDLM_DEBUG(lock, "setting FL_LOCAL_ONLY");
322 if (lock->l_completion_ast)
323 lock->l_completion_ast(lock, 0, NULL);
329 struct lustre_handle lockh;
332 ldlm_lock2handle(lock, &lockh);
334 rc = ldlm_cli_cancel(&lockh);
336 CERROR("ldlm_cli_cancel: %d\n", rc);
338 /* Force local cleanup on errors, too. */
339 if (local_only || rc != ELDLM_OK)
340 ldlm_lock_cancel(lock);
342 ldlm_resource_unlink_lock(lock);
344 LDLM_DEBUG(lock, "Freeing a lock still held by a "
346 ldlm_lock_destroy(lock);
354 int ldlm_namespace_cleanup(struct ldlm_namespace *ns, int flags)
356 struct list_head *tmp;
360 CDEBUG(D_INFO, "NULL ns, skipping cleanup\n");
364 for (i = 0; i < RES_HASH_SIZE; i++) {
365 spin_lock(&ns->ns_hash_lock);
366 tmp = ns->ns_hash[i].next;
367 while (tmp != &(ns->ns_hash[i])) {
368 struct ldlm_resource *res;
369 res = list_entry(tmp, struct ldlm_resource, lr_hash);
370 ldlm_resource_getref(res);
371 spin_unlock(&ns->ns_hash_lock);
373 cleanup_resource(res, &res->lr_granted, flags);
374 cleanup_resource(res, &res->lr_converting, flags);
375 cleanup_resource(res, &res->lr_waiting, flags);
377 spin_lock(&ns->ns_hash_lock);
380 /* XXX: former stuff caused issues in case of race
381 * between ldlm_namespace_cleanup() and lockd() when
382 * client gets blocking ast when lock gets distracted by
383 * server. This is 1_4 branch solution, let's see how
385 if (!ldlm_resource_putref_locked(res))
387 "Namespace %s resource refcount nonzero "
388 "(%d) after lock cleanup; forcing cleanup.\n",
389 ns->ns_name, atomic_read(&res->lr_refcount));
391 spin_unlock(&ns->ns_hash_lock);
397 /* Cleanup, but also free, the namespace */
398 int ldlm_namespace_free(struct ldlm_namespace *ns, int force)
404 mutex_down(&ldlm_namespace_lock);
405 list_del(&ns->ns_list_chain);
406 mutex_up(&ldlm_namespace_lock);
408 /* At shutdown time, don't call the cancellation callback */
409 ldlm_namespace_cleanup(ns, 0);
413 struct proc_dir_entry *dir;
414 dir = lprocfs_srch(ldlm_ns_proc_dir, ns->ns_name);
416 CERROR("dlm namespace %s has no procfs dir?\n",
419 lprocfs_remove(&dir);
424 if (ns->ns_refcount > 0) {
425 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
428 "dlm namespace %s free waiting on refcount %d\n",
429 ns->ns_name, ns->ns_refcount);
430 rc = l_wait_event(ns->ns_waitq,
431 ns->ns_refcount == 0, &lwi);
433 LCONSOLE_ERROR_MSG(0x139, "Lock manager: wait for %s "
434 "namespace cleanup aborted with %d "
435 "resources in use. (%d)\nI'm going "
436 "to try to clean up anyway, but I "
437 "might need a reboot of this node.\n",
438 ns->ns_name, (int) ns->ns_refcount,
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,
455 const 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, const struct ldlm_res_id *name,
498 struct list_head *bucket, *tmp;
499 struct ldlm_resource *res;
501 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
502 bucket = ns->ns_hash + hash;
504 list_for_each(tmp, bucket) {
505 res = list_entry(tmp, struct ldlm_resource, lr_hash);
506 if (memcmp(&res->lr_name, name, sizeof(res->lr_name)) == 0)
513 /* Args: locked namespace
514 * Returns: newly-allocated, referenced, unlocked resource */
515 static struct ldlm_resource *
516 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
517 const struct ldlm_res_id *name, __u32 hash, ldlm_type_t type)
519 struct list_head *bucket;
520 struct ldlm_resource *res, *old_res;
523 LASSERTF(type >= LDLM_MIN_TYPE && type < LDLM_MAX_TYPE,
526 res = ldlm_resource_new();
530 res->lr_name = *name;
531 res->lr_namespace = ns;
533 res->lr_most_restr = LCK_NL;
535 spin_lock(&ns->ns_hash_lock);
536 old_res = ldlm_resource_find(ns, name, hash);
538 /* someone won the race and added the resource before */
539 ldlm_resource_getref(old_res);
540 spin_unlock(&ns->ns_hash_lock);
541 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
542 /* synchronize WRT resource creation */
543 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
544 down(&old_res->lr_lvb_sem);
545 up(&old_res->lr_lvb_sem);
550 /* we won! let's add the resource */
551 bucket = ns->ns_hash + hash;
552 list_add(&res->lr_hash, bucket);
556 if (parent == NULL) {
557 list_add(&res->lr_childof, &ns->ns_root_list);
559 res->lr_parent = parent;
560 list_add(&res->lr_childof, &parent->lr_children);
562 spin_unlock(&ns->ns_hash_lock);
564 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
567 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
568 rc = ns->ns_lvbo->lvbo_init(res);
570 CERROR("lvbo_init failed for resource "
571 LPU64": rc %d\n", name->name[0], rc);
572 /* we create resource with locked lr_lvb_sem */
573 up(&res->lr_lvb_sem);
579 /* Args: unlocked namespace
580 * Locks: takes and releases ns->ns_lock and res->lr_lock
581 * Returns: referenced, unlocked ldlm_resource or NULL */
582 struct ldlm_resource *
583 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
584 const struct ldlm_res_id *name, ldlm_type_t type, int create)
586 __u32 hash = ldlm_hash_fn(parent, name);
587 struct ldlm_resource *res = NULL;
591 LASSERT(ns->ns_hash != NULL);
592 LASSERT(name->name[0] != 0);
594 spin_lock(&ns->ns_hash_lock);
595 res = ldlm_resource_find(ns, name, hash);
597 ldlm_resource_getref(res);
598 spin_unlock(&ns->ns_hash_lock);
599 /* synchronize WRT resource creation */
600 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
601 down(&res->lr_lvb_sem);
602 up(&res->lr_lvb_sem);
606 spin_unlock(&ns->ns_hash_lock);
611 res = ldlm_resource_add(ns, parent, name, hash, type);
615 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
617 LASSERT(res != NULL);
618 LASSERT(res != LP_POISON);
619 atomic_inc(&res->lr_refcount);
620 CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
621 atomic_read(&res->lr_refcount));
625 void __ldlm_resource_putref_final(struct ldlm_resource *res)
627 struct ldlm_namespace *ns = res->lr_namespace;
629 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
631 if (!list_empty(&res->lr_granted)) {
632 ldlm_resource_dump(D_ERROR, res);
636 if (!list_empty(&res->lr_converting)) {
637 ldlm_resource_dump(D_ERROR, res);
641 if (!list_empty(&res->lr_waiting)) {
642 ldlm_resource_dump(D_ERROR, res);
646 if (!list_empty(&res->lr_children)) {
647 ldlm_resource_dump(D_ERROR, res);
652 list_del_init(&res->lr_hash);
653 list_del_init(&res->lr_childof);
656 if (ns->ns_resources == 0)
657 wake_up(&ns->ns_waitq);
660 /* Returns 1 if the resource was freed, 0 if it remains. */
661 int ldlm_resource_putref(struct ldlm_resource *res)
663 struct ldlm_namespace *ns = res->lr_namespace;
667 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
668 atomic_read(&res->lr_refcount) - 1);
669 LASSERTF(atomic_read(&res->lr_refcount) > 0, "%d",
670 atomic_read(&res->lr_refcount));
671 LASSERTF(atomic_read(&res->lr_refcount) < LI_POISON, "%d",
672 atomic_read(&res->lr_refcount));
674 if (atomic_dec_and_lock(&res->lr_refcount, &ns->ns_hash_lock)) {
675 __ldlm_resource_putref_final(res);
676 spin_unlock(&ns->ns_hash_lock);
677 if (res->lr_lvb_data)
678 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
679 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
686 /* Returns 1 if the resource was freed, 0 if it remains. */
687 int ldlm_resource_putref_locked(struct ldlm_resource *res)
692 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
693 atomic_read(&res->lr_refcount) - 1);
694 LASSERT(atomic_read(&res->lr_refcount) > 0);
695 LASSERT(atomic_read(&res->lr_refcount) < LI_POISON);
697 LASSERT(atomic_read(&res->lr_refcount) >= 0);
698 if (atomic_dec_and_test(&res->lr_refcount)) {
699 __ldlm_resource_putref_final(res);
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 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
710 struct ldlm_lock *lock)
712 check_res_locked(res);
714 ldlm_resource_dump(D_OTHER, res);
715 CDEBUG(D_OTHER, "About to add this lock:\n");
716 ldlm_lock_dump(D_OTHER, lock, 0);
718 if (lock->l_destroyed) {
719 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
723 LASSERT(list_empty(&lock->l_res_link));
725 list_add_tail(&lock->l_res_link, head);
728 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
729 struct ldlm_lock *new)
731 struct ldlm_resource *res = original->l_resource;
733 check_res_locked(res);
735 ldlm_resource_dump(D_OTHER, res);
736 CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
737 ldlm_lock_dump(D_OTHER, new, 0);
739 if (new->l_destroyed) {
740 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
744 LASSERT(list_empty(&new->l_res_link));
746 list_add(&new->l_res_link, &original->l_res_link);
750 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
752 check_res_locked(lock->l_resource);
753 ldlm_unlink_lock_skiplist(lock);
754 list_del_init(&lock->l_res_link);
757 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
759 desc->lr_type = res->lr_type;
760 desc->lr_name = res->lr_name;
763 void ldlm_dump_all_namespaces(int level)
765 struct list_head *tmp;
767 if (!((libcfs_debug | D_ERROR) & level))
770 mutex_down(&ldlm_namespace_lock);
772 list_for_each(tmp, &ldlm_namespace_list) {
773 struct ldlm_namespace *ns;
774 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
775 ldlm_namespace_dump(level, ns);
778 mutex_up(&ldlm_namespace_lock);
781 void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
783 struct list_head *tmp;
785 if (!((libcfs_debug | D_ERROR) & level))
788 CDEBUG(level, "--- Namespace: %s (rc: %d, client: %d)\n",
789 ns->ns_name, ns->ns_refcount, ns->ns_client);
791 if (cfs_time_before(cfs_time_current(), ns->ns_next_dump))
794 spin_lock(&ns->ns_hash_lock);
795 tmp = ns->ns_root_list.next;
796 while (tmp != &ns->ns_root_list) {
797 struct ldlm_resource *res;
798 res = list_entry(tmp, struct ldlm_resource, lr_childof);
800 ldlm_resource_getref(res);
801 spin_unlock(&ns->ns_hash_lock);
804 ldlm_resource_dump(level, res);
807 spin_lock(&ns->ns_hash_lock);
809 ldlm_resource_putref_locked(res);
811 ns->ns_next_dump = cfs_time_shift(10);
812 spin_unlock(&ns->ns_hash_lock);
815 void ldlm_resource_dump(int level, struct ldlm_resource *res)
817 struct list_head *tmp;
820 CLASSERT(RES_NAME_SIZE == 4);
822 if (!((libcfs_debug | D_ERROR) & level))
825 CDEBUG(level, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
826 ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
827 res->lr_name.name[2], res->lr_name.name[3],
828 atomic_read(&res->lr_refcount));
830 if (!list_empty(&res->lr_granted)) {
832 CDEBUG(level, "Granted locks:\n");
833 list_for_each(tmp, &res->lr_granted) {
834 struct ldlm_lock *lock;
835 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
836 ldlm_lock_dump(level, lock, ++pos);
839 if (!list_empty(&res->lr_converting)) {
841 CDEBUG(level, "Converting locks:\n");
842 list_for_each(tmp, &res->lr_converting) {
843 struct ldlm_lock *lock;
844 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
845 ldlm_lock_dump(level, lock, ++pos);
848 if (!list_empty(&res->lr_waiting)) {
850 CDEBUG(level, "Waiting locks:\n");
851 list_for_each(tmp, &res->lr_waiting) {
852 struct ldlm_lock *lock;
853 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
854 ldlm_lock_dump(level, lock, ++pos);