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