1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * debug functionality for the dlm
8 * Copyright (C) 2004, 2008 Oracle. All rights reserved.
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public
21 * License along with this program; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 021110-1307, USA.
27 #include <linux/types.h>
28 #include <linux/slab.h>
29 #include <linux/highmem.h>
30 #include <linux/utsname.h>
31 #include <linux/sysctl.h>
32 #include <linux/spinlock.h>
33 #include <linux/debugfs.h>
35 #include "cluster/heartbeat.h"
36 #include "cluster/nodemanager.h"
37 #include "cluster/tcp.h"
40 #include "dlmcommon.h"
41 #include "dlmdomain.h"
44 #define MLOG_MASK_PREFIX ML_DLM
45 #include "cluster/masklog.h"
47 static int stringify_lockname(const char *lockname
, int locklen
, char *buf
,
50 void dlm_print_one_lock_resource(struct dlm_lock_resource
*res
)
52 spin_lock(&res
->spinlock
);
53 __dlm_print_one_lock_resource(res
);
54 spin_unlock(&res
->spinlock
);
57 static void dlm_print_lockres_refmap(struct dlm_lock_resource
*res
)
60 assert_spin_locked(&res
->spinlock
);
62 printk(" refmap nodes: [ ");
65 bit
= find_next_bit(res
->refmap
, O2NM_MAX_NODES
, bit
);
66 if (bit
>= O2NM_MAX_NODES
)
71 printk("], inflight=%u\n", res
->inflight_locks
);
74 static void __dlm_print_lock(struct dlm_lock
*lock
)
76 spin_lock(&lock
->spinlock
);
78 printk(" type=%d, conv=%d, node=%u, cookie=%u:%llu, "
79 "ref=%u, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c), "
80 "pending=(conv=%c,lock=%c,cancel=%c,unlock=%c)\n",
81 lock
->ml
.type
, lock
->ml
.convert_type
, lock
->ml
.node
,
82 dlm_get_lock_cookie_node(be64_to_cpu(lock
->ml
.cookie
)),
83 dlm_get_lock_cookie_seq(be64_to_cpu(lock
->ml
.cookie
)),
84 atomic_read(&lock
->lock_refs
.refcount
),
85 (list_empty(&lock
->ast_list
) ? 'y' : 'n'),
86 (lock
->ast_pending
? 'y' : 'n'),
87 (list_empty(&lock
->bast_list
) ? 'y' : 'n'),
88 (lock
->bast_pending
? 'y' : 'n'),
89 (lock
->convert_pending
? 'y' : 'n'),
90 (lock
->lock_pending
? 'y' : 'n'),
91 (lock
->cancel_pending
? 'y' : 'n'),
92 (lock
->unlock_pending
? 'y' : 'n'));
94 spin_unlock(&lock
->spinlock
);
97 void __dlm_print_one_lock_resource(struct dlm_lock_resource
*res
)
99 struct list_head
*iter2
;
100 struct dlm_lock
*lock
;
101 char buf
[DLM_LOCKID_NAME_MAX
];
103 assert_spin_locked(&res
->spinlock
);
105 stringify_lockname(res
->lockname
.name
, res
->lockname
.len
,
106 buf
, sizeof(buf
) - 1);
107 printk("lockres: %s, owner=%u, state=%u\n",
108 buf
, res
->owner
, res
->state
);
109 printk(" last used: %lu, refcnt: %u, on purge list: %s\n",
110 res
->last_used
, atomic_read(&res
->refs
.refcount
),
111 list_empty(&res
->purge
) ? "no" : "yes");
112 printk(" on dirty list: %s, on reco list: %s, "
113 "migrating pending: %s\n",
114 list_empty(&res
->dirty
) ? "no" : "yes",
115 list_empty(&res
->recovering
) ? "no" : "yes",
116 res
->migration_pending
? "yes" : "no");
117 printk(" inflight locks: %d, asts reserved: %d\n",
118 res
->inflight_locks
, atomic_read(&res
->asts_reserved
));
119 dlm_print_lockres_refmap(res
);
120 printk(" granted queue:\n");
121 list_for_each(iter2
, &res
->granted
) {
122 lock
= list_entry(iter2
, struct dlm_lock
, list
);
123 __dlm_print_lock(lock
);
125 printk(" converting queue:\n");
126 list_for_each(iter2
, &res
->converting
) {
127 lock
= list_entry(iter2
, struct dlm_lock
, list
);
128 __dlm_print_lock(lock
);
130 printk(" blocked queue:\n");
131 list_for_each(iter2
, &res
->blocked
) {
132 lock
= list_entry(iter2
, struct dlm_lock
, list
);
133 __dlm_print_lock(lock
);
137 void dlm_print_one_lock(struct dlm_lock
*lockid
)
139 dlm_print_one_lock_resource(lockid
->lockres
);
141 EXPORT_SYMBOL_GPL(dlm_print_one_lock
);
143 static const char *dlm_errnames
[] = {
144 [DLM_NORMAL
] = "DLM_NORMAL",
145 [DLM_GRANTED
] = "DLM_GRANTED",
146 [DLM_DENIED
] = "DLM_DENIED",
147 [DLM_DENIED_NOLOCKS
] = "DLM_DENIED_NOLOCKS",
148 [DLM_WORKING
] = "DLM_WORKING",
149 [DLM_BLOCKED
] = "DLM_BLOCKED",
150 [DLM_BLOCKED_ORPHAN
] = "DLM_BLOCKED_ORPHAN",
151 [DLM_DENIED_GRACE_PERIOD
] = "DLM_DENIED_GRACE_PERIOD",
152 [DLM_SYSERR
] = "DLM_SYSERR",
153 [DLM_NOSUPPORT
] = "DLM_NOSUPPORT",
154 [DLM_CANCELGRANT
] = "DLM_CANCELGRANT",
155 [DLM_IVLOCKID
] = "DLM_IVLOCKID",
156 [DLM_SYNC
] = "DLM_SYNC",
157 [DLM_BADTYPE
] = "DLM_BADTYPE",
158 [DLM_BADRESOURCE
] = "DLM_BADRESOURCE",
159 [DLM_MAXHANDLES
] = "DLM_MAXHANDLES",
160 [DLM_NOCLINFO
] = "DLM_NOCLINFO",
161 [DLM_NOLOCKMGR
] = "DLM_NOLOCKMGR",
162 [DLM_NOPURGED
] = "DLM_NOPURGED",
163 [DLM_BADARGS
] = "DLM_BADARGS",
164 [DLM_VOID
] = "DLM_VOID",
165 [DLM_NOTQUEUED
] = "DLM_NOTQUEUED",
166 [DLM_IVBUFLEN
] = "DLM_IVBUFLEN",
167 [DLM_CVTUNGRANT
] = "DLM_CVTUNGRANT",
168 [DLM_BADPARAM
] = "DLM_BADPARAM",
169 [DLM_VALNOTVALID
] = "DLM_VALNOTVALID",
170 [DLM_REJECTED
] = "DLM_REJECTED",
171 [DLM_ABORT
] = "DLM_ABORT",
172 [DLM_CANCEL
] = "DLM_CANCEL",
173 [DLM_IVRESHANDLE
] = "DLM_IVRESHANDLE",
174 [DLM_DEADLOCK
] = "DLM_DEADLOCK",
175 [DLM_DENIED_NOASTS
] = "DLM_DENIED_NOASTS",
176 [DLM_FORWARD
] = "DLM_FORWARD",
177 [DLM_TIMEOUT
] = "DLM_TIMEOUT",
178 [DLM_IVGROUPID
] = "DLM_IVGROUPID",
179 [DLM_VERS_CONFLICT
] = "DLM_VERS_CONFLICT",
180 [DLM_BAD_DEVICE_PATH
] = "DLM_BAD_DEVICE_PATH",
181 [DLM_NO_DEVICE_PERMISSION
] = "DLM_NO_DEVICE_PERMISSION",
182 [DLM_NO_CONTROL_DEVICE
] = "DLM_NO_CONTROL_DEVICE ",
183 [DLM_RECOVERING
] = "DLM_RECOVERING",
184 [DLM_MIGRATING
] = "DLM_MIGRATING",
185 [DLM_MAXSTATS
] = "DLM_MAXSTATS",
188 static const char *dlm_errmsgs
[] = {
189 [DLM_NORMAL
] = "request in progress",
190 [DLM_GRANTED
] = "request granted",
191 [DLM_DENIED
] = "request denied",
192 [DLM_DENIED_NOLOCKS
] = "request denied, out of system resources",
193 [DLM_WORKING
] = "async request in progress",
194 [DLM_BLOCKED
] = "lock request blocked",
195 [DLM_BLOCKED_ORPHAN
] = "lock request blocked by a orphan lock",
196 [DLM_DENIED_GRACE_PERIOD
] = "topological change in progress",
197 [DLM_SYSERR
] = "system error",
198 [DLM_NOSUPPORT
] = "unsupported",
199 [DLM_CANCELGRANT
] = "can't cancel convert: already granted",
200 [DLM_IVLOCKID
] = "bad lockid",
201 [DLM_SYNC
] = "synchronous request granted",
202 [DLM_BADTYPE
] = "bad resource type",
203 [DLM_BADRESOURCE
] = "bad resource handle",
204 [DLM_MAXHANDLES
] = "no more resource handles",
205 [DLM_NOCLINFO
] = "can't contact cluster manager",
206 [DLM_NOLOCKMGR
] = "can't contact lock manager",
207 [DLM_NOPURGED
] = "can't contact purge daemon",
208 [DLM_BADARGS
] = "bad api args",
209 [DLM_VOID
] = "no status",
210 [DLM_NOTQUEUED
] = "NOQUEUE was specified and request failed",
211 [DLM_IVBUFLEN
] = "invalid resource name length",
212 [DLM_CVTUNGRANT
] = "attempted to convert ungranted lock",
213 [DLM_BADPARAM
] = "invalid lock mode specified",
214 [DLM_VALNOTVALID
] = "value block has been invalidated",
215 [DLM_REJECTED
] = "request rejected, unrecognized client",
216 [DLM_ABORT
] = "blocked lock request cancelled",
217 [DLM_CANCEL
] = "conversion request cancelled",
218 [DLM_IVRESHANDLE
] = "invalid resource handle",
219 [DLM_DEADLOCK
] = "deadlock recovery refused this request",
220 [DLM_DENIED_NOASTS
] = "failed to allocate AST",
221 [DLM_FORWARD
] = "request must wait for primary's response",
222 [DLM_TIMEOUT
] = "timeout value for lock has expired",
223 [DLM_IVGROUPID
] = "invalid group specification",
224 [DLM_VERS_CONFLICT
] = "version conflicts prevent request handling",
225 [DLM_BAD_DEVICE_PATH
] = "Locks device does not exist or path wrong",
226 [DLM_NO_DEVICE_PERMISSION
] = "Client has insufficient perms for device",
227 [DLM_NO_CONTROL_DEVICE
] = "Cannot set options on opened device ",
228 [DLM_RECOVERING
] = "lock resource being recovered",
229 [DLM_MIGRATING
] = "lock resource being migrated",
230 [DLM_MAXSTATS
] = "invalid error number",
233 const char *dlm_errmsg(enum dlm_status err
)
235 if (err
>= DLM_MAXSTATS
|| err
< 0)
236 return dlm_errmsgs
[DLM_MAXSTATS
];
237 return dlm_errmsgs
[err
];
239 EXPORT_SYMBOL_GPL(dlm_errmsg
);
241 const char *dlm_errname(enum dlm_status err
)
243 if (err
>= DLM_MAXSTATS
|| err
< 0)
244 return dlm_errnames
[DLM_MAXSTATS
];
245 return dlm_errnames
[err
];
247 EXPORT_SYMBOL_GPL(dlm_errname
);
249 /* NOTE: This function converts a lockname into a string. It uses knowledge
250 * of the format of the lockname that should be outside the purview of the dlm.
251 * We are adding only to make dlm debugging slightly easier.
253 * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h.
255 static int stringify_lockname(const char *lockname
, int locklen
, char *buf
,
259 __be64 inode_blkno_be
;
261 #define OCFS2_DENTRY_LOCK_INO_START 18
262 if (*lockname
== 'N') {
263 memcpy((__be64
*)&inode_blkno_be
,
264 (char *)&lockname
[OCFS2_DENTRY_LOCK_INO_START
],
266 out
+= snprintf(buf
+ out
, len
- out
, "%.*s%08x",
267 OCFS2_DENTRY_LOCK_INO_START
- 1, lockname
,
268 (unsigned int)be64_to_cpu(inode_blkno_be
));
270 out
+= snprintf(buf
+ out
, len
- out
, "%.*s",
275 static int stringify_nodemap(unsigned long *nodemap
, int maxnodes
,
281 while ((i
= find_next_bit(nodemap
, maxnodes
, i
+ 1)) < maxnodes
)
282 out
+= snprintf(buf
+ out
, len
- out
, "%d ", i
);
287 static int dump_mle(struct dlm_master_list_entry
*mle
, char *buf
, int len
)
292 if (mle
->type
== DLM_MLE_BLOCK
)
294 else if (mle
->type
== DLM_MLE_MASTER
)
299 out
+= stringify_lockname(mle
->mname
, mle
->mnamelen
, buf
+ out
, len
- out
);
300 out
+= snprintf(buf
+ out
, len
- out
,
301 "\t%3s\tmas=%3u\tnew=%3u\tevt=%1d\tuse=%1d\tref=%3d\n",
302 mle_type
, mle
->master
, mle
->new_master
,
303 !list_empty(&mle
->hb_events
),
305 atomic_read(&mle
->mle_refs
.refcount
));
307 out
+= snprintf(buf
+ out
, len
- out
, "Maybe=");
308 out
+= stringify_nodemap(mle
->maybe_map
, O2NM_MAX_NODES
,
309 buf
+ out
, len
- out
);
310 out
+= snprintf(buf
+ out
, len
- out
, "\n");
312 out
+= snprintf(buf
+ out
, len
- out
, "Vote=");
313 out
+= stringify_nodemap(mle
->vote_map
, O2NM_MAX_NODES
,
314 buf
+ out
, len
- out
);
315 out
+= snprintf(buf
+ out
, len
- out
, "\n");
317 out
+= snprintf(buf
+ out
, len
- out
, "Response=");
318 out
+= stringify_nodemap(mle
->response_map
, O2NM_MAX_NODES
,
319 buf
+ out
, len
- out
);
320 out
+= snprintf(buf
+ out
, len
- out
, "\n");
322 out
+= snprintf(buf
+ out
, len
- out
, "Node=");
323 out
+= stringify_nodemap(mle
->node_map
, O2NM_MAX_NODES
,
324 buf
+ out
, len
- out
);
325 out
+= snprintf(buf
+ out
, len
- out
, "\n");
327 out
+= snprintf(buf
+ out
, len
- out
, "\n");
332 void dlm_print_one_mle(struct dlm_master_list_entry
*mle
)
336 buf
= (char *) get_zeroed_page(GFP_NOFS
);
338 dump_mle(mle
, buf
, PAGE_SIZE
- 1);
339 free_page((unsigned long)buf
);
343 #ifdef CONFIG_DEBUG_FS
345 static struct dentry
*dlm_debugfs_root
= NULL
;
347 #define DLM_DEBUGFS_DIR "o2dlm"
348 #define DLM_DEBUGFS_DLM_STATE "dlm_state"
349 #define DLM_DEBUGFS_LOCKING_STATE "locking_state"
350 #define DLM_DEBUGFS_MLE_STATE "mle_state"
351 #define DLM_DEBUGFS_PURGE_LIST "purge_list"
353 /* begin - utils funcs */
354 static void dlm_debug_free(struct kref
*kref
)
356 struct dlm_debug_ctxt
*dc
;
358 dc
= container_of(kref
, struct dlm_debug_ctxt
, debug_refcnt
);
363 static void dlm_debug_put(struct dlm_debug_ctxt
*dc
)
366 kref_put(&dc
->debug_refcnt
, dlm_debug_free
);
369 static void dlm_debug_get(struct dlm_debug_ctxt
*dc
)
371 kref_get(&dc
->debug_refcnt
);
374 static struct debug_buffer
*debug_buffer_allocate(void)
376 struct debug_buffer
*db
= NULL
;
378 db
= kzalloc(sizeof(struct debug_buffer
), GFP_KERNEL
);
383 db
->buf
= kmalloc(db
->len
, GFP_KERNEL
);
393 static ssize_t
debug_buffer_read(struct file
*file
, char __user
*buf
,
394 size_t nbytes
, loff_t
*ppos
)
396 struct debug_buffer
*db
= file
->private_data
;
398 return simple_read_from_buffer(buf
, nbytes
, ppos
, db
->buf
, db
->len
);
401 static loff_t
debug_buffer_llseek(struct file
*file
, loff_t off
, int whence
)
403 struct debug_buffer
*db
= file
->private_data
;
411 new = file
->f_pos
+ off
;
415 if (new < 0 || new > db
->len
)
418 return (file
->f_pos
= new);
421 static int debug_buffer_release(struct inode
*inode
, struct file
*file
)
423 struct debug_buffer
*db
= (struct debug_buffer
*)file
->private_data
;
431 /* end - util funcs */
433 /* begin - purge list funcs */
434 static int debug_purgelist_print(struct dlm_ctxt
*dlm
, struct debug_buffer
*db
)
436 struct dlm_lock_resource
*res
;
438 unsigned long total
= 0;
440 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
441 "Dumping Purgelist for Domain: %s\n", dlm
->name
);
443 spin_lock(&dlm
->spinlock
);
444 list_for_each_entry(res
, &dlm
->purge_list
, purge
) {
446 if (db
->len
- out
< 100)
448 spin_lock(&res
->spinlock
);
449 out
+= stringify_lockname(res
->lockname
.name
,
451 db
->buf
+ out
, db
->len
- out
);
452 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\t%ld\n",
453 (jiffies
- res
->last_used
)/HZ
);
454 spin_unlock(&res
->spinlock
);
456 spin_unlock(&dlm
->spinlock
);
458 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
459 "Total on list: %ld\n", total
);
464 static int debug_purgelist_open(struct inode
*inode
, struct file
*file
)
466 struct dlm_ctxt
*dlm
= inode
->i_private
;
467 struct debug_buffer
*db
;
469 db
= debug_buffer_allocate();
473 db
->len
= debug_purgelist_print(dlm
, db
);
475 file
->private_data
= db
;
482 static struct file_operations debug_purgelist_fops
= {
483 .open
= debug_purgelist_open
,
484 .release
= debug_buffer_release
,
485 .read
= debug_buffer_read
,
486 .llseek
= debug_buffer_llseek
,
488 /* end - purge list funcs */
490 /* begin - debug mle funcs */
491 static int debug_mle_print(struct dlm_ctxt
*dlm
, struct debug_buffer
*db
)
493 struct dlm_master_list_entry
*mle
;
494 struct hlist_head
*bucket
;
495 struct hlist_node
*list
;
497 unsigned long total
= 0, longest
= 0, bktcnt
;
499 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
500 "Dumping MLEs for Domain: %s\n", dlm
->name
);
502 spin_lock(&dlm
->master_lock
);
503 for (i
= 0; i
< DLM_HASH_BUCKETS
; i
++) {
504 bucket
= dlm_master_hash(dlm
, i
);
505 hlist_for_each(list
, bucket
) {
506 mle
= hlist_entry(list
, struct dlm_master_list_entry
,
510 if (db
->len
- out
< 200)
512 out
+= dump_mle(mle
, db
->buf
+ out
, db
->len
- out
);
514 longest
= max(longest
, bktcnt
);
517 spin_unlock(&dlm
->master_lock
);
519 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
520 "Total: %ld, Longest: %ld\n", total
, longest
);
524 static int debug_mle_open(struct inode
*inode
, struct file
*file
)
526 struct dlm_ctxt
*dlm
= inode
->i_private
;
527 struct debug_buffer
*db
;
529 db
= debug_buffer_allocate();
533 db
->len
= debug_mle_print(dlm
, db
);
535 file
->private_data
= db
;
542 static struct file_operations debug_mle_fops
= {
543 .open
= debug_mle_open
,
544 .release
= debug_buffer_release
,
545 .read
= debug_buffer_read
,
546 .llseek
= debug_buffer_llseek
,
549 /* end - debug mle funcs */
551 /* begin - debug lockres funcs */
552 static int dump_lock(struct dlm_lock
*lock
, int list_type
, char *buf
, int len
)
556 #define DEBUG_LOCK_VERSION 1
557 spin_lock(&lock
->spinlock
);
558 out
= snprintf(buf
, len
, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
561 list_type
, lock
->ml
.type
, lock
->ml
.convert_type
,
563 dlm_get_lock_cookie_node(be64_to_cpu(lock
->ml
.cookie
)),
564 dlm_get_lock_cookie_seq(be64_to_cpu(lock
->ml
.cookie
)),
565 !list_empty(&lock
->ast_list
),
566 !list_empty(&lock
->bast_list
),
567 lock
->ast_pending
, lock
->bast_pending
,
568 lock
->convert_pending
, lock
->lock_pending
,
569 lock
->cancel_pending
, lock
->unlock_pending
,
570 atomic_read(&lock
->lock_refs
.refcount
));
571 spin_unlock(&lock
->spinlock
);
576 static int dump_lockres(struct dlm_lock_resource
*res
, char *buf
, int len
)
578 struct dlm_lock
*lock
;
582 out
+= snprintf(buf
+ out
, len
- out
, "NAME:");
583 out
+= stringify_lockname(res
->lockname
.name
, res
->lockname
.len
,
584 buf
+ out
, len
- out
);
585 out
+= snprintf(buf
+ out
, len
- out
, "\n");
587 #define DEBUG_LRES_VERSION 1
588 out
+= snprintf(buf
+ out
, len
- out
,
589 "LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
591 res
->owner
, res
->state
, res
->last_used
,
592 !list_empty(&res
->purge
),
593 !list_empty(&res
->dirty
),
594 !list_empty(&res
->recovering
),
595 res
->inflight_locks
, res
->migration_pending
,
596 atomic_read(&res
->asts_reserved
),
597 atomic_read(&res
->refs
.refcount
));
600 out
+= snprintf(buf
+ out
, len
- out
, "RMAP:");
601 out
+= stringify_nodemap(res
->refmap
, O2NM_MAX_NODES
,
602 buf
+ out
, len
- out
);
603 out
+= snprintf(buf
+ out
, len
- out
, "\n");
606 out
+= snprintf(buf
+ out
, len
- out
, "LVBX:");
607 for (i
= 0; i
< DLM_LVB_LEN
; i
++)
608 out
+= snprintf(buf
+ out
, len
- out
,
609 "%02x", (unsigned char)res
->lvb
[i
]);
610 out
+= snprintf(buf
+ out
, len
- out
, "\n");
613 list_for_each_entry(lock
, &res
->granted
, list
)
614 out
+= dump_lock(lock
, 0, buf
+ out
, len
- out
);
617 list_for_each_entry(lock
, &res
->converting
, list
)
618 out
+= dump_lock(lock
, 1, buf
+ out
, len
- out
);
621 list_for_each_entry(lock
, &res
->blocked
, list
)
622 out
+= dump_lock(lock
, 2, buf
+ out
, len
- out
);
624 out
+= snprintf(buf
+ out
, len
- out
, "\n");
629 static void *lockres_seq_start(struct seq_file
*m
, loff_t
*pos
)
631 struct debug_lockres
*dl
= m
->private;
632 struct dlm_ctxt
*dlm
= dl
->dl_ctxt
;
633 struct dlm_lock_resource
*oldres
= dl
->dl_res
;
634 struct dlm_lock_resource
*res
= NULL
;
635 struct list_head
*track_list
;
637 spin_lock(&dlm
->track_lock
);
639 track_list
= &oldres
->tracking
;
641 track_list
= &dlm
->tracking_list
;
643 list_for_each_entry(res
, track_list
, tracking
) {
644 if (&res
->tracking
== &dlm
->tracking_list
)
647 dlm_lockres_get(res
);
650 spin_unlock(&dlm
->track_lock
);
653 dlm_lockres_put(oldres
);
658 spin_lock(&res
->spinlock
);
659 dump_lockres(res
, dl
->dl_buf
, dl
->dl_len
- 1);
660 spin_unlock(&res
->spinlock
);
664 /* passed to seq_show */
668 static void lockres_seq_stop(struct seq_file
*m
, void *v
)
672 static void *lockres_seq_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
677 static int lockres_seq_show(struct seq_file
*s
, void *v
)
679 struct debug_lockres
*dl
= (struct debug_lockres
*)v
;
681 seq_printf(s
, "%s", dl
->dl_buf
);
686 static struct seq_operations debug_lockres_ops
= {
687 .start
= lockres_seq_start
,
688 .stop
= lockres_seq_stop
,
689 .next
= lockres_seq_next
,
690 .show
= lockres_seq_show
,
693 static int debug_lockres_open(struct inode
*inode
, struct file
*file
)
695 struct dlm_ctxt
*dlm
= inode
->i_private
;
697 struct seq_file
*seq
;
698 struct debug_lockres
*dl
= NULL
;
700 dl
= kzalloc(sizeof(struct debug_lockres
), GFP_KERNEL
);
706 dl
->dl_len
= PAGE_SIZE
;
707 dl
->dl_buf
= kmalloc(dl
->dl_len
, GFP_KERNEL
);
713 ret
= seq_open(file
, &debug_lockres_ops
);
719 seq
= (struct seq_file
*) file
->private_data
;
733 static int debug_lockres_release(struct inode
*inode
, struct file
*file
)
735 struct seq_file
*seq
= (struct seq_file
*)file
->private_data
;
736 struct debug_lockres
*dl
= (struct debug_lockres
*)seq
->private;
739 dlm_lockres_put(dl
->dl_res
);
740 dlm_put(dl
->dl_ctxt
);
742 return seq_release_private(inode
, file
);
745 static struct file_operations debug_lockres_fops
= {
746 .open
= debug_lockres_open
,
747 .release
= debug_lockres_release
,
751 /* end - debug lockres funcs */
753 /* begin - debug state funcs */
754 static int debug_state_print(struct dlm_ctxt
*dlm
, struct debug_buffer
*db
)
757 struct dlm_reco_node_data
*node
;
759 int cur_mles
= 0, tot_mles
= 0;
762 spin_lock(&dlm
->spinlock
);
764 switch (dlm
->dlm_state
) {
766 state
= "NEW"; break;
767 case DLM_CTXT_JOINED
:
768 state
= "JOINED"; break;
769 case DLM_CTXT_IN_SHUTDOWN
:
770 state
= "SHUTDOWN"; break;
771 case DLM_CTXT_LEAVING
:
772 state
= "LEAVING"; break;
774 state
= "UNKNOWN"; break;
777 /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
778 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
779 "Domain: %s Key: 0x%08x\n", dlm
->name
, dlm
->key
);
781 /* Thread Pid: xxx Node: xxx State: xxxxx */
782 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
783 "Thread Pid: %d Node: %d State: %s\n",
784 dlm
->dlm_thread_task
->pid
, dlm
->node_num
, state
);
786 /* Number of Joins: xxx Joining Node: xxx */
787 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
788 "Number of Joins: %d Joining Node: %d\n",
789 dlm
->num_joins
, dlm
->joining_node
);
791 /* Domain Map: xx xx xx */
792 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Domain Map: ");
793 out
+= stringify_nodemap(dlm
->domain_map
, O2NM_MAX_NODES
,
794 db
->buf
+ out
, db
->len
- out
);
795 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\n");
797 /* Live Map: xx xx xx */
798 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Live Map: ");
799 out
+= stringify_nodemap(dlm
->live_nodes_map
, O2NM_MAX_NODES
,
800 db
->buf
+ out
, db
->len
- out
);
801 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\n");
803 /* Lock Resources: xxx (xxx) */
804 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
805 "Lock Resources: %d (%d)\n",
806 atomic_read(&dlm
->res_cur_count
),
807 atomic_read(&dlm
->res_tot_count
));
809 for (i
= 0; i
< DLM_MLE_NUM_TYPES
; ++i
)
810 tot_mles
+= atomic_read(&dlm
->mle_tot_count
[i
]);
812 for (i
= 0; i
< DLM_MLE_NUM_TYPES
; ++i
)
813 cur_mles
+= atomic_read(&dlm
->mle_cur_count
[i
]);
815 /* MLEs: xxx (xxx) */
816 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
817 "MLEs: %d (%d)\n", cur_mles
, tot_mles
);
819 /* Blocking: xxx (xxx) */
820 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
821 " Blocking: %d (%d)\n",
822 atomic_read(&dlm
->mle_cur_count
[DLM_MLE_BLOCK
]),
823 atomic_read(&dlm
->mle_tot_count
[DLM_MLE_BLOCK
]));
825 /* Mastery: xxx (xxx) */
826 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
827 " Mastery: %d (%d)\n",
828 atomic_read(&dlm
->mle_cur_count
[DLM_MLE_MASTER
]),
829 atomic_read(&dlm
->mle_tot_count
[DLM_MLE_MASTER
]));
831 /* Migration: xxx (xxx) */
832 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
833 " Migration: %d (%d)\n",
834 atomic_read(&dlm
->mle_cur_count
[DLM_MLE_MIGRATION
]),
835 atomic_read(&dlm
->mle_tot_count
[DLM_MLE_MIGRATION
]));
837 /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
838 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
839 "Lists: Dirty=%s Purge=%s PendingASTs=%s "
841 (list_empty(&dlm
->dirty_list
) ? "Empty" : "InUse"),
842 (list_empty(&dlm
->purge_list
) ? "Empty" : "InUse"),
843 (list_empty(&dlm
->pending_asts
) ? "Empty" : "InUse"),
844 (list_empty(&dlm
->pending_basts
) ? "Empty" : "InUse"));
846 /* Purge Count: xxx Refs: xxx */
847 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
848 "Purge Count: %d Refs: %d\n", dlm
->purge_count
,
849 atomic_read(&dlm
->dlm_refs
.refcount
));
852 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
853 "Dead Node: %d\n", dlm
->reco
.dead_node
);
855 /* What about DLM_RECO_STATE_FINALIZE? */
856 if (dlm
->reco
.state
== DLM_RECO_STATE_ACTIVE
)
861 /* Recovery Pid: xxxx Master: xxx State: xxxx */
862 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
863 "Recovery Pid: %d Master: %d State: %s\n",
864 dlm
->dlm_reco_thread_task
->pid
,
865 dlm
->reco
.new_master
, state
);
867 /* Recovery Map: xx xx */
868 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Recovery Map: ");
869 out
+= stringify_nodemap(dlm
->recovery_map
, O2NM_MAX_NODES
,
870 db
->buf
+ out
, db
->len
- out
);
871 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\n");
873 /* Recovery Node State: */
874 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Recovery Node State:\n");
875 list_for_each_entry(node
, &dlm
->reco
.node_data
, list
) {
876 switch (node
->state
) {
877 case DLM_RECO_NODE_DATA_INIT
:
880 case DLM_RECO_NODE_DATA_REQUESTING
:
881 state
= "REQUESTING";
883 case DLM_RECO_NODE_DATA_DEAD
:
886 case DLM_RECO_NODE_DATA_RECEIVING
:
889 case DLM_RECO_NODE_DATA_REQUESTED
:
892 case DLM_RECO_NODE_DATA_DONE
:
895 case DLM_RECO_NODE_DATA_FINALIZE_SENT
:
896 state
= "FINALIZE-SENT";
902 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\t%u - %s\n",
903 node
->node_num
, state
);
906 spin_unlock(&dlm
->spinlock
);
911 static int debug_state_open(struct inode
*inode
, struct file
*file
)
913 struct dlm_ctxt
*dlm
= inode
->i_private
;
914 struct debug_buffer
*db
= NULL
;
916 db
= debug_buffer_allocate();
920 db
->len
= debug_state_print(dlm
, db
);
922 file
->private_data
= db
;
929 static struct file_operations debug_state_fops
= {
930 .open
= debug_state_open
,
931 .release
= debug_buffer_release
,
932 .read
= debug_buffer_read
,
933 .llseek
= debug_buffer_llseek
,
935 /* end - debug state funcs */
937 /* files in subroot */
938 int dlm_debug_init(struct dlm_ctxt
*dlm
)
940 struct dlm_debug_ctxt
*dc
= dlm
->dlm_debug_ctxt
;
942 /* for dumping dlm_ctxt */
943 dc
->debug_state_dentry
= debugfs_create_file(DLM_DEBUGFS_DLM_STATE
,
945 dlm
->dlm_debugfs_subroot
,
946 dlm
, &debug_state_fops
);
947 if (!dc
->debug_state_dentry
) {
952 /* for dumping lockres */
953 dc
->debug_lockres_dentry
=
954 debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE
,
956 dlm
->dlm_debugfs_subroot
,
957 dlm
, &debug_lockres_fops
);
958 if (!dc
->debug_lockres_dentry
) {
963 /* for dumping mles */
964 dc
->debug_mle_dentry
= debugfs_create_file(DLM_DEBUGFS_MLE_STATE
,
966 dlm
->dlm_debugfs_subroot
,
967 dlm
, &debug_mle_fops
);
968 if (!dc
->debug_mle_dentry
) {
973 /* for dumping lockres on the purge list */
974 dc
->debug_purgelist_dentry
=
975 debugfs_create_file(DLM_DEBUGFS_PURGE_LIST
,
977 dlm
->dlm_debugfs_subroot
,
978 dlm
, &debug_purgelist_fops
);
979 if (!dc
->debug_purgelist_dentry
) {
988 dlm_debug_shutdown(dlm
);
992 void dlm_debug_shutdown(struct dlm_ctxt
*dlm
)
994 struct dlm_debug_ctxt
*dc
= dlm
->dlm_debug_ctxt
;
997 if (dc
->debug_purgelist_dentry
)
998 debugfs_remove(dc
->debug_purgelist_dentry
);
999 if (dc
->debug_mle_dentry
)
1000 debugfs_remove(dc
->debug_mle_dentry
);
1001 if (dc
->debug_lockres_dentry
)
1002 debugfs_remove(dc
->debug_lockres_dentry
);
1003 if (dc
->debug_state_dentry
)
1004 debugfs_remove(dc
->debug_state_dentry
);
1009 /* subroot - domain dir */
1010 int dlm_create_debugfs_subroot(struct dlm_ctxt
*dlm
)
1012 dlm
->dlm_debugfs_subroot
= debugfs_create_dir(dlm
->name
,
1014 if (!dlm
->dlm_debugfs_subroot
) {
1015 mlog_errno(-ENOMEM
);
1019 dlm
->dlm_debug_ctxt
= kzalloc(sizeof(struct dlm_debug_ctxt
),
1021 if (!dlm
->dlm_debug_ctxt
) {
1022 mlog_errno(-ENOMEM
);
1025 kref_init(&dlm
->dlm_debug_ctxt
->debug_refcnt
);
1029 dlm_destroy_debugfs_subroot(dlm
);
1033 void dlm_destroy_debugfs_subroot(struct dlm_ctxt
*dlm
)
1035 if (dlm
->dlm_debugfs_subroot
)
1036 debugfs_remove(dlm
->dlm_debugfs_subroot
);
1040 int dlm_create_debugfs_root(void)
1042 dlm_debugfs_root
= debugfs_create_dir(DLM_DEBUGFS_DIR
, NULL
);
1043 if (!dlm_debugfs_root
) {
1044 mlog_errno(-ENOMEM
);
1050 void dlm_destroy_debugfs_root(void)
1052 if (dlm_debugfs_root
)
1053 debugfs_remove(dlm_debugfs_root
);
1055 #endif /* CONFIG_DEBUG_FS */