aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2014-11-19 13:02:53 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2014-11-19 13:02:53 -0500
commit8ce74dd6057832618957fc2cbd38fa959c3a0a6c (patch)
treeaf3bede951087ebc58988ad073182a85bf899e27 /fs
parent78d28e651f97866d608d9b41f8ad291e65d47dd5 (diff)
parent9761536e1d9e9e1f325fb04d4ad46b15a39eb94a (diff)
Merge tag 'trace-seq-file-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace into for-next
Pull the beginning of seq_file cleanup from Steven: "I'm looking to clean up the seq_file code and to eventually merge the trace_seq code with seq_file as well, since they basically do the same thing. Part of this process is to remove the return code of seq_printf() and friends as they are rather inconsistent. It is better to use the new function seq_has_overflowed() if you want to stop processing when the buffer is full. Note, if the buffer is full, the seq_file code will throw away the contents, allocate a bigger buffer, and then call your code again to fill in the data. The only thing that breaking out of the function early does is to save a little time which is probably never noticed. I started with patches from Joe Perches and modified them as well. There's many more places that need to be updated before we can convert seq_printf() and friends to return void. But this patch set introduces the seq_has_overflowed() and does some initial updates."
Diffstat (limited to 'fs')
-rw-r--r--fs/debugfs/file.c15
-rw-r--r--fs/dlm/debug_fs.c263
-rw-r--r--fs/eventfd.c9
-rw-r--r--fs/eventpoll.c13
-rw-r--r--fs/notify/fdinfo.c78
-rw-r--r--fs/notify/fdinfo.h4
-rw-r--r--fs/proc/fd.c3
-rw-r--r--fs/seq_file.c15
-rw-r--r--fs/signalfd.c4
-rw-r--r--fs/timerfd.c27
10 files changed, 191 insertions, 240 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 76c08c2beb2f..8e0f2f410189 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -692,18 +692,19 @@ EXPORT_SYMBOL_GPL(debugfs_create_u32_array);
692 * because some peripherals have several blocks of identical registers, 692 * because some peripherals have several blocks of identical registers,
693 * for example configuration of dma channels 693 * for example configuration of dma channels
694 */ 694 */
695int debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs, 695void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
696 int nregs, void __iomem *base, char *prefix) 696 int nregs, void __iomem *base, char *prefix)
697{ 697{
698 int i, ret = 0; 698 int i;
699 699
700 for (i = 0; i < nregs; i++, regs++) { 700 for (i = 0; i < nregs; i++, regs++) {
701 if (prefix) 701 if (prefix)
702 ret += seq_printf(s, "%s", prefix); 702 seq_printf(s, "%s", prefix);
703 ret += seq_printf(s, "%s = 0x%08x\n", regs->name, 703 seq_printf(s, "%s = 0x%08x\n", regs->name,
704 readl(base + regs->offset)); 704 readl(base + regs->offset));
705 if (seq_has_overflowed(s))
706 break;
705 } 707 }
706 return ret;
707} 708}
708EXPORT_SYMBOL_GPL(debugfs_print_regs32); 709EXPORT_SYMBOL_GPL(debugfs_print_regs32);
709 710
diff --git a/fs/dlm/debug_fs.c b/fs/dlm/debug_fs.c
index 1323c568e362..eea64912c9c0 100644
--- a/fs/dlm/debug_fs.c
+++ b/fs/dlm/debug_fs.c
@@ -48,8 +48,8 @@ static char *print_lockmode(int mode)
48 } 48 }
49} 49}
50 50
51static int print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb, 51static void print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
52 struct dlm_rsb *res) 52 struct dlm_rsb *res)
53{ 53{
54 seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode)); 54 seq_printf(s, "%08x %s", lkb->lkb_id, print_lockmode(lkb->lkb_grmode));
55 55
@@ -68,21 +68,17 @@ static int print_format1_lock(struct seq_file *s, struct dlm_lkb *lkb,
68 if (lkb->lkb_wait_type) 68 if (lkb->lkb_wait_type)
69 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); 69 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
70 70
71 return seq_puts(s, "\n"); 71 seq_puts(s, "\n");
72} 72}
73 73
74static int print_format1(struct dlm_rsb *res, struct seq_file *s) 74static void print_format1(struct dlm_rsb *res, struct seq_file *s)
75{ 75{
76 struct dlm_lkb *lkb; 76 struct dlm_lkb *lkb;
77 int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list; 77 int i, lvblen = res->res_ls->ls_lvblen, recover_list, root_list;
78 int rv;
79 78
80 lock_rsb(res); 79 lock_rsb(res);
81 80
82 rv = seq_printf(s, "\nResource %p Name (len=%d) \"", 81 seq_printf(s, "\nResource %p Name (len=%d) \"", res, res->res_length);
83 res, res->res_length);
84 if (rv)
85 goto out;
86 82
87 for (i = 0; i < res->res_length; i++) { 83 for (i = 0; i < res->res_length; i++) {
88 if (isprint(res->res_name[i])) 84 if (isprint(res->res_name[i]))
@@ -92,17 +88,16 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s)
92 } 88 }
93 89
94 if (res->res_nodeid > 0) 90 if (res->res_nodeid > 0)
95 rv = seq_printf(s, "\"\nLocal Copy, Master is node %d\n", 91 seq_printf(s, "\"\nLocal Copy, Master is node %d\n",
96 res->res_nodeid); 92 res->res_nodeid);
97 else if (res->res_nodeid == 0) 93 else if (res->res_nodeid == 0)
98 rv = seq_puts(s, "\"\nMaster Copy\n"); 94 seq_puts(s, "\"\nMaster Copy\n");
99 else if (res->res_nodeid == -1) 95 else if (res->res_nodeid == -1)
100 rv = seq_printf(s, "\"\nLooking up master (lkid %x)\n", 96 seq_printf(s, "\"\nLooking up master (lkid %x)\n",
101 res->res_first_lkid); 97 res->res_first_lkid);
102 else 98 else
103 rv = seq_printf(s, "\"\nInvalid master %d\n", 99 seq_printf(s, "\"\nInvalid master %d\n", res->res_nodeid);
104 res->res_nodeid); 100 if (seq_has_overflowed(s))
105 if (rv)
106 goto out; 101 goto out;
107 102
108 /* Print the LVB: */ 103 /* Print the LVB: */
@@ -116,8 +111,8 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s)
116 } 111 }
117 if (rsb_flag(res, RSB_VALNOTVALID)) 112 if (rsb_flag(res, RSB_VALNOTVALID))
118 seq_puts(s, " (INVALID)"); 113 seq_puts(s, " (INVALID)");
119 rv = seq_puts(s, "\n"); 114 seq_puts(s, "\n");
120 if (rv) 115 if (seq_has_overflowed(s))
121 goto out; 116 goto out;
122 } 117 }
123 118
@@ -125,32 +120,30 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s)
125 recover_list = !list_empty(&res->res_recover_list); 120 recover_list = !list_empty(&res->res_recover_list);
126 121
127 if (root_list || recover_list) { 122 if (root_list || recover_list) {
128 rv = seq_printf(s, "Recovery: root %d recover %d flags %lx " 123 seq_printf(s, "Recovery: root %d recover %d flags %lx count %d\n",
129 "count %d\n", root_list, recover_list, 124 root_list, recover_list,
130 res->res_flags, res->res_recover_locks_count); 125 res->res_flags, res->res_recover_locks_count);
131 if (rv)
132 goto out;
133 } 126 }
134 127
135 /* Print the locks attached to this resource */ 128 /* Print the locks attached to this resource */
136 seq_puts(s, "Granted Queue\n"); 129 seq_puts(s, "Granted Queue\n");
137 list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) { 130 list_for_each_entry(lkb, &res->res_grantqueue, lkb_statequeue) {
138 rv = print_format1_lock(s, lkb, res); 131 print_format1_lock(s, lkb, res);
139 if (rv) 132 if (seq_has_overflowed(s))
140 goto out; 133 goto out;
141 } 134 }
142 135
143 seq_puts(s, "Conversion Queue\n"); 136 seq_puts(s, "Conversion Queue\n");
144 list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) { 137 list_for_each_entry(lkb, &res->res_convertqueue, lkb_statequeue) {
145 rv = print_format1_lock(s, lkb, res); 138 print_format1_lock(s, lkb, res);
146 if (rv) 139 if (seq_has_overflowed(s))
147 goto out; 140 goto out;
148 } 141 }
149 142
150 seq_puts(s, "Waiting Queue\n"); 143 seq_puts(s, "Waiting Queue\n");
151 list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) { 144 list_for_each_entry(lkb, &res->res_waitqueue, lkb_statequeue) {
152 rv = print_format1_lock(s, lkb, res); 145 print_format1_lock(s, lkb, res);
153 if (rv) 146 if (seq_has_overflowed(s))
154 goto out; 147 goto out;
155 } 148 }
156 149
@@ -159,23 +152,23 @@ static int print_format1(struct dlm_rsb *res, struct seq_file *s)
159 152
160 seq_puts(s, "Lookup Queue\n"); 153 seq_puts(s, "Lookup Queue\n");
161 list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) { 154 list_for_each_entry(lkb, &res->res_lookup, lkb_rsb_lookup) {
162 rv = seq_printf(s, "%08x %s", lkb->lkb_id, 155 seq_printf(s, "%08x %s",
163 print_lockmode(lkb->lkb_rqmode)); 156 lkb->lkb_id, print_lockmode(lkb->lkb_rqmode));
164 if (lkb->lkb_wait_type) 157 if (lkb->lkb_wait_type)
165 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type); 158 seq_printf(s, " wait_type: %d", lkb->lkb_wait_type);
166 rv = seq_puts(s, "\n"); 159 seq_puts(s, "\n");
160 if (seq_has_overflowed(s))
161 goto out;
167 } 162 }
168 out: 163 out:
169 unlock_rsb(res); 164 unlock_rsb(res);
170 return rv;
171} 165}
172 166
173static int print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb, 167static void print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
174 struct dlm_rsb *r) 168 struct dlm_rsb *r)
175{ 169{
176 u64 xid = 0; 170 u64 xid = 0;
177 u64 us; 171 u64 us;
178 int rv;
179 172
180 if (lkb->lkb_flags & DLM_IFL_USER) { 173 if (lkb->lkb_flags & DLM_IFL_USER) {
181 if (lkb->lkb_ua) 174 if (lkb->lkb_ua)
@@ -188,103 +181,97 @@ static int print_format2_lock(struct seq_file *s, struct dlm_lkb *lkb,
188 /* id nodeid remid pid xid exflags flags sts grmode rqmode time_us 181 /* id nodeid remid pid xid exflags flags sts grmode rqmode time_us
189 r_nodeid r_len r_name */ 182 r_nodeid r_len r_name */
190 183
191 rv = seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n", 184 seq_printf(s, "%x %d %x %u %llu %x %x %d %d %d %llu %u %d \"%s\"\n",
192 lkb->lkb_id, 185 lkb->lkb_id,
193 lkb->lkb_nodeid, 186 lkb->lkb_nodeid,
194 lkb->lkb_remid, 187 lkb->lkb_remid,
195 lkb->lkb_ownpid, 188 lkb->lkb_ownpid,
196 (unsigned long long)xid, 189 (unsigned long long)xid,
197 lkb->lkb_exflags, 190 lkb->lkb_exflags,
198 lkb->lkb_flags, 191 lkb->lkb_flags,
199 lkb->lkb_status, 192 lkb->lkb_status,
200 lkb->lkb_grmode, 193 lkb->lkb_grmode,
201 lkb->lkb_rqmode, 194 lkb->lkb_rqmode,
202 (unsigned long long)us, 195 (unsigned long long)us,
203 r->res_nodeid, 196 r->res_nodeid,
204 r->res_length, 197 r->res_length,
205 r->res_name); 198 r->res_name);
206 return rv;
207} 199}
208 200
209static int print_format2(struct dlm_rsb *r, struct seq_file *s) 201static void print_format2(struct dlm_rsb *r, struct seq_file *s)
210{ 202{
211 struct dlm_lkb *lkb; 203 struct dlm_lkb *lkb;
212 int rv = 0;
213 204
214 lock_rsb(r); 205 lock_rsb(r);
215 206
216 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { 207 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
217 rv = print_format2_lock(s, lkb, r); 208 print_format2_lock(s, lkb, r);
218 if (rv) 209 if (seq_has_overflowed(s))
219 goto out; 210 goto out;
220 } 211 }
221 212
222 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { 213 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
223 rv = print_format2_lock(s, lkb, r); 214 print_format2_lock(s, lkb, r);
224 if (rv) 215 if (seq_has_overflowed(s))
225 goto out; 216 goto out;
226 } 217 }
227 218
228 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) { 219 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
229 rv = print_format2_lock(s, lkb, r); 220 print_format2_lock(s, lkb, r);
230 if (rv) 221 if (seq_has_overflowed(s))
231 goto out; 222 goto out;
232 } 223 }
233 out: 224 out:
234 unlock_rsb(r); 225 unlock_rsb(r);
235 return rv;
236} 226}
237 227
238static int print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb, 228static void print_format3_lock(struct seq_file *s, struct dlm_lkb *lkb,
239 int rsb_lookup) 229 int rsb_lookup)
240{ 230{
241 u64 xid = 0; 231 u64 xid = 0;
242 int rv;
243 232
244 if (lkb->lkb_flags & DLM_IFL_USER) { 233 if (lkb->lkb_flags & DLM_IFL_USER) {
245 if (lkb->lkb_ua) 234 if (lkb->lkb_ua)
246 xid = lkb->lkb_ua->xid; 235 xid = lkb->lkb_ua->xid;
247 } 236 }
248 237
249 rv = seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n", 238 seq_printf(s, "lkb %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu\n",
250 lkb->lkb_id, 239 lkb->lkb_id,
251 lkb->lkb_nodeid, 240 lkb->lkb_nodeid,
252 lkb->lkb_remid, 241 lkb->lkb_remid,
253 lkb->lkb_ownpid, 242 lkb->lkb_ownpid,
254 (unsigned long long)xid, 243 (unsigned long long)xid,
255 lkb->lkb_exflags, 244 lkb->lkb_exflags,
256 lkb->lkb_flags, 245 lkb->lkb_flags,
257 lkb->lkb_status, 246 lkb->lkb_status,
258 lkb->lkb_grmode, 247 lkb->lkb_grmode,
259 lkb->lkb_rqmode, 248 lkb->lkb_rqmode,
260 lkb->lkb_last_bast.mode, 249 lkb->lkb_last_bast.mode,
261 rsb_lookup, 250 rsb_lookup,
262 lkb->lkb_wait_type, 251 lkb->lkb_wait_type,
263 lkb->lkb_lvbseq, 252 lkb->lkb_lvbseq,
264 (unsigned long long)ktime_to_ns(lkb->lkb_timestamp), 253 (unsigned long long)ktime_to_ns(lkb->lkb_timestamp),
265 (unsigned long long)ktime_to_ns(lkb->lkb_last_bast_time)); 254 (unsigned long long)ktime_to_ns(lkb->lkb_last_bast_time));
266 return rv;
267} 255}
268 256
269static int print_format3(struct dlm_rsb *r, struct seq_file *s) 257static void print_format3(struct dlm_rsb *r, struct seq_file *s)
270{ 258{
271 struct dlm_lkb *lkb; 259 struct dlm_lkb *lkb;
272 int i, lvblen = r->res_ls->ls_lvblen; 260 int i, lvblen = r->res_ls->ls_lvblen;
273 int print_name = 1; 261 int print_name = 1;
274 int rv;
275 262
276 lock_rsb(r); 263 lock_rsb(r);
277 264
278 rv = seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ", 265 seq_printf(s, "rsb %p %d %x %lx %d %d %u %d ",
279 r, 266 r,
280 r->res_nodeid, 267 r->res_nodeid,
281 r->res_first_lkid, 268 r->res_first_lkid,
282 r->res_flags, 269 r->res_flags,
283 !list_empty(&r->res_root_list), 270 !list_empty(&r->res_root_list),
284 !list_empty(&r->res_recover_list), 271 !list_empty(&r->res_recover_list),
285 r->res_recover_locks_count, 272 r->res_recover_locks_count,
286 r->res_length); 273 r->res_length);
287 if (rv) 274 if (seq_has_overflowed(s))
288 goto out; 275 goto out;
289 276
290 for (i = 0; i < r->res_length; i++) { 277 for (i = 0; i < r->res_length; i++) {
@@ -292,7 +279,7 @@ static int print_format3(struct dlm_rsb *r, struct seq_file *s)
292 print_name = 0; 279 print_name = 0;
293 } 280 }
294 281
295 seq_printf(s, "%s", print_name ? "str " : "hex"); 282 seq_puts(s, print_name ? "str " : "hex");
296 283
297 for (i = 0; i < r->res_length; i++) { 284 for (i = 0; i < r->res_length; i++) {
298 if (print_name) 285 if (print_name)
@@ -300,8 +287,8 @@ static int print_format3(struct dlm_rsb *r, struct seq_file *s)
300 else 287 else
301 seq_printf(s, " %02x", (unsigned char)r->res_name[i]); 288 seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
302 } 289 }
303 rv = seq_puts(s, "\n"); 290 seq_puts(s, "\n");
304 if (rv) 291 if (seq_has_overflowed(s))
305 goto out; 292 goto out;
306 293
307 if (!r->res_lvbptr) 294 if (!r->res_lvbptr)
@@ -311,65 +298,62 @@ static int print_format3(struct dlm_rsb *r, struct seq_file *s)
311 298
312 for (i = 0; i < lvblen; i++) 299 for (i = 0; i < lvblen; i++)
313 seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]); 300 seq_printf(s, " %02x", (unsigned char)r->res_lvbptr[i]);
314 rv = seq_puts(s, "\n"); 301 seq_puts(s, "\n");
315 if (rv) 302 if (seq_has_overflowed(s))
316 goto out; 303 goto out;
317 304
318 do_locks: 305 do_locks:
319 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) { 306 list_for_each_entry(lkb, &r->res_grantqueue, lkb_statequeue) {
320 rv = print_format3_lock(s, lkb, 0); 307 print_format3_lock(s, lkb, 0);
321 if (rv) 308 if (seq_has_overflowed(s))
322 goto out; 309 goto out;
323 } 310 }
324 311
325 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) { 312 list_for_each_entry(lkb, &r->res_convertqueue, lkb_statequeue) {
326 rv = print_format3_lock(s, lkb, 0); 313 print_format3_lock(s, lkb, 0);
327 if (rv) 314 if (seq_has_overflowed(s))
328 goto out; 315 goto out;
329 } 316 }
330 317
331 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) { 318 list_for_each_entry(lkb, &r->res_waitqueue, lkb_statequeue) {
332 rv = print_format3_lock(s, lkb, 0); 319 print_format3_lock(s, lkb, 0);
333 if (rv) 320 if (seq_has_overflowed(s))
334 goto out; 321 goto out;
335 } 322 }
336 323
337 list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) { 324 list_for_each_entry(lkb, &r->res_lookup, lkb_rsb_lookup) {
338 rv = print_format3_lock(s, lkb, 1); 325 print_format3_lock(s, lkb, 1);
339 if (rv) 326 if (seq_has_overflowed(s))
340 goto out; 327 goto out;
341 } 328 }
342 out: 329 out:
343 unlock_rsb(r); 330 unlock_rsb(r);
344 return rv;
345} 331}
346 332
347static int print_format4(struct dlm_rsb *r, struct seq_file *s) 333static void print_format4(struct dlm_rsb *r, struct seq_file *s)
348{ 334{
349 int our_nodeid = dlm_our_nodeid(); 335 int our_nodeid = dlm_our_nodeid();
350 int print_name = 1; 336 int print_name = 1;
351 int i, rv; 337 int i;
352 338
353 lock_rsb(r); 339 lock_rsb(r);
354 340
355 rv = seq_printf(s, "rsb %p %d %d %d %d %lu %lx %d ", 341 seq_printf(s, "rsb %p %d %d %d %d %lu %lx %d ",
356 r, 342 r,
357 r->res_nodeid, 343 r->res_nodeid,
358 r->res_master_nodeid, 344 r->res_master_nodeid,
359 r->res_dir_nodeid, 345 r->res_dir_nodeid,
360 our_nodeid, 346 our_nodeid,
361 r->res_toss_time, 347 r->res_toss_time,
362 r->res_flags, 348 r->res_flags,
363 r->res_length); 349 r->res_length);
364 if (rv)
365 goto out;
366 350
367 for (i = 0; i < r->res_length; i++) { 351 for (i = 0; i < r->res_length; i++) {
368 if (!isascii(r->res_name[i]) || !isprint(r->res_name[i])) 352 if (!isascii(r->res_name[i]) || !isprint(r->res_name[i]))
369 print_name = 0; 353 print_name = 0;
370 } 354 }
371 355
372 seq_printf(s, "%s", print_name ? "str " : "hex"); 356 seq_puts(s, print_name ? "str " : "hex");
373 357
374 for (i = 0; i < r->res_length; i++) { 358 for (i = 0; i < r->res_length; i++) {
375 if (print_name) 359 if (print_name)
@@ -377,10 +361,9 @@ static int print_format4(struct dlm_rsb *r, struct seq_file *s)
377 else 361 else
378 seq_printf(s, " %02x", (unsigned char)r->res_name[i]); 362 seq_printf(s, " %02x", (unsigned char)r->res_name[i]);
379 } 363 }
380 rv = seq_puts(s, "\n"); 364 seq_puts(s, "\n");
381 out: 365
382 unlock_rsb(r); 366 unlock_rsb(r);
383 return rv;
384} 367}
385 368
386struct rsbtbl_iter { 369struct rsbtbl_iter {
@@ -390,47 +373,45 @@ struct rsbtbl_iter {
390 int header; 373 int header;
391}; 374};
392 375
393/* seq_printf returns -1 if the buffer is full, and 0 otherwise. 376/*
394 If the buffer is full, seq_printf can be called again, but it 377 * If the buffer is full, seq_printf can be called again, but it
395 does nothing and just returns -1. So, the these printing routines 378 * does nothing. So, the these printing routines periodically check
396 periodically check the return value to avoid wasting too much time 379 * seq_has_overflowed to avoid wasting too much time trying to print to
397 trying to print to a full buffer. */ 380 * a full buffer.
381 */
398 382
399static int table_seq_show(struct seq_file *seq, void *iter_ptr) 383static int table_seq_show(struct seq_file *seq, void *iter_ptr)
400{ 384{
401 struct rsbtbl_iter *ri = iter_ptr; 385 struct rsbtbl_iter *ri = iter_ptr;
402 int rv = 0;
403 386
404 switch (ri->format) { 387 switch (ri->format) {
405 case 1: 388 case 1:
406 rv = print_format1(ri->rsb, seq); 389 print_format1(ri->rsb, seq);
407 break; 390 break;
408 case 2: 391 case 2:
409 if (ri->header) { 392 if (ri->header) {
410 seq_printf(seq, "id nodeid remid pid xid exflags " 393 seq_puts(seq, "id nodeid remid pid xid exflags flags sts grmode rqmode time_ms r_nodeid r_len r_name\n");
411 "flags sts grmode rqmode time_ms "
412 "r_nodeid r_len r_name\n");
413 ri->header = 0; 394 ri->header = 0;
414 } 395 }
415 rv = print_format2(ri->rsb, seq); 396 print_format2(ri->rsb, seq);
416 break; 397 break;
417 case 3: 398 case 3:
418 if (ri->header) { 399 if (ri->header) {
419 seq_printf(seq, "version rsb 1.1 lvb 1.1 lkb 1.1\n"); 400 seq_puts(seq, "version rsb 1.1 lvb 1.1 lkb 1.1\n");
420 ri->header = 0; 401 ri->header = 0;
421 } 402 }
422 rv = print_format3(ri->rsb, seq); 403 print_format3(ri->rsb, seq);
423 break; 404 break;
424 case 4: 405 case 4:
425 if (ri->header) { 406 if (ri->header) {
426 seq_printf(seq, "version 4 rsb 2\n"); 407 seq_puts(seq, "version 4 rsb 2\n");
427 ri->header = 0; 408 ri->header = 0;
428 } 409 }
429 rv = print_format4(ri->rsb, seq); 410 print_format4(ri->rsb, seq);
430 break; 411 break;
431 } 412 }
432 413
433 return rv; 414 return 0;
434} 415}
435 416
436static const struct seq_operations format1_seq_ops; 417static const struct seq_operations format1_seq_ops;
diff --git a/fs/eventfd.c b/fs/eventfd.c
index d6a88e7812f3..4b0a226024fa 100644
--- a/fs/eventfd.c
+++ b/fs/eventfd.c
@@ -287,17 +287,14 @@ static ssize_t eventfd_write(struct file *file, const char __user *buf, size_t c
287} 287}
288 288
289#ifdef CONFIG_PROC_FS 289#ifdef CONFIG_PROC_FS
290static int eventfd_show_fdinfo(struct seq_file *m, struct file *f) 290static void eventfd_show_fdinfo(struct seq_file *m, struct file *f)
291{ 291{
292 struct eventfd_ctx *ctx = f->private_data; 292 struct eventfd_ctx *ctx = f->private_data;
293 int ret;
294 293
295 spin_lock_irq(&ctx->wqh.lock); 294 spin_lock_irq(&ctx->wqh.lock);
296 ret = seq_printf(m, "eventfd-count: %16llx\n", 295 seq_printf(m, "eventfd-count: %16llx\n",
297 (unsigned long long)ctx->count); 296 (unsigned long long)ctx->count);
298 spin_unlock_irq(&ctx->wqh.lock); 297 spin_unlock_irq(&ctx->wqh.lock);
299
300 return ret;
301} 298}
302#endif 299#endif
303 300
diff --git a/fs/eventpoll.c b/fs/eventpoll.c
index 7bcfff900f05..d77f94491352 100644
--- a/fs/eventpoll.c
+++ b/fs/eventpoll.c
@@ -870,25 +870,22 @@ static unsigned int ep_eventpoll_poll(struct file *file, poll_table *wait)
870} 870}
871 871
872#ifdef CONFIG_PROC_FS 872#ifdef CONFIG_PROC_FS
873static int ep_show_fdinfo(struct seq_file *m, struct file *f) 873static void ep_show_fdinfo(struct seq_file *m, struct file *f)
874{ 874{
875 struct eventpoll *ep = f->private_data; 875 struct eventpoll *ep = f->private_data;
876 struct rb_node *rbp; 876 struct rb_node *rbp;
877 int ret = 0;
878 877
879 mutex_lock(&ep->mtx); 878 mutex_lock(&ep->mtx);
880 for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) { 879 for (rbp = rb_first(&ep->rbr); rbp; rbp = rb_next(rbp)) {
881 struct epitem *epi = rb_entry(rbp, struct epitem, rbn); 880 struct epitem *epi = rb_entry(rbp, struct epitem, rbn);
882 881
883 ret = seq_printf(m, "tfd: %8d events: %8x data: %16llx\n", 882 seq_printf(m, "tfd: %8d events: %8x data: %16llx\n",
884 epi->ffd.fd, epi->event.events, 883 epi->ffd.fd, epi->event.events,
885 (long long)epi->event.data); 884 (long long)epi->event.data);
886 if (ret) 885 if (seq_has_overflowed(m))
887 break; 886 break;
888 } 887 }
889 mutex_unlock(&ep->mtx); 888 mutex_unlock(&ep->mtx);
890
891 return ret;
892} 889}
893#endif 890#endif
894 891
diff --git a/fs/notify/fdinfo.c b/fs/notify/fdinfo.c
index 9d7e2b9659cb..6ffd220eb14d 100644
--- a/fs/notify/fdinfo.c
+++ b/fs/notify/fdinfo.c
@@ -20,25 +20,24 @@
20 20
21#if defined(CONFIG_INOTIFY_USER) || defined(CONFIG_FANOTIFY) 21#if defined(CONFIG_INOTIFY_USER) || defined(CONFIG_FANOTIFY)
22 22
23static int show_fdinfo(struct seq_file *m, struct file *f, 23static void show_fdinfo(struct seq_file *m, struct file *f,
24 int (*show)(struct seq_file *m, struct fsnotify_mark *mark)) 24 void (*show)(struct seq_file *m,
25 struct fsnotify_mark *mark))
25{ 26{
26 struct fsnotify_group *group = f->private_data; 27 struct fsnotify_group *group = f->private_data;
27 struct fsnotify_mark *mark; 28 struct fsnotify_mark *mark;
28 int ret = 0;
29 29
30 mutex_lock(&group->mark_mutex); 30 mutex_lock(&group->mark_mutex);
31 list_for_each_entry(mark, &group->marks_list, g_list) { 31 list_for_each_entry(mark, &group->marks_list, g_list) {
32 ret = show(m, mark); 32 show(m, mark);
33 if (ret) 33 if (seq_has_overflowed(m))
34 break; 34 break;
35 } 35 }
36 mutex_unlock(&group->mark_mutex); 36 mutex_unlock(&group->mark_mutex);
37 return ret;
38} 37}
39 38
40#if defined(CONFIG_EXPORTFS) 39#if defined(CONFIG_EXPORTFS)
41static int show_mark_fhandle(struct seq_file *m, struct inode *inode) 40static void show_mark_fhandle(struct seq_file *m, struct inode *inode)
42{ 41{
43 struct { 42 struct {
44 struct file_handle handle; 43 struct file_handle handle;
@@ -52,71 +51,62 @@ static int show_mark_fhandle(struct seq_file *m, struct inode *inode)
52 ret = exportfs_encode_inode_fh(inode, (struct fid *)f.handle.f_handle, &size, 0); 51 ret = exportfs_encode_inode_fh(inode, (struct fid *)f.handle.f_handle, &size, 0);
53 if ((ret == FILEID_INVALID) || (ret < 0)) { 52 if ((ret == FILEID_INVALID) || (ret < 0)) {
54 WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret); 53 WARN_ONCE(1, "Can't encode file handler for inotify: %d\n", ret);
55 return 0; 54 return;
56 } 55 }
57 56
58 f.handle.handle_type = ret; 57 f.handle.handle_type = ret;
59 f.handle.handle_bytes = size * sizeof(u32); 58 f.handle.handle_bytes = size * sizeof(u32);
60 59
61 ret = seq_printf(m, "fhandle-bytes:%x fhandle-type:%x f_handle:", 60 seq_printf(m, "fhandle-bytes:%x fhandle-type:%x f_handle:",
62 f.handle.handle_bytes, f.handle.handle_type); 61 f.handle.handle_bytes, f.handle.handle_type);
63 62
64 for (i = 0; i < f.handle.handle_bytes; i++) 63 for (i = 0; i < f.handle.handle_bytes; i++)
65 ret |= seq_printf(m, "%02x", (int)f.handle.f_handle[i]); 64 seq_printf(m, "%02x", (int)f.handle.f_handle[i]);
66
67 return ret;
68} 65}
69#else 66#else
70static int show_mark_fhandle(struct seq_file *m, struct inode *inode) 67static void show_mark_fhandle(struct seq_file *m, struct inode *inode)
71{ 68{
72 return 0;
73} 69}
74#endif 70#endif
75 71
76#ifdef CONFIG_INOTIFY_USER 72#ifdef CONFIG_INOTIFY_USER
77 73
78static int inotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) 74static void inotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
79{ 75{
80 struct inotify_inode_mark *inode_mark; 76 struct inotify_inode_mark *inode_mark;
81 struct inode *inode; 77 struct inode *inode;
82 int ret = 0;
83 78
84 if (!(mark->flags & (FSNOTIFY_MARK_FLAG_ALIVE | FSNOTIFY_MARK_FLAG_INODE))) 79 if (!(mark->flags & (FSNOTIFY_MARK_FLAG_ALIVE | FSNOTIFY_MARK_FLAG_INODE)))
85 return 0; 80 return;
86 81
87 inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark); 82 inode_mark = container_of(mark, struct inotify_inode_mark, fsn_mark);
88 inode = igrab(mark->i.inode); 83 inode = igrab(mark->i.inode);
89 if (inode) { 84 if (inode) {
90 ret = seq_printf(m, "inotify wd:%x ino:%lx sdev:%x " 85 seq_printf(m, "inotify wd:%x ino:%lx sdev:%x mask:%x ignored_mask:%x ",
91 "mask:%x ignored_mask:%x ", 86 inode_mark->wd, inode->i_ino, inode->i_sb->s_dev,
92 inode_mark->wd, inode->i_ino, 87 mark->mask, mark->ignored_mask);
93 inode->i_sb->s_dev, 88 show_mark_fhandle(m, inode);
94 mark->mask, mark->ignored_mask); 89 seq_putc(m, '\n');
95 ret |= show_mark_fhandle(m, inode);
96 ret |= seq_putc(m, '\n');
97 iput(inode); 90 iput(inode);
98 } 91 }
99
100 return ret;
101} 92}
102 93
103int inotify_show_fdinfo(struct seq_file *m, struct file *f) 94void inotify_show_fdinfo(struct seq_file *m, struct file *f)
104{ 95{
105 return show_fdinfo(m, f, inotify_fdinfo); 96 show_fdinfo(m, f, inotify_fdinfo);
106} 97}
107 98
108#endif /* CONFIG_INOTIFY_USER */ 99#endif /* CONFIG_INOTIFY_USER */
109 100
110#ifdef CONFIG_FANOTIFY 101#ifdef CONFIG_FANOTIFY
111 102
112static int fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark) 103static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
113{ 104{
114 unsigned int mflags = 0; 105 unsigned int mflags = 0;
115 struct inode *inode; 106 struct inode *inode;
116 int ret = 0;
117 107
118 if (!(mark->flags & FSNOTIFY_MARK_FLAG_ALIVE)) 108 if (!(mark->flags & FSNOTIFY_MARK_FLAG_ALIVE))
119 return 0; 109 return;
120 110
121 if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY) 111 if (mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY)
122 mflags |= FAN_MARK_IGNORED_SURV_MODIFY; 112 mflags |= FAN_MARK_IGNORED_SURV_MODIFY;
@@ -124,26 +114,22 @@ static int fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
124 if (mark->flags & FSNOTIFY_MARK_FLAG_INODE) { 114 if (mark->flags & FSNOTIFY_MARK_FLAG_INODE) {
125 inode = igrab(mark->i.inode); 115 inode = igrab(mark->i.inode);
126 if (!inode) 116 if (!inode)
127 goto out; 117 return;
128 ret = seq_printf(m, "fanotify ino:%lx sdev:%x " 118 seq_printf(m, "fanotify ino:%lx sdev:%x mflags:%x mask:%x ignored_mask:%x ",
129 "mflags:%x mask:%x ignored_mask:%x ", 119 inode->i_ino, inode->i_sb->s_dev,
130 inode->i_ino, inode->i_sb->s_dev, 120 mflags, mark->mask, mark->ignored_mask);
131 mflags, mark->mask, mark->ignored_mask); 121 show_mark_fhandle(m, inode);
132 ret |= show_mark_fhandle(m, inode); 122 seq_putc(m, '\n');
133 ret |= seq_putc(m, '\n');
134 iput(inode); 123 iput(inode);
135 } else if (mark->flags & FSNOTIFY_MARK_FLAG_VFSMOUNT) { 124 } else if (mark->flags & FSNOTIFY_MARK_FLAG_VFSMOUNT) {
136 struct mount *mnt = real_mount(mark->m.mnt); 125 struct mount *mnt = real_mount(mark->m.mnt);
137 126
138 ret = seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x " 127 seq_printf(m, "fanotify mnt_id:%x mflags:%x mask:%x ignored_mask:%x\n",
139 "ignored_mask:%x\n", mnt->mnt_id, mflags, 128 mnt->mnt_id, mflags, mark->mask, mark->ignored_mask);
140 mark->mask, mark->ignored_mask);
141 } 129 }
142out:
143 return ret;
144} 130}
145 131
146int fanotify_show_fdinfo(struct seq_file *m, struct file *f) 132void fanotify_show_fdinfo(struct seq_file *m, struct file *f)
147{ 133{
148 struct fsnotify_group *group = f->private_data; 134 struct fsnotify_group *group = f->private_data;
149 unsigned int flags = 0; 135 unsigned int flags = 0;
@@ -169,7 +155,7 @@ int fanotify_show_fdinfo(struct seq_file *m, struct file *f)
169 seq_printf(m, "fanotify flags:%x event-flags:%x\n", 155 seq_printf(m, "fanotify flags:%x event-flags:%x\n",
170 flags, group->fanotify_data.f_flags); 156 flags, group->fanotify_data.f_flags);
171 157
172 return show_fdinfo(m, f, fanotify_fdinfo); 158 show_fdinfo(m, f, fanotify_fdinfo);
173} 159}
174 160
175#endif /* CONFIG_FANOTIFY */ 161#endif /* CONFIG_FANOTIFY */
diff --git a/fs/notify/fdinfo.h b/fs/notify/fdinfo.h
index 556afda990e9..9664c4904d6b 100644
--- a/fs/notify/fdinfo.h
+++ b/fs/notify/fdinfo.h
@@ -10,11 +10,11 @@ struct file;
10#ifdef CONFIG_PROC_FS 10#ifdef CONFIG_PROC_FS
11 11
12#ifdef CONFIG_INOTIFY_USER 12#ifdef CONFIG_INOTIFY_USER
13extern int inotify_show_fdinfo(struct seq_file *m, struct file *f); 13void inotify_show_fdinfo(struct seq_file *m, struct file *f);
14#endif 14#endif
15 15
16#ifdef CONFIG_FANOTIFY 16#ifdef CONFIG_FANOTIFY
17extern int fanotify_show_fdinfo(struct seq_file *m, struct file *f); 17void fanotify_show_fdinfo(struct seq_file *m, struct file *f);
18#endif 18#endif
19 19
20#else /* CONFIG_PROC_FS */ 20#else /* CONFIG_PROC_FS */
diff --git a/fs/proc/fd.c b/fs/proc/fd.c
index e11d7c590bb0..8e5ad83b629a 100644
--- a/fs/proc/fd.c
+++ b/fs/proc/fd.c
@@ -53,7 +53,8 @@ static int seq_show(struct seq_file *m, void *v)
53 (long long)file->f_pos, f_flags, 53 (long long)file->f_pos, f_flags,
54 real_mount(file->f_path.mnt)->mnt_id); 54 real_mount(file->f_path.mnt)->mnt_id);
55 if (file->f_op->show_fdinfo) 55 if (file->f_op->show_fdinfo)
56 ret = file->f_op->show_fdinfo(m, file); 56 file->f_op->show_fdinfo(m, file);
57 ret = seq_has_overflowed(m);
57 fput(file); 58 fput(file);
58 } 59 }
59 60
diff --git a/fs/seq_file.c b/fs/seq_file.c
index 3857b720cb1b..353948ba1c5b 100644
--- a/fs/seq_file.c
+++ b/fs/seq_file.c
@@ -16,17 +16,6 @@
16#include <asm/uaccess.h> 16#include <asm/uaccess.h>
17#include <asm/page.h> 17#include <asm/page.h>
18 18
19
20/*
21 * seq_files have a buffer which can may overflow. When this happens a larger
22 * buffer is reallocated and all the data will be printed again.
23 * The overflow state is true when m->count == m->size.
24 */
25static bool seq_overflow(struct seq_file *m)
26{
27 return m->count == m->size;
28}
29
30static void seq_set_overflow(struct seq_file *m) 19static void seq_set_overflow(struct seq_file *m)
31{ 20{
32 m->count = m->size; 21 m->count = m->size;
@@ -124,7 +113,7 @@ static int traverse(struct seq_file *m, loff_t offset)
124 error = 0; 113 error = 0;
125 m->count = 0; 114 m->count = 0;
126 } 115 }
127 if (seq_overflow(m)) 116 if (seq_has_overflowed(m))
128 goto Eoverflow; 117 goto Eoverflow;
129 if (pos + m->count > offset) { 118 if (pos + m->count > offset) {
130 m->from = offset - pos; 119 m->from = offset - pos;
@@ -267,7 +256,7 @@ Fill:
267 break; 256 break;
268 } 257 }
269 err = m->op->show(m, p); 258 err = m->op->show(m, p);
270 if (seq_overflow(m) || err) { 259 if (seq_has_overflowed(m) || err) {
271 m->count = offs; 260 m->count = offs;
272 if (likely(err <= 0)) 261 if (likely(err <= 0))
273 break; 262 break;
diff --git a/fs/signalfd.c b/fs/signalfd.c
index 424b7b65321f..7e412ad74836 100644
--- a/fs/signalfd.c
+++ b/fs/signalfd.c
@@ -230,7 +230,7 @@ static ssize_t signalfd_read(struct file *file, char __user *buf, size_t count,
230} 230}
231 231
232#ifdef CONFIG_PROC_FS 232#ifdef CONFIG_PROC_FS
233static int signalfd_show_fdinfo(struct seq_file *m, struct file *f) 233static void signalfd_show_fdinfo(struct seq_file *m, struct file *f)
234{ 234{
235 struct signalfd_ctx *ctx = f->private_data; 235 struct signalfd_ctx *ctx = f->private_data;
236 sigset_t sigmask; 236 sigset_t sigmask;
@@ -238,8 +238,6 @@ static int signalfd_show_fdinfo(struct seq_file *m, struct file *f)
238 sigmask = ctx->sigmask; 238 sigmask = ctx->sigmask;
239 signotset(&sigmask); 239 signotset(&sigmask);
240 render_sigset_t(m, "sigmask:\t", &sigmask); 240 render_sigset_t(m, "sigmask:\t", &sigmask);
241
242 return 0;
243} 241}
244#endif 242#endif
245 243
diff --git a/fs/timerfd.c b/fs/timerfd.c
index b46ffa94372a..b94fa6c3c6eb 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -288,7 +288,7 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
288} 288}
289 289
290#ifdef CONFIG_PROC_FS 290#ifdef CONFIG_PROC_FS
291static int timerfd_show(struct seq_file *m, struct file *file) 291static void timerfd_show(struct seq_file *m, struct file *file)
292{ 292{
293 struct timerfd_ctx *ctx = file->private_data; 293 struct timerfd_ctx *ctx = file->private_data;
294 struct itimerspec t; 294 struct itimerspec t;
@@ -298,18 +298,19 @@ static int timerfd_show(struct seq_file *m, struct file *file)
298 t.it_interval = ktime_to_timespec(ctx->tintv); 298 t.it_interval = ktime_to_timespec(ctx->tintv);
299 spin_unlock_irq(&ctx->wqh.lock); 299 spin_unlock_irq(&ctx->wqh.lock);
300 300
301 return seq_printf(m, 301 seq_printf(m,
302 "clockid: %d\n" 302 "clockid: %d\n"
303 "ticks: %llu\n" 303 "ticks: %llu\n"
304 "settime flags: 0%o\n" 304 "settime flags: 0%o\n"
305 "it_value: (%llu, %llu)\n" 305 "it_value: (%llu, %llu)\n"
306 "it_interval: (%llu, %llu)\n", 306 "it_interval: (%llu, %llu)\n",
307 ctx->clockid, (unsigned long long)ctx->ticks, 307 ctx->clockid,
308 ctx->settime_flags, 308 (unsigned long long)ctx->ticks,
309 (unsigned long long)t.it_value.tv_sec, 309 ctx->settime_flags,
310 (unsigned long long)t.it_value.tv_nsec, 310 (unsigned long long)t.it_value.tv_sec,
311 (unsigned long long)t.it_interval.tv_sec, 311 (unsigned long long)t.it_value.tv_nsec,
312 (unsigned long long)t.it_interval.tv_nsec); 312 (unsigned long long)t.it_interval.tv_sec,
313 (unsigned long long)t.it_interval.tv_nsec);
313} 314}
314#else 315#else
315#define timerfd_show NULL 316#define timerfd_show NULL