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