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 int ldlm_namespace_free_prior(struct ldlm_namespace *ns)
428 mutex_down(&ldlm_namespace_lock);
429 list_del(&ns->ns_list_chain);
430 mutex_up(&ldlm_namespace_lock);
432 /* At shutdown time, don't call the cancellation callback */
433 ldlm_namespace_cleanup(ns, 0);
435 if (ns->ns_refcount > 0) {
436 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
439 "dlm namespace %s free waiting on refcount %d\n",
440 ns->ns_name, ns->ns_refcount);
441 rc = l_wait_event(ns->ns_waitq,
442 ns->ns_refcount == 0, &lwi);
444 LCONSOLE_ERROR_MSG(0x139, "Lock manager: wait for %s "
445 "namespace cleanup aborted with %d "
446 "resources in use. (%d)\nI'm going "
447 "to try to clean up anyway, but I "
448 "might need a reboot of this node.\n",
449 ns->ns_name, (int) ns->ns_refcount,
452 "dlm namespace %s free done waiting\n", ns->ns_name);
458 int ldlm_namespace_free_post(struct ldlm_namespace *ns, int force)
466 struct proc_dir_entry *dir;
467 dir = lprocfs_srch(ldlm_ns_proc_dir, ns->ns_name);
469 CERROR("dlm namespace %s has no procfs dir?\n",
472 lprocfs_remove(&dir);
477 POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
478 OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
479 OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
480 OBD_FREE(ns, sizeof(*ns));
486 /* Cleanup the resource, and free namespace.
489 * proc1: destroy import
490 * class_disconnect_export(grab cl_sem) ->
491 * -> ldlm_namespace_free ->
492 * -> lprocfs_remove(grab _lprocfs_lock).
493 * proc2: read proc info
494 * lprocfs_fops_read(grab _lprocfs_lock) ->
495 * -> osc_rd_active, etc(grab cl_sem).
497 * So that I have to split the ldlm_namespace_free into two parts - the first
498 * part ldlm_namespace_free_prior is used to cleanup the resource which is
499 * being used; the 2nd part ldlm_namespace_free_post is used to unregister the
500 * lprocfs entries, and then free memory. It will be called w/o cli->cl_sem
503 int ldlm_namespace_free(struct ldlm_namespace *ns, int force)
505 ldlm_namespace_free_prior(ns);
506 ldlm_namespace_free_post(ns, force);
510 static __u32 ldlm_hash_fn(struct ldlm_resource *parent, struct ldlm_res_id name)
515 for (i = 0; i < RES_NAME_SIZE; i++)
516 hash += name.name[i];
518 hash += (__u32)((unsigned long)parent >> 4);
520 return (hash & RES_HASH_MASK);
523 static struct ldlm_resource *ldlm_resource_new(void)
525 struct ldlm_resource *res;
527 OBD_SLAB_ALLOC(res, ldlm_resource_slab, CFS_ALLOC_IO, sizeof *res);
531 memset(res, 0, sizeof(*res));
533 CFS_INIT_LIST_HEAD(&res->lr_children);
534 CFS_INIT_LIST_HEAD(&res->lr_childof);
535 CFS_INIT_LIST_HEAD(&res->lr_granted);
536 CFS_INIT_LIST_HEAD(&res->lr_converting);
537 CFS_INIT_LIST_HEAD(&res->lr_waiting);
538 atomic_set(&res->lr_refcount, 1);
539 spin_lock_init(&res->lr_lock);
541 /* one who creates the resource must unlock
542 * the semaphore after lvb initialization */
543 init_MUTEX_LOCKED(&res->lr_lvb_sem);
548 /* must be called with hash lock held */
549 static struct ldlm_resource *
550 ldlm_resource_find(struct ldlm_namespace *ns, struct ldlm_res_id name, __u32 hash)
552 struct list_head *bucket, *tmp;
553 struct ldlm_resource *res;
555 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
556 bucket = ns->ns_hash + hash;
558 list_for_each(tmp, bucket) {
559 res = list_entry(tmp, struct ldlm_resource, lr_hash);
560 if (memcmp(&res->lr_name, &name, sizeof(res->lr_name)) == 0)
567 /* Args: locked namespace
568 * Returns: newly-allocated, referenced, unlocked resource */
569 static struct ldlm_resource *
570 ldlm_resource_add(struct ldlm_namespace *ns, struct ldlm_resource *parent,
571 struct ldlm_res_id name, __u32 hash, ldlm_type_t type)
573 struct list_head *bucket;
574 struct ldlm_resource *res, *old_res;
577 LASSERTF(type >= LDLM_MIN_TYPE && type < LDLM_MAX_TYPE,
580 res = ldlm_resource_new();
585 res->lr_namespace = ns;
587 res->lr_most_restr = LCK_NL;
589 spin_lock(&ns->ns_hash_lock);
590 old_res = ldlm_resource_find(ns, name, hash);
592 /* someone won the race and added the resource before */
593 ldlm_resource_getref(old_res);
594 spin_unlock(&ns->ns_hash_lock);
595 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
596 /* synchronize WRT resource creation */
597 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
598 down(&old_res->lr_lvb_sem);
599 up(&old_res->lr_lvb_sem);
604 /* we won! let's add the resource */
605 bucket = ns->ns_hash + hash;
606 list_add(&res->lr_hash, bucket);
610 if (parent == NULL) {
611 list_add(&res->lr_childof, &ns->ns_root_list);
613 res->lr_parent = parent;
614 list_add(&res->lr_childof, &parent->lr_children);
616 spin_unlock(&ns->ns_hash_lock);
618 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
621 OBD_FAIL_TIMEOUT(OBD_FAIL_LDLM_CREATE_RESOURCE, 2);
622 rc = ns->ns_lvbo->lvbo_init(res);
624 CERROR("lvbo_init failed for resource "
625 LPU64": rc %d\n", name.name[0], rc);
626 /* we create resource with locked lr_lvb_sem */
627 up(&res->lr_lvb_sem);
633 /* Args: unlocked namespace
634 * Locks: takes and releases ns->ns_lock and res->lr_lock
635 * Returns: referenced, unlocked ldlm_resource or NULL */
636 struct ldlm_resource *
637 ldlm_resource_get(struct ldlm_namespace *ns, struct ldlm_resource *parent,
638 struct ldlm_res_id name, ldlm_type_t type, int create)
640 __u32 hash = ldlm_hash_fn(parent, name);
641 struct ldlm_resource *res = NULL;
645 LASSERT(ns->ns_hash != NULL);
646 LASSERT(name.name[0] != 0);
648 spin_lock(&ns->ns_hash_lock);
649 res = ldlm_resource_find(ns, name, hash);
651 ldlm_resource_getref(res);
652 spin_unlock(&ns->ns_hash_lock);
653 /* synchronize WRT resource creation */
654 if (ns->ns_lvbo && ns->ns_lvbo->lvbo_init) {
655 down(&res->lr_lvb_sem);
656 up(&res->lr_lvb_sem);
660 spin_unlock(&ns->ns_hash_lock);
665 res = ldlm_resource_add(ns, parent, name, hash, type);
669 struct ldlm_resource *ldlm_resource_getref(struct ldlm_resource *res)
671 LASSERT(res != NULL);
672 LASSERT(res != LP_POISON);
673 atomic_inc(&res->lr_refcount);
674 CDEBUG(D_INFO, "getref res: %p count: %d\n", res,
675 atomic_read(&res->lr_refcount));
679 void __ldlm_resource_putref_final(struct ldlm_resource *res)
681 struct ldlm_namespace *ns = res->lr_namespace;
683 LASSERT_SPIN_LOCKED(&ns->ns_hash_lock);
685 if (!list_empty(&res->lr_granted)) {
686 ldlm_resource_dump(D_ERROR, res);
690 if (!list_empty(&res->lr_converting)) {
691 ldlm_resource_dump(D_ERROR, res);
695 if (!list_empty(&res->lr_waiting)) {
696 ldlm_resource_dump(D_ERROR, res);
700 if (!list_empty(&res->lr_children)) {
701 ldlm_resource_dump(D_ERROR, res);
706 list_del_init(&res->lr_hash);
707 list_del_init(&res->lr_childof);
710 if (ns->ns_resources == 0)
711 wake_up(&ns->ns_waitq);
714 /* Returns 1 if the resource was freed, 0 if it remains. */
715 int ldlm_resource_putref(struct ldlm_resource *res)
717 struct ldlm_namespace *ns = res->lr_namespace;
721 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
722 atomic_read(&res->lr_refcount) - 1);
723 LASSERTF(atomic_read(&res->lr_refcount) > 0, "%d",
724 atomic_read(&res->lr_refcount));
725 LASSERTF(atomic_read(&res->lr_refcount) < LI_POISON, "%d",
726 atomic_read(&res->lr_refcount));
728 if (atomic_dec_and_lock(&res->lr_refcount, &ns->ns_hash_lock)) {
729 __ldlm_resource_putref_final(res);
730 spin_unlock(&ns->ns_hash_lock);
731 if (res->lr_lvb_data)
732 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
733 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
740 /* Returns 1 if the resource was freed, 0 if it remains. */
741 int ldlm_resource_putref_locked(struct ldlm_resource *res)
746 CDEBUG(D_INFO, "putref res: %p count: %d\n", res,
747 atomic_read(&res->lr_refcount) - 1);
748 LASSERT(atomic_read(&res->lr_refcount) > 0);
749 LASSERT(atomic_read(&res->lr_refcount) < LI_POISON);
751 LASSERT(atomic_read(&res->lr_refcount) >= 0);
752 if (atomic_dec_and_test(&res->lr_refcount)) {
753 __ldlm_resource_putref_final(res);
754 if (res->lr_lvb_data)
755 OBD_FREE(res->lr_lvb_data, res->lr_lvb_len);
756 OBD_SLAB_FREE(res, ldlm_resource_slab, sizeof *res);
763 void ldlm_resource_add_lock(struct ldlm_resource *res, struct list_head *head,
764 struct ldlm_lock *lock)
766 check_res_locked(res);
768 ldlm_resource_dump(D_OTHER, res);
769 CDEBUG(D_OTHER, "About to add this lock:\n");
770 ldlm_lock_dump(D_OTHER, lock, 0);
772 if (lock->l_destroyed) {
773 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
777 LASSERT(list_empty(&lock->l_res_link));
779 list_add_tail(&lock->l_res_link, head);
782 void ldlm_resource_insert_lock_after(struct ldlm_lock *original,
783 struct ldlm_lock *new)
785 struct ldlm_resource *res = original->l_resource;
787 check_res_locked(res);
789 ldlm_resource_dump(D_OTHER, res);
790 CDEBUG(D_OTHER, "About to insert this lock after %p:\n", original);
791 ldlm_lock_dump(D_OTHER, new, 0);
793 if (new->l_destroyed) {
794 CDEBUG(D_OTHER, "Lock destroyed, not adding to resource\n");
798 LASSERT(list_empty(&new->l_res_link));
800 list_add(&new->l_res_link, &original->l_res_link);
804 void ldlm_resource_unlink_lock(struct ldlm_lock *lock)
806 check_res_locked(lock->l_resource);
807 ldlm_unlink_lock_skiplist(lock);
808 list_del_init(&lock->l_res_link);
811 void ldlm_res2desc(struct ldlm_resource *res, struct ldlm_resource_desc *desc)
813 desc->lr_type = res->lr_type;
814 desc->lr_name = res->lr_name;
817 void ldlm_dump_all_namespaces(int level)
819 struct list_head *tmp;
821 if (!((libcfs_debug | D_ERROR) & level))
824 mutex_down(&ldlm_namespace_lock);
826 list_for_each(tmp, &ldlm_namespace_list) {
827 struct ldlm_namespace *ns;
828 ns = list_entry(tmp, struct ldlm_namespace, ns_list_chain);
829 ldlm_namespace_dump(level, ns);
832 mutex_up(&ldlm_namespace_lock);
835 void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
837 struct list_head *tmp;
839 if (!((libcfs_debug | D_ERROR) & level))
842 CDEBUG(level, "--- Namespace: %s (rc: %d, client: %d)\n",
843 ns->ns_name, ns->ns_refcount, ns->ns_client);
845 if (cfs_time_before(cfs_time_current(), ns->ns_next_dump))
848 spin_lock(&ns->ns_hash_lock);
849 tmp = ns->ns_root_list.next;
850 while (tmp != &ns->ns_root_list) {
851 struct ldlm_resource *res;
852 res = list_entry(tmp, struct ldlm_resource, lr_childof);
854 ldlm_resource_getref(res);
855 spin_unlock(&ns->ns_hash_lock);
858 ldlm_resource_dump(level, res);
861 spin_lock(&ns->ns_hash_lock);
863 ldlm_resource_putref_locked(res);
865 ns->ns_next_dump = cfs_time_shift(10);
866 spin_unlock(&ns->ns_hash_lock);
869 void ldlm_resource_dump(int level, struct ldlm_resource *res)
871 struct list_head *tmp;
874 CLASSERT(RES_NAME_SIZE == 4);
876 if (!((libcfs_debug | D_ERROR) & level))
879 CDEBUG(level, "--- Resource: %p ("LPU64"/"LPU64"/"LPU64"/"LPU64
880 ") (rc: %d)\n", res, res->lr_name.name[0], res->lr_name.name[1],
881 res->lr_name.name[2], res->lr_name.name[3],
882 atomic_read(&res->lr_refcount));
884 if (!list_empty(&res->lr_granted)) {
886 CDEBUG(level, "Granted locks:\n");
887 list_for_each(tmp, &res->lr_granted) {
888 struct ldlm_lock *lock;
889 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
890 ldlm_lock_dump(level, lock, ++pos);
893 if (!list_empty(&res->lr_converting)) {
895 CDEBUG(level, "Converting locks:\n");
896 list_for_each(tmp, &res->lr_converting) {
897 struct ldlm_lock *lock;
898 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
899 ldlm_lock_dump(level, lock, ++pos);
902 if (!list_empty(&res->lr_waiting)) {
904 CDEBUG(level, "Waiting locks:\n");
905 list_for_each(tmp, &res->lr_waiting) {
906 struct ldlm_lock *lock;
907 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
908 ldlm_lock_dump(level, lock, ++pos);