debug_fs.c 19 KB

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