dlmdebug.c 27 KB

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