dlmdebug.c 27 KB

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