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