Whamcloud - gitweb
LU-925 agl: async glimpse lock process in CLIO stack
[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 struct lprocfs_vars lprocfs_llite_obd_vars[] = {
642         { "uuid",         ll_rd_sb_uuid,          0, 0 },
643         //{ "mntpt_path",   ll_rd_path,             0, 0 },
644         { "fstype",       ll_rd_fstype,           0, 0 },
645         { "site",         ll_rd_site_stats,       0, 0 },
646         { "blocksize",    ll_rd_blksize,          0, 0 },
647         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
648         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
649         { "kbytesavail",  ll_rd_kbytesavail,      0, 0 },
650         { "filestotal",   ll_rd_filestotal,       0, 0 },
651         { "filesfree",    ll_rd_filesfree,        0, 0 },
652         { "client_type",  ll_rd_client_type,      0, 0 },
653         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
654         { "max_read_ahead_mb", ll_rd_max_readahead_mb,
655                                ll_wr_max_readahead_mb, 0 },
656         { "max_read_ahead_per_file_mb", ll_rd_max_readahead_per_file_mb,
657                                         ll_wr_max_readahead_per_file_mb, 0 },
658         { "max_read_ahead_whole_mb", ll_rd_max_read_ahead_whole_mb,
659                                      ll_wr_max_read_ahead_whole_mb, 0 },
660         { "max_cached_mb",    ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
661         { "checksum_pages",   ll_rd_checksum, ll_wr_checksum, 0 },
662         { "max_rw_chunk",     ll_rd_max_rw_chunk, ll_wr_max_rw_chunk, 0 },
663         { "stats_track_pid",  ll_rd_track_pid, ll_wr_track_pid, 0 },
664         { "stats_track_ppid", ll_rd_track_ppid, ll_wr_track_ppid, 0 },
665         { "stats_track_gid",  ll_rd_track_gid, ll_wr_track_gid, 0 },
666         { "statahead_max",    ll_rd_statahead_max, ll_wr_statahead_max, 0 },
667         { "statahead_agl",    ll_rd_statahead_agl, ll_wr_statahead_agl, 0 },
668         { "statahead_stats",  ll_rd_statahead_stats, 0, 0 },
669         { "lazystatfs",         ll_rd_lazystatfs, ll_wr_lazystatfs, 0 },
670         { 0 }
671 };
672
673 #define MAX_STRING_SIZE 128
674
675 struct llite_file_opcode {
676         __u32       opcode;
677         __u32       type;
678         const char *opname;
679 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
680         /* file operation */
681         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
682         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
683         { LPROC_LL_WB_WRITEPAGE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
684                                    "writeback_from_writepage" },
685         { LPROC_LL_WB_PRESSURE,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
686                                    "writeback_from_pressure" },
687         { LPROC_LL_WB_OK,          LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
688                                    "writeback_ok_pages" },
689         { LPROC_LL_WB_FAIL,        LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
690                                    "writeback_failed_pages" },
691         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
692                                    "read_bytes" },
693         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
694                                    "write_bytes" },
695         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
696                                    "brw_read" },
697         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
698                                    "brw_write" },
699         { LPROC_LL_OSC_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
700                                    "osc_read" },
701         { LPROC_LL_OSC_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
702                                    "osc_write" },
703
704         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
705         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
706         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
707         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
708         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
709         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
710         /* inode operation */
711         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
712         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "truncate" },
713         { LPROC_LL_LOCKLESS_TRUNC, LPROCFS_TYPE_REGS, "lockless_truncate"},
714         { LPROC_LL_FLOCK,          LPROCFS_TYPE_REGS, "flock" },
715         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
716         /* special inode operation */
717         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
718         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
719         { LPROC_LL_SETXATTR,       LPROCFS_TYPE_REGS, "setxattr" },
720         { LPROC_LL_GETXATTR,       LPROCFS_TYPE_REGS, "getxattr" },
721         { LPROC_LL_LISTXATTR,      LPROCFS_TYPE_REGS, "listxattr" },
722         { LPROC_LL_REMOVEXATTR,    LPROCFS_TYPE_REGS, "removexattr" },
723         { LPROC_LL_INODE_PERM,     LPROCFS_TYPE_REGS, "inode_permission" },
724         { LPROC_LL_DIRECT_READ,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
725                                    "direct_read" },
726         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
727                                    "direct_write" },
728         { LPROC_LL_LOCKLESS_READ,  LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
729                                    "lockless_read_bytes" },
730         { LPROC_LL_LOCKLESS_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
731                                    "lockless_write_bytes" },
732
733 };
734
735 void ll_stats_ops_tally(struct ll_sb_info *sbi, int op, int count)
736 {
737         if (!sbi->ll_stats)
738                 return;
739         if (sbi->ll_stats_track_type == STATS_TRACK_ALL)
740                 lprocfs_counter_add(sbi->ll_stats, op, count);
741         else if (sbi->ll_stats_track_type == STATS_TRACK_PID &&
742                  sbi->ll_stats_track_id == current->pid)
743                 lprocfs_counter_add(sbi->ll_stats, op, count);
744         else if (sbi->ll_stats_track_type == STATS_TRACK_PPID &&
745                  sbi->ll_stats_track_id == current->parent->pid)
746                 lprocfs_counter_add(sbi->ll_stats, op, count);
747         else if (sbi->ll_stats_track_type == STATS_TRACK_GID &&
748                  sbi->ll_stats_track_id == cfs_curproc_gid())
749                 lprocfs_counter_add(sbi->ll_stats, op, count);
750 }
751 EXPORT_SYMBOL(ll_stats_ops_tally);
752
753 static const char *ra_stat_string[] = {
754         [RA_STAT_HIT] = "hits",
755         [RA_STAT_MISS] = "misses",
756         [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
757         [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
758         [RA_STAT_FAILED_GRAB_PAGE] = "failed grab_cache_page",
759         [RA_STAT_FAILED_MATCH] = "failed lock match",
760         [RA_STAT_DISCARDED] = "read but discarded",
761         [RA_STAT_ZERO_LEN] = "zero length file",
762         [RA_STAT_ZERO_WINDOW] = "zero size window",
763         [RA_STAT_EOF] = "read-ahead to EOF",
764         [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
765         [RA_STAT_WRONG_GRAB_PAGE] = "wrong page from grab_cache_page",
766 };
767
768
769 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
770                                 struct super_block *sb, char *osc, char *mdc)
771 {
772         struct lprocfs_vars lvars[2];
773         struct lustre_sb_info *lsi = s2lsi(sb);
774         struct ll_sb_info *sbi = ll_s2sbi(sb);
775         struct obd_device *obd;
776         char name[MAX_STRING_SIZE + 1], *ptr;
777         int err, id, len, rc;
778         ENTRY;
779
780         memset(lvars, 0, sizeof(lvars));
781
782         name[MAX_STRING_SIZE] = '\0';
783         lvars[0].name = name;
784
785         LASSERT(sbi != NULL);
786         LASSERT(mdc != NULL);
787         LASSERT(osc != NULL);
788
789         /* Get fsname */
790         len = strlen(lsi->lsi_lmd->lmd_profile);
791         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
792         if (ptr && (strcmp(ptr, "-client") == 0))
793                 len -= 7;
794
795         /* Mount info */
796         snprintf(name, MAX_STRING_SIZE, "%.*s-%p", len,
797                  lsi->lsi_lmd->lmd_profile, sb);
798
799         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
800         if (IS_ERR(sbi->ll_proc_root)) {
801                 err = PTR_ERR(sbi->ll_proc_root);
802                 sbi->ll_proc_root = NULL;
803                 RETURN(err);
804         }
805
806         rc = lprocfs_seq_create(sbi->ll_proc_root, "dump_page_cache", 0444,
807                                 &vvp_dump_pgcache_file_ops, sbi);
808         if (rc)
809                 CWARN("Error adding the dump_page_cache file\n");
810
811         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats", 0644,
812                                 &ll_rw_extents_stats_fops, sbi);
813         if (rc)
814                 CWARN("Error adding the extent_stats file\n");
815
816         rc = lprocfs_seq_create(sbi->ll_proc_root, "extents_stats_per_process",
817                                 0644, &ll_rw_extents_stats_pp_fops, sbi);
818         if (rc)
819                 CWARN("Error adding the extents_stats_per_process file\n");
820
821         rc = lprocfs_seq_create(sbi->ll_proc_root, "offset_stats", 0644,
822                                 &ll_rw_offset_stats_fops, sbi);
823         if (rc)
824                 CWARN("Error adding the offset_stats file\n");
825
826         /* File operations stats */
827         sbi->ll_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES,
828                                             LPROCFS_STATS_FLAG_NONE);
829         if (sbi->ll_stats == NULL)
830                 GOTO(out, err = -ENOMEM);
831         /* do counter init */
832         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
833                 __u32 type = llite_opcode_table[id].type;
834                 void *ptr = NULL;
835                 if (type & LPROCFS_TYPE_REGS)
836                         ptr = "regs";
837                 else if (type & LPROCFS_TYPE_BYTES)
838                         ptr = "bytes";
839                 else if (type & LPROCFS_TYPE_PAGES)
840                         ptr = "pages";
841                 lprocfs_counter_init(sbi->ll_stats,
842                                      llite_opcode_table[id].opcode,
843                                      (type & LPROCFS_CNTR_AVGMINMAX),
844                                      llite_opcode_table[id].opname, ptr);
845         }
846         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", sbi->ll_stats);
847         if (err)
848                 GOTO(out, err);
849
850         sbi->ll_ra_stats = lprocfs_alloc_stats(ARRAY_SIZE(ra_stat_string),
851                                                LPROCFS_STATS_FLAG_NONE);
852         if (sbi->ll_ra_stats == NULL)
853                 GOTO(out, err = -ENOMEM);
854
855         for (id = 0; id < ARRAY_SIZE(ra_stat_string); id++)
856                 lprocfs_counter_init(sbi->ll_ra_stats, id, 0,
857                                      ra_stat_string[id], "pages");
858         err = lprocfs_register_stats(sbi->ll_proc_root, "read_ahead_stats",
859                                      sbi->ll_ra_stats);
860         if (err)
861                 GOTO(out, err);
862
863
864         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_llite_obd_vars, sb);
865         if (err)
866                 GOTO(out, err);
867
868         /* MDC info */
869         obd = class_name2obd(mdc);
870
871         LASSERT(obd != NULL);
872         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
873         LASSERT(obd->obd_type->typ_name != NULL);
874
875         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
876                  obd->obd_type->typ_name);
877         lvars[0].read_fptr = lprocfs_rd_name;
878         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
879         if (err)
880                 GOTO(out, err);
881
882         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
883         lvars[0].read_fptr = lprocfs_rd_uuid;
884         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
885         if (err)
886                 GOTO(out, err);
887
888         /* OSC */
889         obd = class_name2obd(osc);
890
891         LASSERT(obd != NULL);
892         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
893         LASSERT(obd->obd_type->typ_name != NULL);
894
895         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
896                  obd->obd_type->typ_name);
897         lvars[0].read_fptr = lprocfs_rd_name;
898         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
899         if (err)
900                 GOTO(out, err);
901
902         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
903         lvars[0].read_fptr = lprocfs_rd_uuid;
904         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
905 out:
906         if (err) {
907                 lprocfs_remove(&sbi->ll_proc_root);
908                 lprocfs_free_stats(&sbi->ll_ra_stats);
909                 lprocfs_free_stats(&sbi->ll_stats);
910         }
911         RETURN(err);
912 }
913
914 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
915 {
916         if (sbi->ll_proc_root) {
917                 lprocfs_remove(&sbi->ll_proc_root);
918                 lprocfs_free_stats(&sbi->ll_ra_stats);
919                 lprocfs_free_stats(&sbi->ll_stats);
920         }
921 }
922 #undef MAX_STRING_SIZE
923
924 #define pct(a,b) (b ? a * 100 / b : 0)
925
926 static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
927                                    struct seq_file *seq, int which)
928 {
929         unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
930         unsigned long start, end, r, w;
931         char *unitp = "KMGTPEZY";
932         int i, units = 10;
933         struct per_process_info *pp_info = &io_extents->pp_extents[which];
934
935         read_cum = 0;
936         write_cum = 0;
937         start = 0;
938
939         for(i = 0; i < LL_HIST_MAX; i++) {
940                 read_tot += pp_info->pp_r_hist.oh_buckets[i];
941                 write_tot += pp_info->pp_w_hist.oh_buckets[i];
942         }
943
944         for(i = 0; i < LL_HIST_MAX; i++) {
945                 r = pp_info->pp_r_hist.oh_buckets[i];
946                 w = pp_info->pp_w_hist.oh_buckets[i];
947                 read_cum += r;
948                 write_cum += w;
949                 end = 1 << (i + LL_HIST_START - units);
950                 seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4lu %4lu  | "
951                            "%14lu %4lu %4lu\n", start, *unitp, end, *unitp,
952                            (i == LL_HIST_MAX - 1) ? '+' : ' ',
953                            r, pct(r, read_tot), pct(read_cum, read_tot),
954                            w, pct(w, write_tot), pct(write_cum, write_tot));
955                 start = end;
956                 if (start == 1<<10) {
957                         start = 1;
958                         units += 10;
959                         unitp++;
960                 }
961                 if (read_cum == read_tot && write_cum == write_tot)
962                         break;
963         }
964 }
965
966 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
967 {
968         struct timeval now;
969         struct ll_sb_info *sbi = seq->private;
970         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
971         int k;
972
973         cfs_gettimeofday(&now);
974
975         if (!sbi->ll_rw_stats_on) {
976                 seq_printf(seq, "disabled\n"
977                                 "write anything in this file to activate, "
978                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
979                 return 0;
980         }
981         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
982                    now.tv_sec, now.tv_usec);
983         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
984         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
985                    "extents", "calls", "%", "cum%",
986                    "calls", "%", "cum%");
987         cfs_spin_lock(&sbi->ll_pp_extent_lock);
988         for(k = 0; k < LL_PROCESS_HIST_MAX; k++) {
989                 if(io_extents->pp_extents[k].pid != 0) {
990                         seq_printf(seq, "\nPID: %d\n",
991                                    io_extents->pp_extents[k].pid);
992                         ll_display_extents_info(io_extents, seq, k);
993                 }
994         }
995         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
996         return 0;
997 }
998
999 static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
1000                                                 const char *buf, size_t len,
1001                                                 loff_t *off)
1002 {
1003         struct seq_file *seq = file->private_data;
1004         struct ll_sb_info *sbi = seq->private;
1005         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1006         int i;
1007         int value = 1, rc = 0;
1008
1009         rc = lprocfs_write_helper(buf, len, &value);
1010         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1011                        strcmp(buf, "Disabled") == 0))
1012                 value = 0;
1013
1014         if (value == 0)
1015                 sbi->ll_rw_stats_on = 0;
1016         else
1017                 sbi->ll_rw_stats_on = 1;
1018
1019         cfs_spin_lock(&sbi->ll_pp_extent_lock);
1020         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1021                 io_extents->pp_extents[i].pid = 0;
1022                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1023                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1024         }
1025         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1026         return len;
1027 }
1028
1029 LPROC_SEQ_FOPS(ll_rw_extents_stats_pp);
1030
1031 static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
1032 {
1033         struct timeval now;
1034         struct ll_sb_info *sbi = seq->private;
1035         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1036
1037         cfs_gettimeofday(&now);
1038
1039         if (!sbi->ll_rw_stats_on) {
1040                 seq_printf(seq, "disabled\n"
1041                                 "write anything in this file to activate, "
1042                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
1043                 return 0;
1044         }
1045         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
1046                    now.tv_sec, now.tv_usec);
1047
1048         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
1049         seq_printf(seq, "%13s   %14s %4s %4s  | %14s %4s %4s\n",
1050                    "extents", "calls", "%", "cum%",
1051                    "calls", "%", "cum%");
1052         cfs_spin_lock(&sbi->ll_lock);
1053         ll_display_extents_info(io_extents, seq, LL_PROCESS_HIST_MAX);
1054         cfs_spin_unlock(&sbi->ll_lock);
1055
1056         return 0;
1057 }
1058
1059 static ssize_t ll_rw_extents_stats_seq_write(struct file *file, const char *buf,
1060                                         size_t len, loff_t *off)
1061 {
1062         struct seq_file *seq = file->private_data;
1063         struct ll_sb_info *sbi = seq->private;
1064         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1065         int i;
1066         int value = 1, rc = 0;
1067
1068         rc = lprocfs_write_helper(buf, len, &value);
1069         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1070                        strcmp(buf, "Disabled") == 0))
1071                 value = 0;
1072
1073         if (value == 0)
1074                 sbi->ll_rw_stats_on = 0;
1075         else
1076                 sbi->ll_rw_stats_on = 1;
1077         cfs_spin_lock(&sbi->ll_pp_extent_lock);
1078         for(i = 0; i <= LL_PROCESS_HIST_MAX; i++)
1079         {
1080                 io_extents->pp_extents[i].pid = 0;
1081                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_r_hist);
1082                 lprocfs_oh_clear(&io_extents->pp_extents[i].pp_w_hist);
1083         }
1084         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1085
1086         return len;
1087 }
1088
1089 LPROC_SEQ_FOPS(ll_rw_extents_stats);
1090
1091 void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
1092                        struct ll_file_data *file, loff_t pos,
1093                        size_t count, int rw)
1094 {
1095         int i, cur = -1;
1096         struct ll_rw_process_info *process;
1097         struct ll_rw_process_info *offset;
1098         int *off_count = &sbi->ll_rw_offset_entry_count;
1099         int *process_count = &sbi->ll_offset_process_count;
1100         struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
1101
1102         if(!sbi->ll_rw_stats_on)
1103                 return;
1104         process = sbi->ll_rw_process_info;
1105         offset = sbi->ll_rw_offset_info;
1106
1107         cfs_spin_lock(&sbi->ll_pp_extent_lock);
1108         /* Extent statistics */
1109         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1110                 if(io_extents->pp_extents[i].pid == pid) {
1111                         cur = i;
1112                         break;
1113                 }
1114         }
1115
1116         if (cur == -1) {
1117                 /* new process */
1118                 sbi->ll_extent_process_count =
1119                         (sbi->ll_extent_process_count + 1) % LL_PROCESS_HIST_MAX;
1120                 cur = sbi->ll_extent_process_count;
1121                 io_extents->pp_extents[cur].pid = pid;
1122                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_r_hist);
1123                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
1124         }
1125
1126         for(i = 0; (count >= (1 << LL_HIST_START << i)) &&
1127              (i < (LL_HIST_MAX - 1)); i++);
1128         if (rw == 0) {
1129                 io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
1130                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_r_hist.oh_buckets[i]++;
1131         } else {
1132                 io_extents->pp_extents[cur].pp_w_hist.oh_buckets[i]++;
1133                 io_extents->pp_extents[LL_PROCESS_HIST_MAX].pp_w_hist.oh_buckets[i]++;
1134         }
1135         cfs_spin_unlock(&sbi->ll_pp_extent_lock);
1136
1137         cfs_spin_lock(&sbi->ll_process_lock);
1138         /* Offset statistics */
1139         for (i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1140                 if (process[i].rw_pid == pid) {
1141                         if (process[i].rw_last_file != file) {
1142                                 process[i].rw_range_start = pos;
1143                                 process[i].rw_last_file_pos = pos + count;
1144                                 process[i].rw_smallest_extent = count;
1145                                 process[i].rw_largest_extent = count;
1146                                 process[i].rw_offset = 0;
1147                                 process[i].rw_last_file = file;
1148                                 cfs_spin_unlock(&sbi->ll_process_lock);
1149                                 return;
1150                         }
1151                         if (process[i].rw_last_file_pos != pos) {
1152                                 *off_count =
1153                                     (*off_count + 1) % LL_OFFSET_HIST_MAX;
1154                                 offset[*off_count].rw_op = process[i].rw_op;
1155                                 offset[*off_count].rw_pid = pid;
1156                                 offset[*off_count].rw_range_start =
1157                                         process[i].rw_range_start;
1158                                 offset[*off_count].rw_range_end =
1159                                         process[i].rw_last_file_pos;
1160                                 offset[*off_count].rw_smallest_extent =
1161                                         process[i].rw_smallest_extent;
1162                                 offset[*off_count].rw_largest_extent =
1163                                         process[i].rw_largest_extent;
1164                                 offset[*off_count].rw_offset =
1165                                         process[i].rw_offset;
1166                                 process[i].rw_op = rw;
1167                                 process[i].rw_range_start = pos;
1168                                 process[i].rw_smallest_extent = count;
1169                                 process[i].rw_largest_extent = count;
1170                                 process[i].rw_offset = pos -
1171                                         process[i].rw_last_file_pos;
1172                         }
1173                         if(process[i].rw_smallest_extent > count)
1174                                 process[i].rw_smallest_extent = count;
1175                         if(process[i].rw_largest_extent < count)
1176                                 process[i].rw_largest_extent = count;
1177                         process[i].rw_last_file_pos = pos + count;
1178                         cfs_spin_unlock(&sbi->ll_process_lock);
1179                         return;
1180                 }
1181         }
1182         *process_count = (*process_count + 1) % LL_PROCESS_HIST_MAX;
1183         process[*process_count].rw_pid = pid;
1184         process[*process_count].rw_op = rw;
1185         process[*process_count].rw_range_start = pos;
1186         process[*process_count].rw_last_file_pos = pos + count;
1187         process[*process_count].rw_smallest_extent = count;
1188         process[*process_count].rw_largest_extent = count;
1189         process[*process_count].rw_offset = 0;
1190         process[*process_count].rw_last_file = file;
1191         cfs_spin_unlock(&sbi->ll_process_lock);
1192 }
1193
1194 static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
1195 {
1196         struct timeval now;
1197         struct ll_sb_info *sbi = seq->private;
1198         struct ll_rw_process_info *offset = sbi->ll_rw_offset_info;
1199         struct ll_rw_process_info *process = sbi->ll_rw_process_info;
1200         int i;
1201
1202         cfs_gettimeofday(&now);
1203
1204         if (!sbi->ll_rw_stats_on) {
1205                 seq_printf(seq, "disabled\n"
1206                                 "write anything in this file to activate, "
1207                                 "then 0 or \"[D/d]isabled\" to deactivate\n");
1208                 return 0;
1209         }
1210         cfs_spin_lock(&sbi->ll_process_lock);
1211
1212         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
1213                    now.tv_sec, now.tv_usec);
1214         seq_printf(seq, "%3s %10s %14s %14s %17s %17s %14s\n",
1215                    "R/W", "PID", "RANGE START", "RANGE END",
1216                    "SMALLEST EXTENT", "LARGEST EXTENT", "OFFSET");
1217         /* We stored the discontiguous offsets here; print them first */
1218         for(i = 0; i < LL_OFFSET_HIST_MAX; i++) {
1219                 if (offset[i].rw_pid != 0)
1220                         seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1221                                    offset[i].rw_op ? 'W' : 'R',
1222                                    offset[i].rw_pid,
1223                                    offset[i].rw_range_start,
1224                                    offset[i].rw_range_end,
1225                                    (unsigned long)offset[i].rw_smallest_extent,
1226                                    (unsigned long)offset[i].rw_largest_extent,
1227                                    offset[i].rw_offset);
1228         }
1229         /* Then print the current offsets for each process */
1230         for(i = 0; i < LL_PROCESS_HIST_MAX; i++) {
1231                 if (process[i].rw_pid != 0)
1232                         seq_printf(seq,"%3c %10d %14Lu %14Lu %17lu %17lu %14Lu",
1233                                    process[i].rw_op ? 'W' : 'R',
1234                                    process[i].rw_pid,
1235                                    process[i].rw_range_start,
1236                                    process[i].rw_last_file_pos,
1237                                    (unsigned long)process[i].rw_smallest_extent,
1238                                    (unsigned long)process[i].rw_largest_extent,
1239                                    process[i].rw_offset);
1240         }
1241         cfs_spin_unlock(&sbi->ll_process_lock);
1242
1243         return 0;
1244 }
1245
1246 static ssize_t ll_rw_offset_stats_seq_write(struct file *file, const char *buf,
1247                                        size_t len, loff_t *off)
1248 {
1249         struct seq_file *seq = file->private_data;
1250         struct ll_sb_info *sbi = seq->private;
1251         struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
1252         struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
1253         int value = 1, rc = 0;
1254
1255         rc = lprocfs_write_helper(buf, len, &value);
1256
1257         if (rc < 0 && (strcmp(buf, "disabled") == 0 ||
1258                            strcmp(buf, "Disabled") == 0))
1259                 value = 0;
1260
1261         if (value == 0)
1262                 sbi->ll_rw_stats_on = 0;
1263         else
1264                 sbi->ll_rw_stats_on = 1;
1265
1266         cfs_spin_lock(&sbi->ll_process_lock);
1267         sbi->ll_offset_process_count = 0;
1268         sbi->ll_rw_offset_entry_count = 0;
1269         memset(process_info, 0, sizeof(struct ll_rw_process_info) *
1270                LL_PROCESS_HIST_MAX);
1271         memset(offset_info, 0, sizeof(struct ll_rw_process_info) *
1272                LL_OFFSET_HIST_MAX);
1273         cfs_spin_unlock(&sbi->ll_process_lock);
1274
1275         return len;
1276 }
1277
1278 LPROC_SEQ_FOPS(ll_rw_offset_stats);
1279
1280 void lprocfs_llite_init_vars(struct lprocfs_static_vars *lvars)
1281 {
1282     lvars->module_vars  = NULL;
1283     lvars->obd_vars     = lprocfs_llite_obd_vars;
1284 }
1285 #endif /* LPROCFS */