Whamcloud - gitweb
LU-2012 tests: disable replay-dual test_14b
[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, Whamcloud, Inc.
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_create_count(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_oscc.oscc_grow_count);
318 }
319
320 /**
321  * Set OSC creator's osc_creator::oscc_grow_count
322  *
323  * \param file   proc file
324  * \param buffer buffer containing the value
325  * \param count  buffer size
326  * \param data   obd device
327  *
328  * \retval \a count
329  */
330 static int osc_wr_create_count(struct file *file, const char *buffer,
331                                unsigned long count, void *data)
332 {
333         struct obd_device *obd = data;
334         int val, rc, i;
335
336         if (obd == NULL)
337                 return 0;
338
339         rc = lprocfs_write_helper(buffer, count, &val);
340         if (rc)
341                 return rc;
342
343         /* The MDT ALWAYS needs to limit the precreate count to
344          * OST_MAX_PRECREATE, and the constant cannot be changed
345          * because it is a value shared between the OSC and OST
346          * that is the maximum possible number of objects that will
347          * ever be handled by MDT->OST recovery processing.
348          *
349          * If the OST ever gets a request to delete more orphans,
350          * this implies that something has gone badly on the MDT
351          * and the OST will refuse to delete so much data from the
352          * filesystem as a safety measure. */
353         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
354                 return -ERANGE;
355         if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
356                 return -ERANGE;
357
358         for (i = 1; (i << 1) <= val; i <<= 1)
359                 ;
360         obd->u.cli.cl_oscc.oscc_grow_count = i;
361
362         return count;
363 }
364
365 /**
366  * Read OSC creator's osc_creator::oscc_max_grow_count
367  *
368  * \param page       buffer to hold the returning string
369  * \param start
370  * \param off
371  * \param count
372  * \param eof
373  *              proc read function parameters, please refer to kernel
374  *              code fs/proc/generic.c proc_file_read()
375  * \param data   obd device
376  *
377  * \retval number of characters printed.
378  */
379 static int osc_rd_max_create_count(char *page, char **start, off_t off,
380                                    int count, int *eof, void *data)
381 {
382         struct obd_device *obd = data;
383
384         if (obd == NULL)
385                 return 0;
386
387         return snprintf(page, count, "%d\n",
388                         obd->u.cli.cl_oscc.oscc_max_grow_count);
389 }
390
391 /**
392  * Set OSC creator's osc_creator::oscc_max_grow_count
393  *
394  * \param file   proc file
395  * \param buffer buffer containing the value
396  * \param count  buffer size
397  * \param data   obd device
398  *
399  * \retval \a count
400  */
401 static int osc_wr_max_create_count(struct file *file, const char *buffer,
402                                    unsigned long count, void *data)
403 {
404         struct obd_device *obd = data;
405         int val, rc;
406
407         if (obd == NULL)
408                 return 0;
409
410         rc = lprocfs_write_helper(buffer, count, &val);
411         if (rc)
412                 return rc;
413
414         if (val < 0)
415                 return -ERANGE;
416         if (val > OST_MAX_PRECREATE)
417                 return -ERANGE;
418
419         if (obd->u.cli.cl_oscc.oscc_grow_count > val)
420                 obd->u.cli.cl_oscc.oscc_grow_count = val;
421
422         obd->u.cli.cl_oscc.oscc_max_grow_count = val;
423
424         return count;
425 }
426
427 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
428                                    int count, int *eof, void *data)
429 {
430         struct obd_device *obd = data;
431
432         if (obd == NULL)
433                 return 0;
434
435         return snprintf(page, count, LPU64"\n",
436                         obd->u.cli.cl_oscc.oscc_next_id);
437 }
438
439 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
440                                    int count, int *eof, void *data)
441 {
442         struct obd_device *obd = data;
443
444         if (obd == NULL)
445                 return 0;
446
447         return snprintf(page, count, LPU64"\n",
448                         obd->u.cli.cl_oscc.oscc_last_id);
449 }
450
451 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
452                            int *eof, void *data)
453 {
454         struct obd_device *obd = data;
455
456         if (obd == NULL)
457                 return 0;
458
459         return snprintf(page, count, "%d\n",
460                         obd->u.cli.cl_checksum ? 1 : 0);
461 }
462
463 static int osc_wr_checksum(struct file *file, const char *buffer,
464                            unsigned long count, void *data)
465 {
466         struct obd_device *obd = data;
467         int val, rc;
468
469         if (obd == NULL)
470                 return 0;
471
472         rc = lprocfs_write_helper(buffer, count, &val);
473         if (rc)
474                 return rc;
475
476         obd->u.cli.cl_checksum = (val ? 1 : 0);
477
478         return count;
479 }
480
481 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
482                                 int *eof, void *data)
483 {
484         struct obd_device *obd = data;
485         int i, len =0;
486         DECLARE_CKSUM_NAME;
487
488         if (obd == NULL)
489                 return 0;
490
491         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
492                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
493                         continue;
494                 if (obd->u.cli.cl_cksum_type == (1 << i))
495                         len += snprintf(page + len, count - len, "[%s] ",
496                                         cksum_name[i]);
497                 else
498                         len += snprintf(page + len, count - len, "%s ",
499                                         cksum_name[i]);
500         }
501         if (len < count)
502                 len += sprintf(page + len, "\n");
503         return len;
504 }
505
506 static int osc_wd_checksum_type(struct file *file, const char *buffer,
507                                 unsigned long count, void *data)
508 {
509         struct obd_device *obd = data;
510         int i;
511         DECLARE_CKSUM_NAME;
512         char kernbuf[10];
513
514         if (obd == NULL)
515                 return 0;
516
517         if (count > sizeof(kernbuf) - 1)
518                 return -EINVAL;
519         if (cfs_copy_from_user(kernbuf, buffer, count))
520                 return -EFAULT;
521         if (count > 0 && kernbuf[count - 1] == '\n')
522                 kernbuf[count - 1] = '\0';
523         else
524                 kernbuf[count] = '\0';
525
526         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
527                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
528                         continue;
529                 if (!strcmp(kernbuf, cksum_name[i])) {
530                        obd->u.cli.cl_cksum_type = 1 << i;
531                        return count;
532                 }
533         }
534         return -EINVAL;
535 }
536
537 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
538                                int *eof, void *data)
539 {
540         struct obd_device *obd = data;
541
542         return snprintf(page, count, "%u\n",
543                         cfs_atomic_read(&obd->u.cli.cl_resends));
544 }
545
546 static int osc_wr_resend_count(struct file *file, const char *buffer,
547                                unsigned long count, void *data)
548 {
549         struct obd_device *obd = data;
550         int val, rc;
551
552         rc = lprocfs_write_helper(buffer, count, &val);
553         if (rc)
554                 return rc;
555
556         if (val < 0)
557                return -EINVAL;
558
559         cfs_atomic_set(&obd->u.cli.cl_resends, val);
560
561         return count;
562 }
563
564 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
565                                      int count, int *eof, void *data)
566 {
567         struct obd_device *obd = data;
568         struct osc_device *od  = obd2osc_dev(obd);
569
570         return snprintf(page, count, "%u\n", od->od_contention_time);
571 }
572
573 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
574                                      unsigned long count, void *data)
575 {
576         struct obd_device *obd = data;
577         struct osc_device *od  = obd2osc_dev(obd);
578
579         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
580                 count;
581 }
582
583 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
584                                     int count, int *eof, void *data)
585 {
586         struct obd_device *obd = data;
587         struct osc_device *od  = obd2osc_dev(obd);
588
589         return snprintf(page, count, "%u\n", od->od_lockless_truncate);
590 }
591
592 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
593                                     unsigned long count, void *data)
594 {
595         struct obd_device *obd = data;
596         struct osc_device *od  = obd2osc_dev(obd);
597
598         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
599                 count;
600 }
601
602 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
603                                      int count, int *eof, void *data)
604 {
605         struct obd_device *obd = data;
606         return snprintf(page, count, "%u\n",
607                         cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
608 }
609
610 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
611         const char *buffer, unsigned long count, void *data)
612 {
613         struct obd_device *dev = data;
614         struct client_obd *cli = &dev->u.cli;
615         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
616         int chunk_mask, val, rc;
617
618         rc = lprocfs_write_helper(buffer, count, &val);
619         if (rc)
620                 return rc;
621
622         LPROCFS_CLIMP_CHECK(dev);
623
624         chunk_mask = ~((1 << (cli->cl_chunkbits - CFS_PAGE_SHIFT)) - 1);
625         /* max_pages_per_rpc must be chunk aligned */
626         val = (val + ~chunk_mask) & chunk_mask;
627         if (val == 0 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
628                 LPROCFS_CLIMP_EXIT(dev);
629                 return -ERANGE;
630         }
631         client_obd_list_lock(&cli->cl_loi_list_lock);
632         cli->cl_max_pages_per_rpc = val;
633         client_obd_list_unlock(&cli->cl_loi_list_lock);
634
635         LPROCFS_CLIMP_EXIT(dev);
636         return count;
637 }
638
639 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
640         { "uuid",            lprocfs_rd_uuid,        0, 0 },
641         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
642         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
643         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
644         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
645         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
646         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
647         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
648         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
649         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
650         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
651         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
652         { "active",          osc_rd_active,
653                              osc_wr_active, 0 },
654         { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
655                                lprocfs_osc_wr_max_pages_per_rpc, 0 },
656         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
657                                 osc_wr_max_rpcs_in_flight, 0 },
658         { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
659         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
660         { "osc_cached_mb",   osc_rd_cached_mb,     osc_wr_cached_mb, 0 },
661         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
662         { "cur_grant_bytes", osc_rd_cur_grant_bytes,
663                              osc_wr_cur_grant_bytes, 0 },
664         { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
665         { "grant_shrink_interval", osc_rd_grant_shrink_interval,
666                                    osc_wr_grant_shrink_interval, 0 },
667         { "create_count",    osc_rd_create_count, osc_wr_create_count, 0 },
668         { "max_create_count", osc_rd_max_create_count,
669                               osc_wr_max_create_count, 0},
670         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
671         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
672         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
673         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
674         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
675         { "timeouts",        lprocfs_rd_timeouts,      0, 0 },
676         { "contention_seconds", osc_rd_contention_seconds,
677                                 osc_wr_contention_seconds, 0 },
678         { "lockless_truncate",  osc_rd_lockless_truncate,
679                                 osc_wr_lockless_truncate, 0 },
680         { "import",          lprocfs_rd_import,        lprocfs_wr_import, 0 },
681         { "state",           lprocfs_rd_state,         0, 0 },
682         { "pinger_recov",    lprocfs_rd_pinger_recov,
683                              lprocfs_wr_pinger_recov,  0, 0 },
684         { 0 }
685 };
686
687 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
688         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
689         { 0 }
690 };
691
692 #define pct(a,b) (b ? a * 100 / b : 0)
693
694 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
695 {
696         struct timeval now;
697         struct obd_device *dev = seq->private;
698         struct client_obd *cli = &dev->u.cli;
699         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
700         int i;
701
702         cfs_gettimeofday(&now);
703
704         client_obd_list_lock(&cli->cl_loi_list_lock);
705
706         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
707                    now.tv_sec, now.tv_usec);
708         seq_printf(seq, "read RPCs in flight:  %d\n",
709                    cli->cl_r_in_flight);
710         seq_printf(seq, "write RPCs in flight: %d\n",
711                    cli->cl_w_in_flight);
712         seq_printf(seq, "pending write pages:  %d\n",
713                    cfs_atomic_read(&cli->cl_pending_w_pages));
714         seq_printf(seq, "pending read pages:   %d\n",
715                    cfs_atomic_read(&cli->cl_pending_r_pages));
716
717         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
718         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
719         seq_printf(seq, "       rpcs   %% cum %%\n");
720
721         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
722         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
723
724         read_cum = 0;
725         write_cum = 0;
726         for (i = 0; i < OBD_HIST_MAX; i++) {
727                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
728                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
729                 read_cum += r;
730                 write_cum += w;
731                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
732                                  1 << i, r, pct(r, read_tot),
733                                  pct(read_cum, read_tot), w,
734                                  pct(w, write_tot),
735                                  pct(write_cum, write_tot));
736                 if (read_cum == read_tot && write_cum == write_tot)
737                         break;
738         }
739
740         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
741         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
742         seq_printf(seq, "       rpcs   %% cum %%\n");
743
744         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
745         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
746
747         read_cum = 0;
748         write_cum = 0;
749         for (i = 0; i < OBD_HIST_MAX; i++) {
750                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
751                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
752                 read_cum += r;
753                 write_cum += w;
754                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
755                                  i, r, pct(r, read_tot),
756                                  pct(read_cum, read_tot), w,
757                                  pct(w, write_tot),
758                                  pct(write_cum, write_tot));
759                 if (read_cum == read_tot && write_cum == write_tot)
760                         break;
761         }
762
763         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
764         seq_printf(seq, "offset                rpcs   %% cum %% |");
765         seq_printf(seq, "       rpcs   %% cum %%\n");
766
767         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
768         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
769
770         read_cum = 0;
771         write_cum = 0;
772         for (i = 0; i < OBD_HIST_MAX; i++) {
773                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
774                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
775                 read_cum += r;
776                 write_cum += w;
777                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
778                            (i == 0) ? 0 : 1 << (i - 1),
779                            r, pct(r, read_tot), pct(read_cum, read_tot),
780                            w, pct(w, write_tot), pct(write_cum, write_tot));
781                 if (read_cum == read_tot && write_cum == write_tot)
782                         break;
783         }
784
785         client_obd_list_unlock(&cli->cl_loi_list_lock);
786
787         return 0;
788 }
789 #undef pct
790
791 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
792                                        size_t len, loff_t *off)
793 {
794         struct seq_file *seq = file->private_data;
795         struct obd_device *dev = seq->private;
796         struct client_obd *cli = &dev->u.cli;
797
798         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
799         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
800         lprocfs_oh_clear(&cli->cl_read_page_hist);
801         lprocfs_oh_clear(&cli->cl_write_page_hist);
802         lprocfs_oh_clear(&cli->cl_read_offset_hist);
803         lprocfs_oh_clear(&cli->cl_write_offset_hist);
804
805         return len;
806 }
807
808 LPROC_SEQ_FOPS(osc_rpc_stats);
809
810 static int osc_stats_seq_show(struct seq_file *seq, void *v)
811 {
812         struct timeval now;
813         struct obd_device *dev = seq->private;
814         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
815
816         cfs_gettimeofday(&now);
817
818         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
819                    now.tv_sec, now.tv_usec);
820         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
821                    stats->os_lockless_writes);
822         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
823                    stats->os_lockless_reads);
824         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
825                    stats->os_lockless_truncates);
826         return 0;
827 }
828
829 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
830                                    size_t len, loff_t *off)
831 {
832         struct seq_file *seq = file->private_data;
833         struct obd_device *dev = seq->private;
834         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
835
836         memset(stats, 0, sizeof(*stats));
837         return len;
838 }
839
840 LPROC_SEQ_FOPS(osc_stats);
841
842 int lproc_osc_attach_seqstat(struct obd_device *dev)
843 {
844         int rc;
845
846         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0444,
847                                 &osc_stats_fops, dev);
848         if (rc == 0)
849                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
850                                             &osc_rpc_stats_fops, dev);
851         return rc;
852 }
853
854 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
855 {
856         lvars->module_vars = lprocfs_osc_module_vars;
857         lvars->obd_vars    = lprocfs_osc_obd_vars;
858 }
859 #endif /* LPROCFS */