]>
Commit | Line | Data |
---|---|---|
e7fd4179 DT |
1 | /****************************************************************************** |
2 | ******************************************************************************* | |
3 | ** | |
892c4467 | 4 | ** Copyright (C) 2005-2009 Red Hat, Inc. All rights reserved. |
e7fd4179 DT |
5 | ** |
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> | |
5a0e3ad6 | 18 | #include <linux/slab.h> |
e7fd4179 DT |
19 | |
20 | #include "dlm_internal.h" | |
916297aa | 21 | #include "lock.h" |
e7fd4179 | 22 | |
5de6319b DT |
23 | #define DLM_DEBUG_BUF_LEN 4096 |
24 | static char debug_buf[DLM_DEBUG_BUF_LEN]; | |
25 | static struct mutex debug_buf_lock; | |
e7fd4179 DT |
26 | |
27 | static struct dentry *dlm_root; | |
28 | ||
e7fd4179 DT |
29 | static char *print_lockmode(int mode) |
30 | { | |
31 | switch (mode) { | |
32 | case DLM_LOCK_IV: | |
33 | return "--"; | |
34 | case DLM_LOCK_NL: | |
35 | return "NL"; | |
36 | case DLM_LOCK_CR: | |
37 | return "CR"; | |
38 | case DLM_LOCK_CW: | |
39 | return "CW"; | |
40 | case DLM_LOCK_PR: | |
41 | return "PR"; | |
42 | case DLM_LOCK_PW: | |
43 | return "PW"; | |
44 | case DLM_LOCK_EX: | |
45 | return "EX"; | |
46 | default: | |
47 | return "??"; | |
48 | } | |
49 | } | |
50 | ||
892c4467 DT |
51 | static int print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb, |
52 | struct dlm_rsb *res) | |
e7fd4179 DT |
53 | { |
54 | seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode)); | |
55 | ||
892c4467 DT |
56 | if (lkb->lkb_status == DLM_LKSTS_CONVERT || |
57 | lkb->lkb_status == DLM_LKSTS_WAITING) | |
e7fd4179 DT |
58 | seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode)); |
59 | ||
e7fd4179 DT |
60 | if (lkb->lkb_nodeid) { |
61 | if (lkb->lkb_nodeid != res->res_nodeid) | |
62 | seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid, | |
63 | lkb->lkb_remid); | |
64 | else | |
65 | seq_printf(s, " Master: %08x", lkb->lkb_remid); | |
66 | } | |
67 | ||
68 | if (lkb->lkb_wait_type) | |
69 | seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); | |
70 | ||
892c4467 | 71 | return seq_printf(s, "\n"); |
e7fd4179 DT |
72 | } |
73 | ||
d022509d | 74 | static int print_format1(struct dlm_rsb *res, struct seq_file *s) |
e7fd4179 DT |
75 | { |
76 | struct dlm_lkb *lkb; | |
5de6319b | 77 | int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list; |
892c4467 | 78 | int rv; |
e7fd4179 | 79 | |
9dd592d7 DT |
80 | lock_rsb(res); |
81 | ||
892c4467 DT |
82 | rv = seq_printf(s, "\nResource %p Name (len=%d) \"", |
83 | res, res->res_length); | |
84 | if (rv) | |
85 | goto out; | |
86 | ||
e7fd4179 DT |
87 | for (i = 0; i < res->res_length; i++) { |
88 | if (isprint(res->res_name[i])) | |
89 | seq_printf(s, "%c", res->res_name[i]); | |
90 | else | |
91 | seq_printf(s, "%c", '.'); | |
92 | } | |
892c4467 | 93 | |
e7fd4179 | 94 | if (res->res_nodeid > 0) |
892c4467 DT |
95 | rv = seq_printf(s, "\" \nLocal Copy, Master is node %d\n", |
96 | res->res_nodeid); | |
e7fd4179 | 97 | else if (res->res_nodeid == 0) |
892c4467 | 98 | rv = seq_printf(s, "\" \nMaster Copy\n"); |
e7fd4179 | 99 | else if (res->res_nodeid == -1) |
892c4467 DT |
100 | rv = seq_printf(s, "\" \nLooking up master (lkid %x)\n", |
101 | res->res_first_lkid); | |
e7fd4179 | 102 | else |
892c4467 DT |
103 | rv = seq_printf(s, "\" \nInvalid master %d\n", |
104 | res->res_nodeid); | |
105 | if (rv) | |
106 | goto out; | |
e7fd4179 DT |
107 | |
108 | /* Print the LVB: */ | |
109 | if (res->res_lvbptr) { | |
110 | seq_printf(s, "LVB: "); | |
111 | for (i = 0; i < lvblen; i++) { | |
112 | if (i == lvblen / 2) | |
113 | seq_printf(s, "\n "); | |
114 | seq_printf(s, "%02x ", | |
115 | (unsigned char) res->res_lvbptr[i]); | |
116 | } | |
117 | if (rsb_flag(res, RSB_VALNOTVALID)) | |
118 | seq_printf(s, " (INVALID)"); | |
892c4467 DT |
119 | rv = seq_printf(s, "\n"); |
120 | if (rv) | |
121 | goto out; | |
e7fd4179 DT |
122 | } |
123 | ||
5de6319b DT |
124 | root_list = !list_empty(&res->res_root_list); |
125 | recover_list = !list_empty(&res->res_recover_list); | |
126 | ||
127 | if (root_list || recover_list) { | |
892c4467 DT |
128 | rv = seq_printf(s, "Recovery: root %d recover %d flags %lx " |
129 | "count %d\n", root_list, recover_list, | |
130 | res->res_flags, res->res_recover_locks_count); | |
131 | if (rv) | |
132 | goto out; | |
5de6319b DT |
133 | } |
134 | ||
e7fd4179 DT |
135 | /* Print the locks attached to this resource */ |
136 | seq_printf(s, "Granted Queue\n"); | |
892c4467 DT |
137 | list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) { |
138 | rv = print_format1_lock(s, lkb, res); | |
139 | if (rv) | |
140 | goto out; | |
141 | } | |
e7fd4179 DT |
142 | |
143 | seq_printf(s, "Conversion Queue\n"); | |
892c4467 DT |
144 | list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) { |
145 | rv = print_format1_lock(s, lkb, res); | |
146 | if (rv) | |
147 | goto out; | |
148 | } | |
e7fd4179 DT |
149 | |
150 | seq_printf(s, "Waiting Queue\n"); | |
892c4467 DT |
151 | list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) { |
152 | rv = print_format1_lock(s, lkb, res); | |
153 | if (rv) | |
154 | goto out; | |
155 | } | |
e7fd4179 | 156 | |
5de6319b DT |
157 | if (list_empty(&res->res_lookup)) |
158 | goto out; | |
159 | ||
160 | seq_printf(s, "Lookup Queue\n"); | |
161 | list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) { | |
892c4467 DT |
162 | rv = seq_printf(s, "%08x %s", lkb->lkb_id, |
163 | print_lockmode(lkb->lkb_rqmode)); | |
5de6319b DT |
164 | if (lkb->lkb_wait_type) |
165 | seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); | |
892c4467 | 166 | rv = seq_printf(s, "\n"); |
5de6319b DT |
167 | } |
168 | out: | |
9dd592d7 | 169 | unlock_rsb(res); |
892c4467 | 170 | return rv; |
9dd592d7 DT |
171 | } |
172 | ||
892c4467 DT |
173 | static int print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb, |
174 | struct dlm_rsb *r) | |
9dd592d7 | 175 | { |
eeda418d DT |
176 | u64 xid = 0; |
177 | u64 us; | |
892c4467 | 178 | int rv; |
9dd592d7 DT |
179 | |
180 | if (lkb->lkb_flags & DLM_IFL_USER) { | |
d292c0cc DT |
181 | if (lkb->lkb_ua) |
182 | xid = lkb->lkb_ua->xid; | |
9dd592d7 DT |
183 | } |
184 | ||
eeda418d DT |
185 | /* microseconds since lkb was added to current queue */ |
186 | us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_timestamp)); | |
9dd592d7 | 187 | |
eeda418d | 188 | /* id nodeid remid pid xid exflags flags sts grmode rqmode time_us |
ac90a255 | 189 | r_nodeid r_len r_name */ |
9dd592d7 | 190 | |
892c4467 DT |
191 | rv = seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n", |
192 | lkb->lkb_id, | |
193 | lkb->lkb_nodeid, | |
194 | lkb->lkb_remid, | |
195 | lkb->lkb_ownpid, | |
196 | (unsigned long long)xid, | |
197 | lkb->lkb_exflags, | |
198 | lkb->lkb_flags, | |
199 | lkb->lkb_status, | |
200 | lkb->lkb_grmode, | |
201 | lkb->lkb_rqmode, | |
202 | (unsigned long long)us, | |
203 | r->res_nodeid, | |
204 | r->res_length, | |
205 | r->res_name); | |
206 | return rv; | |
9dd592d7 DT |
207 | } |
208 | ||
d022509d | 209 | static int print_format2(struct dlm_rsb *r, struct seq_file *s) |
9dd592d7 DT |
210 | { |
211 | struct dlm_lkb *lkb; | |
892c4467 | 212 | int rv = 0; |
9dd592d7 DT |
213 | |
214 | lock_rsb(r); | |
215 | ||
892c4467 DT |
216 | list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { |
217 | rv = print_format2_lock(s, lkb, r); | |
218 | if (rv) | |
219 | goto out; | |
220 | } | |
9dd592d7 | 221 | |
892c4467 DT |
222 | list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { |
223 | rv = print_format2_lock(s, lkb, r); | |
224 | if (rv) | |
225 | goto out; | |
226 | } | |
d022509d | 227 | |
892c4467 DT |
228 | list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) { |
229 | rv = print_format2_lock(s, lkb, r); | |
230 | if (rv) | |
231 | goto out; | |
232 | } | |
233 | out: | |
d022509d | 234 | unlock_rsb(r); |
892c4467 | 235 | return rv; |
d022509d DT |
236 | } |
237 | ||
892c4467 DT |
238 | static int print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb, |
239 | int rsb_lookup) | |
d022509d DT |
240 | { |
241 | u64 xid = 0; | |
892c4467 | 242 | int rv; |
d022509d DT |
243 | |
244 | if (lkb->lkb_flags & DLM_IFL_USER) { | |
245 | if (lkb->lkb_ua) | |
246 | xid = lkb->lkb_ua->xid; | |
247 | } | |
248 | ||
892c4467 DT |
249 | rv = seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n", |
250 | lkb->lkb_id, | |
251 | lkb->lkb_nodeid, | |
252 | lkb->lkb_remid, | |
253 | lkb->lkb_ownpid, | |
254 | (unsigned long long)xid, | |
255 | lkb->lkb_exflags, | |
256 | lkb->lkb_flags, | |
257 | lkb->lkb_status, | |
258 | lkb->lkb_grmode, | |
259 | lkb->lkb_rqmode, | |
b6fa8796 | 260 | lkb->lkb_bastmode, |
892c4467 DT |
261 | rsb_lookup, |
262 | lkb->lkb_wait_type, | |
263 | lkb->lkb_lvbseq, | |
264 | (unsigned long long)ktime_to_ns(lkb->lkb_timestamp), | |
265 | (unsigned long long)ktime_to_ns(lkb->lkb_time_bast)); | |
266 | return rv; | |
d022509d DT |
267 | } |
268 | ||
269 | static int print_format3(struct dlm_rsb *r, struct seq_file *s) | |
270 | { | |
271 | struct dlm_lkb *lkb; | |
272 | int i, lvblen = r->res_ls->ls_lvblen; | |
273 | int print_name = 1; | |
892c4467 | 274 | int rv; |
d022509d DT |
275 | |
276 | lock_rsb(r); | |
277 | ||
892c4467 DT |
278 | rv = seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ", |
279 | r, | |
280 | r->res_nodeid, | |
281 | r->res_first_lkid, | |
282 | r->res_flags, | |
283 | !list_empty(&r->res_root_list), | |
284 | !list_empty(&r->res_recover_list), | |
285 | r->res_recover_locks_count, | |
286 | r->res_length); | |
287 | if (rv) | |
288 | goto out; | |
d022509d DT |
289 | |
290 | for (i = 0; i < r->res_length; i++) { | |
291 | if (!isascii(r->res_name[i]) || !isprint(r->res_name[i])) | |
292 | print_name = 0; | |
293 | } | |
294 | ||
295 | seq_printf(s, "%s", print_name ? "str " : "hex"); | |
296 | ||
297 | for (i = 0; i < r->res_length; i++) { | |
298 | if (print_name) | |
299 | seq_printf(s, "%c", r->res_name[i]); | |
300 | else | |
301 | seq_printf(s, " %02x", (unsigned char)r->res_name[i]); | |
302 | } | |
892c4467 DT |
303 | rv = seq_printf(s, "\n"); |
304 | if (rv) | |
305 | goto out; | |
d022509d DT |
306 | |
307 | if (!r->res_lvbptr) | |
308 | goto do_locks; | |
309 | ||
310 | seq_printf(s, "lvb %u %d", r->res_lvbseq, lvblen); | |
311 | ||
312 | for (i = 0; i < lvblen; i++) | |
313 | seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]); | |
892c4467 DT |
314 | rv = seq_printf(s, "\n"); |
315 | if (rv) | |
316 | goto out; | |
d022509d DT |
317 | |
318 | do_locks: | |
892c4467 DT |
319 | list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { |
320 | rv = print_format3_lock(s, lkb, 0); | |
321 | if (rv) | |
322 | goto out; | |
e7fd4179 | 323 | } |
e7fd4179 | 324 | |
892c4467 DT |
325 | list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { |
326 | rv = print_format3_lock(s, lkb, 0); | |
327 | if (rv) | |
328 | goto out; | |
e7fd4179 DT |
329 | } |
330 | ||
892c4467 DT |
331 | list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) { |
332 | rv = print_format3_lock(s, lkb, 0); | |
333 | if (rv) | |
334 | goto out; | |
e7fd4179 DT |
335 | } |
336 | ||
892c4467 DT |
337 | list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) { |
338 | rv = print_format3_lock(s, lkb, 1); | |
339 | if (rv) | |
340 | goto out; | |
e7fd4179 | 341 | } |
892c4467 DT |
342 | out: |
343 | unlock_rsb(r); | |
344 | return rv; | |
e7fd4179 DT |
345 | } |
346 | ||
892c4467 DT |
347 | struct rsbtbl_iter { |
348 | struct dlm_rsb *rsb; | |
349 | unsigned bucket; | |
350 | int format; | |
351 | int header; | |
352 | }; | |
e7fd4179 | 353 | |
892c4467 DT |
354 | /* seq_printf returns -1 if the buffer is full, and 0 otherwise. |
355 | If the buffer is full, seq_printf can be called again, but it | |
356 | does nothing and just returns -1. So, the these printing routines | |
357 | periodically check the return value to avoid wasting too much time | |
358 | trying to print to a full buffer. */ | |
359 | ||
360 | static int table_seq_show(struct seq_file *seq, void *iter_ptr) | |
e7fd4179 | 361 | { |
892c4467 DT |
362 | struct rsbtbl_iter *ri = iter_ptr; |
363 | int rv = 0; | |
e7fd4179 | 364 | |
d022509d DT |
365 | switch (ri->format) { |
366 | case 1: | |
892c4467 | 367 | rv = print_format1(ri->rsb, seq); |
d022509d DT |
368 | break; |
369 | case 2: | |
9dd592d7 | 370 | if (ri->header) { |
892c4467 DT |
371 | seq_printf(seq, "id nodeid remid pid xid exflags " |
372 | "flags sts grmode rqmode time_ms " | |
373 | "r_nodeid r_len r_name\n"); | |
9dd592d7 DT |
374 | ri->header = 0; |
375 | } | |
892c4467 | 376 | rv = print_format2(ri->rsb, seq); |
d022509d DT |
377 | break; |
378 | case 3: | |
379 | if (ri->header) { | |
892c4467 | 380 | seq_printf(seq, "version rsb 1.1 lvb 1.1 lkb 1.1\n"); |
d022509d DT |
381 | ri->header = 0; |
382 | } | |
892c4467 | 383 | rv = print_format3(ri->rsb, seq); |
d022509d | 384 | break; |
9dd592d7 | 385 | } |
e7fd4179 | 386 | |
892c4467 | 387 | return rv; |
e7fd4179 DT |
388 | } |
389 | ||
88e9d34c JM |
390 | static const struct seq_operations format1_seq_ops; |
391 | static const struct seq_operations format2_seq_ops; | |
392 | static const struct seq_operations format3_seq_ops; | |
e7fd4179 | 393 | |
892c4467 | 394 | static void *table_seq_start(struct seq_file *seq, loff_t *pos) |
e7fd4179 | 395 | { |
892c4467 DT |
396 | struct dlm_ls *ls = seq->private; |
397 | struct rsbtbl_iter *ri; | |
398 | struct dlm_rsb *r; | |
399 | loff_t n = *pos; | |
400 | unsigned bucket, entry; | |
e7fd4179 | 401 | |
892c4467 DT |
402 | bucket = n >> 32; |
403 | entry = n & ((1LL << 32) - 1); | |
9dd592d7 | 404 | |
892c4467 DT |
405 | if (bucket >= ls->ls_rsbtbl_size) |
406 | return NULL; | |
9dd592d7 | 407 | |
573c24c4 | 408 | ri = kzalloc(sizeof(struct rsbtbl_iter), GFP_NOFS); |
9dd592d7 DT |
409 | if (!ri) |
410 | return NULL; | |
892c4467 | 411 | if (n == 0) |
9dd592d7 | 412 | ri->header = 1; |
892c4467 DT |
413 | if (seq->op == &format1_seq_ops) |
414 | ri->format = 1; | |
415 | if (seq->op == &format2_seq_ops) | |
416 | ri->format = 2; | |
417 | if (seq->op == &format3_seq_ops) | |
418 | ri->format = 3; | |
419 | ||
c7be761a | 420 | spin_lock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
421 | if (!list_empty(&ls->ls_rsbtbl[bucket].list)) { |
422 | list_for_each_entry(r, &ls->ls_rsbtbl[bucket].list, | |
423 | res_hashchain) { | |
424 | if (!entry--) { | |
425 | dlm_hold_rsb(r); | |
426 | ri->rsb = r; | |
427 | ri->bucket = bucket; | |
c7be761a | 428 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
429 | return ri; |
430 | } | |
431 | } | |
9dd592d7 | 432 | } |
c7be761a | 433 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
9dd592d7 | 434 | |
892c4467 DT |
435 | /* |
436 | * move to the first rsb in the next non-empty bucket | |
437 | */ | |
9dd592d7 | 438 | |
892c4467 DT |
439 | /* zero the entry */ |
440 | n &= ~((1LL << 32) - 1); | |
9dd592d7 | 441 | |
892c4467 DT |
442 | while (1) { |
443 | bucket++; | |
444 | n += 1LL << 32; | |
9dd592d7 | 445 | |
892c4467 DT |
446 | if (bucket >= ls->ls_rsbtbl_size) { |
447 | kfree(ri); | |
9dd592d7 DT |
448 | return NULL; |
449 | } | |
9dd592d7 | 450 | |
c7be761a | 451 | spin_lock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
452 | if (!list_empty(&ls->ls_rsbtbl[bucket].list)) { |
453 | r = list_first_entry(&ls->ls_rsbtbl[bucket].list, | |
454 | struct dlm_rsb, res_hashchain); | |
455 | dlm_hold_rsb(r); | |
456 | ri->rsb = r; | |
457 | ri->bucket = bucket; | |
c7be761a | 458 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
459 | *pos = n; |
460 | return ri; | |
461 | } | |
c7be761a | 462 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 | 463 | } |
9dd592d7 DT |
464 | } |
465 | ||
892c4467 | 466 | static void *table_seq_next(struct seq_file *seq, void *iter_ptr, loff_t *pos) |
9dd592d7 | 467 | { |
892c4467 DT |
468 | struct dlm_ls *ls = seq->private; |
469 | struct rsbtbl_iter *ri = iter_ptr; | |
470 | struct list_head *next; | |
471 | struct dlm_rsb *r, *rp; | |
472 | loff_t n = *pos; | |
473 | unsigned bucket; | |
474 | ||
475 | bucket = n >> 32; | |
476 | ||
477 | /* | |
478 | * move to the next rsb in the same bucket | |
479 | */ | |
480 | ||
c7be761a | 481 | spin_lock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
482 | rp = ri->rsb; |
483 | next = rp->res_hashchain.next; | |
484 | ||
485 | if (next != &ls->ls_rsbtbl[bucket].list) { | |
486 | r = list_entry(next, struct dlm_rsb, res_hashchain); | |
487 | dlm_hold_rsb(r); | |
488 | ri->rsb = r; | |
c7be761a | 489 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
490 | dlm_put_rsb(rp); |
491 | ++*pos; | |
492 | return ri; | |
493 | } | |
c7be761a | 494 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 | 495 | dlm_put_rsb(rp); |
d022509d | 496 | |
892c4467 DT |
497 | /* |
498 | * move to the first rsb in the next non-empty bucket | |
499 | */ | |
d022509d | 500 | |
892c4467 DT |
501 | /* zero the entry */ |
502 | n &= ~((1LL << 32) - 1); | |
d022509d | 503 | |
892c4467 DT |
504 | while (1) { |
505 | bucket++; | |
506 | n += 1LL << 32; | |
d022509d | 507 | |
892c4467 DT |
508 | if (bucket >= ls->ls_rsbtbl_size) { |
509 | kfree(ri); | |
510 | return NULL; | |
511 | } | |
d022509d | 512 | |
c7be761a | 513 | spin_lock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
514 | if (!list_empty(&ls->ls_rsbtbl[bucket].list)) { |
515 | r = list_first_entry(&ls->ls_rsbtbl[bucket].list, | |
516 | struct dlm_rsb, res_hashchain); | |
517 | dlm_hold_rsb(r); | |
518 | ri->rsb = r; | |
519 | ri->bucket = bucket; | |
c7be761a | 520 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
892c4467 DT |
521 | *pos = n; |
522 | return ri; | |
523 | } | |
c7be761a | 524 | spin_unlock(&ls->ls_rsbtbl[bucket].lock); |
d022509d | 525 | } |
d022509d DT |
526 | } |
527 | ||
892c4467 | 528 | static void table_seq_stop(struct seq_file *seq, void *iter_ptr) |
d022509d | 529 | { |
892c4467 | 530 | struct rsbtbl_iter *ri = iter_ptr; |
d022509d | 531 | |
892c4467 DT |
532 | if (ri) { |
533 | dlm_put_rsb(ri->rsb); | |
534 | kfree(ri); | |
d022509d | 535 | } |
d022509d DT |
536 | } |
537 | ||
88e9d34c | 538 | static const struct seq_operations format1_seq_ops = { |
892c4467 DT |
539 | .start = table_seq_start, |
540 | .next = table_seq_next, | |
541 | .stop = table_seq_stop, | |
542 | .show = table_seq_show, | |
d022509d DT |
543 | }; |
544 | ||
88e9d34c | 545 | static const struct seq_operations format2_seq_ops = { |
892c4467 DT |
546 | .start = table_seq_start, |
547 | .next = table_seq_next, | |
548 | .stop = table_seq_stop, | |
549 | .show = table_seq_show, | |
550 | }; | |
551 | ||
88e9d34c | 552 | static const struct seq_operations format3_seq_ops = { |
892c4467 DT |
553 | .start = table_seq_start, |
554 | .next = table_seq_next, | |
555 | .stop = table_seq_stop, | |
556 | .show = table_seq_show, | |
557 | }; | |
558 | ||
559 | static const struct file_operations format1_fops; | |
560 | static const struct file_operations format2_fops; | |
561 | static const struct file_operations format3_fops; | |
562 | ||
563 | static int table_open(struct inode *inode, struct file *file) | |
d022509d DT |
564 | { |
565 | struct seq_file *seq; | |
892c4467 DT |
566 | int ret = -1; |
567 | ||
568 | if (file->f_op == &format1_fops) | |
569 | ret = seq_open(file, &format1_seq_ops); | |
570 | else if (file->f_op == &format2_fops) | |
571 | ret = seq_open(file, &format2_seq_ops); | |
572 | else if (file->f_op == &format3_fops) | |
573 | ret = seq_open(file, &format3_seq_ops); | |
d022509d | 574 | |
d022509d DT |
575 | if (ret) |
576 | return ret; | |
577 | ||
578 | seq = file->private_data; | |
892c4467 | 579 | seq->private = inode->i_private; /* the dlm_ls */ |
d022509d DT |
580 | return 0; |
581 | } | |
582 | ||
892c4467 DT |
583 | static const struct file_operations format1_fops = { |
584 | .owner = THIS_MODULE, | |
585 | .open = table_open, | |
586 | .read = seq_read, | |
587 | .llseek = seq_lseek, | |
588 | .release = seq_release | |
589 | }; | |
590 | ||
591 | static const struct file_operations format2_fops = { | |
592 | .owner = THIS_MODULE, | |
593 | .open = table_open, | |
594 | .read = seq_read, | |
595 | .llseek = seq_lseek, | |
596 | .release = seq_release | |
597 | }; | |
598 | ||
599 | static const struct file_operations format3_fops = { | |
d022509d | 600 | .owner = THIS_MODULE, |
892c4467 | 601 | .open = table_open, |
d022509d DT |
602 | .read = seq_read, |
603 | .llseek = seq_lseek, | |
604 | .release = seq_release | |
605 | }; | |
606 | ||
5de6319b DT |
607 | /* |
608 | * dump lkb's on the ls_waiters list | |
609 | */ | |
610 | ||
611 | static int waiters_open(struct inode *inode, struct file *file) | |
612 | { | |
bba9dfd8 | 613 | file->private_data = inode->i_private; |
5de6319b DT |
614 | return 0; |
615 | } | |
616 | ||
617 | static ssize_t waiters_read(struct file *file, char __user *userbuf, | |
618 | size_t count, loff_t *ppos) | |
619 | { | |
620 | struct dlm_ls *ls = file->private_data; | |
621 | struct dlm_lkb *lkb; | |
06442440 | 622 | size_t len = DLM_DEBUG_BUF_LEN, pos = 0, ret, rv; |
5de6319b DT |
623 | |
624 | mutex_lock(&debug_buf_lock); | |
625 | mutex_lock(&ls->ls_waiters_mutex); | |
626 | memset(debug_buf, 0, sizeof(debug_buf)); | |
627 | ||
628 | list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) { | |
06442440 DT |
629 | ret = snprintf(debug_buf + pos, len - pos, "%x %d %d %s\n", |
630 | lkb->lkb_id, lkb->lkb_wait_type, | |
631 | lkb->lkb_nodeid, lkb->lkb_resource->res_name); | |
632 | if (ret >= len - pos) | |
633 | break; | |
634 | pos += ret; | |
5de6319b DT |
635 | } |
636 | mutex_unlock(&ls->ls_waiters_mutex); | |
637 | ||
638 | rv = simple_read_from_buffer(userbuf, count, ppos, debug_buf, pos); | |
639 | mutex_unlock(&debug_buf_lock); | |
640 | return rv; | |
641 | } | |
642 | ||
00977a59 | 643 | static const struct file_operations waiters_fops = { |
5de6319b DT |
644 | .owner = THIS_MODULE, |
645 | .open = waiters_open, | |
6038f373 AB |
646 | .read = waiters_read, |
647 | .llseek = default_llseek, | |
5de6319b DT |
648 | }; |
649 | ||
d022509d DT |
650 | void dlm_delete_debug_file(struct dlm_ls *ls) |
651 | { | |
652 | if (ls->ls_debug_rsb_dentry) | |
653 | debugfs_remove(ls->ls_debug_rsb_dentry); | |
654 | if (ls->ls_debug_waiters_dentry) | |
655 | debugfs_remove(ls->ls_debug_waiters_dentry); | |
656 | if (ls->ls_debug_locks_dentry) | |
657 | debugfs_remove(ls->ls_debug_locks_dentry); | |
658 | if (ls->ls_debug_all_dentry) | |
659 | debugfs_remove(ls->ls_debug_all_dentry); | |
660 | } | |
661 | ||
e7fd4179 DT |
662 | int dlm_create_debug_file(struct dlm_ls *ls) |
663 | { | |
5de6319b DT |
664 | char name[DLM_LOCKSPACE_LEN+8]; |
665 | ||
d022509d DT |
666 | /* format 1 */ |
667 | ||
5de6319b DT |
668 | ls->ls_debug_rsb_dentry = debugfs_create_file(ls->ls_name, |
669 | S_IFREG | S_IRUGO, | |
670 | dlm_root, | |
671 | ls, | |
892c4467 | 672 | &format1_fops); |
20abf975 | 673 | if (!ls->ls_debug_rsb_dentry) |
d022509d | 674 | goto fail; |
5de6319b | 675 | |
d022509d | 676 | /* format 2 */ |
5de6319b | 677 | |
9dd592d7 | 678 | memset(name, 0, sizeof(name)); |
ac90a255 DT |
679 | snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_locks", ls->ls_name); |
680 | ||
681 | ls->ls_debug_locks_dentry = debugfs_create_file(name, | |
682 | S_IFREG | S_IRUGO, | |
683 | dlm_root, | |
684 | ls, | |
892c4467 | 685 | &format2_fops); |
d022509d DT |
686 | if (!ls->ls_debug_locks_dentry) |
687 | goto fail; | |
688 | ||
689 | /* format 3 */ | |
690 | ||
691 | memset(name, 0, sizeof(name)); | |
692 | snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_all", ls->ls_name); | |
693 | ||
694 | ls->ls_debug_all_dentry = debugfs_create_file(name, | |
695 | S_IFREG | S_IRUGO, | |
696 | dlm_root, | |
697 | ls, | |
892c4467 | 698 | &format3_fops); |
d022509d DT |
699 | if (!ls->ls_debug_all_dentry) |
700 | goto fail; | |
701 | ||
702 | memset(name, 0, sizeof(name)); | |
703 | snprintf(name, DLM_LOCKSPACE_LEN+8, "%s_waiters", ls->ls_name); | |
704 | ||
705 | ls->ls_debug_waiters_dentry = debugfs_create_file(name, | |
706 | S_IFREG | S_IRUGO, | |
707 | dlm_root, | |
708 | ls, | |
709 | &waiters_fops); | |
710 | if (!ls->ls_debug_waiters_dentry) | |
711 | goto fail; | |
9dd592d7 | 712 | |
5de6319b | 713 | return 0; |
e7fd4179 | 714 | |
d022509d DT |
715 | fail: |
716 | dlm_delete_debug_file(ls); | |
717 | return -ENOMEM; | |
e7fd4179 DT |
718 | } |
719 | ||
30727174 | 720 | int __init dlm_register_debugfs(void) |
e7fd4179 | 721 | { |
5de6319b | 722 | mutex_init(&debug_buf_lock); |
e7fd4179 DT |
723 | dlm_root = debugfs_create_dir("dlm", NULL); |
724 | return dlm_root ? 0 : -ENOMEM; | |
725 | } | |
726 | ||
727 | void dlm_unregister_debugfs(void) | |
728 | { | |
729 | debugfs_remove(dlm_root); | |
730 | } | |
731 |