These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / staging / lustre / 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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/statfs.h>
39 #include "../include/obd_cksum.h"
40 #include "../include/obd_class.h"
41 #include "../include/lprocfs_status.h"
42 #include <linux/seq_file.h>
43 #include "osc_internal.h"
44
45 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
46                            char *buf)
47 {
48         struct obd_device *dev = container_of(kobj, struct obd_device,
49                                               obd_kobj);
50
51         return sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive);
52 }
53
54 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
55                             const char *buffer,
56                             size_t count)
57 {
58         struct obd_device *dev = container_of(kobj, struct obd_device,
59                                               obd_kobj);
60         int rc;
61         unsigned long val;
62
63         rc = kstrtoul(buffer, 10, &val);
64         if (rc)
65                 return rc;
66         if (val > 1)
67                 return -ERANGE;
68
69         /* opposite senses */
70         if (dev->u.cli.cl_import->imp_deactive == val)
71                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
72         else
73                 CDEBUG(D_CONFIG, "activate %ld: ignoring repeat request\n",
74                        val);
75
76         return count;
77 }
78 LUSTRE_RW_ATTR(active);
79
80 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
81                                        struct attribute *attr,
82                                        char *buf)
83 {
84         struct obd_device *dev = container_of(kobj, struct obd_device,
85                                               obd_kobj);
86         struct client_obd *cli = &dev->u.cli;
87
88         return sprintf(buf, "%u\n", cli->cl_max_rpcs_in_flight);
89 }
90
91 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
92                                         struct attribute *attr,
93                                         const char *buffer,
94                                         size_t count)
95 {
96         struct obd_device *dev = container_of(kobj, struct obd_device,
97                                               obd_kobj);
98         struct client_obd *cli = &dev->u.cli;
99         int rc;
100         unsigned long val;
101         int adding, added, req_count;
102
103         rc = kstrtoul(buffer, 10, &val);
104         if (rc)
105                 return rc;
106
107         if (val < 1 || val > OSC_MAX_RIF_MAX)
108                 return -ERANGE;
109
110         adding = val - cli->cl_max_rpcs_in_flight;
111         req_count = atomic_read(&osc_pool_req_count);
112         if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
113                 /*
114                  * There might be some race which will cause over-limit
115                  * allocation, but it is fine.
116                  */
117                 if (req_count + adding > osc_reqpool_maxreqcount)
118                         adding = osc_reqpool_maxreqcount - req_count;
119
120                 added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
121                 atomic_add(added, &osc_pool_req_count);
122         }
123
124         client_obd_list_lock(&cli->cl_loi_list_lock);
125         cli->cl_max_rpcs_in_flight = val;
126         client_obd_list_unlock(&cli->cl_loi_list_lock);
127
128         return count;
129 }
130 LUSTRE_RW_ATTR(max_rpcs_in_flight);
131
132 static ssize_t max_dirty_mb_show(struct kobject *kobj,
133                                  struct attribute *attr,
134                                  char *buf)
135 {
136         struct obd_device *dev = container_of(kobj, struct obd_device,
137                                               obd_kobj);
138         struct client_obd *cli = &dev->u.cli;
139         long val;
140         int mult;
141
142         client_obd_list_lock(&cli->cl_loi_list_lock);
143         val = cli->cl_dirty_max;
144         client_obd_list_unlock(&cli->cl_loi_list_lock);
145
146         mult = 1 << 20;
147         return lprocfs_read_frac_helper(buf, PAGE_SIZE, val, mult);
148 }
149
150 static ssize_t max_dirty_mb_store(struct kobject *kobj,
151                                   struct attribute *attr,
152                                   const char *buffer,
153                                   size_t count)
154 {
155         struct obd_device *dev = container_of(kobj, struct obd_device,
156                                               obd_kobj);
157         struct client_obd *cli = &dev->u.cli;
158         int rc;
159         unsigned long pages_number;
160
161         rc = kstrtoul(buffer, 10, &pages_number);
162         if (rc)
163                 return rc;
164
165         pages_number *= 1 << (20 - PAGE_CACHE_SHIFT); /* MB -> pages */
166
167         if (pages_number <= 0 ||
168             pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_CACHE_SHIFT) ||
169             pages_number > totalram_pages / 4) /* 1/4 of RAM */
170                 return -ERANGE;
171
172         client_obd_list_lock(&cli->cl_loi_list_lock);
173         cli->cl_dirty_max = (u32)(pages_number << PAGE_CACHE_SHIFT);
174         osc_wake_cache_waiters(cli);
175         client_obd_list_unlock(&cli->cl_loi_list_lock);
176
177         return count;
178 }
179 LUSTRE_RW_ATTR(max_dirty_mb);
180
181 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
182 {
183         struct obd_device *dev = m->private;
184         struct client_obd *cli = &dev->u.cli;
185         int shift = 20 - PAGE_CACHE_SHIFT;
186
187         seq_printf(m,
188                    "used_mb: %d\n"
189                    "busy_cnt: %d\n",
190                    (atomic_read(&cli->cl_lru_in_list) +
191                     atomic_read(&cli->cl_lru_busy)) >> shift,
192                    atomic_read(&cli->cl_lru_busy));
193
194         return 0;
195 }
196
197 /* shrink the number of caching pages to a specific number */
198 static ssize_t osc_cached_mb_seq_write(struct file *file,
199                                        const char __user *buffer,
200                                        size_t count, loff_t *off)
201 {
202         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
203         struct client_obd *cli = &dev->u.cli;
204         int pages_number, mult, rc;
205         char kernbuf[128];
206
207         if (count >= sizeof(kernbuf))
208                 return -EINVAL;
209
210         if (copy_from_user(kernbuf, buffer, count))
211                 return -EFAULT;
212         kernbuf[count] = 0;
213
214         mult = 1 << (20 - PAGE_CACHE_SHIFT);
215         buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
216                   kernbuf;
217         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
218         if (rc)
219                 return rc;
220
221         if (pages_number < 0)
222                 return -ERANGE;
223
224         rc = atomic_read(&cli->cl_lru_in_list) - pages_number;
225         if (rc > 0)
226                 (void)osc_lru_shrink(cli, rc);
227
228         return count;
229 }
230
231 LPROC_SEQ_FOPS(osc_cached_mb);
232
233 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
234                                     struct attribute *attr,
235                                     char *buf)
236 {
237         struct obd_device *dev = container_of(kobj, struct obd_device,
238                                               obd_kobj);
239         struct client_obd *cli = &dev->u.cli;
240         int len;
241
242         client_obd_list_lock(&cli->cl_loi_list_lock);
243         len = sprintf(buf, "%lu\n", cli->cl_dirty);
244         client_obd_list_unlock(&cli->cl_loi_list_lock);
245
246         return len;
247 }
248 LUSTRE_RO_ATTR(cur_dirty_bytes);
249
250 static ssize_t cur_grant_bytes_show(struct kobject *kobj,
251                                     struct attribute *attr,
252                                     char *buf)
253 {
254         struct obd_device *dev = container_of(kobj, struct obd_device,
255                                               obd_kobj);
256         struct client_obd *cli = &dev->u.cli;
257         int len;
258
259         client_obd_list_lock(&cli->cl_loi_list_lock);
260         len = sprintf(buf, "%lu\n", cli->cl_avail_grant);
261         client_obd_list_unlock(&cli->cl_loi_list_lock);
262
263         return len;
264 }
265
266 static ssize_t cur_grant_bytes_store(struct kobject *kobj,
267                                      struct attribute *attr,
268                                      const char *buffer,
269                                      size_t count)
270 {
271         struct obd_device *obd = container_of(kobj, struct obd_device,
272                                               obd_kobj);
273         struct client_obd *cli = &obd->u.cli;
274         int rc;
275         unsigned long long val;
276
277         rc = kstrtoull(buffer, 10, &val);
278         if (rc)
279                 return rc;
280
281         /* this is only for shrinking grant */
282         client_obd_list_lock(&cli->cl_loi_list_lock);
283         if (val >= cli->cl_avail_grant) {
284                 client_obd_list_unlock(&cli->cl_loi_list_lock);
285                 return -EINVAL;
286         }
287         client_obd_list_unlock(&cli->cl_loi_list_lock);
288
289         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
290                 rc = osc_shrink_grant_to_target(cli, val);
291         if (rc)
292                 return rc;
293         return count;
294 }
295 LUSTRE_RW_ATTR(cur_grant_bytes);
296
297 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
298                                          struct attribute *attr,
299                                          char *buf)
300 {
301         struct obd_device *dev = container_of(kobj, struct obd_device,
302                                               obd_kobj);
303         struct client_obd *cli = &dev->u.cli;
304         int len;
305
306         client_obd_list_lock(&cli->cl_loi_list_lock);
307         len = sprintf(buf, "%lu\n", cli->cl_lost_grant);
308         client_obd_list_unlock(&cli->cl_loi_list_lock);
309
310         return len;
311 }
312 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
313
314 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
315                                           struct attribute *attr,
316                                           char *buf)
317 {
318         struct obd_device *obd = container_of(kobj, struct obd_device,
319                                               obd_kobj);
320
321         return sprintf(buf, "%d\n", obd->u.cli.cl_grant_shrink_interval);
322 }
323
324 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
325                                            struct attribute *attr,
326                                            const char *buffer,
327                                            size_t count)
328 {
329         struct obd_device *obd = container_of(kobj, struct obd_device,
330                                               obd_kobj);
331         int rc;
332         unsigned long val;
333
334         rc = kstrtoul(buffer, 10, &val);
335         if (rc)
336                 return rc;
337
338         if (val <= 0)
339                 return -ERANGE;
340
341         obd->u.cli.cl_grant_shrink_interval = val;
342
343         return count;
344 }
345 LUSTRE_RW_ATTR(grant_shrink_interval);
346
347 static ssize_t checksums_show(struct kobject *kobj,
348                               struct attribute *attr,
349                               char *buf)
350 {
351         struct obd_device *obd = container_of(kobj, struct obd_device,
352                                               obd_kobj);
353
354         return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
355 }
356
357 static ssize_t checksums_store(struct kobject *kobj,
358                                struct attribute *attr,
359                                const char *buffer,
360                                size_t count)
361 {
362         struct obd_device *obd = container_of(kobj, struct obd_device,
363                                               obd_kobj);
364         int rc;
365         unsigned long val;
366
367         rc = kstrtoul(buffer, 10, &val);
368         if (rc)
369                 return rc;
370
371         obd->u.cli.cl_checksum = (val ? 1 : 0);
372
373         return count;
374 }
375 LUSTRE_RW_ATTR(checksums);
376
377 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
378 {
379         struct obd_device *obd = m->private;
380         int i;
381
382         DECLARE_CKSUM_NAME;
383
384         if (obd == NULL)
385                 return 0;
386
387         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
388                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
389                         continue;
390                 if (obd->u.cli.cl_cksum_type == (1 << i))
391                         seq_printf(m, "[%s] ", cksum_name[i]);
392                 else
393                         seq_printf(m, "%s ", cksum_name[i]);
394         }
395         seq_putc(m, '\n');
396         return 0;
397 }
398
399 static ssize_t osc_checksum_type_seq_write(struct file *file,
400                                 const char __user *buffer,
401                                 size_t count, loff_t *off)
402 {
403         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
404         int i;
405
406         DECLARE_CKSUM_NAME;
407         char kernbuf[10];
408
409         if (obd == NULL)
410                 return 0;
411
412         if (count > sizeof(kernbuf) - 1)
413                 return -EINVAL;
414         if (copy_from_user(kernbuf, buffer, count))
415                 return -EFAULT;
416         if (count > 0 && kernbuf[count - 1] == '\n')
417                 kernbuf[count - 1] = '\0';
418         else
419                 kernbuf[count] = '\0';
420
421         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
422                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
423                         continue;
424                 if (!strcmp(kernbuf, cksum_name[i])) {
425                        obd->u.cli.cl_cksum_type = 1 << i;
426                        return count;
427                 }
428         }
429         return -EINVAL;
430 }
431
432 LPROC_SEQ_FOPS(osc_checksum_type);
433
434 static ssize_t resend_count_show(struct kobject *kobj,
435                                  struct attribute *attr,
436                                  char *buf)
437 {
438         struct obd_device *obd = container_of(kobj, struct obd_device,
439                                               obd_kobj);
440
441         return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
442 }
443
444 static ssize_t resend_count_store(struct kobject *kobj,
445                                   struct attribute *attr,
446                                   const char *buffer,
447                                   size_t count)
448 {
449         struct obd_device *obd = container_of(kobj, struct obd_device,
450                                               obd_kobj);
451         int rc;
452         unsigned long val;
453
454         rc = kstrtoul(buffer, 10, &val);
455         if (rc)
456                 return rc;
457
458         atomic_set(&obd->u.cli.cl_resends, val);
459
460         return count;
461 }
462 LUSTRE_RW_ATTR(resend_count);
463
464 static ssize_t contention_seconds_show(struct kobject *kobj,
465                                        struct attribute *attr,
466                                        char *buf)
467 {
468         struct obd_device *obd = container_of(kobj, struct obd_device,
469                                               obd_kobj);
470         struct osc_device *od  = obd2osc_dev(obd);
471
472         return sprintf(buf, "%u\n", od->od_contention_time);
473 }
474
475 static ssize_t contention_seconds_store(struct kobject *kobj,
476                                         struct attribute *attr,
477                                         const char *buffer,
478                                         size_t count)
479 {
480         struct obd_device *obd = container_of(kobj, struct obd_device,
481                                               obd_kobj);
482         struct osc_device *od  = obd2osc_dev(obd);
483
484         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
485                 count;
486 }
487 LUSTRE_RW_ATTR(contention_seconds);
488
489 static ssize_t lockless_truncate_show(struct kobject *kobj,
490                                       struct attribute *attr,
491                                       char *buf)
492 {
493         struct obd_device *obd = container_of(kobj, struct obd_device,
494                                               obd_kobj);
495         struct osc_device *od  = obd2osc_dev(obd);
496
497         return sprintf(buf, "%u\n", od->od_lockless_truncate);
498 }
499
500 static ssize_t lockless_truncate_store(struct kobject *kobj,
501                                        struct attribute *attr,
502                                        const char *buffer,
503                                        size_t count)
504 {
505         struct obd_device *obd = container_of(kobj, struct obd_device,
506                                               obd_kobj);
507         struct osc_device *od  = obd2osc_dev(obd);
508
509         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
510                 count;
511 }
512 LUSTRE_RW_ATTR(lockless_truncate);
513
514 static ssize_t destroys_in_flight_show(struct kobject *kobj,
515                                        struct attribute *attr,
516                                        char *buf)
517 {
518         struct obd_device *obd = container_of(kobj, struct obd_device,
519                                               obd_kobj);
520
521         return sprintf(buf, "%u\n",
522                        atomic_read(&obd->u.cli.cl_destroy_in_flight));
523 }
524 LUSTRE_RO_ATTR(destroys_in_flight);
525
526 static ssize_t max_pages_per_rpc_show(struct kobject *kobj,
527                                       struct attribute *attr,
528                                       char *buf)
529 {
530         struct obd_device *dev = container_of(kobj, struct obd_device,
531                                               obd_kobj);
532         struct client_obd *cli = &dev->u.cli;
533
534         return sprintf(buf, "%d\n", cli->cl_max_pages_per_rpc);
535 }
536
537 static ssize_t max_pages_per_rpc_store(struct kobject *kobj,
538                                        struct attribute *attr,
539                                        const char *buffer,
540                                        size_t count)
541 {
542         struct obd_device *dev = container_of(kobj, struct obd_device,
543                                               obd_kobj);
544         struct client_obd *cli = &dev->u.cli;
545         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
546         int chunk_mask, rc;
547         unsigned long long val;
548
549         rc = kstrtoull(buffer, 10, &val);
550         if (rc)
551                 return rc;
552
553         /* if the max_pages is specified in bytes, convert to pages */
554         if (val >= ONE_MB_BRW_SIZE)
555                 val >>= PAGE_CACHE_SHIFT;
556
557         chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1);
558         /* max_pages_per_rpc must be chunk aligned */
559         val = (val + ~chunk_mask) & chunk_mask;
560         if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) {
561                 return -ERANGE;
562         }
563         client_obd_list_lock(&cli->cl_loi_list_lock);
564         cli->cl_max_pages_per_rpc = val;
565         client_obd_list_unlock(&cli->cl_loi_list_lock);
566
567         return count;
568 }
569 LUSTRE_RW_ATTR(max_pages_per_rpc);
570
571 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
572 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
573 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
574 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
575 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
576
577 LPROC_SEQ_FOPS_WR_ONLY(osc, ping);
578
579 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
580 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
581
582 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
583         { "ping",            &osc_ping_fops,    NULL, 0222 },
584         { "connect_flags",   &osc_connect_flags_fops, NULL, 0 },
585         /*{ "filegroups",      lprocfs_rd_filegroups,  NULL, 0 },*/
586         { "ost_server_uuid", &osc_server_uuid_fops, NULL, 0 },
587         { "ost_conn_uuid",   &osc_conn_uuid_fops, NULL, 0 },
588         { "osc_cached_mb",   &osc_cached_mb_fops, NULL },
589         { "checksum_type",   &osc_checksum_type_fops, NULL },
590         { "timeouts",        &osc_timeouts_fops, NULL, 0 },
591         { "import",             &osc_import_fops, NULL },
592         { "state",              &osc_state_fops, NULL, 0 },
593         { "pinger_recov",       &osc_pinger_recov_fops, NULL },
594         { NULL }
595 };
596
597 #define pct(a, b) (b ? a * 100 / b : 0)
598
599 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
600 {
601         struct timespec64 now;
602         struct obd_device *dev = seq->private;
603         struct client_obd *cli = &dev->u.cli;
604         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
605         int i;
606
607         ktime_get_real_ts64(&now);
608
609         client_obd_list_lock(&cli->cl_loi_list_lock);
610
611         seq_printf(seq, "snapshot_time:  %llu.%9lu (secs.usecs)\n",
612                    (s64)now.tv_sec, (unsigned long)now.tv_nsec);
613         seq_printf(seq, "read RPCs in flight:  %d\n",
614                    cli->cl_r_in_flight);
615         seq_printf(seq, "write RPCs in flight: %d\n",
616                    cli->cl_w_in_flight);
617         seq_printf(seq, "pending write pages:  %d\n",
618                    atomic_read(&cli->cl_pending_w_pages));
619         seq_printf(seq, "pending read pages:   %d\n",
620                    atomic_read(&cli->cl_pending_r_pages));
621
622         seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
623         seq_puts(seq, "pages per rpc     rpcs   % cum % |");
624         seq_puts(seq, "       rpcs   % cum %\n");
625
626         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
627         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
628
629         read_cum = 0;
630         write_cum = 0;
631         for (i = 0; i < OBD_HIST_MAX; i++) {
632                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
633                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
634
635                 read_cum += r;
636                 write_cum += w;
637                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
638                                  1 << i, r, pct(r, read_tot),
639                                  pct(read_cum, read_tot), w,
640                                  pct(w, write_tot),
641                                  pct(write_cum, write_tot));
642                 if (read_cum == read_tot && write_cum == write_tot)
643                         break;
644         }
645
646         seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
647         seq_puts(seq, "rpcs in flight   rpcs   % cum % |");
648         seq_puts(seq, "       rpcs   % cum %\n");
649
650         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
651         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
652
653         read_cum = 0;
654         write_cum = 0;
655         for (i = 0; i < OBD_HIST_MAX; i++) {
656                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
657                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
658
659                 read_cum += r;
660                 write_cum += w;
661                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
662                                  i, r, pct(r, read_tot),
663                                  pct(read_cum, read_tot), w,
664                                  pct(w, write_tot),
665                                  pct(write_cum, write_tot));
666                 if (read_cum == read_tot && write_cum == write_tot)
667                         break;
668         }
669
670         seq_puts(seq, "\n\t\t\tread\t\t\twrite\n");
671         seq_puts(seq, "offset           rpcs   % cum % |");
672         seq_puts(seq, "       rpcs   % cum %\n");
673
674         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
675         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
676
677         read_cum = 0;
678         write_cum = 0;
679         for (i = 0; i < OBD_HIST_MAX; i++) {
680                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
681                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
682
683                 read_cum += r;
684                 write_cum += w;
685                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
686                            (i == 0) ? 0 : 1 << (i - 1),
687                            r, pct(r, read_tot), pct(read_cum, read_tot),
688                            w, pct(w, write_tot), pct(write_cum, write_tot));
689                 if (read_cum == read_tot && write_cum == write_tot)
690                         break;
691         }
692
693         client_obd_list_unlock(&cli->cl_loi_list_lock);
694
695         return 0;
696 }
697
698 #undef pct
699
700 static ssize_t osc_rpc_stats_seq_write(struct file *file,
701                                        const char __user *buf,
702                                        size_t len, loff_t *off)
703 {
704         struct seq_file *seq = file->private_data;
705         struct obd_device *dev = seq->private;
706         struct client_obd *cli = &dev->u.cli;
707
708         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
709         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
710         lprocfs_oh_clear(&cli->cl_read_page_hist);
711         lprocfs_oh_clear(&cli->cl_write_page_hist);
712         lprocfs_oh_clear(&cli->cl_read_offset_hist);
713         lprocfs_oh_clear(&cli->cl_write_offset_hist);
714
715         return len;
716 }
717
718 LPROC_SEQ_FOPS(osc_rpc_stats);
719
720 static int osc_stats_seq_show(struct seq_file *seq, void *v)
721 {
722         struct timespec64 now;
723         struct obd_device *dev = seq->private;
724         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
725
726         ktime_get_real_ts64(&now);
727
728         seq_printf(seq, "snapshot_time:  %llu.%9lu (secs.usecs)\n",
729                    (s64)now.tv_sec, (unsigned long)now.tv_nsec);
730         seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
731                    stats->os_lockless_writes);
732         seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
733                    stats->os_lockless_reads);
734         seq_printf(seq, "lockless_truncate\t\t%llu\n",
735                    stats->os_lockless_truncates);
736         return 0;
737 }
738
739 static ssize_t osc_stats_seq_write(struct file *file,
740                                    const char __user *buf,
741                                    size_t len, loff_t *off)
742 {
743         struct seq_file *seq = file->private_data;
744         struct obd_device *dev = seq->private;
745         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
746
747         memset(stats, 0, sizeof(*stats));
748         return len;
749 }
750
751 LPROC_SEQ_FOPS(osc_stats);
752
753 int lproc_osc_attach_seqstat(struct obd_device *dev)
754 {
755         int rc;
756
757         rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "osc_stats", 0644,
758                                  &osc_stats_fops, dev);
759         if (rc == 0)
760                 rc = ldebugfs_obd_seq_create(dev, "rpc_stats", 0644,
761                                              &osc_rpc_stats_fops, dev);
762
763         return rc;
764 }
765
766 static struct attribute *osc_attrs[] = {
767         &lustre_attr_active.attr,
768         &lustre_attr_checksums.attr,
769         &lustre_attr_contention_seconds.attr,
770         &lustre_attr_cur_dirty_bytes.attr,
771         &lustre_attr_cur_grant_bytes.attr,
772         &lustre_attr_cur_lost_grant_bytes.attr,
773         &lustre_attr_destroys_in_flight.attr,
774         &lustre_attr_grant_shrink_interval.attr,
775         &lustre_attr_lockless_truncate.attr,
776         &lustre_attr_max_dirty_mb.attr,
777         &lustre_attr_max_pages_per_rpc.attr,
778         &lustre_attr_max_rpcs_in_flight.attr,
779         &lustre_attr_resend_count.attr,
780         NULL,
781 };
782
783 static struct attribute_group osc_attr_group = {
784         .attrs = osc_attrs,
785 };
786
787 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
788 {
789         lvars->sysfs_vars  = &osc_attr_group;
790         lvars->obd_vars    = lprocfs_osc_obd_vars;
791 }