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