Whamcloud - gitweb
b=21587 don't LBUG if transno has changed during replay
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
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_class.h>
41 #include <lprocfs_status.h>
42 #include <linux/seq_file.h>
43 #include "osc_internal.h"
44
45 #ifdef LPROCFS
46 static int osc_rd_active(char *page, char **start, off_t off,
47                          int count, int *eof, void *data)
48 {
49         struct obd_device *dev = data;
50         int rc;
51
52         LPROCFS_CLIMP_CHECK(dev);
53         rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
54         LPROCFS_CLIMP_EXIT(dev);
55         return rc;
56 }
57
58 static int osc_wr_active(struct file *file, const char *buffer,
59                          unsigned long count, void *data)
60 {
61         struct obd_device *dev = data;
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         LPROCFS_CLIMP_CHECK(dev);
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", val);
76
77         LPROCFS_CLIMP_EXIT(dev);
78         return count;
79 }
80
81
82 static int osc_rd_max_pages_per_rpc(char *page, char **start, off_t off,
83                                     int count, int *eof, void *data)
84 {
85         struct obd_device *dev = data;
86         struct client_obd *cli = &dev->u.cli;
87         int rc;
88
89         client_obd_list_lock(&cli->cl_loi_list_lock);
90         rc = snprintf(page, count, "%d\n", cli->cl_max_pages_per_rpc);
91         client_obd_list_unlock(&cli->cl_loi_list_lock);
92         return rc;
93 }
94
95 static int osc_wr_max_pages_per_rpc(struct file *file, const char *buffer,
96                                     unsigned long count, void *data)
97 {
98         struct obd_device *dev = data;
99         struct client_obd *cli = &dev->u.cli;
100         struct obd_connect_data *ocd;
101         int val, rc;
102
103         rc = lprocfs_write_helper(buffer, count, &val);
104         if (rc)
105                 return rc;
106
107         LPROCFS_CLIMP_CHECK(dev);
108         ocd = &cli->cl_import->imp_connect_data;
109         if (val < 1 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
110                 LPROCFS_CLIMP_EXIT(dev);
111                 return -ERANGE;
112         }
113         client_obd_list_lock(&cli->cl_loi_list_lock);
114         cli->cl_max_pages_per_rpc = val;
115         client_obd_list_unlock(&cli->cl_loi_list_lock);
116         LPROCFS_CLIMP_EXIT(dev);
117         return count;
118 }
119
120 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
121                                      int count, int *eof, void *data)
122 {
123         struct obd_device *dev = data;
124         struct client_obd *cli = &dev->u.cli;
125         int rc;
126
127         client_obd_list_lock(&cli->cl_loi_list_lock);
128         rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
129         client_obd_list_unlock(&cli->cl_loi_list_lock);
130         return rc;
131 }
132
133 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
134                                      unsigned long count, void *data)
135 {
136         struct obd_device *dev = data;
137         struct client_obd *cli = &dev->u.cli;
138         struct ptlrpc_request_pool *pool;
139         int val, rc;
140
141         rc = lprocfs_write_helper(buffer, count, &val);
142         if (rc)
143                 return rc;
144         if (val < 1 || val > OSC_MAX_RIF_MAX)
145                 return -ERANGE;
146
147         LPROCFS_CLIMP_CHECK(dev);
148         pool = cli->cl_import->imp_rq_pool;
149         if (pool && val > cli->cl_max_rpcs_in_flight)
150                 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
151
152         client_obd_list_lock(&cli->cl_loi_list_lock);
153         cli->cl_max_rpcs_in_flight = val;
154         client_obd_list_unlock(&cli->cl_loi_list_lock);
155
156         LPROCFS_CLIMP_EXIT(dev);
157         return count;
158 }
159
160 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
161                                int *eof, void *data)
162 {
163         struct obd_device *dev = data;
164         struct client_obd *cli = &dev->u.cli;
165         long val;
166         int mult;
167
168         client_obd_list_lock(&cli->cl_loi_list_lock);
169         val = cli->cl_dirty_max;
170         client_obd_list_unlock(&cli->cl_loi_list_lock);
171
172         mult = 1 << 20;
173         return lprocfs_read_frac_helper(page, count, val, mult);
174 }
175
176 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
177                                unsigned long count, void *data)
178 {
179         struct obd_device *dev = data;
180         struct client_obd *cli = &dev->u.cli;
181         int pages_number, mult, rc;
182
183         mult = 1 << (20 - CFS_PAGE_SHIFT);
184         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
185         if (rc)
186                 return rc;
187
188         if (pages_number < 0 || pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
189             pages_number > num_physpages / 4) /* 1/4 of RAM */
190                 return -ERANGE;
191
192         client_obd_list_lock(&cli->cl_loi_list_lock);
193         cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
194         osc_wake_cache_waiters(cli);
195         client_obd_list_unlock(&cli->cl_loi_list_lock);
196
197         return count;
198 }
199
200 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
201                                   int count, int *eof, void *data)
202 {
203         struct obd_device *dev = data;
204         struct client_obd *cli = &dev->u.cli;
205         int rc;
206
207         client_obd_list_lock(&cli->cl_loi_list_lock);
208         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
209         client_obd_list_unlock(&cli->cl_loi_list_lock);
210         return rc;
211 }
212
213 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
214                                   int count, int *eof, void *data)
215 {
216         struct obd_device *dev = data;
217         struct client_obd *cli = &dev->u.cli;
218         int rc;
219
220         client_obd_list_lock(&cli->cl_loi_list_lock);
221         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
222         client_obd_list_unlock(&cli->cl_loi_list_lock);
223         return rc;
224 }
225
226 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
227                                   unsigned long count, void *data)
228 {
229         struct obd_device *obd = data;
230         struct client_obd *cli = &obd->u.cli;
231         int                rc;
232         __u64              val;
233
234         if (obd == NULL)
235                 return 0;
236
237         rc = lprocfs_write_u64_helper(buffer, count, &val);
238         if (rc)
239                 return rc;
240
241         /* this is only for shrinking grant */
242         client_obd_list_lock(&cli->cl_loi_list_lock);
243         if (val >= cli->cl_avail_grant) {
244                 client_obd_list_unlock(&cli->cl_loi_list_lock);
245                 return 0;
246         }
247         client_obd_list_unlock(&cli->cl_loi_list_lock);
248
249         LPROCFS_CLIMP_CHECK(obd);
250         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
251                 rc = osc_shrink_grant_to_target(cli, val);
252         LPROCFS_CLIMP_EXIT(obd);
253         if (rc)
254                 return rc;
255         return count;
256 }
257
258 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
259                                        int count, int *eof, void *data)
260 {
261         struct obd_device *dev = data;
262         struct client_obd *cli = &dev->u.cli;
263         int rc;
264
265         client_obd_list_lock(&cli->cl_loi_list_lock);
266         rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
267         client_obd_list_unlock(&cli->cl_loi_list_lock);
268         return rc;
269 }
270
271 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
272                                         int count, int *eof, void *data)
273 {
274         struct obd_device *obd = data;
275
276         if (obd == NULL)
277                 return 0;
278         return snprintf(page, count, "%d\n",
279                         obd->u.cli.cl_grant_shrink_interval);
280 }
281
282 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
283                                         unsigned long count, void *data)
284 {
285         struct obd_device *obd = data;
286         int val, rc;
287
288         if (obd == NULL)
289                 return 0;
290
291         rc = lprocfs_write_helper(buffer, count, &val);
292         if (rc)
293                 return rc;
294
295         if (val <= 0)
296                 return -ERANGE;
297
298         obd->u.cli.cl_grant_shrink_interval = val;
299
300         return count;
301 }
302
303 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
304                                int *eof, void *data)
305 {
306         struct obd_device *obd = data;
307
308         if (obd == NULL)
309                 return 0;
310
311         return snprintf(page, count, "%d\n",
312                         obd->u.cli.cl_oscc.oscc_grow_count);
313 }
314
315 static int osc_wr_create_count(struct file *file, const char *buffer,
316                                unsigned long count, void *data)
317 {
318         struct obd_device *obd = data;
319         int val, rc, i;
320
321         if (obd == NULL)
322                 return 0;
323
324         rc = lprocfs_write_helper(buffer, count, &val);
325         if (rc)
326                 return rc;
327
328         /* The MDT ALWAYS needs to limit the precreate count to
329          * OST_MAX_PRECREATE, and the constant cannot be changed
330          * because it is a value shared between the OSC and OST
331          * that is the maximum possible number of objects that will
332          * ever be handled by MDT->OST recovery processing.
333          *
334          * If the OST ever gets a request to delete more orphans,
335          * this implies that something has gone badly on the MDT
336          * and the OST will refuse to delete so much data from the
337          * filesystem as a safety measure. */
338         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
339                 return -ERANGE;
340         if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
341                 return -ERANGE;
342
343         for (i = 1; (i << 1) <= val; i <<= 1)
344                 ;
345         obd->u.cli.cl_oscc.oscc_grow_count = i;
346
347         return count;
348 }
349
350 static int osc_rd_max_create_count(char *page, char **start, off_t off,
351                                    int count, int *eof, void *data)
352 {
353         struct obd_device *obd = data;
354
355         if (obd == NULL)
356                 return 0;
357
358         return snprintf(page, count, "%d\n",
359                         obd->u.cli.cl_oscc.oscc_max_grow_count);
360 }
361
362 static int osc_wr_max_create_count(struct file *file, const char *buffer,
363                                    unsigned long count, void *data)
364 {
365         struct obd_device *obd = data;
366         int val, rc;
367
368         if (obd == NULL)
369                 return 0;
370
371         rc = lprocfs_write_helper(buffer, count, &val);
372         if (rc)
373                 return rc;
374
375         if (val < 0)
376                 return -ERANGE;
377         if (val > OST_MAX_PRECREATE)
378                 return -ERANGE;
379
380         if (obd->u.cli.cl_oscc.oscc_grow_count > val)
381                 obd->u.cli.cl_oscc.oscc_grow_count = val;
382
383         obd->u.cli.cl_oscc.oscc_max_grow_count = val;
384
385         return count;
386 }
387
388 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
389                                    int count, int *eof, void *data)
390 {
391         struct obd_device *obd = data;
392
393         if (obd == NULL)
394                 return 0;
395
396         return snprintf(page, count, LPU64"\n",
397                         obd->u.cli.cl_oscc.oscc_next_id);
398 }
399
400 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
401                                    int count, int *eof, void *data)
402 {
403         struct obd_device *obd = data;
404
405         if (obd == NULL)
406                 return 0;
407
408         return snprintf(page, count, LPU64"\n",
409                         obd->u.cli.cl_oscc.oscc_last_id);
410 }
411
412 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
413                            int *eof, void *data)
414 {
415         struct obd_device *obd = data;
416
417         if (obd == NULL)
418                 return 0;
419
420         return snprintf(page, count, "%d\n",
421                         obd->u.cli.cl_checksum ? 1 : 0);
422 }
423
424 static int osc_wr_checksum(struct file *file, const char *buffer,
425                            unsigned long count, void *data)
426 {
427         struct obd_device *obd = data;
428         int val, rc;
429
430         if (obd == NULL)
431                 return 0;
432
433         rc = lprocfs_write_helper(buffer, count, &val);
434         if (rc)
435                 return rc;
436
437         obd->u.cli.cl_checksum = (val ? 1 : 0);
438
439         return count;
440 }
441
442 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
443                                 int *eof, void *data)
444 {
445         struct obd_device *obd = data;
446         int i, len =0;
447         DECLARE_CKSUM_NAME;
448
449         if (obd == NULL)
450                 return 0;
451
452         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
453                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
454                         continue;
455                 if (obd->u.cli.cl_cksum_type == (1 << i))
456                         len += snprintf(page + len, count - len, "[%s] ",
457                                         cksum_name[i]);
458                 else
459                         len += snprintf(page + len, count - len, "%s ",
460                                         cksum_name[i]);
461         }
462         if (len < count)
463                 len += sprintf(page + len, "\n");
464         return len;
465 }
466
467 static int osc_wd_checksum_type(struct file *file, const char *buffer,
468                                 unsigned long count, void *data)
469 {
470         struct obd_device *obd = data;
471         int i;
472         DECLARE_CKSUM_NAME;
473         char kernbuf[10];
474
475         if (obd == NULL)
476                 return 0;
477
478         if (count > sizeof(kernbuf) - 1)
479                 return -EINVAL;
480         if (copy_from_user(kernbuf, buffer, count))
481                 return -EFAULT;
482         if (count > 0 && kernbuf[count - 1] == '\n')
483                 kernbuf[count - 1] = '\0';
484         else
485                 kernbuf[count] = '\0';
486
487         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
488                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
489                         continue;
490                 if (!strcmp(kernbuf, cksum_name[i])) {
491                        obd->u.cli.cl_cksum_type = 1 << i;
492                        return count;
493                 }
494         }
495         return -EINVAL;
496 }
497
498 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
499                                int *eof, void *data)
500 {
501         struct obd_device *obd = data;
502
503         return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends));
504 }
505
506 static int osc_wr_resend_count(struct file *file, const char *buffer,
507                                unsigned long count, void *data)
508 {
509         struct obd_device *obd = data;
510         int val, rc;
511
512         rc = lprocfs_write_helper(buffer, count, &val);
513         if (rc)
514                 return rc;
515
516         if (val < 0)
517                return -EINVAL;
518
519         atomic_set(&obd->u.cli.cl_resends, val);
520
521         return count;
522 }
523
524 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
525                                      int count, int *eof, void *data)
526 {
527         struct obd_device *obd = data;
528         return snprintf(page, count, "%u\n",
529                         atomic_read(&obd->u.cli.cl_destroy_in_flight));
530 }
531
532 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
533         { "uuid",            lprocfs_rd_uuid,        0, 0 },
534         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
535         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
536         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
537         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
538         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
539         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
540         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
541         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
542         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
543         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
544         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
545         { "active",          osc_rd_active,
546                              osc_wr_active, 0 },
547         { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
548                                osc_wr_max_pages_per_rpc, 0 },
549         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
550                                 osc_wr_max_rpcs_in_flight, 0 },
551         { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
552         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
553         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
554         { "cur_grant_bytes", osc_rd_cur_grant_bytes,
555                              osc_wr_cur_grant_bytes, 0 },
556         { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
557         { "grant_shrink_interval", osc_rd_grant_shrink_interval,
558                                    osc_wr_grant_shrink_interval, 0 },
559         { "create_count",    osc_rd_create_count, osc_wr_create_count, 0 },
560         { "max_create_count", osc_rd_max_create_count,
561                               osc_wr_max_create_count, 0},
562         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
563         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
564         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
565         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
566         { "resend_count",  osc_rd_resend_count, osc_wr_resend_count, 0},
567         { "timeouts",        lprocfs_rd_timeouts,      0, 0 },
568         { "import",          lprocfs_rd_import,    0, 0 },
569         { "state",           lprocfs_rd_state,         0, 0 },
570         { 0 }
571 };
572
573 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
574         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
575         { 0 }
576 };
577
578 #define pct(a,b) (b ? a * 100 / b : 0)
579
580 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
581 {
582         struct timeval now;
583         struct obd_device *dev = seq->private;
584         struct client_obd *cli = &dev->u.cli;
585         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
586         int i;
587
588         do_gettimeofday(&now);
589
590         client_obd_list_lock(&cli->cl_loi_list_lock);
591
592         seq_printf(seq, "snapshot_time:            %lu.%lu (secs.usecs)\n",
593                    now.tv_sec, now.tv_usec);
594         seq_printf(seq, "read RPCs in flight:      %d\n",
595                    cli->cl_r_in_flight);
596         seq_printf(seq, "write RPCs in flight:     %d\n",
597                    cli->cl_w_in_flight);
598         seq_printf(seq, "dio read RPCs in flight:  %d\n",
599                    cli->cl_dio_r_in_flight);
600         seq_printf(seq, "dio write RPCs in flight: %d\n",
601                    cli->cl_dio_w_in_flight);
602         seq_printf(seq, "pending write pages:      %d\n",
603                    cli->cl_pending_w_pages);
604         seq_printf(seq, "pending read pages:       %d\n",
605                    cli->cl_pending_r_pages);
606
607         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
608         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
609         seq_printf(seq, "       rpcs   %% cum %%\n");
610
611         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
612         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
613
614         read_cum = 0;
615         write_cum = 0;
616         for (i = 0; i < OBD_HIST_MAX; i++) {
617                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
618                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
619                 read_cum += r;
620                 write_cum += w;
621                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
622                                  1 << i, r, pct(r, read_tot),
623                                  pct(read_cum, read_tot), w,
624                                  pct(w, write_tot),
625                                  pct(write_cum, write_tot));
626                 if (read_cum == read_tot && write_cum == write_tot)
627                         break;
628         }
629
630         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
631         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
632         seq_printf(seq, "       rpcs   %% cum %%\n");
633
634         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
635         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
636
637         read_cum = 0;
638         write_cum = 0;
639         for (i = 0; i < OBD_HIST_MAX; i++) {
640                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
641                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
642                 read_cum += r;
643                 write_cum += w;
644                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
645                                  i, r, pct(r, read_tot),
646                                  pct(read_cum, read_tot), w,
647                                  pct(w, write_tot),
648                                  pct(write_cum, write_tot));
649                 if (read_cum == read_tot && write_cum == write_tot)
650                         break;
651         }
652
653         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
654         seq_printf(seq, "offset                rpcs   %% cum %% |");
655         seq_printf(seq, "       rpcs   %% cum %%\n");
656
657         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
658         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
659
660         read_cum = 0;
661         write_cum = 0;
662         for (i = 0; i < OBD_HIST_MAX; i++) {
663                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
664                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
665                 read_cum += r;
666                 write_cum += w;
667                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
668                            (i == 0) ? 0 : 1 << (i - 1),
669                            r, pct(r, read_tot), pct(read_cum, read_tot),
670                            w, pct(w, write_tot), pct(write_cum, write_tot));
671                 if (read_cum == read_tot && write_cum == write_tot)
672                         break;
673         }
674
675         client_obd_list_unlock(&cli->cl_loi_list_lock);
676
677         return 0;
678 }
679 #undef pct
680
681 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
682                                        size_t len, loff_t *off)
683 {
684         struct seq_file *seq = file->private_data;
685         struct obd_device *dev = seq->private;
686         struct client_obd *cli = &dev->u.cli;
687
688         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
689         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
690         lprocfs_oh_clear(&cli->cl_read_page_hist);
691         lprocfs_oh_clear(&cli->cl_write_page_hist);
692         lprocfs_oh_clear(&cli->cl_read_offset_hist);
693         lprocfs_oh_clear(&cli->cl_write_offset_hist);
694
695         return len;
696 }
697
698 LPROC_SEQ_FOPS(osc_rpc_stats);
699
700 int lproc_osc_attach_seqstat(struct obd_device *dev)
701 {
702         return lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
703                                       &osc_rpc_stats_fops, dev);
704 }
705
706 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
707 {
708         lvars->module_vars = lprocfs_osc_module_vars;
709         lvars->obd_vars    = lprocfs_osc_obd_vars;
710 }
711 #endif /* LPROCFS */