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