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