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