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