blob: 1d1d27442235b9487c3db8a8490a6a0da7c6122c [file] [log] [blame]
David Teiglande7fd4172006-01-18 09:30:29 +00001/******************************************************************************
2*******************************************************************************
3**
David Teigland892c4462009-01-07 16:48:52 -06004** Copyright (C) 2005-2009 Red Hat, Inc. All rights reserved.
David Teiglande7fd4172006-01-18 09:30:29 +00005**
6** This copyrighted material is made available to anyone wishing to use,
7** modify, copy, or redistribute it subject to the terms and conditions
8** of the GNU General Public License v.2.
9**
10*******************************************************************************
11******************************************************************************/
12
13#include <linux/pagemap.h>
14#include <linux/seq_file.h>
15#include <linux/module.h>
16#include <linux/ctype.h>
17#include <linux/debugfs.h>
18
19#include "dlm_internal.h"
Josef Bacik916297a2007-05-16 15:56:13 -040020#include "lock.h"
David Teiglande7fd4172006-01-18 09:30:29 +000021
David Teigland5de63192006-07-25 13:44:31 -050022#define DLM_DEBUG_BUF_LEN 4096
23static char debug_buf[DLM_DEBUG_BUF_LEN];
24static struct mutex debug_buf_lock;
David Teiglande7fd4172006-01-18 09:30:29 +000025
26static struct dentry *dlm_root;
27
David Teiglande7fd4172006-01-18 09:30:29 +000028static char *print_lockmode(int mode)
29{
30 switch (mode) {
31 case DLM_LOCK_IV:
32 return "--";
33 case DLM_LOCK_NL:
34 return "NL";
35 case DLM_LOCK_CR:
36 return "CR";
37 case DLM_LOCK_CW:
38 return "CW";
39 case DLM_LOCK_PR:
40 return "PR";
41 case DLM_LOCK_PW:
42 return "PW";
43 case DLM_LOCK_EX:
44 return "EX";
45 default:
46 return "??";
47 }
48}
49
David Teigland892c4462009-01-07 16:48:52 -060050static int print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
51 struct dlm_rsb *res)
David Teiglande7fd4172006-01-18 09:30:29 +000052{
53 seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode));
54
David Teigland892c4462009-01-07 16:48:52 -060055 if (lkb->lkb_status == DLM_LKSTS_CONVERT ||
56 lkb->lkb_status == DLM_LKSTS_WAITING)
David Teiglande7fd4172006-01-18 09:30:29 +000057 seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode));
58
David Teiglande7fd4172006-01-18 09:30:29 +000059 if (lkb->lkb_nodeid) {
60 if (lkb->lkb_nodeid != res->res_nodeid)
61 seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
62 lkb->lkb_remid);
63 else
64 seq_printf(s, " Master: %08x", lkb->lkb_remid);
65 }
66
67 if (lkb->lkb_wait_type)
68 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
69
David Teigland892c4462009-01-07 16:48:52 -060070 return seq_printf(s, "\n");
David Teiglande7fd4172006-01-18 09:30:29 +000071}
72
David Teiglandd0225092008-12-16 14:53:23 -060073static int print_format1(struct dlm_rsb *res, struct seq_file *s)
David Teiglande7fd4172006-01-18 09:30:29 +000074{
75 struct dlm_lkb *lkb;
David Teigland5de63192006-07-25 13:44:31 -050076 int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list;
David Teigland892c4462009-01-07 16:48:52 -060077 int rv;
David Teiglande7fd4172006-01-18 09:30:29 +000078
David Teigland9dd592d2007-05-29 08:47:04 -050079 lock_rsb(res);
80
David Teigland892c4462009-01-07 16:48:52 -060081 rv = seq_printf(s, "\nResource %p Name (len=%d) \"",
82 res, res->res_length);
83 if (rv)
84 goto out;
85
David Teiglande7fd4172006-01-18 09:30:29 +000086 for (i = 0; i < res->res_length; i++) {
87 if (isprint(res->res_name[i]))
88 seq_printf(s, "%c", res->res_name[i]);
89 else
90 seq_printf(s, "%c", '.');
91 }
David Teigland892c4462009-01-07 16:48:52 -060092
David Teiglande7fd4172006-01-18 09:30:29 +000093 if (res->res_nodeid > 0)
David Teigland892c4462009-01-07 16:48:52 -060094 rv = seq_printf(s, "\" \nLocal Copy, Master is node %d\n",
95 res->res_nodeid);
David Teiglande7fd4172006-01-18 09:30:29 +000096 else if (res->res_nodeid == 0)
David Teigland892c4462009-01-07 16:48:52 -060097 rv = seq_printf(s, "\" \nMaster Copy\n");
David Teiglande7fd4172006-01-18 09:30:29 +000098 else if (res->res_nodeid == -1)
David Teigland892c4462009-01-07 16:48:52 -060099 rv = seq_printf(s, "\" \nLooking up master (lkid %x)\n",
100 res->res_first_lkid);
David Teiglande7fd4172006-01-18 09:30:29 +0000101 else
David Teigland892c4462009-01-07 16:48:52 -0600102 rv = seq_printf(s, "\" \nInvalid master %d\n",
103 res->res_nodeid);
104 if (rv)
105 goto out;
David Teiglande7fd4172006-01-18 09:30:29 +0000106
107 /* Print the LVB: */
108 if (res->res_lvbptr) {
109 seq_printf(s, "LVB: ");
110 for (i = 0; i < lvblen; i++) {
111 if (i == lvblen / 2)
112 seq_printf(s, "\n ");
113 seq_printf(s, "%02x ",
114 (unsigned char) res->res_lvbptr[i]);
115 }
116 if (rsb_flag(res, RSB_VALNOTVALID))
117 seq_printf(s, " (INVALID)");
David Teigland892c4462009-01-07 16:48:52 -0600118 rv = seq_printf(s, "\n");
119 if (rv)
120 goto out;
David Teiglande7fd4172006-01-18 09:30:29 +0000121 }
122
David Teigland5de63192006-07-25 13:44:31 -0500123 root_list = !list_empty(&res->res_root_list);
124 recover_list = !list_empty(&res->res_recover_list);
125
126 if (root_list || recover_list) {
David Teigland892c4462009-01-07 16:48:52 -0600127 rv = seq_printf(s, "Recovery: root %d recover %d flags %lx "
128 "count %d\n", root_list, recover_list,
129 res->res_flags, res->res_recover_locks_count);
130 if (rv)
131 goto out;
David Teigland5de63192006-07-25 13:44:31 -0500132 }
133
David Teiglande7fd4172006-01-18 09:30:29 +0000134 /* Print the locks attached to this resource */
135 seq_printf(s, "Granted Queue\n");
David Teigland892c4462009-01-07 16:48:52 -0600136 list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) {
137 rv = print_format1_lock(s, lkb, res);
138 if (rv)
139 goto out;
140 }
David Teiglande7fd4172006-01-18 09:30:29 +0000141
142 seq_printf(s, "Conversion Queue\n");
David Teigland892c4462009-01-07 16:48:52 -0600143 list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) {
144 rv = print_format1_lock(s, lkb, res);
145 if (rv)
146 goto out;
147 }
David Teiglande7fd4172006-01-18 09:30:29 +0000148
149 seq_printf(s, "Waiting Queue\n");
David Teigland892c4462009-01-07 16:48:52 -0600150 list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) {
151 rv = print_format1_lock(s, lkb, res);
152 if (rv)
153 goto out;
154 }
David Teiglande7fd4172006-01-18 09:30:29 +0000155
David Teigland5de63192006-07-25 13:44:31 -0500156 if (list_empty(&res->res_lookup))
157 goto out;
158
159 seq_printf(s, "Lookup Queue\n");
160 list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) {
David Teigland892c4462009-01-07 16:48:52 -0600161 rv = seq_printf(s, "%08x %s", lkb->lkb_id,
162 print_lockmode(lkb->lkb_rqmode));
David Teigland5de63192006-07-25 13:44:31 -0500163 if (lkb->lkb_wait_type)
164 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
David Teigland892c4462009-01-07 16:48:52 -0600165 rv = seq_printf(s, "\n");
David Teigland5de63192006-07-25 13:44:31 -0500166 }
167 out:
David Teigland9dd592d2007-05-29 08:47:04 -0500168 unlock_rsb(res);
David Teigland892c4462009-01-07 16:48:52 -0600169 return rv;
David Teigland9dd592d2007-05-29 08:47:04 -0500170}
171
David Teigland892c4462009-01-07 16:48:52 -0600172static int print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
173 struct dlm_rsb *r)
David Teigland9dd592d2007-05-29 08:47:04 -0500174{
David Teiglandeeda4182008-12-09 14:12:21 -0600175 u64 xid = 0;
176 u64 us;
David Teigland892c4462009-01-07 16:48:52 -0600177 int rv;
David Teigland9dd592d2007-05-29 08:47:04 -0500178
179 if (lkb->lkb_flags & DLM_IFL_USER) {
David Teiglandd292c0c2008-02-06 23:27:04 -0600180 if (lkb->lkb_ua)
181 xid = lkb->lkb_ua->xid;
David Teigland9dd592d2007-05-29 08:47:04 -0500182 }
183
David Teiglandeeda4182008-12-09 14:12:21 -0600184 /* microseconds since lkb was added to current queue */
185 us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_timestamp));
David Teigland9dd592d2007-05-29 08:47:04 -0500186
David Teiglandeeda4182008-12-09 14:12:21 -0600187 /* id nodeid remid pid xid exflags flags sts grmode rqmode time_us
David Teiglandac90a252007-07-06 09:47:08 -0500188 r_nodeid r_len r_name */
David Teigland9dd592d2007-05-29 08:47:04 -0500189
David Teigland892c4462009-01-07 16:48:52 -0600190 rv = seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
191 lkb->lkb_id,
192 lkb->lkb_nodeid,
193 lkb->lkb_remid,
194 lkb->lkb_ownpid,
195 (unsigned long long)xid,
196 lkb->lkb_exflags,
197 lkb->lkb_flags,
198 lkb->lkb_status,
199 lkb->lkb_grmode,
200 lkb->lkb_rqmode,
201 (unsigned long long)us,
202 r->res_nodeid,
203 r->res_length,
204 r->res_name);
205 return rv;
David Teigland9dd592d2007-05-29 08:47:04 -0500206}
207
David Teiglandd0225092008-12-16 14:53:23 -0600208static int print_format2(struct dlm_rsb *r, struct seq_file *s)
David Teigland9dd592d2007-05-29 08:47:04 -0500209{
210 struct dlm_lkb *lkb;
David Teigland892c4462009-01-07 16:48:52 -0600211 int rv = 0;
David Teigland9dd592d2007-05-29 08:47:04 -0500212
213 lock_rsb(r);
214
David Teigland892c4462009-01-07 16:48:52 -0600215 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
216 rv = print_format2_lock(s, lkb, r);
217 if (rv)
218 goto out;
219 }
David Teigland9dd592d2007-05-29 08:47:04 -0500220
David Teigland892c4462009-01-07 16:48:52 -0600221 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
222 rv = print_format2_lock(s, lkb, r);
223 if (rv)
224 goto out;
225 }
David Teigland9dd592d2007-05-29 08:47:04 -0500226
David Teigland892c4462009-01-07 16:48:52 -0600227 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
228 rv = print_format2_lock(s, lkb, r);
229 if (rv)
230 goto out;
231 }
232 out:
David Teiglandd0225092008-12-16 14:53:23 -0600233 unlock_rsb(r);
David Teigland892c4462009-01-07 16:48:52 -0600234 return rv;
David Teiglandd0225092008-12-16 14:53:23 -0600235}
236
David Teigland892c4462009-01-07 16:48:52 -0600237static int print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
238 int rsb_lookup)
David Teiglandd0225092008-12-16 14:53:23 -0600239{
240 u64 xid = 0;
David Teigland892c4462009-01-07 16:48:52 -0600241 int rv;
David Teiglandd0225092008-12-16 14:53:23 -0600242
243 if (lkb->lkb_flags & DLM_IFL_USER) {
244 if (lkb->lkb_ua)
245 xid = lkb->lkb_ua->xid;
246 }
247
David Teigland892c4462009-01-07 16:48:52 -0600248 rv = seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
249 lkb->lkb_id,
250 lkb->lkb_nodeid,
251 lkb->lkb_remid,
252 lkb->lkb_ownpid,
253 (unsigned long long)xid,
254 lkb->lkb_exflags,
255 lkb->lkb_flags,
256 lkb->lkb_status,
257 lkb->lkb_grmode,
258 lkb->lkb_rqmode,
259 lkb->lkb_highbast,
260 rsb_lookup,
261 lkb->lkb_wait_type,
262 lkb->lkb_lvbseq,
263 (unsigned long long)ktime_to_ns(lkb->lkb_timestamp),
264 (unsigned long long)ktime_to_ns(lkb->lkb_time_bast));
265 return rv;
David Teiglandd0225092008-12-16 14:53:23 -0600266}
267
268static int print_format3(struct dlm_rsb *r, struct seq_file *s)
269{
270 struct dlm_lkb *lkb;
271 int i, lvblen = r->res_ls->ls_lvblen;
272 int print_name = 1;
David Teigland892c4462009-01-07 16:48:52 -0600273 int rv;
David Teiglandd0225092008-12-16 14:53:23 -0600274
275 lock_rsb(r);
276
David Teigland892c4462009-01-07 16:48:52 -0600277 rv = seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
278 r,
279 r->res_nodeid,
280 r->res_first_lkid,
281 r->res_flags,
282 !list_empty(&r->res_root_list),
283 !list_empty(&r->res_recover_list),
284 r->res_recover_locks_count,
285 r->res_length);
286 if (rv)
287 goto out;
David Teiglandd0225092008-12-16 14:53:23 -0600288
289 for (i = 0; i < r->res_length; i++) {
290 if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
291 print_name = 0;
292 }
293
294 seq_printf(s, "%s", print_name ? "str " : "hex");
295
296 for (i = 0; i < r->res_length; i++) {
297 if (print_name)
298 seq_printf(s, "%c", r->res_name[i]);
299 else
300 seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
301 }
David Teigland892c4462009-01-07 16:48:52 -0600302 rv = seq_printf(s, "\n");
303 if (rv)
304 goto out;
David Teiglandd0225092008-12-16 14:53:23 -0600305
306 if (!r->res_lvbptr)
307 goto do_locks;
308
309 seq_printf(s, "lvb %u %d", r->res_lvbseq, lvblen);
310
311 for (i = 0; i < lvblen; i++)
312 seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
David Teigland892c4462009-01-07 16:48:52 -0600313 rv = seq_printf(s, "\n");
314 if (rv)
315 goto out;
David Teiglandd0225092008-12-16 14:53:23 -0600316
317 do_locks:
David Teigland892c4462009-01-07 16:48:52 -0600318 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
319 rv = print_format3_lock(s, lkb, 0);
320 if (rv)
321 goto out;
322 }
David Teiglandd0225092008-12-16 14:53:23 -0600323
David Teigland892c4462009-01-07 16:48:52 -0600324 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
325 rv = print_format3_lock(s, lkb, 0);
326 if (rv)
327 goto out;
328 }
David Teiglandd0225092008-12-16 14:53:23 -0600329
David Teigland892c4462009-01-07 16:48:52 -0600330 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
331 rv = print_format3_lock(s, lkb, 0);
332 if (rv)
333 goto out;
334 }
David Teiglandd0225092008-12-16 14:53:23 -0600335
David Teigland892c4462009-01-07 16:48:52 -0600336 list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) {
337 rv = print_format3_lock(s, lkb, 1);
338 if (rv)
339 goto out;
340 }
341 out:
David Teigland9dd592d2007-05-29 08:47:04 -0500342 unlock_rsb(r);
David Teigland892c4462009-01-07 16:48:52 -0600343 return rv;
David Teiglande7fd4172006-01-18 09:30:29 +0000344}
345
David Teigland892c4462009-01-07 16:48:52 -0600346struct rsbtbl_iter {
347 struct dlm_rsb *rsb;
348 unsigned bucket;
349 int format;
350 int header;
351};
352
353/* seq_printf returns -1 if the buffer is full, and 0 otherwise.
354 If the buffer is full, seq_printf can be called again, but it
355 does nothing and just returns -1. So, the these printing routines
356 periodically check the return value to avoid wasting too much time
357 trying to print to a full buffer. */
358
359static int table_seq_show(struct seq_file *seq, void *iter_ptr)
David Teiglande7fd4172006-01-18 09:30:29 +0000360{
David Teigland892c4462009-01-07 16:48:52 -0600361 struct rsbtbl_iter *ri = iter_ptr;
362 int rv = 0;
David Teiglande7fd4172006-01-18 09:30:29 +0000363
David Teiglandd0225092008-12-16 14:53:23 -0600364 switch (ri->format) {
365 case 1:
David Teigland892c4462009-01-07 16:48:52 -0600366 rv = print_format1(ri->rsb, seq);
David Teiglandd0225092008-12-16 14:53:23 -0600367 break;
368 case 2:
David Teigland9dd592d2007-05-29 08:47:04 -0500369 if (ri->header) {
David Teigland892c4462009-01-07 16:48:52 -0600370 seq_printf(seq, "id nodeid remid pid xid exflags "
371 "flags sts grmode rqmode time_ms "
372 "r_nodeid r_len r_name\n");
David Teigland9dd592d2007-05-29 08:47:04 -0500373 ri->header = 0;
374 }
David Teigland892c4462009-01-07 16:48:52 -0600375 rv = print_format2(ri->rsb, seq);
David Teiglandd0225092008-12-16 14:53:23 -0600376 break;
377 case 3:
378 if (ri->header) {
David Teigland892c4462009-01-07 16:48:52 -0600379 seq_printf(seq, "version rsb 1.1 lvb 1.1 lkb 1.1\n");
David Teiglandd0225092008-12-16 14:53:23 -0600380 ri->header = 0;
381 }
David Teigland892c4462009-01-07 16:48:52 -0600382 rv = print_format3(ri->rsb, seq);
David Teiglandd0225092008-12-16 14:53:23 -0600383 break;
David Teigland9dd592d2007-05-29 08:47:04 -0500384 }
David Teiglande7fd4172006-01-18 09:30:29 +0000385
David Teigland892c4462009-01-07 16:48:52 -0600386 return rv;
David Teiglande7fd4172006-01-18 09:30:29 +0000387}
388
David Teigland892c4462009-01-07 16:48:52 -0600389static struct seq_operations format1_seq_ops;
390static struct seq_operations format2_seq_ops;
391static struct seq_operations format3_seq_ops;
392
393static void *table_seq_start(struct seq_file *seq, loff_t *pos)
394{
395 struct dlm_ls *ls = seq->private;
396 struct rsbtbl_iter *ri;
397 struct dlm_rsb *r;
398 loff_t n = *pos;
399 unsigned bucket, entry;
400
401 bucket = n >> 32;
402 entry = n & ((1LL << 32) - 1);
403
404 if (bucket >= ls->ls_rsbtbl_size)
405 return NULL;
406
407 ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_KERNEL);
408 if (!ri)
409 return NULL;
410 if (n == 0)
411 ri->header = 1;
412 if (seq->op == &format1_seq_ops)
413 ri->format = 1;
414 if (seq->op == &format2_seq_ops)
415 ri->format = 2;
416 if (seq->op == &format3_seq_ops)
417 ri->format = 3;
418
David Teiglandc7be7612009-01-07 16:50:41 -0600419 spin_lock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600420 if (!list_empty(&ls->ls_rsbtbl[bucket].list)) {
421 list_for_each_entry(r, &ls->ls_rsbtbl[bucket].list,
422 res_hashchain) {
423 if (!entry--) {
424 dlm_hold_rsb(r);
425 ri->rsb = r;
426 ri->bucket = bucket;
David Teiglandc7be7612009-01-07 16:50:41 -0600427 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600428 return ri;
429 }
430 }
431 }
David Teiglandc7be7612009-01-07 16:50:41 -0600432 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600433
434 /*
435 * move to the first rsb in the next non-empty bucket
436 */
437
438 /* zero the entry */
439 n &= ~((1LL << 32) - 1);
440
441 while (1) {
442 bucket++;
443 n += 1LL << 32;
444
445 if (bucket >= ls->ls_rsbtbl_size) {
446 kfree(ri);
447 return NULL;
448 }
449
David Teiglandc7be7612009-01-07 16:50:41 -0600450 spin_lock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600451 if (!list_empty(&ls->ls_rsbtbl[bucket].list)) {
452 r = list_first_entry(&ls->ls_rsbtbl[bucket].list,
453 struct dlm_rsb, res_hashchain);
454 dlm_hold_rsb(r);
455 ri->rsb = r;
456 ri->bucket = bucket;
David Teiglandc7be7612009-01-07 16:50:41 -0600457 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600458 *pos = n;
459 return ri;
460 }
David Teiglandc7be7612009-01-07 16:50:41 -0600461 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600462 }
463}
464
465static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos)
466{
467 struct dlm_ls *ls = seq->private;
468 struct rsbtbl_iter *ri = iter_ptr;
469 struct list_head *next;
470 struct dlm_rsb *r, *rp;
471 loff_t n = *pos;
472 unsigned bucket;
473
474 bucket = n >> 32;
475
476 /*
477 * move to the next rsb in the same bucket
478 */
479
David Teiglandc7be7612009-01-07 16:50:41 -0600480 spin_lock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600481 rp = ri->rsb;
482 next = rp->res_hashchain.next;
483
484 if (next != &ls->ls_rsbtbl[bucket].list) {
485 r = list_entry(next, struct dlm_rsb, res_hashchain);
486 dlm_hold_rsb(r);
487 ri->rsb = r;
David Teiglandc7be7612009-01-07 16:50:41 -0600488 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600489 dlm_put_rsb(rp);
490 ++*pos;
491 return ri;
492 }
David Teiglandc7be7612009-01-07 16:50:41 -0600493 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600494 dlm_put_rsb(rp);
495
496 /*
497 * move to the first rsb in the next non-empty bucket
498 */
499
500 /* zero the entry */
501 n &= ~((1LL << 32) - 1);
502
503 while (1) {
504 bucket++;
505 n += 1LL << 32;
506
507 if (bucket >= ls->ls_rsbtbl_size) {
508 kfree(ri);
509 return NULL;
510 }
511
David Teiglandc7be7612009-01-07 16:50:41 -0600512 spin_lock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600513 if (!list_empty(&ls->ls_rsbtbl[bucket].list)) {
514 r = list_first_entry(&ls->ls_rsbtbl[bucket].list,
515 struct dlm_rsb, res_hashchain);
516 dlm_hold_rsb(r);
517 ri->rsb = r;
518 ri->bucket = bucket;
David Teiglandc7be7612009-01-07 16:50:41 -0600519 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600520 *pos = n;
521 return ri;
522 }
David Teiglandc7be7612009-01-07 16:50:41 -0600523 spin_unlock(&ls->ls_rsbtbl[bucket].lock);
David Teigland892c4462009-01-07 16:48:52 -0600524 }
525}
526
527static void table_seq_stop(struct seq_file *seq, void *iter_ptr)
528{
529 struct rsbtbl_iter *ri = iter_ptr;
530
531 if (ri) {
532 dlm_put_rsb(ri->rsb);
533 kfree(ri);
534 }
535}
536
537static struct seq_operations format1_seq_ops = {
538 .start = table_seq_start,
539 .next = table_seq_next,
540 .stop = table_seq_stop,
541 .show = table_seq_show,
David Teiglande7fd4172006-01-18 09:30:29 +0000542};
543
David Teigland892c4462009-01-07 16:48:52 -0600544static struct seq_operations format2_seq_ops = {
545 .start = table_seq_start,
546 .next = table_seq_next,
547 .stop = table_seq_stop,
548 .show = table_seq_show,
549};
550
551static struct seq_operations format3_seq_ops = {
552 .start = table_seq_start,
553 .next = table_seq_next,
554 .stop = table_seq_stop,
555 .show = table_seq_show,
556};
557
558static const struct file_operations format1_fops;
559static const struct file_operations format2_fops;
560static const struct file_operations format3_fops;
561
562static int table_open(struct inode *inode, struct file *file)
David Teiglande7fd4172006-01-18 09:30:29 +0000563{
564 struct seq_file *seq;
David Teigland892c4462009-01-07 16:48:52 -0600565 int ret = -1;
David Teiglande7fd4172006-01-18 09:30:29 +0000566
David Teigland892c4462009-01-07 16:48:52 -0600567 if (file->f_op == &format1_fops)
568 ret = seq_open(file, &format1_seq_ops);
569 else if (file->f_op == &format2_fops)
570 ret = seq_open(file, &format2_seq_ops);
571 else if (file->f_op == &format3_fops)
572 ret = seq_open(file, &format3_seq_ops);
573
David Teiglande7fd4172006-01-18 09:30:29 +0000574 if (ret)
575 return ret;
576
577 seq = file->private_data;
David Teigland892c4462009-01-07 16:48:52 -0600578 seq->private = inode->i_private; /* the dlm_ls */
David Teiglande7fd4172006-01-18 09:30:29 +0000579 return 0;
580}
581
David Teigland892c4462009-01-07 16:48:52 -0600582static const struct file_operations format1_fops = {
David Teiglande7fd4172006-01-18 09:30:29 +0000583 .owner = THIS_MODULE,
David Teigland892c4462009-01-07 16:48:52 -0600584 .open = table_open,
David Teiglande7fd4172006-01-18 09:30:29 +0000585 .read = seq_read,
586 .llseek = seq_lseek,
587 .release = seq_release
588};
589
David Teigland892c4462009-01-07 16:48:52 -0600590static const struct file_operations format2_fops = {
David Teigland9dd592d2007-05-29 08:47:04 -0500591 .owner = THIS_MODULE,
David Teigland892c4462009-01-07 16:48:52 -0600592 .open = table_open,
David Teigland9dd592d2007-05-29 08:47:04 -0500593 .read = seq_read,
594 .llseek = seq_lseek,
595 .release = seq_release
596};
597
David Teigland892c4462009-01-07 16:48:52 -0600598static const struct file_operations format3_fops = {
David Teiglandd0225092008-12-16 14:53:23 -0600599 .owner = THIS_MODULE,
David Teigland892c4462009-01-07 16:48:52 -0600600 .open = table_open,
David Teiglandd0225092008-12-16 14:53:23 -0600601 .read = seq_read,
602 .llseek = seq_lseek,
603 .release = seq_release
604};
605
606/*
David Teigland5de63192006-07-25 13:44:31 -0500607 * dump lkb's on the ls_waiters list
608 */
609
610static int waiters_open(struct inode *inode, struct file *file)
611{
Theodore Ts'obba9dfd2006-09-27 01:50:31 -0700612 file->private_data = inode->i_private;
David Teigland5de63192006-07-25 13:44:31 -0500613 return 0;
614}
615
616static ssize_t waiters_read(struct file *file, char __user *userbuf,
617 size_t count, loff_t *ppos)
618{
619 struct dlm_ls *ls = file->private_data;
620 struct dlm_lkb *lkb;
David Teigland06442442006-08-08 11:31:30 -0500621 size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv;
David Teigland5de63192006-07-25 13:44:31 -0500622
623 mutex_lock(&debug_buf_lock);
624 mutex_lock(&ls->ls_waiters_mutex);
625 memset(debug_buf, 0, sizeof(debug_buf));
626
627 list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
David Teigland06442442006-08-08 11:31:30 -0500628 ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n",
629 lkb->lkb_id, lkb->lkb_wait_type,
630 lkb->lkb_nodeid, lkb->lkb_resource->res_name);
631 if (ret >= len - pos)
632 break;
633 pos += ret;
David Teigland5de63192006-07-25 13:44:31 -0500634 }
635 mutex_unlock(&ls->ls_waiters_mutex);
636
637 rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos);
638 mutex_unlock(&debug_buf_lock);
639 return rv;
640}
641
Arjan van de Ven00977a52007-02-12 00:55:34 -0800642static const struct file_operations waiters_fops = {
David Teigland5de63192006-07-25 13:44:31 -0500643 .owner = THIS_MODULE,
644 .open = waiters_open,
645 .read = waiters_read
646};
647
David Teiglandd0225092008-12-16 14:53:23 -0600648void dlm_delete_debug_file(struct dlm_ls *ls)
649{
650 if (ls->ls_debug_rsb_dentry)
651 debugfs_remove(ls->ls_debug_rsb_dentry);
652 if (ls->ls_debug_waiters_dentry)
653 debugfs_remove(ls->ls_debug_waiters_dentry);
654 if (ls->ls_debug_locks_dentry)
655 debugfs_remove(ls->ls_debug_locks_dentry);
656 if (ls->ls_debug_all_dentry)
657 debugfs_remove(ls->ls_debug_all_dentry);
658}
659
David Teiglande7fd4172006-01-18 09:30:29 +0000660int dlm_create_debug_file(struct dlm_ls *ls)
661{
David Teigland5de63192006-07-25 13:44:31 -0500662 char name[DLM_LOCKSPACE_LEN+8];
663
David Teiglandd0225092008-12-16 14:53:23 -0600664 /* format 1 */
665
David Teigland5de63192006-07-25 13:44:31 -0500666 ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name,
667 S_IFREG | S_IRUGO,
668 dlm_root,
669 ls,
David Teigland892c4462009-01-07 16:48:52 -0600670 &format1_fops);
David Teigland20abf972006-07-26 08:29:06 -0500671 if (!ls->ls_debug_rsb_dentry)
David Teiglandd0225092008-12-16 14:53:23 -0600672 goto fail;
David Teigland5de63192006-07-25 13:44:31 -0500673
David Teiglandd0225092008-12-16 14:53:23 -0600674 /* format 2 */
David Teigland5de63192006-07-25 13:44:31 -0500675
David Teigland9dd592d2007-05-29 08:47:04 -0500676 memset(name, 0, sizeof(name));
David Teiglandac90a252007-07-06 09:47:08 -0500677 snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name);
David Teigland9dd592d2007-05-29 08:47:04 -0500678
David Teiglandac90a252007-07-06 09:47:08 -0500679 ls->ls_debug_locks_dentry = debugfs_create_file(name,
680 S_IFREG | S_IRUGO,
681 dlm_root,
682 ls,
David Teigland892c4462009-01-07 16:48:52 -0600683 &format2_fops);
David Teiglandd0225092008-12-16 14:53:23 -0600684 if (!ls->ls_debug_locks_dentry)
685 goto fail;
686
687 /* format 3 */
688
689 memset(name, 0, sizeof(name));
690 snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name);
691
692 ls->ls_debug_all_dentry = debugfs_create_file(name,
693 S_IFREG | S_IRUGO,
694 dlm_root,
695 ls,
David Teigland892c4462009-01-07 16:48:52 -0600696 &format3_fops);
David Teiglandd0225092008-12-16 14:53:23 -0600697 if (!ls->ls_debug_all_dentry)
698 goto fail;
699
700 memset(name, 0, sizeof(name));
701 snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name);
702
703 ls->ls_debug_waiters_dentry = debugfs_create_file(name,
704 S_IFREG | S_IRUGO,
705 dlm_root,
706 ls,
707 &waiters_fops);
708 if (!ls->ls_debug_waiters_dentry)
709 goto fail;
David Teigland9dd592d2007-05-29 08:47:04 -0500710
David Teigland5de63192006-07-25 13:44:31 -0500711 return 0;
David Teiglande7fd4172006-01-18 09:30:29 +0000712
David Teiglandd0225092008-12-16 14:53:23 -0600713 fail:
714 dlm_delete_debug_file(ls);
715 return -ENOMEM;
David Teiglande7fd4172006-01-18 09:30:29 +0000716}
717
Denis Cheng30727172008-02-02 01:53:46 +0800718int __init dlm_register_debugfs(void)
David Teiglande7fd4172006-01-18 09:30:29 +0000719{
David Teigland5de63192006-07-25 13:44:31 -0500720 mutex_init(&debug_buf_lock);
David Teiglande7fd4172006-01-18 09:30:29 +0000721 dlm_root = debugfs_create_dir("dlm", NULL);
722 return dlm_root ? 0 : -ENOMEM;
723}
724
725void dlm_unregister_debugfs(void)
726{
727 debugfs_remove(dlm_root);
728}
729