Whamcloud - gitweb
LU-1030 osc: new IO engine implementation
[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_cur_dirty_bytes(char *page, char **start, off_t off,
164                                   int count, int *eof, void *data)
165 {
166         struct obd_device *dev = data;
167         struct client_obd *cli = &dev->u.cli;
168         int rc;
169
170         client_obd_list_lock(&cli->cl_loi_list_lock);
171         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
172         client_obd_list_unlock(&cli->cl_loi_list_lock);
173         return rc;
174 }
175
176 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
177                                   int count, int *eof, void *data)
178 {
179         struct obd_device *dev = data;
180         struct client_obd *cli = &dev->u.cli;
181         int rc;
182
183         client_obd_list_lock(&cli->cl_loi_list_lock);
184         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
185         client_obd_list_unlock(&cli->cl_loi_list_lock);
186         return rc;
187 }
188
189 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
190                                   unsigned long count, void *data)
191 {
192         struct obd_device *obd = data;
193         struct client_obd *cli = &obd->u.cli;
194         int                rc;
195         __u64              val;
196
197         if (obd == NULL)
198                 return 0;
199
200         rc = lprocfs_write_u64_helper(buffer, count, &val);
201         if (rc)
202                 return rc;
203
204         /* this is only for shrinking grant */
205         client_obd_list_lock(&cli->cl_loi_list_lock);
206         if (val >= cli->cl_avail_grant) {
207                 client_obd_list_unlock(&cli->cl_loi_list_lock);
208                 return 0;
209         }
210         client_obd_list_unlock(&cli->cl_loi_list_lock);
211
212         LPROCFS_CLIMP_CHECK(obd);
213         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
214                 rc = osc_shrink_grant_to_target(cli, val);
215         LPROCFS_CLIMP_EXIT(obd);
216         if (rc)
217                 return rc;
218         return count;
219 }
220
221 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
222                                        int count, int *eof, void *data)
223 {
224         struct obd_device *dev = data;
225         struct client_obd *cli = &dev->u.cli;
226         int rc;
227
228         client_obd_list_lock(&cli->cl_loi_list_lock);
229         rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
230         client_obd_list_unlock(&cli->cl_loi_list_lock);
231         return rc;
232 }
233
234 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
235                                         int count, int *eof, void *data)
236 {
237         struct obd_device *obd = data;
238
239         if (obd == NULL)
240                 return 0;
241         return snprintf(page, count, "%d\n",
242                         obd->u.cli.cl_grant_shrink_interval);
243 }
244
245 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
246                                         unsigned long count, void *data)
247 {
248         struct obd_device *obd = data;
249         int val, rc;
250
251         if (obd == NULL)
252                 return 0;
253
254         rc = lprocfs_write_helper(buffer, count, &val);
255         if (rc)
256                 return rc;
257
258         if (val <= 0)
259                 return -ERANGE;
260
261         obd->u.cli.cl_grant_shrink_interval = val;
262
263         return count;
264 }
265
266 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
267                                int *eof, void *data)
268 {
269         struct obd_device *obd = data;
270
271         if (obd == NULL)
272                 return 0;
273
274         return snprintf(page, count, "%d\n",
275                         obd->u.cli.cl_oscc.oscc_grow_count);
276 }
277
278 /**
279  * Set OSC creator's osc_creator::oscc_grow_count
280  *
281  * \param file   proc file
282  * \param buffer buffer containing the value
283  * \param count  buffer size
284  * \param data   obd device
285  *
286  * \retval \a count
287  */
288 static int osc_wr_create_count(struct file *file, const char *buffer,
289                                unsigned long count, void *data)
290 {
291         struct obd_device *obd = data;
292         int val, rc, i;
293
294         if (obd == NULL)
295                 return 0;
296
297         rc = lprocfs_write_helper(buffer, count, &val);
298         if (rc)
299                 return rc;
300
301         /* The MDT ALWAYS needs to limit the precreate count to
302          * OST_MAX_PRECREATE, and the constant cannot be changed
303          * because it is a value shared between the OSC and OST
304          * that is the maximum possible number of objects that will
305          * ever be handled by MDT->OST recovery processing.
306          *
307          * If the OST ever gets a request to delete more orphans,
308          * this implies that something has gone badly on the MDT
309          * and the OST will refuse to delete so much data from the
310          * filesystem as a safety measure. */
311         if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
312                 return -ERANGE;
313         if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
314                 return -ERANGE;
315
316         for (i = 1; (i << 1) <= val; i <<= 1)
317                 ;
318         obd->u.cli.cl_oscc.oscc_grow_count = i;
319
320         return count;
321 }
322
323 /**
324  * Read OSC creator's osc_creator::oscc_max_grow_count
325  *
326  * \param page       buffer to hold the returning string
327  * \param start
328  * \param off
329  * \param count
330  * \param eof
331  *              proc read function parameters, please refer to kernel
332  *              code fs/proc/generic.c proc_file_read()
333  * \param data   obd device
334  *
335  * \retval number of characters printed.
336  */
337 static int osc_rd_max_create_count(char *page, char **start, off_t off,
338                                    int count, int *eof, void *data)
339 {
340         struct obd_device *obd = data;
341
342         if (obd == NULL)
343                 return 0;
344
345         return snprintf(page, count, "%d\n",
346                         obd->u.cli.cl_oscc.oscc_max_grow_count);
347 }
348
349 /**
350  * Set OSC creator's osc_creator::oscc_max_grow_count
351  *
352  * \param file   proc file
353  * \param buffer buffer containing the value
354  * \param count  buffer size
355  * \param data   obd device
356  *
357  * \retval \a count
358  */
359 static int osc_wr_max_create_count(struct file *file, const char *buffer,
360                                    unsigned long count, void *data)
361 {
362         struct obd_device *obd = data;
363         int val, rc;
364
365         if (obd == NULL)
366                 return 0;
367
368         rc = lprocfs_write_helper(buffer, count, &val);
369         if (rc)
370                 return rc;
371
372         if (val < 0)
373                 return -ERANGE;
374         if (val > OST_MAX_PRECREATE)
375                 return -ERANGE;
376
377         if (obd->u.cli.cl_oscc.oscc_grow_count > val)
378                 obd->u.cli.cl_oscc.oscc_grow_count = val;
379
380         obd->u.cli.cl_oscc.oscc_max_grow_count = val;
381
382         return count;
383 }
384
385 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
386                                    int count, int *eof, void *data)
387 {
388         struct obd_device *obd = data;
389
390         if (obd == NULL)
391                 return 0;
392
393         return snprintf(page, count, LPU64"\n",
394                         obd->u.cli.cl_oscc.oscc_next_id);
395 }
396
397 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
398                                    int count, int *eof, void *data)
399 {
400         struct obd_device *obd = data;
401
402         if (obd == NULL)
403                 return 0;
404
405         return snprintf(page, count, LPU64"\n",
406                         obd->u.cli.cl_oscc.oscc_last_id);
407 }
408
409 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
410                            int *eof, void *data)
411 {
412         struct obd_device *obd = data;
413
414         if (obd == NULL)
415                 return 0;
416
417         return snprintf(page, count, "%d\n",
418                         obd->u.cli.cl_checksum ? 1 : 0);
419 }
420
421 static int osc_wr_checksum(struct file *file, const char *buffer,
422                            unsigned long count, void *data)
423 {
424         struct obd_device *obd = data;
425         int val, rc;
426
427         if (obd == NULL)
428                 return 0;
429
430         rc = lprocfs_write_helper(buffer, count, &val);
431         if (rc)
432                 return rc;
433
434         obd->u.cli.cl_checksum = (val ? 1 : 0);
435
436         return count;
437 }
438
439 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
440                                 int *eof, void *data)
441 {
442         struct obd_device *obd = data;
443         int i, len =0;
444         DECLARE_CKSUM_NAME;
445
446         if (obd == NULL)
447                 return 0;
448
449         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
450                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
451                         continue;
452                 if (obd->u.cli.cl_cksum_type == (1 << i))
453                         len += snprintf(page + len, count - len, "[%s] ",
454                                         cksum_name[i]);
455                 else
456                         len += snprintf(page + len, count - len, "%s ",
457                                         cksum_name[i]);
458         }
459         if (len < count)
460                 len += sprintf(page + len, "\n");
461         return len;
462 }
463
464 static int osc_wd_checksum_type(struct file *file, const char *buffer,
465                                 unsigned long count, void *data)
466 {
467         struct obd_device *obd = data;
468         int i;
469         DECLARE_CKSUM_NAME;
470         char kernbuf[10];
471
472         if (obd == NULL)
473                 return 0;
474
475         if (count > sizeof(kernbuf) - 1)
476                 return -EINVAL;
477         if (cfs_copy_from_user(kernbuf, buffer, count))
478                 return -EFAULT;
479         if (count > 0 && kernbuf[count - 1] == '\n')
480                 kernbuf[count - 1] = '\0';
481         else
482                 kernbuf[count] = '\0';
483
484         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
485                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
486                         continue;
487                 if (!strcmp(kernbuf, cksum_name[i])) {
488                        obd->u.cli.cl_cksum_type = 1 << i;
489                        return count;
490                 }
491         }
492         return -EINVAL;
493 }
494
495 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
496                                int *eof, void *data)
497 {
498         struct obd_device *obd = data;
499
500         return snprintf(page, count, "%u\n",
501                         cfs_atomic_read(&obd->u.cli.cl_resends));
502 }
503
504 static int osc_wr_resend_count(struct file *file, const char *buffer,
505                                unsigned long count, void *data)
506 {
507         struct obd_device *obd = data;
508         int val, rc;
509
510         rc = lprocfs_write_helper(buffer, count, &val);
511         if (rc)
512                 return rc;
513
514         if (val < 0)
515                return -EINVAL;
516
517         cfs_atomic_set(&obd->u.cli.cl_resends, val);
518
519         return count;
520 }
521
522 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
523                                      int count, int *eof, void *data)
524 {
525         struct obd_device *obd = data;
526         struct osc_device *od  = obd2osc_dev(obd);
527
528         return snprintf(page, count, "%u\n", od->od_contention_time);
529 }
530
531 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
532                                      unsigned long count, void *data)
533 {
534         struct obd_device *obd = data;
535         struct osc_device *od  = obd2osc_dev(obd);
536
537         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
538                 count;
539 }
540
541 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
542                                     int count, int *eof, void *data)
543 {
544         struct obd_device *obd = data;
545         struct osc_device *od  = obd2osc_dev(obd);
546
547         return snprintf(page, count, "%u\n", od->od_lockless_truncate);
548 }
549
550 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
551                                     unsigned long count, void *data)
552 {
553         struct obd_device *obd = data;
554         struct osc_device *od  = obd2osc_dev(obd);
555
556         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
557                 count;
558 }
559
560 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
561                                      int count, int *eof, void *data)
562 {
563         struct obd_device *obd = data;
564         return snprintf(page, count, "%u\n",
565                         cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
566 }
567
568 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
569         const char *buffer, unsigned long count, void *data)
570 {
571         struct obd_device *dev = data;
572         struct client_obd *cli = &dev->u.cli;
573         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
574         int chunk_mask, val, rc;
575
576         rc = lprocfs_write_helper(buffer, count, &val);
577         if (rc)
578                 return rc;
579
580         LPROCFS_CLIMP_CHECK(dev);
581
582         chunk_mask = ~((1 << (cli->cl_chunkbits - CFS_PAGE_SHIFT)) - 1);
583         /* max_pages_per_rpc must be chunk aligned */
584         val = (val + ~chunk_mask) & chunk_mask;
585         if (val == 0 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
586                 LPROCFS_CLIMP_EXIT(dev);
587                 return -ERANGE;
588         }
589         client_obd_list_lock(&cli->cl_loi_list_lock);
590         cli->cl_max_pages_per_rpc = val;
591         client_obd_list_unlock(&cli->cl_loi_list_lock);
592
593         LPROCFS_CLIMP_EXIT(dev);
594         return count;
595 }
596
597 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
598         { "uuid",            lprocfs_rd_uuid,        0, 0 },
599         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
600         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
601         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
602         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
603         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
604         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
605         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
606         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
607         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
608         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
609         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
610         { "active",          osc_rd_active,
611                              osc_wr_active, 0 },
612         { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
613                                lprocfs_osc_wr_max_pages_per_rpc, 0 },
614         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
615                                 osc_wr_max_rpcs_in_flight, 0 },
616         { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
617         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
618         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
619         { "cur_grant_bytes", osc_rd_cur_grant_bytes,
620                              osc_wr_cur_grant_bytes, 0 },
621         { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
622         { "grant_shrink_interval", osc_rd_grant_shrink_interval,
623                                    osc_wr_grant_shrink_interval, 0 },
624         { "create_count",    osc_rd_create_count, osc_wr_create_count, 0 },
625         { "max_create_count", osc_rd_max_create_count,
626                               osc_wr_max_create_count, 0},
627         { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
628         { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
629         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
630         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
631         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
632         { "timeouts",        lprocfs_rd_timeouts,      0, 0 },
633         { "contention_seconds", osc_rd_contention_seconds,
634                                 osc_wr_contention_seconds, 0 },
635         { "lockless_truncate",  osc_rd_lockless_truncate,
636                                 osc_wr_lockless_truncate, 0 },
637         { "import",          lprocfs_rd_import,        lprocfs_wr_import, 0 },
638         { "state",           lprocfs_rd_state,         0, 0 },
639         { "pinger_recov",    lprocfs_rd_pinger_recov,
640                              lprocfs_wr_pinger_recov,  0, 0 },
641         { 0 }
642 };
643
644 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
645         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
646         { 0 }
647 };
648
649 #define pct(a,b) (b ? a * 100 / b : 0)
650
651 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
652 {
653         struct timeval now;
654         struct obd_device *dev = seq->private;
655         struct client_obd *cli = &dev->u.cli;
656         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
657         int i;
658
659         cfs_gettimeofday(&now);
660
661         client_obd_list_lock(&cli->cl_loi_list_lock);
662
663         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
664                    now.tv_sec, now.tv_usec);
665         seq_printf(seq, "read RPCs in flight:  %d\n",
666                    cli->cl_r_in_flight);
667         seq_printf(seq, "write RPCs in flight: %d\n",
668                    cli->cl_w_in_flight);
669         seq_printf(seq, "pending write pages:  %d\n",
670                    cfs_atomic_read(&cli->cl_pending_w_pages));
671         seq_printf(seq, "pending read pages:   %d\n",
672                    cfs_atomic_read(&cli->cl_pending_r_pages));
673
674         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
675         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
676         seq_printf(seq, "       rpcs   %% cum %%\n");
677
678         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
679         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
680
681         read_cum = 0;
682         write_cum = 0;
683         for (i = 0; i < OBD_HIST_MAX; i++) {
684                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
685                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
686                 read_cum += r;
687                 write_cum += w;
688                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
689                                  1 << i, r, pct(r, read_tot),
690                                  pct(read_cum, read_tot), w,
691                                  pct(w, write_tot),
692                                  pct(write_cum, write_tot));
693                 if (read_cum == read_tot && write_cum == write_tot)
694                         break;
695         }
696
697         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
698         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
699         seq_printf(seq, "       rpcs   %% cum %%\n");
700
701         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
702         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
703
704         read_cum = 0;
705         write_cum = 0;
706         for (i = 0; i < OBD_HIST_MAX; i++) {
707                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
708                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
709                 read_cum += r;
710                 write_cum += w;
711                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
712                                  i, r, pct(r, read_tot),
713                                  pct(read_cum, read_tot), w,
714                                  pct(w, write_tot),
715                                  pct(write_cum, write_tot));
716                 if (read_cum == read_tot && write_cum == write_tot)
717                         break;
718         }
719
720         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
721         seq_printf(seq, "offset                rpcs   %% cum %% |");
722         seq_printf(seq, "       rpcs   %% cum %%\n");
723
724         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
725         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
726
727         read_cum = 0;
728         write_cum = 0;
729         for (i = 0; i < OBD_HIST_MAX; i++) {
730                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
731                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
732                 read_cum += r;
733                 write_cum += w;
734                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
735                            (i == 0) ? 0 : 1 << (i - 1),
736                            r, pct(r, read_tot), pct(read_cum, read_tot),
737                            w, pct(w, write_tot), pct(write_cum, write_tot));
738                 if (read_cum == read_tot && write_cum == write_tot)
739                         break;
740         }
741
742         client_obd_list_unlock(&cli->cl_loi_list_lock);
743
744         return 0;
745 }
746 #undef pct
747
748 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
749                                        size_t len, loff_t *off)
750 {
751         struct seq_file *seq = file->private_data;
752         struct obd_device *dev = seq->private;
753         struct client_obd *cli = &dev->u.cli;
754
755         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
756         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
757         lprocfs_oh_clear(&cli->cl_read_page_hist);
758         lprocfs_oh_clear(&cli->cl_write_page_hist);
759         lprocfs_oh_clear(&cli->cl_read_offset_hist);
760         lprocfs_oh_clear(&cli->cl_write_offset_hist);
761
762         return len;
763 }
764
765 LPROC_SEQ_FOPS(osc_rpc_stats);
766
767 static int osc_stats_seq_show(struct seq_file *seq, void *v)
768 {
769         struct timeval now;
770         struct obd_device *dev = seq->private;
771         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
772
773         cfs_gettimeofday(&now);
774
775         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
776                    now.tv_sec, now.tv_usec);
777         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
778                    stats->os_lockless_writes);
779         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
780                    stats->os_lockless_reads);
781         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
782                    stats->os_lockless_truncates);
783         return 0;
784 }
785
786 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
787                                    size_t len, loff_t *off)
788 {
789         struct seq_file *seq = file->private_data;
790         struct obd_device *dev = seq->private;
791         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
792
793         memset(stats, 0, sizeof(*stats));
794         return len;
795 }
796
797 LPROC_SEQ_FOPS(osc_stats);
798
799 int lproc_osc_attach_seqstat(struct obd_device *dev)
800 {
801         int rc;
802
803         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0444,
804                                 &osc_stats_fops, dev);
805         if (rc == 0)
806                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
807                                             &osc_rpc_stats_fops, dev);
808         return rc;
809 }
810
811 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
812 {
813         lvars->module_vars = lprocfs_osc_module_vars;
814         lvars->obd_vars    = lprocfs_osc_obd_vars;
815 }
816 #endif /* LPROCFS */