dlmdebug.c 8.6 KB

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