blob: e335403800134f311a00409c0d63fb9c77e7aa31 [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
271
272#ifdef CONFIG_DEBUG_FS
273
274static struct dentry *dlm_debugfs_root = NULL;
275
276#define DLM_DEBUGFS_DIR "o2dlm"
Sunil Mushran007dce52008-03-10 15:16:23 -0700277#define DLM_DEBUGFS_DLM_STATE "dlm_state"
278
279/* begin - utils funcs */
280static void dlm_debug_free(struct kref *kref)
281{
282 struct dlm_debug_ctxt *dc;
283
284 dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);
285
286 kfree(dc);
287}
288
289void dlm_debug_put(struct dlm_debug_ctxt *dc)
290{
291 if (dc)
292 kref_put(&dc->debug_refcnt, dlm_debug_free);
293}
294
295static void dlm_debug_get(struct dlm_debug_ctxt *dc)
296{
297 kref_get(&dc->debug_refcnt);
298}
299
300static int stringify_nodemap(unsigned long *nodemap, int maxnodes,
301 char *buf, int len)
302{
303 int out = 0;
304 int i = -1;
305
306 while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)
307 out += snprintf(buf + out, len - out, "%d ", i);
308
309 return out;
310}
311
312static struct debug_buffer *debug_buffer_allocate(void)
313{
314 struct debug_buffer *db = NULL;
315
316 db = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
317 if (!db)
318 goto bail;
319
320 db->len = PAGE_SIZE;
321 db->buf = kmalloc(db->len, GFP_KERNEL);
322 if (!db->buf)
323 goto bail;
324
325 return db;
326bail:
327 kfree(db);
328 return NULL;
329}
330
331static ssize_t debug_buffer_read(struct file *file, char __user *buf,
332 size_t nbytes, loff_t *ppos)
333{
334 struct debug_buffer *db = file->private_data;
335
336 return simple_read_from_buffer(buf, nbytes, ppos, db->buf, db->len);
337}
338
339static loff_t debug_buffer_llseek(struct file *file, loff_t off, int whence)
340{
341 struct debug_buffer *db = file->private_data;
342 loff_t new = -1;
343
344 switch (whence) {
345 case 0:
346 new = off;
347 break;
348 case 1:
349 new = file->f_pos + off;
350 break;
351 }
352
353 if (new < 0 || new > db->len)
354 return -EINVAL;
355
356 return (file->f_pos = new);
357}
358
359static int debug_buffer_release(struct inode *inode, struct file *file)
360{
361 struct debug_buffer *db = (struct debug_buffer *)file->private_data;
362
363 if (db)
364 kfree(db->buf);
365 kfree(db);
366
367 return 0;
368}
369/* end - util funcs */
370
371/* begin - debug state funcs */
372static int debug_state_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
373{
374 int out = 0;
375 struct dlm_reco_node_data *node;
376 char *state;
377 int lres, rres, ures, tres;
378
379 lres = atomic_read(&dlm->local_resources);
380 rres = atomic_read(&dlm->remote_resources);
381 ures = atomic_read(&dlm->unknown_resources);
382 tres = lres + rres + ures;
383
384 spin_lock(&dlm->spinlock);
385
386 switch (dlm->dlm_state) {
387 case DLM_CTXT_NEW:
388 state = "NEW"; break;
389 case DLM_CTXT_JOINED:
390 state = "JOINED"; break;
391 case DLM_CTXT_IN_SHUTDOWN:
392 state = "SHUTDOWN"; break;
393 case DLM_CTXT_LEAVING:
394 state = "LEAVING"; break;
395 default:
396 state = "UNKNOWN"; break;
397 }
398
399 /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
400 out += snprintf(db->buf + out, db->len - out,
401 "Domain: %s Key: 0x%08x\n", dlm->name, dlm->key);
402
403 /* Thread Pid: xxx Node: xxx State: xxxxx */
404 out += snprintf(db->buf + out, db->len - out,
405 "Thread Pid: %d Node: %d State: %s\n",
406 dlm->dlm_thread_task->pid, dlm->node_num, state);
407
408 /* Number of Joins: xxx Joining Node: xxx */
409 out += snprintf(db->buf + out, db->len - out,
410 "Number of Joins: %d Joining Node: %d\n",
411 dlm->num_joins, dlm->joining_node);
412
413 /* Domain Map: xx xx xx */
414 out += snprintf(db->buf + out, db->len - out, "Domain Map: ");
415 out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
416 db->buf + out, db->len - out);
417 out += snprintf(db->buf + out, db->len - out, "\n");
418
419 /* Live Map: xx xx xx */
420 out += snprintf(db->buf + out, db->len - out, "Live Map: ");
421 out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
422 db->buf + out, db->len - out);
423 out += snprintf(db->buf + out, db->len - out, "\n");
424
425 /* Mastered Resources Total: xxx Locally: xxx Remotely: ... */
426 out += snprintf(db->buf + out, db->len - out,
427 "Mastered Resources Total: %d Locally: %d "
428 "Remotely: %d Unknown: %d\n",
429 tres, lres, rres, ures);
430
431 /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
432 out += snprintf(db->buf + out, db->len - out,
433 "Lists: Dirty=%s Purge=%s PendingASTs=%s "
434 "PendingBASTs=%s Master=%s\n",
435 (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
436 (list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
437 (list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
438 (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"),
439 (list_empty(&dlm->master_list) ? "Empty" : "InUse"));
440
441 /* Purge Count: xxx Refs: xxx */
442 out += snprintf(db->buf + out, db->len - out,
443 "Purge Count: %d Refs: %d\n", dlm->purge_count,
444 atomic_read(&dlm->dlm_refs.refcount));
445
446 /* Dead Node: xxx */
447 out += snprintf(db->buf + out, db->len - out,
448 "Dead Node: %d\n", dlm->reco.dead_node);
449
450 /* What about DLM_RECO_STATE_FINALIZE? */
451 if (dlm->reco.state == DLM_RECO_STATE_ACTIVE)
452 state = "ACTIVE";
453 else
454 state = "INACTIVE";
455
456 /* Recovery Pid: xxxx Master: xxx State: xxxx */
457 out += snprintf(db->buf + out, db->len - out,
458 "Recovery Pid: %d Master: %d State: %s\n",
459 dlm->dlm_reco_thread_task->pid,
460 dlm->reco.new_master, state);
461
462 /* Recovery Map: xx xx */
463 out += snprintf(db->buf + out, db->len - out, "Recovery Map: ");
464 out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
465 db->buf + out, db->len - out);
466 out += snprintf(db->buf + out, db->len - out, "\n");
467
468 /* Recovery Node State: */
469 out += snprintf(db->buf + out, db->len - out, "Recovery Node State:\n");
470 list_for_each_entry(node, &dlm->reco.node_data, list) {
471 switch (node->state) {
472 case DLM_RECO_NODE_DATA_INIT:
473 state = "INIT";
474 break;
475 case DLM_RECO_NODE_DATA_REQUESTING:
476 state = "REQUESTING";
477 break;
478 case DLM_RECO_NODE_DATA_DEAD:
479 state = "DEAD";
480 break;
481 case DLM_RECO_NODE_DATA_RECEIVING:
482 state = "RECEIVING";
483 break;
484 case DLM_RECO_NODE_DATA_REQUESTED:
485 state = "REQUESTED";
486 break;
487 case DLM_RECO_NODE_DATA_DONE:
488 state = "DONE";
489 break;
490 case DLM_RECO_NODE_DATA_FINALIZE_SENT:
491 state = "FINALIZE-SENT";
492 break;
493 default:
494 state = "BAD";
495 break;
496 }
497 out += snprintf(db->buf + out, db->len - out, "\t%u - %s\n",
498 node->node_num, state);
499 }
500
501 spin_unlock(&dlm->spinlock);
502
503 return out;
504}
505
506static int debug_state_open(struct inode *inode, struct file *file)
507{
508 struct dlm_ctxt *dlm = inode->i_private;
509 struct debug_buffer *db = NULL;
510
511 db = debug_buffer_allocate();
512 if (!db)
513 goto bail;
514
515 db->len = debug_state_print(dlm, db);
516
517 file->private_data = db;
518
519 return 0;
520bail:
521 return -ENOMEM;
522}
523
524static struct file_operations debug_state_fops = {
525 .open = debug_state_open,
526 .release = debug_buffer_release,
527 .read = debug_buffer_read,
528 .llseek = debug_buffer_llseek,
529};
530/* end - debug state funcs */
531
532/* files in subroot */
533int dlm_debug_init(struct dlm_ctxt *dlm)
534{
535 struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
536
537 /* for dumping dlm_ctxt */
538 dc->debug_state_dentry = debugfs_create_file(DLM_DEBUGFS_DLM_STATE,
539 S_IFREG|S_IRUSR,
540 dlm->dlm_debugfs_subroot,
541 dlm, &debug_state_fops);
542 if (!dc->debug_state_dentry) {
543 mlog_errno(-ENOMEM);
544 goto bail;
545 }
546
547 dlm_debug_get(dc);
548 return 0;
549
550bail:
551 dlm_debug_shutdown(dlm);
552 return -ENOMEM;
553}
554
555void dlm_debug_shutdown(struct dlm_ctxt *dlm)
556{
557 struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
558
559 if (dc) {
560 if (dc->debug_state_dentry)
561 debugfs_remove(dc->debug_state_dentry);
562 dlm_debug_put(dc);
563 }
564}
Sunil Mushran6325b4a2008-03-10 15:16:22 -0700565
566/* subroot - domain dir */
567int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
568{
569 dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
570 dlm_debugfs_root);
571 if (!dlm->dlm_debugfs_subroot) {
572 mlog_errno(-ENOMEM);
573 goto bail;
574 }
575
Sunil Mushran007dce52008-03-10 15:16:23 -0700576 dlm->dlm_debug_ctxt = kzalloc(sizeof(struct dlm_debug_ctxt),
577 GFP_KERNEL);
578 if (!dlm->dlm_debug_ctxt) {
579 mlog_errno(-ENOMEM);
580 goto bail;
581 }
582 kref_init(&dlm->dlm_debug_ctxt->debug_refcnt);
583
Sunil Mushran6325b4a2008-03-10 15:16:22 -0700584 return 0;
585bail:
586 dlm_destroy_debugfs_subroot(dlm);
587 return -ENOMEM;
588}
589
590void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
591{
592 if (dlm->dlm_debugfs_subroot)
593 debugfs_remove(dlm->dlm_debugfs_subroot);
594}
595
596/* debugfs root */
597int dlm_create_debugfs_root(void)
598{
599 dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
600 if (!dlm_debugfs_root) {
601 mlog_errno(-ENOMEM);
602 return -ENOMEM;
603 }
604 return 0;
605}
606
607void dlm_destroy_debugfs_root(void)
608{
609 if (dlm_debugfs_root)
610 debugfs_remove(dlm_debugfs_root);
611}
612#endif /* CONFIG_DEBUG_FS */