dlmdebug.c 27 KB

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