debug_fs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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 int 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. return seq_printf(s, "\n");
  62. }
  63. static int 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. int rv;
  68. lock_rsb(res);
  69. rv = seq_printf(s, "\nResource %p Name (len=%d) \"",
  70. res, res->res_length);
  71. if (rv)
  72. goto out;
  73. for (i = 0; i < res->res_length; i++) {
  74. if (isprint(res->res_name[i]))
  75. seq_printf(s, "%c", res->res_name[i]);
  76. else
  77. seq_printf(s, "%c", '.');
  78. }
  79. if (res->res_nodeid > 0)
  80. rv = seq_printf(s, "\" \nLocal Copy, Master is node %d\n",
  81. res->res_nodeid);
  82. else if (res->res_nodeid == 0)
  83. rv = seq_printf(s, "\" \nMaster Copy\n");
  84. else if (res->res_nodeid == -1)
  85. rv = seq_printf(s, "\" \nLooking up master (lkid %x)\n",
  86. res->res_first_lkid);
  87. else
  88. rv = seq_printf(s, "\" \nInvalid master %d\n",
  89. res->res_nodeid);
  90. if (rv)
  91. goto out;
  92. /* Print the LVB: */
  93. if (res->res_lvbptr) {
  94. seq_printf(s, "LVB: ");
  95. for (i = 0; i < lvblen; i++) {
  96. if (i == lvblen / 2)
  97. seq_printf(s, "\n ");
  98. seq_printf(s, "%02x ",
  99. (unsigned char) res->res_lvbptr[i]);
  100. }
  101. if (rsb_flag(res, RSB_VALNOTVALID))
  102. seq_printf(s, " (INVALID)");
  103. rv = seq_printf(s, "\n");
  104. if (rv)
  105. goto out;
  106. }
  107. root_list = !list_empty(&res->res_root_list);
  108. recover_list = !list_empty(&res->res_recover_list);
  109. if (root_list || recover_list) {
  110. rv = seq_printf(s, "Recovery: root %d recover %d flags %lx "
  111. "count %d\n", root_list, recover_list,
  112. res->res_flags, res->res_recover_locks_count);
  113. if (rv)
  114. goto out;
  115. }
  116. /* Print the locks attached to this resource */
  117. seq_printf(s, "Granted Queue\n");
  118. list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) {
  119. rv = print_format1_lock(s, lkb, res);
  120. if (rv)
  121. goto out;
  122. }
  123. seq_printf(s, "Conversion Queue\n");
  124. list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) {
  125. rv = print_format1_lock(s, lkb, res);
  126. if (rv)
  127. goto out;
  128. }
  129. seq_printf(s, "Waiting Queue\n");
  130. list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) {
  131. rv = print_format1_lock(s, lkb, res);
  132. if (rv)
  133. goto out;
  134. }
  135. if (list_empty(&res->res_lookup))
  136. goto out;
  137. seq_printf(s, "Lookup Queue\n");
  138. list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) {
  139. rv = seq_printf(s, "%08x %s", lkb->lkb_id,
  140. print_lockmode(lkb->lkb_rqmode));
  141. if (lkb->lkb_wait_type)
  142. seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
  143. rv = seq_printf(s, "\n");
  144. }
  145. out:
  146. unlock_rsb(res);
  147. return rv;
  148. }
  149. static int print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
  150. struct dlm_rsb *r)
  151. {
  152. u64 xid = 0;
  153. u64 us;
  154. int rv;
  155. if (lkb->lkb_flags & DLM_IFL_USER) {
  156. if (lkb->lkb_ua)
  157. xid = lkb->lkb_ua->xid;
  158. }
  159. /* microseconds since lkb was added to current queue */
  160. us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_timestamp));
  161. /* id nodeid remid pid xid exflags flags sts grmode rqmode time_us
  162. r_nodeid r_len r_name */
  163. rv = seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
  164. lkb->lkb_id,
  165. lkb->lkb_nodeid,
  166. lkb->lkb_remid,
  167. lkb->lkb_ownpid,
  168. (unsigned long long)xid,
  169. lkb->lkb_exflags,
  170. lkb->lkb_flags,
  171. lkb->lkb_status,
  172. lkb->lkb_grmode,
  173. lkb->lkb_rqmode,
  174. (unsigned long long)us,
  175. r->res_nodeid,
  176. r->res_length,
  177. r->res_name);
  178. return rv;
  179. }
  180. static int print_format2(struct dlm_rsb *r, struct seq_file *s)
  181. {
  182. struct dlm_lkb *lkb;
  183. int rv = 0;
  184. lock_rsb(r);
  185. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  186. rv = print_format2_lock(s, lkb, r);
  187. if (rv)
  188. goto out;
  189. }
  190. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  191. rv = print_format2_lock(s, lkb, r);
  192. if (rv)
  193. goto out;
  194. }
  195. list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
  196. rv = print_format2_lock(s, lkb, r);
  197. if (rv)
  198. goto out;
  199. }
  200. out:
  201. unlock_rsb(r);
  202. return rv;
  203. }
  204. static int print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
  205. int rsb_lookup)
  206. {
  207. u64 xid = 0;
  208. int rv;
  209. if (lkb->lkb_flags & DLM_IFL_USER) {
  210. if (lkb->lkb_ua)
  211. xid = lkb->lkb_ua->xid;
  212. }
  213. rv = seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
  214. lkb->lkb_id,
  215. lkb->lkb_nodeid,
  216. lkb->lkb_remid,
  217. lkb->lkb_ownpid,
  218. (unsigned long long)xid,
  219. lkb->lkb_exflags,
  220. lkb->lkb_flags,
  221. lkb->lkb_status,
  222. lkb->lkb_grmode,
  223. lkb->lkb_rqmode,
  224. lkb->lkb_last_bast.mode,
  225. rsb_lookup,
  226. lkb->lkb_wait_type,
  227. lkb->lkb_lvbseq,
  228. (unsigned long long)ktime_to_ns(lkb->lkb_timestamp),
  229. (unsigned long long)ktime_to_ns(lkb->lkb_last_bast_time));
  230. return rv;
  231. }
  232. static int print_format3(struct dlm_rsb *r, struct seq_file *s)
  233. {
  234. struct dlm_lkb *lkb;
  235. int i, lvblen = r->res_ls->ls_lvblen;
  236. int print_name = 1;
  237. int rv;
  238. lock_rsb(r);
  239. rv = seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
  240. r,
  241. r->res_nodeid,
  242. r->res_first_lkid,
  243. r->res_flags,
  244. !list_empty(&r->res_root_list),
  245. !list_empty(&r->res_recover_list),
  246. r->res_recover_locks_count,
  247. r->res_length);
  248. if (rv)
  249. goto out;
  250. for (i = 0; i < r->res_length; i++) {
  251. if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
  252. print_name = 0;
  253. }
  254. seq_printf(s, "%s", print_name ? "str " : "hex");
  255. for (i = 0; i < r->res_length; i++) {
  256. if (print_name)
  257. seq_printf(s, "%c", r->res_name[i]);
  258. else
  259. seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
  260. }
  261. rv = seq_printf(s, "\n");
  262. if (rv)
  263. goto out;
  264. if (!r->res_lvbptr)
  265. goto do_locks;
  266. seq_printf(s, "lvb %u %d", r->res_lvbseq, lvblen);
  267. for (i = 0; i < lvblen; i++)
  268. seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
  269. rv = seq_printf(s, "\n");
  270. if (rv)
  271. goto out;
  272. do_locks:
  273. list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
  274. rv = print_format3_lock(s, lkb, 0);
  275. if (rv)
  276. goto out;
  277. }
  278. list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
  279. rv = print_format3_lock(s, lkb, 0);
  280. if (rv)
  281. goto out;
  282. }
  283. list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
  284. rv = print_format3_lock(s, lkb, 0);
  285. if (rv)
  286. goto out;
  287. }
  288. list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) {
  289. rv = print_format3_lock(s, lkb, 1);
  290. if (rv)
  291. goto out;
  292. }
  293. out:
  294. unlock_rsb(r);
  295. return rv;
  296. }
  297. struct rsbtbl_iter {
  298. struct dlm_rsb *rsb;
  299. unsigned bucket;
  300. int format;
  301. int header;
  302. };
  303. /* seq_printf returns -1 if the buffer is full, and 0 otherwise.
  304. If the buffer is full, seq_printf can be called again, but it
  305. does nothing and just returns -1. So, the these printing routines
  306. periodically check the return value to avoid wasting too much time
  307. trying to print to a full buffer. */
  308. static int table_seq_show(struct seq_file *seq, void *iter_ptr)
  309. {
  310. struct rsbtbl_iter *ri = iter_ptr;
  311. int rv = 0;
  312. switch (ri->format) {
  313. case 1:
  314. rv = print_format1(ri->rsb, seq);
  315. break;
  316. case 2:
  317. if (ri->header) {
  318. seq_printf(seq, "id nodeid remid pid xid exflags "
  319. "flags sts grmode rqmode time_ms "
  320. "r_nodeid r_len r_name\n");
  321. ri->header = 0;
  322. }
  323. rv = print_format2(ri->rsb, seq);
  324. break;
  325. case 3:
  326. if (ri->header) {
  327. seq_printf(seq, "version rsb 1.1 lvb 1.1 lkb 1.1\n");
  328. ri->header = 0;
  329. }
  330. rv = print_format3(ri->rsb, seq);
  331. break;
  332. }
  333. return rv;
  334. }
  335. static const struct seq_operations format1_seq_ops;
  336. static const struct seq_operations format2_seq_ops;
  337. static const struct seq_operations format3_seq_ops;
  338. static void *table_seq_start(struct seq_file *seq, loff_t *pos)
  339. {
  340. struct rb_node *node;
  341. struct dlm_ls *ls = seq->private;
  342. struct rsbtbl_iter *ri;
  343. struct dlm_rsb *r;
  344. loff_t n = *pos;
  345. unsigned bucket, entry;
  346. bucket = n >> 32;
  347. entry = n & ((1LL << 32) - 1);
  348. if (bucket >= ls->ls_rsbtbl_size)
  349. return NULL;
  350. ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS);
  351. if (!ri)
  352. return NULL;
  353. if (n == 0)
  354. ri->header = 1;
  355. if (seq->op == &format1_seq_ops)
  356. ri->format = 1;
  357. if (seq->op == &format2_seq_ops)
  358. ri->format = 2;
  359. if (seq->op == &format3_seq_ops)
  360. ri->format = 3;
  361. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  362. if (!RB_EMPTY_ROOT(&ls->ls_rsbtbl[bucket].keep)) {
  363. for (node = rb_first(&ls->ls_rsbtbl[bucket].keep); node;
  364. node = rb_next(node)) {
  365. r = rb_entry(node, struct dlm_rsb, res_hashnode);
  366. if (!entry--) {
  367. dlm_hold_rsb(r);
  368. ri->rsb = r;
  369. ri->bucket = bucket;
  370. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  371. return ri;
  372. }
  373. }
  374. }
  375. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  376. /*
  377. * move to the first rsb in the next non-empty bucket
  378. */
  379. /* zero the entry */
  380. n &= ~((1LL << 32) - 1);
  381. while (1) {
  382. bucket++;
  383. n += 1LL << 32;
  384. if (bucket >= ls->ls_rsbtbl_size) {
  385. kfree(ri);
  386. return NULL;
  387. }
  388. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  389. if (!RB_EMPTY_ROOT(&ls->ls_rsbtbl[bucket].keep)) {
  390. node = rb_first(&ls->ls_rsbtbl[bucket].keep);
  391. r = rb_entry(node, struct dlm_rsb, res_hashnode);
  392. dlm_hold_rsb(r);
  393. ri->rsb = r;
  394. ri->bucket = bucket;
  395. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  396. *pos = n;
  397. return ri;
  398. }
  399. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  400. }
  401. }
  402. static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos)
  403. {
  404. struct dlm_ls *ls = seq->private;
  405. struct rsbtbl_iter *ri = iter_ptr;
  406. struct rb_node *next;
  407. struct dlm_rsb *r, *rp;
  408. loff_t n = *pos;
  409. unsigned bucket;
  410. bucket = n >> 32;
  411. /*
  412. * move to the next rsb in the same bucket
  413. */
  414. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  415. rp = ri->rsb;
  416. next = rb_next(&rp->res_hashnode);
  417. if (next) {
  418. r = rb_entry(next, struct dlm_rsb, res_hashnode);
  419. dlm_hold_rsb(r);
  420. ri->rsb = r;
  421. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  422. dlm_put_rsb(rp);
  423. ++*pos;
  424. return ri;
  425. }
  426. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  427. dlm_put_rsb(rp);
  428. /*
  429. * move to the first rsb in the next non-empty bucket
  430. */
  431. /* zero the entry */
  432. n &= ~((1LL << 32) - 1);
  433. while (1) {
  434. bucket++;
  435. n += 1LL << 32;
  436. if (bucket >= ls->ls_rsbtbl_size) {
  437. kfree(ri);
  438. return NULL;
  439. }
  440. spin_lock(&ls->ls_rsbtbl[bucket].lock);
  441. if (!RB_EMPTY_ROOT(&ls->ls_rsbtbl[bucket].keep)) {
  442. next = rb_first(&ls->ls_rsbtbl[bucket].keep);
  443. r = rb_entry(next, struct dlm_rsb, res_hashnode);
  444. dlm_hold_rsb(r);
  445. ri->rsb = r;
  446. ri->bucket = bucket;
  447. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  448. *pos = n;
  449. return ri;
  450. }
  451. spin_unlock(&ls->ls_rsbtbl[bucket].lock);
  452. }
  453. }
  454. static void table_seq_stop(struct seq_file *seq, void *iter_ptr)
  455. {
  456. struct rsbtbl_iter *ri = iter_ptr;
  457. if (ri) {
  458. dlm_put_rsb(ri->rsb);
  459. kfree(ri);
  460. }
  461. }
  462. static const struct seq_operations format1_seq_ops = {
  463. .start = table_seq_start,
  464. .next = table_seq_next,
  465. .stop = table_seq_stop,
  466. .show = table_seq_show,
  467. };
  468. static const struct seq_operations format2_seq_ops = {
  469. .start = table_seq_start,
  470. .next = table_seq_next,
  471. .stop = table_seq_stop,
  472. .show = table_seq_show,
  473. };
  474. static const struct seq_operations format3_seq_ops = {
  475. .start = table_seq_start,
  476. .next = table_seq_next,
  477. .stop = table_seq_stop,
  478. .show = table_seq_show,
  479. };
  480. static const struct file_operations format1_fops;
  481. static const struct file_operations format2_fops;
  482. static const struct file_operations format3_fops;
  483. static int table_open(struct inode *inode, struct file *file)
  484. {
  485. struct seq_file *seq;
  486. int ret = -1;
  487. if (file->f_op == &format1_fops)
  488. ret = seq_open(file, &format1_seq_ops);
  489. else if (file->f_op == &format2_fops)
  490. ret = seq_open(file, &format2_seq_ops);
  491. else if (file->f_op == &format3_fops)
  492. ret = seq_open(file, &format3_seq_ops);
  493. if (ret)
  494. return ret;
  495. seq = file->private_data;
  496. seq->private = inode->i_private; /* the dlm_ls */
  497. return 0;
  498. }
  499. static const struct file_operations format1_fops = {
  500. .owner = THIS_MODULE,
  501. .open = table_open,
  502. .read = seq_read,
  503. .llseek = seq_lseek,
  504. .release = seq_release
  505. };
  506. static const struct file_operations format2_fops = {
  507. .owner = THIS_MODULE,
  508. .open = table_open,
  509. .read = seq_read,
  510. .llseek = seq_lseek,
  511. .release = seq_release
  512. };
  513. static const struct file_operations format3_fops = {
  514. .owner = THIS_MODULE,
  515. .open = table_open,
  516. .read = seq_read,
  517. .llseek = seq_lseek,
  518. .release = seq_release
  519. };
  520. /*
  521. * dump lkb's on the ls_waiters list
  522. */
  523. static ssize_t waiters_read(struct file *file, char __user *userbuf,
  524. size_t count, loff_t *ppos)
  525. {
  526. struct dlm_ls *ls = file->private_data;
  527. struct dlm_lkb *lkb;
  528. size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv;
  529. mutex_lock(&debug_buf_lock);
  530. mutex_lock(&ls->ls_waiters_mutex);
  531. memset(debug_buf, 0, sizeof(debug_buf));
  532. list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
  533. ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
  534. lkb->lkb_id, lkb->lkb_wait_type,
  535. lkb->lkb_nodeid, lkb->lkb_resource->res_name);
  536. if (ret >= len - pos)
  537. break;
  538. pos += ret;
  539. }
  540. mutex_unlock(&ls->ls_waiters_mutex);
  541. rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos);
  542. mutex_unlock(&debug_buf_lock);
  543. return rv;
  544. }
  545. static const struct file_operations waiters_fops = {
  546. .owner = THIS_MODULE,
  547. .open = simple_open,
  548. .read = waiters_read,
  549. .llseek = default_llseek,
  550. };
  551. void dlm_delete_debug_file(struct dlm_ls *ls)
  552. {
  553. if (ls->ls_debug_rsb_dentry)
  554. debugfs_remove(ls->ls_debug_rsb_dentry);
  555. if (ls->ls_debug_waiters_dentry)
  556. debugfs_remove(ls->ls_debug_waiters_dentry);
  557. if (ls->ls_debug_locks_dentry)
  558. debugfs_remove(ls->ls_debug_locks_dentry);
  559. if (ls->ls_debug_all_dentry)
  560. debugfs_remove(ls->ls_debug_all_dentry);
  561. }
  562. int dlm_create_debug_file(struct dlm_ls *ls)
  563. {
  564. char name[DLM_LOCKSPACE_LEN+8];
  565. /* format 1 */
  566. ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name,
  567. S_IFREG | S_IRUGO,
  568. dlm_root,
  569. ls,
  570. &format1_fops);
  571. if (!ls->ls_debug_rsb_dentry)
  572. goto fail;
  573. /* format 2 */
  574. memset(name, 0, sizeof(name));
  575. snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name);
  576. ls->ls_debug_locks_dentry = debugfs_create_file(name,
  577. S_IFREG | S_IRUGO,
  578. dlm_root,
  579. ls,
  580. &format2_fops);
  581. if (!ls->ls_debug_locks_dentry)
  582. goto fail;
  583. /* format 3 */
  584. memset(name, 0, sizeof(name));
  585. snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name);
  586. ls->ls_debug_all_dentry = debugfs_create_file(name,
  587. S_IFREG | S_IRUGO,
  588. dlm_root,
  589. ls,
  590. &format3_fops);
  591. if (!ls->ls_debug_all_dentry)
  592. goto fail;
  593. memset(name, 0, sizeof(name));
  594. snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name);
  595. ls->ls_debug_waiters_dentry = debugfs_create_file(name,
  596. S_IFREG | S_IRUGO,
  597. dlm_root,
  598. ls,
  599. &waiters_fops);
  600. if (!ls->ls_debug_waiters_dentry)
  601. goto fail;
  602. return 0;
  603. fail:
  604. dlm_delete_debug_file(ls);
  605. return -ENOMEM;
  606. }
  607. int __init dlm_register_debugfs(void)
  608. {
  609. mutex_init(&debug_buf_lock);
  610. dlm_root = debugfs_create_dir("dlm", NULL);
  611. return dlm_root ? 0 : -ENOMEM;
  612. }
  613. void dlm_unregister_debugfs(void)
  614. {
  615. debugfs_remove(dlm_root);
  616. }