debug_fs.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. /******************************************************************************
  2. *******************************************************************************
  3. **
  4. ** Copyright (C) 2005-2009 Red Hat, Inc. All rights reserved.
  5. **
  6. ** This copyrighted material is made available to anyone wishing to use,
  7. ** modify, copy, or redistribute it subject to the terms and conditions
  8. ** of the GNU General Public License v.2.
  9. **
  10. *******************************************************************************
  11. ******************************************************************************/
  12. #include <linux/pagemap.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/module.h>
  15. #include <linux/ctype.h>
  16. #include <linux/debugfs.h>
  17. #include <linux/slab.h>
  18. #include "dlm_internal.h"
  19. #include "lock.h"
  20. #define DLM_DEBUG_BUF_LEN 4096
  21. static char debug_buf[DLM_DEBUG_BUF_LEN];
  22. static struct mutex debug_buf_lock;
  23. static struct dentry *dlm_root;
  24. static char *print_lockmode(int mode)
  25. {
  26. switch (mode) {
  27. case DLM_LOCK_IV:
  28. return "--";
  29. case DLM_LOCK_NL:
  30. return "NL";
  31. case DLM_LOCK_CR:
  32. return "CR";
  33. case DLM_LOCK_CW:
  34. return "CW";
  35. case DLM_LOCK_PR:
  36. return "PR";
  37. case DLM_LOCK_PW:
  38. return "PW";
  39. case DLM_LOCK_EX:
  40. return "EX";
  41. default:
  42. return "??";
  43. }
  44. }
  45. static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
  46. struct dlm_rsb *res)
  47. {
  48. seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode));
  49. if (lkb->lkb_status == DLM_LKSTS_CONVERT ||
  50. lkb->lkb_status == DLM_LKSTS_WAITING)
  51. seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode));
  52. if (lkb->lkb_nodeid) {
  53. if (lkb->lkb_nodeid != res->res_nodeid)
  54. seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
  55. lkb->lkb_remid);
  56. else
  57. seq_printf(s, " Master: %08x", lkb->lkb_remid);
  58. }
  59. if (lkb->lkb_wait_type)
  60. seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
  61. seq_puts(s, "\n");
  62. }
  63. static void print_format1(struct dlm_rsb *res, struct seq_file *s)
  64. {
  65. struct dlm_lkb *lkb;
  66. int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list;
  67. lock_rsb(res);
  68. seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length);
  69. for (i = 0; i < res->res_length; i++) {
  70. if (isprint(res->res_name[i]))
  71. seq_printf(s, "%c", res->res_name[i]);
  72. else
  73. seq_printf(s, "%c", '.');
  74. }
  75. if (res->res_nodeid > 0)
  76. seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
  77. res->res_nodeid);
  78. else if (res->res_nodeid == 0)
  79. seq_puts(s, "\"\nMaster Copy\n");
  80. else if (res->res_nodeid == -1)
  81. seq_printf(s, "\"\nLooking up master (lkid %x)\n",
  82. res->res_first_lkid);
  83. else
  84. seq_printf(s, "\"\nInvalid master %d\n", res->res_nodeid);
  85. if (seq_has_overflowed(s))
  86. goto out;
  87. /* Print the LVB: */
  88. if (res->res_lvbptr) {
  89. seq_puts(s, "LVB: ");
  90. for (i = 0; i < lvblen; i++) {
  91. if (i == lvblen / 2)
  92. seq_puts(s, "\n ");
  93. seq_printf(s, "%02x ",
  94. (unsigned char) res->res_lvbptr[i]);
  95. }
  96. if (rsb_flag(res, RSB_VALNOTVALID))
  97. seq_puts(s, " (INVALID)");
  98. seq_puts(s, "\n");
  99. if (seq_has_overflowed(s))
  100. goto out;
  101. }
  102. root_list = !list_empty(&res->res_root_list);
  103. recover_list = !list_empty(&res->res_recover_list);
  104. if (root_list || recover_list) {
  105. seq_printf(s, "Recovery: root %d recover %d flags %lx count %d\n",
  106. root_list, recover_list,
  107. res->res_flags, res->res_recover_locks_count);
  108. }
  109. /* Print the locks attached to this resource */
  110. seq_puts(s, "Granted Queue\n");
  111. list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) {
  112. print_format1_lock(s, lkb, res);
  113. if (seq_has_overflowed(s))
  114. goto out;
  115. }
  116. seq_puts(s, "Conversion Queue\n");
  117. list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) {
  118. print_format1_lock(s, lkb, res);
  119. if (seq_has_overflowed(s))
  120. goto out;
  121. }
  122. seq_puts(s, "Waiting Queue\n");
  123. list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) {
  124. print_format1_lock(s, lkb, res);
  125. if (seq_has_overflowed(s))
  126. goto out;
  127. }
  128. if (list_empty(&res->res_lookup))
  129. goto out;
  130. seq_puts(s, "Lookup Queue\n");
  131. list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) {
  132. seq_printf(s, "%08x %s",
  133. lkb->lkb_id, print_lockmode(lkb->lkb_rqmode));
  134. if (lkb->lkb_wait_type)
  135. seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
  136. seq_puts(s, "\n");
  137. if (seq_has_overflowed(s))
  138. goto out;
  139. }
  140. out:
  141. unlock_rsb(res);
  142. }
  143. static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
  144. struct dlm_rsb *r)
  145. {
  146. u64 xid = 0;
  147. u64 us;
  148. if (lkb->lkb_flags & DLM_IFL_USER) {
  149. if (lkb->lkb_ua)
  150. xid = lkb->lkb_ua->xid;
  151. }
  152. /* microseconds since lkb was added to current queue */
  153. us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_timestamp));
  154. /* id nodeid remid pid xid exflags flags sts grmode rqmode time_us
  155. r_nodeid r_len r_name */
  156. seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
  157. lkb->lkb_id,
  158. lkb->lkb_nodeid,
  159. lkb->lkb_remid,
  160. lkb->lkb_ownpid,
  161. (unsigned long long)xid,
  162. lkb->lkb_exflags,
  163. lkb->lkb_flags,
  164. lkb->lkb_status,
  165. lkb->lkb_grmode,
  166. lkb->lkb_rqmode,
  167. (unsigned long long)us,
  168. r->res_nodeid,
  169. r->res_length,
  170. r->res_name);
  171. }
  172. static void print_format2(struct dlm_rsb *r, struct seq_file *s)
  173. {
  174. struct dlm_lkb *lkb;
  175. lock_rsb(r);
  176. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  177. print_format2_lock(s, lkb, r);
  178. if (seq_has_overflowed(s))
  179. goto out;
  180. }
  181. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  182. print_format2_lock(s, lkb, r);
  183. if (seq_has_overflowed(s))
  184. goto out;
  185. }
  186. list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
  187. print_format2_lock(s, lkb, r);
  188. if (seq_has_overflowed(s))
  189. goto out;
  190. }
  191. out:
  192. unlock_rsb(r);
  193. }
  194. static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
  195. int rsb_lookup)
  196. {
  197. u64 xid = 0;
  198. if (lkb->lkb_flags & DLM_IFL_USER) {
  199. if (lkb->lkb_ua)
  200. xid = lkb->lkb_ua->xid;
  201. }
  202. seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
  203. lkb->lkb_id,
  204. lkb->lkb_nodeid,
  205. lkb->lkb_remid,
  206. lkb->lkb_ownpid,
  207. (unsigned long long)xid,
  208. lkb->lkb_exflags,
  209. lkb->lkb_flags,
  210. lkb->lkb_status,
  211. lkb->lkb_grmode,
  212. lkb->lkb_rqmode,
  213. lkb->lkb_last_bast.mode,
  214. rsb_lookup,
  215. lkb->lkb_wait_type,
  216. lkb->lkb_lvbseq,
  217. (unsigned long long)ktime_to_ns(lkb->lkb_timestamp),
  218. (unsigned long long)ktime_to_ns(lkb->lkb_last_bast_time));
  219. }
  220. static void print_format3(struct dlm_rsb *r, struct seq_file *s)
  221. {
  222. struct dlm_lkb *lkb;
  223. int i, lvblen = r->res_ls->ls_lvblen;
  224. int print_name = 1;
  225. lock_rsb(r);
  226. seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
  227. r,
  228. r->res_nodeid,
  229. r->res_first_lkid,
  230. r->res_flags,
  231. !list_empty(&r->res_root_list),
  232. !list_empty(&r->res_recover_list),
  233. r->res_recover_locks_count,
  234. r->res_length);
  235. if (seq_has_overflowed(s))
  236. goto out;
  237. for (i = 0; i < r->res_length; i++) {
  238. if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
  239. print_name = 0;
  240. }
  241. seq_puts(s, print_name ? "str " : "hex");
  242. for (i = 0; i < r->res_length; i++) {
  243. if (print_name)
  244. seq_printf(s, "%c", r->res_name[i]);
  245. else
  246. seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
  247. }
  248. seq_puts(s, "\n");
  249. if (seq_has_overflowed(s))
  250. goto out;
  251. if (!r->res_lvbptr)
  252. goto do_locks;
  253. seq_printf(s, "lvb %u %d", r->res_lvbseq, lvblen);
  254. for (i = 0; i < lvblen; i++)
  255. seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
  256. seq_puts(s, "\n");
  257. if (seq_has_overflowed(s))
  258. goto out;
  259. do_locks:
  260. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  261. print_format3_lock(s, lkb, 0);
  262. if (seq_has_overflowed(s))
  263. goto out;
  264. }
  265. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  266. print_format3_lock(s, lkb, 0);
  267. if (seq_has_overflowed(s))
  268. goto out;
  269. }
  270. list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
  271. print_format3_lock(s, lkb, 0);
  272. if (seq_has_overflowed(s))
  273. goto out;
  274. }
  275. list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) {
  276. print_format3_lock(s, lkb, 1);
  277. if (seq_has_overflowed(s))
  278. goto out;
  279. }
  280. out:
  281. unlock_rsb(r);
  282. }
  283. static void print_format4(struct dlm_rsb *r, struct seq_file *s)
  284. {
  285. int our_nodeid = dlm_our_nodeid();
  286. int print_name = 1;
  287. int i;
  288. lock_rsb(r);
  289. seq_printf(s, "rsb %p %d %d %d %d %lu %lx %d ",
  290. r,
  291. r->res_nodeid,
  292. r->res_master_nodeid,
  293. r->res_dir_nodeid,
  294. our_nodeid,
  295. r->res_toss_time,
  296. r->res_flags,
  297. r->res_length);
  298. for (i = 0; i < r->res_length; i++) {
  299. if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
  300. print_name = 0;
  301. }
  302. seq_puts(s, print_name ? "str " : "hex");
  303. for (i = 0; i < r->res_length; i++) {
  304. if (print_name)
  305. seq_printf(s, "%c", r->res_name[i]);
  306. else
  307. seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
  308. }
  309. seq_puts(s, "\n");
  310. unlock_rsb(r);
  311. }
  312. struct rsbtbl_iter {
  313. struct dlm_rsb *rsb;
  314. unsigned bucket;
  315. int format;
  316. int header;
  317. };
  318. /*
  319. * If the buffer is full, seq_printf can be called again, but it
  320. * does nothing. So, the these printing routines periodically check
  321. * seq_has_overflowed to avoid wasting too much time trying to print to
  322. * a full buffer.
  323. */
  324. static int table_seq_show(struct seq_file *seq, void *iter_ptr)
  325. {
  326. struct rsbtbl_iter *ri = iter_ptr;
  327. switch (ri->format) {
  328. case 1:
  329. print_format1(ri->rsb, seq);
  330. break;
  331. case 2:
  332. if (ri->header) {
  333. seq_puts(seq, "id nodeid remid pid xid exflags flags sts grmode rqmode time_ms r_nodeid r_len r_name\n");
  334. ri->header = 0;
  335. }
  336. print_format2(ri->rsb, seq);
  337. break;
  338. case 3:
  339. if (ri->header) {
  340. seq_puts(seq, "version rsb 1.1 lvb 1.1 lkb 1.1\n");
  341. ri->header = 0;
  342. }
  343. print_format3(ri->rsb, seq);
  344. break;
  345. case 4:
  346. if (ri->header) {
  347. seq_puts(seq, "version 4 rsb 2\n");
  348. ri->header = 0;
  349. }
  350. print_format4(ri->rsb, seq);
  351. break;
  352. }
  353. return 0;
  354. }
  355. static const struct seq_operations format1_seq_ops;
  356. static const struct seq_operations format2_seq_ops;
  357. static const struct seq_operations format3_seq_ops;
  358. static const struct seq_operations format4_seq_ops;
  359. static void *table_seq_start(struct seq_file *seq, loff_t *pos)
  360. {
  361. struct rb_root *tree;
  362. struct rb_node *node;
  363. struct dlm_ls *ls = seq->private;
  364. struct rsbtbl_iter *ri;
  365. struct dlm_rsb *r;
  366. loff_t n = *pos;
  367. unsigned bucket, entry;
  368. int toss = (seq->op == &format4_seq_ops);
  369. bucket = n >> 32;
  370. entry = n & ((1LL << 32) - 1);
  371. if (bucket >= ls->ls_rsbtbl_size)
  372. return NULL;
  373. ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS);
  374. if (!ri)
  375. return NULL;
  376. if (n == 0)
  377. ri->header = 1;
  378. if (seq->op == &format1_seq_ops)
  379. ri->format = 1;
  380. if (seq->op == &format2_seq_ops)
  381. ri->format = 2;
  382. if (seq->op == &format3_seq_ops)
  383. ri->format = 3;
  384. if (seq->op == &format4_seq_ops)
  385. ri->format = 4;
  386. tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
  387. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  388. if (!RB_EMPTY_ROOT(tree)) {
  389. for (node = rb_first(tree); node; node = rb_next(node)) {
  390. r = rb_entry(node, struct dlm_rsb, res_hashnode);
  391. if (!entry--) {
  392. dlm_hold_rsb(r);
  393. ri->rsb = r;
  394. ri->bucket = bucket;
  395. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  396. return ri;
  397. }
  398. }
  399. }
  400. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  401. /*
  402. * move to the first rsb in the next non-empty bucket
  403. */
  404. /* zero the entry */
  405. n &= ~((1LL << 32) - 1);
  406. while (1) {
  407. bucket++;
  408. n += 1LL << 32;
  409. if (bucket >= ls->ls_rsbtbl_size) {
  410. kfree(ri);
  411. return NULL;
  412. }
  413. tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
  414. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  415. if (!RB_EMPTY_ROOT(tree)) {
  416. node = rb_first(tree);
  417. r = rb_entry(node, struct dlm_rsb, res_hashnode);
  418. dlm_hold_rsb(r);
  419. ri->rsb = r;
  420. ri->bucket = bucket;
  421. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  422. *pos = n;
  423. return ri;
  424. }
  425. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  426. }
  427. }
  428. static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos)
  429. {
  430. struct dlm_ls *ls = seq->private;
  431. struct rsbtbl_iter *ri = iter_ptr;
  432. struct rb_root *tree;
  433. struct rb_node *next;
  434. struct dlm_rsb *r, *rp;
  435. loff_t n = *pos;
  436. unsigned bucket;
  437. int toss = (seq->op == &format4_seq_ops);
  438. bucket = n >> 32;
  439. /*
  440. * move to the next rsb in the same bucket
  441. */
  442. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  443. rp = ri->rsb;
  444. next = rb_next(&rp->res_hashnode);
  445. if (next) {
  446. r = rb_entry(next, struct dlm_rsb, res_hashnode);
  447. dlm_hold_rsb(r);
  448. ri->rsb = r;
  449. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  450. dlm_put_rsb(rp);
  451. ++*pos;
  452. return ri;
  453. }
  454. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  455. dlm_put_rsb(rp);
  456. /*
  457. * move to the first rsb in the next non-empty bucket
  458. */
  459. /* zero the entry */
  460. n &= ~((1LL << 32) - 1);
  461. while (1) {
  462. bucket++;
  463. n += 1LL << 32;
  464. if (bucket >= ls->ls_rsbtbl_size) {
  465. kfree(ri);
  466. return NULL;
  467. }
  468. tree = toss ? &ls->ls_rsbtbl[bucket].toss : &ls->ls_rsbtbl[bucket].keep;
  469. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  470. if (!RB_EMPTY_ROOT(tree)) {
  471. next = rb_first(tree);
  472. r = rb_entry(next, struct dlm_rsb, res_hashnode);
  473. dlm_hold_rsb(r);
  474. ri->rsb = r;
  475. ri->bucket = bucket;
  476. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  477. *pos = n;
  478. return ri;
  479. }
  480. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  481. }
  482. }
  483. static void table_seq_stop(struct seq_file *seq, void *iter_ptr)
  484. {
  485. struct rsbtbl_iter *ri = iter_ptr;
  486. if (ri) {
  487. dlm_put_rsb(ri->rsb);
  488. kfree(ri);
  489. }
  490. }
  491. static const struct seq_operations format1_seq_ops = {
  492. .start = table_seq_start,
  493. .next = table_seq_next,
  494. .stop = table_seq_stop,
  495. .show = table_seq_show,
  496. };
  497. static const struct seq_operations format2_seq_ops = {
  498. .start = table_seq_start,
  499. .next = table_seq_next,
  500. .stop = table_seq_stop,
  501. .show = table_seq_show,
  502. };
  503. static const struct seq_operations format3_seq_ops = {
  504. .start = table_seq_start,
  505. .next = table_seq_next,
  506. .stop = table_seq_stop,
  507. .show = table_seq_show,
  508. };
  509. static const struct seq_operations format4_seq_ops = {
  510. .start = table_seq_start,
  511. .next = table_seq_next,
  512. .stop = table_seq_stop,
  513. .show = table_seq_show,
  514. };
  515. static const struct file_operations format1_fops;
  516. static const struct file_operations format2_fops;
  517. static const struct file_operations format3_fops;
  518. static const struct file_operations format4_fops;
  519. static int table_open1(struct inode *inode, struct file *file)
  520. {
  521. struct seq_file *seq;
  522. int ret;
  523. ret = seq_open(file, &format1_seq_ops);
  524. if (ret)
  525. return ret;
  526. seq = file->private_data;
  527. seq->private = inode->i_private; /* the dlm_ls */
  528. return 0;
  529. }
  530. static int table_open2(struct inode *inode, struct file *file)
  531. {
  532. struct seq_file *seq;
  533. int ret;
  534. ret = seq_open(file, &format2_seq_ops);
  535. if (ret)
  536. return ret;
  537. seq = file->private_data;
  538. seq->private = inode->i_private; /* the dlm_ls */
  539. return 0;
  540. }
  541. static int table_open3(struct inode *inode, struct file *file)
  542. {
  543. struct seq_file *seq;
  544. int ret;
  545. ret = seq_open(file, &format3_seq_ops);
  546. if (ret)
  547. return ret;
  548. seq = file->private_data;
  549. seq->private = inode->i_private; /* the dlm_ls */
  550. return 0;
  551. }
  552. static int table_open4(struct inode *inode, struct file *file)
  553. {
  554. struct seq_file *seq;
  555. int ret;
  556. ret = seq_open(file, &format4_seq_ops);
  557. if (ret)
  558. return ret;
  559. seq = file->private_data;
  560. seq->private = inode->i_private; /* the dlm_ls */
  561. return 0;
  562. }
  563. static const struct file_operations format1_fops = {
  564. .owner = THIS_MODULE,
  565. .open = table_open1,
  566. .read = seq_read,
  567. .llseek = seq_lseek,
  568. .release = seq_release
  569. };
  570. static const struct file_operations format2_fops = {
  571. .owner = THIS_MODULE,
  572. .open = table_open2,
  573. .read = seq_read,
  574. .llseek = seq_lseek,
  575. .release = seq_release
  576. };
  577. static const struct file_operations format3_fops = {
  578. .owner = THIS_MODULE,
  579. .open = table_open3,
  580. .read = seq_read,
  581. .llseek = seq_lseek,
  582. .release = seq_release
  583. };
  584. static const struct file_operations format4_fops = {
  585. .owner = THIS_MODULE,
  586. .open = table_open4,
  587. .read = seq_read,
  588. .llseek = seq_lseek,
  589. .release = seq_release
  590. };
  591. /*
  592. * dump lkb's on the ls_waiters list
  593. */
  594. static ssize_t waiters_read(struct file *file, char __user *userbuf,
  595. size_t count, loff_t *ppos)
  596. {
  597. struct dlm_ls *ls = file->private_data;
  598. struct dlm_lkb *lkb;
  599. size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv;
  600. mutex_lock(&debug_buf_lock);
  601. mutex_lock(&ls->ls_waiters_mutex);
  602. memset(debug_buf, 0, sizeof(debug_buf));
  603. list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
  604. ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
  605. lkb->lkb_id, lkb->lkb_wait_type,
  606. lkb->lkb_nodeid, lkb->lkb_resource->res_name);
  607. if (ret >= len - pos)
  608. break;
  609. pos += ret;
  610. }
  611. mutex_unlock(&ls->ls_waiters_mutex);
  612. rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos);
  613. mutex_unlock(&debug_buf_lock);
  614. return rv;
  615. }
  616. static const struct file_operations waiters_fops = {
  617. .owner = THIS_MODULE,
  618. .open = simple_open,
  619. .read = waiters_read,
  620. .llseek = default_llseek,
  621. };
  622. void dlm_delete_debug_file(struct dlm_ls *ls)
  623. {
  624. debugfs_remove(ls->ls_debug_rsb_dentry);
  625. debugfs_remove(ls->ls_debug_waiters_dentry);
  626. debugfs_remove(ls->ls_debug_locks_dentry);
  627. debugfs_remove(ls->ls_debug_all_dentry);
  628. debugfs_remove(ls->ls_debug_toss_dentry);
  629. }
  630. int dlm_create_debug_file(struct dlm_ls *ls)
  631. {
  632. char name[DLM_LOCKSPACE_LEN+8];
  633. /* format 1 */
  634. ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name,
  635. S_IFREG | S_IRUGO,
  636. dlm_root,
  637. ls,
  638. &format1_fops);
  639. if (!ls->ls_debug_rsb_dentry)
  640. goto fail;
  641. /* format 2 */
  642. memset(name, 0, sizeof(name));
  643. snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name);
  644. ls->ls_debug_locks_dentry = debugfs_create_file(name,
  645. S_IFREG | S_IRUGO,
  646. dlm_root,
  647. ls,
  648. &format2_fops);
  649. if (!ls->ls_debug_locks_dentry)
  650. goto fail;
  651. /* format 3 */
  652. memset(name, 0, sizeof(name));
  653. snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name);
  654. ls->ls_debug_all_dentry = debugfs_create_file(name,
  655. S_IFREG | S_IRUGO,
  656. dlm_root,
  657. ls,
  658. &format3_fops);
  659. if (!ls->ls_debug_all_dentry)
  660. goto fail;
  661. /* format 4 */
  662. memset(name, 0, sizeof(name));
  663. snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_toss", ls->ls_name);
  664. ls->ls_debug_toss_dentry = debugfs_create_file(name,
  665. S_IFREG | S_IRUGO,
  666. dlm_root,
  667. ls,
  668. &format4_fops);
  669. if (!ls->ls_debug_toss_dentry)
  670. goto fail;
  671. memset(name, 0, sizeof(name));
  672. snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name);
  673. ls->ls_debug_waiters_dentry = debugfs_create_file(name,
  674. S_IFREG | S_IRUGO,
  675. dlm_root,
  676. ls,
  677. &waiters_fops);
  678. if (!ls->ls_debug_waiters_dentry)
  679. goto fail;
  680. return 0;
  681. fail:
  682. dlm_delete_debug_file(ls);
  683. return -ENOMEM;
  684. }
  685. int __init dlm_register_debugfs(void)
  686. {
  687. mutex_init(&debug_buf_lock);
  688. dlm_root = debugfs_create_dir("dlm", NULL);
  689. return dlm_root ? 0 : -ENOMEM;
  690. }
  691. void dlm_unregister_debugfs(void)
  692. {
  693. debugfs_remove(dlm_root);
  694. }