Whamcloud - gitweb
LU-1146 build: batch update copyright messages
[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  * Copyright (c) 2011, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  */
38 #define DEBUG_SUBSYSTEM S_CLASS
39
40 #include <linux/version.h>
41 #include <asm/statfs.h>
42 #include <obd_cksum.h>
43 #include <obd_class.h>
44 #include <lprocfs_status.h>
45 #include <linux/seq_file.h>
46 #include "osc_internal.h"
47
48 #ifdef LPROCFS
49 static int osc_rd_active(char *page, char **start, off_t off,
50                          int count, int *eof, void *data)
51 {
52         struct obd_device *dev = data;
53         int rc;
54
55         LPROCFS_CLIMP_CHECK(dev);
56         rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
57         LPROCFS_CLIMP_EXIT(dev);
58         return rc;
59 }
60
61 static int osc_wr_active(struct file *file, const char *buffer,
62                          unsigned long count, void *data)
63 {
64         struct obd_device *dev = data;
65         int val, rc;
66
67         rc = lprocfs_write_helper(buffer, count, &val);
68         if (rc)
69                 return rc;
70         if (val < 0 || val > 1)
71                 return -ERANGE;
72
73         LPROCFS_CLIMP_CHECK(dev);
74         /* opposite senses */
75         if (dev->u.cli.cl_import->imp_deactive == val)
76                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
77         else
78                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
79
80         LPROCFS_CLIMP_EXIT(dev);
81         return count;
82 }
83
84 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
85                                      int count, int *eof, void *data)
86 {
87         struct obd_device *dev = data;
88         struct client_obd *cli = &dev->u.cli;
89         int rc;
90
91         client_obd_list_lock(&cli->cl_loi_list_lock);
92         rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
93         client_obd_list_unlock(&cli->cl_loi_list_lock);
94         return rc;
95 }
96
97 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
98                                      unsigned long count, void *data)
99 {
100         struct obd_device *dev = data;
101         struct client_obd *cli = &dev->u.cli;
102         struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
103         int val, rc;
104
105         rc = lprocfs_write_helper(buffer, count, &val);
106         if (rc)
107                 return rc;
108
109         if (val < 1 || val > OSC_MAX_RIF_MAX)
110                 return -ERANGE;
111
112         LPROCFS_CLIMP_CHECK(dev);
113         if (pool && val > cli->cl_max_rpcs_in_flight)
114                 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
115
116         client_obd_list_lock(&cli->cl_loi_list_lock);
117         cli->cl_max_rpcs_in_flight = val;
118         client_obd_list_unlock(&cli->cl_loi_list_lock);
119
120         LPROCFS_CLIMP_EXIT(dev);
121         return count;
122 }
123
124 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
125                                int *eof, void *data)
126 {
127         struct obd_device *dev = data;
128         struct client_obd *cli = &dev->u.cli;
129         long val;
130         int mult;
131
132         client_obd_list_lock(&cli->cl_loi_list_lock);
133         val = cli->cl_dirty_max;
134         client_obd_list_unlock(&cli->cl_loi_list_lock);
135
136         mult = 1 << 20;
137         return lprocfs_read_frac_helper(page, count, val, mult);
138 }
139
140 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
141                                unsigned long count, void *data)
142 {
143         struct obd_device *dev = data;
144         struct client_obd *cli = &dev->u.cli;
145         int pages_number, mult, rc;
146
147         mult = 1 << (20 - CFS_PAGE_SHIFT);
148         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
149         if (rc)
150                 return rc;
151
152         if (pages_number < 0 ||
153             pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
154             pages_number > cfs_num_physpages / 4) /* 1/4 of RAM */
155                 return -ERANGE;
156
157         client_obd_list_lock(&cli->cl_loi_list_lock);
158         cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
159         osc_wake_cache_waiters(cli);
160         client_obd_list_unlock(&cli->cl_loi_list_lock);
161
162         return count;
163 }
164
165 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
166                                   int count, int *eof, void *data)
167 {
168         struct obd_device *dev = data;
169         struct client_obd *cli = &dev->u.cli;
170         int rc;
171
172         client_obd_list_lock(&cli->cl_loi_list_lock);
173         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
174         client_obd_list_unlock(&cli->cl_loi_list_lock);
175         return rc;
176 }
177
178 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
179                                   int count, int *eof, void *data)
180 {
181         struct obd_device *dev = data;
182         struct client_obd *cli = &dev->u.cli;
183         int rc;
184
185         client_obd_list_lock(&cli->cl_loi_list_lock);
186         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
187         client_obd_list_unlock(&cli->cl_loi_list_lock);
188         return rc;
189 }
190
191 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
192                                   unsigned long count, void *data)
193 {
194         struct obd_device *obd = data;
195         struct client_obd *cli = &obd->u.cli;
196         int                rc;
197         __u64              val;
198
199         if (obd == NULL)
200                 return 0;
201
202         rc = lprocfs_write_u64_helper(buffer, count, &val);
203         if (rc)
204                 return rc;
205
206         /* this is only for shrinking grant */
207         client_obd_list_lock(&cli->cl_loi_list_lock);
208         if (val >= cli->cl_avail_grant) {
209                 client_obd_list_unlock(&cli->cl_loi_list_lock);
210                 return 0;
211         }
212         client_obd_list_unlock(&cli->cl_loi_list_lock);
213
214         LPROCFS_CLIMP_CHECK(obd);
215         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
216                 rc = osc_shrink_grant_to_target(cli, val);
217         LPROCFS_CLIMP_EXIT(obd);
218         if (rc)
219                 return rc;
220         return count;
221 }
222
223 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
224                                        int count, int *eof, void *data)
225 {
226         struct obd_device *dev = data;
227         struct client_obd *cli = &dev->u.cli;
228         int rc;
229
230         client_obd_list_lock(&cli->cl_loi_list_lock);
231         rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
232         client_obd_list_unlock(&cli->cl_loi_list_lock);
233         return rc;
234 }
235
236 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
237                                         int count, int *eof, void *data)
238 {
239         struct obd_device *obd = data;
240
241         if (obd == NULL)
242                 return 0;
243         return snprintf(page, count, "%d\n",
244                         obd->u.cli.cl_grant_shrink_interval);
245 }
246
247 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
248                                         unsigned long count, void *data)
249 {
250         struct obd_device *obd = data;
251         int val, rc;
252
253         if (obd == NULL)
254                 return 0;
255
256         rc = lprocfs_write_helper(buffer, count, &val);
257         if (rc)
258                 return rc;
259
260         if (val <= 0)
261                 return -ERANGE;
262
263         obd->u.cli.cl_grant_shrink_interval = val;
264
265         return count;
266 }
267
268 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
269                                int *eof, void *data)
270 {
271         struct obd_device *obd = data;
272
273         if (obd == NULL)
274                 return 0;
275
276         return snprintf(page, count, "%d\n",
277                         obd->u.cli.cl_oscc.oscc_grow_count);
278 }
279
280 /**
281  * Set OSC creator's osc_creator::oscc_grow_count
282  *
283  * \param file   proc file
284  * \param buffer buffer containing the value
285  * \param count  buffer size
286  * \param data   obd device
287  *
288  * \retval \a count
289  */
290 static int osc_wr_create_count(struct file *file, const char *buffer,
291                                unsigned long count, void *data)
292 {
293         struct obd_device *obd = data;
294         int val, rc, i;
295
296         if (obd == NULL)
297                 return 0;
298
299         rc = lprocfs_write_helper(buffer, count, &val);
300         if (rc)
301                 return rc;
302
303         /* The MDT ALWAYS needs to limit the precreate count to
304          * OST_MAX_PRECREATE, and the constant cannot be changed
305          * because it is a value shared between the OSC and OST
306          * that is the maximum possible number of objects that will
307          * ever be handled by MDT->OST recovery processing.
308          *
309          * If the OST ever gets a request to delete more orphans,
310          * this implies that something has gone badly on the MDT
311          * and the OST will refuse to delete so much data from the
312          * filesystem as a safety measure. */
313         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
314                 return -ERANGE;
315         if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
316                 return -ERANGE;
317
318         for (i = 1; (i << 1) <= val; i <<= 1)
319                 ;
320         obd->u.cli.cl_oscc.oscc_grow_count = i;
321
322         return count;
323 }
324
325 /**
326  * Read OSC creator's osc_creator::oscc_max_grow_count
327  *
328  * \param page       buffer to hold the returning string
329  * \param start
330  * \param off
331  * \param count
332  * \param eof
333  *              proc read function parameters, please refer to kernel
334  *              code fs/proc/generic.c proc_file_read()
335  * \param data   obd device
336  *
337  * \retval number of characters printed.
338  */
339 static int osc_rd_max_create_count(char *page, char **start, off_t off,
340                                    int count, int *eof, void *data)
341 {
342         struct obd_device *obd = data;
343
344         if (obd == NULL)
345                 return 0;
346
347         return snprintf(page, count, "%d\n",
348                         obd->u.cli.cl_oscc.oscc_max_grow_count);
349 }
350
351 /**
352  * Set OSC creator's osc_creator::oscc_max_grow_count
353  *
354  * \param file   proc file
355  * \param buffer buffer containing the value
356  * \param count  buffer size
357  * \param data   obd device
358  *
359  * \retval \a count
360  */
361 static int osc_wr_max_create_count(struct file *file, const char *buffer,
362                                    unsigned long count, void *data)
363 {
364         struct obd_device *obd = data;
365         int val, rc;
366
367         if (obd == NULL)
368                 return 0;
369
370         rc = lprocfs_write_helper(buffer, count, &val);
371         if (rc)
372                 return rc;
373
374         if (val < 0)
375                 return -ERANGE;
376         if (val > OST_MAX_PRECREATE)
377                 return -ERANGE;
378
379         if (obd->u.cli.cl_oscc.oscc_grow_count > val)
380                 obd->u.cli.cl_oscc.oscc_grow_count = val;
381
382         obd->u.cli.cl_oscc.oscc_max_grow_count = val;
383
384         return count;
385 }
386
387 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
388                                    int count, int *eof, void *data)
389 {
390         struct obd_device *obd = data;
391
392         if (obd == NULL)
393                 return 0;
394
395         return snprintf(page, count, LPU64"\n",
396                         obd->u.cli.cl_oscc.oscc_next_id);
397 }
398
399 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
400                                    int count, int *eof, void *data)
401 {
402         struct obd_device *obd = data;
403
404         if (obd == NULL)
405                 return 0;
406
407         return snprintf(page, count, LPU64"\n",
408                         obd->u.cli.cl_oscc.oscc_last_id);
409 }
410
411 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
412                            int *eof, void *data)
413 {
414         struct obd_device *obd = data;
415
416         if (obd == NULL)
417                 return 0;
418
419         return snprintf(page, count, "%d\n",
420                         obd->u.cli.cl_checksum ? 1 : 0);
421 }
422
423 static int osc_wr_checksum(struct file *file, const char *buffer,
424                            unsigned long count, void *data)
425 {
426         struct obd_device *obd = data;
427         int val, rc;
428
429         if (obd == NULL)
430                 return 0;
431
432         rc = lprocfs_write_helper(buffer, count, &val);
433         if (rc)
434                 return rc;
435
436         obd->u.cli.cl_checksum = (val ? 1 : 0);
437
438         return count;
439 }
440
441 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
442                                 int *eof, void *data)
443 {
444         struct obd_device *obd = data;
445         int i, len =0;
446         DECLARE_CKSUM_NAME;
447
448         if (obd == NULL)
449                 return 0;
450
451         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
452                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
453                         continue;
454                 if (obd->u.cli.cl_cksum_type == (1 << i))
455                         len += snprintf(page + len, count - len, "[%s] ",
456                                         cksum_name[i]);
457                 else
458                         len += snprintf(page + len, count - len, "%s ",
459                                         cksum_name[i]);
460         }
461         if (len < count)
462                 len += sprintf(page + len, "\n");
463         return len;
464 }
465
466 static int osc_wd_checksum_type(struct file *file, const char *buffer,
467                                 unsigned long count, void *data)
468 {
469         struct obd_device *obd = data;
470         int i;
471         DECLARE_CKSUM_NAME;
472         char kernbuf[10];
473
474         if (obd == NULL)
475                 return 0;
476
477         if (count > sizeof(kernbuf) - 1)
478                 return -EINVAL;
479         if (cfs_copy_from_user(kernbuf, buffer, count))
480                 return -EFAULT;
481         if (count > 0 && kernbuf[count - 1] == '\n')
482                 kernbuf[count - 1] = '\0';
483         else
484                 kernbuf[count] = '\0';
485
486         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
487                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
488                         continue;
489                 if (!strcmp(kernbuf, cksum_name[i])) {
490                        obd->u.cli.cl_cksum_type = 1 << i;
491                        return count;
492                 }
493         }
494         return -EINVAL;
495 }
496
497 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
498                                int *eof, void *data)
499 {
500         struct obd_device *obd = data;
501
502         return snprintf(page, count, "%u\n",
503                         cfs_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         cfs_atomic_set(&obd->u.cli.cl_resends, val);
520
521         return count;
522 }
523
524 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
525                                      int count, int *eof, void *data)
526 {
527         struct obd_device *obd = data;
528         struct osc_device *od  = obd2osc_dev(obd);
529
530         return snprintf(page, count, "%u\n", od->od_contention_time);
531 }
532
533 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
534                                      unsigned long count, void *data)
535 {
536         struct obd_device *obd = data;
537         struct osc_device *od  = obd2osc_dev(obd);
538
539         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
540                 count;
541 }
542
543 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
544                                     int count, int *eof, void *data)
545 {
546         struct obd_device *obd = data;
547         struct osc_device *od  = obd2osc_dev(obd);
548
549         return snprintf(page, count, "%u\n", od->od_lockless_truncate);
550 }
551
552 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
553                                     unsigned long count, void *data)
554 {
555         struct obd_device *obd = data;
556         struct osc_device *od  = obd2osc_dev(obd);
557
558         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
559                 count;
560 }
561
562 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
563                                      int count, int *eof, void *data)
564 {
565         struct obd_device *obd = data;
566         return snprintf(page, count, "%u\n",
567                         cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
568 }
569
570 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
571         { "uuid",            lprocfs_rd_uuid,        0, 0 },
572         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
573         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
574         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
575         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
576         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
577         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
578         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
579         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
580         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
581         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
582         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
583         { "active",          osc_rd_active,
584                              osc_wr_active, 0 },
585         { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
586                                lprocfs_obd_wr_max_pages_per_rpc, 0 },
587         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
588                                 osc_wr_max_rpcs_in_flight, 0 },
589         { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
590         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
591         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
592         { "cur_grant_bytes", osc_rd_cur_grant_bytes,
593                              osc_wr_cur_grant_bytes, 0 },
594         { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
595         { "grant_shrink_interval", osc_rd_grant_shrink_interval,
596                                    osc_wr_grant_shrink_interval, 0 },
597         { "create_count",    osc_rd_create_count, osc_wr_create_count, 0 },
598         { "max_create_count", osc_rd_max_create_count,
599                               osc_wr_max_create_count, 0},
600         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
601         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
602         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
603         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
604         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
605         { "timeouts",        lprocfs_rd_timeouts,      0, 0 },
606         { "contention_seconds", osc_rd_contention_seconds,
607                                 osc_wr_contention_seconds, 0 },
608         { "lockless_truncate",  osc_rd_lockless_truncate,
609                                 osc_wr_lockless_truncate, 0 },
610         { "import",          lprocfs_rd_import,        lprocfs_wr_import, 0 },
611         { "state",           lprocfs_rd_state,         0, 0 },
612         { "pinger_recov",    lprocfs_rd_pinger_recov,
613                              lprocfs_wr_pinger_recov,  0, 0 },
614         { 0 }
615 };
616
617 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
618         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
619         { 0 }
620 };
621
622 #define pct(a,b) (b ? a * 100 / b : 0)
623
624 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
625 {
626         struct timeval now;
627         struct obd_device *dev = seq->private;
628         struct client_obd *cli = &dev->u.cli;
629         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
630         int i;
631
632         cfs_gettimeofday(&now);
633
634         client_obd_list_lock(&cli->cl_loi_list_lock);
635
636         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
637                    now.tv_sec, now.tv_usec);
638         seq_printf(seq, "read RPCs in flight:  %d\n",
639                    cli->cl_r_in_flight);
640         seq_printf(seq, "write RPCs in flight: %d\n",
641                    cli->cl_w_in_flight);
642         seq_printf(seq, "pending write pages:  %d\n",
643                    cli->cl_pending_w_pages);
644         seq_printf(seq, "pending read pages:   %d\n",
645                    cli->cl_pending_r_pages);
646
647         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
648         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
649         seq_printf(seq, "       rpcs   %% cum %%\n");
650
651         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
652         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
653
654         read_cum = 0;
655         write_cum = 0;
656         for (i = 0; i < OBD_HIST_MAX; i++) {
657                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
658                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
659                 read_cum += r;
660                 write_cum += w;
661                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
662                                  1 << i, r, pct(r, read_tot),
663                                  pct(read_cum, read_tot), w,
664                                  pct(w, write_tot),
665                                  pct(write_cum, write_tot));
666                 if (read_cum == read_tot && write_cum == write_tot)
667                         break;
668         }
669
670         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
671         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
672         seq_printf(seq, "       rpcs   %% cum %%\n");
673
674         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
675         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
676
677         read_cum = 0;
678         write_cum = 0;
679         for (i = 0; i < OBD_HIST_MAX; i++) {
680                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
681                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
682                 read_cum += r;
683                 write_cum += w;
684                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
685                                  i, r, pct(r, read_tot),
686                                  pct(read_cum, read_tot), w,
687                                  pct(w, write_tot),
688                                  pct(write_cum, write_tot));
689                 if (read_cum == read_tot && write_cum == write_tot)
690                         break;
691         }
692
693         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
694         seq_printf(seq, "offset                rpcs   %% cum %% |");
695         seq_printf(seq, "       rpcs   %% cum %%\n");
696
697         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
698         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
699
700         read_cum = 0;
701         write_cum = 0;
702         for (i = 0; i < OBD_HIST_MAX; i++) {
703                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
704                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
705                 read_cum += r;
706                 write_cum += w;
707                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
708                            (i == 0) ? 0 : 1 << (i - 1),
709                            r, pct(r, read_tot), pct(read_cum, read_tot),
710                            w, pct(w, write_tot), pct(write_cum, write_tot));
711                 if (read_cum == read_tot && write_cum == write_tot)
712                         break;
713         }
714
715         client_obd_list_unlock(&cli->cl_loi_list_lock);
716
717         return 0;
718 }
719 #undef pct
720
721 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
722                                        size_t len, loff_t *off)
723 {
724         struct seq_file *seq = file->private_data;
725         struct obd_device *dev = seq->private;
726         struct client_obd *cli = &dev->u.cli;
727
728         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
729         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
730         lprocfs_oh_clear(&cli->cl_read_page_hist);
731         lprocfs_oh_clear(&cli->cl_write_page_hist);
732         lprocfs_oh_clear(&cli->cl_read_offset_hist);
733         lprocfs_oh_clear(&cli->cl_write_offset_hist);
734
735         return len;
736 }
737
738 LPROC_SEQ_FOPS(osc_rpc_stats);
739
740 static int osc_stats_seq_show(struct seq_file *seq, void *v)
741 {
742         struct timeval now;
743         struct obd_device *dev = seq->private;
744         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
745
746         cfs_gettimeofday(&now);
747
748         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
749                    now.tv_sec, now.tv_usec);
750         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
751                    stats->os_lockless_writes);
752         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
753                    stats->os_lockless_reads);
754         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
755                    stats->os_lockless_truncates);
756         return 0;
757 }
758
759 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
760                                    size_t len, loff_t *off)
761 {
762         struct seq_file *seq = file->private_data;
763         struct obd_device *dev = seq->private;
764         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
765
766         memset(stats, 0, sizeof(*stats));
767         return len;
768 }
769
770 LPROC_SEQ_FOPS(osc_stats);
771
772 int lproc_osc_attach_seqstat(struct obd_device *dev)
773 {
774         int rc;
775
776         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0444,
777                                 &osc_stats_fops, dev);
778         if (rc == 0)
779                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
780                                             &osc_rpc_stats_fops, dev);
781         return rc;
782 }
783
784 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
785 {
786         lvars->module_vars = lprocfs_osc_module_vars;
787         lvars->obd_vars    = lprocfs_osc_obd_vars;
788 }
789 #endif /* LPROCFS */