Whamcloud - gitweb
2f8da8c6114674b717204fc81449cec814284f5a
[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, 2013, Intel Corporation.
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_active_seq_show(struct seq_file *m, void *v)
48 {
49         struct obd_device *dev = m->private;
50         int rc;
51
52         LPROCFS_CLIMP_CHECK(dev);
53         rc = seq_printf(m, "%d\n", !dev->u.cli.cl_import->imp_deactive);
54         LPROCFS_CLIMP_EXIT(dev);
55         return rc;
56 }
57
58 static ssize_t osc_active_seq_write(struct file *file, const char *buffer,
59                                     size_t count, loff_t *off)
60 {
61         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
62         int val, rc;
63
64         rc = lprocfs_write_helper(buffer, count, &val);
65         if (rc)
66                 return rc;
67         if (val < 0 || val > 1)
68                 return -ERANGE;
69
70         /* opposite senses */
71         if (dev->u.cli.cl_import->imp_deactive == val)
72                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
73         else
74                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
75
76         return count;
77 }
78 LPROC_SEQ_FOPS(osc_active);
79
80 static int osc_max_rpcs_in_flight_seq_show(struct seq_file *m, void *v)
81 {
82         struct obd_device *dev = m->private;
83         struct client_obd *cli = &dev->u.cli;
84         int rc;
85
86         client_obd_list_lock(&cli->cl_loi_list_lock);
87         rc = seq_printf(m, "%u\n", cli->cl_max_rpcs_in_flight);
88         client_obd_list_unlock(&cli->cl_loi_list_lock);
89         return rc;
90 }
91
92 static ssize_t osc_max_rpcs_in_flight_seq_write(struct file *file,
93                                                 const char *buffer,
94                                                 size_t count, loff_t *off)
95 {
96         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
97         struct client_obd *cli = &dev->u.cli;
98         struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
99         int val, rc;
100
101         rc = lprocfs_write_helper(buffer, count, &val);
102         if (rc)
103                 return rc;
104
105         if (val < 1 || val > OSC_MAX_RIF_MAX)
106                 return -ERANGE;
107
108         LPROCFS_CLIMP_CHECK(dev);
109         if (pool && val > cli->cl_max_rpcs_in_flight)
110                 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
111
112         client_obd_list_lock(&cli->cl_loi_list_lock);
113         cli->cl_max_rpcs_in_flight = val;
114         client_obd_list_unlock(&cli->cl_loi_list_lock);
115
116         LPROCFS_CLIMP_EXIT(dev);
117         return count;
118 }
119 LPROC_SEQ_FOPS(osc_max_rpcs_in_flight);
120
121 static int osc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
122 {
123         struct obd_device *dev = m->private;
124         struct client_obd *cli = &dev->u.cli;
125         long val;
126         int mult;
127
128         client_obd_list_lock(&cli->cl_loi_list_lock);
129         val = cli->cl_dirty_max;
130         client_obd_list_unlock(&cli->cl_loi_list_lock);
131
132         mult = 1 << 20;
133         return lprocfs_seq_read_frac_helper(m, val, mult);
134 }
135
136 static ssize_t osc_max_dirty_mb_seq_write(struct file *file, const char *buffer,
137                                           size_t count, loff_t *off)
138 {
139         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
140         struct client_obd *cli = &dev->u.cli;
141         int pages_number, mult, rc;
142
143         mult = 1 << (20 - PAGE_CACHE_SHIFT);
144         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
145         if (rc)
146                 return rc;
147
148         if (pages_number <= 0 ||
149             pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_CACHE_SHIFT) ||
150             pages_number > totalram_pages / 4) /* 1/4 of RAM */
151                 return -ERANGE;
152
153         client_obd_list_lock(&cli->cl_loi_list_lock);
154         cli->cl_dirty_max = (obd_count)(pages_number << PAGE_CACHE_SHIFT);
155         osc_wake_cache_waiters(cli);
156         client_obd_list_unlock(&cli->cl_loi_list_lock);
157
158         return count;
159 }
160 LPROC_SEQ_FOPS(osc_max_dirty_mb);
161
162 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
163 {
164         struct obd_device *dev = m->private;
165         struct client_obd *cli = &dev->u.cli;
166         int shift = 20 - PAGE_CACHE_SHIFT;
167         int rc;
168
169         rc = seq_printf(m,
170                       "used_mb: %d\n"
171                       "busy_cnt: %d\n",
172                       (atomic_read(&cli->cl_lru_in_list) +
173                         atomic_read(&cli->cl_lru_busy)) >> shift,
174                       atomic_read(&cli->cl_lru_busy));
175
176         return rc;
177 }
178
179 /* shrink the number of caching pages to a specific number */
180 static ssize_t
181 osc_cached_mb_seq_write(struct file *file, const char __user *buffer,
182                         size_t count, loff_t *off)
183 {
184         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
185         struct client_obd *cli = &dev->u.cli;
186         int pages_number, mult, rc;
187         char kernbuf[128];
188
189         if (count >= sizeof(kernbuf))
190                 return -EINVAL;
191
192         if (copy_from_user(kernbuf, buffer, count))
193                 return -EFAULT;
194         kernbuf[count] = 0;
195
196         mult = 1 << (20 - PAGE_CACHE_SHIFT);
197         buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
198                   kernbuf;
199         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
200         if (rc)
201                 return rc;
202
203         if (pages_number < 0)
204                 return -ERANGE;
205
206         rc = atomic_read(&cli->cl_lru_in_list) - pages_number;
207         if (rc > 0) {
208                 struct lu_env *env;
209                 int refcheck;
210
211                 env = cl_env_get(&refcheck);
212                 if (!IS_ERR(env)) {
213                         (void)osc_lru_shrink(env, cli, rc, true);
214                         cl_env_put(env, &refcheck);
215                 }
216         }
217
218         return count;
219 }
220 LPROC_SEQ_FOPS(osc_cached_mb);
221
222 static int osc_cur_dirty_bytes_seq_show(struct seq_file *m, void *v)
223 {
224         struct obd_device *dev = m->private;
225         struct client_obd *cli = &dev->u.cli;
226         int rc;
227
228         client_obd_list_lock(&cli->cl_loi_list_lock);
229         rc = seq_printf(m, "%lu\n", cli->cl_dirty);
230         client_obd_list_unlock(&cli->cl_loi_list_lock);
231         return rc;
232 }
233 LPROC_SEQ_FOPS_RO(osc_cur_dirty_bytes);
234
235 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
236 {
237         struct obd_device *dev = m->private;
238         struct client_obd *cli = &dev->u.cli;
239         int rc;
240
241         client_obd_list_lock(&cli->cl_loi_list_lock);
242         rc = seq_printf(m, "%lu\n", cli->cl_avail_grant);
243         client_obd_list_unlock(&cli->cl_loi_list_lock);
244         return rc;
245 }
246
247 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file, const char *buffer,
248                                              size_t count, loff_t *off)
249 {
250         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
251         struct client_obd *cli = &obd->u.cli;
252         int                rc;
253         __u64              val;
254
255         if (obd == NULL)
256                 return 0;
257
258         rc = lprocfs_write_u64_helper(buffer, count, &val);
259         if (rc)
260                 return rc;
261
262         /* this is only for shrinking grant */
263         client_obd_list_lock(&cli->cl_loi_list_lock);
264         if (val >= cli->cl_avail_grant) {
265                 client_obd_list_unlock(&cli->cl_loi_list_lock);
266                 return 0;
267         }
268         client_obd_list_unlock(&cli->cl_loi_list_lock);
269
270         LPROCFS_CLIMP_CHECK(obd);
271         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
272                 rc = osc_shrink_grant_to_target(cli, val);
273         LPROCFS_CLIMP_EXIT(obd);
274         if (rc)
275                 return rc;
276         return count;
277 }
278 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
279
280 static int osc_cur_lost_grant_bytes_seq_show(struct seq_file *m, void *v)
281 {
282         struct obd_device *dev = m->private;
283         struct client_obd *cli = &dev->u.cli;
284         int rc;
285
286         client_obd_list_lock(&cli->cl_loi_list_lock);
287         rc = seq_printf(m, "%lu\n", cli->cl_lost_grant);
288         client_obd_list_unlock(&cli->cl_loi_list_lock);
289         return rc;
290 }
291 LPROC_SEQ_FOPS_RO(osc_cur_lost_grant_bytes);
292
293 static int osc_grant_shrink_interval_seq_show(struct seq_file *m, void *v)
294 {
295         struct obd_device *obd = m->private;
296
297         if (obd == NULL)
298                 return 0;
299         return seq_printf(m, "%d\n",
300                           obd->u.cli.cl_grant_shrink_interval);
301 }
302
303 static ssize_t osc_grant_shrink_interval_seq_write(struct file *file,
304                                                    const char *buffer,
305                                                    size_t count, loff_t *off)
306 {
307         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
308         int val, rc;
309
310         if (obd == NULL)
311                 return 0;
312
313         rc = lprocfs_write_helper(buffer, count, &val);
314         if (rc)
315                 return rc;
316
317         if (val <= 0)
318                 return -ERANGE;
319
320         obd->u.cli.cl_grant_shrink_interval = val;
321
322         return count;
323 }
324 LPROC_SEQ_FOPS(osc_grant_shrink_interval);
325
326 static int osc_checksum_seq_show(struct seq_file *m, void *v)
327 {
328         struct obd_device *obd = m->private;
329
330         if (obd == NULL)
331                 return 0;
332
333         return seq_printf(m, "%d\n",
334                           obd->u.cli.cl_checksum ? 1 : 0);
335 }
336
337 static ssize_t osc_checksum_seq_write(struct file *file, const char *buffer,
338                                       size_t count, loff_t *off)
339 {
340         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
341         int val, rc;
342
343         if (obd == NULL)
344                 return 0;
345
346         rc = lprocfs_write_helper(buffer, count, &val);
347         if (rc)
348                 return rc;
349
350         obd->u.cli.cl_checksum = (val ? 1 : 0);
351
352         return count;
353 }
354 LPROC_SEQ_FOPS(osc_checksum);
355
356 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
357 {
358         struct obd_device *obd = m->private;
359         int i;
360         DECLARE_CKSUM_NAME;
361
362         if (obd == NULL)
363                 return 0;
364
365         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
366                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
367                         continue;
368                 if (obd->u.cli.cl_cksum_type == (1 << i))
369                         seq_printf(m, "[%s] ", cksum_name[i]);
370                 else
371                         seq_printf(m, "%s ", cksum_name[i]);
372         }
373         seq_printf(m, "\n");
374         return 0;
375 }
376
377 static ssize_t osc_checksum_type_seq_write(struct file *file, const char *buffer,
378                                            size_t count, loff_t *off)
379 {
380         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
381         int i;
382         DECLARE_CKSUM_NAME;
383         char kernbuf[10];
384
385         if (obd == NULL)
386                 return 0;
387
388         if (count > sizeof(kernbuf) - 1)
389                 return -EINVAL;
390         if (copy_from_user(kernbuf, buffer, count))
391                 return -EFAULT;
392         if (count > 0 && kernbuf[count - 1] == '\n')
393                 kernbuf[count - 1] = '\0';
394         else
395                 kernbuf[count] = '\0';
396
397         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
398                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
399                         continue;
400                 if (!strcmp(kernbuf, cksum_name[i])) {
401                        obd->u.cli.cl_cksum_type = 1 << i;
402                        return count;
403                 }
404         }
405         return -EINVAL;
406 }
407 LPROC_SEQ_FOPS(osc_checksum_type);
408
409 static int osc_resend_count_seq_show(struct seq_file *m, void *v)
410 {
411         struct obd_device *obd = m->private;
412
413         return seq_printf(m, "%u\n", atomic_read(&obd->u.cli.cl_resends));
414 }
415
416 static ssize_t osc_resend_count_seq_write(struct file *file, const char *buffer,
417                                           size_t count, loff_t *off)
418 {
419         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
420         int val, rc;
421
422         rc = lprocfs_write_helper(buffer, count, &val);
423         if (rc)
424                 return rc;
425
426         if (val < 0)
427                 return -EINVAL;
428
429         atomic_set(&obd->u.cli.cl_resends, val);
430
431         return count;
432 }
433 LPROC_SEQ_FOPS(osc_resend_count);
434
435 static int osc_contention_seconds_seq_show(struct seq_file *m, void *v)
436 {
437         struct obd_device *obd = m->private;
438         struct osc_device *od  = obd2osc_dev(obd);
439
440         return seq_printf(m, "%u\n", od->od_contention_time);
441 }
442
443 static ssize_t osc_contention_seconds_seq_write(struct file *file, const char *buffer,
444                                                 size_t count, loff_t *off)
445 {
446         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
447         struct osc_device *od  = obd2osc_dev(obd);
448
449         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?: count;
450 }
451 LPROC_SEQ_FOPS(osc_contention_seconds);
452
453 static int osc_lockless_truncate_seq_show(struct seq_file *m, void *v)
454 {
455         struct obd_device *obd = m->private;
456         struct osc_device *od  = obd2osc_dev(obd);
457
458         return seq_printf(m, "%u\n", od->od_lockless_truncate);
459 }
460
461 static ssize_t osc_lockless_truncate_seq_write(struct file *file, const char *buffer,
462                                     size_t count, loff_t *off)
463 {
464         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
465         struct osc_device *od  = obd2osc_dev(obd);
466
467         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
468                 count;
469 }
470 LPROC_SEQ_FOPS(osc_lockless_truncate);
471
472 static int osc_destroys_in_flight_seq_show(struct seq_file *m, void *v)
473 {
474         struct obd_device *obd = m->private;
475         return seq_printf(m, "%u\n",
476                           atomic_read(&obd->u.cli.cl_destroy_in_flight));
477 }
478 LPROC_SEQ_FOPS_RO(osc_destroys_in_flight);
479
480 static int osc_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
481 {
482         return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
483 }
484
485 static ssize_t osc_obd_max_pages_per_rpc_seq_write(struct file *file,
486                                                    const char *buffer,
487                                                    size_t count, loff_t *off)
488 {
489         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
490         struct client_obd *cli = &dev->u.cli;
491         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
492         int chunk_mask, rc;
493         __u64 val;
494
495         rc = lprocfs_write_u64_helper(buffer, count, &val);
496         if (rc)
497                 return rc;
498
499         /* if the max_pages is specified in bytes, convert to pages */
500         if (val >= ONE_MB_BRW_SIZE)
501                 val >>= PAGE_CACHE_SHIFT;
502
503         LPROCFS_CLIMP_CHECK(dev);
504
505         chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1);
506         /* max_pages_per_rpc must be chunk aligned */
507         val = (val + ~chunk_mask) & chunk_mask;
508         if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) {
509                 LPROCFS_CLIMP_EXIT(dev);
510                 return -ERANGE;
511         }
512         client_obd_list_lock(&cli->cl_loi_list_lock);
513         cli->cl_max_pages_per_rpc = val;
514         client_obd_list_unlock(&cli->cl_loi_list_lock);
515
516         LPROCFS_CLIMP_EXIT(dev);
517         return count;
518 }
519 LPROC_SEQ_FOPS(osc_obd_max_pages_per_rpc);
520
521 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
522 {
523         struct obd_device *dev = m->private;
524         struct client_obd *cli = &dev->u.cli;
525         int pages, mb;
526
527         pages = atomic_read(&cli->cl_unstable_count);
528         mb    = (pages * PAGE_CACHE_SIZE) >> 20;
529
530         return seq_printf(m, "unstable_pages: %8d\n"
531                         "unstable_mb:    %8d\n",
532                         pages, mb);
533 }
534 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
535
536 LPROC_SEQ_FOPS_RO_TYPE(osc, uuid);
537 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
538 LPROC_SEQ_FOPS_RO_TYPE(osc, blksize);
539 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytestotal);
540 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesfree);
541 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesavail);
542 LPROC_SEQ_FOPS_RO_TYPE(osc, filestotal);
543 LPROC_SEQ_FOPS_RO_TYPE(osc, filesfree);
544 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
545 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
546 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
547 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
548
549 LPROC_SEQ_FOPS_WO_TYPE(osc, ping);
550
551 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
552 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
553
554 struct lprocfs_seq_vars lprocfs_osc_obd_vars[] = {
555         { .name =       "uuid",
556           .fops =       &osc_uuid_fops                  },
557         { .name =       "ping",
558           .fops =       &osc_ping_fops,
559           .proc_mode =  0222                            },
560         { .name =       "connect_flags",
561           .fops =       &osc_connect_flags_fops         },
562         { .name =       "blocksize",
563           .fops =       &osc_blksize_fops               },
564         { .name =       "kbytestotal",
565           .fops =       &osc_kbytestotal_fops           },
566         { .name =       "kbytesfree",
567           .fops =       &osc_kbytesfree_fops            },
568         { .name =       "kbytesavail",
569           .fops =       &osc_kbytesavail_fops           },
570         { .name =       "filestotal",
571           .fops =       &osc_filestotal_fops            },
572         { .name =       "filesfree",
573           .fops =       &osc_filesfree_fops             },
574         { .name =       "ost_server_uuid",
575           .fops =       &osc_server_uuid_fops           },
576         { .name =       "ost_conn_uuid",
577           .fops =       &osc_conn_uuid_fops             },
578         { .name =       "active",
579           .fops =       &osc_active_fops                },
580         { .name =       "max_pages_per_rpc",
581           .fops =       &osc_obd_max_pages_per_rpc_fops },
582         { .name =       "max_rpcs_in_flight",
583           .fops =       &osc_max_rpcs_in_flight_fops    },
584         { .name =       "destroys_in_flight",
585           .fops =       &osc_destroys_in_flight_fops    },
586         { .name =       "max_dirty_mb",
587           .fops =       &osc_max_dirty_mb_fops          },
588         { .name =       "osc_cached_mb",
589           .fops =       &osc_cached_mb_fops             },
590         { .name =       "cur_dirty_bytes",
591           .fops =       &osc_cur_dirty_bytes_fops       },
592         { .name =       "cur_grant_bytes",
593           .fops =       &osc_cur_grant_bytes_fops       },
594         { .name =       "cur_lost_grant_bytes",
595           .fops =       &osc_cur_lost_grant_bytes_fops  },
596         { .name =       "grant_shrink_interval",
597           .fops =       &osc_grant_shrink_interval_fops },
598         { .name =       "checksums",
599           .fops =       &osc_checksum_fops              },
600         { .name =       "checksum_type",
601           .fops =       &osc_checksum_type_fops         },
602         { .name =       "resend_count",
603           .fops =       &osc_resend_count_fops          },
604         { .name =       "timeouts",
605           .fops =       &osc_timeouts_fops              },
606         { .name =       "contention_seconds",
607           .fops =       &osc_contention_seconds_fops    },
608         { .name =       "lockless_truncate",
609           .fops =       &osc_lockless_truncate_fops     },
610         { .name =       "import",
611           .fops =       &osc_import_fops                },
612         { .name =       "state",
613           .fops =       &osc_state_fops                 },
614         { .name =       "pinger_recov",
615           .fops =       &osc_pinger_recov_fops          },
616         { .name =       "unstable_stats",
617           .fops =       &osc_unstable_stats_fops        },
618         { 0 }
619 };
620
621 #define pct(a,b) (b ? a * 100 / b : 0)
622
623 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
624 {
625         struct timeval now;
626         struct obd_device *dev = seq->private;
627         struct client_obd *cli = &dev->u.cli;
628         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
629         int i;
630
631         do_gettimeofday(&now);
632
633         client_obd_list_lock(&cli->cl_loi_list_lock);
634
635         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
636                    now.tv_sec, now.tv_usec);
637         seq_printf(seq, "read RPCs in flight:  %d\n",
638                    cli->cl_r_in_flight);
639         seq_printf(seq, "write RPCs in flight: %d\n",
640                    cli->cl_w_in_flight);
641         seq_printf(seq, "pending write pages:  %d\n",
642                    atomic_read(&cli->cl_pending_w_pages));
643         seq_printf(seq, "pending read pages:   %d\n",
644                    atomic_read(&cli->cl_pending_r_pages));
645
646         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
647         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
648         seq_printf(seq, "       rpcs   %% cum %%\n");
649
650         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
651         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
652
653         read_cum = 0;
654         write_cum = 0;
655         for (i = 0; i < OBD_HIST_MAX; i++) {
656                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
657                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
658
659                 read_cum += r;
660                 write_cum += w;
661                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
662                            1 << i, r, pct(r, read_tot),
663                            pct(read_cum, read_tot), w,
664                            pct(w, write_tot),
665                            pct(write_cum, write_tot));
666                 if (read_cum == read_tot && write_cum == write_tot)
667                         break;
668         }
669
670         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
671         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
672         seq_printf(seq, "       rpcs   %% cum %%\n");
673
674         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
675         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
676
677         read_cum = 0;
678         write_cum = 0;
679         for (i = 0; i < OBD_HIST_MAX; i++) {
680                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
681                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
682                 read_cum += r;
683                 write_cum += w;
684                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
685                                  i, r, pct(r, read_tot),
686                                  pct(read_cum, read_tot), w,
687                                  pct(w, write_tot),
688                                  pct(write_cum, write_tot));
689                 if (read_cum == read_tot && write_cum == write_tot)
690                         break;
691         }
692
693         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
694         seq_printf(seq, "offset                rpcs   %% cum %% |");
695         seq_printf(seq, "       rpcs   %% cum %%\n");
696
697         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
698         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
699
700         read_cum = 0;
701         write_cum = 0;
702         for (i = 0; i < OBD_HIST_MAX; i++) {
703                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
704                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
705                 read_cum += r;
706                 write_cum += w;
707                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
708                            (i == 0) ? 0 : 1 << (i - 1),
709                            r, pct(r, read_tot), pct(read_cum, read_tot),
710                            w, pct(w, write_tot), pct(write_cum, write_tot));
711                 if (read_cum == read_tot && write_cum == write_tot)
712                         break;
713         }
714
715         client_obd_list_unlock(&cli->cl_loi_list_lock);
716
717         return 0;
718 }
719 #undef pct
720
721 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
722                                        size_t len, loff_t *off)
723 {
724         struct seq_file *seq = file->private_data;
725         struct obd_device *dev = seq->private;
726         struct client_obd *cli = &dev->u.cli;
727
728         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
729         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
730         lprocfs_oh_clear(&cli->cl_read_page_hist);
731         lprocfs_oh_clear(&cli->cl_write_page_hist);
732         lprocfs_oh_clear(&cli->cl_read_offset_hist);
733         lprocfs_oh_clear(&cli->cl_write_offset_hist);
734
735         return len;
736 }
737 LPROC_SEQ_FOPS(osc_rpc_stats);
738
739 static int osc_stats_seq_show(struct seq_file *seq, void *v)
740 {
741         struct timeval now;
742         struct obd_device *dev = seq->private;
743         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
744
745         do_gettimeofday(&now);
746
747         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
748                    now.tv_sec, now.tv_usec);
749         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
750                    stats->os_lockless_writes);
751         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
752                    stats->os_lockless_reads);
753         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
754                    stats->os_lockless_truncates);
755         return 0;
756 }
757
758 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
759                                    size_t len, loff_t *off)
760 {
761         struct seq_file *seq = file->private_data;
762         struct obd_device *dev = seq->private;
763         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
764
765         memset(stats, 0, sizeof(*stats));
766         return len;
767 }
768
769 LPROC_SEQ_FOPS(osc_stats);
770
771 int lproc_osc_attach_seqstat(struct obd_device *dev)
772 {
773         int rc;
774
775         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
776                                 &osc_stats_fops, dev);
777         if (rc == 0)
778                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
779                                             &osc_rpc_stats_fops, dev);
780
781         return rc;
782 }
783 #endif /* LPROCFS */