Whamcloud - gitweb
cf472d15d0f2b788fb8ed9ee6fa234a6367ec9b1
[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, 2012, 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_rd_active(char *page, char **start, off_t off,
48                          int count, int *eof, void *data)
49 {
50         struct obd_device *dev = data;
51         int rc;
52
53         LPROCFS_CLIMP_CHECK(dev);
54         rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
55         LPROCFS_CLIMP_EXIT(dev);
56         return rc;
57 }
58
59 static int osc_wr_active(struct file *file, const char *buffer,
60                          unsigned long count, void *data)
61 {
62         struct obd_device *dev = data;
63         int val, rc;
64
65         rc = lprocfs_write_helper(buffer, count, &val);
66         if (rc)
67                 return rc;
68         if (val < 0 || val > 1)
69                 return -ERANGE;
70
71         LPROCFS_CLIMP_CHECK(dev);
72         /* opposite senses */
73         if (dev->u.cli.cl_import->imp_deactive == val)
74                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
75         else
76                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
77
78         LPROCFS_CLIMP_EXIT(dev);
79         return count;
80 }
81
82 static int osc_rd_max_rpcs_in_flight(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, "%u\n", cli->cl_max_rpcs_in_flight);
91         client_obd_list_unlock(&cli->cl_loi_list_lock);
92         return rc;
93 }
94
95 static int osc_wr_max_rpcs_in_flight(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 ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
101         int val, rc;
102
103         rc = lprocfs_write_helper(buffer, count, &val);
104         if (rc)
105                 return rc;
106
107         if (val < 1 || val > OSC_MAX_RIF_MAX)
108                 return -ERANGE;
109
110         LPROCFS_CLIMP_CHECK(dev);
111         if (pool && val > cli->cl_max_rpcs_in_flight)
112                 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
113
114         client_obd_list_lock(&cli->cl_loi_list_lock);
115         cli->cl_max_rpcs_in_flight = val;
116         client_obd_list_unlock(&cli->cl_loi_list_lock);
117
118         LPROCFS_CLIMP_EXIT(dev);
119         return count;
120 }
121
122 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
123                                int *eof, void *data)
124 {
125         struct obd_device *dev = data;
126         struct client_obd *cli = &dev->u.cli;
127         long val;
128         int mult;
129
130         client_obd_list_lock(&cli->cl_loi_list_lock);
131         val = cli->cl_dirty_max;
132         client_obd_list_unlock(&cli->cl_loi_list_lock);
133
134         mult = 1 << 20;
135         return lprocfs_read_frac_helper(page, count, val, mult);
136 }
137
138 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
139                                unsigned long count, void *data)
140 {
141         struct obd_device *dev = data;
142         struct client_obd *cli = &dev->u.cli;
143         int pages_number, mult, rc;
144
145         mult = 1 << (20 - CFS_PAGE_SHIFT);
146         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
147         if (rc)
148                 return rc;
149
150         if (pages_number < 0 ||
151             pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
152             pages_number > cfs_num_physpages / 4) /* 1/4 of RAM */
153                 return -ERANGE;
154
155         client_obd_list_lock(&cli->cl_loi_list_lock);
156         cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
157         osc_wake_cache_waiters(cli);
158         client_obd_list_unlock(&cli->cl_loi_list_lock);
159
160         return count;
161 }
162
163 static int osc_rd_cached_mb(char *page, char **start, off_t off, int count,
164                             int *eof, void *data)
165 {
166         struct obd_device *dev = data;
167         struct client_obd *cli = &dev->u.cli;
168         int shift = 20 - CFS_PAGE_SHIFT;
169         int rc;
170
171         rc = snprintf(page, count,
172                       "used_mb: %d\n"
173                       "busy_cnt: %d\n",
174                       (cfs_atomic_read(&cli->cl_lru_in_list) +
175                         cfs_atomic_read(&cli->cl_lru_busy)) >> shift,
176                       cfs_atomic_read(&cli->cl_lru_busy));
177
178         return rc;
179 }
180
181 /* shrink the number of caching pages to a specific number */
182 static int osc_wr_cached_mb(struct file *file, const char *buffer,
183                             unsigned long count, void *data)
184 {
185         struct obd_device *dev = data;
186         struct client_obd *cli = &dev->u.cli;
187         int pages_number, mult, rc;
188
189         mult = 1 << (20 - CFS_PAGE_SHIFT);
190         buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
191         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
192         if (rc)
193                 return rc;
194
195         if (pages_number < 0)
196                 return -ERANGE;
197
198         rc = cfs_atomic_read(&cli->cl_lru_in_list) - pages_number;
199         if (rc > 0)
200                 (void)osc_lru_shrink(cli, rc);
201
202         return count;
203 }
204
205 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
206                                   int count, int *eof, void *data)
207 {
208         struct obd_device *dev = data;
209         struct client_obd *cli = &dev->u.cli;
210         int rc;
211
212         client_obd_list_lock(&cli->cl_loi_list_lock);
213         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
214         client_obd_list_unlock(&cli->cl_loi_list_lock);
215         return rc;
216 }
217
218 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
219                                   int count, int *eof, void *data)
220 {
221         struct obd_device *dev = data;
222         struct client_obd *cli = &dev->u.cli;
223         int rc;
224
225         client_obd_list_lock(&cli->cl_loi_list_lock);
226         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
227         client_obd_list_unlock(&cli->cl_loi_list_lock);
228         return rc;
229 }
230
231 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
232                                   unsigned long count, void *data)
233 {
234         struct obd_device *obd = data;
235         struct client_obd *cli = &obd->u.cli;
236         int                rc;
237         __u64              val;
238
239         if (obd == NULL)
240                 return 0;
241
242         rc = lprocfs_write_u64_helper(buffer, count, &val);
243         if (rc)
244                 return rc;
245
246         /* this is only for shrinking grant */
247         client_obd_list_lock(&cli->cl_loi_list_lock);
248         if (val >= cli->cl_avail_grant) {
249                 client_obd_list_unlock(&cli->cl_loi_list_lock);
250                 return 0;
251         }
252         client_obd_list_unlock(&cli->cl_loi_list_lock);
253
254         LPROCFS_CLIMP_CHECK(obd);
255         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
256                 rc = osc_shrink_grant_to_target(cli, val);
257         LPROCFS_CLIMP_EXIT(obd);
258         if (rc)
259                 return rc;
260         return count;
261 }
262
263 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
264                                        int count, int *eof, void *data)
265 {
266         struct obd_device *dev = data;
267         struct client_obd *cli = &dev->u.cli;
268         int rc;
269
270         client_obd_list_lock(&cli->cl_loi_list_lock);
271         rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
272         client_obd_list_unlock(&cli->cl_loi_list_lock);
273         return rc;
274 }
275
276 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
277                                         int count, int *eof, void *data)
278 {
279         struct obd_device *obd = data;
280
281         if (obd == NULL)
282                 return 0;
283         return snprintf(page, count, "%d\n",
284                         obd->u.cli.cl_grant_shrink_interval);
285 }
286
287 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
288                                         unsigned long count, void *data)
289 {
290         struct obd_device *obd = data;
291         int val, rc;
292
293         if (obd == NULL)
294                 return 0;
295
296         rc = lprocfs_write_helper(buffer, count, &val);
297         if (rc)
298                 return rc;
299
300         if (val <= 0)
301                 return -ERANGE;
302
303         obd->u.cli.cl_grant_shrink_interval = val;
304
305         return count;
306 }
307
308 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
309                            int *eof, void *data)
310 {
311         struct obd_device *obd = data;
312
313         if (obd == NULL)
314                 return 0;
315
316         return snprintf(page, count, "%d\n",
317                         obd->u.cli.cl_checksum ? 1 : 0);
318 }
319
320 static int osc_wr_checksum(struct file *file, const char *buffer,
321                            unsigned long count, void *data)
322 {
323         struct obd_device *obd = data;
324         int val, rc;
325
326         if (obd == NULL)
327                 return 0;
328
329         rc = lprocfs_write_helper(buffer, count, &val);
330         if (rc)
331                 return rc;
332
333         obd->u.cli.cl_checksum = (val ? 1 : 0);
334
335         return count;
336 }
337
338 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
339                                 int *eof, void *data)
340 {
341         struct obd_device *obd = data;
342         int i, len =0;
343         DECLARE_CKSUM_NAME;
344
345         if (obd == NULL)
346                 return 0;
347
348         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
349                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
350                         continue;
351                 if (obd->u.cli.cl_cksum_type == (1 << i))
352                         len += snprintf(page + len, count - len, "[%s] ",
353                                         cksum_name[i]);
354                 else
355                         len += snprintf(page + len, count - len, "%s ",
356                                         cksum_name[i]);
357         }
358         if (len < count)
359                 len += sprintf(page + len, "\n");
360         return len;
361 }
362
363 static int osc_wd_checksum_type(struct file *file, const char *buffer,
364                                 unsigned long count, void *data)
365 {
366         struct obd_device *obd = data;
367         int i;
368         DECLARE_CKSUM_NAME;
369         char kernbuf[10];
370
371         if (obd == NULL)
372                 return 0;
373
374         if (count > sizeof(kernbuf) - 1)
375                 return -EINVAL;
376         if (cfs_copy_from_user(kernbuf, buffer, count))
377                 return -EFAULT;
378         if (count > 0 && kernbuf[count - 1] == '\n')
379                 kernbuf[count - 1] = '\0';
380         else
381                 kernbuf[count] = '\0';
382
383         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
384                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
385                         continue;
386                 if (!strcmp(kernbuf, cksum_name[i])) {
387                        obd->u.cli.cl_cksum_type = 1 << i;
388                        return count;
389                 }
390         }
391         return -EINVAL;
392 }
393
394 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
395                                int *eof, void *data)
396 {
397         struct obd_device *obd = data;
398
399         return snprintf(page, count, "%u\n",
400                         cfs_atomic_read(&obd->u.cli.cl_resends));
401 }
402
403 static int osc_wr_resend_count(struct file *file, const char *buffer,
404                                unsigned long count, void *data)
405 {
406         struct obd_device *obd = data;
407         int val, rc;
408
409         rc = lprocfs_write_helper(buffer, count, &val);
410         if (rc)
411                 return rc;
412
413         if (val < 0)
414                return -EINVAL;
415
416         cfs_atomic_set(&obd->u.cli.cl_resends, val);
417
418         return count;
419 }
420
421 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
422                                      int count, int *eof, void *data)
423 {
424         struct obd_device *obd = data;
425         struct osc_device *od  = obd2osc_dev(obd);
426
427         return snprintf(page, count, "%u\n", od->od_contention_time);
428 }
429
430 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
431                                      unsigned long count, void *data)
432 {
433         struct obd_device *obd = data;
434         struct osc_device *od  = obd2osc_dev(obd);
435
436         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
437                 count;
438 }
439
440 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
441                                     int count, int *eof, void *data)
442 {
443         struct obd_device *obd = data;
444         struct osc_device *od  = obd2osc_dev(obd);
445
446         return snprintf(page, count, "%u\n", od->od_lockless_truncate);
447 }
448
449 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
450                                     unsigned long count, void *data)
451 {
452         struct obd_device *obd = data;
453         struct osc_device *od  = obd2osc_dev(obd);
454
455         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
456                 count;
457 }
458
459 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
460                                      int count, int *eof, void *data)
461 {
462         struct obd_device *obd = data;
463         return snprintf(page, count, "%u\n",
464                         cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
465 }
466
467 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
468         const char *buffer, unsigned long count, void *data)
469 {
470         struct obd_device *dev = data;
471         struct client_obd *cli = &dev->u.cli;
472         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
473         int chunk_mask, val, rc;
474
475         rc = lprocfs_write_helper(buffer, count, &val);
476         if (rc)
477                 return rc;
478
479         LPROCFS_CLIMP_CHECK(dev);
480
481         chunk_mask = ~((1 << (cli->cl_chunkbits - CFS_PAGE_SHIFT)) - 1);
482         /* max_pages_per_rpc must be chunk aligned */
483         val = (val + ~chunk_mask) & chunk_mask;
484         if (val == 0 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
485                 LPROCFS_CLIMP_EXIT(dev);
486                 return -ERANGE;
487         }
488         client_obd_list_lock(&cli->cl_loi_list_lock);
489         cli->cl_max_pages_per_rpc = val;
490         client_obd_list_unlock(&cli->cl_loi_list_lock);
491
492         LPROCFS_CLIMP_EXIT(dev);
493         return count;
494 }
495
496 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
497         { "uuid",            lprocfs_rd_uuid,        0, 0 },
498         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
499         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
500         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
501         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
502         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
503         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
504         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
505         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
506         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
507         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
508         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
509         { "active",          osc_rd_active,
510                              osc_wr_active, 0 },
511         { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
512                                lprocfs_osc_wr_max_pages_per_rpc, 0 },
513         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
514                                 osc_wr_max_rpcs_in_flight, 0 },
515         { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
516         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
517         { "osc_cached_mb",   osc_rd_cached_mb,     osc_wr_cached_mb, 0 },
518         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
519         { "cur_grant_bytes", osc_rd_cur_grant_bytes,
520                              osc_wr_cur_grant_bytes, 0 },
521         { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
522         { "grant_shrink_interval", osc_rd_grant_shrink_interval,
523                                    osc_wr_grant_shrink_interval, 0 },
524         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
525         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
526         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
527         { "timeouts",        lprocfs_rd_timeouts,      0, 0 },
528         { "contention_seconds", osc_rd_contention_seconds,
529                                 osc_wr_contention_seconds, 0 },
530         { "lockless_truncate",  osc_rd_lockless_truncate,
531                                 osc_wr_lockless_truncate, 0 },
532         { "import",          lprocfs_rd_import,        lprocfs_wr_import, 0 },
533         { "state",           lprocfs_rd_state,         0, 0 },
534         { "pinger_recov",    lprocfs_rd_pinger_recov,
535                              lprocfs_wr_pinger_recov,  0, 0 },
536         { 0 }
537 };
538
539 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
540         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
541         { 0 }
542 };
543
544 #define pct(a,b) (b ? a * 100 / b : 0)
545
546 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
547 {
548         struct timeval now;
549         struct obd_device *dev = seq->private;
550         struct client_obd *cli = &dev->u.cli;
551         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
552         int i;
553
554         cfs_gettimeofday(&now);
555
556         client_obd_list_lock(&cli->cl_loi_list_lock);
557
558         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
559                    now.tv_sec, now.tv_usec);
560         seq_printf(seq, "read RPCs in flight:  %d\n",
561                    cli->cl_r_in_flight);
562         seq_printf(seq, "write RPCs in flight: %d\n",
563                    cli->cl_w_in_flight);
564         seq_printf(seq, "pending write pages:  %d\n",
565                    cfs_atomic_read(&cli->cl_pending_w_pages));
566         seq_printf(seq, "pending read pages:   %d\n",
567                    cfs_atomic_read(&cli->cl_pending_r_pages));
568
569         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
570         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
571         seq_printf(seq, "       rpcs   %% cum %%\n");
572
573         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
574         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
575
576         read_cum = 0;
577         write_cum = 0;
578         for (i = 0; i < OBD_HIST_MAX; i++) {
579                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
580                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
581                 read_cum += r;
582                 write_cum += w;
583                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
584                                  1 << i, r, pct(r, read_tot),
585                                  pct(read_cum, read_tot), w,
586                                  pct(w, write_tot),
587                                  pct(write_cum, write_tot));
588                 if (read_cum == read_tot && write_cum == write_tot)
589                         break;
590         }
591
592         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
593         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
594         seq_printf(seq, "       rpcs   %% cum %%\n");
595
596         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
597         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
598
599         read_cum = 0;
600         write_cum = 0;
601         for (i = 0; i < OBD_HIST_MAX; i++) {
602                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
603                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
604                 read_cum += r;
605                 write_cum += w;
606                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
607                                  i, r, pct(r, read_tot),
608                                  pct(read_cum, read_tot), w,
609                                  pct(w, write_tot),
610                                  pct(write_cum, write_tot));
611                 if (read_cum == read_tot && write_cum == write_tot)
612                         break;
613         }
614
615         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
616         seq_printf(seq, "offset                rpcs   %% cum %% |");
617         seq_printf(seq, "       rpcs   %% cum %%\n");
618
619         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
620         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
621
622         read_cum = 0;
623         write_cum = 0;
624         for (i = 0; i < OBD_HIST_MAX; i++) {
625                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
626                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
627                 read_cum += r;
628                 write_cum += w;
629                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
630                            (i == 0) ? 0 : 1 << (i - 1),
631                            r, pct(r, read_tot), pct(read_cum, read_tot),
632                            w, pct(w, write_tot), pct(write_cum, write_tot));
633                 if (read_cum == read_tot && write_cum == write_tot)
634                         break;
635         }
636
637         client_obd_list_unlock(&cli->cl_loi_list_lock);
638
639         return 0;
640 }
641 #undef pct
642
643 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
644                                        size_t len, loff_t *off)
645 {
646         struct seq_file *seq = file->private_data;
647         struct obd_device *dev = seq->private;
648         struct client_obd *cli = &dev->u.cli;
649
650         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
651         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
652         lprocfs_oh_clear(&cli->cl_read_page_hist);
653         lprocfs_oh_clear(&cli->cl_write_page_hist);
654         lprocfs_oh_clear(&cli->cl_read_offset_hist);
655         lprocfs_oh_clear(&cli->cl_write_offset_hist);
656
657         return len;
658 }
659
660 LPROC_SEQ_FOPS(osc_rpc_stats);
661
662 static int osc_stats_seq_show(struct seq_file *seq, void *v)
663 {
664         struct timeval now;
665         struct obd_device *dev = seq->private;
666         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
667
668         cfs_gettimeofday(&now);
669
670         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
671                    now.tv_sec, now.tv_usec);
672         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
673                    stats->os_lockless_writes);
674         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
675                    stats->os_lockless_reads);
676         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
677                    stats->os_lockless_truncates);
678         return 0;
679 }
680
681 static ssize_t osc_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 osc_stats *stats = &obd2osc_dev(dev)->od_stats;
687
688         memset(stats, 0, sizeof(*stats));
689         return len;
690 }
691
692 LPROC_SEQ_FOPS(osc_stats);
693
694 int lproc_osc_attach_seqstat(struct obd_device *dev)
695 {
696         int rc;
697
698         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
699                                 &osc_stats_fops, dev);
700         if (rc == 0)
701                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
702                                             &osc_rpc_stats_fops, dev);
703
704         return rc;
705 }
706
707 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
708 {
709         lvars->module_vars = lprocfs_osc_module_vars;
710         lvars->obd_vars    = lprocfs_osc_obd_vars;
711 }
712 #endif /* LPROCFS */