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/sysctl.h>
31 #include <linux/spinlock.h>
32 #include <linux/debugfs.h>
34 #include "cluster/heartbeat.h"
35 #include "cluster/nodemanager.h"
36 #include "cluster/tcp.h"
39 #include "dlmcommon.h"
40 #include "dlmdomain.h"
43 #define MLOG_MASK_PREFIX ML_DLM
44 #include "cluster/masklog.h"
46 static int stringify_lockname(const char *lockname
, int locklen
, char *buf
,
49 void dlm_print_one_lock_resource(struct dlm_lock_resource
*res
)
51 spin_lock(&res
->spinlock
);
52 __dlm_print_one_lock_resource(res
);
53 spin_unlock(&res
->spinlock
);
56 static void dlm_print_lockres_refmap(struct dlm_lock_resource
*res
)
59 assert_spin_locked(&res
->spinlock
);
61 printk(" refmap nodes: [ ");
64 bit
= find_next_bit(res
->refmap
, O2NM_MAX_NODES
, bit
);
65 if (bit
>= O2NM_MAX_NODES
)
70 printk("], inflight=%u\n", res
->inflight_locks
);
73 static void __dlm_print_lock(struct dlm_lock
*lock
)
75 spin_lock(&lock
->spinlock
);
77 printk(" type=%d, conv=%d, node=%u, cookie=%u:%llu, "
78 "ref=%u, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c), "
79 "pending=(conv=%c,lock=%c,cancel=%c,unlock=%c)\n",
80 lock
->ml
.type
, lock
->ml
.convert_type
, lock
->ml
.node
,
81 dlm_get_lock_cookie_node(be64_to_cpu(lock
->ml
.cookie
)),
82 dlm_get_lock_cookie_seq(be64_to_cpu(lock
->ml
.cookie
)),
83 atomic_read(&lock
->lock_refs
.refcount
),
84 (list_empty(&lock
->ast_list
) ? 'y' : 'n'),
85 (lock
->ast_pending
? 'y' : 'n'),
86 (list_empty(&lock
->bast_list
) ? 'y' : 'n'),
87 (lock
->bast_pending
? 'y' : 'n'),
88 (lock
->convert_pending
? 'y' : 'n'),
89 (lock
->lock_pending
? 'y' : 'n'),
90 (lock
->cancel_pending
? 'y' : 'n'),
91 (lock
->unlock_pending
? 'y' : 'n'));
93 spin_unlock(&lock
->spinlock
);
96 void __dlm_print_one_lock_resource(struct dlm_lock_resource
*res
)
98 struct list_head
*iter2
;
99 struct dlm_lock
*lock
;
100 char buf
[DLM_LOCKID_NAME_MAX
];
102 assert_spin_locked(&res
->spinlock
);
104 stringify_lockname(res
->lockname
.name
, res
->lockname
.len
,
105 buf
, sizeof(buf
) - 1);
106 printk("lockres: %s, owner=%u, state=%u\n",
107 buf
, res
->owner
, res
->state
);
108 printk(" last used: %lu, refcnt: %u, on purge list: %s\n",
109 res
->last_used
, atomic_read(&res
->refs
.refcount
),
110 list_empty(&res
->purge
) ? "no" : "yes");
111 printk(" on dirty list: %s, on reco list: %s, "
112 "migrating pending: %s\n",
113 list_empty(&res
->dirty
) ? "no" : "yes",
114 list_empty(&res
->recovering
) ? "no" : "yes",
115 res
->migration_pending
? "yes" : "no");
116 printk(" inflight locks: %d, asts reserved: %d\n",
117 res
->inflight_locks
, atomic_read(&res
->asts_reserved
));
118 dlm_print_lockres_refmap(res
);
119 printk(" granted queue:\n");
120 list_for_each(iter2
, &res
->granted
) {
121 lock
= list_entry(iter2
, struct dlm_lock
, list
);
122 __dlm_print_lock(lock
);
124 printk(" converting queue:\n");
125 list_for_each(iter2
, &res
->converting
) {
126 lock
= list_entry(iter2
, struct dlm_lock
, list
);
127 __dlm_print_lock(lock
);
129 printk(" blocked queue:\n");
130 list_for_each(iter2
, &res
->blocked
) {
131 lock
= list_entry(iter2
, struct dlm_lock
, list
);
132 __dlm_print_lock(lock
);
136 void dlm_print_one_lock(struct dlm_lock
*lockid
)
138 dlm_print_one_lock_resource(lockid
->lockres
);
140 EXPORT_SYMBOL_GPL(dlm_print_one_lock
);
142 static const char *dlm_errnames
[] = {
143 [DLM_NORMAL
] = "DLM_NORMAL",
144 [DLM_GRANTED
] = "DLM_GRANTED",
145 [DLM_DENIED
] = "DLM_DENIED",
146 [DLM_DENIED_NOLOCKS
] = "DLM_DENIED_NOLOCKS",
147 [DLM_WORKING
] = "DLM_WORKING",
148 [DLM_BLOCKED
] = "DLM_BLOCKED",
149 [DLM_BLOCKED_ORPHAN
] = "DLM_BLOCKED_ORPHAN",
150 [DLM_DENIED_GRACE_PERIOD
] = "DLM_DENIED_GRACE_PERIOD",
151 [DLM_SYSERR
] = "DLM_SYSERR",
152 [DLM_NOSUPPORT
] = "DLM_NOSUPPORT",
153 [DLM_CANCELGRANT
] = "DLM_CANCELGRANT",
154 [DLM_IVLOCKID
] = "DLM_IVLOCKID",
155 [DLM_SYNC
] = "DLM_SYNC",
156 [DLM_BADTYPE
] = "DLM_BADTYPE",
157 [DLM_BADRESOURCE
] = "DLM_BADRESOURCE",
158 [DLM_MAXHANDLES
] = "DLM_MAXHANDLES",
159 [DLM_NOCLINFO
] = "DLM_NOCLINFO",
160 [DLM_NOLOCKMGR
] = "DLM_NOLOCKMGR",
161 [DLM_NOPURGED
] = "DLM_NOPURGED",
162 [DLM_BADARGS
] = "DLM_BADARGS",
163 [DLM_VOID
] = "DLM_VOID",
164 [DLM_NOTQUEUED
] = "DLM_NOTQUEUED",
165 [DLM_IVBUFLEN
] = "DLM_IVBUFLEN",
166 [DLM_CVTUNGRANT
] = "DLM_CVTUNGRANT",
167 [DLM_BADPARAM
] = "DLM_BADPARAM",
168 [DLM_VALNOTVALID
] = "DLM_VALNOTVALID",
169 [DLM_REJECTED
] = "DLM_REJECTED",
170 [DLM_ABORT
] = "DLM_ABORT",
171 [DLM_CANCEL
] = "DLM_CANCEL",
172 [DLM_IVRESHANDLE
] = "DLM_IVRESHANDLE",
173 [DLM_DEADLOCK
] = "DLM_DEADLOCK",
174 [DLM_DENIED_NOASTS
] = "DLM_DENIED_NOASTS",
175 [DLM_FORWARD
] = "DLM_FORWARD",
176 [DLM_TIMEOUT
] = "DLM_TIMEOUT",
177 [DLM_IVGROUPID
] = "DLM_IVGROUPID",
178 [DLM_VERS_CONFLICT
] = "DLM_VERS_CONFLICT",
179 [DLM_BAD_DEVICE_PATH
] = "DLM_BAD_DEVICE_PATH",
180 [DLM_NO_DEVICE_PERMISSION
] = "DLM_NO_DEVICE_PERMISSION",
181 [DLM_NO_CONTROL_DEVICE
] = "DLM_NO_CONTROL_DEVICE ",
182 [DLM_RECOVERING
] = "DLM_RECOVERING",
183 [DLM_MIGRATING
] = "DLM_MIGRATING",
184 [DLM_MAXSTATS
] = "DLM_MAXSTATS",
187 static const char *dlm_errmsgs
[] = {
188 [DLM_NORMAL
] = "request in progress",
189 [DLM_GRANTED
] = "request granted",
190 [DLM_DENIED
] = "request denied",
191 [DLM_DENIED_NOLOCKS
] = "request denied, out of system resources",
192 [DLM_WORKING
] = "async request in progress",
193 [DLM_BLOCKED
] = "lock request blocked",
194 [DLM_BLOCKED_ORPHAN
] = "lock request blocked by a orphan lock",
195 [DLM_DENIED_GRACE_PERIOD
] = "topological change in progress",
196 [DLM_SYSERR
] = "system error",
197 [DLM_NOSUPPORT
] = "unsupported",
198 [DLM_CANCELGRANT
] = "can't cancel convert: already granted",
199 [DLM_IVLOCKID
] = "bad lockid",
200 [DLM_SYNC
] = "synchronous request granted",
201 [DLM_BADTYPE
] = "bad resource type",
202 [DLM_BADRESOURCE
] = "bad resource handle",
203 [DLM_MAXHANDLES
] = "no more resource handles",
204 [DLM_NOCLINFO
] = "can't contact cluster manager",
205 [DLM_NOLOCKMGR
] = "can't contact lock manager",
206 [DLM_NOPURGED
] = "can't contact purge daemon",
207 [DLM_BADARGS
] = "bad api args",
208 [DLM_VOID
] = "no status",
209 [DLM_NOTQUEUED
] = "NOQUEUE was specified and request failed",
210 [DLM_IVBUFLEN
] = "invalid resource name length",
211 [DLM_CVTUNGRANT
] = "attempted to convert ungranted lock",
212 [DLM_BADPARAM
] = "invalid lock mode specified",
213 [DLM_VALNOTVALID
] = "value block has been invalidated",
214 [DLM_REJECTED
] = "request rejected, unrecognized client",
215 [DLM_ABORT
] = "blocked lock request cancelled",
216 [DLM_CANCEL
] = "conversion request cancelled",
217 [DLM_IVRESHANDLE
] = "invalid resource handle",
218 [DLM_DEADLOCK
] = "deadlock recovery refused this request",
219 [DLM_DENIED_NOASTS
] = "failed to allocate AST",
220 [DLM_FORWARD
] = "request must wait for primary's response",
221 [DLM_TIMEOUT
] = "timeout value for lock has expired",
222 [DLM_IVGROUPID
] = "invalid group specification",
223 [DLM_VERS_CONFLICT
] = "version conflicts prevent request handling",
224 [DLM_BAD_DEVICE_PATH
] = "Locks device does not exist or path wrong",
225 [DLM_NO_DEVICE_PERMISSION
] = "Client has insufficient perms for device",
226 [DLM_NO_CONTROL_DEVICE
] = "Cannot set options on opened device ",
227 [DLM_RECOVERING
] = "lock resource being recovered",
228 [DLM_MIGRATING
] = "lock resource being migrated",
229 [DLM_MAXSTATS
] = "invalid error number",
232 const char *dlm_errmsg(enum dlm_status err
)
234 if (err
>= DLM_MAXSTATS
|| err
< 0)
235 return dlm_errmsgs
[DLM_MAXSTATS
];
236 return dlm_errmsgs
[err
];
238 EXPORT_SYMBOL_GPL(dlm_errmsg
);
240 const char *dlm_errname(enum dlm_status err
)
242 if (err
>= DLM_MAXSTATS
|| err
< 0)
243 return dlm_errnames
[DLM_MAXSTATS
];
244 return dlm_errnames
[err
];
246 EXPORT_SYMBOL_GPL(dlm_errname
);
248 /* NOTE: This function converts a lockname into a string. It uses knowledge
249 * of the format of the lockname that should be outside the purview of the dlm.
250 * We are adding only to make dlm debugging slightly easier.
252 * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h.
254 static int stringify_lockname(const char *lockname
, int locklen
, char *buf
,
258 __be64 inode_blkno_be
;
260 #define OCFS2_DENTRY_LOCK_INO_START 18
261 if (*lockname
== 'N') {
262 memcpy((__be64
*)&inode_blkno_be
,
263 (char *)&lockname
[OCFS2_DENTRY_LOCK_INO_START
],
265 out
+= snprintf(buf
+ out
, len
- out
, "%.*s%08x",
266 OCFS2_DENTRY_LOCK_INO_START
- 1, lockname
,
267 (unsigned int)be64_to_cpu(inode_blkno_be
));
269 out
+= snprintf(buf
+ out
, len
- out
, "%.*s",
274 static int stringify_nodemap(unsigned long *nodemap
, int maxnodes
,
280 while ((i
= find_next_bit(nodemap
, maxnodes
, i
+ 1)) < maxnodes
)
281 out
+= snprintf(buf
+ out
, len
- out
, "%d ", i
);
286 static int dump_mle(struct dlm_master_list_entry
*mle
, char *buf
, int len
)
291 if (mle
->type
== DLM_MLE_BLOCK
)
293 else if (mle
->type
== DLM_MLE_MASTER
)
298 out
+= stringify_lockname(mle
->mname
, mle
->mnamelen
, buf
+ out
, len
- out
);
299 out
+= snprintf(buf
+ out
, len
- out
,
300 "\t%3s\tmas=%3u\tnew=%3u\tevt=%1d\tuse=%1d\tref=%3d\n",
301 mle_type
, mle
->master
, mle
->new_master
,
302 !list_empty(&mle
->hb_events
),
304 atomic_read(&mle
->mle_refs
.refcount
));
306 out
+= snprintf(buf
+ out
, len
- out
, "Maybe=");
307 out
+= stringify_nodemap(mle
->maybe_map
, O2NM_MAX_NODES
,
308 buf
+ out
, len
- out
);
309 out
+= snprintf(buf
+ out
, len
- out
, "\n");
311 out
+= snprintf(buf
+ out
, len
- out
, "Vote=");
312 out
+= stringify_nodemap(mle
->vote_map
, O2NM_MAX_NODES
,
313 buf
+ out
, len
- out
);
314 out
+= snprintf(buf
+ out
, len
- out
, "\n");
316 out
+= snprintf(buf
+ out
, len
- out
, "Response=");
317 out
+= stringify_nodemap(mle
->response_map
, O2NM_MAX_NODES
,
318 buf
+ out
, len
- out
);
319 out
+= snprintf(buf
+ out
, len
- out
, "\n");
321 out
+= snprintf(buf
+ out
, len
- out
, "Node=");
322 out
+= stringify_nodemap(mle
->node_map
, O2NM_MAX_NODES
,
323 buf
+ out
, len
- out
);
324 out
+= snprintf(buf
+ out
, len
- out
, "\n");
326 out
+= snprintf(buf
+ out
, len
- out
, "\n");
331 void dlm_print_one_mle(struct dlm_master_list_entry
*mle
)
335 buf
= (char *) get_zeroed_page(GFP_NOFS
);
337 dump_mle(mle
, buf
, PAGE_SIZE
- 1);
338 free_page((unsigned long)buf
);
342 #ifdef CONFIG_DEBUG_FS
344 static struct dentry
*dlm_debugfs_root
= NULL
;
346 #define DLM_DEBUGFS_DIR "o2dlm"
347 #define DLM_DEBUGFS_DLM_STATE "dlm_state"
348 #define DLM_DEBUGFS_LOCKING_STATE "locking_state"
349 #define DLM_DEBUGFS_MLE_STATE "mle_state"
350 #define DLM_DEBUGFS_PURGE_LIST "purge_list"
352 /* begin - utils funcs */
353 static void dlm_debug_free(struct kref
*kref
)
355 struct dlm_debug_ctxt
*dc
;
357 dc
= container_of(kref
, struct dlm_debug_ctxt
, debug_refcnt
);
362 static void dlm_debug_put(struct dlm_debug_ctxt
*dc
)
365 kref_put(&dc
->debug_refcnt
, dlm_debug_free
);
368 static void dlm_debug_get(struct dlm_debug_ctxt
*dc
)
370 kref_get(&dc
->debug_refcnt
);
373 static struct debug_buffer
*debug_buffer_allocate(void)
375 struct debug_buffer
*db
= NULL
;
377 db
= kzalloc(sizeof(struct debug_buffer
), GFP_KERNEL
);
382 db
->buf
= kmalloc(db
->len
, GFP_KERNEL
);
392 static ssize_t
debug_buffer_read(struct file
*file
, char __user
*buf
,
393 size_t nbytes
, loff_t
*ppos
)
395 struct debug_buffer
*db
= file
->private_data
;
397 return simple_read_from_buffer(buf
, nbytes
, ppos
, db
->buf
, db
->len
);
400 static loff_t
debug_buffer_llseek(struct file
*file
, loff_t off
, int whence
)
402 struct debug_buffer
*db
= file
->private_data
;
410 new = file
->f_pos
+ off
;
414 if (new < 0 || new > db
->len
)
417 return (file
->f_pos
= new);
420 static int debug_buffer_release(struct inode
*inode
, struct file
*file
)
422 struct debug_buffer
*db
= (struct debug_buffer
*)file
->private_data
;
430 /* end - util funcs */
432 /* begin - purge list funcs */
433 static int debug_purgelist_print(struct dlm_ctxt
*dlm
, struct debug_buffer
*db
)
435 struct dlm_lock_resource
*res
;
437 unsigned long total
= 0;
439 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
440 "Dumping Purgelist for Domain: %s\n", dlm
->name
);
442 spin_lock(&dlm
->spinlock
);
443 list_for_each_entry(res
, &dlm
->purge_list
, purge
) {
445 if (db
->len
- out
< 100)
447 spin_lock(&res
->spinlock
);
448 out
+= stringify_lockname(res
->lockname
.name
,
450 db
->buf
+ out
, db
->len
- out
);
451 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\t%ld\n",
452 (jiffies
- res
->last_used
)/HZ
);
453 spin_unlock(&res
->spinlock
);
455 spin_unlock(&dlm
->spinlock
);
457 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
458 "Total on list: %ld\n", total
);
463 static int debug_purgelist_open(struct inode
*inode
, struct file
*file
)
465 struct dlm_ctxt
*dlm
= inode
->i_private
;
466 struct debug_buffer
*db
;
468 db
= debug_buffer_allocate();
472 db
->len
= debug_purgelist_print(dlm
, db
);
474 file
->private_data
= db
;
481 static const struct file_operations debug_purgelist_fops
= {
482 .open
= debug_purgelist_open
,
483 .release
= debug_buffer_release
,
484 .read
= debug_buffer_read
,
485 .llseek
= debug_buffer_llseek
,
487 /* end - purge list funcs */
489 /* begin - debug mle funcs */
490 static int debug_mle_print(struct dlm_ctxt
*dlm
, struct debug_buffer
*db
)
492 struct dlm_master_list_entry
*mle
;
493 struct hlist_head
*bucket
;
494 struct hlist_node
*list
;
496 unsigned long total
= 0, longest
= 0, bktcnt
;
498 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
499 "Dumping MLEs for Domain: %s\n", dlm
->name
);
501 spin_lock(&dlm
->master_lock
);
502 for (i
= 0; i
< DLM_HASH_BUCKETS
; i
++) {
503 bucket
= dlm_master_hash(dlm
, i
);
504 hlist_for_each(list
, bucket
) {
505 mle
= hlist_entry(list
, struct dlm_master_list_entry
,
509 if (db
->len
- out
< 200)
511 out
+= dump_mle(mle
, db
->buf
+ out
, db
->len
- out
);
513 longest
= max(longest
, bktcnt
);
516 spin_unlock(&dlm
->master_lock
);
518 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
519 "Total: %ld, Longest: %ld\n", total
, longest
);
523 static int debug_mle_open(struct inode
*inode
, struct file
*file
)
525 struct dlm_ctxt
*dlm
= inode
->i_private
;
526 struct debug_buffer
*db
;
528 db
= debug_buffer_allocate();
532 db
->len
= debug_mle_print(dlm
, db
);
534 file
->private_data
= db
;
541 static const struct file_operations debug_mle_fops
= {
542 .open
= debug_mle_open
,
543 .release
= debug_buffer_release
,
544 .read
= debug_buffer_read
,
545 .llseek
= debug_buffer_llseek
,
548 /* end - debug mle funcs */
550 /* begin - debug lockres funcs */
551 static int dump_lock(struct dlm_lock
*lock
, int list_type
, char *buf
, int len
)
555 #define DEBUG_LOCK_VERSION 1
556 spin_lock(&lock
->spinlock
);
557 out
= snprintf(buf
, len
, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
560 list_type
, lock
->ml
.type
, lock
->ml
.convert_type
,
562 dlm_get_lock_cookie_node(be64_to_cpu(lock
->ml
.cookie
)),
563 dlm_get_lock_cookie_seq(be64_to_cpu(lock
->ml
.cookie
)),
564 !list_empty(&lock
->ast_list
),
565 !list_empty(&lock
->bast_list
),
566 lock
->ast_pending
, lock
->bast_pending
,
567 lock
->convert_pending
, lock
->lock_pending
,
568 lock
->cancel_pending
, lock
->unlock_pending
,
569 atomic_read(&lock
->lock_refs
.refcount
));
570 spin_unlock(&lock
->spinlock
);
575 static int dump_lockres(struct dlm_lock_resource
*res
, char *buf
, int len
)
577 struct dlm_lock
*lock
;
581 out
+= snprintf(buf
+ out
, len
- out
, "NAME:");
582 out
+= stringify_lockname(res
->lockname
.name
, res
->lockname
.len
,
583 buf
+ out
, len
- out
);
584 out
+= snprintf(buf
+ out
, len
- out
, "\n");
586 #define DEBUG_LRES_VERSION 1
587 out
+= snprintf(buf
+ out
, len
- out
,
588 "LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
590 res
->owner
, res
->state
, res
->last_used
,
591 !list_empty(&res
->purge
),
592 !list_empty(&res
->dirty
),
593 !list_empty(&res
->recovering
),
594 res
->inflight_locks
, res
->migration_pending
,
595 atomic_read(&res
->asts_reserved
),
596 atomic_read(&res
->refs
.refcount
));
599 out
+= snprintf(buf
+ out
, len
- out
, "RMAP:");
600 out
+= stringify_nodemap(res
->refmap
, O2NM_MAX_NODES
,
601 buf
+ out
, len
- out
);
602 out
+= snprintf(buf
+ out
, len
- out
, "\n");
605 out
+= snprintf(buf
+ out
, len
- out
, "LVBX:");
606 for (i
= 0; i
< DLM_LVB_LEN
; i
++)
607 out
+= snprintf(buf
+ out
, len
- out
,
608 "%02x", (unsigned char)res
->lvb
[i
]);
609 out
+= snprintf(buf
+ out
, len
- out
, "\n");
612 list_for_each_entry(lock
, &res
->granted
, list
)
613 out
+= dump_lock(lock
, 0, buf
+ out
, len
- out
);
616 list_for_each_entry(lock
, &res
->converting
, list
)
617 out
+= dump_lock(lock
, 1, buf
+ out
, len
- out
);
620 list_for_each_entry(lock
, &res
->blocked
, list
)
621 out
+= dump_lock(lock
, 2, buf
+ out
, len
- out
);
623 out
+= snprintf(buf
+ out
, len
- out
, "\n");
628 static void *lockres_seq_start(struct seq_file
*m
, loff_t
*pos
)
630 struct debug_lockres
*dl
= m
->private;
631 struct dlm_ctxt
*dlm
= dl
->dl_ctxt
;
632 struct dlm_lock_resource
*oldres
= dl
->dl_res
;
633 struct dlm_lock_resource
*res
= NULL
;
634 struct list_head
*track_list
;
636 spin_lock(&dlm
->track_lock
);
638 track_list
= &oldres
->tracking
;
640 track_list
= &dlm
->tracking_list
;
642 list_for_each_entry(res
, track_list
, tracking
) {
643 if (&res
->tracking
== &dlm
->tracking_list
)
646 dlm_lockres_get(res
);
649 spin_unlock(&dlm
->track_lock
);
652 dlm_lockres_put(oldres
);
657 spin_lock(&res
->spinlock
);
658 dump_lockres(res
, dl
->dl_buf
, dl
->dl_len
- 1);
659 spin_unlock(&res
->spinlock
);
663 /* passed to seq_show */
667 static void lockres_seq_stop(struct seq_file
*m
, void *v
)
671 static void *lockres_seq_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
676 static int lockres_seq_show(struct seq_file
*s
, void *v
)
678 struct debug_lockres
*dl
= (struct debug_lockres
*)v
;
680 seq_printf(s
, "%s", dl
->dl_buf
);
685 static const struct seq_operations debug_lockres_ops
= {
686 .start
= lockres_seq_start
,
687 .stop
= lockres_seq_stop
,
688 .next
= lockres_seq_next
,
689 .show
= lockres_seq_show
,
692 static int debug_lockres_open(struct inode
*inode
, struct file
*file
)
694 struct dlm_ctxt
*dlm
= inode
->i_private
;
696 struct seq_file
*seq
;
697 struct debug_lockres
*dl
= NULL
;
699 dl
= kzalloc(sizeof(struct debug_lockres
), GFP_KERNEL
);
705 dl
->dl_len
= PAGE_SIZE
;
706 dl
->dl_buf
= kmalloc(dl
->dl_len
, GFP_KERNEL
);
712 ret
= seq_open(file
, &debug_lockres_ops
);
718 seq
= (struct seq_file
*) file
->private_data
;
732 static int debug_lockres_release(struct inode
*inode
, struct file
*file
)
734 struct seq_file
*seq
= (struct seq_file
*)file
->private_data
;
735 struct debug_lockres
*dl
= (struct debug_lockres
*)seq
->private;
738 dlm_lockres_put(dl
->dl_res
);
739 dlm_put(dl
->dl_ctxt
);
741 return seq_release_private(inode
, file
);
744 static const struct file_operations debug_lockres_fops
= {
745 .open
= debug_lockres_open
,
746 .release
= debug_lockres_release
,
750 /* end - debug lockres funcs */
752 /* begin - debug state funcs */
753 static int debug_state_print(struct dlm_ctxt
*dlm
, struct debug_buffer
*db
)
756 struct dlm_reco_node_data
*node
;
758 int cur_mles
= 0, tot_mles
= 0;
761 spin_lock(&dlm
->spinlock
);
763 switch (dlm
->dlm_state
) {
765 state
= "NEW"; break;
766 case DLM_CTXT_JOINED
:
767 state
= "JOINED"; break;
768 case DLM_CTXT_IN_SHUTDOWN
:
769 state
= "SHUTDOWN"; break;
770 case DLM_CTXT_LEAVING
:
771 state
= "LEAVING"; break;
773 state
= "UNKNOWN"; break;
776 /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
777 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
778 "Domain: %s Key: 0x%08x\n", dlm
->name
, dlm
->key
);
780 /* Thread Pid: xxx Node: xxx State: xxxxx */
781 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
782 "Thread Pid: %d Node: %d State: %s\n",
783 dlm
->dlm_thread_task
->pid
, dlm
->node_num
, state
);
785 /* Number of Joins: xxx Joining Node: xxx */
786 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
787 "Number of Joins: %d Joining Node: %d\n",
788 dlm
->num_joins
, dlm
->joining_node
);
790 /* Domain Map: xx xx xx */
791 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Domain Map: ");
792 out
+= stringify_nodemap(dlm
->domain_map
, O2NM_MAX_NODES
,
793 db
->buf
+ out
, db
->len
- out
);
794 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\n");
796 /* Live Map: xx xx xx */
797 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Live Map: ");
798 out
+= stringify_nodemap(dlm
->live_nodes_map
, O2NM_MAX_NODES
,
799 db
->buf
+ out
, db
->len
- out
);
800 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\n");
802 /* Lock Resources: xxx (xxx) */
803 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
804 "Lock Resources: %d (%d)\n",
805 atomic_read(&dlm
->res_cur_count
),
806 atomic_read(&dlm
->res_tot_count
));
808 for (i
= 0; i
< DLM_MLE_NUM_TYPES
; ++i
)
809 tot_mles
+= atomic_read(&dlm
->mle_tot_count
[i
]);
811 for (i
= 0; i
< DLM_MLE_NUM_TYPES
; ++i
)
812 cur_mles
+= atomic_read(&dlm
->mle_cur_count
[i
]);
814 /* MLEs: xxx (xxx) */
815 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
816 "MLEs: %d (%d)\n", cur_mles
, tot_mles
);
818 /* Blocking: xxx (xxx) */
819 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
820 " Blocking: %d (%d)\n",
821 atomic_read(&dlm
->mle_cur_count
[DLM_MLE_BLOCK
]),
822 atomic_read(&dlm
->mle_tot_count
[DLM_MLE_BLOCK
]));
824 /* Mastery: xxx (xxx) */
825 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
826 " Mastery: %d (%d)\n",
827 atomic_read(&dlm
->mle_cur_count
[DLM_MLE_MASTER
]),
828 atomic_read(&dlm
->mle_tot_count
[DLM_MLE_MASTER
]));
830 /* Migration: xxx (xxx) */
831 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
832 " Migration: %d (%d)\n",
833 atomic_read(&dlm
->mle_cur_count
[DLM_MLE_MIGRATION
]),
834 atomic_read(&dlm
->mle_tot_count
[DLM_MLE_MIGRATION
]));
836 /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
837 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
838 "Lists: Dirty=%s Purge=%s PendingASTs=%s "
840 (list_empty(&dlm
->dirty_list
) ? "Empty" : "InUse"),
841 (list_empty(&dlm
->purge_list
) ? "Empty" : "InUse"),
842 (list_empty(&dlm
->pending_asts
) ? "Empty" : "InUse"),
843 (list_empty(&dlm
->pending_basts
) ? "Empty" : "InUse"));
845 /* Purge Count: xxx Refs: xxx */
846 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
847 "Purge Count: %d Refs: %d\n", dlm
->purge_count
,
848 atomic_read(&dlm
->dlm_refs
.refcount
));
851 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
852 "Dead Node: %d\n", dlm
->reco
.dead_node
);
854 /* What about DLM_RECO_STATE_FINALIZE? */
855 if (dlm
->reco
.state
== DLM_RECO_STATE_ACTIVE
)
860 /* Recovery Pid: xxxx Master: xxx State: xxxx */
861 out
+= snprintf(db
->buf
+ out
, db
->len
- out
,
862 "Recovery Pid: %d Master: %d State: %s\n",
863 dlm
->dlm_reco_thread_task
->pid
,
864 dlm
->reco
.new_master
, state
);
866 /* Recovery Map: xx xx */
867 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Recovery Map: ");
868 out
+= stringify_nodemap(dlm
->recovery_map
, O2NM_MAX_NODES
,
869 db
->buf
+ out
, db
->len
- out
);
870 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\n");
872 /* Recovery Node State: */
873 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "Recovery Node State:\n");
874 list_for_each_entry(node
, &dlm
->reco
.node_data
, list
) {
875 switch (node
->state
) {
876 case DLM_RECO_NODE_DATA_INIT
:
879 case DLM_RECO_NODE_DATA_REQUESTING
:
880 state
= "REQUESTING";
882 case DLM_RECO_NODE_DATA_DEAD
:
885 case DLM_RECO_NODE_DATA_RECEIVING
:
888 case DLM_RECO_NODE_DATA_REQUESTED
:
891 case DLM_RECO_NODE_DATA_DONE
:
894 case DLM_RECO_NODE_DATA_FINALIZE_SENT
:
895 state
= "FINALIZE-SENT";
901 out
+= snprintf(db
->buf
+ out
, db
->len
- out
, "\t%u - %s\n",
902 node
->node_num
, state
);
905 spin_unlock(&dlm
->spinlock
);
910 static int debug_state_open(struct inode
*inode
, struct file
*file
)
912 struct dlm_ctxt
*dlm
= inode
->i_private
;
913 struct debug_buffer
*db
= NULL
;
915 db
= debug_buffer_allocate();
919 db
->len
= debug_state_print(dlm
, db
);
921 file
->private_data
= db
;
928 static const struct file_operations debug_state_fops
= {
929 .open
= debug_state_open
,
930 .release
= debug_buffer_release
,
931 .read
= debug_buffer_read
,
932 .llseek
= debug_buffer_llseek
,
934 /* end - debug state funcs */
936 /* files in subroot */
937 int dlm_debug_init(struct dlm_ctxt
*dlm
)
939 struct dlm_debug_ctxt
*dc
= dlm
->dlm_debug_ctxt
;
941 /* for dumping dlm_ctxt */
942 dc
->debug_state_dentry
= debugfs_create_file(DLM_DEBUGFS_DLM_STATE
,
944 dlm
->dlm_debugfs_subroot
,
945 dlm
, &debug_state_fops
);
946 if (!dc
->debug_state_dentry
) {
951 /* for dumping lockres */
952 dc
->debug_lockres_dentry
=
953 debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE
,
955 dlm
->dlm_debugfs_subroot
,
956 dlm
, &debug_lockres_fops
);
957 if (!dc
->debug_lockres_dentry
) {
962 /* for dumping mles */
963 dc
->debug_mle_dentry
= debugfs_create_file(DLM_DEBUGFS_MLE_STATE
,
965 dlm
->dlm_debugfs_subroot
,
966 dlm
, &debug_mle_fops
);
967 if (!dc
->debug_mle_dentry
) {
972 /* for dumping lockres on the purge list */
973 dc
->debug_purgelist_dentry
=
974 debugfs_create_file(DLM_DEBUGFS_PURGE_LIST
,
976 dlm
->dlm_debugfs_subroot
,
977 dlm
, &debug_purgelist_fops
);
978 if (!dc
->debug_purgelist_dentry
) {
987 dlm_debug_shutdown(dlm
);
991 void dlm_debug_shutdown(struct dlm_ctxt
*dlm
)
993 struct dlm_debug_ctxt
*dc
= dlm
->dlm_debug_ctxt
;
996 if (dc
->debug_purgelist_dentry
)
997 debugfs_remove(dc
->debug_purgelist_dentry
);
998 if (dc
->debug_mle_dentry
)
999 debugfs_remove(dc
->debug_mle_dentry
);
1000 if (dc
->debug_lockres_dentry
)
1001 debugfs_remove(dc
->debug_lockres_dentry
);
1002 if (dc
->debug_state_dentry
)
1003 debugfs_remove(dc
->debug_state_dentry
);
1008 /* subroot - domain dir */
1009 int dlm_create_debugfs_subroot(struct dlm_ctxt
*dlm
)
1011 dlm
->dlm_debugfs_subroot
= debugfs_create_dir(dlm
->name
,
1013 if (!dlm
->dlm_debugfs_subroot
) {
1014 mlog_errno(-ENOMEM
);
1018 dlm
->dlm_debug_ctxt
= kzalloc(sizeof(struct dlm_debug_ctxt
),
1020 if (!dlm
->dlm_debug_ctxt
) {
1021 mlog_errno(-ENOMEM
);
1024 kref_init(&dlm
->dlm_debug_ctxt
->debug_refcnt
);
1028 dlm_destroy_debugfs_subroot(dlm
);
1032 void dlm_destroy_debugfs_subroot(struct dlm_ctxt
*dlm
)
1034 if (dlm
->dlm_debugfs_subroot
)
1035 debugfs_remove(dlm
->dlm_debugfs_subroot
);
1039 int dlm_create_debugfs_root(void)
1041 dlm_debugfs_root
= debugfs_create_dir(DLM_DEBUGFS_DIR
, NULL
);
1042 if (!dlm_debugfs_root
) {
1043 mlog_errno(-ENOMEM
);
1049 void dlm_destroy_debugfs_root(void)
1051 if (dlm_debugfs_root
)
1052 debugfs_remove(dlm_debugfs_root
);
1054 #endif /* CONFIG_DEBUG_FS */