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));
63 /* FIXME: this warns on Alpha */
64 if (lkb->lkb_status == DLM_LKSTS_CONVERT
65 || lkb->lkb_status == DLM_LKSTS_GRANTED)
66 seq_printf(s, " %llx-%llx",
67 lkb->lkb_range[GR_RANGE_START],
68 lkb->lkb_range[GR_RANGE_END]);
69 if (lkb->lkb_status == DLM_LKSTS_CONVERT
70 || lkb->lkb_status == DLM_LKSTS_WAITING)
71 seq_printf(s, " (%llx-%llx)",
72 lkb->lkb_range[RQ_RANGE_START],
73 lkb->lkb_range[RQ_RANGE_END]);
76 if (lkb->lkb_nodeid) {
77 if (lkb->lkb_nodeid != res->res_nodeid)
78 seq_printf(s, " Remote: %3d %08x", lkb->lkb_nodeid,
81 seq_printf(s, " Master: %08x", lkb->lkb_remid);
84 if (lkb->lkb_wait_type)
85 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
90 static int print_resource(struct dlm_rsb *res, struct seq_file *s)
93 int i, lvblen = res->res_ls->ls_lvblen;
95 seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length);
96 for (i = 0; i < res->res_length; i++) {
97 if (isprint(res->res_name[i]))
98 seq_printf(s, "%c", res->res_name[i]);
100 seq_printf(s, "%c", '.');
102 if (res->res_nodeid > 0)
103 seq_printf(s, "\" \nLocal Copy, Master is node %d\n",
105 else if (res->res_nodeid == 0)
106 seq_printf(s, "\" \nMaster Copy\n");
107 else if (res->res_nodeid == -1)
108 seq_printf(s, "\" \nLooking up master (lkid %x)\n",
109 res->res_first_lkid);
111 seq_printf(s, "\" \nInvalid master %d\n", res->res_nodeid);
114 if (res->res_lvbptr) {
115 seq_printf(s, "LVB: ");
116 for (i = 0; i < lvblen; i++) {
118 seq_printf(s, "\n ");
119 seq_printf(s, "%02x ",
120 (unsigned char) res->res_lvbptr[i]);
122 if (rsb_flag(res, RSB_VALNOTVALID))
123 seq_printf(s, " (INVALID)");
127 /* Print the locks attached to this resource */
128 seq_printf(s, "Granted Queue\n");
129 list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue)
130 print_lock(s, lkb, res);
132 seq_printf(s, "Conversion Queue\n");
133 list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue)
134 print_lock(s, lkb, res);
136 seq_printf(s, "Waiting Queue\n");
137 list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue)
138 print_lock(s, lkb, res);
143 static int rsb_iter_next(struct rsb_iter *ri)
145 struct dlm_ls *ls = ri->ls;
150 /* Find the next non-empty hash bucket */
151 for (i = ri->entry; i < ls->ls_rsbtbl_size; i++) {
152 read_lock(&ls->ls_rsbtbl[i].lock);
153 if (!list_empty(&ls->ls_rsbtbl[i].list)) {
154 ri->next = ls->ls_rsbtbl[i].list.next;
155 read_unlock(&ls->ls_rsbtbl[i].lock);
158 read_unlock(&ls->ls_rsbtbl[i].lock);
162 if (ri->entry >= ls->ls_rsbtbl_size)
166 read_lock(&ls->ls_rsbtbl[i].lock);
167 ri->next = ri->next->next;
168 if (ri->next->next == ls->ls_rsbtbl[i].list.next) {
169 /* End of list - move to next bucket */
172 read_unlock(&ls->ls_rsbtbl[i].lock);
175 read_unlock(&ls->ls_rsbtbl[i].lock);
177 ri->rsb = list_entry(ri->next, struct dlm_rsb, res_hashchain);
182 static void rsb_iter_free(struct rsb_iter *ri)
187 static struct rsb_iter *rsb_iter_init(struct dlm_ls *ls)
191 ri = kmalloc(sizeof *ri, GFP_KERNEL);
199 if (rsb_iter_next(ri)) {
207 static void *seq_start(struct seq_file *file, loff_t *pos)
212 ri = rsb_iter_init(file->private);
217 if (rsb_iter_next(ri)) {
226 static void *seq_next(struct seq_file *file, void *iter_ptr, loff_t *pos)
228 struct rsb_iter *ri = iter_ptr;
232 if (rsb_iter_next(ri)) {
240 static void seq_stop(struct seq_file *file, void *iter_ptr)
242 /* nothing for now */
245 static int seq_show(struct seq_file *file, void *iter_ptr)
247 struct rsb_iter *ri = iter_ptr;
249 print_resource(ri->rsb, file);
254 static struct seq_operations dlm_seq_ops = {
261 static int do_open(struct inode *inode, struct file *file)
263 struct seq_file *seq;
266 ret = seq_open(file, &dlm_seq_ops);
270 seq = file->private_data;
271 seq->private = inode->u.generic_ip;
276 static struct file_operations dlm_fops = {
277 .owner = THIS_MODULE,
281 .release = seq_release
284 int dlm_create_debug_file(struct dlm_ls *ls)
286 ls->ls_debug_dentry = debugfs_create_file(ls->ls_name,
291 return ls->ls_debug_dentry ? 0 : -ENOMEM;
294 void dlm_delete_debug_file(struct dlm_ls *ls)
296 if (ls->ls_debug_dentry)
297 debugfs_remove(ls->ls_debug_dentry);
300 int dlm_register_debugfs(void)
302 dlm_root = debugfs_create_dir("dlm", NULL);
303 return dlm_root ? 0 : -ENOMEM;
306 void dlm_unregister_debugfs(void)
308 debugfs_remove(dlm_root);