Whamcloud - gitweb
back the mmap code out of b1_2
[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 <linux/lustre_lite.h>
26 #include <linux/lprocfs_status.h>
27 #include <linux/seq_file.h>
28 #include <linux/obd_support.h>
29
30 #include "llite_internal.h"
31
32 /* /proc/lustre/llite mount point registration */
33 struct proc_dir_entry *proc_lustre_fs_root;
34 struct file_operations llite_dump_pgcache_fops;
35 struct file_operations ll_ra_stats_fops;
36
37 #ifndef LPROCFS
38 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
39                                 struct super_block *sb, char *osc, char *mdc)
40 {
41         return 0;
42 }
43 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
44 #else
45
46 long long mnt_instance;
47
48 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
49                          int *eof, void *data)
50 {
51         struct super_block *sb = (struct super_block *)data;
52         struct obd_statfs osfs;
53         int rc;
54
55         LASSERT(sb != NULL);
56         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
57         if (!rc) {
58               *eof = 1;
59               rc = snprintf(page, count, "%u\n", osfs.os_bsize);
60         }
61
62         return rc;
63 }
64
65 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
66                              int *eof, void *data)
67 {
68         struct super_block *sb = (struct super_block *)data;
69         struct obd_statfs osfs;
70         int rc;
71
72         LASSERT(sb != NULL);
73         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
74         if (!rc) {
75                 __u32 blk_size = osfs.os_bsize >> 10;
76                 __u64 result = osfs.os_blocks;
77
78                 while (blk_size >>= 1)
79                         result <<= 1;
80
81                 *eof = 1;
82                 rc = snprintf(page, count, LPU64"\n", result);
83         }
84         return rc;
85
86 }
87
88 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
89                             int *eof, void *data)
90 {
91         struct super_block *sb = (struct super_block *)data;
92         struct obd_statfs osfs;
93         int rc;
94
95         LASSERT(sb != NULL);
96         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
97         if (!rc) {
98                 __u32 blk_size = osfs.os_bsize >> 10;
99                 __u64 result = osfs.os_bfree;
100
101                 while (blk_size >>= 1)
102                         result <<= 1;
103
104                 *eof = 1;
105                 rc = snprintf(page, count, LPU64"\n", result);
106         }
107         return rc;
108 }
109
110 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
111                              int *eof, void *data)
112 {
113         struct super_block *sb = (struct super_block *)data;
114         struct obd_statfs osfs;
115         int rc;
116
117         LASSERT(sb != NULL);
118         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
119         if (!rc) {
120                 __u32 blk_size = osfs.os_bsize >> 10;
121                 __u64 result = osfs.os_bavail;
122
123                 while (blk_size >>= 1)
124                         result <<= 1;
125
126                 *eof = 1;
127                 rc = snprintf(page, count, LPU64"\n", result);
128         }
129         return rc;
130 }
131
132 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
133                             int *eof, void *data)
134 {
135         struct super_block *sb = (struct super_block *)data;
136         struct obd_statfs osfs;
137         int rc;
138
139         LASSERT(sb != NULL);
140         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
141         if (!rc) {
142                  *eof = 1;
143                  rc = snprintf(page, count, LPU64"\n", osfs.os_files);
144         }
145         return rc;
146 }
147
148 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
149                            int *eof, void *data)
150 {
151         struct super_block *sb = (struct super_block *)data;
152         struct obd_statfs osfs;
153         int rc;
154
155         LASSERT(sb != NULL);
156         rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
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_fstype(char *page, char **start, off_t off, int count,
166                         int *eof, void *data)
167 {
168         struct super_block *sb = (struct super_block*)data;
169
170         LASSERT(sb != NULL);
171         *eof = 1;
172         return snprintf(page, count, "%s\n", sb->s_type->name);
173 }
174
175 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
176                          int *eof, void *data)
177 {
178         struct super_block *sb = (struct super_block *)data;
179
180         LASSERT(sb != NULL);
181         *eof = 1;
182         return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
183 }
184
185 static int ll_rd_read_ahead(char *page, char **start, off_t off, int count,
186                             int *eof, void *data)
187 {
188         struct super_block *sb = (struct super_block*)data;
189         struct ll_sb_info *sbi = ll_s2sbi(sb);
190         int val, rc;
191         ENTRY;
192
193         *eof = 1;
194         val = (sbi->ll_flags & LL_SBI_READAHEAD) ? 1 : 0;
195         rc = snprintf(page, count, "%d\n", val);
196         RETURN(rc);
197 }
198
199 static int ll_wr_read_ahead(struct file *file, const char *buffer,
200                             unsigned long count, void *data)
201 {
202         struct super_block *sb = (struct super_block*)data;
203         struct ll_sb_info *sbi = ll_s2sbi(sb);
204         int readahead;
205         ENTRY;
206
207         if (sscanf(buffer, "%d", &readahead) != 1)
208                 RETURN(-EINVAL);        
209
210         if (readahead)
211                 sbi->ll_flags |= LL_SBI_READAHEAD;
212         else
213                 sbi->ll_flags &= ~LL_SBI_READAHEAD;
214
215         RETURN(count);
216 }
217
218 static int ll_rd_max_read_ahead_mb(char *page, char **start, off_t off, 
219                                    int count, int *eof, void *data)
220 {
221         struct super_block *sb = data;
222         struct ll_sb_info *sbi = ll_s2sbi(sb);
223         unsigned val;
224
225         spin_lock(&sbi->ll_lock);
226         val = (sbi->ll_ra_info.ra_max_pages << PAGE_CACHE_SHIFT) >> 20;
227         spin_unlock(&sbi->ll_lock);
228
229         return snprintf(page, count, "%u\n", val);
230 }
231
232 static int ll_wr_max_read_ahead_mb(struct file *file, const char *buffer,
233                                    unsigned long count, void *data)
234 {
235         struct super_block *sb = data;
236         struct ll_sb_info *sbi = ll_s2sbi(sb);
237         int val, rc;
238
239         rc = lprocfs_write_helper(buffer, count, &val);
240         if (rc)
241                 return rc;
242
243         if (val < 0 || val > (num_physpages << PAGE_SHIFT) >> 20)
244                 return -ERANGE;
245
246         spin_lock(&sbi->ll_lock);
247         sbi->ll_ra_info.ra_max_pages = (val << 20) >> PAGE_CACHE_SHIFT;
248         spin_unlock(&sbi->ll_lock);
249
250         return count;
251 }
252
253 static struct lprocfs_vars lprocfs_obd_vars[] = {
254         { "uuid",         ll_rd_sb_uuid,          0, 0 },
255         //{ "mntpt_path",   ll_rd_path,             0, 0 },
256         { "fstype",       ll_rd_fstype,           0, 0 },
257         { "blocksize",    ll_rd_blksize,          0, 0 },
258         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
259         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
260         { "kbytesavail",  ll_rd_kbytesavail,      0, 0 },
261         { "filestotal",   ll_rd_filestotal,       0, 0 },
262         { "filesfree",    ll_rd_filesfree,        0, 0 },
263         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
264         { "read_ahead",   ll_rd_read_ahead, ll_wr_read_ahead, 0 },
265         { "max_read_ahead_mb",   ll_rd_max_read_ahead_mb, 
266                                  ll_wr_max_read_ahead_mb, 0 },
267         { 0 }
268 };
269
270 #define MAX_STRING_SIZE 128
271
272 struct llite_file_opcode {
273         __u32       opcode;
274         __u32       type;
275         const char *opname;
276 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
277         /* file operation */
278         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
279         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
280         { LPROC_LL_WB_WRITEPAGE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
281                                    "writeback_from_writepage" },
282         { LPROC_LL_WB_PRESSURE,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
283                                    "writeback_from_pressure" },
284         { LPROC_LL_WB_OK,          LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
285                                    "writeback_ok_pages" },
286         { LPROC_LL_WB_FAIL,        LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
287                                    "writeback_failed_pages" },
288         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
289                                    "read_bytes" },
290         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
291                                    "write_bytes" },
292         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
293                                    "brw_read" },
294         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
295                                    "brw_write" },
296
297         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
298         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
299         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
300         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
301         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
302         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
303         /* inode operation */
304         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
305         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "punch" },
306 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
307         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
308 #else
309         { LPROC_LL_REVALIDATE,     LPROCFS_TYPE_REGS, "getattr" },
310 #endif
311         /* special inode operation */
312         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
313         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
314         { LPROC_LL_DIRECT_READ,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
315                                    "direct_read" },
316         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
317                                    "direct_write" },
318
319 };
320
321 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
322                                 struct super_block *sb, char *osc, char *mdc)
323 {
324         struct lprocfs_vars lvars[2];
325         struct ll_sb_info *sbi = ll_s2sbi(sb);
326         struct obd_device *obd;
327         char name[MAX_STRING_SIZE + 1];
328         int err, id;
329         struct lprocfs_stats *svc_stats = NULL;
330         struct proc_dir_entry *entry;
331         ENTRY;
332
333         memset(lvars, 0, sizeof(lvars));
334
335         name[MAX_STRING_SIZE] = '\0';
336         lvars[0].name = name;
337
338         LASSERT(sbi != NULL);
339         LASSERT(mdc != NULL);
340         LASSERT(osc != NULL);
341
342         /* Mount info */
343         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
344
345         mnt_instance++;
346         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
347         if (IS_ERR(sbi->ll_proc_root)) {
348                 err = PTR_ERR(sbi->ll_proc_root);
349                 sbi->ll_proc_root = NULL;
350                 RETURN(err);
351         }
352
353         entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
354         if (entry == NULL)
355                 GOTO(out, err = -ENOMEM);
356         entry->proc_fops = &llite_dump_pgcache_fops;
357         entry->data = sbi;
358
359         entry = create_proc_entry("read_ahead_stats", 0444, sbi->ll_proc_root);
360         if (entry == NULL)
361                 GOTO(out, err = -ENOMEM);
362         entry->proc_fops = &ll_ra_stats_fops;
363         entry->data = sbi;
364
365         svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
366         if (svc_stats == NULL) {
367                 err = -ENOMEM;
368                 goto out;
369         }
370         /* do counter init */
371         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
372                 __u32 type = llite_opcode_table[id].type;
373                 void *ptr = NULL;
374                 if (type & LPROCFS_TYPE_REGS)
375                         ptr = "regs";
376                 else {
377                         if (type & LPROCFS_TYPE_BYTES)
378                                 ptr = "bytes";
379                         else {
380                                 if (type & LPROCFS_TYPE_PAGES)
381                                         ptr = "pages";
382                         }
383                 }
384                 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
385                                      (type & LPROCFS_CNTR_AVGMINMAX),
386                                      llite_opcode_table[id].opname, ptr);
387         }
388         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
389         if (err)
390                 goto out;
391         else
392                 sbi->ll_stats = svc_stats;
393         /* need place to keep svc_stats */
394
395         /* Static configuration info */
396         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
397         if (err)
398                 goto out;
399
400         /* MDC info */
401         obd = class_name2obd(mdc);
402
403         LASSERT(obd != NULL);
404         LASSERT(obd->obd_type != NULL);
405         LASSERT(obd->obd_type->typ_name != NULL);
406
407         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
408                  obd->obd_type->typ_name);
409         lvars[0].read_fptr = lprocfs_rd_name;
410         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
411         if (err)
412                 goto out;
413
414         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
415         lvars[0].read_fptr = lprocfs_rd_uuid;
416         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
417         if (err)
418                 goto out;
419
420         /* OSC */
421         obd = class_name2obd(osc);
422
423         LASSERT(obd != NULL);
424         LASSERT(obd->obd_type != NULL);
425         LASSERT(obd->obd_type->typ_name != NULL);
426
427         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
428                  obd->obd_type->typ_name);
429         lvars[0].read_fptr = lprocfs_rd_name;
430         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
431         if (err)
432                 goto out;
433
434         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
435         lvars[0].read_fptr = lprocfs_rd_uuid;
436         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
437 out:
438         if (err) {
439                 if (svc_stats)
440                         lprocfs_free_stats(svc_stats);
441                 if (sbi->ll_proc_root)
442                         lprocfs_remove(sbi->ll_proc_root);
443         }
444         RETURN(err);
445 }
446
447 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
448 {
449         if (sbi->ll_proc_root) {
450                 struct proc_dir_entry *file_stats =
451                         lprocfs_srch(sbi->ll_proc_root, "stats");
452
453                 if (file_stats) {
454                         lprocfs_free_stats(sbi->ll_stats);
455                         lprocfs_remove(file_stats);
456                 }
457         }
458 }
459 #undef MAX_STRING_SIZE
460
461 static struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
462                                                     struct list_head *list)
463 {
464         struct ll_async_page *llap;
465         struct list_head *pos;
466
467         list_for_each(pos, list) {
468                 if (pos == &sbi->ll_pglist)
469                         return NULL;
470                 llap = list_entry(pos, struct ll_async_page, llap_proc_item);
471                 if (llap->llap_page == NULL)
472                         continue;
473                 return llap;
474         }
475         LBUG();
476         return NULL;
477 }
478
479 #define seq_page_flag(seq, page, flag, has_flags) do {                  \
480                 if (test_bit(PG_##flag, &(page)->flags)) {              \
481                         if (!has_flags)                                 \
482                                 has_flags = 1;                          \
483                         else                                            \
484                                 seq_putc(seq, '|');                     \
485                         seq_puts(seq, #flag);                           \
486                 }                                                       \
487         } while(0);
488
489 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
490 {
491         struct ll_async_page *llap, *dummy_llap = seq->private;
492         struct ll_sb_info *sbi = dummy_llap->llap_cookie;
493
494         /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
495          * it in our own state */
496         if (dummy_llap->llap_magic == 0) {
497                 seq_printf(seq, "generation | llap .cookie | page ");
498                 seq_printf(seq, "inode .index [ page flags ]\n");
499                 return 0;
500         }
501
502         spin_lock(&sbi->ll_lock);
503
504         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
505         if (llap != NULL)  {
506                 int has_flags = 0;
507                 struct page *page = llap->llap_page;
508
509                 seq_printf(seq, "%lu | %p %p | %p %p %lu [", 
510                                 sbi->ll_pglist_gen, 
511                                 llap, llap->llap_cookie,
512                                 page, page->mapping->host, page->index);
513                 seq_page_flag(seq, page, locked, has_flags);
514                 seq_page_flag(seq, page, error, has_flags);
515                 seq_page_flag(seq, page, referenced, has_flags);
516                 seq_page_flag(seq, page, uptodate, has_flags);
517                 seq_page_flag(seq, page, dirty, has_flags);
518                 seq_page_flag(seq, page, highmem, has_flags);
519                 if (!has_flags)
520                         seq_puts(seq, "-]\n");
521                 else 
522                         seq_puts(seq, "]\n");
523         }
524
525         spin_unlock(&sbi->ll_lock);
526
527         return 0;
528 }
529
530 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
531 {
532         struct ll_async_page *llap = seq->private;
533
534         if (llap->llap_magic == 2)
535                 return NULL;
536
537         return (void *)1;
538 }
539
540 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v, 
541                                          loff_t *pos)
542 {
543         struct ll_async_page *llap, *dummy_llap = seq->private;
544         struct ll_sb_info *sbi = dummy_llap->llap_cookie;
545
546         /* bail if we just displayed the banner */
547         if (dummy_llap->llap_magic == 0) {
548                 dummy_llap->llap_magic = 1;
549                 return dummy_llap;
550         }
551
552         /* we've just displayed the llap that is after us in the list.
553          * we advance to a position beyond it, returning null if there
554          * isn't another llap in the list beyond that new position. */
555         spin_lock(&sbi->ll_lock);
556         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
557         list_del_init(&dummy_llap->llap_proc_item);
558         if (llap) {
559                 list_add(&dummy_llap->llap_proc_item, &llap->llap_proc_item);
560                 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
561         }
562         spin_unlock(&sbi->ll_lock);
563
564         ++*pos;
565         if (llap == NULL) {
566                 dummy_llap->llap_magic = 2;
567                 return NULL;
568         }
569         return dummy_llap;
570 }
571
572 static void llite_dump_pgcache_seq_stop(struct seq_file *seq, void *v)
573 {
574 }
575
576 struct seq_operations llite_dump_pgcache_seq_sops = {
577         .start = llite_dump_pgcache_seq_start,
578         .stop = llite_dump_pgcache_seq_stop,
579         .next = llite_dump_pgcache_seq_next,
580         .show = llite_dump_pgcache_seq_show,
581 };
582
583 /* we're displaying llaps in a list_head list.  we don't want to hold a lock
584  * while we walk the entire list, and we don't want to have to seek into
585  * the right position in the list as an app advances with many syscalls.  we
586  * allocate a dummy llap and hang it off file->private.  its position in
587  * the list records where the app is currently displaying.  this way our
588  * seq .start and .stop don't actually do anything.  .next returns null
589  * when the dummy hits the end of the list which eventually leads to .release
590  * where we tear down.  this kind of displaying is super-racey, so we put
591  * a generation counter on the list so the output shows when the list
592  * changes between reads.
593  */
594 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
595 {
596         struct proc_dir_entry *dp = PDE(inode);
597         struct ll_async_page *llap;
598         struct seq_file *seq;
599         struct ll_sb_info *sbi = dp->data;
600         int rc;
601
602         OBD_ALLOC_GFP(llap, sizeof(*llap), GFP_KERNEL);
603         if (llap == NULL)
604                 return -ENOMEM;
605         llap->llap_page = NULL;
606         llap->llap_cookie = sbi;
607         llap->llap_magic = 0;
608
609         rc = seq_open(file, &llite_dump_pgcache_seq_sops);
610         if (rc) {
611                 OBD_FREE(llap, sizeof(*llap));
612                 return rc;
613         }
614         seq = file->private_data;
615         seq->private = llap;
616
617         spin_lock(&sbi->ll_lock);
618         list_add(&llap->llap_proc_item, &sbi->ll_pglist);
619         spin_unlock(&sbi->ll_lock);
620
621         return 0;
622 }
623
624 static int llite_dump_pgcache_seq_release(struct inode *inode,
625                                           struct file *file)
626 {
627         struct seq_file *seq = file->private_data;
628         struct ll_async_page *llap = seq->private;
629         struct ll_sb_info *sbi = llap->llap_cookie;
630
631         spin_lock(&sbi->ll_lock);
632         if (!list_empty(&llap->llap_proc_item))
633                 list_del_init(&llap->llap_proc_item);
634         spin_unlock(&sbi->ll_lock);
635         OBD_FREE(llap, sizeof(*llap));
636
637         return seq_release(inode, file);
638 }
639
640 struct file_operations llite_dump_pgcache_fops = {
641         .owner   = THIS_MODULE,
642         .open    = llite_dump_pgcache_seq_open,
643         .read    = seq_read,
644         .release = llite_dump_pgcache_seq_release,
645 };
646
647 static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
648 {
649         struct timeval now;
650         struct ll_sb_info *sbi = seq->private;
651         struct ll_ra_info *ra = &sbi->ll_ra_info;
652         int i;
653         static char *ra_stat_strings[] = {
654                 [RA_STAT_HIT] = "hits",
655                 [RA_STAT_MISS] = "misses",
656                 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
657                 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
658                 [RA_STAT_FAILED_MATCH] = "failed lock match",
659                 [RA_STAT_DISCARDED] = "read but discarded",
660                 [RA_STAT_ZERO_LEN] = "zero length file",
661                 [RA_STAT_ZERO_WINDOW] = "zero size window",
662                 [RA_STAT_EOF] = "read-ahead to EOF",
663                 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
664         };
665
666         do_gettimeofday(&now);
667
668         spin_lock(&sbi->ll_lock);
669
670         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
671                    now.tv_sec, now.tv_usec);
672         seq_printf(seq, "pending issued pages:           %lu\n",
673                    ra->ra_cur_pages);
674
675         for(i = 0; i < _NR_RA_STAT; i++)
676                 seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i], 
677                            ra->ra_stats[i]);
678
679         spin_unlock(&sbi->ll_lock);
680
681         return 0;
682 }
683
684 static void *ll_ra_stats_seq_start(struct seq_file *p, loff_t *pos)
685 {
686         if (*pos == 0)
687                 return (void *)1;
688         return NULL;
689 }
690 static void *ll_ra_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
691 {
692         ++*pos;
693         return NULL;
694 }
695 static void ll_ra_stats_seq_stop(struct seq_file *p, void *v)
696 {
697 }
698 struct seq_operations ll_ra_stats_seq_sops = {
699         .start = ll_ra_stats_seq_start,
700         .stop = ll_ra_stats_seq_stop,
701         .next = ll_ra_stats_seq_next,
702         .show = ll_ra_stats_seq_show,
703 };
704
705 static int ll_ra_stats_seq_open(struct inode *inode, struct file *file)
706 {
707         struct proc_dir_entry *dp = PDE(inode);
708         struct seq_file *seq;
709         int rc;
710
711         rc = seq_open(file, &ll_ra_stats_seq_sops);
712         if (rc)
713                 return rc;
714         seq = file->private_data;
715         seq->private = dp->data;
716         return 0;
717 }
718
719 static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
720                                        size_t len, loff_t *off)
721 {
722         struct seq_file *seq = file->private_data;
723         struct ll_sb_info *sbi = seq->private;
724         struct ll_ra_info *ra = &sbi->ll_ra_info;
725
726         spin_lock(&sbi->ll_lock);
727         memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
728         spin_unlock(&sbi->ll_lock);
729
730         return len;
731 }
732
733 struct file_operations ll_ra_stats_fops = {
734         .owner   = THIS_MODULE,
735         .open    = ll_ra_stats_seq_open,
736         .read    = seq_read,
737         .write   = ll_ra_stats_seq_write,
738         .llseek  = seq_lseek,
739         .release = seq_release,
740 };
741
742 #endif /* LPROCFS */