dlmdebug.c 28 KB

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