dlmdebug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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 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. void dlm_print_one_lock_resource(struct dlm_lock_resource *res)
  43. {
  44. mlog(ML_NOTICE, "lockres: %.*s, owner=%u, state=%u\n",
  45. res->lockname.len, res->lockname.name,
  46. res->owner, res->state);
  47. spin_lock(&res->spinlock);
  48. __dlm_print_one_lock_resource(res);
  49. spin_unlock(&res->spinlock);
  50. }
  51. static void dlm_print_lockres_refmap(struct dlm_lock_resource *res)
  52. {
  53. int bit;
  54. assert_spin_locked(&res->spinlock);
  55. mlog(ML_NOTICE, " refmap nodes: [ ");
  56. bit = 0;
  57. while (1) {
  58. bit = find_next_bit(res->refmap, O2NM_MAX_NODES, bit);
  59. if (bit >= O2NM_MAX_NODES)
  60. break;
  61. printk("%u ", bit);
  62. bit++;
  63. }
  64. printk("], inflight=%u\n", res->inflight_locks);
  65. }
  66. void __dlm_print_one_lock_resource(struct dlm_lock_resource *res)
  67. {
  68. struct list_head *iter2;
  69. struct dlm_lock *lock;
  70. assert_spin_locked(&res->spinlock);
  71. mlog(ML_NOTICE, "lockres: %.*s, owner=%u, state=%u\n",
  72. res->lockname.len, res->lockname.name,
  73. res->owner, res->state);
  74. mlog(ML_NOTICE, " last used: %lu, on purge list: %s\n",
  75. res->last_used, list_empty(&res->purge) ? "no" : "yes");
  76. dlm_print_lockres_refmap(res);
  77. mlog(ML_NOTICE, " granted queue: \n");
  78. list_for_each(iter2, &res->granted) {
  79. lock = list_entry(iter2, struct dlm_lock, list);
  80. spin_lock(&lock->spinlock);
  81. mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
  82. "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
  83. lock->ml.type, lock->ml.convert_type, lock->ml.node,
  84. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  85. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  86. list_empty(&lock->ast_list) ? 'y' : 'n',
  87. lock->ast_pending ? 'y' : 'n',
  88. list_empty(&lock->bast_list) ? 'y' : 'n',
  89. lock->bast_pending ? 'y' : 'n');
  90. spin_unlock(&lock->spinlock);
  91. }
  92. mlog(ML_NOTICE, " converting queue: \n");
  93. list_for_each(iter2, &res->converting) {
  94. lock = list_entry(iter2, struct dlm_lock, list);
  95. spin_lock(&lock->spinlock);
  96. mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
  97. "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
  98. lock->ml.type, lock->ml.convert_type, lock->ml.node,
  99. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  100. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  101. list_empty(&lock->ast_list) ? 'y' : 'n',
  102. lock->ast_pending ? 'y' : 'n',
  103. list_empty(&lock->bast_list) ? 'y' : 'n',
  104. lock->bast_pending ? 'y' : 'n');
  105. spin_unlock(&lock->spinlock);
  106. }
  107. mlog(ML_NOTICE, " blocked queue: \n");
  108. list_for_each(iter2, &res->blocked) {
  109. lock = list_entry(iter2, struct dlm_lock, list);
  110. spin_lock(&lock->spinlock);
  111. mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
  112. "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
  113. lock->ml.type, lock->ml.convert_type, lock->ml.node,
  114. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  115. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  116. list_empty(&lock->ast_list) ? 'y' : 'n',
  117. lock->ast_pending ? 'y' : 'n',
  118. list_empty(&lock->bast_list) ? 'y' : 'n',
  119. lock->bast_pending ? 'y' : 'n');
  120. spin_unlock(&lock->spinlock);
  121. }
  122. }
  123. void dlm_print_one_lock(struct dlm_lock *lockid)
  124. {
  125. dlm_print_one_lock_resource(lockid->lockres);
  126. }
  127. EXPORT_SYMBOL_GPL(dlm_print_one_lock);
  128. #if 0
  129. void dlm_dump_lock_resources(struct dlm_ctxt *dlm)
  130. {
  131. struct dlm_lock_resource *res;
  132. struct hlist_node *iter;
  133. struct hlist_head *bucket;
  134. int i;
  135. mlog(ML_NOTICE, "struct dlm_ctxt: %s, node=%u, key=%u\n",
  136. dlm->name, dlm->node_num, dlm->key);
  137. if (!dlm || !dlm->name) {
  138. mlog(ML_ERROR, "dlm=%p\n", dlm);
  139. return;
  140. }
  141. spin_lock(&dlm->spinlock);
  142. for (i=0; i<DLM_HASH_BUCKETS; i++) {
  143. bucket = dlm_lockres_hash(dlm, i);
  144. hlist_for_each_entry(res, iter, bucket, hash_node)
  145. dlm_print_one_lock_resource(res);
  146. }
  147. spin_unlock(&dlm->spinlock);
  148. }
  149. #endif /* 0 */
  150. static const char *dlm_errnames[] = {
  151. [DLM_NORMAL] = "DLM_NORMAL",
  152. [DLM_GRANTED] = "DLM_GRANTED",
  153. [DLM_DENIED] = "DLM_DENIED",
  154. [DLM_DENIED_NOLOCKS] = "DLM_DENIED_NOLOCKS",
  155. [DLM_WORKING] = "DLM_WORKING",
  156. [DLM_BLOCKED] = "DLM_BLOCKED",
  157. [DLM_BLOCKED_ORPHAN] = "DLM_BLOCKED_ORPHAN",
  158. [DLM_DENIED_GRACE_PERIOD] = "DLM_DENIED_GRACE_PERIOD",
  159. [DLM_SYSERR] = "DLM_SYSERR",
  160. [DLM_NOSUPPORT] = "DLM_NOSUPPORT",
  161. [DLM_CANCELGRANT] = "DLM_CANCELGRANT",
  162. [DLM_IVLOCKID] = "DLM_IVLOCKID",
  163. [DLM_SYNC] = "DLM_SYNC",
  164. [DLM_BADTYPE] = "DLM_BADTYPE",
  165. [DLM_BADRESOURCE] = "DLM_BADRESOURCE",
  166. [DLM_MAXHANDLES] = "DLM_MAXHANDLES",
  167. [DLM_NOCLINFO] = "DLM_NOCLINFO",
  168. [DLM_NOLOCKMGR] = "DLM_NOLOCKMGR",
  169. [DLM_NOPURGED] = "DLM_NOPURGED",
  170. [DLM_BADARGS] = "DLM_BADARGS",
  171. [DLM_VOID] = "DLM_VOID",
  172. [DLM_NOTQUEUED] = "DLM_NOTQUEUED",
  173. [DLM_IVBUFLEN] = "DLM_IVBUFLEN",
  174. [DLM_CVTUNGRANT] = "DLM_CVTUNGRANT",
  175. [DLM_BADPARAM] = "DLM_BADPARAM",
  176. [DLM_VALNOTVALID] = "DLM_VALNOTVALID",
  177. [DLM_REJECTED] = "DLM_REJECTED",
  178. [DLM_ABORT] = "DLM_ABORT",
  179. [DLM_CANCEL] = "DLM_CANCEL",
  180. [DLM_IVRESHANDLE] = "DLM_IVRESHANDLE",
  181. [DLM_DEADLOCK] = "DLM_DEADLOCK",
  182. [DLM_DENIED_NOASTS] = "DLM_DENIED_NOASTS",
  183. [DLM_FORWARD] = "DLM_FORWARD",
  184. [DLM_TIMEOUT] = "DLM_TIMEOUT",
  185. [DLM_IVGROUPID] = "DLM_IVGROUPID",
  186. [DLM_VERS_CONFLICT] = "DLM_VERS_CONFLICT",
  187. [DLM_BAD_DEVICE_PATH] = "DLM_BAD_DEVICE_PATH",
  188. [DLM_NO_DEVICE_PERMISSION] = "DLM_NO_DEVICE_PERMISSION",
  189. [DLM_NO_CONTROL_DEVICE ] = "DLM_NO_CONTROL_DEVICE ",
  190. [DLM_RECOVERING] = "DLM_RECOVERING",
  191. [DLM_MIGRATING] = "DLM_MIGRATING",
  192. [DLM_MAXSTATS] = "DLM_MAXSTATS",
  193. };
  194. static const char *dlm_errmsgs[] = {
  195. [DLM_NORMAL] = "request in progress",
  196. [DLM_GRANTED] = "request granted",
  197. [DLM_DENIED] = "request denied",
  198. [DLM_DENIED_NOLOCKS] = "request denied, out of system resources",
  199. [DLM_WORKING] = "async request in progress",
  200. [DLM_BLOCKED] = "lock request blocked",
  201. [DLM_BLOCKED_ORPHAN] = "lock request blocked by a orphan lock",
  202. [DLM_DENIED_GRACE_PERIOD] = "topological change in progress",
  203. [DLM_SYSERR] = "system error",
  204. [DLM_NOSUPPORT] = "unsupported",
  205. [DLM_CANCELGRANT] = "can't cancel convert: already granted",
  206. [DLM_IVLOCKID] = "bad lockid",
  207. [DLM_SYNC] = "synchronous request granted",
  208. [DLM_BADTYPE] = "bad resource type",
  209. [DLM_BADRESOURCE] = "bad resource handle",
  210. [DLM_MAXHANDLES] = "no more resource handles",
  211. [DLM_NOCLINFO] = "can't contact cluster manager",
  212. [DLM_NOLOCKMGR] = "can't contact lock manager",
  213. [DLM_NOPURGED] = "can't contact purge daemon",
  214. [DLM_BADARGS] = "bad api args",
  215. [DLM_VOID] = "no status",
  216. [DLM_NOTQUEUED] = "NOQUEUE was specified and request failed",
  217. [DLM_IVBUFLEN] = "invalid resource name length",
  218. [DLM_CVTUNGRANT] = "attempted to convert ungranted lock",
  219. [DLM_BADPARAM] = "invalid lock mode specified",
  220. [DLM_VALNOTVALID] = "value block has been invalidated",
  221. [DLM_REJECTED] = "request rejected, unrecognized client",
  222. [DLM_ABORT] = "blocked lock request cancelled",
  223. [DLM_CANCEL] = "conversion request cancelled",
  224. [DLM_IVRESHANDLE] = "invalid resource handle",
  225. [DLM_DEADLOCK] = "deadlock recovery refused this request",
  226. [DLM_DENIED_NOASTS] = "failed to allocate AST",
  227. [DLM_FORWARD] = "request must wait for primary's response",
  228. [DLM_TIMEOUT] = "timeout value for lock has expired",
  229. [DLM_IVGROUPID] = "invalid group specification",
  230. [DLM_VERS_CONFLICT] = "version conflicts prevent request handling",
  231. [DLM_BAD_DEVICE_PATH] = "Locks device does not exist or path wrong",
  232. [DLM_NO_DEVICE_PERMISSION] = "Client has insufficient perms for device",
  233. [DLM_NO_CONTROL_DEVICE] = "Cannot set options on opened device ",
  234. [DLM_RECOVERING] = "lock resource being recovered",
  235. [DLM_MIGRATING] = "lock resource being migrated",
  236. [DLM_MAXSTATS] = "invalid error number",
  237. };
  238. const char *dlm_errmsg(enum dlm_status err)
  239. {
  240. if (err >= DLM_MAXSTATS || err < 0)
  241. return dlm_errmsgs[DLM_MAXSTATS];
  242. return dlm_errmsgs[err];
  243. }
  244. EXPORT_SYMBOL_GPL(dlm_errmsg);
  245. const char *dlm_errname(enum dlm_status err)
  246. {
  247. if (err >= DLM_MAXSTATS || err < 0)
  248. return dlm_errnames[DLM_MAXSTATS];
  249. return dlm_errnames[err];
  250. }
  251. EXPORT_SYMBOL_GPL(dlm_errname);
  252. #ifdef CONFIG_DEBUG_FS
  253. static struct dentry *dlm_debugfs_root = NULL;
  254. #define DLM_DEBUGFS_DIR "o2dlm"
  255. #define DLM_DEBUGFS_DLM_STATE "dlm_state"
  256. /* begin - utils funcs */
  257. static void dlm_debug_free(struct kref *kref)
  258. {
  259. struct dlm_debug_ctxt *dc;
  260. dc = container_of(kref, struct dlm_debug_ctxt, debug_refcnt);
  261. kfree(dc);
  262. }
  263. void dlm_debug_put(struct dlm_debug_ctxt *dc)
  264. {
  265. if (dc)
  266. kref_put(&dc->debug_refcnt, dlm_debug_free);
  267. }
  268. static void dlm_debug_get(struct dlm_debug_ctxt *dc)
  269. {
  270. kref_get(&dc->debug_refcnt);
  271. }
  272. static int stringify_nodemap(unsigned long *nodemap, int maxnodes,
  273. char *buf, int len)
  274. {
  275. int out = 0;
  276. int i = -1;
  277. while ((i = find_next_bit(nodemap, maxnodes, i + 1)) < maxnodes)
  278. out += snprintf(buf + out, len - out, "%d ", i);
  279. return out;
  280. }
  281. static struct debug_buffer *debug_buffer_allocate(void)
  282. {
  283. struct debug_buffer *db = NULL;
  284. db = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
  285. if (!db)
  286. goto bail;
  287. db->len = PAGE_SIZE;
  288. db->buf = kmalloc(db->len, GFP_KERNEL);
  289. if (!db->buf)
  290. goto bail;
  291. return db;
  292. bail:
  293. kfree(db);
  294. return NULL;
  295. }
  296. static ssize_t debug_buffer_read(struct file *file, char __user *buf,
  297. size_t nbytes, loff_t *ppos)
  298. {
  299. struct debug_buffer *db = file->private_data;
  300. return simple_read_from_buffer(buf, nbytes, ppos, db->buf, db->len);
  301. }
  302. static loff_t debug_buffer_llseek(struct file *file, loff_t off, int whence)
  303. {
  304. struct debug_buffer *db = file->private_data;
  305. loff_t new = -1;
  306. switch (whence) {
  307. case 0:
  308. new = off;
  309. break;
  310. case 1:
  311. new = file->f_pos + off;
  312. break;
  313. }
  314. if (new < 0 || new > db->len)
  315. return -EINVAL;
  316. return (file->f_pos = new);
  317. }
  318. static int debug_buffer_release(struct inode *inode, struct file *file)
  319. {
  320. struct debug_buffer *db = (struct debug_buffer *)file->private_data;
  321. if (db)
  322. kfree(db->buf);
  323. kfree(db);
  324. return 0;
  325. }
  326. /* end - util funcs */
  327. /* begin - debug state funcs */
  328. static int debug_state_print(struct dlm_ctxt *dlm, struct debug_buffer *db)
  329. {
  330. int out = 0;
  331. struct dlm_reco_node_data *node;
  332. char *state;
  333. int lres, rres, ures, tres;
  334. lres = atomic_read(&dlm->local_resources);
  335. rres = atomic_read(&dlm->remote_resources);
  336. ures = atomic_read(&dlm->unknown_resources);
  337. tres = lres + rres + ures;
  338. spin_lock(&dlm->spinlock);
  339. switch (dlm->dlm_state) {
  340. case DLM_CTXT_NEW:
  341. state = "NEW"; break;
  342. case DLM_CTXT_JOINED:
  343. state = "JOINED"; break;
  344. case DLM_CTXT_IN_SHUTDOWN:
  345. state = "SHUTDOWN"; break;
  346. case DLM_CTXT_LEAVING:
  347. state = "LEAVING"; break;
  348. default:
  349. state = "UNKNOWN"; break;
  350. }
  351. /* Domain: xxxxxxxxxx Key: 0xdfbac769 */
  352. out += snprintf(db->buf + out, db->len - out,
  353. "Domain: %s Key: 0x%08x\n", dlm->name, dlm->key);
  354. /* Thread Pid: xxx Node: xxx State: xxxxx */
  355. out += snprintf(db->buf + out, db->len - out,
  356. "Thread Pid: %d Node: %d State: %s\n",
  357. dlm->dlm_thread_task->pid, dlm->node_num, state);
  358. /* Number of Joins: xxx Joining Node: xxx */
  359. out += snprintf(db->buf + out, db->len - out,
  360. "Number of Joins: %d Joining Node: %d\n",
  361. dlm->num_joins, dlm->joining_node);
  362. /* Domain Map: xx xx xx */
  363. out += snprintf(db->buf + out, db->len - out, "Domain Map: ");
  364. out += stringify_nodemap(dlm->domain_map, O2NM_MAX_NODES,
  365. db->buf + out, db->len - out);
  366. out += snprintf(db->buf + out, db->len - out, "\n");
  367. /* Live Map: xx xx xx */
  368. out += snprintf(db->buf + out, db->len - out, "Live Map: ");
  369. out += stringify_nodemap(dlm->live_nodes_map, O2NM_MAX_NODES,
  370. db->buf + out, db->len - out);
  371. out += snprintf(db->buf + out, db->len - out, "\n");
  372. /* Mastered Resources Total: xxx Locally: xxx Remotely: ... */
  373. out += snprintf(db->buf + out, db->len - out,
  374. "Mastered Resources Total: %d Locally: %d "
  375. "Remotely: %d Unknown: %d\n",
  376. tres, lres, rres, ures);
  377. /* Lists: Dirty=Empty Purge=InUse PendingASTs=Empty ... */
  378. out += snprintf(db->buf + out, db->len - out,
  379. "Lists: Dirty=%s Purge=%s PendingASTs=%s "
  380. "PendingBASTs=%s Master=%s\n",
  381. (list_empty(&dlm->dirty_list) ? "Empty" : "InUse"),
  382. (list_empty(&dlm->purge_list) ? "Empty" : "InUse"),
  383. (list_empty(&dlm->pending_asts) ? "Empty" : "InUse"),
  384. (list_empty(&dlm->pending_basts) ? "Empty" : "InUse"),
  385. (list_empty(&dlm->master_list) ? "Empty" : "InUse"));
  386. /* Purge Count: xxx Refs: xxx */
  387. out += snprintf(db->buf + out, db->len - out,
  388. "Purge Count: %d Refs: %d\n", dlm->purge_count,
  389. atomic_read(&dlm->dlm_refs.refcount));
  390. /* Dead Node: xxx */
  391. out += snprintf(db->buf + out, db->len - out,
  392. "Dead Node: %d\n", dlm->reco.dead_node);
  393. /* What about DLM_RECO_STATE_FINALIZE? */
  394. if (dlm->reco.state == DLM_RECO_STATE_ACTIVE)
  395. state = "ACTIVE";
  396. else
  397. state = "INACTIVE";
  398. /* Recovery Pid: xxxx Master: xxx State: xxxx */
  399. out += snprintf(db->buf + out, db->len - out,
  400. "Recovery Pid: %d Master: %d State: %s\n",
  401. dlm->dlm_reco_thread_task->pid,
  402. dlm->reco.new_master, state);
  403. /* Recovery Map: xx xx */
  404. out += snprintf(db->buf + out, db->len - out, "Recovery Map: ");
  405. out += stringify_nodemap(dlm->recovery_map, O2NM_MAX_NODES,
  406. db->buf + out, db->len - out);
  407. out += snprintf(db->buf + out, db->len - out, "\n");
  408. /* Recovery Node State: */
  409. out += snprintf(db->buf + out, db->len - out, "Recovery Node State:\n");
  410. list_for_each_entry(node, &dlm->reco.node_data, list) {
  411. switch (node->state) {
  412. case DLM_RECO_NODE_DATA_INIT:
  413. state = "INIT";
  414. break;
  415. case DLM_RECO_NODE_DATA_REQUESTING:
  416. state = "REQUESTING";
  417. break;
  418. case DLM_RECO_NODE_DATA_DEAD:
  419. state = "DEAD";
  420. break;
  421. case DLM_RECO_NODE_DATA_RECEIVING:
  422. state = "RECEIVING";
  423. break;
  424. case DLM_RECO_NODE_DATA_REQUESTED:
  425. state = "REQUESTED";
  426. break;
  427. case DLM_RECO_NODE_DATA_DONE:
  428. state = "DONE";
  429. break;
  430. case DLM_RECO_NODE_DATA_FINALIZE_SENT:
  431. state = "FINALIZE-SENT";
  432. break;
  433. default:
  434. state = "BAD";
  435. break;
  436. }
  437. out += snprintf(db->buf + out, db->len - out, "\t%u - %s\n",
  438. node->node_num, state);
  439. }
  440. spin_unlock(&dlm->spinlock);
  441. return out;
  442. }
  443. static int debug_state_open(struct inode *inode, struct file *file)
  444. {
  445. struct dlm_ctxt *dlm = inode->i_private;
  446. struct debug_buffer *db = NULL;
  447. db = debug_buffer_allocate();
  448. if (!db)
  449. goto bail;
  450. db->len = debug_state_print(dlm, db);
  451. file->private_data = db;
  452. return 0;
  453. bail:
  454. return -ENOMEM;
  455. }
  456. static struct file_operations debug_state_fops = {
  457. .open = debug_state_open,
  458. .release = debug_buffer_release,
  459. .read = debug_buffer_read,
  460. .llseek = debug_buffer_llseek,
  461. };
  462. /* end - debug state funcs */
  463. /* files in subroot */
  464. int dlm_debug_init(struct dlm_ctxt *dlm)
  465. {
  466. struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
  467. /* for dumping dlm_ctxt */
  468. dc->debug_state_dentry = debugfs_create_file(DLM_DEBUGFS_DLM_STATE,
  469. S_IFREG|S_IRUSR,
  470. dlm->dlm_debugfs_subroot,
  471. dlm, &debug_state_fops);
  472. if (!dc->debug_state_dentry) {
  473. mlog_errno(-ENOMEM);
  474. goto bail;
  475. }
  476. dlm_debug_get(dc);
  477. return 0;
  478. bail:
  479. dlm_debug_shutdown(dlm);
  480. return -ENOMEM;
  481. }
  482. void dlm_debug_shutdown(struct dlm_ctxt *dlm)
  483. {
  484. struct dlm_debug_ctxt *dc = dlm->dlm_debug_ctxt;
  485. if (dc) {
  486. if (dc->debug_state_dentry)
  487. debugfs_remove(dc->debug_state_dentry);
  488. dlm_debug_put(dc);
  489. }
  490. }
  491. /* subroot - domain dir */
  492. int dlm_create_debugfs_subroot(struct dlm_ctxt *dlm)
  493. {
  494. dlm->dlm_debugfs_subroot = debugfs_create_dir(dlm->name,
  495. dlm_debugfs_root);
  496. if (!dlm->dlm_debugfs_subroot) {
  497. mlog_errno(-ENOMEM);
  498. goto bail;
  499. }
  500. dlm->dlm_debug_ctxt = kzalloc(sizeof(struct dlm_debug_ctxt),
  501. GFP_KERNEL);
  502. if (!dlm->dlm_debug_ctxt) {
  503. mlog_errno(-ENOMEM);
  504. goto bail;
  505. }
  506. kref_init(&dlm->dlm_debug_ctxt->debug_refcnt);
  507. return 0;
  508. bail:
  509. dlm_destroy_debugfs_subroot(dlm);
  510. return -ENOMEM;
  511. }
  512. void dlm_destroy_debugfs_subroot(struct dlm_ctxt *dlm)
  513. {
  514. if (dlm->dlm_debugfs_subroot)
  515. debugfs_remove(dlm->dlm_debugfs_subroot);
  516. }
  517. /* debugfs root */
  518. int dlm_create_debugfs_root(void)
  519. {
  520. dlm_debugfs_root = debugfs_create_dir(DLM_DEBUGFS_DIR, NULL);
  521. if (!dlm_debugfs_root) {
  522. mlog_errno(-ENOMEM);
  523. return -ENOMEM;
  524. }
  525. return 0;
  526. }
  527. void dlm_destroy_debugfs_root(void)
  528. {
  529. if (dlm_debugfs_root)
  530. debugfs_remove(dlm_debugfs_root);
  531. }
  532. #endif /* CONFIG_DEBUG_FS */