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