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