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