Whamcloud - gitweb
Branch b1_4
[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_max_readahead_mb(char *page, char **start, off_t off,
186                                    int count, int *eof, void *data)
187 {
188         struct super_block *sb = data;
189         struct ll_sb_info *sbi = ll_s2sbi(sb);
190         unsigned val;
191
192         spin_lock(&sbi->ll_lock);
193         val = sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_CACHE_SHIFT);
194         spin_unlock(&sbi->ll_lock);
195
196         return snprintf(page, count, "%u\n", val);
197 }
198
199 static int ll_wr_max_readahead_mb(struct file *file, const char *buffer,
200                                    unsigned long count, void *data)
201 {
202         struct super_block *sb = data;
203         struct ll_sb_info *sbi = ll_s2sbi(sb);
204         int val, rc;
205
206         rc = lprocfs_write_helper(buffer, count, &val);
207         if (rc)
208                 return rc;
209
210         if (val < 0 || val > (num_physpages >> (20 - PAGE_CACHE_SHIFT - 1))) {
211                 CERROR("can't set readahead more than %lu MB\n",
212                         num_physpages >> (20 - PAGE_CACHE_SHIFT - 1));
213                 return -ERANGE;
214         }
215
216         spin_lock(&sbi->ll_lock);
217         sbi->ll_ra_info.ra_max_pages = val << (20 - PAGE_CACHE_SHIFT);
218         spin_unlock(&sbi->ll_lock);
219
220         return count;
221 }
222
223 static int ll_rd_max_cached_mb(char *page, char **start, off_t off,
224                                int count, int *eof, void *data)
225 {
226         struct super_block *sb = data;
227         struct ll_sb_info *sbi = ll_s2sbi(sb);
228         unsigned val;
229
230         spin_lock(&sbi->ll_lock);
231         val = sbi->ll_async_page_max >> (20 - PAGE_CACHE_SHIFT);
232         spin_unlock(&sbi->ll_lock);
233
234         return snprintf(page, count, "%u\n", val);
235 }
236
237 static int ll_wr_max_cached_mb(struct file *file, const char *buffer,
238                                   unsigned long count, void *data)
239 {
240         struct super_block *sb = data;
241         struct ll_sb_info *sbi = ll_s2sbi(sb);
242         int val, rc;
243
244         rc = lprocfs_write_helper(buffer, count, &val);
245         if (rc)
246                 return rc;
247
248         if (val < 0 || val > (num_physpages >> (20 - PAGE_CACHE_SHIFT))) {
249                 CERROR("can't set max cache more than %lu MB\n",
250                         num_physpages >> (20 - PAGE_CACHE_SHIFT));
251                 return -ERANGE;
252         }
253
254         spin_lock(&sbi->ll_lock);
255         sbi->ll_async_page_max = val << (20 - PAGE_CACHE_SHIFT);
256         spin_unlock(&sbi->ll_lock);
257
258         if (sbi->ll_async_page_count >= sbi->ll_async_page_max)
259                 llap_shrink_cache(sbi, 0);
260
261         return count;
262 }
263
264 static int ll_rd_checksum(char *page, char **start, off_t off,
265                           int count, int *eof, void *data)
266 {
267         struct super_block *sb = data;
268         struct ll_sb_info *sbi = ll_s2sbi(sb);
269
270         return snprintf(page, count, "%u\n",
271                         (sbi->ll_flags & LL_SBI_CHECKSUM) ? 1 : 0);
272 }
273
274 static int ll_wr_checksum(struct file *file, const char *buffer,
275                           unsigned long count, void *data)
276 {
277         struct super_block *sb = data;
278         struct ll_sb_info *sbi = ll_s2sbi(sb);
279         int val, rc;
280
281         rc = lprocfs_write_helper(buffer, count, &val);
282         if (rc)
283                 return rc;
284
285         if (val)
286                 sbi->ll_flags |= LL_SBI_CHECKSUM;
287         else
288                 sbi->ll_flags &= ~LL_SBI_CHECKSUM;
289
290         rc = obd_set_info(sbi->ll_osc_exp, strlen("checksum"), "checksum",
291                           sizeof(val), &val);
292         if (rc)
293                 CWARN("Failed to set OSC checksum flags: %d\n", rc);
294
295         return count;
296 }
297
298 static struct lprocfs_vars lprocfs_obd_vars[] = {
299         { "uuid",         ll_rd_sb_uuid,          0, 0 },
300         //{ "mntpt_path",   ll_rd_path,             0, 0 },
301         { "fstype",       ll_rd_fstype,           0, 0 },
302         { "blocksize",    ll_rd_blksize,          0, 0 },
303         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
304         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
305         { "kbytesavail",  ll_rd_kbytesavail,      0, 0 },
306         { "filestotal",   ll_rd_filestotal,       0, 0 },
307         { "filesfree",    ll_rd_filesfree,        0, 0 },
308         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
309         { "max_read_ahead_mb", ll_rd_max_readahead_mb,
310                                ll_wr_max_readahead_mb, 0 },
311         { "max_cached_mb", ll_rd_max_cached_mb, ll_wr_max_cached_mb, 0 },
312         { "checksum_pages", ll_rd_checksum, ll_wr_checksum, 0 },
313         { 0 }
314 };
315
316 #define MAX_STRING_SIZE 128
317
318 struct llite_file_opcode {
319         __u32       opcode;
320         __u32       type;
321         const char *opname;
322 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
323         /* file operation */
324         { LPROC_LL_DIRTY_HITS,     LPROCFS_TYPE_REGS, "dirty_pages_hits" },
325         { LPROC_LL_DIRTY_MISSES,   LPROCFS_TYPE_REGS, "dirty_pages_misses" },
326         { LPROC_LL_WB_WRITEPAGE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
327                                    "writeback_from_writepage" },
328         { LPROC_LL_WB_PRESSURE,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
329                                    "writeback_from_pressure" },
330         { LPROC_LL_WB_OK,          LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
331                                    "writeback_ok_pages" },
332         { LPROC_LL_WB_FAIL,        LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
333                                    "writeback_failed_pages" },
334         { LPROC_LL_READ_BYTES,     LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
335                                    "read_bytes" },
336         { LPROC_LL_WRITE_BYTES,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
337                                    "write_bytes" },
338         { LPROC_LL_BRW_READ,       LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
339                                    "brw_read" },
340         { LPROC_LL_BRW_WRITE,      LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
341                                    "brw_write" },
342
343         { LPROC_LL_IOCTL,          LPROCFS_TYPE_REGS, "ioctl" },
344         { LPROC_LL_OPEN,           LPROCFS_TYPE_REGS, "open" },
345         { LPROC_LL_RELEASE,        LPROCFS_TYPE_REGS, "close" },
346         { LPROC_LL_MAP,            LPROCFS_TYPE_REGS, "mmap" },
347         { LPROC_LL_LLSEEK,         LPROCFS_TYPE_REGS, "seek" },
348         { LPROC_LL_FSYNC,          LPROCFS_TYPE_REGS, "fsync" },
349         /* inode operation */
350         { LPROC_LL_SETATTR,        LPROCFS_TYPE_REGS, "setattr" },
351         { LPROC_LL_TRUNC,          LPROCFS_TYPE_REGS, "punch" },
352 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
353         { LPROC_LL_GETATTR,        LPROCFS_TYPE_REGS, "getattr" },
354 #else
355         { LPROC_LL_REVALIDATE,     LPROCFS_TYPE_REGS, "getattr" },
356 #endif
357         /* special inode operation */
358         { LPROC_LL_STAFS,          LPROCFS_TYPE_REGS, "statfs" },
359         { LPROC_LL_ALLOC_INODE,    LPROCFS_TYPE_REGS, "alloc_inode" },
360         { LPROC_LL_DIRECT_READ,    LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
361                                    "direct_read" },
362         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
363                                    "direct_write" },
364
365 };
366
367 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
368                                 struct super_block *sb, char *osc, char *mdc)
369 {
370         struct lprocfs_vars lvars[2];
371         struct ll_sb_info *sbi = ll_s2sbi(sb);
372         struct obd_device *obd;
373         char name[MAX_STRING_SIZE + 1];
374         int err, id;
375         struct lprocfs_stats *svc_stats = NULL;
376         struct proc_dir_entry *entry;
377         ENTRY;
378
379         memset(lvars, 0, sizeof(lvars));
380
381         name[MAX_STRING_SIZE] = '\0';
382         lvars[0].name = name;
383
384         LASSERT(sbi != NULL);
385         LASSERT(mdc != NULL);
386         LASSERT(osc != NULL);
387
388         /* Mount info */
389         snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
390
391         mnt_instance++;
392         sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
393         if (IS_ERR(sbi->ll_proc_root)) {
394                 err = PTR_ERR(sbi->ll_proc_root);
395                 sbi->ll_proc_root = NULL;
396                 RETURN(err);
397         }
398
399         entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
400         if (entry == NULL)
401                 GOTO(out, err = -ENOMEM);
402         entry->proc_fops = &llite_dump_pgcache_fops;
403         entry->data = sbi;
404
405         entry = create_proc_entry("read_ahead_stats", 0444, sbi->ll_proc_root);
406         if (entry == NULL)
407                 GOTO(out, err = -ENOMEM);
408         entry->proc_fops = &ll_ra_stats_fops;
409         entry->data = sbi;
410
411         svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
412         if (svc_stats == NULL) {
413                 err = -ENOMEM;
414                 goto out;
415         }
416         /* do counter init */
417         for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
418                 __u32 type = llite_opcode_table[id].type;
419                 void *ptr = NULL;
420                 if (type & LPROCFS_TYPE_REGS)
421                         ptr = "regs";
422                 else {
423                         if (type & LPROCFS_TYPE_BYTES)
424                                 ptr = "bytes";
425                         else {
426                                 if (type & LPROCFS_TYPE_PAGES)
427                                         ptr = "pages";
428                         }
429                 }
430                 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
431                                      (type & LPROCFS_CNTR_AVGMINMAX),
432                                      llite_opcode_table[id].opname, ptr);
433         }
434         err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
435         if (err)
436                 goto out;
437         else
438                 sbi->ll_stats = svc_stats;
439         /* need place to keep svc_stats */
440
441         /* Static configuration info */
442         err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
443         if (err)
444                 goto out;
445
446         /* MDC info */
447         obd = class_name2obd(mdc);
448
449         LASSERT(obd != NULL);
450         LASSERT(obd->obd_type != NULL);
451         LASSERT(obd->obd_type->typ_name != NULL);
452
453         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
454                  obd->obd_type->typ_name);
455         lvars[0].read_fptr = lprocfs_rd_name;
456         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
457         if (err)
458                 goto out;
459
460         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
461         lvars[0].read_fptr = lprocfs_rd_uuid;
462         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
463         if (err)
464                 goto out;
465
466         /* OSC */
467         obd = class_name2obd(osc);
468
469         LASSERT(obd != NULL);
470         LASSERT(obd->obd_type != NULL);
471         LASSERT(obd->obd_type->typ_name != NULL);
472
473         snprintf(name, MAX_STRING_SIZE, "%s/common_name",
474                  obd->obd_type->typ_name);
475         lvars[0].read_fptr = lprocfs_rd_name;
476         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
477         if (err)
478                 goto out;
479
480         snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
481         lvars[0].read_fptr = lprocfs_rd_uuid;
482         err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
483 out:
484         if (err) {
485                 if (svc_stats)
486                         lprocfs_free_stats(svc_stats);
487                 if (sbi->ll_proc_root)
488                         lprocfs_remove(sbi->ll_proc_root);
489         }
490         RETURN(err);
491 }
492
493 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
494 {
495         if (sbi->ll_proc_root) {
496                 struct proc_dir_entry *file_stats =
497                         lprocfs_srch(sbi->ll_proc_root, "stats");
498
499                 if (file_stats) {
500                         lprocfs_free_stats(sbi->ll_stats);
501                         lprocfs_remove(file_stats);
502                 }
503         }
504 }
505 #undef MAX_STRING_SIZE
506
507 #define seq_page_flag(seq, page, flag, has_flags) do {                  \
508                 if (test_bit(PG_##flag, &(page)->flags)) {              \
509                         if (!has_flags)                                 \
510                                 has_flags = 1;                          \
511                         else                                            \
512                                 seq_putc(seq, '|');                     \
513                         seq_puts(seq, #flag);                           \
514                 }                                                       \
515         } while(0);
516
517 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
518 {
519         struct ll_async_page *dummy_llap = seq->private;
520
521         if (dummy_llap->llap_magic == 2)
522                 return NULL;
523
524         return (void *)1;
525 }
526
527 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
528 {
529         struct ll_async_page *llap, *dummy_llap = seq->private;
530         struct ll_sb_info *sbi = dummy_llap->llap_cookie;
531
532         /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
533          * it in our own state */
534         if (dummy_llap->llap_magic == 0) {
535                 seq_printf(seq, "gener |  llap  cookie  origin wq du | page "
536                                 "inode index count [ page flags ]\n");
537                 return 0;
538         }
539
540         spin_lock(&sbi->ll_lock);
541
542         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
543         if (llap != NULL)  {
544                 int has_flags = 0;
545                 struct page *page = llap->llap_page;
546
547                 LASSERTF(llap->llap_origin < LLAP__ORIGIN_MAX, "%u\n",
548                          llap->llap_origin);
549
550                 seq_printf(seq, "%5lu | %p %p %s %s %s | %p %p %lu %u [",
551                            sbi->ll_pglist_gen,
552                            llap, llap->llap_cookie,
553                            llap_origins[llap->llap_origin],
554                            llap->llap_write_queued ? "wq" : "- ",
555                            llap->llap_defer_uptodate ? "du" : "- ",
556                            page, page->mapping->host, page->index,
557                            page_count(page));
558                 seq_page_flag(seq, page, locked, has_flags);
559                 seq_page_flag(seq, page, error, has_flags);
560                 seq_page_flag(seq, page, referenced, has_flags);
561                 seq_page_flag(seq, page, uptodate, has_flags);
562                 seq_page_flag(seq, page, dirty, has_flags);
563                 seq_page_flag(seq, page, highmem, has_flags);
564                 if (!has_flags)
565                         seq_puts(seq, "-]\n");
566                 else 
567                         seq_puts(seq, "]\n");
568         }
569
570         spin_unlock(&sbi->ll_lock);
571
572         return 0;
573 }
574
575 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v, 
576                                          loff_t *pos)
577 {
578         struct ll_async_page *llap, *dummy_llap = seq->private;
579         struct ll_sb_info *sbi = dummy_llap->llap_cookie;
580
581         /* bail if we just displayed the banner */
582         if (dummy_llap->llap_magic == 0) {
583                 dummy_llap->llap_magic = 1;
584                 return dummy_llap;
585         }
586
587         /* we've just displayed the llap that is after us in the list.
588          * we advance to a position beyond it, returning null if there
589          * isn't another llap in the list beyond that new position. */
590         spin_lock(&sbi->ll_lock);
591         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_pglist_item);
592         list_del_init(&dummy_llap->llap_pglist_item);
593         if (llap) {
594                 list_add(&dummy_llap->llap_pglist_item,&llap->llap_pglist_item);
595                 llap =llite_pglist_next_llap(sbi,&dummy_llap->llap_pglist_item);
596         }
597         spin_unlock(&sbi->ll_lock);
598
599         ++*pos;
600         if (llap == NULL) {
601                 dummy_llap->llap_magic = 2;
602                 return NULL;
603         }
604         return dummy_llap;
605 }
606
607 static void llite_dump_pgcache_seq_stop(struct seq_file *seq, void *v)
608 {
609 }
610
611 struct seq_operations llite_dump_pgcache_seq_sops = {
612         .start = llite_dump_pgcache_seq_start,
613         .stop = llite_dump_pgcache_seq_stop,
614         .next = llite_dump_pgcache_seq_next,
615         .show = llite_dump_pgcache_seq_show,
616 };
617
618 /* we're displaying llaps in a list_head list.  we don't want to hold a lock
619  * while we walk the entire list, and we don't want to have to seek into
620  * the right position in the list as an app advances with many syscalls.  we
621  * allocate a dummy llap and hang it off file->private.  its position in
622  * the list records where the app is currently displaying.  this way our
623  * seq .start and .stop don't actually do anything.  .next returns null
624  * when the dummy hits the end of the list which eventually leads to .release
625  * where we tear down.  this kind of displaying is super-racey, so we put
626  * a generation counter on the list so the output shows when the list
627  * changes between reads.
628  */
629 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
630 {
631         struct proc_dir_entry *dp = PDE(inode);
632         struct ll_async_page *dummy_llap;
633         struct seq_file *seq;
634         struct ll_sb_info *sbi = dp->data;
635         int rc;
636
637         OBD_ALLOC_GFP(dummy_llap, sizeof(*dummy_llap), GFP_KERNEL);
638         if (dummy_llap == NULL)
639                 return -ENOMEM;
640         dummy_llap->llap_page = NULL;
641         dummy_llap->llap_cookie = sbi;
642         dummy_llap->llap_magic = 0;
643
644         rc = seq_open(file, &llite_dump_pgcache_seq_sops);
645         if (rc) {
646                 OBD_FREE(dummy_llap, sizeof(*dummy_llap));
647                 return rc;
648         }
649         seq = file->private_data;
650         seq->private = dummy_llap;
651
652         spin_lock(&sbi->ll_lock);
653         list_add(&dummy_llap->llap_pglist_item, &sbi->ll_pglist);
654         spin_unlock(&sbi->ll_lock);
655
656         return 0;
657 }
658
659 static int llite_dump_pgcache_seq_release(struct inode *inode,
660                                           struct file *file)
661 {
662         struct seq_file *seq = file->private_data;
663         struct ll_async_page *dummy_llap = seq->private;
664         struct ll_sb_info *sbi = dummy_llap->llap_cookie;
665
666         spin_lock(&sbi->ll_lock);
667         if (!list_empty(&dummy_llap->llap_pglist_item))
668                 list_del_init(&dummy_llap->llap_pglist_item);
669         spin_unlock(&sbi->ll_lock);
670         OBD_FREE(dummy_llap, sizeof(*dummy_llap));
671
672         return seq_release(inode, file);
673 }
674
675 struct file_operations llite_dump_pgcache_fops = {
676         .owner   = THIS_MODULE,
677         .open    = llite_dump_pgcache_seq_open,
678         .read    = seq_read,
679         .release = llite_dump_pgcache_seq_release,
680 };
681
682 static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
683 {
684         struct timeval now;
685         struct ll_sb_info *sbi = seq->private;
686         struct ll_ra_info *ra = &sbi->ll_ra_info;
687         int i;
688         static char *ra_stat_strings[] = {
689                 [RA_STAT_HIT] = "hits",
690                 [RA_STAT_MISS] = "misses",
691                 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
692                 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
693                 [RA_STAT_FAILED_MATCH] = "failed lock match",
694                 [RA_STAT_DISCARDED] = "read but discarded",
695                 [RA_STAT_ZERO_LEN] = "zero length file",
696                 [RA_STAT_ZERO_WINDOW] = "zero size window",
697                 [RA_STAT_EOF] = "read-ahead to EOF",
698                 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
699         };
700
701         do_gettimeofday(&now);
702
703         spin_lock(&sbi->ll_lock);
704
705         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
706                    now.tv_sec, now.tv_usec);
707         seq_printf(seq, "pending issued pages:           %lu\n",
708                    ra->ra_cur_pages);
709
710         for(i = 0; i < _NR_RA_STAT; i++)
711                 seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i], 
712                            ra->ra_stats[i]);
713
714         spin_unlock(&sbi->ll_lock);
715
716         return 0;
717 }
718
719 static void *ll_ra_stats_seq_start(struct seq_file *p, loff_t *pos)
720 {
721         if (*pos == 0)
722                 return (void *)1;
723         return NULL;
724 }
725 static void *ll_ra_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
726 {
727         ++*pos;
728         return NULL;
729 }
730 static void ll_ra_stats_seq_stop(struct seq_file *p, void *v)
731 {
732 }
733 struct seq_operations ll_ra_stats_seq_sops = {
734         .start = ll_ra_stats_seq_start,
735         .stop = ll_ra_stats_seq_stop,
736         .next = ll_ra_stats_seq_next,
737         .show = ll_ra_stats_seq_show,
738 };
739
740 static int ll_ra_stats_seq_open(struct inode *inode, struct file *file)
741 {
742         struct proc_dir_entry *dp = PDE(inode);
743         struct seq_file *seq;
744         int rc;
745
746         rc = seq_open(file, &ll_ra_stats_seq_sops);
747         if (rc)
748                 return rc;
749         seq = file->private_data;
750         seq->private = dp->data;
751         return 0;
752 }
753
754 static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
755                                        size_t len, loff_t *off)
756 {
757         struct seq_file *seq = file->private_data;
758         struct ll_sb_info *sbi = seq->private;
759         struct ll_ra_info *ra = &sbi->ll_ra_info;
760
761         spin_lock(&sbi->ll_lock);
762         memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
763         spin_unlock(&sbi->ll_lock);
764
765         return len;
766 }
767
768 struct file_operations ll_ra_stats_fops = {
769         .owner   = THIS_MODULE,
770         .open    = ll_ra_stats_seq_open,
771         .read    = seq_read,
772         .write   = ll_ra_stats_seq_write,
773         .llseek  = seq_lseek,
774         .release = seq_release,
775 };
776
777 #endif /* LPROCFS */