Whamcloud - gitweb
b2333438fbb467d990e86c3734c385bc871b59a7
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  */
32 #define DEBUG_SUBSYSTEM S_CLASS
33
34 #include <linux/version.h>
35 #include <asm/statfs.h>
36 #include <obd_cksum.h>
37 #include <obd_class.h>
38 #include <lprocfs_status.h>
39 #include <linux/seq_file.h>
40 #include <lustre_osc.h>
41
42 #include "osc_internal.h"
43
44 #ifdef CONFIG_PROC_FS
45 static int osc_active_seq_show(struct seq_file *m, void *v)
46 {
47         struct obd_device *dev = m->private;
48
49         LPROCFS_CLIMP_CHECK(dev);
50         seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
51         LPROCFS_CLIMP_EXIT(dev);
52         return 0;
53 }
54
55 static ssize_t osc_active_seq_write(struct file *file,
56                                     const char __user *buffer,
57                                     size_t count, loff_t *off)
58 {
59         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
60         bool val;
61         int rc;
62
63         rc = kstrtobool_from_user(buffer, count, &val);
64         if (rc)
65                 return rc;
66
67         /* opposite senses */
68         if (dev->u.cli.cl_import->imp_deactive == val)
69                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
70         else
71                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n",
72                         (int)val);
73
74         return count;
75 }
76 LPROC_SEQ_FOPS(osc_active);
77
78 static int osc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
79 {
80         struct obd_device *dev = m->private;
81         struct client_obd *cli = &dev->u.cli;
82
83         spin_lock(&cli->cl_loi_list_lock);
84         seq_printf(m, "%u\n", cli->cl_max_rpcs_in_flight);
85         spin_unlock(&cli->cl_loi_list_lock);
86         return 0;
87 }
88
89 static ssize_t osc_max_rpcs_in_flight_seq_write(struct file *file,
90                                                 const char __user *buffer,
91                                                 size_t count, loff_t *off)
92 {
93         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
94         struct client_obd *cli = &dev->u.cli;
95         int adding, added, req_count;
96         unsigned int val;
97         int rc;
98
99         rc = kstrtouint_from_user(buffer, count, 0, &val);
100         if (rc)
101                 return rc;
102
103         if (val == 0 || val > OSC_MAX_RIF_MAX)
104                 return -ERANGE;
105
106         LPROCFS_CLIMP_CHECK(dev);
107
108         adding = (int)val - cli->cl_max_rpcs_in_flight;
109         req_count = atomic_read(&osc_pool_req_count);
110         if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
111                 /*
112                  * There might be some race which will cause over-limit
113                  * allocation, but it is fine.
114                  */
115                 if (req_count + adding > osc_reqpool_maxreqcount)
116                         adding = osc_reqpool_maxreqcount - req_count;
117
118                 added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
119                 atomic_add(added, &osc_pool_req_count);
120         }
121
122         spin_lock(&cli->cl_loi_list_lock);
123         cli->cl_max_rpcs_in_flight = val;
124         client_adjust_max_dirty(cli);
125         spin_unlock(&cli->cl_loi_list_lock);
126
127         LPROCFS_CLIMP_EXIT(dev);
128         return count;
129 }
130 LPROC_SEQ_FOPS(osc_max_rpcs_in_flight);
131
132 static int osc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
133 {
134         struct obd_device *dev = m->private;
135         struct client_obd *cli = &dev->u.cli;
136         long val;
137         int mult;
138
139         spin_lock(&cli->cl_loi_list_lock);
140         val = cli->cl_dirty_max_pages;
141         spin_unlock(&cli->cl_loi_list_lock);
142
143         mult = 1 << (20 - PAGE_SHIFT);
144         return lprocfs_seq_read_frac_helper(m, val, mult);
145 }
146
147 static ssize_t osc_max_dirty_mb_seq_write(struct file *file,
148                                           const char __user *buffer,
149                                           size_t count, loff_t *off)
150 {
151         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
152         struct client_obd *cli = &dev->u.cli;
153         int rc;
154         __s64 pages_number;
155
156         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
157         if (rc)
158                 return rc;
159
160         pages_number >>= PAGE_SHIFT;
161
162         if (pages_number <= 0 ||
163             pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
164             pages_number > totalram_pages / 4) /* 1/4 of RAM */
165                 return -ERANGE;
166
167         spin_lock(&cli->cl_loi_list_lock);
168         cli->cl_dirty_max_pages = pages_number;
169         osc_wake_cache_waiters(cli);
170         spin_unlock(&cli->cl_loi_list_lock);
171
172         return count;
173 }
174 LPROC_SEQ_FOPS(osc_max_dirty_mb);
175
176 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
177 {
178         struct obd_device *dev = m->private;
179         struct client_obd *cli = &dev->u.cli;
180         int shift = 20 - PAGE_SHIFT;
181
182         seq_printf(m, "used_mb: %ld\n"
183                    "busy_cnt: %ld\n"
184                    "reclaim: %llu\n",
185                    (atomic_long_read(&cli->cl_lru_in_list) +
186                     atomic_long_read(&cli->cl_lru_busy)) >> shift,
187                     atomic_long_read(&cli->cl_lru_busy),
188                    cli->cl_lru_reclaim);
189
190         return 0;
191 }
192
193 /* shrink the number of caching pages to a specific number */
194 static ssize_t
195 osc_cached_mb_seq_write(struct file *file, const char __user *buffer,
196                         size_t count, loff_t *off)
197 {
198         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
199         struct client_obd *cli = &dev->u.cli;
200         __s64 pages_number;
201         long rc;
202         char kernbuf[128];
203
204         if (count >= sizeof(kernbuf))
205                 return -EINVAL;
206
207         if (copy_from_user(kernbuf, buffer, count))
208                 return -EFAULT;
209         kernbuf[count] = 0;
210
211         buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
212                   kernbuf;
213         rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
214         if (rc)
215                 return rc;
216
217         pages_number >>= PAGE_SHIFT;
218
219         if (pages_number < 0)
220                 return -ERANGE;
221
222         rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
223         if (rc > 0) {
224                 struct lu_env *env;
225                 __u16 refcheck;
226
227                 env = cl_env_get(&refcheck);
228                 if (!IS_ERR(env)) {
229                         (void)osc_lru_shrink(env, cli, rc, true);
230                         cl_env_put(env, &refcheck);
231                 }
232         }
233
234         return count;
235 }
236 LPROC_SEQ_FOPS(osc_cached_mb);
237
238 static int osc_cur_dirty_bytes_seq_show(struct seq_file *m, void *v)
239 {
240         struct obd_device *dev = m->private;
241         struct client_obd *cli = &dev->u.cli;
242
243         spin_lock(&cli->cl_loi_list_lock);
244         seq_printf(m, "%lu\n", cli->cl_dirty_pages << PAGE_SHIFT);
245         spin_unlock(&cli->cl_loi_list_lock);
246         return 0;
247 }
248 LPROC_SEQ_FOPS_RO(osc_cur_dirty_bytes);
249
250 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
251 {
252         struct obd_device *dev = m->private;
253         struct client_obd *cli = &dev->u.cli;
254
255         spin_lock(&cli->cl_loi_list_lock);
256         seq_printf(m, "%lu\n", cli->cl_avail_grant);
257         spin_unlock(&cli->cl_loi_list_lock);
258         return 0;
259 }
260
261 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
262                                              const char __user *buffer,
263                                              size_t count, loff_t *off)
264 {
265         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
266         struct client_obd *cli = &obd->u.cli;
267         s64 val;
268         int rc;
269
270         if (obd == NULL)
271                 return 0;
272
273         rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
274         if (rc)
275                 return rc;
276         if (val < 0)
277                 return -ERANGE;
278
279         /* this is only for shrinking grant */
280         spin_lock(&cli->cl_loi_list_lock);
281         if (val >= cli->cl_avail_grant) {
282                 spin_unlock(&cli->cl_loi_list_lock);
283                 return 0;
284         }
285
286         spin_unlock(&cli->cl_loi_list_lock);
287
288         LPROCFS_CLIMP_CHECK(obd);
289         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
290                 rc = osc_shrink_grant_to_target(cli, val);
291         LPROCFS_CLIMP_EXIT(obd);
292         if (rc)
293                 return rc;
294         return count;
295 }
296 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
297
298 static int osc_cur_lost_grant_bytes_seq_show(struct seq_file *m, void *v)
299 {
300         struct obd_device *dev = m->private;
301         struct client_obd *cli = &dev->u.cli;
302
303         spin_lock(&cli->cl_loi_list_lock);
304         seq_printf(m, "%lu\n", cli->cl_lost_grant);
305         spin_unlock(&cli->cl_loi_list_lock);
306         return 0;
307 }
308 LPROC_SEQ_FOPS_RO(osc_cur_lost_grant_bytes);
309
310 static int osc_cur_dirty_grant_bytes_seq_show(struct seq_file *m, void *v)
311 {
312         struct obd_device *dev = m->private;
313         struct client_obd *cli = &dev->u.cli;
314
315         spin_lock(&cli->cl_loi_list_lock);
316         seq_printf(m, "%lu\n", cli->cl_dirty_grant);
317         spin_unlock(&cli->cl_loi_list_lock);
318         return 0;
319 }
320 LPROC_SEQ_FOPS_RO(osc_cur_dirty_grant_bytes);
321
322 static int osc_grant_shrink_interval_seq_show(struct seq_file *m, void *v)
323 {
324         struct obd_device *obd = m->private;
325
326         if (obd == NULL)
327                 return 0;
328         seq_printf(m, "%lld\n",
329                    obd->u.cli.cl_grant_shrink_interval);
330         return 0;
331 }
332
333 static ssize_t osc_grant_shrink_interval_seq_write(struct file *file,
334                                                    const char __user *buffer,
335                                                    size_t count, loff_t *off)
336 {
337         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
338         unsigned int val;
339         int rc;
340
341         if (obd == NULL)
342                 return 0;
343
344         rc = kstrtouint_from_user(buffer, count, 0, &val);
345         if (rc)
346                 return rc;
347
348         if (val == 0)
349                 return -ERANGE;
350
351         obd->u.cli.cl_grant_shrink_interval = val;
352
353         return count;
354 }
355 LPROC_SEQ_FOPS(osc_grant_shrink_interval);
356
357 static int osc_checksum_seq_show(struct seq_file *m, void *v)
358 {
359         struct obd_device *obd = m->private;
360
361         if (obd == NULL)
362                 return 0;
363
364         seq_printf(m, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
365         return 0;
366 }
367
368 static ssize_t osc_checksum_seq_write(struct file *file,
369                                       const char __user *buffer,
370                                       size_t count, loff_t *off)
371 {
372         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
373         bool val;
374         int rc;
375
376         if (obd == NULL)
377                 return 0;
378
379         rc = kstrtobool_from_user(buffer, count, &val);
380         if (rc)
381                 return rc;
382
383         obd->u.cli.cl_checksum = val;
384
385         return count;
386 }
387 LPROC_SEQ_FOPS(osc_checksum);
388
389 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
390 {
391         struct obd_device *obd = m->private;
392         int i;
393         DECLARE_CKSUM_NAME;
394
395         if (obd == NULL)
396                 return 0;
397
398         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
399                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
400                         continue;
401                 if (obd->u.cli.cl_cksum_type == (1 << i))
402                         seq_printf(m, "[%s] ", cksum_name[i]);
403                 else
404                         seq_printf(m, "%s ", cksum_name[i]);
405         }
406         seq_printf(m, "\n");
407         return 0;
408 }
409
410 static ssize_t osc_checksum_type_seq_write(struct file *file,
411                                            const char __user *buffer,
412                                            size_t count, loff_t *off)
413 {
414         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
415         int i;
416         DECLARE_CKSUM_NAME;
417         char kernbuf[10];
418
419         if (obd == NULL)
420                 return 0;
421
422         if (count > sizeof(kernbuf) - 1)
423                 return -EINVAL;
424         if (copy_from_user(kernbuf, buffer, count))
425                 return -EFAULT;
426         if (count > 0 && kernbuf[count - 1] == '\n')
427                 kernbuf[count - 1] = '\0';
428         else
429                 kernbuf[count] = '\0';
430
431         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
432                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
433                         continue;
434                 if (!strcmp(kernbuf, cksum_name[i])) {
435                        obd->u.cli.cl_cksum_type = 1 << i;
436                        return count;
437                 }
438         }
439         return -EINVAL;
440 }
441 LPROC_SEQ_FOPS(osc_checksum_type);
442
443 static int osc_resend_count_seq_show(struct seq_file *m, void *v)
444 {
445         struct obd_device *obd = m->private;
446
447         seq_printf(m, "%u\n", atomic_read(&obd->u.cli.cl_resends));
448         return 0;
449 }
450
451 static ssize_t osc_resend_count_seq_write(struct file *file,
452                                           const char __user *buffer,
453                                           size_t count, loff_t *off)
454 {
455         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
456         unsigned int val;
457         int rc;
458
459         rc = kstrtouint_from_user(buffer, count, 0, &val);
460         if (rc)
461                 return rc;
462
463         atomic_set(&obd->u.cli.cl_resends, val);
464
465         return count;
466 }
467 LPROC_SEQ_FOPS(osc_resend_count);
468
469 static int osc_checksum_dump_seq_show(struct seq_file *m, void *v)
470 {
471         struct obd_device *obd = m->private;
472
473         if (obd == NULL)
474                 return 0;
475
476         seq_printf(m, "%d\n", obd->u.cli.cl_checksum_dump ? 1 : 0);
477         return 0;
478 }
479
480 static ssize_t osc_checksum_dump_seq_write(struct file *file,
481                                            const char __user *buffer,
482                                            size_t count, loff_t *off)
483 {
484         struct obd_device *obd;
485         bool val;
486         int rc;
487
488         obd = ((struct seq_file *)file->private_data)->private;
489         if (obd == NULL)
490                 return 0;
491
492         rc = kstrtobool_from_user(buffer, count, &val);
493         if (rc)
494                 return rc;
495
496         obd->u.cli.cl_checksum_dump = val;
497
498         return count;
499 }
500 LPROC_SEQ_FOPS(osc_checksum_dump);
501
502 static int osc_contention_seconds_seq_show(struct seq_file *m, void *v)
503 {
504         struct obd_device *obd = m->private;
505         struct osc_device *od  = obd2osc_dev(obd);
506
507         seq_printf(m, "%lld\n", od->od_contention_time);
508         return 0;
509 }
510
511 static ssize_t osc_contention_seconds_seq_write(struct file *file,
512                                                 const char __user *buffer,
513                                                 size_t count, loff_t *off)
514 {
515         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
516         struct osc_device *od  = obd2osc_dev(obd);
517         unsigned int val;
518         int rc;
519
520         rc = kstrtouint_from_user(buffer, count, 0, &val);
521         if (rc)
522                 return rc;
523         if (val < 0 || val > INT_MAX)
524                 return -ERANGE;
525
526         od->od_contention_time = val;
527
528         return count;
529 }
530 LPROC_SEQ_FOPS(osc_contention_seconds);
531
532 static int osc_lockless_truncate_seq_show(struct seq_file *m, void *v)
533 {
534         struct obd_device *obd = m->private;
535         struct osc_device *od  = obd2osc_dev(obd);
536
537         seq_printf(m, "%u\n", od->od_lockless_truncate);
538         return 0;
539 }
540
541 static ssize_t osc_lockless_truncate_seq_write(struct file *file,
542                                                const char __user *buffer,
543                                     size_t count, loff_t *off)
544 {
545         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
546         struct osc_device *od  = obd2osc_dev(obd);
547         bool val;
548         int rc;
549
550         rc = kstrtobool_from_user(buffer, count, &val);
551         if (rc)
552                 return rc;
553
554         od->od_lockless_truncate = val;
555
556         return count;
557 }
558 LPROC_SEQ_FOPS(osc_lockless_truncate);
559
560 static int osc_destroys_in_flight_seq_show(struct seq_file *m, void *v)
561 {
562         struct obd_device *obd = m->private;
563         seq_printf(m, "%u\n",
564                    atomic_read(&obd->u.cli.cl_destroy_in_flight));
565         return 0;
566 }
567 LPROC_SEQ_FOPS_RO(osc_destroys_in_flight);
568
569 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_max_pages_per_rpc);
570
571 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_short_io_bytes);
572
573 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
574 {
575         struct obd_device *dev = m->private;
576         struct client_obd *cli = &dev->u.cli;
577         long pages;
578         int mb;
579
580         pages = atomic_long_read(&cli->cl_unstable_count);
581         mb    = (pages * PAGE_SIZE) >> 20;
582
583         seq_printf(m, "unstable_pages: %20ld\n"
584                    "unstable_mb:              %10d\n",
585                    pages, mb);
586         return 0;
587 }
588 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
589
590 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
591 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
592 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
593 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
594 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
595
596 LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
597
598 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
599 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
600
601 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
602         { .name =       "ping",
603           .fops =       &osc_ping_fops,
604           .proc_mode =  0222                            },
605         { .name =       "connect_flags",
606           .fops =       &osc_connect_flags_fops         },
607         { .name =       "ost_server_uuid",
608           .fops =       &osc_server_uuid_fops           },
609         { .name =       "ost_conn_uuid",
610           .fops =       &osc_conn_uuid_fops             },
611         { .name =       "active",
612           .fops =       &osc_active_fops                },
613         { .name =       "max_pages_per_rpc",
614           .fops =       &osc_obd_max_pages_per_rpc_fops },
615         { .name =       "short_io_bytes",
616           .fops =       &osc_obd_short_io_bytes_fops    },
617         { .name =       "max_rpcs_in_flight",
618           .fops =       &osc_max_rpcs_in_flight_fops    },
619         { .name =       "destroys_in_flight",
620           .fops =       &osc_destroys_in_flight_fops    },
621         { .name =       "max_dirty_mb",
622           .fops =       &osc_max_dirty_mb_fops          },
623         { .name =       "osc_cached_mb",
624           .fops =       &osc_cached_mb_fops             },
625         { .name =       "cur_dirty_bytes",
626           .fops =       &osc_cur_dirty_bytes_fops       },
627         { .name =       "cur_grant_bytes",
628           .fops =       &osc_cur_grant_bytes_fops       },
629         { .name =       "cur_lost_grant_bytes",
630           .fops =       &osc_cur_lost_grant_bytes_fops  },
631         { .name =       "cur_dirty_grant_bytes",
632           .fops =       &osc_cur_dirty_grant_bytes_fops },
633         { .name =       "grant_shrink_interval",
634           .fops =       &osc_grant_shrink_interval_fops },
635         { .name =       "checksums",
636           .fops =       &osc_checksum_fops              },
637         { .name =       "checksum_type",
638           .fops =       &osc_checksum_type_fops         },
639         { .name =       "checksum_dump",
640           .fops =       &osc_checksum_dump_fops         },
641         { .name =       "resend_count",
642           .fops =       &osc_resend_count_fops          },
643         { .name =       "timeouts",
644           .fops =       &osc_timeouts_fops              },
645         { .name =       "contention_seconds",
646           .fops =       &osc_contention_seconds_fops    },
647         { .name =       "lockless_truncate",
648           .fops =       &osc_lockless_truncate_fops     },
649         { .name =       "import",
650           .fops =       &osc_import_fops                },
651         { .name =       "state",
652           .fops =       &osc_state_fops                 },
653         { .name =       "pinger_recov",
654           .fops =       &osc_pinger_recov_fops          },
655         { .name =       "unstable_stats",
656           .fops =       &osc_unstable_stats_fops        },
657         { NULL }
658 };
659
660 #define pct(a,b) (b ? a * 100 / b : 0)
661
662 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
663 {
664         struct timespec64 now;
665         struct obd_device *dev = seq->private;
666         struct client_obd *cli = &dev->u.cli;
667         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
668         int i;
669
670         ktime_get_real_ts64(&now);
671
672         spin_lock(&cli->cl_loi_list_lock);
673
674         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
675                    (s64)now.tv_sec, now.tv_nsec);
676         seq_printf(seq, "read RPCs in flight:  %d\n",
677                    cli->cl_r_in_flight);
678         seq_printf(seq, "write RPCs in flight: %d\n",
679                    cli->cl_w_in_flight);
680         seq_printf(seq, "pending write pages:  %d\n",
681                    atomic_read(&cli->cl_pending_w_pages));
682         seq_printf(seq, "pending read pages:   %d\n",
683                    atomic_read(&cli->cl_pending_r_pages));
684
685         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
686         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
687         seq_printf(seq, "       rpcs   %% cum %%\n");
688
689         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
690         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
691
692         read_cum = 0;
693         write_cum = 0;
694         for (i = 0; i < OBD_HIST_MAX; i++) {
695                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
696                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
697
698                 read_cum += r;
699                 write_cum += w;
700                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
701                            1 << i, r, pct(r, read_tot),
702                            pct(read_cum, read_tot), w,
703                            pct(w, write_tot),
704                            pct(write_cum, write_tot));
705                 if (read_cum == read_tot && write_cum == write_tot)
706                         break;
707         }
708
709         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
710         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
711         seq_printf(seq, "       rpcs   %% cum %%\n");
712
713         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
714         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
715
716         read_cum = 0;
717         write_cum = 0;
718         for (i = 0; i < OBD_HIST_MAX; i++) {
719                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
720                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
721                 read_cum += r;
722                 write_cum += w;
723                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
724                            i, r, pct(r, read_tot),
725                            pct(read_cum, read_tot), w,
726                            pct(w, write_tot),
727                            pct(write_cum, write_tot));
728                 if (read_cum == read_tot && write_cum == write_tot)
729                         break;
730         }
731
732         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
733         seq_printf(seq, "offset                rpcs   %% cum %% |");
734         seq_printf(seq, "       rpcs   %% cum %%\n");
735
736         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
737         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
738
739         read_cum = 0;
740         write_cum = 0;
741         for (i = 0; i < OBD_HIST_MAX; i++) {
742                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
743                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
744                 read_cum += r;
745                 write_cum += w;
746                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
747                            (i == 0) ? 0 : 1 << (i - 1),
748                            r, pct(r, read_tot), pct(read_cum, read_tot),
749                            w, pct(w, write_tot), pct(write_cum, write_tot));
750                 if (read_cum == read_tot && write_cum == write_tot)
751                         break;
752         }
753
754         spin_unlock(&cli->cl_loi_list_lock);
755
756         return 0;
757 }
758 #undef pct
759
760 static ssize_t osc_rpc_stats_seq_write(struct file *file,
761                                        const char __user *buf,
762                                        size_t len, loff_t *off)
763 {
764         struct seq_file *seq = file->private_data;
765         struct obd_device *dev = seq->private;
766         struct client_obd *cli = &dev->u.cli;
767
768         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
769         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
770         lprocfs_oh_clear(&cli->cl_read_page_hist);
771         lprocfs_oh_clear(&cli->cl_write_page_hist);
772         lprocfs_oh_clear(&cli->cl_read_offset_hist);
773         lprocfs_oh_clear(&cli->cl_write_offset_hist);
774
775         return len;
776 }
777 LPROC_SEQ_FOPS(osc_rpc_stats);
778
779 static int osc_stats_seq_show(struct seq_file *seq, void *v)
780 {
781         struct timespec64 now;
782         struct obd_device *dev = seq->private;
783         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
784
785         ktime_get_real_ts64(&now);
786
787         seq_printf(seq, "snapshot_time:         %lld.%09lu (secs.nsecs)\n",
788                    (s64)now.tv_sec, now.tv_nsec);
789         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
790                    stats->os_lockless_writes);
791         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
792                    stats->os_lockless_reads);
793         seq_printf(seq, "lockless_truncate\t\t%llu\n",
794                    stats->os_lockless_truncates);
795         return 0;
796 }
797
798 static ssize_t osc_stats_seq_write(struct file *file,
799                                    const char __user *buf,
800                                    size_t len, loff_t *off)
801 {
802         struct seq_file *seq = file->private_data;
803         struct obd_device *dev = seq->private;
804         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
805
806         memset(stats, 0, sizeof(*stats));
807         return len;
808 }
809
810 LPROC_SEQ_FOPS(osc_stats);
811
812 int lproc_osc_attach_seqstat(struct obd_device *dev)
813 {
814         int rc;
815
816         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
817                                 &osc_stats_fops, dev);
818         if (rc == 0)
819                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
820                                             &osc_rpc_stats_fops, dev);
821
822         return rc;
823 }
824 #endif /* CONFIG_PROC_FS */