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