1 /******************************************************************************
2 *******************************************************************************
4 ** Copyright (C) 2005 Red Hat, Inc. All rights reserved.
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.
10 *******************************************************************************
11 ******************************************************************************/
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>
19 #include "dlm_internal.h"
22 static struct dentry *dlm_root;
27 struct list_head *next;
31 static char *print_lockmode(int mode)
53 static void print_lock(struct seq_file *s, struct dlm_lkb *lkb,
56 seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode));
58 if (lkb->lkb_status == DLM_LKSTS_CONVERT
59 || lkb->lkb_status == DLM_LKSTS_WAITING)
60 seq_printf(s, " (%s)", print_lockmode(lkb->lkb_rqmode));
62 if (lkb->lkb_nodeid) {
63 if (lkb->lkb_nodeid != res->res_nodeid)
64 seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
67 seq_printf(s, " Master: %08x", lkb->lkb_remid);
70 if (lkb->lkb_wait_type)
71 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
76 static int print_resource(struct dlm_rsb *res, struct seq_file *s)
79 int i, lvblen = res->res_ls->ls_lvblen;
81 seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length);
82 for (i = 0; i < res->res_length; i++) {
83 if (isprint(res->res_name[i]))
84 seq_printf(s, "%c", res->res_name[i]);
86 seq_printf(s, "%c", '.');
88 if (res->res_nodeid > 0)
89 seq_printf(s, "\" \nLocal Copy, Master is node %d\n",
91 else if (res->res_nodeid == 0)
92 seq_printf(s, "\" \nMaster Copy\n");
93 else if (res->res_nodeid == -1)
94 seq_printf(s, "\" \nLooking up master (lkid %x)\n",
97 seq_printf(s, "\" \nInvalid master %d\n", res->res_nodeid);
100 if (res->res_lvbptr) {
101 seq_printf(s, "LVB: ");
102 for (i = 0; i < lvblen; i++) {
104 seq_printf(s, "\n ");
105 seq_printf(s, "%02x ",
106 (unsigned char) res->res_lvbptr[i]);
108 if (rsb_flag(res, RSB_VALNOTVALID))
109 seq_printf(s, " (INVALID)");
113 /* Print the locks attached to this resource */
114 seq_printf(s, "Granted Queue\n");
115 list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue)
116 print_lock(s, lkb, res);
118 seq_printf(s, "Conversion Queue\n");
119 list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue)
120 print_lock(s, lkb, res);
122 seq_printf(s, "Waiting Queue\n");
123 list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue)
124 print_lock(s, lkb, res);
129 static int rsb_iter_next(struct rsb_iter *ri)
131 struct dlm_ls *ls = ri->ls;
136 /* Find the next non-empty hash bucket */
137 for (i = ri->entry; i < ls->ls_rsbtbl_size; i++) {
138 read_lock(&ls->ls_rsbtbl[i].lock);
139 if (!list_empty(&ls->ls_rsbtbl[i].list)) {
140 ri->next = ls->ls_rsbtbl[i].list.next;
141 read_unlock(&ls->ls_rsbtbl[i].lock);
144 read_unlock(&ls->ls_rsbtbl[i].lock);
148 if (ri->entry >= ls->ls_rsbtbl_size)
152 read_lock(&ls->ls_rsbtbl[i].lock);
153 ri->next = ri->next->next;
154 if (ri->next->next == ls->ls_rsbtbl[i].list.next) {
155 /* End of list - move to next bucket */
158 read_unlock(&ls->ls_rsbtbl[i].lock);
161 read_unlock(&ls->ls_rsbtbl[i].lock);
163 ri->rsb = list_entry(ri->next, struct dlm_rsb, res_hashchain);
168 static void rsb_iter_free(struct rsb_iter *ri)
173 static struct rsb_iter *rsb_iter_init(struct dlm_ls *ls)
177 ri = kmalloc(sizeof *ri, GFP_KERNEL);
185 if (rsb_iter_next(ri)) {
193 static void *seq_start(struct seq_file *file, loff_t *pos)
198 ri = rsb_iter_init(file->private);
203 if (rsb_iter_next(ri)) {
212 static void *seq_next(struct seq_file *file, void *iter_ptr, loff_t *pos)
214 struct rsb_iter *ri = iter_ptr;
218 if (rsb_iter_next(ri)) {
226 static void seq_stop(struct seq_file *file, void *iter_ptr)
228 /* nothing for now */
231 static int seq_show(struct seq_file *file, void *iter_ptr)
233 struct rsb_iter *ri = iter_ptr;
235 print_resource(ri->rsb, file);
240 static struct seq_operations dlm_seq_ops = {
247 static int do_open(struct inode *inode, struct file *file)
249 struct seq_file *seq;
252 ret = seq_open(file, &dlm_seq_ops);
256 seq = file->private_data;
257 seq->private = inode->u.generic_ip;
262 static struct file_operations dlm_fops = {
263 .owner = THIS_MODULE,
267 .release = seq_release
270 int dlm_create_debug_file(struct dlm_ls *ls)
272 ls->ls_debug_dentry = debugfs_create_file(ls->ls_name,
277 return ls->ls_debug_dentry ? 0 : -ENOMEM;
280 void dlm_delete_debug_file(struct dlm_ls *ls)
282 if (ls->ls_debug_dentry)
283 debugfs_remove(ls->ls_debug_dentry);
286 int dlm_register_debugfs(void)
288 dlm_root = debugfs_create_dir("dlm", NULL);
289 return dlm_root ? 0 : -ENOMEM;
292 void dlm_unregister_debugfs(void)
294 debugfs_remove(dlm_root);