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