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