1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
22 #define DEBUG_SUBSYSTEM S_LLITE
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>
30 #include <linux/mm_inline.h>
33 #include "llite_internal.h"
35 /* /proc/lustre/llite mount point registration */
36 struct proc_dir_entry *proc_lustre_fs_root;
37 struct file_operations llite_dump_pgcache_fops;
38 struct file_operations ll_ra_stats_fops;
39 struct file_operations llite_wait_times_fops;
42 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
43 struct super_block *sb, char *osc, char *mdc)
47 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
50 long long mnt_instance;
52 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
55 struct super_block *sb = (struct super_block *)data;
56 struct obd_statfs osfs;
60 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
63 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
69 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
72 struct super_block *sb = (struct super_block *)data;
73 struct obd_statfs osfs;
77 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
79 __u32 blk_size = osfs.os_bsize >> 10;
80 __u64 result = osfs.os_blocks;
82 while (blk_size >>= 1)
86 rc = snprintf(page, count, LPU64"\n", result);
92 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
95 struct super_block *sb = (struct super_block *)data;
96 struct obd_statfs osfs;
100 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
102 __u32 blk_size = osfs.os_bsize >> 10;
103 __u64 result = osfs.os_bfree;
105 while (blk_size >>= 1)
109 rc = snprintf(page, count, LPU64"\n", result);
114 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
115 int *eof, void *data)
117 struct super_block *sb = (struct super_block *)data;
118 struct obd_statfs osfs;
122 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
124 __u32 blk_size = osfs.os_bsize >> 10;
125 __u64 result = osfs.os_bavail;
127 while (blk_size >>= 1)
131 rc = snprintf(page, count, LPU64"\n", result);
136 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
137 int *eof, void *data)
139 struct super_block *sb = (struct super_block *)data;
140 struct obd_statfs osfs;
144 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
147 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
152 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
153 int *eof, void *data)
155 struct super_block *sb = (struct super_block *)data;
156 struct obd_statfs osfs;
160 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
163 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
169 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
170 int *eof, void *data)
172 struct super_block *sb = (struct super_block*)data;
176 return snprintf(page, count, "%s\n", sb->s_type->name);
179 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
180 int *eof, void *data)
182 struct super_block *sb = (struct super_block *)data;
186 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
189 static int ll_rd_read_ahead(char *page, char **start, off_t off, int count,
190 int *eof, void *data)
192 struct super_block *sb = (struct super_block*)data;
193 struct ll_sb_info *sbi = ll_s2sbi(sb);
198 val = (sbi->ll_flags & LL_SBI_READAHEAD) ? 1 : 0;
199 rc = snprintf(page, count, "%d\n", val);
203 static int ll_wr_read_ahead(struct file *file, const char *buffer,
204 unsigned long count, void *data)
206 struct super_block *sb = (struct super_block*)data;
207 struct ll_sb_info *sbi = ll_s2sbi(sb);
211 if (sscanf(buffer, "%d", &readahead) != 1)
215 sbi->ll_flags |= LL_SBI_READAHEAD;
217 sbi->ll_flags &= ~LL_SBI_READAHEAD;
222 static int ll_wr_config_update(struct file *file, const char *buffer,
223 unsigned long count, void *data)
225 struct super_block *sb = (struct super_block*)data;
226 struct ll_sb_info *sbi = ll_s2sbi(sb);
229 CWARN("Starting a LOV/OST update !\n");
230 RETURN(ll_process_config_update(sbi, 0));
233 static int ll_rd_max_read_ahead_mb(char *page, char **start, off_t off,
234 int count, int *eof, void *data)
236 struct super_block *sb = data;
237 struct ll_sb_info *sbi = ll_s2sbi(sb);
240 spin_lock(&sbi->ll_lock);
241 val = (sbi->ll_ra_info.ra_max_pages << PAGE_CACHE_SHIFT) >> 20;
242 spin_unlock(&sbi->ll_lock);
244 return snprintf(page, count, "%u\n", val);
247 static int ll_wr_max_read_ahead_mb(struct file *file, const char *buffer,
248 unsigned long count, void *data)
250 struct super_block *sb = data;
251 struct ll_sb_info *sbi = ll_s2sbi(sb);
254 rc = lprocfs_write_helper(buffer, count, &val);
258 if (val < 0 || val > (num_physpages << PAGE_SHIFT) >> 20)
261 spin_lock(&sbi->ll_lock);
262 sbi->ll_ra_info.ra_max_pages = (val << 20) >> PAGE_CACHE_SHIFT;
263 spin_unlock(&sbi->ll_lock);
268 static int ll_rd_gns_upcall(char *page, char **start, off_t off,
269 int count, int *eof, void *data)
271 struct super_block *sb = (struct super_block *)data;
272 struct ll_sb_info *sbi = ll_s2sbi(sb);
275 down(&sbi->ll_gns_sem);
276 len = snprintf(page, count, "%s\n", sbi->ll_gns_upcall);
277 up(&sbi->ll_gns_sem);
282 static int ll_wr_gns_upcall(struct file *file, const char *buffer,
283 unsigned long count, void *data)
285 struct super_block *sb = (struct super_block *)data;
286 struct ll_sb_info *sbi = ll_s2sbi(sb);
288 down(&sbi->ll_gns_sem);
291 * upcall should not be the same as object name, check for possible
294 if (count < sizeof(sbi->ll_gns_upcall) &&
295 (strlen(sbi->ll_gns_oname) != count ||
296 strncmp(sbi->ll_gns_oname, buffer, count)))
297 snprintf(sbi->ll_gns_upcall, count, "%s", buffer);
299 up(&sbi->ll_gns_sem);
303 static int ll_rd_gns_object_name(char *page, char **start, off_t off,
304 int count, int *eof, void *data)
306 struct super_block *sb = (struct super_block *)data;
307 struct ll_sb_info *sbi = ll_s2sbi(sb);
310 down(&sbi->ll_gns_sem);
311 len = snprintf(page, count, "%s\n", sbi->ll_gns_oname);
312 up(&sbi->ll_gns_sem);
317 static int ll_wr_gns_object_name(struct file *file, const char *buffer,
318 unsigned long count, void *data)
320 struct super_block *sb = (struct super_block *)data;
321 struct ll_sb_info *sbi = ll_s2sbi(sb);
323 /* checking for setting "." and ".." as object name */
324 if (buffer[0] == '.') switch (count) {
326 /* this is "." case with terminating zero */
329 /* this is ".." case with terminating zero */
330 if (buffer[1] == '.')
334 down(&sbi->ll_gns_sem);
337 * upcall should not be the same as object name, check for possible
340 if (count < sizeof(sbi->ll_gns_oname) &&
341 (strlen(sbi->ll_gns_upcall) != count ||
342 strncmp(sbi->ll_gns_upcall, buffer, count)))
343 snprintf(sbi->ll_gns_oname, count, "%s", buffer);
345 up(&sbi->ll_gns_sem);
349 static int ll_rd_gns_timeout(char *page, char **start, off_t off,
350 int count, int *eof, void *data)
352 struct super_block *sb = (struct super_block *)data;
353 struct ll_sb_info *sbi = ll_s2sbi(sb);
356 down(&sbi->ll_gns_sem);
357 len = snprintf(page, count, "%lu\n",
358 (unsigned long)sbi->ll_gns_timeout);
359 up(&sbi->ll_gns_sem);
364 static int ll_wr_gns_timeout(struct file *file, const char *buffer,
365 unsigned long count, void *data)
367 struct super_block *sb = (struct super_block *)data;
368 struct ll_sb_info *sbi = ll_s2sbi(sb);
371 rc = lprocfs_write_helper(buffer, count, &val);
375 down(&sbi->ll_gns_sem);
376 if (val > sbi->ll_gns_tick)
377 sbi->ll_gns_timeout = val;
378 up(&sbi->ll_gns_sem);
383 static int ll_rd_gns_tick(char *page, char **start, off_t off,
384 int count, int *eof, void *data)
386 struct super_block *sb = (struct super_block *)data;
387 struct ll_sb_info *sbi = ll_s2sbi(sb);
390 down(&sbi->ll_gns_sem);
391 len = snprintf(page, count, "%lu\n",
392 (unsigned long)sbi->ll_gns_tick);
393 up(&sbi->ll_gns_sem);
398 static int ll_wr_gns_tick(struct file *file, const char *buffer,
399 unsigned long count, void *data)
401 struct super_block *sb = (struct super_block *)data;
402 struct ll_sb_info *sbi = ll_s2sbi(sb);
405 rc = lprocfs_write_helper(buffer, count, &val);
409 down(&sbi->ll_gns_sem);
410 if (val < sbi->ll_gns_timeout)
411 sbi->ll_gns_tick = val;
412 up(&sbi->ll_gns_sem);
417 static int ll_rd_gns_enabled(char *page, char **start, off_t off,
418 int count, int *eof, void *data)
420 struct super_block *sb = (struct super_block *)data;
421 struct ll_sb_info *sbi = ll_s2sbi(sb);
424 spin_lock(&sbi->ll_gns_lock);
425 enabled = (sbi->ll_gns_state == LL_GNS_DISABLED ? 0 : 1);
426 spin_unlock(&sbi->ll_gns_lock);
428 return snprintf(page, count, "%d\n", enabled);
431 static int ll_wr_gns_enabled(struct file *file, const char *buffer,
432 unsigned long count, void *data)
434 struct super_block *sb = (struct super_block *)data;
435 struct ll_sb_info *sbi = ll_s2sbi(sb);
438 rc = lprocfs_write_helper(buffer, count, &val);
442 spin_lock(&sbi->ll_gns_lock);
443 if (val == 0 && sbi->ll_gns_state == LL_GNS_IDLE) {
444 sbi->ll_gns_state = LL_GNS_DISABLED;
447 if (val == 1 && sbi->ll_gns_state == LL_GNS_DISABLED) {
448 sbi->ll_gns_state = LL_GNS_IDLE;
452 spin_unlock(&sbi->ll_gns_lock);
456 static struct lprocfs_vars lprocfs_obd_vars[] = {
457 { "uuid", ll_rd_sb_uuid, 0, 0 },
458 //{ "mntpt_path", ll_rd_path, 0, 0 },
459 { "fstype", ll_rd_fstype, 0, 0 },
460 { "blocksize", ll_rd_blksize, 0, 0 },
461 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
462 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
463 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
464 { "filestotal", ll_rd_filestotal, 0, 0 },
465 { "filesfree", ll_rd_filesfree, 0, 0 },
466 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
467 { "read_ahead", ll_rd_read_ahead, ll_wr_read_ahead, 0 },
468 { "config_update", 0, ll_wr_config_update, 0 },
469 { "max_read_ahead_mb", ll_rd_max_read_ahead_mb,
470 ll_wr_max_read_ahead_mb, 0 },
472 { "gns_upcall", ll_rd_gns_upcall,
473 ll_wr_gns_upcall, 0 },
475 { "gns_timeout", ll_rd_gns_timeout,
476 ll_wr_gns_timeout, 0 },
478 { "gns_tick", ll_rd_gns_tick,
481 { "gns_enabled", ll_rd_gns_enabled,
482 ll_wr_gns_enabled, 0 },
484 { "gns_object_name", ll_rd_gns_object_name,
485 ll_wr_gns_object_name, 0 },
490 #define MAX_STRING_SIZE 128
492 struct llite_file_opcode {
496 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
498 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
499 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
500 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
501 "writeback_from_writepage" },
502 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
503 "writeback_from_pressure" },
504 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
505 "writeback_ok_pages" },
506 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
507 "writeback_failed_pages" },
508 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
510 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
512 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
514 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
517 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
518 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
519 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
520 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
521 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
522 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
523 /* inode operation */
524 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
525 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "punch" },
526 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
527 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
529 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
531 /* special inode operation */
532 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
533 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
534 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
536 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
538 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
539 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
542 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
543 struct super_block *sb, char *osc, char *mdc)
545 struct lprocfs_vars lvars[2];
546 struct ll_sb_info *sbi = ll_s2sbi(sb);
547 struct obd_device *obd;
548 char name[MAX_STRING_SIZE + 1];
550 struct lprocfs_stats *svc_stats = NULL;
551 struct proc_dir_entry *mdc_symlink, *osc_symlink;
552 struct proc_dir_entry *entry;
555 memset(lvars, 0, sizeof(lvars));
557 name[MAX_STRING_SIZE] = '\0';
558 lvars[0].name = name;
560 LASSERT(sbi != NULL);
561 LASSERT(mdc != NULL);
562 LASSERT(osc != NULL);
565 snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
568 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
569 if (IS_ERR(sbi->ll_proc_root)) {
570 err = PTR_ERR(sbi->ll_proc_root);
571 sbi->ll_proc_root = NULL;
575 entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
577 GOTO(out, err = -ENOMEM);
578 entry->proc_fops = &llite_dump_pgcache_fops;
581 entry = create_proc_entry("wait_times", 0444, sbi->ll_proc_root);
583 GOTO(out, err = -ENOMEM);
584 entry->proc_fops = &llite_wait_times_fops;
587 entry = create_proc_entry("read_ahead_stats", 0444, sbi->ll_proc_root);
589 GOTO(out, err = -ENOMEM);
590 entry->proc_fops = &ll_ra_stats_fops;
593 svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
594 if (svc_stats == NULL) {
598 /* do counter init */
599 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
600 __u32 type = llite_opcode_table[id].type;
602 if (type & LPROCFS_TYPE_REGS)
605 if (type & LPROCFS_TYPE_BYTES)
608 if (type & LPROCFS_TYPE_PAGES)
612 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
613 (type & LPROCFS_CNTR_AVGMINMAX),
614 llite_opcode_table[id].opname, ptr);
616 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
620 sbi->ll_stats = svc_stats;
621 /* need place to keep svc_stats */
623 /* Static configuration info */
624 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
629 obd = class_name2obd(mdc);
631 LASSERT(obd != NULL);
632 LASSERT(obd->obd_type != NULL);
633 LASSERT(obd->obd_type->typ_name != NULL);
635 snprintf(name, MAX_STRING_SIZE, "../../%s/%s",
636 obd->obd_type->typ_name, obd->obd_name);
637 mdc_symlink = proc_symlink(obd->obd_type->typ_name, sbi->ll_proc_root,
639 if (mdc_symlink == NULL) {
645 obd = class_name2obd(osc);
647 LASSERT(obd != NULL);
648 LASSERT(obd->obd_type != NULL);
649 LASSERT(obd->obd_type->typ_name != NULL);
651 snprintf(name, MAX_STRING_SIZE, "../../%s/%s",
652 obd->obd_type->typ_name, obd->obd_name);
653 osc_symlink = proc_symlink(obd->obd_type->typ_name, sbi->ll_proc_root,
655 if (osc_symlink == NULL)
662 lprocfs_free_stats(svc_stats);
663 if (sbi->ll_proc_root)
664 lprocfs_remove(sbi->ll_proc_root);
669 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
671 if (sbi->ll_proc_root) {
672 struct proc_dir_entry *file_stats =
673 lprocfs_srch(sbi->ll_proc_root, "stats");
676 lprocfs_free_stats(sbi->ll_stats);
677 lprocfs_remove(file_stats);
681 #undef MAX_STRING_SIZE
683 static struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
684 struct list_head *list)
686 struct ll_async_page *llap;
687 struct list_head *pos;
689 list_for_each(pos, list) {
690 if (pos == &sbi->ll_pglist)
692 llap = list_entry(pos, struct ll_async_page, llap_proc_item);
693 if (llap->llap_page == NULL)
701 #define seq_page_flag(seq, page, flag, has_flags) do { \
702 if (test_bit(PG_##flag, &(page)->flags)) { \
706 seq_putc(seq, '|'); \
707 seq_puts(seq, #flag); \
711 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
713 struct ll_async_page *llap, *dummy_llap = seq->private;
714 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
716 /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
717 * it in our own state */
718 if (dummy_llap->llap_magic == 0) {
719 seq_printf(seq, "generation | llap cookie origin | page ");
720 seq_printf(seq, "inode index count [ page flags ]\n");
724 spin_lock(&sbi->ll_lock);
726 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
729 struct page *page = llap->llap_page;
730 static char *origins[] = {
731 [LLAP_ORIGIN_UNKNOWN] = "--",
732 [LLAP_ORIGIN_READPAGE] = "rp",
733 [LLAP_ORIGIN_READAHEAD] = "ra",
734 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
735 [LLAP_ORIGIN_WRITEPAGE] = "wp",
738 LASSERTF(llap->llap_origin < LLAP__ORIGIN_MAX, "%u\n",
741 seq_printf(seq, "%lu | %p %p %s | %p %p %lu %u [",
743 llap, llap->llap_cookie,
744 origins[llap->llap_origin],
745 page, page->mapping->host, page->index,
747 seq_page_flag(seq, page, locked, has_flags);
748 seq_page_flag(seq, page, error, has_flags);
749 seq_page_flag(seq, page, referenced, has_flags);
750 seq_page_flag(seq, page, uptodate, has_flags);
751 seq_page_flag(seq, page, dirty, has_flags);
752 seq_page_flag(seq, page, highmem, has_flags);
754 seq_puts(seq, "-]\n");
756 seq_puts(seq, "]\n");
759 spin_unlock(&sbi->ll_lock);
764 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
766 struct ll_async_page *llap = seq->private;
768 if (llap->llap_magic == 2)
774 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
777 struct ll_async_page *llap, *dummy_llap = seq->private;
778 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
780 /* bail if we just displayed the banner */
781 if (dummy_llap->llap_magic == 0) {
782 dummy_llap->llap_magic = 1;
786 /* we've just displayed the llap that is after us in the list.
787 * we advance to a position beyond it, returning null if there
788 * isn't another llap in the list beyond that new position. */
789 spin_lock(&sbi->ll_lock);
790 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
791 list_del_init(&dummy_llap->llap_proc_item);
793 list_add(&dummy_llap->llap_proc_item, &llap->llap_proc_item);
794 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
796 spin_unlock(&sbi->ll_lock);
800 dummy_llap->llap_magic = 2;
806 static void llite_dump_pgcache_seq_stop(struct seq_file *seq, void *v)
810 struct seq_operations llite_dump_pgcache_seq_sops = {
811 .start = llite_dump_pgcache_seq_start,
812 .stop = llite_dump_pgcache_seq_stop,
813 .next = llite_dump_pgcache_seq_next,
814 .show = llite_dump_pgcache_seq_show,
817 /* we're displaying llaps in a list_head list. we don't want to hold a lock
818 * while we walk the entire list, and we don't want to have to seek into
819 * the right position in the list as an app advances with many syscalls. we
820 * allocate a dummy llap and hang it off file->private. its position in
821 * the list records where the app is currently displaying. this way our
822 * seq .start and .stop don't actually do anything. .next returns null
823 * when the dummy hits the end of the list which eventually leads to .release
824 * where we tear down. this kind of displaying is super-racey, so we put
825 * a generation counter on the list so the output shows when the list
826 * changes between reads.
828 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
830 struct proc_dir_entry *dp = PDE(inode);
831 struct ll_async_page *llap;
832 struct seq_file *seq;
833 struct ll_sb_info *sbi = dp->data;
836 OBD_ALLOC_GFP(llap, sizeof(*llap), GFP_KERNEL);
839 llap->llap_page = NULL;
840 llap->llap_cookie = sbi;
841 llap->llap_magic = 0;
843 rc = seq_open(file, &llite_dump_pgcache_seq_sops);
845 OBD_FREE(llap, sizeof(*llap));
848 seq = file->private_data;
851 spin_lock(&sbi->ll_lock);
852 list_add(&llap->llap_proc_item, &sbi->ll_pglist);
853 spin_unlock(&sbi->ll_lock);
858 static int llite_dump_pgcache_seq_release(struct inode *inode,
861 struct seq_file *seq = file->private_data;
862 struct ll_async_page *llap = seq->private;
863 struct ll_sb_info *sbi = llap->llap_cookie;
865 spin_lock(&sbi->ll_lock);
866 if (!list_empty(&llap->llap_proc_item))
867 list_del_init(&llap->llap_proc_item);
868 spin_unlock(&sbi->ll_lock);
869 OBD_FREE(llap, sizeof(*llap));
871 return seq_release(inode, file);
874 struct file_operations llite_dump_pgcache_fops = {
875 .owner = THIS_MODULE,
876 .open = llite_dump_pgcache_seq_open,
878 .release = llite_dump_pgcache_seq_release,
880 static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
883 struct ll_sb_info *sbi = seq->private;
884 struct ll_ra_info *ra = &sbi->ll_ra_info;
886 static char *ra_stat_strings[] = {
887 [RA_STAT_HIT] = "hits",
888 [RA_STAT_MISS] = "misses",
889 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
890 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
891 [RA_STAT_FAILED_MATCH] = "failed lock match",
892 [RA_STAT_DISCARDED] = "read but discarded",
893 [RA_STAT_ZERO_LEN] = "zero length file",
894 [RA_STAT_ZERO_WINDOW] = "zero size window",
895 [RA_STAT_EOF] = "read-ahead to EOF",
896 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
899 do_gettimeofday(&now);
901 spin_lock(&sbi->ll_lock);
903 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
904 now.tv_sec, now.tv_usec);
905 seq_printf(seq, "pending issued pages: %lu\n",
908 for(i = 0; i < _NR_RA_STAT; i++)
909 seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i],
912 spin_unlock(&sbi->ll_lock);
917 static void *ll_ra_stats_seq_start(struct seq_file *p, loff_t *pos)
923 static void *ll_ra_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
928 static void ll_ra_stats_seq_stop(struct seq_file *p, void *v)
931 struct seq_operations ll_ra_stats_seq_sops = {
932 .start = ll_ra_stats_seq_start,
933 .stop = ll_ra_stats_seq_stop,
934 .next = ll_ra_stats_seq_next,
935 .show = ll_ra_stats_seq_show,
938 static int ll_ra_stats_seq_open(struct inode *inode, struct file *file)
940 struct proc_dir_entry *dp = PDE(inode);
941 struct seq_file *seq;
944 rc = seq_open(file, &ll_ra_stats_seq_sops);
947 seq = file->private_data;
948 seq->private = dp->data;
952 static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
953 size_t len, loff_t *off)
955 struct seq_file *seq = file->private_data;
956 struct ll_sb_info *sbi = seq->private;
957 struct ll_ra_info *ra = &sbi->ll_ra_info;
959 spin_lock(&sbi->ll_lock);
960 memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
961 spin_unlock(&sbi->ll_lock);
966 struct file_operations ll_ra_stats_fops = {
967 .owner = THIS_MODULE,
968 .open = ll_ra_stats_seq_open,
970 .write = ll_ra_stats_seq_write,
972 .release = seq_release,
975 #define PRINTF_STIME(stime) (unsigned long)(stime)->st_num, \
976 lprocfs_stime_avg_ms(stime), lprocfs_stime_avg_us(stime)
978 static int llite_wait_times_seq_show(struct seq_file *seq, void *v)
980 struct ll_sb_info *sbi = seq->private;
983 do_gettimeofday(&now);
985 spin_lock(&sbi->ll_lock);
987 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n\n",
988 now.tv_sec, now.tv_usec);
990 seq_printf(seq, "lock wait times: (num, average ms)\n");
991 seq_printf(seq, "\tread\t%lu\t%lu.%04lu\n",
992 PRINTF_STIME(&sbi->ll_read_stime));
993 seq_printf(seq, "\twrite\t%lu\t%lu.%04lu\n",
994 PRINTF_STIME(&sbi->ll_write_stime));
995 seq_printf(seq, "\tgroup\t%lu\t%lu.%04lu\n",
996 PRINTF_STIME(&sbi->ll_grouplock_stime));
997 seq_printf(seq, "\tseek\t%lu\t%lu.%04lu\n",
998 PRINTF_STIME(&sbi->ll_seek_stime));
999 seq_printf(seq, "\tsetattr\t%lu\t%lu.%04lu\n\n",
1000 PRINTF_STIME(&sbi->ll_setattr_stime));
1002 seq_printf(seq, "io path wait times: (num, average ms)\n");
1003 seq_printf(seq, "\tll_brw\t%lu\t%lu.%04lu\n",
1004 PRINTF_STIME(&sbi->ll_brw_stime));
1006 seq_printf(seq, "\tdone\t%lu\t%lu.%04lu\n",
1007 PRINTF_STIME(&sbi->ll_done_stime));
1010 spin_unlock(&sbi->ll_lock);
1016 static void *llite_wait_times_seq_start(struct seq_file *p, loff_t *pos)
1022 static void *llite_wait_times_seq_next(struct seq_file *p, void *v, loff_t *pos)
1027 static void llite_wait_times_seq_stop(struct seq_file *p, void *v)
1030 struct seq_operations llite_wait_times_seq_sops = {
1031 .start = llite_wait_times_seq_start,
1032 .stop = llite_wait_times_seq_stop,
1033 .next = llite_wait_times_seq_next,
1034 .show = llite_wait_times_seq_show,
1037 static int llite_wait_times_seq_open(struct inode *inode, struct file *file)
1039 struct proc_dir_entry *dp = PDE(inode);
1040 struct seq_file *seq;
1043 rc = seq_open(file, &llite_wait_times_seq_sops);
1046 seq = file->private_data;
1047 seq->private = dp->data;
1051 static ssize_t llite_wait_times_seq_write(struct file *file, const char *buf,
1052 size_t len, loff_t *off)
1054 struct seq_file *seq = file->private_data;
1055 struct ll_sb_info *sbi = seq->private;
1057 spin_lock(&sbi->ll_lock);
1058 memset(&sbi->ll_read_stime, 0, sizeof(sbi->ll_read_stime));
1059 memset(&sbi->ll_write_stime, 0, sizeof(sbi->ll_write_stime));
1060 memset(&sbi->ll_grouplock_stime, 0, sizeof(sbi->ll_grouplock_stime));
1061 memset(&sbi->ll_seek_stime, 0, sizeof(sbi->ll_seek_stime));
1062 memset(&sbi->ll_setattr_stime, 0, sizeof(sbi->ll_setattr_stime));
1063 memset(&sbi->ll_brw_stime, 0, sizeof(sbi->ll_brw_stime));
1064 // memset(&sbi->ll_done_stime, 0, sizeof(sbi->ll_done_stime));
1065 spin_unlock(&sbi->ll_lock);
1070 struct file_operations llite_wait_times_fops = {
1071 .owner = THIS_MODULE,
1072 .open = llite_wait_times_seq_open,
1074 .write = llite_wait_times_seq_write,
1075 .llseek = seq_lseek,
1076 .release = seq_release,
1079 #endif /* LPROCFS */