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