Whamcloud - gitweb
LU-2683 lov: release all locks in closure to release sublock
[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, 2012, 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_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         /* opposite senses */
72         if (dev->u.cli.cl_import->imp_deactive == val)
73                 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
74         else
75                 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
76
77         return count;
78 }
79
80 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
81                                      int count, int *eof, void *data)
82 {
83         struct obd_device *dev = data;
84         struct client_obd *cli = &dev->u.cli;
85         int rc;
86
87         client_obd_list_lock(&cli->cl_loi_list_lock);
88         rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
89         client_obd_list_unlock(&cli->cl_loi_list_lock);
90         return rc;
91 }
92
93 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
94                                      unsigned long count, void *data)
95 {
96         struct obd_device *dev = data;
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
120 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
121                                int *eof, void *data)
122 {
123         struct obd_device *dev = data;
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_read_frac_helper(page, count, val, mult);
134 }
135
136 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
137                                unsigned long count, void *data)
138 {
139         struct obd_device *dev = data;
140         struct client_obd *cli = &dev->u.cli;
141         int pages_number, mult, rc;
142
143         mult = 1 << (20 - CFS_PAGE_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 - CFS_PAGE_SHIFT) ||
150             pages_number > cfs_num_physpages / 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 << CFS_PAGE_SHIFT);
155         osc_wake_cache_waiters(cli);
156         client_obd_list_unlock(&cli->cl_loi_list_lock);
157
158         return count;
159 }
160
161 static int osc_rd_cached_mb(char *page, char **start, off_t off, int count,
162                             int *eof, void *data)
163 {
164         struct obd_device *dev = data;
165         struct client_obd *cli = &dev->u.cli;
166         int shift = 20 - CFS_PAGE_SHIFT;
167         int rc;
168
169         rc = snprintf(page, count,
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 int osc_wr_cached_mb(struct file *file, const char *buffer,
181                             unsigned long count, void *data)
182 {
183         struct obd_device *dev = data;
184         struct client_obd *cli = &dev->u.cli;
185         int pages_number, mult, rc;
186
187         mult = 1 << (20 - CFS_PAGE_SHIFT);
188         buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
189         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
190         if (rc)
191                 return rc;
192
193         if (pages_number < 0)
194                 return -ERANGE;
195
196         rc = cfs_atomic_read(&cli->cl_lru_in_list) - pages_number;
197         if (rc > 0)
198                 (void)osc_lru_shrink(cli, rc);
199
200         return count;
201 }
202
203 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
204                                   int count, int *eof, void *data)
205 {
206         struct obd_device *dev = data;
207         struct client_obd *cli = &dev->u.cli;
208         int rc;
209
210         client_obd_list_lock(&cli->cl_loi_list_lock);
211         rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
212         client_obd_list_unlock(&cli->cl_loi_list_lock);
213         return rc;
214 }
215
216 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
217                                   int count, int *eof, void *data)
218 {
219         struct obd_device *dev = data;
220         struct client_obd *cli = &dev->u.cli;
221         int rc;
222
223         client_obd_list_lock(&cli->cl_loi_list_lock);
224         rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
225         client_obd_list_unlock(&cli->cl_loi_list_lock);
226         return rc;
227 }
228
229 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
230                                   unsigned long count, void *data)
231 {
232         struct obd_device *obd = data;
233         struct client_obd *cli = &obd->u.cli;
234         int                rc;
235         __u64              val;
236
237         if (obd == NULL)
238                 return 0;
239
240         rc = lprocfs_write_u64_helper(buffer, count, &val);
241         if (rc)
242                 return rc;
243
244         /* this is only for shrinking grant */
245         client_obd_list_lock(&cli->cl_loi_list_lock);
246         if (val >= cli->cl_avail_grant) {
247                 client_obd_list_unlock(&cli->cl_loi_list_lock);
248                 return 0;
249         }
250         client_obd_list_unlock(&cli->cl_loi_list_lock);
251
252         LPROCFS_CLIMP_CHECK(obd);
253         if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
254                 rc = osc_shrink_grant_to_target(cli, val);
255         LPROCFS_CLIMP_EXIT(obd);
256         if (rc)
257                 return rc;
258         return count;
259 }
260
261 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
262                                        int count, int *eof, void *data)
263 {
264         struct obd_device *dev = data;
265         struct client_obd *cli = &dev->u.cli;
266         int rc;
267
268         client_obd_list_lock(&cli->cl_loi_list_lock);
269         rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
270         client_obd_list_unlock(&cli->cl_loi_list_lock);
271         return rc;
272 }
273
274 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
275                                         int count, int *eof, void *data)
276 {
277         struct obd_device *obd = data;
278
279         if (obd == NULL)
280                 return 0;
281         return snprintf(page, count, "%d\n",
282                         obd->u.cli.cl_grant_shrink_interval);
283 }
284
285 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
286                                         unsigned long count, void *data)
287 {
288         struct obd_device *obd = data;
289         int val, rc;
290
291         if (obd == NULL)
292                 return 0;
293
294         rc = lprocfs_write_helper(buffer, count, &val);
295         if (rc)
296                 return rc;
297
298         if (val <= 0)
299                 return -ERANGE;
300
301         obd->u.cli.cl_grant_shrink_interval = val;
302
303         return count;
304 }
305
306 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
307                            int *eof, void *data)
308 {
309         struct obd_device *obd = data;
310
311         if (obd == NULL)
312                 return 0;
313
314         return snprintf(page, count, "%d\n",
315                         obd->u.cli.cl_checksum ? 1 : 0);
316 }
317
318 static int osc_wr_checksum(struct file *file, const char *buffer,
319                            unsigned long count, void *data)
320 {
321         struct obd_device *obd = data;
322         int val, rc;
323
324         if (obd == NULL)
325                 return 0;
326
327         rc = lprocfs_write_helper(buffer, count, &val);
328         if (rc)
329                 return rc;
330
331         obd->u.cli.cl_checksum = (val ? 1 : 0);
332
333         return count;
334 }
335
336 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
337                                 int *eof, void *data)
338 {
339         struct obd_device *obd = data;
340         int i, len =0;
341         DECLARE_CKSUM_NAME;
342
343         if (obd == NULL)
344                 return 0;
345
346         for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
347                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
348                         continue;
349                 if (obd->u.cli.cl_cksum_type == (1 << i))
350                         len += snprintf(page + len, count - len, "[%s] ",
351                                         cksum_name[i]);
352                 else
353                         len += snprintf(page + len, count - len, "%s ",
354                                         cksum_name[i]);
355         }
356         if (len < count)
357                 len += sprintf(page + len, "\n");
358         return len;
359 }
360
361 static int osc_wd_checksum_type(struct file *file, const char *buffer,
362                                 unsigned long count, void *data)
363 {
364         struct obd_device *obd = data;
365         int i;
366         DECLARE_CKSUM_NAME;
367         char kernbuf[10];
368
369         if (obd == NULL)
370                 return 0;
371
372         if (count > sizeof(kernbuf) - 1)
373                 return -EINVAL;
374         if (cfs_copy_from_user(kernbuf, buffer, count))
375                 return -EFAULT;
376         if (count > 0 && kernbuf[count - 1] == '\n')
377                 kernbuf[count - 1] = '\0';
378         else
379                 kernbuf[count] = '\0';
380
381         for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
382                 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
383                         continue;
384                 if (!strcmp(kernbuf, cksum_name[i])) {
385                        obd->u.cli.cl_cksum_type = 1 << i;
386                        return count;
387                 }
388         }
389         return -EINVAL;
390 }
391
392 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
393                                int *eof, void *data)
394 {
395         struct obd_device *obd = data;
396
397         return snprintf(page, count, "%u\n",
398                         cfs_atomic_read(&obd->u.cli.cl_resends));
399 }
400
401 static int osc_wr_resend_count(struct file *file, const char *buffer,
402                                unsigned long count, void *data)
403 {
404         struct obd_device *obd = data;
405         int val, rc;
406
407         rc = lprocfs_write_helper(buffer, count, &val);
408         if (rc)
409                 return rc;
410
411         if (val < 0)
412                return -EINVAL;
413
414         cfs_atomic_set(&obd->u.cli.cl_resends, val);
415
416         return count;
417 }
418
419 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
420                                      int count, int *eof, void *data)
421 {
422         struct obd_device *obd = data;
423         struct osc_device *od  = obd2osc_dev(obd);
424
425         return snprintf(page, count, "%u\n", od->od_contention_time);
426 }
427
428 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
429                                      unsigned long count, void *data)
430 {
431         struct obd_device *obd = data;
432         struct osc_device *od  = obd2osc_dev(obd);
433
434         return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
435                 count;
436 }
437
438 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
439                                     int count, int *eof, void *data)
440 {
441         struct obd_device *obd = data;
442         struct osc_device *od  = obd2osc_dev(obd);
443
444         return snprintf(page, count, "%u\n", od->od_lockless_truncate);
445 }
446
447 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
448                                     unsigned long count, void *data)
449 {
450         struct obd_device *obd = data;
451         struct osc_device *od  = obd2osc_dev(obd);
452
453         return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
454                 count;
455 }
456
457 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
458                                      int count, int *eof, void *data)
459 {
460         struct obd_device *obd = data;
461         return snprintf(page, count, "%u\n",
462                         cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
463 }
464
465 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
466         const char *buffer, unsigned long count, void *data)
467 {
468         struct obd_device *dev = data;
469         struct client_obd *cli = &dev->u.cli;
470         struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
471         int chunk_mask, rc;
472         __u64 val;
473
474         rc = lprocfs_write_u64_helper(buffer, count, &val);
475         if (rc)
476                 return rc;
477
478         /* if the max_pages is specified in bytes, convert to pages */
479         if (val >= ONE_MB_BRW_SIZE)
480                 val >>= CFS_PAGE_SHIFT;
481
482         LPROCFS_CLIMP_CHECK(dev);
483
484         chunk_mask = ~((1 << (cli->cl_chunkbits - CFS_PAGE_SHIFT)) - 1);
485         /* max_pages_per_rpc must be chunk aligned */
486         val = (val + ~chunk_mask) & chunk_mask;
487         if (val == 0 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
488                 LPROCFS_CLIMP_EXIT(dev);
489                 return -ERANGE;
490         }
491         client_obd_list_lock(&cli->cl_loi_list_lock);
492         cli->cl_max_pages_per_rpc = val;
493         client_obd_list_unlock(&cli->cl_loi_list_lock);
494
495         LPROCFS_CLIMP_EXIT(dev);
496         return count;
497 }
498
499 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
500         { "uuid",            lprocfs_rd_uuid,        0, 0 },
501         { "ping",            0, lprocfs_wr_ping,     0, 0, 0222 },
502         { "connect_flags",   lprocfs_rd_connect_flags, 0, 0 },
503         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
504         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
505         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
506         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
507         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
508         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
509         //{ "filegroups",      lprocfs_rd_filegroups,  0, 0 },
510         { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
511         { "ost_conn_uuid",   lprocfs_rd_conn_uuid, 0, 0 },
512         { "active",          osc_rd_active,
513                              osc_wr_active, 0 },
514         { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
515                                lprocfs_osc_wr_max_pages_per_rpc, 0 },
516         { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
517                                 osc_wr_max_rpcs_in_flight, 0 },
518         { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
519         { "max_dirty_mb",    osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
520         { "osc_cached_mb",   osc_rd_cached_mb,     osc_wr_cached_mb, 0 },
521         { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
522         { "cur_grant_bytes", osc_rd_cur_grant_bytes,
523                              osc_wr_cur_grant_bytes, 0 },
524         { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
525         { "grant_shrink_interval", osc_rd_grant_shrink_interval,
526                                    osc_wr_grant_shrink_interval, 0 },
527         { "checksums",       osc_rd_checksum, osc_wr_checksum, 0 },
528         { "checksum_type",   osc_rd_checksum_type, osc_wd_checksum_type, 0 },
529         { "resend_count",    osc_rd_resend_count, osc_wr_resend_count, 0},
530         { "timeouts",        lprocfs_rd_timeouts,      0, 0 },
531         { "contention_seconds", osc_rd_contention_seconds,
532                                 osc_wr_contention_seconds, 0 },
533         { "lockless_truncate",  osc_rd_lockless_truncate,
534                                 osc_wr_lockless_truncate, 0 },
535         { "import",          lprocfs_rd_import,        lprocfs_wr_import, 0 },
536         { "state",           lprocfs_rd_state,         0, 0 },
537         { "pinger_recov",    lprocfs_rd_pinger_recov,
538                              lprocfs_wr_pinger_recov,  0, 0 },
539         { 0 }
540 };
541
542 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
543         { "num_refs",        lprocfs_rd_numrefs,     0, 0 },
544         { 0 }
545 };
546
547 #define pct(a,b) (b ? a * 100 / b : 0)
548
549 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
550 {
551         struct timeval now;
552         struct obd_device *dev = seq->private;
553         struct client_obd *cli = &dev->u.cli;
554         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
555         int i;
556
557         cfs_gettimeofday(&now);
558
559         client_obd_list_lock(&cli->cl_loi_list_lock);
560
561         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
562                    now.tv_sec, now.tv_usec);
563         seq_printf(seq, "read RPCs in flight:  %d\n",
564                    cli->cl_r_in_flight);
565         seq_printf(seq, "write RPCs in flight: %d\n",
566                    cli->cl_w_in_flight);
567         seq_printf(seq, "pending write pages:  %d\n",
568                    cfs_atomic_read(&cli->cl_pending_w_pages));
569         seq_printf(seq, "pending read pages:   %d\n",
570                    cfs_atomic_read(&cli->cl_pending_r_pages));
571
572         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
573         seq_printf(seq, "pages per rpc         rpcs   %% cum %% |");
574         seq_printf(seq, "       rpcs   %% cum %%\n");
575
576         read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
577         write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
578
579         read_cum = 0;
580         write_cum = 0;
581         for (i = 0; i < OBD_HIST_MAX; i++) {
582                 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
583                 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
584                 read_cum += r;
585                 write_cum += w;
586                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
587                                  1 << i, r, pct(r, read_tot),
588                                  pct(read_cum, read_tot), w,
589                                  pct(w, write_tot),
590                                  pct(write_cum, write_tot));
591                 if (read_cum == read_tot && write_cum == write_tot)
592                         break;
593         }
594
595         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
596         seq_printf(seq, "rpcs in flight        rpcs   %% cum %% |");
597         seq_printf(seq, "       rpcs   %% cum %%\n");
598
599         read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
600         write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
601
602         read_cum = 0;
603         write_cum = 0;
604         for (i = 0; i < OBD_HIST_MAX; i++) {
605                 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
606                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
607                 read_cum += r;
608                 write_cum += w;
609                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
610                                  i, r, pct(r, read_tot),
611                                  pct(read_cum, read_tot), w,
612                                  pct(w, write_tot),
613                                  pct(write_cum, write_tot));
614                 if (read_cum == read_tot && write_cum == write_tot)
615                         break;
616         }
617
618         seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
619         seq_printf(seq, "offset                rpcs   %% cum %% |");
620         seq_printf(seq, "       rpcs   %% cum %%\n");
621
622         read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
623         write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
624
625         read_cum = 0;
626         write_cum = 0;
627         for (i = 0; i < OBD_HIST_MAX; i++) {
628                 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
629                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
630                 read_cum += r;
631                 write_cum += w;
632                 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
633                            (i == 0) ? 0 : 1 << (i - 1),
634                            r, pct(r, read_tot), pct(read_cum, read_tot),
635                            w, pct(w, write_tot), pct(write_cum, write_tot));
636                 if (read_cum == read_tot && write_cum == write_tot)
637                         break;
638         }
639
640         client_obd_list_unlock(&cli->cl_loi_list_lock);
641
642         return 0;
643 }
644 #undef pct
645
646 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
647                                        size_t len, loff_t *off)
648 {
649         struct seq_file *seq = file->private_data;
650         struct obd_device *dev = seq->private;
651         struct client_obd *cli = &dev->u.cli;
652
653         lprocfs_oh_clear(&cli->cl_read_rpc_hist);
654         lprocfs_oh_clear(&cli->cl_write_rpc_hist);
655         lprocfs_oh_clear(&cli->cl_read_page_hist);
656         lprocfs_oh_clear(&cli->cl_write_page_hist);
657         lprocfs_oh_clear(&cli->cl_read_offset_hist);
658         lprocfs_oh_clear(&cli->cl_write_offset_hist);
659
660         return len;
661 }
662
663 LPROC_SEQ_FOPS(osc_rpc_stats);
664
665 static int osc_stats_seq_show(struct seq_file *seq, void *v)
666 {
667         struct timeval now;
668         struct obd_device *dev = seq->private;
669         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
670
671         cfs_gettimeofday(&now);
672
673         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
674                    now.tv_sec, now.tv_usec);
675         seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
676                    stats->os_lockless_writes);
677         seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
678                    stats->os_lockless_reads);
679         seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
680                    stats->os_lockless_truncates);
681         return 0;
682 }
683
684 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
685                                    size_t len, loff_t *off)
686 {
687         struct seq_file *seq = file->private_data;
688         struct obd_device *dev = seq->private;
689         struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
690
691         memset(stats, 0, sizeof(*stats));
692         return len;
693 }
694
695 LPROC_SEQ_FOPS(osc_stats);
696
697 int lproc_osc_attach_seqstat(struct obd_device *dev)
698 {
699         int rc;
700
701         rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
702                                 &osc_stats_fops, dev);
703         if (rc == 0)
704                 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
705                                             &osc_rpc_stats_fops, dev);
706
707         return rc;
708 }
709
710 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
711 {
712         lvars->module_vars = lprocfs_osc_module_vars;
713         lvars->obd_vars    = lprocfs_osc_obd_vars;
714 }
715 #endif /* LPROCFS */