dlmdebug.c 28 KB

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