Linux Audio

Check our new training course

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