Whamcloud - gitweb
land clio.
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_LLITE
37
38 #include <linux/version.h>
39 #include <lustre_lite.h>
40 #include <lprocfs_status.h>
41 #include <linux/seq_file.h>
42 #include <obd_support.h>
43
44 #include "llite_internal.h"
45
46 struct proc_dir_entry *proc_lustre_fs_root;
47
48 #ifdef LPROCFS
49 /* /proc/lustre/llite mount point registration */
50 extern struct file_operations vvp_dump_pgcache_file_ops;
51 struct file_operations ll_rw_extents_stats_fops;
52 struct file_operations ll_rw_extents_stats_pp_fops;
53 struct file_operations ll_rw_offset_stats_fops;
54
55 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
56                          int *eof, void *data)
57 {
58         struct super_block *sb = (struct super_block *)data;
59         struct obd_statfs osfs;
60         int rc;
61
62         LASSERT(sb != NULL);
63         rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
64                                 OBD_STATFS_NODELAY);
65         if (!rc) {
66               *eof = 1;
67               rc = snprintf(page, count, "%u\n", osfs.os_bsize);
68         }
69
70         return rc;
71 }
72
73 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
74                              int *eof, void *data)
75 {
76         struct super_block *sb = (struct super_block *)data;
77         struct obd_statfs osfs;
78         int rc;
79
80         LASSERT(sb != NULL);
81         rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
82                                 OBD_STATFS_NODELAY);
83         if (!rc) {
84                 __u32 blk_size = osfs.os_bsize >> 10;
85                 __u64 result = osfs.os_blocks;
86
87                 while (blk_size >>= 1)
88                         result <<= 1;
89
90                 *eof = 1;
91                 rc = snprintf(page, count, LPU64"\n", result);
92         }
93         return rc;
94
95 }
96
97 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
98                             int *eof, void *data)
99 {
100         struct super_block *sb = (struct super_block *)data;
101         struct obd_statfs osfs;
102         int rc;
103
104         LASSERT(sb != NULL);
105         rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
106                                 OBD_STATFS_NODELAY);
107         if (!rc) {
108                 __u32 blk_size = osfs.os_bsize >> 10;
109                 __u64 result = osfs.os_bfree;
110
111                 while (blk_size >>= 1)
112                         result <<= 1;
113
114                 *eof = 1;
115                 rc = snprintf(page, count, LPU64"\n", result);
116         }
117         return rc;
118 }
119
120 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
121                              int *eof, void *data)
122 {
123         struct super_block *sb = (struct super_block *)data;
124         struct obd_statfs osfs;
125         int rc;
126
127         LASSERT(sb != NULL);
128         rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
129                                 OBD_STATFS_NODELAY);
130         if (!rc) {
131                 __u32 blk_size = osfs.os_bsize >> 10;
132                 __u64 result = osfs.os_bavail;
133
134                 while (blk_size >>= 1)
135                         result <<= 1;
136
137                 *eof = 1;
138                 rc = snprintf(page, count, LPU64"\n", result);
139         }
140         return rc;
141 }
142
143 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
144                             int *eof, void *data)
145 {
146         struct super_block *sb = (struct super_block *)data;
147         struct obd_statfs osfs;
148         int rc;
149
150         LASSERT(sb != NULL);
151         rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
152                                 OBD_STATFS_NODELAY);
153         if (!rc) {
154                  *eof = 1;
155                  rc = snprintf(page, count, LPU64"\n", osfs.os_files);
156         }
157         return rc;
158 }
159
160 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
161                            int *eof, void *data)
162 {
163         struct super_block *sb = (struct super_block *)data;
164         struct obd_statfs osfs;
165         int rc;
166
167         LASSERT(sb != NULL);
168         rc = ll_statfs_internal(sb, &osfs, cfs_time_current_64() - HZ,
169                                 OBD_STATFS_NODELAY);
170         if (!rc) {
171                  *eof = 1;
172                  rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
173         }
174         return rc;
175
176 }
177
178 static int ll_rd_client_type(char *page, char **start, off_t off, int count,
179                             int *eof, void *data)
180 {
181         struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)data);
182         int rc;
183
184         LASSERT(sbi != NULL);
185
186         *eof = 1;
187         if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
188                 rc = snprintf(page, count, "remote client\n");
189         else
190                 rc = snprintf(page, count, "local client\n");
191
192         return rc;
193 }
194
195 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
196                         int *eof, void *data)
197 {
198         struct super_block *sb = (struct super_block*)data;
199
200         LASSERT(sb != NULL);
201         *eof = 1;
202         return snprintf(page, count, "%s\n", sb->s_type->name);
203 }
204
205 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
206                          int *eof, void *data)
207 {
208         struct super_block *sb = (struct super_block *)data;
209
210         LASSERT(sb != NULL);
211         *eof = 1;
212         return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
213 }
214
215 static int ll_rd_site_stats(char *page, char **start, off_t off,
216                             int count, int *eof, void *data)
217 {
218         struct super_block *sb = data;
219
220         /*
221          * See description of statistical counters in struct cl_site, and
222          * struct lu_site.
223          */
224         return cl_site_stats_print(lu2cl_site(ll_s2sbi(sb)->ll_site),
225                                    page, count);
226 }
227
228 static int ll_rd_max_readahead_mb(char *page, char **start, off_t off,
229                                    int count, int *eof, void *data)
230 {
231         struct super_block *sb = data;
232         struct ll_sb_info *sbi = ll_s2sbi(sb);
233         long pages_number;
234         int mult;
235
236         spin_lock(&sbi->ll_lock);
237         pages_number = sbi->ll_ra_info.ra_max_pages;
238         spin_unlock(&sbi->ll_lock);
239
240         mult = 1 << (20 - PAGE_CACHE_SHIFT);
241         return lprocfs_read_frac_helper(page, count, pages_number, mult);
242 }
243
244 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
245                                    unsigned long count, void *data)
246 {
247         struct super_block *sb = data;
248         struct ll_sb_info *sbi = ll_s2sbi(sb);
249         int mult, rc, pages_number;
250
251         mult = 1 << (20 - CFS_PAGE_SHIFT);
252         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
253         if (rc)
254                 return rc;
255
256         if (pages_number < 0 || pages_number > num_physpages / 2) {
257                 CERROR("can't set file readahead more than %lu MB\n",
258                         num_physpages >> (20 - CFS_PAGE_SHIFT + 1)); /*1/2 of RAM*/
259                 return -ERANGE;
260         }
261
262         spin_lock(&sbi->ll_lock);
263         sbi->ll_ra_info.ra_max_pages = pages_number;
264         spin_unlock(&sbi->ll_lock);
265
266         return count;
267 }
268
269 static int ll_rd_max_read_ahead_whole_mb(char *page, char **start, off_t off,
270                                        int count, int *eof, void *data)
271 {
272         struct super_block *sb = data;
273         struct ll_sb_info *sbi = ll_s2sbi(sb);
274         long pages_number;
275         int mult;
276
277         spin_lock(&sbi->ll_lock);
278         pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
279         spin_unlock(&sbi->ll_lock);
280
281         mult = 1 << (20 - CFS_PAGE_SHIFT);
282         return lprocfs_read_frac_helper(page, count, pages_number, mult);
283 }
284
285 static int ll_wr_max_read_ahead_whole_mb(struct file *file, const char *buffer,
286                                        unsigned long count, void *data)
287 {
288         struct super_block *sb = data;
289         struct ll_sb_info *sbi = ll_s2sbi(sb);
290         int mult, rc, pages_number;
291
292         mult = 1 << (20 - CFS_PAGE_SHIFT);
293         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
294         if (rc)
295                 return rc;
296
297         /* Cap this at the current max readahead window size, the readahead
298          * algorithm does this anyway so it's pointless to set it larger. */
299         if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
300                 CERROR("can't set max_read_ahead_whole_mb more than "
301                        "max_read_ahead_mb: %lu\n",
302                        sbi->ll_ra_info.ra_max_pages >> (20 - CFS_PAGE_SHIFT));
303                 return -ERANGE;
304         }
305
306         spin_lock(&sbi->ll_lock);
307         sbi->ll_ra_info.ra_max_read_ahead_whole_pages = pages_number;
308         spin_unlock(&sbi->ll_lock);
309
310         return count;
311 }
312
313 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
314                                int count, int *eof, void *data)
315 {
316         struct super_block *sb = data;
317         struct ll_sb_info *sbi = ll_s2sbi(sb);
318         long pages_number;
319         int mult;
320
321         spin_lock(&sbi->ll_lock);
322         pages_number = sbi->ll_async_page_max;
323         spin_unlock(&sbi->ll_lock);
324
325         mult = 1 << (20 - CFS_PAGE_SHIFT);
326         return lprocfs_read_frac_helper(page, count, pages_number, mult);;
327 }
328
329 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
330                                   unsigned long count, void *data)
331 {
332         struct super_block *sb = data;
333         struct ll_sb_info *sbi = ll_s2sbi(sb);
334         int mult, rc, pages_number;
335
336         mult = 1 << (20 - CFS_PAGE_SHIFT);
337         rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
338         if (rc)
339                 return rc;
340
341         if (pages_number < 0 || pages_number > num_physpages) {
342                 CERROR("can't set max cache more than %lu MB\n",
343                         num_physpages >> (20 - CFS_PAGE_SHIFT));
344                 return -ERANGE;
345         }
346
347         spin_lock(&sbi->ll_lock);
348         sbi->ll_async_page_max = pages_number ;
349         spin_unlock(&sbi->ll_lock);
350
351         if (!sbi->ll_dt_exp)
352                 /* Not set up yet, don't call llap_shrink_cache */
353                 return count;
354
355         return count;
356 }
357
358 static int ll_rd_checksum(char *page, char **start, off_t off,
359                           int count, int *eof, void *data)
360 {
361         struct super_block *sb = data;
362         struct ll_sb_info *sbi = ll_s2sbi(sb);
363
364         return snprintf(page, count, "%u\n",
365                         (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
366 }
367
368 static int ll_wr_checksum(struct file *file, const char *buffer,
369                           unsigned long count, void *data)
370 {
371         struct super_block *sb = data;
372         struct ll_sb_info *sbi = ll_s2sbi(sb);
373         int val, rc;
374
375         if (!sbi->ll_dt_exp)
376                 /* Not set up yet */
377                 return -EAGAIN;
378
379         rc = lprocfs_write_helper(buffer, count, &val);
380         if (rc)
381                 return rc;
382         if (val)
383                 sbi->ll_flags |= LL_SBI_CHECKSUM;
384         else
385                 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
386
387         rc = obd_set_info_async(sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
388                                 KEY_CHECKSUM, sizeof(val), &val, NULL);
389         if (rc)
390                 CWARN("Failed to set OSC checksum flags: %d\n", rc);
391
392         return count;
393 }
394
395 static int ll_rd_max_rw_chunk(char *page, char **start, off_t off,
396                           int count, int *eof, void *data)
397 {
398         struct super_block *sb = data;
399
400         return snprintf(page, count, "%lu\n", ll_s2sbi(sb)->ll_max_rw_chunk);
401 }
402
403 static int ll_wr_max_rw_chunk(struct file *file, const char *buffer,
404                           unsigned long count, void *data)
405 {
406         struct super_block *sb = data;
407         int rc, val;
408
409         rc = lprocfs_write_helper(buffer, count, &val);
410         if (rc)
411                 return rc;
412         ll_s2sbi(sb)->ll_max_rw_chunk = val;
413         return count;
414 }
415
416 static int ll_rd_track_id(char *page, int count, void *data,
417                           enum stats_track_type type)
418 {
419         struct super_block *sb = data;
420
421         if (ll_s2sbi(sb)->ll_stats_track_type == type) {
422                 return snprintf(page, count, "%d\n",
423                                 ll_s2sbi(sb)->ll_stats_track_id);
424
425         } else if (ll_s2sbi(sb)->ll_stats_track_type == STATS_TRACK_ALL) {
426                 return snprintf(page, count, "0 (all)\n");
427         } else {
428                 return snprintf(page, count, "untracked\n");
429         }
430 }
431
432 static int ll_wr_track_id(const char *buffer, unsigned long count, void *data,
433                           enum stats_track_type type)
434 {
435         struct super_block *sb = data;
436         int rc, pid;
437
438         rc = lprocfs_write_helper(buffer, count, &pid);
439         if (rc)
440                 return rc;
441         ll_s2sbi(sb)->ll_stats_track_id = pid;
442         if (pid == 0)
443                 ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
444         else
445                 ll_s2sbi(sb)->ll_stats_track_type = type;
446         lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
447         return count;
448 }
449
450 static int ll_rd_track_pid(char *page, char **start, off_t off,
451                           int count, int *eof, void *data)
452 {
453         return (ll_rd_track_id(page, count, data, STATS_TRACK_PID));
454 }
455
456 static int ll_wr_track_pid(struct file *file, const char *buffer,
457                           unsigned long count, void *data)
458 {
459         return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PID));
460 }
461
462 static int ll_rd_track_ppid(char *page, char **start, off_t off,
463                           int count, int *eof, void *data)
464 {
465         return (ll_rd_track_id(page, count, data, STATS_TRACK_PPID));
466 }
467
468 static int ll_wr_track_ppid(struct file *file, const char *buffer,
469                           unsigned long count, void *data)
470 {
471         return (ll_wr_track_id(buffer, count, data, STATS_TRACK_PPID));
472 }
473
474 static int ll_rd_track_gid(char *page, char **start, off_t off,
475                           int count, int *eof, void *data)
476 {
477         return (ll_rd_track_id(page, count, data, STATS_TRACK_GID));
478 }
479
480 static int ll_wr_track_gid(struct file *file, const char *buffer,
481                           unsigned long count, void *data)
482 {
483         return (ll_wr_track_id(buffer, count, data, STATS_TRACK_GID));
484 }
485
486 static int ll_rd_statahead_max(char *page, char **start, off_t off,
487                                int count, int *eof, void *data)
488 {
489         struct super_block *sb = data;
490         struct ll_sb_info *sbi = ll_s2sbi(sb);
491
492         return snprintf(page, count, "%u\n", sbi->ll_sa_max);
493 }
494
495 static int ll_wr_statahead_max(struct file *file, const char *buffer,
496                                unsigned long count, void *data)
497 {
498         struct super_block *sb = data;
499         struct ll_sb_info *sbi = ll_s2sbi(sb);
500         int val, rc;
501
502         rc = lprocfs_write_helper(buffer, count, &val);
503         if (rc)
504                 return rc;
505
506         if (val >= 0 && val <= LL_SA_RPC_MAX)
507                 sbi->ll_sa_max = val;
508         else
509                 CERROR("Bad statahead_max value %d. Valid values are in the "
510                        "range [0, %d]\n", val, LL_SA_RPC_MAX);
511
512         return count;
513 }
514
515 static int ll_rd_statahead_stats(char *page, char **start, off_t off,
516                                  int count, int *eof, void *data)
517 {
518         struct super_block *sb = data;
519         struct ll_sb_info *sbi = ll_s2sbi(sb);
520
521         return snprintf(page, count,
522                         "statahead wrong: %u\n"
523                         "statahead total: %u\n"
524                         "ls blocked:      %llu\n"
525                         "ls cached:       %llu\n"
526                         "hit count:       %llu\n"
527                         "miss count:      %llu\n",
528                         sbi->ll_sa_wrong,
529                         sbi->ll_sa_total,
530                         sbi->ll_sa_blocked,
531                         sbi->ll_sa_cached,
532                         sbi->ll_sa_hit,
533                         sbi->ll_sa_miss);
534 }
535
536 static struct lprocfs_vars lprocfs_llite_obd_vars[] = {
537         { "uuid",         ll_rd_sb_uuid,          0, 0 },
538         //{ "mntpt_path",   ll_rd_path,             0, 0 },
539         { "fstype",       ll_rd_fstype,           0, 0 },
540         { "site",         ll_rd_site_stats,       0, 0 },
541         { "blocksize",    ll_rd_blksize,          0, 0 },
542         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
543         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
544         { "kbytesavail",  ll_rd_kbytesavail,      0, 0 },
545         { "filestotal",   ll_rd_filestotal,       0, 0 },
546         { "filesfree",    ll_rd_filesfree,        0, 0 },
547         { "client_type",  ll_rd_client_type,      0, 0 },
548         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
549         { "max_read_ahead_mb", ll_rd_max_readahead_mb,
550                                ll_wr_max_readahead_mb, 0 },
551         { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
552                                      ll_wr_max_read_ahead_whole_mb, 0 },
553         { "max_cached_mb",    ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
554         { "checksum_pages",   ll_rd_checksum, ll_wr_checksum, 0 },
555         { "max_rw_chunk",     ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
556         { "stats_track_pid",  ll_rd_track_pid, ll_wr_track_pid, 0 },
557         { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
558         { "stats_track_gid",  ll_rd_track_gid, ll_wr_track_gid, 0 },
559         { "statahead_max",    ll_rd_statahead_max, ll_wr_statahead_max, 0 },
560         { "statahead_stats",  ll_rd_statahead_stats, 0, 0 },
561         { 0 }
562 };
563
564 #define MAX_STRING_SIZE 128
565
566 struct llite_file_opcode {
567         __u32       opcode;
568         __u32       type;
569         const char *opname;
570 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
571         /* file operation */
572         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
573         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
574         { LPROC_LL_WB_WRITEPAGE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
575                                    "writeback_from_writepage" },
576         { LPROC_LL_WB_PRESSURE,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
577                                    "writeback_from_pressure" },
578         { LPROC_LL_WB_OK,          LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
579                                    "writeback_ok_pages" },
580         { LPROC_LL_WB_FAIL,        LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
581                                    "writeback_failed_pages" },
582         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
583                                    "read_bytes" },
584         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
585                                    "write_bytes" },
586         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
587                                    "brw_read" },
588         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
589                                    "brw_write" },
590
591         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
592         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
593         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
594         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
595         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
596         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
597         /* inode operation */
598         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
599         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "truncate" },
600         { LPROC_LL_LOCKLESS_TRUNC, LPROCFS_TYPE_REGS, "lockless_truncate"},
601         { LPROC_LL_FLOCK,          LPROCFS_TYPE_REGS, "flock" },
602         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
603         /* special inode operation */
604         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
605         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
606         { LPROC_LL_SETXATTR,       LPROCFS_TYPE_REGS, "setxattr" },
607         { LPROC_LL_GETXATTR,       LPROCFS_TYPE_REGS, "getxattr" },
608         { LPROC_LL_LISTXATTR,      LPROCFS_TYPE_REGS, "listxattr" },
609         { LPROC_LL_REMOVEXATTR,    LPROCFS_TYPE_REGS, "removexattr" },
610         { LPROC_LL_INODE_PERM,     LPROCFS_TYPE_REGS, "inode_permission" },
611         { LPROC_LL_DIRECT_READ,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
612                                    "direct_read" },
613         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
614                                    "direct_write" },
615         { LPROC_LL_LOCKLESS_READ,  LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
616                                    "lockless_read_bytes" },
617         { LPROC_LL_LOCKLESS_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
618                                    "lockless_write_bytes" },
619
620 };
621
622 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
623 {
624         if (!sbi->ll_stats)
625                 return;
626         if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
627                 lprocfs_counter_add(sbi->ll_stats, op, count);
628         else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
629                  sbi->ll_stats_track_id == current->pid)
630                 lprocfs_counter_add(sbi->ll_stats, op, count);
631         else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
632                  sbi->ll_stats_track_id == current->p_pptr->pid)
633                 lprocfs_counter_add(sbi->ll_stats, op, count);
634         else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
635                  sbi->ll_stats_track_id == current->gid)
636                 lprocfs_counter_add(sbi->ll_stats, op, count);
637 }
638 EXPORT_SYMBOL(ll_stats_ops_tally);
639
640 static const char *ra_stat_string[] = {
641         [RA_STAT_HIT] = "hits",
642         [RA_STAT_MISS] = "misses",
643         [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
644         [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
645         [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
646         [RA_STAT_FAILED_MATCH] = "failed lock match",
647         [RA_STAT_DISCARDED] = "read but discarded",
648         [RA_STAT_ZERO_LEN] = "zero length file",
649         [RA_STAT_ZERO_WINDOW] = "zero size window",
650         [RA_STAT_EOF] = "read-ahead to EOF",
651         [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
652         [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
653 };
654
655
656 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
657                                 struct super_block *sb, char *osc, char *mdc)
658 {
659         struct lprocfs_vars lvars[2];
660         struct lustre_sb_info *lsi = s2lsi(sb);
661         struct ll_sb_info *sbi = ll_s2sbi(sb);
662         struct obd_device *obd;
663         char name[MAX_STRING_SIZE + 1], *ptr;
664         int err, id, len, rc;
665         ENTRY;
666
667         memset(lvars, 0, sizeof(lvars));
668
669         name[MAX_STRING_SIZE] = '\0';
670         lvars[0].name = name;
671
672         LASSERT(sbi != NULL);
673         LASSERT(mdc != NULL);
674         LASSERT(osc != NULL);
675
676         /* Get fsname */
677         len = strlen(lsi->lsi_lmd->lmd_profile);
678         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
679         if (ptr && (strcmp(ptr, "-client") == 0))
680                 len -= 7;
681
682         /* Mount info */
683         snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
684                  lsi->lsi_lmd->lmd_profile, sb);
685
686         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
687         if (IS_ERR(sbi->ll_proc_root)) {
688                 err = PTR_ERR(sbi->ll_proc_root);
689                 sbi->ll_proc_root = NULL;
690                 RETURN(err);
691         }
692
693         rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
694                                 &vvp_dump_pgcache_file_ops, sbi);
695         if (rc)
696                 CWARN("Error adding the dump_page_cache file\n");
697
698         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
699                                 &ll_rw_extents_stats_fops, sbi);
700         if (rc)
701                 CWARN("Error adding the extent_stats file\n");
702
703         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
704                                 0644, &ll_rw_extents_stats_pp_fops, sbi);
705         if (rc)
706                 CWARN("Error adding the extents_stats_per_process file\n");
707
708         rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
709                                 &ll_rw_offset_stats_fops, sbi);
710         if (rc)
711                 CWARN("Error adding the offset_stats file\n");
712
713         /* File operations stats */
714         sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
715                                             LPROCFS_STATS_FLAG_PERCPU);
716         if (sbi->ll_stats == NULL)
717                 GOTO(out, err = -ENOMEM);
718         /* do counter init */
719         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
720                 __u32 type = llite_opcode_table[id].type;
721                 void *ptr = NULL;
722                 if (type & LPROCFS_TYPE_REGS)
723                         ptr = "regs";
724                 else if (type & LPROCFS_TYPE_BYTES)
725                         ptr = "bytes";
726                 else if (type & LPROCFS_TYPE_PAGES)
727                         ptr = "pages";
728                 lprocfs_counter_init(sbi->ll_stats,
729                                      llite_opcode_table[id].opcode,
730                                      (type & LPROCFS_CNTR_AVGMINMAX),
731                                      llite_opcode_table[id].opname, ptr);
732         }
733         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
734         if (err)
735                 GOTO(out, err);
736
737         sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
738                                                LPROCFS_STATS_FLAG_PERCPU);
739         if (sbi->ll_ra_stats == NULL)
740                 GOTO(out, err = -ENOMEM);
741
742         for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
743                 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
744                                      ra_stat_string[id], "pages");
745         err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
746                                      sbi->ll_ra_stats);
747         if (err)
748                 GOTO(out, err);
749
750
751         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
752         if (err)
753                 GOTO(out, err);
754
755         /* MDC info */
756         obd = class_name2obd(mdc);
757
758         LASSERT(obd != NULL);
759         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
760         LASSERT(obd->obd_type->typ_name != NULL);
761
762         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
763                  obd->obd_type->typ_name);
764         lvars[0].read_fptr = lprocfs_rd_name;
765         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
766         if (err)
767                 GOTO(out, err);
768
769         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
770         lvars[0].read_fptr = lprocfs_rd_uuid;
771         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
772         if (err)
773                 GOTO(out, err);
774
775         /* OSC */
776         obd = class_name2obd(osc);
777
778         LASSERT(obd != NULL);
779         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
780         LASSERT(obd->obd_type->typ_name != NULL);
781
782         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
783                  obd->obd_type->typ_name);
784         lvars[0].read_fptr = lprocfs_rd_name;
785         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
786         if (err)
787                 GOTO(out, err);
788
789         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
790         lvars[0].read_fptr = lprocfs_rd_uuid;
791         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
792 out:
793         if (err) {
794                 lprocfs_remove(&sbi->ll_proc_root);
795                 lprocfs_free_stats(&sbi->ll_ra_stats);
796                 lprocfs_free_stats(&sbi->ll_stats);
797         }
798         RETURN(err);
799 }
800
801 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
802 {
803         if (sbi->ll_proc_root) {
804                 lprocfs_remove(&sbi->ll_proc_root);
805                 lprocfs_free_stats(&sbi->ll_ra_stats);
806                 lprocfs_free_stats(&sbi->ll_stats);
807         }
808 }
809 #undef MAX_STRING_SIZE
810
811 #define pct(a,b) (b ? a * 100 / b : 0)
812
813 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
814                                    struct seq_file *seq, int which)
815 {
816         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
817         unsigned long start, end, r, w;
818         char *unitp = "KMGTPEZY";
819         int i, units = 10;
820         struct per_process_info *pp_info = &io_extents->pp_extents[which];
821
822         read_cum = 0;
823         write_cum = 0;
824         start = 0;
825
826         for(i = 0; i < LL_HIST_MAX; i++) {
827                 read_tot += pp_info->pp_r_hist.oh_buckets[i];
828                 write_tot += pp_info->pp_w_hist.oh_buckets[i];
829         }
830
831         for(i = 0; i < LL_HIST_MAX; i++) {
832                 r = pp_info->pp_r_hist.oh_buckets[i];
833                 w = pp_info->pp_w_hist.oh_buckets[i];
834                 read_cum += r;
835                 write_cum += w;
836                 end = 1 << (i + LL_HIST_START - units);
837                 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu  | "
838                            "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
839                            (i == LL_HIST_MAX - 1) ? '+' : ' ',
840                            r, pct(r, read_tot), pct(read_cum, read_tot),
841                            w, pct(w, write_tot), pct(write_cum, write_tot));
842                 start = end;
843                 if (start == 1<<10) {
844                         start = 1;
845                         units += 10;
846                         unitp++;
847                 }
848                 if (read_cum == read_tot && write_cum == write_tot)
849                         break;
850         }
851 }
852
853 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
854 {
855         struct timeval now;
856         struct ll_sb_info *sbi = seq->private;
857         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
858         int k;
859
860         do_gettimeofday(&now);
861
862         if (!sbi->ll_rw_stats_on) {
863                 seq_printf(seq, "disabled\n"
864                                 "write anything in this file to activate, "
865                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
866                 return 0;
867         }
868         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
869                    now.tv_sec, now.tv_usec);
870         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
871         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
872                    "extents", "calls", "%", "cum%",
873                    "calls", "%", "cum%");
874         spin_lock(&sbi->ll_pp_extent_lock);
875         for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
876                 if(io_extents->pp_extents[k].pid != 0) {
877                         seq_printf(seq, "\nPID: %d\n",
878                                    io_extents->pp_extents[k].pid);
879                         ll_display_extents_info(io_extents, seq, k);
880                 }
881         }
882         spin_unlock(&sbi->ll_pp_extent_lock);
883         return 0;
884 }
885
886 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
887                                                 const char *buf, size_t len,
888                                                 loff_t *off)
889 {
890         struct seq_file *seq = file->private_data;
891         struct ll_sb_info *sbi = seq->private;
892         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
893         int i;
894         int value = 1, rc = 0;
895
896         rc = lprocfs_write_helper(buf, len, &value);
897         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
898                        strcmp(buf, "Disabled") == 0))
899                 value = 0;
900
901         if (value == 0)
902                 sbi->ll_rw_stats_on = 0;
903         else
904                 sbi->ll_rw_stats_on = 1;
905
906         spin_lock(&sbi->ll_pp_extent_lock);
907         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
908                 io_extents->pp_extents[i].pid = 0;
909                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
910                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
911         }
912         spin_unlock(&sbi->ll_pp_extent_lock);
913         return len;
914 }
915
916 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
917
918 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
919 {
920         struct timeval now;
921         struct ll_sb_info *sbi = seq->private;
922         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
923
924         do_gettimeofday(&now);
925
926         if (!sbi->ll_rw_stats_on) {
927                 seq_printf(seq, "disabled\n"
928                                 "write anything in this file to activate, "
929                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
930                 return 0;
931         }
932         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
933                    now.tv_sec, now.tv_usec);
934
935         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
936         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
937                    "extents", "calls", "%", "cum%",
938                    "calls", "%", "cum%");
939         spin_lock(&sbi->ll_lock);
940         ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
941         spin_unlock(&sbi->ll_lock);
942
943         return 0;
944 }
945
946 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
947                                         size_t len, loff_t *off)
948 {
949         struct seq_file *seq = file->private_data;
950         struct ll_sb_info *sbi = seq->private;
951         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
952         int i;
953         int value = 1, rc = 0;
954
955         rc = lprocfs_write_helper(buf, len, &value);
956         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
957                        strcmp(buf, "Disabled") == 0))
958                 value = 0;
959
960         if (value == 0)
961                 sbi->ll_rw_stats_on = 0;
962         else
963                 sbi->ll_rw_stats_on = 1;
964         spin_lock(&sbi->ll_pp_extent_lock);
965         for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
966         {
967                 io_extents->pp_extents[i].pid = 0;
968                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
969                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
970         }
971         spin_unlock(&sbi->ll_pp_extent_lock);
972
973         return len;
974 }
975
976 LPROC_SEQ_FOPS(ll_rw_extents_stats);
977
978 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
979                        struct ll_file_data *file, loff_t pos,
980                        size_t count, int rw)
981 {
982         int i, cur = -1;
983         struct ll_rw_process_info *process;
984         struct ll_rw_process_info *offset;
985         int *off_count = &sbi->ll_rw_offset_entry_count;
986         int *process_count = &sbi->ll_offset_process_count;
987         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
988
989         if(!sbi->ll_rw_stats_on)
990                 return;
991         process = sbi->ll_rw_process_info;
992         offset = sbi->ll_rw_offset_info;
993
994         spin_lock(&sbi->ll_pp_extent_lock);
995         /* Extent statistics */
996         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
997                 if(io_extents->pp_extents[i].pid == pid) {
998                         cur = i;
999                         break;
1000                 }
1001         }
1002
1003         if (cur == -1) {
1004                 /* new process */
1005                 sbi->ll_extent_process_count =
1006                         (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1007                 cur = sbi->ll_extent_process_count;
1008                 io_extents->pp_extents[cur].pid = pid;
1009                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1010                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1011         }
1012
1013         for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1014              (i < (LL_HIST_MAX - 1)); i++);
1015         if (rw == 0) {
1016                 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1017                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1018         } else {
1019                 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1020                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1021         }
1022         spin_unlock(&sbi->ll_pp_extent_lock);
1023
1024         spin_lock(&sbi->ll_process_lock);
1025         /* Offset statistics */
1026         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1027                 if (process[i].rw_pid == pid) {
1028                         if (process[i].rw_last_file != file) {
1029                                 process[i].rw_range_start = pos;
1030                                 process[i].rw_last_file_pos = pos + count;
1031                                 process[i].rw_smallest_extent = count;
1032                                 process[i].rw_largest_extent = count;
1033                                 process[i].rw_offset = 0;
1034                                 process[i].rw_last_file = file;
1035                                 spin_unlock(&sbi->ll_process_lock);
1036                                 return;
1037                         }
1038                         if (process[i].rw_last_file_pos != pos) {
1039                                 *off_count =
1040                                     (*off_count + 1) % LL_OFFSET_HIST_MAX;
1041                                 offset[*off_count].rw_op = process[i].rw_op;
1042                                 offset[*off_count].rw_pid = pid;
1043                                 offset[*off_count].rw_range_start =
1044                                         process[i].rw_range_start;
1045                                 offset[*off_count].rw_range_end =
1046                                         process[i].rw_last_file_pos;
1047                                 offset[*off_count].rw_smallest_extent =
1048                                         process[i].rw_smallest_extent;
1049                                 offset[*off_count].rw_largest_extent =
1050                                         process[i].rw_largest_extent;
1051                                 offset[*off_count].rw_offset =
1052                                         process[i].rw_offset;
1053                                 process[i].rw_op = rw;
1054                                 process[i].rw_range_start = pos;
1055                                 process[i].rw_smallest_extent = count;
1056                                 process[i].rw_largest_extent = count;
1057                                 process[i].rw_offset = pos -
1058                                         process[i].rw_last_file_pos;
1059                         }
1060                         if(process[i].rw_smallest_extent > count)
1061                                 process[i].rw_smallest_extent = count;
1062                         if(process[i].rw_largest_extent < count)
1063                                 process[i].rw_largest_extent = count;
1064                         process[i].rw_last_file_pos = pos + count;
1065                         spin_unlock(&sbi->ll_process_lock);
1066                         return;
1067                 }
1068         }
1069         *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1070         process[*process_count].rw_pid = pid;
1071         process[*process_count].rw_op = rw;
1072         process[*process_count].rw_range_start = pos;
1073         process[*process_count].rw_last_file_pos = pos + count;
1074         process[*process_count].rw_smallest_extent = count;
1075         process[*process_count].rw_largest_extent = count;
1076         process[*process_count].rw_offset = 0;
1077         process[*process_count].rw_last_file = file;
1078         spin_unlock(&sbi->ll_process_lock);
1079 }
1080
1081 char lpszt[] = LPSZ;
1082
1083 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1084 {
1085         struct timeval now;
1086         struct ll_sb_info *sbi = seq->private;
1087         struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1088         struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1089         char format[50];
1090         int i;
1091
1092         do_gettimeofday(&now);
1093
1094         if (!sbi->ll_rw_stats_on) {
1095                 seq_printf(seq, "disabled\n"
1096                                 "write anything in this file to activate, "
1097                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
1098                 return 0;
1099         }
1100         spin_lock(&sbi->ll_process_lock);
1101
1102         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
1103                    now.tv_sec, now.tv_usec);
1104         seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1105                    "R/W", "PID", "RANGE START", "RANGE END",
1106                    "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1107         sprintf(format, "%s%s%s%s%s\n",
1108                 "%3c %10d %14Lu %14Lu %17", lpszt+1, " %17", lpszt+1, " %14Ld");
1109         /* We stored the discontiguous offsets here; print them first */
1110         for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1111                 if (offset[i].rw_pid != 0)
1112                         /* Is there a way to snip the '%' off of LPSZ? */
1113                         seq_printf(seq, format,
1114                                    offset[i].rw_op ? 'W' : 'R',
1115                                    offset[i].rw_pid,
1116                                    offset[i].rw_range_start,
1117                                    offset[i].rw_range_end,
1118                                    offset[i].rw_smallest_extent,
1119                                    offset[i].rw_largest_extent,
1120                                    offset[i].rw_offset);
1121         }
1122         /* Then print the current offsets for each process */
1123         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1124                 if (process[i].rw_pid != 0)
1125                         seq_printf(seq, format,
1126                                    process[i].rw_op ? 'W' : 'R',
1127                                    process[i].rw_pid,
1128                                    process[i].rw_range_start,
1129                                    process[i].rw_last_file_pos,
1130                                    process[i].rw_smallest_extent,
1131                                    process[i].rw_largest_extent,
1132                                    process[i].rw_offset);
1133         }
1134         spin_unlock(&sbi->ll_process_lock);
1135
1136         return 0;
1137 }
1138
1139 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1140                                        size_t len, loff_t *off)
1141 {
1142         struct seq_file *seq = file->private_data;
1143         struct ll_sb_info *sbi = seq->private;
1144         struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1145         struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1146         int value = 1, rc = 0;
1147
1148         rc = lprocfs_write_helper(buf, len, &value);
1149
1150         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1151                            strcmp(buf, "Disabled") == 0))
1152                 value = 0;
1153
1154         if (value == 0)
1155                 sbi->ll_rw_stats_on = 0;
1156         else
1157                 sbi->ll_rw_stats_on = 1;
1158
1159         spin_lock(&sbi->ll_process_lock);
1160         sbi->ll_offset_process_count = 0;
1161         sbi->ll_rw_offset_entry_count = 0;
1162         memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1163                LL_PROCESS_HIST_MAX);
1164         memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1165                LL_OFFSET_HIST_MAX);
1166         spin_unlock(&sbi->ll_process_lock);
1167
1168         return len;
1169 }
1170
1171 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1172
1173 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1174 {
1175     lvars->module_vars  = NULL;
1176     lvars->obd_vars     = lprocfs_llite_obd_vars;
1177 }
1178 #endif /* LPROCFS */