dlmdebug.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 "cluster/heartbeat.h"
  33. #include "cluster/nodemanager.h"
  34. #include "cluster/tcp.h"
  35. #include "dlmapi.h"
  36. #include "dlmcommon.h"
  37. #include "dlmdomain.h"
  38. #define MLOG_MASK_PREFIX ML_DLM
  39. #include "cluster/masklog.h"
  40. void dlm_print_one_lock_resource(struct dlm_lock_resource *res)
  41. {
  42. mlog(ML_NOTICE, "lockres: %.*s, owner=%u, state=%u\n",
  43. res->lockname.len, res->lockname.name,
  44. res->owner, res->state);
  45. spin_lock(&res->spinlock);
  46. __dlm_print_one_lock_resource(res);
  47. spin_unlock(&res->spinlock);
  48. }
  49. static void dlm_print_lockres_refmap(struct dlm_lock_resource *res)
  50. {
  51. int bit;
  52. assert_spin_locked(&res->spinlock);
  53. mlog(ML_NOTICE, " refmap nodes: [ ");
  54. bit = 0;
  55. while (1) {
  56. bit = find_next_bit(res->refmap, O2NM_MAX_NODES, bit);
  57. if (bit >= O2NM_MAX_NODES)
  58. break;
  59. printk("%u ", bit);
  60. bit++;
  61. }
  62. printk("], inflight=%u\n", res->inflight_locks);
  63. }
  64. void __dlm_print_one_lock_resource(struct dlm_lock_resource *res)
  65. {
  66. struct list_head *iter2;
  67. struct dlm_lock *lock;
  68. assert_spin_locked(&res->spinlock);
  69. mlog(ML_NOTICE, "lockres: %.*s, owner=%u, state=%u\n",
  70. res->lockname.len, res->lockname.name,
  71. res->owner, res->state);
  72. mlog(ML_NOTICE, " last used: %lu, on purge list: %s\n",
  73. res->last_used, list_empty(&res->purge) ? "no" : "yes");
  74. dlm_print_lockres_refmap(res);
  75. mlog(ML_NOTICE, " granted queue: \n");
  76. list_for_each(iter2, &res->granted) {
  77. lock = list_entry(iter2, struct dlm_lock, list);
  78. spin_lock(&lock->spinlock);
  79. mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
  80. "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
  81. lock->ml.type, lock->ml.convert_type, lock->ml.node,
  82. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  83. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  84. list_empty(&lock->ast_list) ? 'y' : 'n',
  85. lock->ast_pending ? 'y' : 'n',
  86. list_empty(&lock->bast_list) ? 'y' : 'n',
  87. lock->bast_pending ? 'y' : 'n');
  88. spin_unlock(&lock->spinlock);
  89. }
  90. mlog(ML_NOTICE, " converting queue: \n");
  91. list_for_each(iter2, &res->converting) {
  92. lock = list_entry(iter2, struct dlm_lock, list);
  93. spin_lock(&lock->spinlock);
  94. mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
  95. "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
  96. lock->ml.type, lock->ml.convert_type, lock->ml.node,
  97. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  98. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  99. list_empty(&lock->ast_list) ? 'y' : 'n',
  100. lock->ast_pending ? 'y' : 'n',
  101. list_empty(&lock->bast_list) ? 'y' : 'n',
  102. lock->bast_pending ? 'y' : 'n');
  103. spin_unlock(&lock->spinlock);
  104. }
  105. mlog(ML_NOTICE, " blocked queue: \n");
  106. list_for_each(iter2, &res->blocked) {
  107. lock = list_entry(iter2, struct dlm_lock, list);
  108. spin_lock(&lock->spinlock);
  109. mlog(ML_NOTICE, " type=%d, conv=%d, node=%u, "
  110. "cookie=%u:%llu, ast=(empty=%c,pend=%c), bast=(empty=%c,pend=%c)\n",
  111. lock->ml.type, lock->ml.convert_type, lock->ml.node,
  112. dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)),
  113. dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)),
  114. list_empty(&lock->ast_list) ? 'y' : 'n',
  115. lock->ast_pending ? 'y' : 'n',
  116. list_empty(&lock->bast_list) ? 'y' : 'n',
  117. lock->bast_pending ? 'y' : 'n');
  118. spin_unlock(&lock->spinlock);
  119. }
  120. }
  121. void dlm_print_one_lock(struct dlm_lock *lockid)
  122. {
  123. dlm_print_one_lock_resource(lockid->lockres);
  124. }
  125. EXPORT_SYMBOL_GPL(dlm_print_one_lock);
  126. #if 0
  127. void dlm_dump_lock_resources(struct dlm_ctxt *dlm)
  128. {
  129. struct dlm_lock_resource *res;
  130. struct hlist_node *iter;
  131. struct hlist_head *bucket;
  132. int i;
  133. mlog(ML_NOTICE, "struct dlm_ctxt: %s, node=%u, key=%u\n",
  134. dlm->name, dlm->node_num, dlm->key);
  135. if (!dlm || !dlm->name) {
  136. mlog(ML_ERROR, "dlm=%p\n", dlm);
  137. return;
  138. }
  139. spin_lock(&dlm->spinlock);
  140. for (i=0; i<DLM_HASH_BUCKETS; i++) {
  141. bucket = dlm_lockres_hash(dlm, i);
  142. hlist_for_each_entry(res, iter, bucket, hash_node)
  143. dlm_print_one_lock_resource(res);
  144. }
  145. spin_unlock(&dlm->spinlock);
  146. }
  147. #endif /* 0 */
  148. static const char *dlm_errnames[] = {
  149. [DLM_NORMAL] = "DLM_NORMAL",
  150. [DLM_GRANTED] = "DLM_GRANTED",
  151. [DLM_DENIED] = "DLM_DENIED",
  152. [DLM_DENIED_NOLOCKS] = "DLM_DENIED_NOLOCKS",
  153. [DLM_WORKING] = "DLM_WORKING",
  154. [DLM_BLOCKED] = "DLM_BLOCKED",
  155. [DLM_BLOCKED_ORPHAN] = "DLM_BLOCKED_ORPHAN",
  156. [DLM_DENIED_GRACE_PERIOD] = "DLM_DENIED_GRACE_PERIOD",
  157. [DLM_SYSERR] = "DLM_SYSERR",
  158. [DLM_NOSUPPORT] = "DLM_NOSUPPORT",
  159. [DLM_CANCELGRANT] = "DLM_CANCELGRANT",
  160. [DLM_IVLOCKID] = "DLM_IVLOCKID",
  161. [DLM_SYNC] = "DLM_SYNC",
  162. [DLM_BADTYPE] = "DLM_BADTYPE",
  163. [DLM_BADRESOURCE] = "DLM_BADRESOURCE",
  164. [DLM_MAXHANDLES] = "DLM_MAXHANDLES",
  165. [DLM_NOCLINFO] = "DLM_NOCLINFO",
  166. [DLM_NOLOCKMGR] = "DLM_NOLOCKMGR",
  167. [DLM_NOPURGED] = "DLM_NOPURGED",
  168. [DLM_BADARGS] = "DLM_BADARGS",
  169. [DLM_VOID] = "DLM_VOID",
  170. [DLM_NOTQUEUED] = "DLM_NOTQUEUED",
  171. [DLM_IVBUFLEN] = "DLM_IVBUFLEN",
  172. [DLM_CVTUNGRANT] = "DLM_CVTUNGRANT",
  173. [DLM_BADPARAM] = "DLM_BADPARAM",
  174. [DLM_VALNOTVALID] = "DLM_VALNOTVALID",
  175. [DLM_REJECTED] = "DLM_REJECTED",
  176. [DLM_ABORT] = "DLM_ABORT",
  177. [DLM_CANCEL] = "DLM_CANCEL",
  178. [DLM_IVRESHANDLE] = "DLM_IVRESHANDLE",
  179. [DLM_DEADLOCK] = "DLM_DEADLOCK",
  180. [DLM_DENIED_NOASTS] = "DLM_DENIED_NOASTS",
  181. [DLM_FORWARD] = "DLM_FORWARD",
  182. [DLM_TIMEOUT] = "DLM_TIMEOUT",
  183. [DLM_IVGROUPID] = "DLM_IVGROUPID",
  184. [DLM_VERS_CONFLICT] = "DLM_VERS_CONFLICT",
  185. [DLM_BAD_DEVICE_PATH] = "DLM_BAD_DEVICE_PATH",
  186. [DLM_NO_DEVICE_PERMISSION] = "DLM_NO_DEVICE_PERMISSION",
  187. [DLM_NO_CONTROL_DEVICE ] = "DLM_NO_CONTROL_DEVICE ",
  188. [DLM_RECOVERING] = "DLM_RECOVERING",
  189. [DLM_MIGRATING] = "DLM_MIGRATING",
  190. [DLM_MAXSTATS] = "DLM_MAXSTATS",
  191. };
  192. static const char *dlm_errmsgs[] = {
  193. [DLM_NORMAL] = "request in progress",
  194. [DLM_GRANTED] = "request granted",
  195. [DLM_DENIED] = "request denied",
  196. [DLM_DENIED_NOLOCKS] = "request denied, out of system resources",
  197. [DLM_WORKING] = "async request in progress",
  198. [DLM_BLOCKED] = "lock request blocked",
  199. [DLM_BLOCKED_ORPHAN] = "lock request blocked by a orphan lock",
  200. [DLM_DENIED_GRACE_PERIOD] = "topological change in progress",
  201. [DLM_SYSERR] = "system error",
  202. [DLM_NOSUPPORT] = "unsupported",
  203. [DLM_CANCELGRANT] = "can't cancel convert: already granted",
  204. [DLM_IVLOCKID] = "bad lockid",
  205. [DLM_SYNC] = "synchronous request granted",
  206. [DLM_BADTYPE] = "bad resource type",
  207. [DLM_BADRESOURCE] = "bad resource handle",
  208. [DLM_MAXHANDLES] = "no more resource handles",
  209. [DLM_NOCLINFO] = "can't contact cluster manager",
  210. [DLM_NOLOCKMGR] = "can't contact lock manager",
  211. [DLM_NOPURGED] = "can't contact purge daemon",
  212. [DLM_BADARGS] = "bad api args",
  213. [DLM_VOID] = "no status",
  214. [DLM_NOTQUEUED] = "NOQUEUE was specified and request failed",
  215. [DLM_IVBUFLEN] = "invalid resource name length",
  216. [DLM_CVTUNGRANT] = "attempted to convert ungranted lock",
  217. [DLM_BADPARAM] = "invalid lock mode specified",
  218. [DLM_VALNOTVALID] = "value block has been invalidated",
  219. [DLM_REJECTED] = "request rejected, unrecognized client",
  220. [DLM_ABORT] = "blocked lock request cancelled",
  221. [DLM_CANCEL] = "conversion request cancelled",
  222. [DLM_IVRESHANDLE] = "invalid resource handle",
  223. [DLM_DEADLOCK] = "deadlock recovery refused this request",
  224. [DLM_DENIED_NOASTS] = "failed to allocate AST",
  225. [DLM_FORWARD] = "request must wait for primary's response",
  226. [DLM_TIMEOUT] = "timeout value for lock has expired",
  227. [DLM_IVGROUPID] = "invalid group specification",
  228. [DLM_VERS_CONFLICT] = "version conflicts prevent request handling",
  229. [DLM_BAD_DEVICE_PATH] = "Locks device does not exist or path wrong",
  230. [DLM_NO_DEVICE_PERMISSION] = "Client has insufficient perms for device",
  231. [DLM_NO_CONTROL_DEVICE] = "Cannot set options on opened device ",
  232. [DLM_RECOVERING] = "lock resource being recovered",
  233. [DLM_MIGRATING] = "lock resource being migrated",
  234. [DLM_MAXSTATS] = "invalid error number",
  235. };
  236. const char *dlm_errmsg(enum dlm_status err)
  237. {
  238. if (err >= DLM_MAXSTATS || err < 0)
  239. return dlm_errmsgs[DLM_MAXSTATS];
  240. return dlm_errmsgs[err];
  241. }
  242. EXPORT_SYMBOL_GPL(dlm_errmsg);
  243. const char *dlm_errname(enum dlm_status err)
  244. {
  245. if (err >= DLM_MAXSTATS || err < 0)
  246. return dlm_errnames[DLM_MAXSTATS];
  247. return dlm_errnames[err];
  248. }
  249. EXPORT_SYMBOL_GPL(dlm_errname);