dlmdebug.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  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. #ifdef CONFIG_DEBUG_FS
  253. static struct dentry *dlm_debugfs_root = NULL;
  254. /* NOTE: This function converts a lockname into a string. It uses knowledge
  255. * of the format of the lockname that should be outside the purview of the dlm.
  256. * We are adding only to make dlm debugging slightly easier.
  257. *
  258. * For more on lockname formats, please refer to dlmglue.c and ocfs2_lockid.h.
  259. */
  260. static int stringify_lockname(const char *lockname, int locklen,
  261. char *buf, int len)
  262. {
  263. int out = 0;
  264. __be64 inode_blkno_be;
  265. #define OCFS2_DENTRY_LOCK_INO_START 18
  266. if (*lockname == 'N') {
  267. memcpy((__be64 *)&inode_blkno_be,
  268. (char *)&lockname[OCFS2_DENTRY_LOCK_INO_START],
  269. sizeof(__be64));
  270. out += snprintf(buf + out, len - out, "%.*s%08x",
  271. OCFS2_DENTRY_LOCK_INO_START - 1, lockname,
  272. (unsigned int)be64_to_cpu(inode_blkno_be));
  273. } else
  274. out += snprintf(buf + out, len - out, "%.*s",
  275. locklen, lockname);
  276. return out;
  277. }
  278. #define DLM_DEBUGFS_DIR "o2dlm"
  279. #define DLM_DEBUGFS_DLM_STATE "dlm_state"
  280. #define DLM_DEBUGFS_LOCKING_STATE "locking_state"
  281. #define DLM_DEBUGFS_MLE_STATE "mle_state"
  282. /* begin - utils funcs */
  283. static void dlm_debug_free(struct kref *kref)
  284. {
  285. struct dlm_debug_ctxt *dc;
  286. dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);
  287. kfree(dc);
  288. }
  289. void dlm_debug_put(struct dlm_debug_ctxt *dc)
  290. {
  291. if (dc)
  292. kref_put(&dc->debug_refcnt, dlm_debug_free);
  293. }
  294. static void dlm_debug_get(struct dlm_debug_ctxt *dc)
  295. {
  296. kref_get(&dc->debug_refcnt);
  297. }
  298. static int stringify_nodemap(unsigned long *nodemap, int maxnodes,
  299. char *buf, int len)
  300. {
  301. int out = 0;
  302. int i = -1;
  303. while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)
  304. out += snprintf(buf + out, len - out, "%d ", i);
  305. return out;
  306. }
  307. static struct debug_buffer *debug_buffer_allocate(void)
  308. {
  309. struct debug_buffer *db = NULL;
  310. db = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
  311. if (!db)
  312. goto bail;
  313. db->len = PAGE_SIZE;
  314. db->buf = kmalloc(db->len, GFP_KERNEL);
  315. if (!db->buf)
  316. goto bail;
  317. return db;
  318. bail:
  319. kfree(db);
  320. return NULL;
  321. }
  322. static ssize_t debug_buffer_read(struct file *file, char __user *buf,
  323. size_t nbytes, loff_t *ppos)
  324. {
  325. struct debug_buffer *db = file->private_data;
  326. return simple_read_from_buffer(buf, nbytes, ppos, db->buf, db->len);
  327. }
  328. static loff_t debug_buffer_llseek(struct file *file, loff_t off, int whence)
  329. {
  330. struct debug_buffer *db = file->private_data;
  331. loff_t new = -1;
  332. switch (whence) {
  333. case 0:
  334. new = off;
  335. break;
  336. case 1:
  337. new = file->f_pos + off;
  338. break;
  339. }
  340. if (new < 0 || new > db->len)
  341. return -EINVAL;
  342. return (file->f_pos = new);
  343. }
  344. static int debug_buffer_release(struct inode *inode, struct file *file)
  345. {
  346. struct debug_buffer *db = (struct debug_buffer *)file->private_data;
  347. if (db)
  348. kfree(db->buf);
  349. kfree(db);
  350. return 0;
  351. }
  352. /* end - util funcs */
  353. /* begin - debug mle funcs */
  354. static int dump_mle(struct dlm_master_list_entry *mle, char *buf, int len)
  355. {
  356. int out = 0;
  357. unsigned int namelen;
  358. const char *name;
  359. char *mle_type;
  360. if (mle->type != DLM_MLE_MASTER) {
  361. namelen = mle->u.name.len;
  362. name = mle->u.name.name;
  363. } else {
  364. namelen = mle->u.res->lockname.len;
  365. name = mle->u.res->lockname.name;
  366. }
  367. if (mle->type == DLM_MLE_BLOCK)
  368. mle_type = "BLK";
  369. else if (mle->type == DLM_MLE_MASTER)
  370. mle_type = "MAS";
  371. else
  372. mle_type = "MIG";
  373. out += stringify_lockname(name, namelen, buf + out, len - out);
  374. out += snprintf(buf + out, len - out,
  375. "\t%3s\tmas=%3u\tnew=%3u\tevt=%1d\tuse=%1d\tref=%3d\n",
  376. mle_type, mle->master, mle->new_master,
  377. !list_empty(&mle->hb_events),
  378. !!mle->inuse,
  379. atomic_read(&mle->mle_refs.refcount));
  380. out += snprintf(buf + out, len - out, "Maybe=");
  381. out += stringify_nodemap(mle->maybe_map, O2NM_MAX_NODES,
  382. buf + out, len - out);
  383. out += snprintf(buf + out, len - out, "\n");
  384. out += snprintf(buf + out, len - out, "Vote=");
  385. out += stringify_nodemap(mle->vote_map, O2NM_MAX_NODES,
  386. buf + out, len - out);
  387. out += snprintf(buf + out, len - out, "\n");
  388. out += snprintf(buf + out, len - out, "Response=");
  389. out += stringify_nodemap(mle->response_map, O2NM_MAX_NODES,
  390. buf + out, len - out);
  391. out += snprintf(buf + out, len - out, "\n");
  392. out += snprintf(buf + out, len - out, "Node=");
  393. out += stringify_nodemap(mle->node_map, O2NM_MAX_NODES,
  394. buf + out, len - out);
  395. out += snprintf(buf + out, len - out, "\n");
  396. out += snprintf(buf + out, len - out, "\n");
  397. return out;
  398. }
  399. static int debug_mle_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
  400. {
  401. struct dlm_master_list_entry *mle;
  402. int out = 0;
  403. unsigned long total = 0;
  404. out += snprintf(db->buf + out, db->len - out,
  405. "Dumping MLEs for Domain: %s\n", dlm->name);
  406. spin_lock(&dlm->master_lock);
  407. list_for_each_entry(mle, &dlm->master_list, list) {
  408. ++total;
  409. if (db->len - out < 200)
  410. continue;
  411. out += dump_mle(mle, db->buf + out, db->len - out);
  412. }
  413. spin_unlock(&dlm->master_lock);
  414. out += snprintf(db->buf + out, db->len - out,
  415. "Total on list: %ld\n", total);
  416. return out;
  417. }
  418. static int debug_mle_open(struct inode *inode, struct file *file)
  419. {
  420. struct dlm_ctxt *dlm = inode->i_private;
  421. struct debug_buffer *db;
  422. db = debug_buffer_allocate();
  423. if (!db)
  424. goto bail;
  425. db->len = debug_mle_print(dlm, db);
  426. file->private_data = db;
  427. return 0;
  428. bail:
  429. return -ENOMEM;
  430. }
  431. static struct file_operations debug_mle_fops = {
  432. .open = debug_mle_open,
  433. .release = debug_buffer_release,
  434. .read = debug_buffer_read,
  435. .llseek = debug_buffer_llseek,
  436. };
  437. /* end - debug mle funcs */
  438. /* begin - debug lockres funcs */
  439. static int dump_lock(struct dlm_lock *lock, int list_type, char *buf, int len)
  440. {
  441. int out;
  442. #define DEBUG_LOCK_VERSION 1
  443. spin_lock(&lock->spinlock);
  444. out = snprintf(buf, len, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
  445. "%d,%d,%d,%d\n",
  446. DEBUG_LOCK_VERSION,
  447. list_type, lock->ml.type, lock->ml.convert_type,
  448. lock->ml.node,
  449. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  450. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  451. !list_empty(&lock->ast_list),
  452. !list_empty(&lock->bast_list),
  453. lock->ast_pending, lock->bast_pending,
  454. lock->convert_pending, lock->lock_pending,
  455. lock->cancel_pending, lock->unlock_pending,
  456. atomic_read(&lock->lock_refs.refcount));
  457. spin_unlock(&lock->spinlock);
  458. return out;
  459. }
  460. static int dump_lockres(struct dlm_lock_resource *res, char *buf, int len)
  461. {
  462. struct dlm_lock *lock;
  463. int i;
  464. int out = 0;
  465. out += snprintf(buf + out, len - out, "NAME:");
  466. out += stringify_lockname(res->lockname.name, res->lockname.len,
  467. buf + out, len - out);
  468. out += snprintf(buf + out, len - out, "\n");
  469. #define DEBUG_LRES_VERSION 1
  470. out += snprintf(buf + out, len - out,
  471. "LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
  472. DEBUG_LRES_VERSION,
  473. res->owner, res->state, res->last_used,
  474. !list_empty(&res->purge),
  475. !list_empty(&res->dirty),
  476. !list_empty(&res->recovering),
  477. res->inflight_locks, res->migration_pending,
  478. atomic_read(&res->asts_reserved),
  479. atomic_read(&res->refs.refcount));
  480. /* refmap */
  481. out += snprintf(buf + out, len - out, "RMAP:");
  482. out += stringify_nodemap(res->refmap, O2NM_MAX_NODES,
  483. buf + out, len - out);
  484. out += snprintf(buf + out, len - out, "\n");
  485. /* lvb */
  486. out += snprintf(buf + out, len - out, "LVBX:");
  487. for (i = 0; i < DLM_LVB_LEN; i++)
  488. out += snprintf(buf + out, len - out,
  489. "%02x", (unsigned char)res->lvb[i]);
  490. out += snprintf(buf + out, len - out, "\n");
  491. /* granted */
  492. list_for_each_entry(lock, &res->granted, list)
  493. out += dump_lock(lock, 0, buf + out, len - out);
  494. /* converting */
  495. list_for_each_entry(lock, &res->converting, list)
  496. out += dump_lock(lock, 1, buf + out, len - out);
  497. /* blocked */
  498. list_for_each_entry(lock, &res->blocked, list)
  499. out += dump_lock(lock, 2, buf + out, len - out);
  500. out += snprintf(buf + out, len - out, "\n");
  501. return out;
  502. }
  503. static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
  504. {
  505. struct debug_lockres *dl = m->private;
  506. struct dlm_ctxt *dlm = dl->dl_ctxt;
  507. struct dlm_lock_resource *res = NULL;
  508. spin_lock(&dlm->spinlock);
  509. if (dl->dl_res) {
  510. list_for_each_entry(res, &dl->dl_res->tracking, tracking) {
  511. if (dl->dl_res) {
  512. dlm_lockres_put(dl->dl_res);
  513. dl->dl_res = NULL;
  514. }
  515. if (&res->tracking == &dlm->tracking_list) {
  516. mlog(0, "End of list found, %p\n", res);
  517. dl = NULL;
  518. break;
  519. }
  520. dlm_lockres_get(res);
  521. dl->dl_res = res;
  522. break;
  523. }
  524. } else {
  525. if (!list_empty(&dlm->tracking_list)) {
  526. list_for_each_entry(res, &dlm->tracking_list, tracking)
  527. break;
  528. dlm_lockres_get(res);
  529. dl->dl_res = res;
  530. } else
  531. dl = NULL;
  532. }
  533. if (dl) {
  534. spin_lock(&dl->dl_res->spinlock);
  535. dump_lockres(dl->dl_res, dl->dl_buf, dl->dl_len - 1);
  536. spin_unlock(&dl->dl_res->spinlock);
  537. }
  538. spin_unlock(&dlm->spinlock);
  539. return dl;
  540. }
  541. static void lockres_seq_stop(struct seq_file *m, void *v)
  542. {
  543. }
  544. static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
  545. {
  546. return NULL;
  547. }
  548. static int lockres_seq_show(struct seq_file *s, void *v)
  549. {
  550. struct debug_lockres *dl = (struct debug_lockres *)v;
  551. seq_printf(s, "%s", dl->dl_buf);
  552. return 0;
  553. }
  554. static struct seq_operations debug_lockres_ops = {
  555. .start = lockres_seq_start,
  556. .stop = lockres_seq_stop,
  557. .next = lockres_seq_next,
  558. .show = lockres_seq_show,
  559. };
  560. static int debug_lockres_open(struct inode *inode, struct file *file)
  561. {
  562. struct dlm_ctxt *dlm = inode->i_private;
  563. int ret = -ENOMEM;
  564. struct seq_file *seq;
  565. struct debug_lockres *dl = NULL;
  566. dl = kzalloc(sizeof(struct debug_lockres), GFP_KERNEL);
  567. if (!dl) {
  568. mlog_errno(ret);
  569. goto bail;
  570. }
  571. dl->dl_len = PAGE_SIZE;
  572. dl->dl_buf = kmalloc(dl->dl_len, GFP_KERNEL);
  573. if (!dl->dl_buf) {
  574. mlog_errno(ret);
  575. goto bail;
  576. }
  577. ret = seq_open(file, &debug_lockres_ops);
  578. if (ret) {
  579. mlog_errno(ret);
  580. goto bail;
  581. }
  582. seq = (struct seq_file *) file->private_data;
  583. seq->private = dl;
  584. dlm_grab(dlm);
  585. dl->dl_ctxt = dlm;
  586. return 0;
  587. bail:
  588. if (dl)
  589. kfree(dl->dl_buf);
  590. kfree(dl);
  591. return ret;
  592. }
  593. static int debug_lockres_release(struct inode *inode, struct file *file)
  594. {
  595. struct seq_file *seq = (struct seq_file *)file->private_data;
  596. struct debug_lockres *dl = (struct debug_lockres *)seq->private;
  597. if (dl->dl_res)
  598. dlm_lockres_put(dl->dl_res);
  599. dlm_put(dl->dl_ctxt);
  600. kfree(dl->dl_buf);
  601. return seq_release_private(inode, file);
  602. }
  603. static struct file_operations debug_lockres_fops = {
  604. .open = debug_lockres_open,
  605. .release = debug_lockres_release,
  606. .read = seq_read,
  607. .llseek = seq_lseek,
  608. };
  609. /* end - debug lockres funcs */
  610. /* begin - debug state funcs */
  611. static int debug_state_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
  612. {
  613. int out = 0;
  614. struct dlm_reco_node_data *node;
  615. char *state;
  616. int lres, rres, ures, tres;
  617. lres = atomic_read(&dlm->local_resources);
  618. rres = atomic_read(&dlm->remote_resources);
  619. ures = atomic_read(&dlm->unknown_resources);
  620. tres = lres + rres + ures;
  621. spin_lock(&dlm->spinlock);
  622. switch (dlm->dlm_state) {
  623. case DLM_CTXT_NEW:
  624. state = "NEW"; break;
  625. case DLM_CTXT_JOINED:
  626. state = "JOINED"; break;
  627. case DLM_CTXT_IN_SHUTDOWN:
  628. state = "SHUTDOWN"; break;
  629. case DLM_CTXT_LEAVING:
  630. state = "LEAVING"; break;
  631. default:
  632. state = "UNKNOWN"; break;
  633. }
  634. /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
  635. out += snprintf(db->buf + out, db->len - out,
  636. "Domain: %s Key: 0x%08x\n", dlm->name, dlm->key);
  637. /* Thread Pid: xxx Node: xxx State: xxxxx */
  638. out += snprintf(db->buf + out, db->len - out,
  639. "Thread Pid: %d Node: %d State: %s\n",
  640. dlm->dlm_thread_task->pid, dlm->node_num, state);
  641. /* Number of Joins: xxx Joining Node: xxx */
  642. out += snprintf(db->buf + out, db->len - out,
  643. "Number of Joins: %d Joining Node: %d\n",
  644. dlm->num_joins, dlm->joining_node);
  645. /* Domain Map: xx xx xx */
  646. out += snprintf(db->buf + out, db->len - out, "Domain Map: ");
  647. out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
  648. db->buf + out, db->len - out);
  649. out += snprintf(db->buf + out, db->len - out, "\n");
  650. /* Live Map: xx xx xx */
  651. out += snprintf(db->buf + out, db->len - out, "Live Map: ");
  652. out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
  653. db->buf + out, db->len - out);
  654. out += snprintf(db->buf + out, db->len - out, "\n");
  655. /* Mastered Resources Total: xxx Locally: xxx Remotely: ... */
  656. out += snprintf(db->buf + out, db->len - out,
  657. "Mastered Resources Total: %d Locally: %d "
  658. "Remotely: %d Unknown: %d\n",
  659. tres, lres, rres, ures);
  660. /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
  661. out += snprintf(db->buf + out, db->len - out,
  662. "Lists: Dirty=%s Purge=%s PendingASTs=%s "
  663. "PendingBASTs=%s Master=%s\n",
  664. (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
  665. (list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
  666. (list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
  667. (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"),
  668. (list_empty(&dlm->master_list) ? "Empty" : "InUse"));
  669. /* Purge Count: xxx Refs: xxx */
  670. out += snprintf(db->buf + out, db->len - out,
  671. "Purge Count: %d Refs: %d\n", dlm->purge_count,
  672. atomic_read(&dlm->dlm_refs.refcount));
  673. /* Dead Node: xxx */
  674. out += snprintf(db->buf + out, db->len - out,
  675. "Dead Node: %d\n", dlm->reco.dead_node);
  676. /* What about DLM_RECO_STATE_FINALIZE? */
  677. if (dlm->reco.state == DLM_RECO_STATE_ACTIVE)
  678. state = "ACTIVE";
  679. else
  680. state = "INACTIVE";
  681. /* Recovery Pid: xxxx Master: xxx State: xxxx */
  682. out += snprintf(db->buf + out, db->len - out,
  683. "Recovery Pid: %d Master: %d State: %s\n",
  684. dlm->dlm_reco_thread_task->pid,
  685. dlm->reco.new_master, state);
  686. /* Recovery Map: xx xx */
  687. out += snprintf(db->buf + out, db->len - out, "Recovery Map: ");
  688. out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
  689. db->buf + out, db->len - out);
  690. out += snprintf(db->buf + out, db->len - out, "\n");
  691. /* Recovery Node State: */
  692. out += snprintf(db->buf + out, db->len - out, "Recovery Node State:\n");
  693. list_for_each_entry(node, &dlm->reco.node_data, list) {
  694. switch (node->state) {
  695. case DLM_RECO_NODE_DATA_INIT:
  696. state = "INIT";
  697. break;
  698. case DLM_RECO_NODE_DATA_REQUESTING:
  699. state = "REQUESTING";
  700. break;
  701. case DLM_RECO_NODE_DATA_DEAD:
  702. state = "DEAD";
  703. break;
  704. case DLM_RECO_NODE_DATA_RECEIVING:
  705. state = "RECEIVING";
  706. break;
  707. case DLM_RECO_NODE_DATA_REQUESTED:
  708. state = "REQUESTED";
  709. break;
  710. case DLM_RECO_NODE_DATA_DONE:
  711. state = "DONE";
  712. break;
  713. case DLM_RECO_NODE_DATA_FINALIZE_SENT:
  714. state = "FINALIZE-SENT";
  715. break;
  716. default:
  717. state = "BAD";
  718. break;
  719. }
  720. out += snprintf(db->buf + out, db->len - out, "\t%u - %s\n",
  721. node->node_num, state);
  722. }
  723. spin_unlock(&dlm->spinlock);
  724. return out;
  725. }
  726. static int debug_state_open(struct inode *inode, struct file *file)
  727. {
  728. struct dlm_ctxt *dlm = inode->i_private;
  729. struct debug_buffer *db = NULL;
  730. db = debug_buffer_allocate();
  731. if (!db)
  732. goto bail;
  733. db->len = debug_state_print(dlm, db);
  734. file->private_data = db;
  735. return 0;
  736. bail:
  737. return -ENOMEM;
  738. }
  739. static struct file_operations debug_state_fops = {
  740. .open = debug_state_open,
  741. .release = debug_buffer_release,
  742. .read = debug_buffer_read,
  743. .llseek = debug_buffer_llseek,
  744. };
  745. /* end - debug state funcs */
  746. /* files in subroot */
  747. int dlm_debug_init(struct dlm_ctxt *dlm)
  748. {
  749. struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
  750. /* for dumping dlm_ctxt */
  751. dc->debug_state_dentry = debugfs_create_file(DLM_DEBUGFS_DLM_STATE,
  752. S_IFREG|S_IRUSR,
  753. dlm->dlm_debugfs_subroot,
  754. dlm, &debug_state_fops);
  755. if (!dc->debug_state_dentry) {
  756. mlog_errno(-ENOMEM);
  757. goto bail;
  758. }
  759. /* for dumping lockres */
  760. dc->debug_lockres_dentry =
  761. debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE,
  762. S_IFREG|S_IRUSR,
  763. dlm->dlm_debugfs_subroot,
  764. dlm, &debug_lockres_fops);
  765. if (!dc->debug_lockres_dentry) {
  766. mlog_errno(-ENOMEM);
  767. goto bail;
  768. }
  769. /* for dumping mles */
  770. dc->debug_mle_dentry = debugfs_create_file(DLM_DEBUGFS_MLE_STATE,
  771. S_IFREG|S_IRUSR,
  772. dlm->dlm_debugfs_subroot,
  773. dlm, &debug_mle_fops);
  774. if (!dc->debug_mle_dentry) {
  775. mlog_errno(-ENOMEM);
  776. goto bail;
  777. }
  778. dlm_debug_get(dc);
  779. return 0;
  780. bail:
  781. dlm_debug_shutdown(dlm);
  782. return -ENOMEM;
  783. }
  784. void dlm_debug_shutdown(struct dlm_ctxt *dlm)
  785. {
  786. struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
  787. if (dc) {
  788. if (dc->debug_mle_dentry)
  789. debugfs_remove(dc->debug_mle_dentry);
  790. if (dc->debug_lockres_dentry)
  791. debugfs_remove(dc->debug_lockres_dentry);
  792. if (dc->debug_state_dentry)
  793. debugfs_remove(dc->debug_state_dentry);
  794. dlm_debug_put(dc);
  795. }
  796. }
  797. /* subroot - domain dir */
  798. int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
  799. {
  800. dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
  801. dlm_debugfs_root);
  802. if (!dlm->dlm_debugfs_subroot) {
  803. mlog_errno(-ENOMEM);
  804. goto bail;
  805. }
  806. dlm->dlm_debug_ctxt = kzalloc(sizeof(struct dlm_debug_ctxt),
  807. GFP_KERNEL);
  808. if (!dlm->dlm_debug_ctxt) {
  809. mlog_errno(-ENOMEM);
  810. goto bail;
  811. }
  812. kref_init(&dlm->dlm_debug_ctxt->debug_refcnt);
  813. return 0;
  814. bail:
  815. dlm_destroy_debugfs_subroot(dlm);
  816. return -ENOMEM;
  817. }
  818. void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
  819. {
  820. if (dlm->dlm_debugfs_subroot)
  821. debugfs_remove(dlm->dlm_debugfs_subroot);
  822. }
  823. /* debugfs root */
  824. int dlm_create_debugfs_root(void)
  825. {
  826. dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
  827. if (!dlm_debugfs_root) {
  828. mlog_errno(-ENOMEM);
  829. return -ENOMEM;
  830. }
  831. return 0;
  832. }
  833. void dlm_destroy_debugfs_root(void)
  834. {
  835. if (dlm_debugfs_root)
  836. debugfs_remove(dlm_debugfs_root);
  837. }
  838. #endif /* CONFIG_DEBUG_FS */