]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/ocfs2/dlm/dlmdebug.c
Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[net-next-2.6.git] / fs / ocfs2 / dlm / dlmdebug.c
CommitLineData
6714d8e8
KH
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * dlmdebug.c
5 *
6 * debug functionality for the dlm
7 *
c834cdb1 8 * Copyright (C) 2004, 2008 Oracle. All rights reserved.
6714d8e8
KH
9 *
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.
14 *
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.
19 *
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.
24 *
25 */
26
27#include <linux/types.h>
28#include <linux/slab.h>
29#include <linux/highmem.h>
6714d8e8
KH
30#include <linux/sysctl.h>
31#include <linux/spinlock.h>
6325b4a2 32#include <linux/debugfs.h>
6714d8e8
KH
33
34#include "cluster/heartbeat.h"
35#include "cluster/nodemanager.h"
36#include "cluster/tcp.h"
37
38#include "dlmapi.h"
39#include "dlmcommon.h"
6714d8e8 40#include "dlmdomain.h"
6325b4a2 41#include "dlmdebug.h"
6714d8e8
KH
42
43#define MLOG_MASK_PREFIX ML_DLM
44#include "cluster/masklog.h"
45
95642e56
AB
46static int stringify_lockname(const char *lockname, int locklen, char *buf,
47 int len);
c834cdb1 48
6714d8e8
KH
49void dlm_print_one_lock_resource(struct dlm_lock_resource *res)
50{
6714d8e8
KH
51 spin_lock(&res->spinlock);
52 __dlm_print_one_lock_resource(res);
53 spin_unlock(&res->spinlock);
54}
55
ba2bf218
KH
56static void dlm_print_lockres_refmap(struct dlm_lock_resource *res)
57{
58 int bit;
59 assert_spin_locked(&res->spinlock);
60
8f50eb97 61 printk(" refmap nodes: [ ");
ba2bf218
KH
62 bit = 0;
63 while (1) {
64 bit = find_next_bit(res->refmap, O2NM_MAX_NODES, bit);
65 if (bit >= O2NM_MAX_NODES)
66 break;
8f50eb97 67 printk("%u ", bit);
ba2bf218
KH
68 bit++;
69 }
8f50eb97 70 printk("], inflight=%u\n", res->inflight_locks);
c834cdb1
SM
71}
72
73static void __dlm_print_lock(struct dlm_lock *lock)
74{
75 spin_lock(&lock->spinlock);
76
8f50eb97 77 printk(" type=%d, conv=%d, node=%u, cookie=%u:%llu, "
c834cdb1
SM
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'));
92
93 spin_unlock(&lock->spinlock);
ba2bf218
KH
94}
95
6714d8e8
KH
96void __dlm_print_one_lock_resource(struct dlm_lock_resource *res)
97{
98 struct list_head *iter2;
99 struct dlm_lock *lock;
c834cdb1 100 char buf[DLM_LOCKID_NAME_MAX];
6714d8e8
KH
101
102 assert_spin_locked(&res->spinlock);
103
c834cdb1 104 stringify_lockname(res->lockname.name, res->lockname.len,
86a06aba 105 buf, sizeof(buf));
8f50eb97 106 printk("lockres: %s, owner=%u, state=%u\n",
c834cdb1 107 buf, res->owner, res->state);
8f50eb97 108 printk(" last used: %lu, refcnt: %u, on purge list: %s\n",
c834cdb1
SM
109 res->last_used, atomic_read(&res->refs.refcount),
110 list_empty(&res->purge) ? "no" : "yes");
8f50eb97 111 printk(" on dirty list: %s, on reco list: %s, "
c834cdb1
SM
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");
8f50eb97 116 printk(" inflight locks: %d, asts reserved: %d\n",
c834cdb1 117 res->inflight_locks, atomic_read(&res->asts_reserved));
ba2bf218 118 dlm_print_lockres_refmap(res);
8f50eb97 119 printk(" granted queue:\n");
6714d8e8
KH
120 list_for_each(iter2, &res->granted) {
121 lock = list_entry(iter2, struct dlm_lock, list);
c834cdb1 122 __dlm_print_lock(lock);
6714d8e8 123 }
8f50eb97 124 printk(" converting queue:\n");
6714d8e8
KH
125 list_for_each(iter2, &res->converting) {
126 lock = list_entry(iter2, struct dlm_lock, list);
c834cdb1 127 __dlm_print_lock(lock);
6714d8e8 128 }
8f50eb97 129 printk(" blocked queue:\n");
6714d8e8
KH
130 list_for_each(iter2, &res->blocked) {
131 lock = list_entry(iter2, struct dlm_lock, list);
c834cdb1 132 __dlm_print_lock(lock);
6714d8e8
KH
133 }
134}
135
136void dlm_print_one_lock(struct dlm_lock *lockid)
137{
138 dlm_print_one_lock_resource(lockid->lockres);
139}
140EXPORT_SYMBOL_GPL(dlm_print_one_lock);
141
6714d8e8
KH
142static 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",
185};
186
187static 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",
230};
231
232const char *dlm_errmsg(enum dlm_status err)
233{
234 if (err >= DLM_MAXSTATS || err < 0)
235 return dlm_errmsgs[DLM_MAXSTATS];
236 return dlm_errmsgs[err];
237}
238EXPORT_SYMBOL_GPL(dlm_errmsg);
239
240const char *dlm_errname(enum dlm_status err)
241{
242 if (err >= DLM_MAXSTATS || err < 0)
243 return dlm_errnames[DLM_MAXSTATS];
244 return dlm_errnames[err];
245}
246EXPORT_SYMBOL_GPL(dlm_errname);
6325b4a2 247
4e3d24ed
SM
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.
251 *
252 * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h.
253 */
95642e56
AB
254static int stringify_lockname(const char *lockname, int locklen, char *buf,
255 int len)
4e3d24ed
SM
256{
257 int out = 0;
258 __be64 inode_blkno_be;
259
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],
264 sizeof(__be64));
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));
268 } else
269 out += snprintf(buf + out, len - out, "%.*s",
270 locklen, lockname);
271 return out;
272}
273
e5a0334c
SM
274static int stringify_nodemap(unsigned long *nodemap, int maxnodes,
275 char *buf, int len)
276{
277 int out = 0;
278 int i = -1;
279
280 while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)
281 out += snprintf(buf + out, len - out, "%d ", i);
282
283 return out;
284}
285
286static int dump_mle(struct dlm_master_list_entry *mle, char *buf, int len)
287{
288 int out = 0;
e5a0334c
SM
289 char *mle_type;
290
e5a0334c
SM
291 if (mle->type == DLM_MLE_BLOCK)
292 mle_type = "BLK";
293 else if (mle->type == DLM_MLE_MASTER)
294 mle_type = "MAS";
295 else
296 mle_type = "MIG";
297
7141514b 298 out += stringify_lockname(mle->mname, mle->mnamelen, buf + out, len - out);
e5a0334c
SM
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),
303 !!mle->inuse,
304 atomic_read(&mle->mle_refs.refcount));
305
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");
310
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");
315
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");
320
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");
325
326 out += snprintf(buf + out, len - out, "\n");
327
328 return out;
329}
330
331void dlm_print_one_mle(struct dlm_master_list_entry *mle)
332{
333 char *buf;
334
335 buf = (char *) get_zeroed_page(GFP_NOFS);
336 if (buf) {
337 dump_mle(mle, buf, PAGE_SIZE - 1);
338 free_page((unsigned long)buf);
339 }
340}
341
342#ifdef CONFIG_DEBUG_FS
343
344static struct dentry *dlm_debugfs_root = NULL;
345
6325b4a2 346#define DLM_DEBUGFS_DIR "o2dlm"
007dce53 347#define DLM_DEBUGFS_DLM_STATE "dlm_state"
4e3d24ed 348#define DLM_DEBUGFS_LOCKING_STATE "locking_state"
d0129ace 349#define DLM_DEBUGFS_MLE_STATE "mle_state"
7209300a 350#define DLM_DEBUGFS_PURGE_LIST "purge_list"
007dce53
SM
351
352/* begin - utils funcs */
353static void dlm_debug_free(struct kref *kref)
354{
355 struct dlm_debug_ctxt *dc;
356
357 dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);
358
359 kfree(dc);
360}
361
95642e56 362static void dlm_debug_put(struct dlm_debug_ctxt *dc)
007dce53
SM
363{
364 if (dc)
365 kref_put(&dc->debug_refcnt, dlm_debug_free);
366}
367
368static void dlm_debug_get(struct dlm_debug_ctxt *dc)
369{
370 kref_get(&dc->debug_refcnt);
371}
372
007dce53
SM
373static struct debug_buffer *debug_buffer_allocate(void)
374{
375 struct debug_buffer *db = NULL;
376
377 db = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
378 if (!db)
379 goto bail;
380
381 db->len = PAGE_SIZE;
382 db->buf = kmalloc(db->len, GFP_KERNEL);
383 if (!db->buf)
384 goto bail;
385
386 return db;
387bail:
388 kfree(db);
389 return NULL;
390}
391
392static ssize_t debug_buffer_read(struct file *file, char __user *buf,
393 size_t nbytes, loff_t *ppos)
394{
395 struct debug_buffer *db = file->private_data;
396
397 return simple_read_from_buffer(buf, nbytes, ppos, db->buf, db->len);
398}
399
400static loff_t debug_buffer_llseek(struct file *file, loff_t off, int whence)
401{
402 struct debug_buffer *db = file->private_data;
403 loff_t new = -1;
404
405 switch (whence) {
406 case 0:
407 new = off;
408 break;
409 case 1:
410 new = file->f_pos + off;
411 break;
412 }
413
414 if (new < 0 || new > db->len)
415 return -EINVAL;
416
417 return (file->f_pos = new);
418}
419
420static int debug_buffer_release(struct inode *inode, struct file *file)
421{
33fa1d90 422 struct debug_buffer *db = file->private_data;
007dce53
SM
423
424 if (db)
425 kfree(db->buf);
426 kfree(db);
427
428 return 0;
429}
430/* end - util funcs */
431
7209300a
SM
432/* begin - purge list funcs */
433static int debug_purgelist_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
434{
435 struct dlm_lock_resource *res;
436 int out = 0;
437 unsigned long total = 0;
438
439 out += snprintf(db->buf + out, db->len - out,
440 "Dumping Purgelist for Domain: %s\n", dlm->name);
441
442 spin_lock(&dlm->spinlock);
443 list_for_each_entry(res, &dlm->purge_list, purge) {
444 ++total;
445 if (db->len - out < 100)
446 continue;
447 spin_lock(&res->spinlock);
448 out += stringify_lockname(res->lockname.name,
449 res->lockname.len,
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);
454 }
455 spin_unlock(&dlm->spinlock);
456
457 out += snprintf(db->buf + out, db->len - out,
458 "Total on list: %ld\n", total);
459
460 return out;
461}
462
463static int debug_purgelist_open(struct inode *inode, struct file *file)
464{
465 struct dlm_ctxt *dlm = inode->i_private;
466 struct debug_buffer *db;
467
468 db = debug_buffer_allocate();
469 if (!db)
470 goto bail;
471
472 db->len = debug_purgelist_print(dlm, db);
473
474 file->private_data = db;
475
476 return 0;
477bail:
478 return -ENOMEM;
479}
480
828c0950 481static const struct file_operations debug_purgelist_fops = {
7209300a
SM
482 .open = debug_purgelist_open,
483 .release = debug_buffer_release,
484 .read = debug_buffer_read,
485 .llseek = debug_buffer_llseek,
486};
487/* end - purge list funcs */
488
d0129ace 489/* begin - debug mle funcs */
d0129ace
SM
490static int debug_mle_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
491{
492 struct dlm_master_list_entry *mle;
2ed6c750
SM
493 struct hlist_head *bucket;
494 struct hlist_node *list;
495 int i, out = 0;
9405dccf 496 unsigned long total = 0, longest = 0, bktcnt;
d0129ace
SM
497
498 out += snprintf(db->buf + out, db->len - out,
499 "Dumping MLEs for Domain: %s\n", dlm->name);
500
501 spin_lock(&dlm->master_lock);
2ed6c750
SM
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,
506 master_hash_node);
507 ++total;
9405dccf 508 ++bktcnt;
2ed6c750
SM
509 if (db->len - out < 200)
510 continue;
511 out += dump_mle(mle, db->buf + out, db->len - out);
512 }
9405dccf
SM
513 longest = max(longest, bktcnt);
514 bktcnt = 0;
d0129ace
SM
515 }
516 spin_unlock(&dlm->master_lock);
517
518 out += snprintf(db->buf + out, db->len - out,
9405dccf 519 "Total: %ld, Longest: %ld\n", total, longest);
d0129ace
SM
520 return out;
521}
522
523static int debug_mle_open(struct inode *inode, struct file *file)
524{
525 struct dlm_ctxt *dlm = inode->i_private;
526 struct debug_buffer *db;
527
528 db = debug_buffer_allocate();
529 if (!db)
530 goto bail;
531
532 db->len = debug_mle_print(dlm, db);
533
534 file->private_data = db;
535
536 return 0;
537bail:
538 return -ENOMEM;
539}
540
828c0950 541static const struct file_operations debug_mle_fops = {
d0129ace
SM
542 .open = debug_mle_open,
543 .release = debug_buffer_release,
544 .read = debug_buffer_read,
545 .llseek = debug_buffer_llseek,
546};
547
548/* end - debug mle funcs */
549
4e3d24ed
SM
550/* begin - debug lockres funcs */
551static int dump_lock(struct dlm_lock *lock, int list_type, char *buf, int len)
552{
553 int out;
554
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,"
558 "%d,%d,%d,%d\n",
559 DEBUG_LOCK_VERSION,
560 list_type, lock->ml.type, lock->ml.convert_type,
561 lock->ml.node,
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);
571
572 return out;
573}
574
575static int dump_lockres(struct dlm_lock_resource *res, char *buf, int len)
576{
577 struct dlm_lock *lock;
578 int i;
579 int out = 0;
580
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");
585
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",
589 DEBUG_LRES_VERSION,
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));
597
598 /* refmap */
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");
603
604 /* lvb */
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");
610
611 /* granted */
612 list_for_each_entry(lock, &res->granted, list)
613 out += dump_lock(lock, 0, buf + out, len - out);
614
615 /* converting */
616 list_for_each_entry(lock, &res->converting, list)
617 out += dump_lock(lock, 1, buf + out, len - out);
618
619 /* blocked */
620 list_for_each_entry(lock, &res->blocked, list)
621 out += dump_lock(lock, 2, buf + out, len - out);
622
623 out += snprintf(buf + out, len - out, "\n");
624
625 return out;
626}
627
628static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
629{
630 struct debug_lockres *dl = m->private;
631 struct dlm_ctxt *dlm = dl->dl_ctxt;
b0d4f817 632 struct dlm_lock_resource *oldres = dl->dl_res;
4e3d24ed 633 struct dlm_lock_resource *res = NULL;
b0d4f817 634 struct list_head *track_list;
4e3d24ed 635
b0d4f817
SM
636 spin_lock(&dlm->track_lock);
637 if (oldres)
638 track_list = &oldres->tracking;
228ac635 639 else {
b0d4f817 640 track_list = &dlm->tracking_list;
228ac635
TY
641 if (list_empty(track_list)) {
642 dl = NULL;
643 spin_unlock(&dlm->track_lock);
644 goto bail;
645 }
646 }
4e3d24ed 647
b0d4f817
SM
648 list_for_each_entry(res, track_list, tracking) {
649 if (&res->tracking == &dlm->tracking_list)
650 res = NULL;
651 else
4e3d24ed 652 dlm_lockres_get(res);
b0d4f817 653 break;
4e3d24ed 654 }
b0d4f817 655 spin_unlock(&dlm->track_lock);
4e3d24ed 656
b0d4f817
SM
657 if (oldres)
658 dlm_lockres_put(oldres);
4e3d24ed 659
b0d4f817
SM
660 dl->dl_res = res;
661
662 if (res) {
663 spin_lock(&res->spinlock);
664 dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
665 spin_unlock(&res->spinlock);
666 } else
667 dl = NULL;
4e3d24ed 668
228ac635 669bail:
b0d4f817 670 /* passed to seq_show */
4e3d24ed
SM
671 return dl;
672}
673
674static void lockres_seq_stop(struct seq_file *m, void *v)
675{
676}
677
678static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
679{
680 return NULL;
681}
682
683static int lockres_seq_show(struct seq_file *s, void *v)
684{
685 struct debug_lockres *dl = (struct debug_lockres *)v;
686
687 seq_printf(s, "%s", dl->dl_buf);
688
689 return 0;
690}
691
88e9d34c 692static const struct seq_operations debug_lockres_ops = {
4e3d24ed
SM
693 .start = lockres_seq_start,
694 .stop = lockres_seq_stop,
695 .next = lockres_seq_next,
696 .show = lockres_seq_show,
697};
698
699static int debug_lockres_open(struct inode *inode, struct file *file)
700{
701 struct dlm_ctxt *dlm = inode->i_private;
702 int ret = -ENOMEM;
703 struct seq_file *seq;
704 struct debug_lockres *dl = NULL;
705
706 dl = kzalloc(sizeof(struct debug_lockres), GFP_KERNEL);
707 if (!dl) {
708 mlog_errno(ret);
709 goto bail;
710 }
711
712 dl->dl_len = PAGE_SIZE;
713 dl->dl_buf = kmalloc(dl->dl_len, GFP_KERNEL);
714 if (!dl->dl_buf) {
715 mlog_errno(ret);
716 goto bail;
717 }
718
719 ret = seq_open(file, &debug_lockres_ops);
720 if (ret) {
721 mlog_errno(ret);
722 goto bail;
723 }
724
33fa1d90 725 seq = file->private_data;
4e3d24ed
SM
726 seq->private = dl;
727
728 dlm_grab(dlm);
729 dl->dl_ctxt = dlm;
730
731 return 0;
732bail:
733 if (dl)
734 kfree(dl->dl_buf);
735 kfree(dl);
736 return ret;
737}
738
739static int debug_lockres_release(struct inode *inode, struct file *file)
740{
33fa1d90 741 struct seq_file *seq = file->private_data;
4e3d24ed
SM
742 struct debug_lockres *dl = (struct debug_lockres *)seq->private;
743
744 if (dl->dl_res)
745 dlm_lockres_put(dl->dl_res);
746 dlm_put(dl->dl_ctxt);
747 kfree(dl->dl_buf);
748 return seq_release_private(inode, file);
749}
750
828c0950 751static const struct file_operations debug_lockres_fops = {
4e3d24ed
SM
752 .open = debug_lockres_open,
753 .release = debug_lockres_release,
754 .read = seq_read,
755 .llseek = seq_lseek,
756};
757/* end - debug lockres funcs */
758
007dce53
SM
759/* begin - debug state funcs */
760static int debug_state_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
761{
762 int out = 0;
763 struct dlm_reco_node_data *node;
764 char *state;
e64ff146
SM
765 int cur_mles = 0, tot_mles = 0;
766 int i;
007dce53
SM
767
768 spin_lock(&dlm->spinlock);
769
770 switch (dlm->dlm_state) {
771 case DLM_CTXT_NEW:
772 state = "NEW"; break;
773 case DLM_CTXT_JOINED:
774 state = "JOINED"; break;
775 case DLM_CTXT_IN_SHUTDOWN:
776 state = "SHUTDOWN"; break;
777 case DLM_CTXT_LEAVING:
778 state = "LEAVING"; break;
779 default:
780 state = "UNKNOWN"; break;
781 }
782
783 /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
784 out += snprintf(db->buf + out, db->len - out,
785 "Domain: %s Key: 0x%08x\n", dlm->name, dlm->key);
786
787 /* Thread Pid: xxx Node: xxx State: xxxxx */
788 out += snprintf(db->buf + out, db->len - out,
789 "Thread Pid: %d Node: %d State: %s\n",
790 dlm->dlm_thread_task->pid, dlm->node_num, state);
791
792 /* Number of Joins: xxx Joining Node: xxx */
793 out += snprintf(db->buf + out, db->len - out,
794 "Number of Joins: %d Joining Node: %d\n",
795 dlm->num_joins, dlm->joining_node);
796
797 /* Domain Map: xx xx xx */
798 out += snprintf(db->buf + out, db->len - out, "Domain Map: ");
799 out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
800 db->buf + out, db->len - out);
801 out += snprintf(db->buf + out, db->len - out, "\n");
802
803 /* Live Map: xx xx xx */
804 out += snprintf(db->buf + out, db->len - out, "Live Map: ");
805 out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
806 db->buf + out, db->len - out);
807 out += snprintf(db->buf + out, db->len - out, "\n");
808
e64ff146
SM
809 /* Lock Resources: xxx (xxx) */
810 out += snprintf(db->buf + out, db->len - out,
811 "Lock Resources: %d (%d)\n",
812 atomic_read(&dlm->res_cur_count),
813 atomic_read(&dlm->res_tot_count));
814
815 for (i = 0; i < DLM_MLE_NUM_TYPES; ++i)
816 tot_mles += atomic_read(&dlm->mle_tot_count[i]);
817
818 for (i = 0; i < DLM_MLE_NUM_TYPES; ++i)
819 cur_mles += atomic_read(&dlm->mle_cur_count[i]);
820
821 /* MLEs: xxx (xxx) */
822 out += snprintf(db->buf + out, db->len - out,
823 "MLEs: %d (%d)\n", cur_mles, tot_mles);
824
825 /* Blocking: xxx (xxx) */
826 out += snprintf(db->buf + out, db->len - out,
827 " Blocking: %d (%d)\n",
828 atomic_read(&dlm->mle_cur_count[DLM_MLE_BLOCK]),
829 atomic_read(&dlm->mle_tot_count[DLM_MLE_BLOCK]));
830
831 /* Mastery: xxx (xxx) */
832 out += snprintf(db->buf + out, db->len - out,
833 " Mastery: %d (%d)\n",
834 atomic_read(&dlm->mle_cur_count[DLM_MLE_MASTER]),
835 atomic_read(&dlm->mle_tot_count[DLM_MLE_MASTER]));
836
837 /* Migration: xxx (xxx) */
838 out += snprintf(db->buf + out, db->len - out,
839 " Migration: %d (%d)\n",
840 atomic_read(&dlm->mle_cur_count[DLM_MLE_MIGRATION]),
841 atomic_read(&dlm->mle_tot_count[DLM_MLE_MIGRATION]));
842
007dce53
SM
843 /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
844 out += snprintf(db->buf + out, db->len - out,
845 "Lists: Dirty=%s Purge=%s PendingASTs=%s "
2ed6c750 846 "PendingBASTs=%s\n",
007dce53
SM
847 (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
848 (list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
849 (list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
2ed6c750 850 (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"));
007dce53
SM
851
852 /* Purge Count: xxx Refs: xxx */
853 out += snprintf(db->buf + out, db->len - out,
854 "Purge Count: %d Refs: %d\n", dlm->purge_count,
855 atomic_read(&dlm->dlm_refs.refcount));
856
857 /* Dead Node: xxx */
858 out += snprintf(db->buf + out, db->len - out,
859 "Dead Node: %d\n", dlm->reco.dead_node);
860
861 /* What about DLM_RECO_STATE_FINALIZE? */
862 if (dlm->reco.state == DLM_RECO_STATE_ACTIVE)
863 state = "ACTIVE";
864 else
865 state = "INACTIVE";
866
867 /* Recovery Pid: xxxx Master: xxx State: xxxx */
868 out += snprintf(db->buf + out, db->len - out,
869 "Recovery Pid: %d Master: %d State: %s\n",
870 dlm->dlm_reco_thread_task->pid,
871 dlm->reco.new_master, state);
872
873 /* Recovery Map: xx xx */
874 out += snprintf(db->buf + out, db->len - out, "Recovery Map: ");
875 out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
876 db->buf + out, db->len - out);
877 out += snprintf(db->buf + out, db->len - out, "\n");
878
879 /* Recovery Node State: */
880 out += snprintf(db->buf + out, db->len - out, "Recovery Node State:\n");
881 list_for_each_entry(node, &dlm->reco.node_data, list) {
882 switch (node->state) {
883 case DLM_RECO_NODE_DATA_INIT:
884 state = "INIT";
885 break;
886 case DLM_RECO_NODE_DATA_REQUESTING:
887 state = "REQUESTING";
888 break;
889 case DLM_RECO_NODE_DATA_DEAD:
890 state = "DEAD";
891 break;
892 case DLM_RECO_NODE_DATA_RECEIVING:
893 state = "RECEIVING";
894 break;
895 case DLM_RECO_NODE_DATA_REQUESTED:
896 state = "REQUESTED";
897 break;
898 case DLM_RECO_NODE_DATA_DONE:
899 state = "DONE";
900 break;
901 case DLM_RECO_NODE_DATA_FINALIZE_SENT:
902 state = "FINALIZE-SENT";
903 break;
904 default:
905 state = "BAD";
906 break;
907 }
908 out += snprintf(db->buf + out, db->len - out, "\t%u - %s\n",
909 node->node_num, state);
910 }
911
912 spin_unlock(&dlm->spinlock);
913
914 return out;
915}
916
917static int debug_state_open(struct inode *inode, struct file *file)
918{
919 struct dlm_ctxt *dlm = inode->i_private;
920 struct debug_buffer *db = NULL;
921
922 db = debug_buffer_allocate();
923 if (!db)
924 goto bail;
925
926 db->len = debug_state_print(dlm, db);
927
928 file->private_data = db;
929
930 return 0;
931bail:
932 return -ENOMEM;
933}
934
828c0950 935static const struct file_operations debug_state_fops = {
007dce53
SM
936 .open = debug_state_open,
937 .release = debug_buffer_release,
938 .read = debug_buffer_read,
939 .llseek = debug_buffer_llseek,
940};
941/* end - debug state funcs */
942
943/* files in subroot */
944int dlm_debug_init(struct dlm_ctxt *dlm)
945{
946 struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
947
948 /* for dumping dlm_ctxt */
949 dc->debug_state_dentry = debugfs_create_file(DLM_DEBUGFS_DLM_STATE,
950 S_IFREG|S_IRUSR,
951 dlm->dlm_debugfs_subroot,
952 dlm, &debug_state_fops);
953 if (!dc->debug_state_dentry) {
954 mlog_errno(-ENOMEM);
955 goto bail;
956 }
957
4e3d24ed
SM
958 /* for dumping lockres */
959 dc->debug_lockres_dentry =
960 debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE,
961 S_IFREG|S_IRUSR,
962 dlm->dlm_debugfs_subroot,
963 dlm, &debug_lockres_fops);
964 if (!dc->debug_lockres_dentry) {
965 mlog_errno(-ENOMEM);
966 goto bail;
967 }
968
d0129ace
SM
969 /* for dumping mles */
970 dc->debug_mle_dentry = debugfs_create_file(DLM_DEBUGFS_MLE_STATE,
971 S_IFREG|S_IRUSR,
972 dlm->dlm_debugfs_subroot,
973 dlm, &debug_mle_fops);
974 if (!dc->debug_mle_dentry) {
975 mlog_errno(-ENOMEM);
976 goto bail;
977 }
978
7209300a
SM
979 /* for dumping lockres on the purge list */
980 dc->debug_purgelist_dentry =
981 debugfs_create_file(DLM_DEBUGFS_PURGE_LIST,
982 S_IFREG|S_IRUSR,
983 dlm->dlm_debugfs_subroot,
984 dlm, &debug_purgelist_fops);
985 if (!dc->debug_purgelist_dentry) {
986 mlog_errno(-ENOMEM);
987 goto bail;
988 }
989
007dce53
SM
990 dlm_debug_get(dc);
991 return 0;
992
993bail:
994 dlm_debug_shutdown(dlm);
995 return -ENOMEM;
996}
997
998void dlm_debug_shutdown(struct dlm_ctxt *dlm)
999{
1000 struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
1001
1002 if (dc) {
7209300a
SM
1003 if (dc->debug_purgelist_dentry)
1004 debugfs_remove(dc->debug_purgelist_dentry);
d0129ace
SM
1005 if (dc->debug_mle_dentry)
1006 debugfs_remove(dc->debug_mle_dentry);
4e3d24ed
SM
1007 if (dc->debug_lockres_dentry)
1008 debugfs_remove(dc->debug_lockres_dentry);
007dce53
SM
1009 if (dc->debug_state_dentry)
1010 debugfs_remove(dc->debug_state_dentry);
1011 dlm_debug_put(dc);
1012 }
1013}
6325b4a2
SM
1014
1015/* subroot - domain dir */
1016int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
1017{
1018 dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
1019 dlm_debugfs_root);
1020 if (!dlm->dlm_debugfs_subroot) {
1021 mlog_errno(-ENOMEM);
1022 goto bail;
1023 }
1024
007dce53
SM
1025 dlm->dlm_debug_ctxt = kzalloc(sizeof(struct dlm_debug_ctxt),
1026 GFP_KERNEL);
1027 if (!dlm->dlm_debug_ctxt) {
1028 mlog_errno(-ENOMEM);
1029 goto bail;
1030 }
1031 kref_init(&dlm->dlm_debug_ctxt->debug_refcnt);
1032
6325b4a2
SM
1033 return 0;
1034bail:
1035 dlm_destroy_debugfs_subroot(dlm);
1036 return -ENOMEM;
1037}
1038
1039void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
1040{
1041 if (dlm->dlm_debugfs_subroot)
1042 debugfs_remove(dlm->dlm_debugfs_subroot);
1043}
1044
1045/* debugfs root */
1046int dlm_create_debugfs_root(void)
1047{
1048 dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
1049 if (!dlm_debugfs_root) {
1050 mlog_errno(-ENOMEM);
1051 return -ENOMEM;
1052 }
1053 return 0;
1054}
1055
1056void dlm_destroy_debugfs_root(void)
1057{
1058 if (dlm_debugfs_root)
1059 debugfs_remove(dlm_debugfs_root);
1060}
1061#endif /* CONFIG_DEBUG_FS */