Whamcloud - gitweb
LU-3319 procfs: move configuration layer proc handling over to seq_file
[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                       (cfs_atomic_read(&cli->cl_lru_in_list) +
173                         cfs_atomic_read(&cli->cl_lru_busy)) >> shift,
174                       cfs_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 *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
188         mult = 1 << (20 - PAGE_CACHE_SHIFT);
189         buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
190         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
191         if (rc)
192                 return rc;
193
194         if (pages_number < 0)
195                 return -ERANGE;
196
197         rc = cfs_atomic_read(&cli->cl_lru_in_list) - pages_number;
198         if (rc > 0) {
199                 struct lu_env *env;
200                 int refcheck;
201
202                 env = cl_env_get(&refcheck);
203                 if (!IS_ERR(env)) {
204                         (void)osc_lru_shrink(env, cli, rc, true);
205                         cl_env_put(env, &refcheck);
206                 }
207         }
208
209         return count;
210 }
211 LPROC_SEQ_FOPS(osc_cached_mb);
212
213 static int osc_cur_dirty_bytes_seq_show(struct seq_file *m, void *v)
214 {
215         struct obd_device *dev = m->private;
216         struct client_obd *cli = &dev->u.cli;
217         int rc;
218
219         client_obd_list_lock(&cli->cl_loi_list_lock);
220         rc = seq_printf(m, "%lu\n", cli->cl_dirty);
221         client_obd_list_unlock(&cli->cl_loi_list_lock);
222         return rc;
223 }
224 LPROC_SEQ_FOPS_RO(osc_cur_dirty_bytes);
225
226 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
227 {
228         struct obd_device *dev = m->private;
229         struct client_obd *cli = &dev->u.cli;
230         int rc;
231
232         client_obd_list_lock(&cli->cl_loi_list_lock);
233         rc = seq_printf(m, "%lu\n", cli->cl_avail_grant);
234         client_obd_list_unlock(&cli->cl_loi_list_lock);
235         return rc;
236 }
237
238 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file, const char *buffer,
239                                              size_t count, loff_t *off)
240 {
241         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
242         struct client_obd *cli = &obd->u.cli;
243         int                rc;
244         __u64              val;
245
246         if (obd == NULL)
247                 return 0;
248
249         rc = lprocfs_write_u64_helper(buffer, count, &val);
250         if (rc)
251                 return rc;
252
253         /* this is only for shrinking grant */
254         client_obd_list_lock(&cli->cl_loi_list_lock);
255         if (val >= cli->cl_avail_grant) {
256                 client_obd_list_unlock(&cli->cl_loi_list_lock);
257                 return 0;
258         }
259         client_obd_list_unlock(&cli->cl_loi_list_lock);
260
261         LPROCFS_CLIMP_CHECK(obd);
262         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
263                 rc = osc_shrink_grant_to_target(cli, val);
264         LPROCFS_CLIMP_EXIT(obd);
265         if (rc)
266                 return rc;
267         return count;
268 }
269 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
270
271 static int osc_cur_lost_grant_bytes_seq_show(struct seq_file *m, void *v)
272 {
273         struct obd_device *dev = m->private;
274         struct client_obd *cli = &dev->u.cli;
275         int rc;
276
277         client_obd_list_lock(&cli->cl_loi_list_lock);
278         rc = seq_printf(m, "%lu\n", cli->cl_lost_grant);
279         client_obd_list_unlock(&cli->cl_loi_list_lock);
280         return rc;
281 }
282 LPROC_SEQ_FOPS_RO(osc_cur_lost_grant_bytes);
283
284 static int osc_grant_shrink_interval_seq_show(struct seq_file *m, void *v)
285 {
286         struct obd_device *obd = m->private;
287
288         if (obd == NULL)
289                 return 0;
290         return seq_printf(m, "%d\n",
291                           obd->u.cli.cl_grant_shrink_interval);
292 }
293
294 static ssize_t osc_grant_shrink_interval_seq_write(struct file *file,
295                                                    const char *buffer,
296                                                    size_t count, loff_t *off)
297 {
298         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
299         int val, rc;
300
301         if (obd == NULL)
302                 return 0;
303
304         rc = lprocfs_write_helper(buffer, count, &val);
305         if (rc)
306                 return rc;
307
308         if (val <= 0)
309                 return -ERANGE;
310
311         obd->u.cli.cl_grant_shrink_interval = val;
312
313         return count;
314 }
315 LPROC_SEQ_FOPS(osc_grant_shrink_interval);
316
317 static int osc_checksum_seq_show(struct seq_file *m, void *v)
318 {
319         struct obd_device *obd = m->private;
320
321         if (obd == NULL)
322                 return 0;
323
324         return seq_printf(m, "%d\n",
325                           obd->u.cli.cl_checksum ? 1 : 0);
326 }
327
328 static ssize_t osc_checksum_seq_write(struct file *file, const char *buffer,
329                                       size_t count, loff_t *off)
330 {
331         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
332         int val, rc;
333
334         if (obd == NULL)
335                 return 0;
336
337         rc = lprocfs_write_helper(buffer, count, &val);
338         if (rc)
339                 return rc;
340
341         obd->u.cli.cl_checksum = (val ? 1 : 0);
342
343         return count;
344 }
345 LPROC_SEQ_FOPS(osc_checksum);
346
347 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
348 {
349         struct obd_device *obd = m->private;
350         int i;
351         DECLARE_CKSUM_NAME;
352
353         if (obd == NULL)
354                 return 0;
355
356         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
357                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
358                         continue;
359                 if (obd->u.cli.cl_cksum_type == (1 << i))
360                         seq_printf(m, "[%s] ", cksum_name[i]);
361                 else
362                         seq_printf(m, "%s ", cksum_name[i]);
363         }
364         seq_printf(m, "\n");
365         return 0;
366 }
367
368 static ssize_t osc_checksum_type_seq_write(struct file *file, const char *buffer,
369                                            size_t count, loff_t *off)
370 {
371         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
372         int i;
373         DECLARE_CKSUM_NAME;
374         char kernbuf[10];
375
376         if (obd == NULL)
377                 return 0;
378
379         if (count > sizeof(kernbuf) - 1)
380                 return -EINVAL;
381         if (copy_from_user(kernbuf, buffer, count))
382                 return -EFAULT;
383         if (count > 0 && kernbuf[count - 1] == '\n')
384                 kernbuf[count - 1] = '\0';
385         else
386                 kernbuf[count] = '\0';
387
388         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
389                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
390                         continue;
391                 if (!strcmp(kernbuf, cksum_name[i])) {
392                        obd->u.cli.cl_cksum_type = 1 << i;
393                        return count;
394                 }
395         }
396         return -EINVAL;
397 }
398 LPROC_SEQ_FOPS(osc_checksum_type);
399
400 static int osc_resend_count_seq_show(struct seq_file *m, void *v)
401 {
402         struct obd_device *obd = m->private;
403
404         return seq_printf(m, "%u\n", cfs_atomic_read(&obd->u.cli.cl_resends));
405 }
406
407 static ssize_t osc_resend_count_seq_write(struct file *file, const char *buffer,
408                                           size_t count, loff_t *off)
409 {
410         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
411         int val, rc;
412
413         rc = lprocfs_write_helper(buffer, count, &val);
414         if (rc)
415                 return rc;
416
417         if (val < 0)
418                return -EINVAL;
419
420         cfs_atomic_set(&obd->u.cli.cl_resends, val);
421
422         return count;
423 }
424 LPROC_SEQ_FOPS(osc_resend_count);
425
426 static int osc_contention_seconds_seq_show(struct seq_file *m, void *v)
427 {
428         struct obd_device *obd = m->private;
429         struct osc_device *od  = obd2osc_dev(obd);
430
431         return seq_printf(m, "%u\n", od->od_contention_time);
432 }
433
434 static ssize_t osc_contention_seconds_seq_write(struct file *file, const char *buffer,
435                                                 size_t count, loff_t *off)
436 {
437         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
438         struct osc_device *od  = obd2osc_dev(obd);
439
440         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?: count;
441 }
442 LPROC_SEQ_FOPS(osc_contention_seconds);
443
444 static int osc_lockless_truncate_seq_show(struct seq_file *m, void *v)
445 {
446         struct obd_device *obd = m->private;
447         struct osc_device *od  = obd2osc_dev(obd);
448
449         return seq_printf(m, "%u\n", od->od_lockless_truncate);
450 }
451
452 static ssize_t osc_lockless_truncate_seq_write(struct file *file, const char *buffer,
453                                     size_t count, loff_t *off)
454 {
455         struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
456         struct osc_device *od  = obd2osc_dev(obd);
457
458         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
459                 count;
460 }
461 LPROC_SEQ_FOPS(osc_lockless_truncate);
462
463 static int osc_destroys_in_flight_seq_show(struct seq_file *m, void *v)
464 {
465         struct obd_device *obd = m->private;
466         return seq_printf(m, "%u\n",
467                           cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
468 }
469 LPROC_SEQ_FOPS_RO(osc_destroys_in_flight);
470
471 static int osc_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *v)
472 {
473         return lprocfs_obd_max_pages_per_rpc_seq_show(m, m->private);
474 }
475
476 static ssize_t osc_obd_max_pages_per_rpc_seq_write(struct file *file,
477                                                    const char *buffer,
478                                                    size_t count, loff_t *off)
479 {
480         struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
481         struct client_obd *cli = &dev->u.cli;
482         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
483         int chunk_mask, rc;
484         __u64 val;
485
486         rc = lprocfs_write_u64_helper(buffer, count, &val);
487         if (rc)
488                 return rc;
489
490         /* if the max_pages is specified in bytes, convert to pages */
491         if (val >= ONE_MB_BRW_SIZE)
492                 val >>= PAGE_CACHE_SHIFT;
493
494         LPROCFS_CLIMP_CHECK(dev);
495
496         chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1);
497         /* max_pages_per_rpc must be chunk aligned */
498         val = (val + ~chunk_mask) & chunk_mask;
499         if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) {
500                 LPROCFS_CLIMP_EXIT(dev);
501                 return -ERANGE;
502         }
503         client_obd_list_lock(&cli->cl_loi_list_lock);
504         cli->cl_max_pages_per_rpc = val;
505         client_obd_list_unlock(&cli->cl_loi_list_lock);
506
507         LPROCFS_CLIMP_EXIT(dev);
508         return count;
509 }
510 LPROC_SEQ_FOPS(osc_obd_max_pages_per_rpc);
511
512 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
513 {
514         struct obd_device *dev = m->private;
515         struct client_obd *cli = &dev->u.cli;
516         int pages, mb;
517
518         pages = cfs_atomic_read(&cli->cl_unstable_count);
519         mb    = (pages * PAGE_CACHE_SIZE) >> 20;
520
521         return seq_printf(m, "unstable_pages: %8d\n"
522                         "unstable_mb:    %8d\n",
523                         pages, mb);
524 }
525 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
526
527 LPROC_SEQ_FOPS_RO_TYPE(osc, uuid);
528 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
529 LPROC_SEQ_FOPS_RO_TYPE(osc, blksize);
530 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytestotal);
531 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesfree);
532 LPROC_SEQ_FOPS_RO_TYPE(osc, kbytesavail);
533 LPROC_SEQ_FOPS_RO_TYPE(osc, filestotal);
534 LPROC_SEQ_FOPS_RO_TYPE(osc, filesfree);
535 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
536 LPROC_SEQ_FOPS_RO_TYPE(osc, conn_uuid);
537 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
538 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
539
540 LPROC_SEQ_FOPS_WO_TYPE(osc, ping);
541
542 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
543 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
544
545 struct lprocfs_seq_vars lprocfs_osc_obd_vars[] = {
546         { "uuid",               &osc_uuid_fops                  },
547         { "ping",               &osc_ping_fops,         0, 0222 },
548         { "connect_flags",      &osc_connect_flags_fops         },
549         { "blocksize",          &osc_blksize_fops               },
550         { "kbytestotal",        &osc_kbytestotal_fops           },
551         { "kbytesfree",         &osc_kbytesfree_fops            },
552         { "kbytesavail",        &osc_kbytesavail_fops           },
553         { "filestotal",         &osc_filestotal_fops            },
554         { "filesfree",          &osc_filesfree_fops             },
555         { "ost_server_uuid",    &osc_server_uuid_fops           },
556         { "ost_conn_uuid",      &osc_conn_uuid_fops             },
557         { "active",             &osc_active_fops                },
558         { "max_pages_per_rpc",  &osc_obd_max_pages_per_rpc_fops },
559         { "max_rpcs_in_flight", &osc_max_rpcs_in_flight_fops    },
560         { "destroys_in_flight", &osc_destroys_in_flight_fops    },
561         { "max_dirty_mb",       &osc_max_dirty_mb_fops          },
562         { "osc_cached_mb",      &osc_cached_mb_fops             },
563         { "cur_dirty_bytes",    &osc_cur_dirty_bytes_fops       },
564         { "cur_grant_bytes",    &osc_cur_grant_bytes_fops       },
565         { "cur_lost_grant_bytes",       &osc_cur_lost_grant_bytes_fops  },
566         { "grant_shrink_interval",      &osc_grant_shrink_interval_fops },
567         { "checksums",          &osc_checksum_fops              },
568         { "checksum_type",      &osc_checksum_type_fops         },
569         { "resend_count",       &osc_resend_count_fops          },
570         { "timeouts",           &osc_timeouts_fops              },
571         { "contention_seconds", &osc_contention_seconds_fops    },
572         { "lockless_truncate",  &osc_lockless_truncate_fops     },
573         { "import",             &osc_import_fops                },
574         { "state",              &osc_state_fops                 },
575         { "pinger_recov",       &osc_pinger_recov_fops          },
576         { "unstable_stats",     &osc_unstable_stats_fops        },
577         { 0 }
578 };
579
580 #define pct(a,b) (b ? a * 100 / b : 0)
581
582 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
583 {
584         struct timeval now;
585         struct obd_device *dev = seq->private;
586         struct client_obd *cli = &dev->u.cli;
587         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
588         int i;
589
590         do_gettimeofday(&now);
591
592         client_obd_list_lock(&cli->cl_loi_list_lock);
593
594         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
595                    now.tv_sec, now.tv_usec);
596         seq_printf(seq, "read RPCs in flight:  %d\n",
597                    cli->cl_r_in_flight);
598         seq_printf(seq, "write RPCs in flight: %d\n",
599                    cli->cl_w_in_flight);
600         seq_printf(seq, "pending write pages:  %d\n",
601                    cfs_atomic_read(&cli->cl_pending_w_pages));
602         seq_printf(seq, "pending read pages:   %d\n",
603                    cfs_atomic_read(&cli->cl_pending_r_pages));
604
605         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
606         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
607         seq_printf(seq, "       rpcs   %% cum %%\n");
608
609         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
610         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
611
612         read_cum = 0;
613         write_cum = 0;
614         for (i = 0; i < OBD_HIST_MAX; i++) {
615                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
616                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
617                 read_cum += r;
618                 write_cum += w;
619                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
620                                  1 << i, r, pct(r, read_tot),
621                                  pct(read_cum, read_tot), w,
622                                  pct(w, write_tot),
623                                  pct(write_cum, write_tot));
624                 if (read_cum == read_tot && write_cum == write_tot)
625                         break;
626         }
627
628         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
629         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
630         seq_printf(seq, "       rpcs   %% cum %%\n");
631
632         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
633         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
634
635         read_cum = 0;
636         write_cum = 0;
637         for (i = 0; i < OBD_HIST_MAX; i++) {
638                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
639                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
640                 read_cum += r;
641                 write_cum += w;
642                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
643                                  i, r, pct(r, read_tot),
644                                  pct(read_cum, read_tot), w,
645                                  pct(w, write_tot),
646                                  pct(write_cum, write_tot));
647                 if (read_cum == read_tot && write_cum == write_tot)
648                         break;
649         }
650
651         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
652         seq_printf(seq, "offset                rpcs   %% cum %% |");
653         seq_printf(seq, "       rpcs   %% cum %%\n");
654
655         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
656         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
657
658         read_cum = 0;
659         write_cum = 0;
660         for (i = 0; i < OBD_HIST_MAX; i++) {
661                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
662                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
663                 read_cum += r;
664                 write_cum += w;
665                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
666                            (i == 0) ? 0 : 1 << (i - 1),
667                            r, pct(r, read_tot), pct(read_cum, read_tot),
668                            w, pct(w, write_tot), pct(write_cum, write_tot));
669                 if (read_cum == read_tot && write_cum == write_tot)
670                         break;
671         }
672
673         client_obd_list_unlock(&cli->cl_loi_list_lock);
674
675         return 0;
676 }
677 #undef pct
678
679 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
680                                        size_t len, loff_t *off)
681 {
682         struct seq_file *seq = file->private_data;
683         struct obd_device *dev = seq->private;
684         struct client_obd *cli = &dev->u.cli;
685
686         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
687         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
688         lprocfs_oh_clear(&cli->cl_read_page_hist);
689         lprocfs_oh_clear(&cli->cl_write_page_hist);
690         lprocfs_oh_clear(&cli->cl_read_offset_hist);
691         lprocfs_oh_clear(&cli->cl_write_offset_hist);
692
693         return len;
694 }
695 LPROC_SEQ_FOPS(osc_rpc_stats);
696
697 static int osc_stats_seq_show(struct seq_file *seq, void *v)
698 {
699         struct timeval now;
700         struct obd_device *dev = seq->private;
701         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
702
703         do_gettimeofday(&now);
704
705         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
706                    now.tv_sec, now.tv_usec);
707         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
708                    stats->os_lockless_writes);
709         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
710                    stats->os_lockless_reads);
711         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
712                    stats->os_lockless_truncates);
713         return 0;
714 }
715
716 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
717                                    size_t len, loff_t *off)
718 {
719         struct seq_file *seq = file->private_data;
720         struct obd_device *dev = seq->private;
721         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
722
723         memset(stats, 0, sizeof(*stats));
724         return len;
725 }
726
727 LPROC_SEQ_FOPS(osc_stats);
728
729 int lproc_osc_attach_seqstat(struct obd_device *dev)
730 {
731         int rc;
732
733         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
734                                 &osc_stats_fops, dev);
735         if (rc == 0)
736                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
737                                             &osc_rpc_stats_fops, dev);
738
739         return rc;
740 }
741 #endif /* LPROCFS */