dlmdebug.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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 void dlm_debug_free(struct kref *kref)
  312. {
  313. struct dlm_debug_ctxt *dc;
  314. dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);
  315. kfree(dc);
  316. }
  317. static void dlm_debug_put(struct dlm_debug_ctxt *dc)
  318. {
  319. if (dc)
  320. kref_put(&dc->debug_refcnt, dlm_debug_free);
  321. }
  322. static void dlm_debug_get(struct dlm_debug_ctxt *dc)
  323. {
  324. kref_get(&dc->debug_refcnt);
  325. }
  326. static int debug_release(struct inode *inode, struct file *file)
  327. {
  328. free_page((unsigned long)file->private_data);
  329. return 0;
  330. }
  331. static ssize_t debug_read(struct file *file, char __user *buf,
  332. size_t nbytes, loff_t *ppos)
  333. {
  334. return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  335. i_size_read(file->f_mapping->host));
  336. }
  337. /* end - util funcs */
  338. /* begin - purge list funcs */
  339. static int debug_purgelist_print(struct dlm_ctxt *dlm, char *buf, int len)
  340. {
  341. struct dlm_lock_resource *res;
  342. int out = 0;
  343. unsigned long total = 0;
  344. out += snprintf(buf + out, len - out,
  345. "Dumping Purgelist for Domain: %s\n", dlm->name);
  346. spin_lock(&dlm->spinlock);
  347. list_for_each_entry(res, &dlm->purge_list, purge) {
  348. ++total;
  349. if (len - out < 100)
  350. continue;
  351. spin_lock(&res->spinlock);
  352. out += stringify_lockname(res->lockname.name,
  353. res->lockname.len,
  354. buf + out, len - out);
  355. out += snprintf(buf + out, len - out, "\t%ld\n",
  356. (jiffies - res->last_used)/HZ);
  357. spin_unlock(&res->spinlock);
  358. }
  359. spin_unlock(&dlm->spinlock);
  360. out += snprintf(buf + out, len - out, "Total on list: %lu\n", total);
  361. return out;
  362. }
  363. static int debug_purgelist_open(struct inode *inode, struct file *file)
  364. {
  365. struct dlm_ctxt *dlm = inode->i_private;
  366. char *buf = NULL;
  367. buf = (char *) get_zeroed_page(GFP_NOFS);
  368. if (!buf)
  369. goto bail;
  370. i_size_write(inode, debug_purgelist_print(dlm, buf, PAGE_SIZE - 1));
  371. file->private_data = buf;
  372. return 0;
  373. bail:
  374. return -ENOMEM;
  375. }
  376. static const struct file_operations debug_purgelist_fops = {
  377. .open = debug_purgelist_open,
  378. .release = debug_release,
  379. .read = debug_read,
  380. .llseek = generic_file_llseek,
  381. };
  382. /* end - purge list funcs */
  383. /* begin - debug mle funcs */
  384. static int debug_mle_print(struct dlm_ctxt *dlm, char *buf, int len)
  385. {
  386. struct dlm_master_list_entry *mle;
  387. struct hlist_head *bucket;
  388. int i, out = 0;
  389. unsigned long total = 0, longest = 0, bucket_count = 0;
  390. out += snprintf(buf + out, len - out,
  391. "Dumping MLEs for Domain: %s\n", dlm->name);
  392. spin_lock(&dlm->master_lock);
  393. for (i = 0; i < DLM_HASH_BUCKETS; i++) {
  394. bucket = dlm_master_hash(dlm, i);
  395. hlist_for_each_entry(mle, bucket, master_hash_node) {
  396. ++total;
  397. ++bucket_count;
  398. if (len - out < 200)
  399. continue;
  400. out += dump_mle(mle, buf + out, len - out);
  401. }
  402. longest = max(longest, bucket_count);
  403. bucket_count = 0;
  404. }
  405. spin_unlock(&dlm->master_lock);
  406. out += snprintf(buf + out, len - out,
  407. "Total: %lu, Longest: %lu\n", total, longest);
  408. return out;
  409. }
  410. static int debug_mle_open(struct inode *inode, struct file *file)
  411. {
  412. struct dlm_ctxt *dlm = inode->i_private;
  413. char *buf = NULL;
  414. buf = (char *) get_zeroed_page(GFP_NOFS);
  415. if (!buf)
  416. goto bail;
  417. i_size_write(inode, debug_mle_print(dlm, buf, PAGE_SIZE - 1));
  418. file->private_data = buf;
  419. return 0;
  420. bail:
  421. return -ENOMEM;
  422. }
  423. static const struct file_operations debug_mle_fops = {
  424. .open = debug_mle_open,
  425. .release = debug_release,
  426. .read = debug_read,
  427. .llseek = generic_file_llseek,
  428. };
  429. /* end - debug mle funcs */
  430. /* begin - debug lockres funcs */
  431. static int dump_lock(struct dlm_lock *lock, int list_type, char *buf, int len)
  432. {
  433. int out;
  434. #define DEBUG_LOCK_VERSION 1
  435. spin_lock(&lock->spinlock);
  436. out = snprintf(buf, len, "LOCK:%d,%d,%d,%d,%d,%d:%lld,%d,%d,%d,%d,%d,"
  437. "%d,%d,%d,%d\n",
  438. DEBUG_LOCK_VERSION,
  439. list_type, lock->ml.type, lock->ml.convert_type,
  440. lock->ml.node,
  441. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  442. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  443. !list_empty(&lock->ast_list),
  444. !list_empty(&lock->bast_list),
  445. lock->ast_pending, lock->bast_pending,
  446. lock->convert_pending, lock->lock_pending,
  447. lock->cancel_pending, lock->unlock_pending,
  448. atomic_read(&lock->lock_refs.refcount));
  449. spin_unlock(&lock->spinlock);
  450. return out;
  451. }
  452. static int dump_lockres(struct dlm_lock_resource *res, char *buf, int len)
  453. {
  454. struct dlm_lock *lock;
  455. int i;
  456. int out = 0;
  457. out += snprintf(buf + out, len - out, "NAME:");
  458. out += stringify_lockname(res->lockname.name, res->lockname.len,
  459. buf + out, len - out);
  460. out += snprintf(buf + out, len - out, "\n");
  461. #define DEBUG_LRES_VERSION 1
  462. out += snprintf(buf + out, len - out,
  463. "LRES:%d,%d,%d,%ld,%d,%d,%d,%d,%d,%d,%d\n",
  464. DEBUG_LRES_VERSION,
  465. res->owner, res->state, res->last_used,
  466. !list_empty(&res->purge),
  467. !list_empty(&res->dirty),
  468. !list_empty(&res->recovering),
  469. res->inflight_locks, res->migration_pending,
  470. atomic_read(&res->asts_reserved),
  471. atomic_read(&res->refs.refcount));
  472. /* refmap */
  473. out += snprintf(buf + out, len - out, "RMAP:");
  474. out += stringify_nodemap(res->refmap, O2NM_MAX_NODES,
  475. buf + out, len - out);
  476. out += snprintf(buf + out, len - out, "\n");
  477. /* lvb */
  478. out += snprintf(buf + out, len - out, "LVBX:");
  479. for (i = 0; i < DLM_LVB_LEN; i++)
  480. out += snprintf(buf + out, len - out,
  481. "%02x", (unsigned char)res->lvb[i]);
  482. out += snprintf(buf + out, len - out, "\n");
  483. /* granted */
  484. list_for_each_entry(lock, &res->granted, list)
  485. out += dump_lock(lock, 0, buf + out, len - out);
  486. /* converting */
  487. list_for_each_entry(lock, &res->converting, list)
  488. out += dump_lock(lock, 1, buf + out, len - out);
  489. /* blocked */
  490. list_for_each_entry(lock, &res->blocked, list)
  491. out += dump_lock(lock, 2, buf + out, len - out);
  492. out += snprintf(buf + out, len - out, "\n");
  493. return out;
  494. }
  495. static void *lockres_seq_start(struct seq_file *m, loff_t *pos)
  496. {
  497. struct debug_lockres *dl = m->private;
  498. struct dlm_ctxt *dlm = dl->dl_ctxt;
  499. struct dlm_lock_resource *oldres = dl->dl_res;
  500. struct dlm_lock_resource *res = NULL;
  501. struct list_head *track_list;
  502. spin_lock(&dlm->track_lock);
  503. if (oldres)
  504. track_list = &oldres->tracking;
  505. else {
  506. track_list = &dlm->tracking_list;
  507. if (list_empty(track_list)) {
  508. dl = NULL;
  509. spin_unlock(&dlm->track_lock);
  510. goto bail;
  511. }
  512. }
  513. list_for_each_entry(res, track_list, tracking) {
  514. if (&res->tracking == &dlm->tracking_list)
  515. res = NULL;
  516. else
  517. dlm_lockres_get(res);
  518. break;
  519. }
  520. spin_unlock(&dlm->track_lock);
  521. if (oldres)
  522. dlm_lockres_put(oldres);
  523. dl->dl_res = res;
  524. if (res) {
  525. spin_lock(&res->spinlock);
  526. dump_lockres(res, dl->dl_buf, dl->dl_len - 1);
  527. spin_unlock(&res->spinlock);
  528. } else
  529. dl = NULL;
  530. bail:
  531. /* passed to seq_show */
  532. return dl;
  533. }
  534. static void lockres_seq_stop(struct seq_file *m, void *v)
  535. {
  536. }
  537. static void *lockres_seq_next(struct seq_file *m, void *v, loff_t *pos)
  538. {
  539. return NULL;
  540. }
  541. static int lockres_seq_show(struct seq_file *s, void *v)
  542. {
  543. struct debug_lockres *dl = (struct debug_lockres *)v;
  544. seq_printf(s, "%s", dl->dl_buf);
  545. return 0;
  546. }
  547. static const struct seq_operations debug_lockres_ops = {
  548. .start = lockres_seq_start,
  549. .stop = lockres_seq_stop,
  550. .next = lockres_seq_next,
  551. .show = lockres_seq_show,
  552. };
  553. static int debug_lockres_open(struct inode *inode, struct file *file)
  554. {
  555. struct dlm_ctxt *dlm = inode->i_private;
  556. struct debug_lockres *dl;
  557. void *buf;
  558. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  559. if (!buf)
  560. goto bail;
  561. dl = __seq_open_private(file, &debug_lockres_ops, sizeof(*dl));
  562. if (!dl)
  563. goto bailfree;
  564. dl->dl_len = PAGE_SIZE;
  565. dl->dl_buf = buf;
  566. dlm_grab(dlm);
  567. dl->dl_ctxt = dlm;
  568. return 0;
  569. bailfree:
  570. kfree(buf);
  571. bail:
  572. mlog_errno(-ENOMEM);
  573. return -ENOMEM;
  574. }
  575. static int debug_lockres_release(struct inode *inode, struct file *file)
  576. {
  577. struct seq_file *seq = file->private_data;
  578. struct debug_lockres *dl = (struct debug_lockres *)seq->private;
  579. if (dl->dl_res)
  580. dlm_lockres_put(dl->dl_res);
  581. dlm_put(dl->dl_ctxt);
  582. kfree(dl->dl_buf);
  583. return seq_release_private(inode, file);
  584. }
  585. static const struct file_operations debug_lockres_fops = {
  586. .open = debug_lockres_open,
  587. .release = debug_lockres_release,
  588. .read = seq_read,
  589. .llseek = seq_lseek,
  590. };
  591. /* end - debug lockres funcs */
  592. /* begin - debug state funcs */
  593. static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
  594. {
  595. int out = 0;
  596. struct dlm_reco_node_data *node;
  597. char *state;
  598. int cur_mles = 0, tot_mles = 0;
  599. int i;
  600. spin_lock(&dlm->spinlock);
  601. switch (dlm->dlm_state) {
  602. case DLM_CTXT_NEW:
  603. state = "NEW"; break;
  604. case DLM_CTXT_JOINED:
  605. state = "JOINED"; break;
  606. case DLM_CTXT_IN_SHUTDOWN:
  607. state = "SHUTDOWN"; break;
  608. case DLM_CTXT_LEAVING:
  609. state = "LEAVING"; break;
  610. default:
  611. state = "UNKNOWN"; break;
  612. }
  613. /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
  614. out += snprintf(buf + out, len - out,
  615. "Domain: %s Key: 0x%08x Protocol: %d.%d\n",
  616. dlm->name, dlm->key, dlm->dlm_locking_proto.pv_major,
  617. dlm->dlm_locking_proto.pv_minor);
  618. /* Thread Pid: xxx Node: xxx State: xxxxx */
  619. out += snprintf(buf + out, len - out,
  620. "Thread Pid: %d Node: %d State: %s\n",
  621. task_pid_nr(dlm->dlm_thread_task), dlm->node_num, state);
  622. /* Number of Joins: xxx Joining Node: xxx */
  623. out += snprintf(buf + out, len - out,
  624. "Number of Joins: %d Joining Node: %d\n",
  625. dlm->num_joins, dlm->joining_node);
  626. /* Domain Map: xx xx xx */
  627. out += snprintf(buf + out, len - out, "Domain Map: ");
  628. out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
  629. buf + out, len - out);
  630. out += snprintf(buf + out, len - out, "\n");
  631. /* Exit Domain Map: xx xx xx */
  632. out += snprintf(buf + out, len - out, "Exit Domain Map: ");
  633. out += stringify_nodemap(dlm->exit_domain_map, O2NM_MAX_NODES,
  634. buf + out, len - out);
  635. out += snprintf(buf + out, len - out, "\n");
  636. /* Live Map: xx xx xx */
  637. out += snprintf(buf + out, len - out, "Live Map: ");
  638. out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
  639. buf + out, len - out);
  640. out += snprintf(buf + out, len - out, "\n");
  641. /* Lock Resources: xxx (xxx) */
  642. out += snprintf(buf + out, len - out,
  643. "Lock Resources: %d (%d)\n",
  644. atomic_read(&dlm->res_cur_count),
  645. atomic_read(&dlm->res_tot_count));
  646. for (i = 0; i < DLM_MLE_NUM_TYPES; ++i)
  647. tot_mles += atomic_read(&dlm->mle_tot_count[i]);
  648. for (i = 0; i < DLM_MLE_NUM_TYPES; ++i)
  649. cur_mles += atomic_read(&dlm->mle_cur_count[i]);
  650. /* MLEs: xxx (xxx) */
  651. out += snprintf(buf + out, len - out,
  652. "MLEs: %d (%d)\n", cur_mles, tot_mles);
  653. /* Blocking: xxx (xxx) */
  654. out += snprintf(buf + out, len - out,
  655. " Blocking: %d (%d)\n",
  656. atomic_read(&dlm->mle_cur_count[DLM_MLE_BLOCK]),
  657. atomic_read(&dlm->mle_tot_count[DLM_MLE_BLOCK]));
  658. /* Mastery: xxx (xxx) */
  659. out += snprintf(buf + out, len - out,
  660. " Mastery: %d (%d)\n",
  661. atomic_read(&dlm->mle_cur_count[DLM_MLE_MASTER]),
  662. atomic_read(&dlm->mle_tot_count[DLM_MLE_MASTER]));
  663. /* Migration: xxx (xxx) */
  664. out += snprintf(buf + out, len - out,
  665. " Migration: %d (%d)\n",
  666. atomic_read(&dlm->mle_cur_count[DLM_MLE_MIGRATION]),
  667. atomic_read(&dlm->mle_tot_count[DLM_MLE_MIGRATION]));
  668. /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
  669. out += snprintf(buf + out, len - out,
  670. "Lists: Dirty=%s Purge=%s PendingASTs=%s "
  671. "PendingBASTs=%s\n",
  672. (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
  673. (list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
  674. (list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
  675. (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"));
  676. /* Purge Count: xxx Refs: xxx */
  677. out += snprintf(buf + out, len - out,
  678. "Purge Count: %d Refs: %d\n", dlm->purge_count,
  679. atomic_read(&dlm->dlm_refs.refcount));
  680. /* Dead Node: xxx */
  681. out += snprintf(buf + out, len - out,
  682. "Dead Node: %d\n", dlm->reco.dead_node);
  683. /* What about DLM_RECO_STATE_FINALIZE? */
  684. if (dlm->reco.state == DLM_RECO_STATE_ACTIVE)
  685. state = "ACTIVE";
  686. else
  687. state = "INACTIVE";
  688. /* Recovery Pid: xxxx Master: xxx State: xxxx */
  689. out += snprintf(buf + out, len - out,
  690. "Recovery Pid: %d Master: %d State: %s\n",
  691. task_pid_nr(dlm->dlm_reco_thread_task),
  692. dlm->reco.new_master, state);
  693. /* Recovery Map: xx xx */
  694. out += snprintf(buf + out, len - out, "Recovery Map: ");
  695. out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
  696. buf + out, len - out);
  697. out += snprintf(buf + out, len - out, "\n");
  698. /* Recovery Node State: */
  699. out += snprintf(buf + out, len - out, "Recovery Node State:\n");
  700. list_for_each_entry(node, &dlm->reco.node_data, list) {
  701. switch (node->state) {
  702. case DLM_RECO_NODE_DATA_INIT:
  703. state = "INIT";
  704. break;
  705. case DLM_RECO_NODE_DATA_REQUESTING:
  706. state = "REQUESTING";
  707. break;
  708. case DLM_RECO_NODE_DATA_DEAD:
  709. state = "DEAD";
  710. break;
  711. case DLM_RECO_NODE_DATA_RECEIVING:
  712. state = "RECEIVING";
  713. break;
  714. case DLM_RECO_NODE_DATA_REQUESTED:
  715. state = "REQUESTED";
  716. break;
  717. case DLM_RECO_NODE_DATA_DONE:
  718. state = "DONE";
  719. break;
  720. case DLM_RECO_NODE_DATA_FINALIZE_SENT:
  721. state = "FINALIZE-SENT";
  722. break;
  723. default:
  724. state = "BAD";
  725. break;
  726. }
  727. out += snprintf(buf + out, len - out, "\t%u - %s\n",
  728. node->node_num, state);
  729. }
  730. spin_unlock(&dlm->spinlock);
  731. return out;
  732. }
  733. static int debug_state_open(struct inode *inode, struct file *file)
  734. {
  735. struct dlm_ctxt *dlm = inode->i_private;
  736. char *buf = NULL;
  737. buf = (char *) get_zeroed_page(GFP_NOFS);
  738. if (!buf)
  739. goto bail;
  740. i_size_write(inode, debug_state_print(dlm, buf, PAGE_SIZE - 1));
  741. file->private_data = buf;
  742. return 0;
  743. bail:
  744. return -ENOMEM;
  745. }
  746. static const struct file_operations debug_state_fops = {
  747. .open = debug_state_open,
  748. .release = debug_release,
  749. .read = debug_read,
  750. .llseek = generic_file_llseek,
  751. };
  752. /* end - debug state funcs */
  753. /* files in subroot */
  754. int dlm_debug_init(struct dlm_ctxt *dlm)
  755. {
  756. struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
  757. /* for dumping dlm_ctxt */
  758. dc->debug_state_dentry = debugfs_create_file(DLM_DEBUGFS_DLM_STATE,
  759. S_IFREG|S_IRUSR,
  760. dlm->dlm_debugfs_subroot,
  761. dlm, &debug_state_fops);
  762. if (!dc->debug_state_dentry) {
  763. mlog_errno(-ENOMEM);
  764. goto bail;
  765. }
  766. /* for dumping lockres */
  767. dc->debug_lockres_dentry =
  768. debugfs_create_file(DLM_DEBUGFS_LOCKING_STATE,
  769. S_IFREG|S_IRUSR,
  770. dlm->dlm_debugfs_subroot,
  771. dlm, &debug_lockres_fops);
  772. if (!dc->debug_lockres_dentry) {
  773. mlog_errno(-ENOMEM);
  774. goto bail;
  775. }
  776. /* for dumping mles */
  777. dc->debug_mle_dentry = debugfs_create_file(DLM_DEBUGFS_MLE_STATE,
  778. S_IFREG|S_IRUSR,
  779. dlm->dlm_debugfs_subroot,
  780. dlm, &debug_mle_fops);
  781. if (!dc->debug_mle_dentry) {
  782. mlog_errno(-ENOMEM);
  783. goto bail;
  784. }
  785. /* for dumping lockres on the purge list */
  786. dc->debug_purgelist_dentry =
  787. debugfs_create_file(DLM_DEBUGFS_PURGE_LIST,
  788. S_IFREG|S_IRUSR,
  789. dlm->dlm_debugfs_subroot,
  790. dlm, &debug_purgelist_fops);
  791. if (!dc->debug_purgelist_dentry) {
  792. mlog_errno(-ENOMEM);
  793. goto bail;
  794. }
  795. dlm_debug_get(dc);
  796. return 0;
  797. bail:
  798. dlm_debug_shutdown(dlm);
  799. return -ENOMEM;
  800. }
  801. void dlm_debug_shutdown(struct dlm_ctxt *dlm)
  802. {
  803. struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
  804. if (dc) {
  805. debugfs_remove(dc->debug_purgelist_dentry);
  806. debugfs_remove(dc->debug_mle_dentry);
  807. debugfs_remove(dc->debug_lockres_dentry);
  808. debugfs_remove(dc->debug_state_dentry);
  809. dlm_debug_put(dc);
  810. }
  811. }
  812. /* subroot - domain dir */
  813. int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
  814. {
  815. dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
  816. dlm_debugfs_root);
  817. if (!dlm->dlm_debugfs_subroot) {
  818. mlog_errno(-ENOMEM);
  819. goto bail;
  820. }
  821. dlm->dlm_debug_ctxt = kzalloc(sizeof(struct dlm_debug_ctxt),
  822. GFP_KERNEL);
  823. if (!dlm->dlm_debug_ctxt) {
  824. mlog_errno(-ENOMEM);
  825. goto bail;
  826. }
  827. kref_init(&dlm->dlm_debug_ctxt->debug_refcnt);
  828. return 0;
  829. bail:
  830. dlm_destroy_debugfs_subroot(dlm);
  831. return -ENOMEM;
  832. }
  833. void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
  834. {
  835. debugfs_remove(dlm->dlm_debugfs_subroot);
  836. }
  837. /* debugfs root */
  838. int dlm_create_debugfs_root(void)
  839. {
  840. dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
  841. if (!dlm_debugfs_root) {
  842. mlog_errno(-ENOMEM);
  843. return -ENOMEM;
  844. }
  845. return 0;
  846. }
  847. void dlm_destroy_debugfs_root(void)
  848. {
  849. debugfs_remove(dlm_debugfs_root);
  850. }
  851. #endif /* CONFIG_DEBUG_FS */