blob: 58e45795a6c650b26bd2fbbb677d893d075627aa [file] [log] [blame]
Kurt Hackel6714d8e2005-12-15 14:31:23 -08001/* -*- 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 *
8 * Copyright (C) 2004 Oracle. All rights reserved.
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>
30#include <linux/utsname.h>
31#include <linux/sysctl.h>
32#include <linux/spinlock.h>
Sunil Mushran6325b4a2008-03-10 15:16:22 -070033#include <linux/debugfs.h>
Kurt Hackel6714d8e2005-12-15 14:31:23 -080034
35#include "cluster/heartbeat.h"
36#include "cluster/nodemanager.h"
37#include "cluster/tcp.h"
38
39#include "dlmapi.h"
40#include "dlmcommon.h"
Kurt Hackel6714d8e2005-12-15 14:31:23 -080041#include "dlmdomain.h"
Sunil Mushran6325b4a2008-03-10 15:16:22 -070042#include "dlmdebug.h"
Kurt Hackel6714d8e2005-12-15 14:31:23 -080043
44#define MLOG_MASK_PREFIX ML_DLM
45#include "cluster/masklog.h"
46
47void dlm_print_one_lock_resource(struct dlm_lock_resource *res)
48{
49 mlog(ML_NOTICE, "lockres: %.*s, owner=%u, state=%u\n",
50 res->lockname.len, res->lockname.name,
51 res->owner, res->state);
52 spin_lock(&res->spinlock);
53 __dlm_print_one_lock_resource(res);
54 spin_unlock(&res->spinlock);
55}
56
Kurt Hackelba2bf212006-12-01 14:47:20 -080057static void dlm_print_lockres_refmap(struct dlm_lock_resource *res)
58{
59 int bit;
60 assert_spin_locked(&res->spinlock);
61
62 mlog(ML_NOTICE, " refmap nodes: [ ");
63 bit = 0;
64 while (1) {
65 bit = find_next_bit(res->refmap, O2NM_MAX_NODES, bit);
66 if (bit >= O2NM_MAX_NODES)
67 break;
68 printk("%u ", bit);
69 bit++;
70 }
71 printk("], inflight=%u\n", res->inflight_locks);
72}
73
Kurt Hackel6714d8e2005-12-15 14:31:23 -080074void __dlm_print_one_lock_resource(struct dlm_lock_resource *res)
75{
76 struct list_head *iter2;
77 struct dlm_lock *lock;
78
79 assert_spin_locked(&res->spinlock);
80
81 mlog(ML_NOTICE, "lockres: %.*s, owner=%u, state=%u\n",
82 res->lockname.len, res->lockname.name,
83 res->owner, res->state);
84 mlog(ML_NOTICE, " last used: %lu, on purge list: %s\n",
85 res->last_used, list_empty(&res->purge) ? "no" : "yes");
Kurt Hackelba2bf212006-12-01 14:47:20 -080086 dlm_print_lockres_refmap(res);
Kurt Hackel6714d8e2005-12-15 14:31:23 -080087 mlog(ML_NOTICE, " granted queue: \n");
88 list_for_each(iter2, &res->granted) {
89 lock = list_entry(iter2, struct dlm_lock, list);
90 spin_lock(&lock->spinlock);
91 mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
Kurt Hackel29004852006-03-02 16:43:36 -080092 "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
93 lock->ml.type, lock->ml.convert_type, lock->ml.node,
Kurt Hackel74aa2582007-01-17 15:11:36 -080094 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
95 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
Kurt Hackel6714d8e2005-12-15 14:31:23 -080096 list_empty(&lock->ast_list) ? 'y' : 'n',
97 lock->ast_pending ? 'y' : 'n',
98 list_empty(&lock->bast_list) ? 'y' : 'n',
99 lock->bast_pending ? 'y' : 'n');
100 spin_unlock(&lock->spinlock);
101 }
102 mlog(ML_NOTICE, " converting queue: \n");
103 list_for_each(iter2, &res->converting) {
104 lock = list_entry(iter2, struct dlm_lock, list);
105 spin_lock(&lock->spinlock);
106 mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
Kurt Hackel29004852006-03-02 16:43:36 -0800107 "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
108 lock->ml.type, lock->ml.convert_type, lock->ml.node,
Kurt Hackel74aa2582007-01-17 15:11:36 -0800109 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
110 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
Kurt Hackel6714d8e2005-12-15 14:31:23 -0800111 list_empty(&lock->ast_list) ? 'y' : 'n',
112 lock->ast_pending ? 'y' : 'n',
113 list_empty(&lock->bast_list) ? 'y' : 'n',
114 lock->bast_pending ? 'y' : 'n');
115 spin_unlock(&lock->spinlock);
116 }
117 mlog(ML_NOTICE, " blocked queue: \n");
118 list_for_each(iter2, &res->blocked) {
119 lock = list_entry(iter2, struct dlm_lock, list);
120 spin_lock(&lock->spinlock);
121 mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
Kurt Hackel29004852006-03-02 16:43:36 -0800122 "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
123 lock->ml.type, lock->ml.convert_type, lock->ml.node,
Kurt Hackel74aa2582007-01-17 15:11:36 -0800124 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
125 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
Kurt Hackel6714d8e2005-12-15 14:31:23 -0800126 list_empty(&lock->ast_list) ? 'y' : 'n',
127 lock->ast_pending ? 'y' : 'n',
128 list_empty(&lock->bast_list) ? 'y' : 'n',
129 lock->bast_pending ? 'y' : 'n');
130 spin_unlock(&lock->spinlock);
131 }
132}
133
134void dlm_print_one_lock(struct dlm_lock *lockid)
135{
136 dlm_print_one_lock_resource(lockid->lockres);
137}
138EXPORT_SYMBOL_GPL(dlm_print_one_lock);
139
Adrian Bunk3fb5a982006-05-16 17:26:41 +0200140#if 0
Kurt Hackel6714d8e2005-12-15 14:31:23 -0800141void dlm_dump_lock_resources(struct dlm_ctxt *dlm)
142{
143 struct dlm_lock_resource *res;
Mark Fasheh81f20942006-02-28 17:31:22 -0800144 struct hlist_node *iter;
145 struct hlist_head *bucket;
Kurt Hackel6714d8e2005-12-15 14:31:23 -0800146 int i;
147
148 mlog(ML_NOTICE, "struct dlm_ctxt: %s, node=%u, key=%u\n",
149 dlm->name, dlm->node_num, dlm->key);
150 if (!dlm || !dlm->name) {
151 mlog(ML_ERROR, "dlm=%p\n", dlm);
152 return;
153 }
154
155 spin_lock(&dlm->spinlock);
Mark Fasheh81f20942006-02-28 17:31:22 -0800156 for (i=0; i<DLM_HASH_BUCKETS; i++) {
Daniel Phillips03d864c2006-03-10 18:08:16 -0800157 bucket = dlm_lockres_hash(dlm, i);
Mark Fasheh81f20942006-02-28 17:31:22 -0800158 hlist_for_each_entry(res, iter, bucket, hash_node)
Kurt Hackel6714d8e2005-12-15 14:31:23 -0800159 dlm_print_one_lock_resource(res);
Kurt Hackel6714d8e2005-12-15 14:31:23 -0800160 }
161 spin_unlock(&dlm->spinlock);
162}
Adrian Bunk3fb5a982006-05-16 17:26:41 +0200163#endif /* 0 */
Kurt Hackel6714d8e2005-12-15 14:31:23 -0800164
165static const char *dlm_errnames[] = {
166 [DLM_NORMAL] = "DLM_NORMAL",
167 [DLM_GRANTED] = "DLM_GRANTED",
168 [DLM_DENIED] = "DLM_DENIED",
169 [DLM_DENIED_NOLOCKS] = "DLM_DENIED_NOLOCKS",
170 [DLM_WORKING] = "DLM_WORKING",
171 [DLM_BLOCKED] = "DLM_BLOCKED",
172 [DLM_BLOCKED_ORPHAN] = "DLM_BLOCKED_ORPHAN",
173 [DLM_DENIED_GRACE_PERIOD] = "DLM_DENIED_GRACE_PERIOD",
174 [DLM_SYSERR] = "DLM_SYSERR",
175 [DLM_NOSUPPORT] = "DLM_NOSUPPORT",
176 [DLM_CANCELGRANT] = "DLM_CANCELGRANT",
177 [DLM_IVLOCKID] = "DLM_IVLOCKID",
178 [DLM_SYNC] = "DLM_SYNC",
179 [DLM_BADTYPE] = "DLM_BADTYPE",
180 [DLM_BADRESOURCE] = "DLM_BADRESOURCE",
181 [DLM_MAXHANDLES] = "DLM_MAXHANDLES",
182 [DLM_NOCLINFO] = "DLM_NOCLINFO",
183 [DLM_NOLOCKMGR] = "DLM_NOLOCKMGR",
184 [DLM_NOPURGED] = "DLM_NOPURGED",
185 [DLM_BADARGS] = "DLM_BADARGS",
186 [DLM_VOID] = "DLM_VOID",
187 [DLM_NOTQUEUED] = "DLM_NOTQUEUED",
188 [DLM_IVBUFLEN] = "DLM_IVBUFLEN",
189 [DLM_CVTUNGRANT] = "DLM_CVTUNGRANT",
190 [DLM_BADPARAM] = "DLM_BADPARAM",
191 [DLM_VALNOTVALID] = "DLM_VALNOTVALID",
192 [DLM_REJECTED] = "DLM_REJECTED",
193 [DLM_ABORT] = "DLM_ABORT",
194 [DLM_CANCEL] = "DLM_CANCEL",
195 [DLM_IVRESHANDLE] = "DLM_IVRESHANDLE",
196 [DLM_DEADLOCK] = "DLM_DEADLOCK",
197 [DLM_DENIED_NOASTS] = "DLM_DENIED_NOASTS",
198 [DLM_FORWARD] = "DLM_FORWARD",
199 [DLM_TIMEOUT] = "DLM_TIMEOUT",
200 [DLM_IVGROUPID] = "DLM_IVGROUPID",
201 [DLM_VERS_CONFLICT] = "DLM_VERS_CONFLICT",
202 [DLM_BAD_DEVICE_PATH] = "DLM_BAD_DEVICE_PATH",
203 [DLM_NO_DEVICE_PERMISSION] = "DLM_NO_DEVICE_PERMISSION",
204 [DLM_NO_CONTROL_DEVICE ] = "DLM_NO_CONTROL_DEVICE ",
205 [DLM_RECOVERING] = "DLM_RECOVERING",
206 [DLM_MIGRATING] = "DLM_MIGRATING",
207 [DLM_MAXSTATS] = "DLM_MAXSTATS",
208};
209
210static const char *dlm_errmsgs[] = {
211 [DLM_NORMAL] = "request in progress",
212 [DLM_GRANTED] = "request granted",
213 [DLM_DENIED] = "request denied",
214 [DLM_DENIED_NOLOCKS] = "request denied, out of system resources",
215 [DLM_WORKING] = "async request in progress",
216 [DLM_BLOCKED] = "lock request blocked",
217 [DLM_BLOCKED_ORPHAN] = "lock request blocked by a orphan lock",
218 [DLM_DENIED_GRACE_PERIOD] = "topological change in progress",
219 [DLM_SYSERR] = "system error",
220 [DLM_NOSUPPORT] = "unsupported",
221 [DLM_CANCELGRANT] = "can't cancel convert: already granted",
222 [DLM_IVLOCKID] = "bad lockid",
223 [DLM_SYNC] = "synchronous request granted",
224 [DLM_BADTYPE] = "bad resource type",
225 [DLM_BADRESOURCE] = "bad resource handle",
226 [DLM_MAXHANDLES] = "no more resource handles",
227 [DLM_NOCLINFO] = "can't contact cluster manager",
228 [DLM_NOLOCKMGR] = "can't contact lock manager",
229 [DLM_NOPURGED] = "can't contact purge daemon",
230 [DLM_BADARGS] = "bad api args",
231 [DLM_VOID] = "no status",
232 [DLM_NOTQUEUED] = "NOQUEUE was specified and request failed",
233 [DLM_IVBUFLEN] = "invalid resource name length",
234 [DLM_CVTUNGRANT] = "attempted to convert ungranted lock",
235 [DLM_BADPARAM] = "invalid lock mode specified",
236 [DLM_VALNOTVALID] = "value block has been invalidated",
237 [DLM_REJECTED] = "request rejected, unrecognized client",
238 [DLM_ABORT] = "blocked lock request cancelled",
239 [DLM_CANCEL] = "conversion request cancelled",
240 [DLM_IVRESHANDLE] = "invalid resource handle",
241 [DLM_DEADLOCK] = "deadlock recovery refused this request",
242 [DLM_DENIED_NOASTS] = "failed to allocate AST",
243 [DLM_FORWARD] = "request must wait for primary's response",
244 [DLM_TIMEOUT] = "timeout value for lock has expired",
245 [DLM_IVGROUPID] = "invalid group specification",
246 [DLM_VERS_CONFLICT] = "version conflicts prevent request handling",
247 [DLM_BAD_DEVICE_PATH] = "Locks device does not exist or path wrong",
248 [DLM_NO_DEVICE_PERMISSION] = "Client has insufficient perms for device",
249 [DLM_NO_CONTROL_DEVICE] = "Cannot set options on opened device ",
250 [DLM_RECOVERING] = "lock resource being recovered",
251 [DLM_MIGRATING] = "lock resource being migrated",
252 [DLM_MAXSTATS] = "invalid error number",
253};
254
255const char *dlm_errmsg(enum dlm_status err)
256{
257 if (err >= DLM_MAXSTATS || err < 0)
258 return dlm_errmsgs[DLM_MAXSTATS];
259 return dlm_errmsgs[err];
260}
261EXPORT_SYMBOL_GPL(dlm_errmsg);
262
263const char *dlm_errname(enum dlm_status err)
264{
265 if (err >= DLM_MAXSTATS || err < 0)
266 return dlm_errnames[DLM_MAXSTATS];
267 return dlm_errnames[err];
268}
269EXPORT_SYMBOL_GPL(dlm_errname);
Sunil Mushran6325b4a2008-03-10 15:16:22 -0700270
Sunil Mushran4e3d24e2008-03-10 15:16:24 -0700271/* NOTE: This function converts a lockname into a string. It uses knowledge
272 * of the format of the lockname that should be outside the purview of the dlm.
273 * We are adding only to make dlm debugging slightly easier.
274 *
275 * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h.
276 */
277static int stringify_lockname(const char *lockname, int locklen,
278 char *buf, int len)
279{
280 int out = 0;
281 __be64 inode_blkno_be;
282
283#define OCFS2_DENTRY_LOCK_INO_START 18
284 if (*lockname == 'N') {
285 memcpy((__be64 *)&inode_blkno_be,
286 (char *)&lockname[OCFS2_DENTRY_LOCK_INO_START],
287 sizeof(__be64));
288 out += snprintf(buf + out, len - out, "%.*s%08x",
289 OCFS2_DENTRY_LOCK_INO_START - 1, lockname,
290 (unsigned int)be64_to_cpu(inode_blkno_be));
291 } else
292 out += snprintf(buf + out, len - out, "%.*s",
293 locklen, lockname);
294 return out;
295}
296
Sunil Mushrane5a03342008-03-10 15:16:28 -0700297static int stringify_nodemap(unsigned long *nodemap, int maxnodes,
298 char *buf, int len)
299{
300 int out = 0;
301 int i = -1;
302
303 while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)
304 out += snprintf(buf + out, len - out, "%d ", i);
305
306 return out;
307}
308
309static int dump_mle(struct dlm_master_list_entry *mle, char *buf, int len)
310{
311 int out = 0;
312 unsigned int namelen;
313 const char *name;
314 char *mle_type;
315
316 if (mle->type != DLM_MLE_MASTER) {
317 namelen = mle->u.name.len;
318 name = mle->u.name.name;
319 } else {
320 namelen = mle->u.res->lockname.len;
321 name = mle->u.res->lockname.name;
322 }
323
324 if (mle->type == DLM_MLE_BLOCK)
325 mle_type = "BLK";
326 else if (mle->type == DLM_MLE_MASTER)
327 mle_type = "MAS";
328 else
329 mle_type = "MIG";
330
331 out += stringify_lockname(name, namelen, buf + out, len - out);
332 out += snprintf(buf + out, len - out,
333 "\t%3s\tmas=%3u\tnew=%3u\tevt=%1d\tuse=%1d\tref=%3d\n",
334 mle_type, mle->master, mle->new_master,
335 !list_empty(&mle->hb_events),
336 !!mle->inuse,
337 atomic_read(&mle->mle_refs.refcount));
338
339 out += snprintf(buf + out, len - out, "Maybe=");
340 out += stringify_nodemap(mle->maybe_map, O2NM_MAX_NODES,
341 buf + out, len - out);
342 out += snprintf(buf + out, len - out, "\n");
343
344 out += snprintf(buf + out, len - out, "Vote=");
345 out += stringify_nodemap(mle->vote_map, O2NM_MAX_NODES,
346 buf + out, len - out);
347 out += snprintf(buf + out, len - out, "\n");
348
349 out += snprintf(buf + out, len - out, "Response=");
350 out += stringify_nodemap(mle->response_map, O2NM_MAX_NODES,
351 buf + out, len - out);
352 out += snprintf(buf + out, len - out, "\n");
353
354 out += snprintf(buf + out, len - out, "Node=");
355 out += stringify_nodemap(mle->node_map, O2NM_MAX_NODES,
356 buf + out, len - out);
357 out += snprintf(buf + out, len - out, "\n");
358
359 out += snprintf(buf + out, len - out, "\n");
360
361 return out;
362}
363
364void dlm_print_one_mle(struct dlm_master_list_entry *mle)
365{
366 char *buf;
367
368 buf = (char *) get_zeroed_page(GFP_NOFS);
369 if (buf) {
370 dump_mle(mle, buf, PAGE_SIZE - 1);
371 free_page((unsigned long)buf);
372 }
373}
374
375#ifdef CONFIG_DEBUG_FS
376
377static struct dentry *dlm_debugfs_root = NULL;
378
Sunil Mushran6325b4a2008-03-10 15:16:22 -0700379#define DLM_DEBUGFS_DIR "o2dlm"
Sunil Mushran007dce52008-03-10 15:16:23 -0700380#define DLM_DEBUGFS_DLM_STATE "dlm_state"
Sunil Mushran4e3d24e2008-03-10 15:16:24 -0700381#define DLM_DEBUGFS_LOCKING_STATE "locking_state"
Sunil Mushrand0129ac2008-03-10 15:16:26 -0700382#define DLM_DEBUGFS_MLE_STATE "mle_state"
Sunil Mushran72093002008-03-10 15:16:27 -0700383#define DLM_DEBUGFS_PURGE_LIST "purge_list"
Sunil Mushran007dce52008-03-10 15:16:23 -0700384
385/* begin - utils funcs */
386static void dlm_debug_free(struct kref *kref)
387{
388 struct dlm_debug_ctxt *dc;
389
390 dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);
391
392 kfree(dc);
393}
394
395void dlm_debug_put(struct dlm_debug_ctxt *dc)
396{
397 if (dc)
398 kref_put(&dc->debug_refcnt, dlm_debug_free);
399}
400
401static void dlm_debug_get(struct dlm_debug_ctxt *dc)
402{
403 kref_get(&dc->debug_refcnt);
404}
405
Sunil Mushran007dce52008-03-10 15:16:23 -0700406static struct debug_buffer *debug_buffer_allocate(void)
407{
408 struct debug_buffer *db = NULL;
409
410 db = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
411 if (!db)
412 goto bail;
413
414 db->len = PAGE_SIZE;
415 db->buf = kmalloc(db->len, GFP_KERNEL);
416 if (!db->buf)
417 goto bail;
418
419 return db;
420bail:
421 kfree(db);
422 return NULL;
423}
424
425static ssize_t debug_buffer_read(struct file *file, char __user *buf,
426 size_t nbytes, loff_t *ppos)
427{
428 struct debug_buffer *db = file->private_data;
429
430 return simple_read_from_buffer(buf, nbytes, ppos, db->buf, db->len);
431}
432
433static loff_t debug_buffer_llseek(struct file *file, loff_t off, int whence)
434{
435 struct debug_buffer *db = file->private_data;
436 loff_t new = -1;
437
438 switch (whence) {
439 case 0:
440 new = off;
441 break;
442 case 1:
443 new = file->f_pos + off;
444 break;
445 }
446
447 if (new < 0 || new > db->len)
448 return -EINVAL;
449
450 return (file->f_pos = new);
451}
452
453static int debug_buffer_release(struct inode *inode, struct file *file)
454{
455 struct debug_buffer *db = (struct debug_buffer *)file->private_data;
456
457 if (db)
458 kfree(db->buf);
459 kfree(db);
460
461 return 0;
462}
463/* end - util funcs */
464
Sunil Mushran72093002008-03-10 15:16:27 -0700465/* begin - purge list funcs */
466static int debug_purgelist_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
467{
468 struct dlm_lock_resource *res;
469 int out = 0;
470 unsigned long total = 0;
471
472 out += snprintf(db->buf + out, db->len - out,
473 "Dumping Purgelist for Domain: %s\n", dlm->name);
474
475 spin_lock(&dlm->spinlock);
476 list_for_each_entry(res, &dlm->purge_list, purge) {
477 ++total;
478 if (db->len - out < 100)
479 continue;
480 spin_lock(&res->spinlock);
481 out += stringify_lockname(res->lockname.name,
482 res->lockname.len,
483 db->buf + out, db->len - out);
484 out += snprintf(db->buf + out, db->len - out, "\t%ld\n",
485 (jiffies - res->last_used)/HZ);
486 spin_unlock(&res->spinlock);
487 }
488 spin_unlock(&dlm->spinlock);
489
490 out += snprintf(db->buf + out, db->len - out,
491 "Total on list: %ld\n", total);
492
493 return out;
494}
495
496static int debug_purgelist_open(struct inode *inode, struct file *file)
497{
498 struct dlm_ctxt *dlm = inode->i_private;
499 struct debug_buffer *db;
500
501 db = debug_buffer_allocate();
502 if (!db)
503 goto bail;
504
505 db->len = debug_purgelist_print(dlm, db);
506
507 file->private_data = db;
508
509 return 0;
510bail:
511 return -ENOMEM;
512}
513
514static struct file_operations debug_purgelist_fops = {
515 .open = debug_purgelist_open,
516 .release = debug_buffer_release,
517 .read = debug_buffer_read,
518 .llseek = debug_buffer_llseek,
519};
520/* end - purge list funcs */
521
Sunil Mushrand0129ac2008-03-10 15:16:26 -0700522/* begin - debug mle funcs */
Sunil Mushrand0129ac2008-03-10 15:16:26 -0700523static int debug_mle_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
524{
525 struct dlm_master_list_entry *mle;
526 int out = 0;
527 unsigned long total = 0;
528
529 out += snprintf(db->buf + out, db->len - out,
530 "Dumping MLEs for Domain: %s\n", dlm->name);
531
532 spin_lock(&dlm->master_lock);
533 list_for_each_entry(mle, &dlm->master_list, list) {
534 ++total;
535 if (db->len - out < 200)
536 continue;
537 out += dump_mle(mle, db->buf + out, db->len - out);
538 }
539 spin_unlock(&dlm->master_lock);
540
541 out += snprintf(db->buf + out, db->len - out,
542 "Total on list: %ld\n", total);
543 return out;
544}
545
546static int debug_mle_open(struct inode *inode, struct file *file)
547{
548 struct dlm_ctxt *dlm = inode->i_private;
549 struct debug_buffer *db;
550
551 db = debug_buffer_allocate();
552 if (!db)
553 goto bail;
554
555 db->len = debug_mle_print(dlm, db);
556
557 file->private_data = db;
558
559 return 0;
560bail:
561 return -ENOMEM;
562}
563
564static struct file_operations debug_mle_fops = {
565 .open = debug_mle_open,
566 .release = debug_buffer_release,
567 .read = debug_buffer_read,
568 .llseek = debug_buffer_llseek,
569};
570
571/* end - debug mle funcs */
572
Sunil Mushran4e3d24e2008-03-10 15:16:24 -0700573/* begin - debug lockres funcs */
574static int dump_lock(struct dlm_lock *lock, int list_type, char *buf, int len)
575{
576 int out;
577
578#define DEBUG_LOCK_VERSION 1
579 spin_lock(&lock->spinlock);
580 out = snprintf(buf, len, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
581 "%d,%d,%d,%d\n",
582 DEBUG_LOCK_VERSION,
583 list_type, lock->ml.type, lock->ml.convert_type,
584 lock->ml.node,
585 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
586 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
587 !list_empty(&lock->ast_list),
588 !list_empty(&lock->bast_list),
589 lock->ast_pending, lock->bast_pending,
590 lock->convert_pending, lock->lock_pending,
591 lock->cancel_pending, lock->unlock_pending,
592 atomic_read(&lock->lock_refs.refcount));
593 spin_unlock(&lock->spinlock);
594
595 return out;
596}
597
598static int dump_lockres(struct dlm_lock_resource *res, char *buf, int len)
599{
600 struct dlm_lock *lock;
601 int i;
602 int out = 0;
603
604 out += snprintf(buf + out, len - out, "NAME:");
605 out += stringify_lockname(res->lockname.name, res->lockname.len,
606 buf + out, len - out);
607 out += snprintf(buf + out, len - out, "\n");
608
609#define DEBUG_LRES_VERSION 1
610 out += snprintf(buf + out, len - out,
611 "LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
612 DEBUG_LRES_VERSION,
613 res->owner, res->state, res->last_used,
614 !list_empty(&res->purge),
615 !list_empty(&res->dirty),
616 !list_empty(&res->recovering),
617 res->inflight_locks, res->migration_pending,
618 atomic_read(&res->asts_reserved),
619 atomic_read(&res->refs.refcount));
620
621 /* refmap */
622 out += snprintf(buf + out, len - out, "RMAP:");
623 out += stringify_nodemap(res->refmap, O2NM_MAX_NODES,
624 buf + out, len - out);
625 out += snprintf(buf + out, len - out, "\n");
626
627 /* lvb */
628 out += snprintf(buf + out, len - out, "LVBX:");
629 for (i = 0; i < DLM_LVB_LEN; i++)
630 out += snprintf(buf + out, len - out,
631 "%02x", (unsigned char)res->lvb[i]);
632 out += snprintf(buf + out, len - out, "\n");
633
634 /* granted */
635 list_for_each_entry(lock, &res->granted, list)
636 out += dump_lock(lock, 0, buf + out, len - out);
637
638 /* converting */
639 list_for_each_entry(lock, &res->converting, list)
640 out += dump_lock(lock, 1, buf + out, len - out);
641
642 /* blocked */
643 list_for_each_entry(lock, &res->blocked, list)
644 out += dump_lock(lock, 2, buf + out, len - out);
645
646 out += snprintf(buf + out, len - out, "\n");
647
648 return out;
649}
650
651static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
652{
653 struct debug_lockres *dl = m->private;
654 struct dlm_ctxt *dlm = dl->dl_ctxt;
655 struct dlm_lock_resource *res = NULL;
656
657 spin_lock(&dlm->spinlock);
658
659 if (dl->dl_res) {
660 list_for_each_entry(res, &dl->dl_res->tracking, tracking) {
661 if (dl->dl_res) {
662 dlm_lockres_put(dl->dl_res);
663 dl->dl_res = NULL;
664 }
665 if (&res->tracking == &dlm->tracking_list) {
666 mlog(0, "End of list found, %p\n", res);
667 dl = NULL;
668 break;
669 }
670 dlm_lockres_get(res);
671 dl->dl_res = res;
672 break;
673 }
674 } else {
675 if (!list_empty(&dlm->tracking_list)) {
676 list_for_each_entry(res, &dlm->tracking_list, tracking)
677 break;
678 dlm_lockres_get(res);
679 dl->dl_res = res;
680 } else
681 dl = NULL;
682 }
683
684 if (dl) {
685 spin_lock(&dl->dl_res->spinlock);
686 dump_lockres(dl->dl_res, dl->dl_buf, dl->dl_len - 1);
687 spin_unlock(&dl->dl_res->spinlock);
688 }
689
690 spin_unlock(&dlm->spinlock);
691
692 return dl;
693}
694
695static void lockres_seq_stop(struct seq_file *m, void *v)
696{
697}
698
699static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
700{
701 return NULL;
702}
703
704static int lockres_seq_show(struct seq_file *s, void *v)
705{
706 struct debug_lockres *dl = (struct debug_lockres *)v;
707
708 seq_printf(s, "%s", dl->dl_buf);
709
710 return 0;
711}
712
713static struct seq_operations debug_lockres_ops = {
714 .start = lockres_seq_start,
715 .stop = lockres_seq_stop,
716 .next = lockres_seq_next,
717 .show = lockres_seq_show,
718};
719
720static int debug_lockres_open(struct inode *inode, struct file *file)
721{
722 struct dlm_ctxt *dlm = inode->i_private;
723 int ret = -ENOMEM;
724 struct seq_file *seq;
725 struct debug_lockres *dl = NULL;
726
727 dl = kzalloc(sizeof(struct debug_lockres), GFP_KERNEL);
728 if (!dl) {
729 mlog_errno(ret);
730 goto bail;
731 }
732
733 dl->dl_len = PAGE_SIZE;
734 dl->dl_buf = kmalloc(dl->dl_len, GFP_KERNEL);
735 if (!dl->dl_buf) {
736 mlog_errno(ret);
737 goto bail;
738 }
739
740 ret = seq_open(file, &debug_lockres_ops);
741 if (ret) {
742 mlog_errno(ret);
743 goto bail;
744 }
745
746 seq = (struct seq_file *) file->private_data;
747 seq->private = dl;
748
749 dlm_grab(dlm);
750 dl->dl_ctxt = dlm;
751
752 return 0;
753bail:
754 if (dl)
755 kfree(dl->dl_buf);
756 kfree(dl);
757 return ret;
758}
759
760static int debug_lockres_release(struct inode *inode, struct file *file)
761{
762 struct seq_file *seq = (struct seq_file *)file->private_data;
763 struct debug_lockres *dl = (struct debug_lockres *)seq->private;
764
765 if (dl->dl_res)
766 dlm_lockres_put(dl->dl_res);
767 dlm_put(dl->dl_ctxt);
768 kfree(dl->dl_buf);
769 return seq_release_private(inode, file);
770}
771
772static struct file_operations debug_lockres_fops = {
773 .open = debug_lockres_open,
774 .release = debug_lockres_release,
775 .read = seq_read,
776 .llseek = seq_lseek,
777};
778/* end - debug lockres funcs */
779
Sunil Mushran007dce52008-03-10 15:16:23 -0700780/* begin - debug state funcs */
781static int debug_state_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
782{
783 int out = 0;
784 struct dlm_reco_node_data *node;
785 char *state;
786 int lres, rres, ures, tres;
787
788 lres = atomic_read(&dlm->local_resources);
789 rres = atomic_read(&dlm->remote_resources);
790 ures = atomic_read(&dlm->unknown_resources);
791 tres = lres + rres + ures;
792
793 spin_lock(&dlm->spinlock);
794
795 switch (dlm->dlm_state) {
796 case DLM_CTXT_NEW:
797 state = "NEW"; break;
798 case DLM_CTXT_JOINED:
799 state = "JOINED"; break;
800 case DLM_CTXT_IN_SHUTDOWN:
801 state = "SHUTDOWN"; break;
802 case DLM_CTXT_LEAVING:
803 state = "LEAVING"; break;
804 default:
805 state = "UNKNOWN"; break;
806 }
807
808 /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
809 out += snprintf(db->buf + out, db->len - out,
810 "Domain: %s Key: 0x%08x\n", dlm->name, dlm->key);
811
812 /* Thread Pid: xxx Node: xxx State: xxxxx */
813 out += snprintf(db->buf + out, db->len - out,
814 "Thread Pid: %d Node: %d State: %s\n",
815 dlm->dlm_thread_task->pid, dlm->node_num, state);
816
817 /* Number of Joins: xxx Joining Node: xxx */
818 out += snprintf(db->buf + out, db->len - out,
819 "Number of Joins: %d Joining Node: %d\n",
820 dlm->num_joins, dlm->joining_node);
821
822 /* Domain Map: xx xx xx */
823 out += snprintf(db->buf + out, db->len - out, "Domain Map: ");
824 out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
825 db->buf + out, db->len - out);
826 out += snprintf(db->buf + out, db->len - out, "\n");
827
828 /* Live Map: xx xx xx */
829 out += snprintf(db->buf + out, db->len - out, "Live Map: ");
830 out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
831 db->buf + out, db->len - out);
832 out += snprintf(db->buf + out, db->len - out, "\n");
833
834 /* Mastered Resources Total: xxx Locally: xxx Remotely: ... */
835 out += snprintf(db->buf + out, db->len - out,
836 "Mastered Resources Total: %d Locally: %d "
837 "Remotely: %d Unknown: %d\n",
838 tres, lres, rres, ures);
839
840 /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
841 out += snprintf(db->buf + out, db->len - out,
842 "Lists: Dirty=%s Purge=%s PendingASTs=%s "
843 "PendingBASTs=%s Master=%s\n",
844 (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
845 (list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
846 (list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
847 (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"),
848 (list_empty(&dlm->master_list) ? "Empty" : "InUse"));
849
850 /* Purge Count: xxx Refs: xxx */
851 out += snprintf(db->buf + out, db->len - out,
852 "Purge Count: %d Refs: %d\n", dlm->purge_count,
853 atomic_read(&dlm->dlm_refs.refcount));
854
855 /* Dead Node: xxx */
856 out += snprintf(db->buf + out, db->len - out,
857 "Dead Node: %d\n", dlm->reco.dead_node);
858
859 /* What about DLM_RECO_STATE_FINALIZE? */
860 if (dlm->reco.state == DLM_RECO_STATE_ACTIVE)
861 state = "ACTIVE";
862 else
863 state = "INACTIVE";
864
865 /* Recovery Pid: xxxx Master: xxx State: xxxx */
866 out += snprintf(db->buf + out, db->len - out,
867 "Recovery Pid: %d Master: %d State: %s\n",
868 dlm->dlm_reco_thread_task->pid,
869 dlm->reco.new_master, state);
870
871 /* Recovery Map: xx xx */
872 out += snprintf(db->buf + out, db->len - out, "Recovery Map: ");
873 out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
874 db->buf + out, db->len - out);
875 out += snprintf(db->buf + out, db->len - out, "\n");
876
877 /* Recovery Node State: */
878 out += snprintf(db->buf + out, db->len - out, "Recovery Node State:\n");
879 list_for_each_entry(node, &dlm->reco.node_data, list) {
880 switch (node->state) {
881 case DLM_RECO_NODE_DATA_INIT:
882 state = "INIT";
883 break;
884 case DLM_RECO_NODE_DATA_REQUESTING:
885 state = "REQUESTING";
886 break;
887 case DLM_RECO_NODE_DATA_DEAD:
888 state = "DEAD";
889 break;
890 case DLM_RECO_NODE_DATA_RECEIVING:
891 state = "RECEIVING";
892 break;
893 case DLM_RECO_NODE_DATA_REQUESTED:
894 state = "REQUESTED";
895 break;
896 case DLM_RECO_NODE_DATA_DONE:
897 state = "DONE";
898 break;
899 case DLM_RECO_NODE_DATA_FINALIZE_SENT:
900 state = "FINALIZE-SENT";
901 break;
902 default:
903 state = "BAD";
904 break;
905 }
906 out += snprintf(db->buf + out, db->len - out, "\t%u - %s\n",
907 node->node_num, state);
908 }
909
910 spin_unlock(&dlm->spinlock);
911
912 return out;
913}
914
915static int debug_state_open(struct inode *inode, struct file *file)
916{
917 struct dlm_ctxt *dlm = inode->i_private;
918 struct debug_buffer *db = NULL;
919
920 db = debug_buffer_allocate();
921 if (!db)
922 goto bail;
923
924 db->len = debug_state_print(dlm, db);
925
926 file->private_data = db;
927
928 return 0;
929bail:
930 return -ENOMEM;
931}
932
933static struct file_operations debug_state_fops = {
934 .open = debug_state_open,
935 .release = debug_buffer_release,
936 .read = debug_buffer_read,
937 .llseek = debug_buffer_llseek,
938};
939/* end - debug state funcs */
940
941/* files in subroot */
942int dlm_debug_init(struct dlm_ctxt *dlm)
943{
944 struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
945
946 /* for dumping dlm_ctxt */
947 dc->debug_state_dentry = debugfs_create_file(DLM_DEBUGFS_DLM_STATE,
948 S_IFREG|S_IRUSR,
949 dlm->dlm_debugfs_subroot,
950 dlm, &debug_state_fops);
951 if (!dc->debug_state_dentry) {
952 mlog_errno(-ENOMEM);
953 goto bail;
954 }
955
Sunil Mushran4e3d24e2008-03-10 15:16:24 -0700956 /* for dumping lockres */
957 dc->debug_lockres_dentry =
958 debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE,
959 S_IFREG|S_IRUSR,
960 dlm->dlm_debugfs_subroot,
961 dlm, &debug_lockres_fops);
962 if (!dc->debug_lockres_dentry) {
963 mlog_errno(-ENOMEM);
964 goto bail;
965 }
966
Sunil Mushrand0129ac2008-03-10 15:16:26 -0700967 /* for dumping mles */
968 dc->debug_mle_dentry = debugfs_create_file(DLM_DEBUGFS_MLE_STATE,
969 S_IFREG|S_IRUSR,
970 dlm->dlm_debugfs_subroot,
971 dlm, &debug_mle_fops);
972 if (!dc->debug_mle_dentry) {
973 mlog_errno(-ENOMEM);
974 goto bail;
975 }
976
Sunil Mushran72093002008-03-10 15:16:27 -0700977 /* for dumping lockres on the purge list */
978 dc->debug_purgelist_dentry =
979 debugfs_create_file(DLM_DEBUGFS_PURGE_LIST,
980 S_IFREG|S_IRUSR,
981 dlm->dlm_debugfs_subroot,
982 dlm, &debug_purgelist_fops);
983 if (!dc->debug_purgelist_dentry) {
984 mlog_errno(-ENOMEM);
985 goto bail;
986 }
987
Sunil Mushran007dce52008-03-10 15:16:23 -0700988 dlm_debug_get(dc);
989 return 0;
990
991bail:
992 dlm_debug_shutdown(dlm);
993 return -ENOMEM;
994}
995
996void dlm_debug_shutdown(struct dlm_ctxt *dlm)
997{
998 struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
999
1000 if (dc) {
Sunil Mushran72093002008-03-10 15:16:27 -07001001 if (dc->debug_purgelist_dentry)
1002 debugfs_remove(dc->debug_purgelist_dentry);
Sunil Mushrand0129ac2008-03-10 15:16:26 -07001003 if (dc->debug_mle_dentry)
1004 debugfs_remove(dc->debug_mle_dentry);
Sunil Mushran4e3d24e2008-03-10 15:16:24 -07001005 if (dc->debug_lockres_dentry)
1006 debugfs_remove(dc->debug_lockres_dentry);
Sunil Mushran007dce52008-03-10 15:16:23 -07001007 if (dc->debug_state_dentry)
1008 debugfs_remove(dc->debug_state_dentry);
1009 dlm_debug_put(dc);
1010 }
1011}
Sunil Mushran6325b4a2008-03-10 15:16:22 -07001012
1013/* subroot - domain dir */
1014int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
1015{
1016 dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
1017 dlm_debugfs_root);
1018 if (!dlm->dlm_debugfs_subroot) {
1019 mlog_errno(-ENOMEM);
1020 goto bail;
1021 }
1022
Sunil Mushran007dce52008-03-10 15:16:23 -07001023 dlm->dlm_debug_ctxt = kzalloc(sizeof(struct dlm_debug_ctxt),
1024 GFP_KERNEL);
1025 if (!dlm->dlm_debug_ctxt) {
1026 mlog_errno(-ENOMEM);
1027 goto bail;
1028 }
1029 kref_init(&dlm->dlm_debug_ctxt->debug_refcnt);
1030
Sunil Mushran6325b4a2008-03-10 15:16:22 -07001031 return 0;
1032bail:
1033 dlm_destroy_debugfs_subroot(dlm);
1034 return -ENOMEM;
1035}
1036
1037void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
1038{
1039 if (dlm->dlm_debugfs_subroot)
1040 debugfs_remove(dlm->dlm_debugfs_subroot);
1041}
1042
1043/* debugfs root */
1044int dlm_create_debugfs_root(void)
1045{
1046 dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
1047 if (!dlm_debugfs_root) {
1048 mlog_errno(-ENOMEM);
1049 return -ENOMEM;
1050 }
1051 return 0;
1052}
1053
1054void dlm_destroy_debugfs_root(void)
1055{
1056 if (dlm_debugfs_root)
1057 debugfs_remove(dlm_debugfs_root);
1058}
1059#endif /* CONFIG_DEBUG_FS */