OSDN Git Service

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