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 ll_process_config_update(sbi, 0);
234 static int ll_rd_max_read_ahead_mb(char *page, char **start, off_t off,
235 int count, int *eof, void *data)
237 struct super_block *sb = data;
238 struct ll_sb_info *sbi = ll_s2sbi(sb);
241 spin_lock(&sbi->ll_lock);
242 val = (sbi->ll_ra_info.ra_max_pages << PAGE_CACHE_SHIFT) >> 20;
243 spin_unlock(&sbi->ll_lock);
245 return snprintf(page, count, "%u\n", val);
248 static int ll_wr_max_read_ahead_mb(struct file *file, const char *buffer,
249 unsigned long count, void *data)
251 struct super_block *sb = data;
252 struct ll_sb_info *sbi = ll_s2sbi(sb);
255 rc = lprocfs_write_helper(buffer, count, &val);
259 if (val < 0 || val > (num_physpages << PAGE_SHIFT) >> 20)
262 spin_lock(&sbi->ll_lock);
263 sbi->ll_ra_info.ra_max_pages = (val << 20) >> PAGE_CACHE_SHIFT;
264 spin_unlock(&sbi->ll_lock);
269 static int ll_rd_gns_upcall(char *page, char **start, off_t off,
270 int count, int *eof, void *data)
272 struct super_block *sb = (struct super_block *)data;
273 struct ll_sb_info *sbi = ll_s2sbi(sb);
276 down(&sbi->ll_gns_sem);
277 len = snprintf(page, count, "%s\n", sbi->ll_gns_upcall);
278 up(&sbi->ll_gns_sem);
283 static int ll_wr_gns_upcall(struct file *file, const char *buffer,
284 unsigned long count, void *data)
286 struct super_block *sb = (struct super_block *)data;
287 struct ll_sb_info *sbi = ll_s2sbi(sb);
289 down(&sbi->ll_gns_sem);
292 * upcall should not be the same as object name, check for possible
295 if (count < sizeof(sbi->ll_gns_upcall) &&
296 (strlen(sbi->ll_gns_oname) != count ||
297 strncmp(sbi->ll_gns_oname, buffer, count)))
298 snprintf(sbi->ll_gns_upcall, count, "%s", buffer);
300 up(&sbi->ll_gns_sem);
304 static int ll_rd_gns_object_name(char *page, char **start, off_t off,
305 int count, int *eof, void *data)
307 struct super_block *sb = (struct super_block *)data;
308 struct ll_sb_info *sbi = ll_s2sbi(sb);
311 down(&sbi->ll_gns_sem);
312 len = snprintf(page, count, "%s\n", sbi->ll_gns_oname);
313 up(&sbi->ll_gns_sem);
318 static int ll_wr_gns_object_name(struct file *file, const char *buffer,
319 unsigned long count, void *data)
321 struct super_block *sb = (struct super_block *)data;
322 struct ll_sb_info *sbi = ll_s2sbi(sb);
324 /* checking for setting "." and ".." as object name */
325 if (buffer[0] == '.') switch (count) {
327 /* this is "." case with terminating zero */
330 /* this is ".." case with terminating zero */
331 if (buffer[1] == '.')
335 down(&sbi->ll_gns_sem);
338 * upcall should not be the same as object name, check for possible
341 if (count < sizeof(sbi->ll_gns_oname) &&
342 (strlen(sbi->ll_gns_upcall) != count ||
343 strncmp(sbi->ll_gns_upcall, buffer, count)))
344 snprintf(sbi->ll_gns_oname, count, "%s", buffer);
346 up(&sbi->ll_gns_sem);
350 static int ll_rd_gns_timeout(char *page, char **start, off_t off,
351 int count, int *eof, void *data)
353 struct super_block *sb = (struct super_block *)data;
354 struct ll_sb_info *sbi = ll_s2sbi(sb);
357 down(&sbi->ll_gns_sem);
358 len = snprintf(page, count, "%lu\n",
359 (unsigned long)sbi->ll_gns_timeout);
360 up(&sbi->ll_gns_sem);
365 static int ll_wr_gns_timeout(struct file *file, const char *buffer,
366 unsigned long count, void *data)
368 struct super_block *sb = (struct super_block *)data;
369 struct ll_sb_info *sbi = ll_s2sbi(sb);
372 rc = lprocfs_write_helper(buffer, count, &val);
376 down(&sbi->ll_gns_sem);
377 if (val > sbi->ll_gns_tick)
378 sbi->ll_gns_timeout = val;
379 up(&sbi->ll_gns_sem);
384 static int ll_rd_gns_tick(char *page, char **start, off_t off,
385 int count, int *eof, void *data)
387 struct super_block *sb = (struct super_block *)data;
388 struct ll_sb_info *sbi = ll_s2sbi(sb);
391 down(&sbi->ll_gns_sem);
392 len = snprintf(page, count, "%lu\n",
393 (unsigned long)sbi->ll_gns_tick);
394 up(&sbi->ll_gns_sem);
399 static int ll_wr_gns_tick(struct file *file, const char *buffer,
400 unsigned long count, void *data)
402 struct super_block *sb = (struct super_block *)data;
403 struct ll_sb_info *sbi = ll_s2sbi(sb);
406 rc = lprocfs_write_helper(buffer, count, &val);
410 down(&sbi->ll_gns_sem);
411 if (val < sbi->ll_gns_timeout)
412 sbi->ll_gns_tick = val;
413 up(&sbi->ll_gns_sem);
418 static int ll_rd_gns_enabled(char *page, char **start, off_t off,
419 int count, int *eof, void *data)
421 struct super_block *sb = (struct super_block *)data;
422 struct ll_sb_info *sbi = ll_s2sbi(sb);
424 return snprintf(page, count, "%d\n",
425 atomic_read(&sbi->ll_gns_enabled));
428 static int ll_wr_gns_enabled(struct file *file, const char *buffer,
429 unsigned long count, void *data)
431 struct super_block *sb = (struct super_block *)data;
432 struct ll_sb_info *sbi = ll_s2sbi(sb);
435 rc = lprocfs_write_helper(buffer, count, &val);
439 atomic_set(&sbi->ll_gns_enabled, (val != 0 ? 1 : 0));
443 static struct lprocfs_vars lprocfs_obd_vars[] = {
444 { "uuid", ll_rd_sb_uuid, 0, 0 },
445 //{ "mntpt_path", ll_rd_path, 0, 0 },
446 { "fstype", ll_rd_fstype, 0, 0 },
447 { "blocksize", ll_rd_blksize, 0, 0 },
448 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
449 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
450 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
451 { "filestotal", ll_rd_filestotal, 0, 0 },
452 { "filesfree", ll_rd_filesfree, 0, 0 },
453 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
454 { "read_ahead", ll_rd_read_ahead, ll_wr_read_ahead, 0 },
455 { "config_update", 0, ll_wr_config_update, 0 },
456 { "max_read_ahead_mb", ll_rd_max_read_ahead_mb,
457 ll_wr_max_read_ahead_mb, 0 },
459 { "gns_upcall", ll_rd_gns_upcall,
460 ll_wr_gns_upcall, 0 },
462 { "gns_timeout", ll_rd_gns_timeout,
463 ll_wr_gns_timeout, 0 },
465 { "gns_tick", ll_rd_gns_tick,
468 { "gns_enabled", ll_rd_gns_enabled,
469 ll_wr_gns_enabled, 0 },
471 { "gns_object_name", ll_rd_gns_object_name,
472 ll_wr_gns_object_name, 0 },
477 #define MAX_STRING_SIZE 128
479 struct llite_file_opcode {
483 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
485 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
486 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
487 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
488 "writeback_from_writepage" },
489 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
490 "writeback_from_pressure" },
491 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
492 "writeback_ok_pages" },
493 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
494 "writeback_failed_pages" },
495 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
497 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
499 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
501 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
504 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
505 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
506 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
507 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
508 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
509 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
510 /* inode operation */
511 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
512 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "punch" },
513 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
514 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
516 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
518 /* special inode operation */
519 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
520 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
521 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
523 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
525 { LPROC_LL_SETXATTR, LPROCFS_TYPE_REGS, "setxattr" },
526 { LPROC_LL_GETXATTR, LPROCFS_TYPE_REGS, "getxattr" },
529 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
530 struct super_block *sb, char *osc, char *mdc)
532 struct lprocfs_vars lvars[2];
533 struct ll_sb_info *sbi = ll_s2sbi(sb);
534 struct obd_device *obd;
535 char name[MAX_STRING_SIZE + 1];
537 struct lprocfs_stats *svc_stats = NULL;
538 struct proc_dir_entry *mdc_symlink, *osc_symlink;
539 struct proc_dir_entry *entry;
542 memset(lvars, 0, sizeof(lvars));
544 name[MAX_STRING_SIZE] = '\0';
545 lvars[0].name = name;
547 LASSERT(sbi != NULL);
548 LASSERT(mdc != NULL);
549 LASSERT(osc != NULL);
552 snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
555 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
556 if (IS_ERR(sbi->ll_proc_root)) {
557 err = PTR_ERR(sbi->ll_proc_root);
558 sbi->ll_proc_root = NULL;
562 entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
564 GOTO(out, err = -ENOMEM);
565 entry->proc_fops = &llite_dump_pgcache_fops;
568 entry = create_proc_entry("wait_times", 0444, sbi->ll_proc_root);
570 GOTO(out, err = -ENOMEM);
571 entry->proc_fops = &llite_wait_times_fops;
574 entry = create_proc_entry("read_ahead_stats", 0444, sbi->ll_proc_root);
576 GOTO(out, err = -ENOMEM);
577 entry->proc_fops = &ll_ra_stats_fops;
580 svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
581 if (svc_stats == NULL) {
585 /* do counter init */
586 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
587 __u32 type = llite_opcode_table[id].type;
589 if (type & LPROCFS_TYPE_REGS)
592 if (type & LPROCFS_TYPE_BYTES)
595 if (type & LPROCFS_TYPE_PAGES)
599 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
600 (type & LPROCFS_CNTR_AVGMINMAX),
601 llite_opcode_table[id].opname, ptr);
603 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
607 sbi->ll_stats = svc_stats;
608 /* need place to keep svc_stats */
610 /* Static configuration info */
611 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
616 obd = class_name2obd(mdc);
618 LASSERT(obd != NULL);
619 LASSERT(obd->obd_type != NULL);
620 LASSERT(obd->obd_type->typ_name != NULL);
622 snprintf(name, MAX_STRING_SIZE, "../../%s/%s",
623 obd->obd_type->typ_name, obd->obd_name);
624 mdc_symlink = proc_symlink(obd->obd_type->typ_name, sbi->ll_proc_root,
626 if (mdc_symlink == NULL) {
632 obd = class_name2obd(osc);
634 LASSERT(obd != NULL);
635 LASSERT(obd->obd_type != NULL);
636 LASSERT(obd->obd_type->typ_name != NULL);
638 snprintf(name, MAX_STRING_SIZE, "../../%s/%s",
639 obd->obd_type->typ_name, obd->obd_name);
640 osc_symlink = proc_symlink(obd->obd_type->typ_name, sbi->ll_proc_root,
642 if (osc_symlink == NULL)
649 lprocfs_free_stats(svc_stats);
650 if (sbi->ll_proc_root)
651 lprocfs_remove(sbi->ll_proc_root);
656 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
658 if (sbi->ll_proc_root) {
659 struct proc_dir_entry *file_stats =
660 lprocfs_srch(sbi->ll_proc_root, "stats");
663 lprocfs_free_stats(sbi->ll_stats);
664 lprocfs_remove(file_stats);
668 #undef MAX_STRING_SIZE
670 static struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
671 struct list_head *list)
673 struct ll_async_page *llap;
674 struct list_head *pos;
676 list_for_each(pos, list) {
677 if (pos == &sbi->ll_pglist)
679 llap = list_entry(pos, struct ll_async_page, llap_proc_item);
680 if (llap->llap_page == NULL)
688 #define seq_page_flag(seq, page, flag, has_flags) do { \
689 if (test_bit(PG_##flag, &(page)->flags)) { \
693 seq_putc(seq, '|'); \
694 seq_puts(seq, #flag); \
698 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
700 struct ll_async_page *llap, *dummy_llap = seq->private;
701 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
703 /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
704 * it in our own state */
705 if (dummy_llap->llap_magic == 0) {
706 seq_printf(seq, "generation | llap cookie origin | page ");
707 seq_printf(seq, "inode index count [ page flags ]\n");
711 spin_lock(&sbi->ll_lock);
713 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
716 struct page *page = llap->llap_page;
717 static char *origins[] = {
718 [LLAP_ORIGIN_UNKNOWN] = "--",
719 [LLAP_ORIGIN_READPAGE] = "rp",
720 [LLAP_ORIGIN_READAHEAD] = "ra",
721 [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
722 [LLAP_ORIGIN_WRITEPAGE] = "wp",
725 LASSERTF(llap->llap_origin < LLAP__ORIGIN_MAX, "%u\n",
728 seq_printf(seq, "%lu | %p %p %s | %p %p %lu %u [",
730 llap, llap->llap_cookie,
731 origins[llap->llap_origin],
732 page, page->mapping->host, page->index,
734 seq_page_flag(seq, page, locked, has_flags);
735 seq_page_flag(seq, page, error, has_flags);
736 seq_page_flag(seq, page, referenced, has_flags);
737 seq_page_flag(seq, page, uptodate, has_flags);
738 seq_page_flag(seq, page, dirty, has_flags);
739 seq_page_flag(seq, page, highmem, has_flags);
741 seq_puts(seq, "-]\n");
743 seq_puts(seq, "]\n");
746 spin_unlock(&sbi->ll_lock);
751 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
753 struct ll_async_page *llap = seq->private;
755 if (llap->llap_magic == 2)
761 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
764 struct ll_async_page *llap, *dummy_llap = seq->private;
765 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
767 /* bail if we just displayed the banner */
768 if (dummy_llap->llap_magic == 0) {
769 dummy_llap->llap_magic = 1;
773 /* we've just displayed the llap that is after us in the list.
774 * we advance to a position beyond it, returning null if there
775 * isn't another llap in the list beyond that new position. */
776 spin_lock(&sbi->ll_lock);
777 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
778 list_del_init(&dummy_llap->llap_proc_item);
780 list_add(&dummy_llap->llap_proc_item, &llap->llap_proc_item);
781 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
783 spin_unlock(&sbi->ll_lock);
787 dummy_llap->llap_magic = 2;
793 static void llite_dump_pgcache_seq_stop(struct seq_file *seq, void *v)
797 struct seq_operations llite_dump_pgcache_seq_sops = {
798 .start = llite_dump_pgcache_seq_start,
799 .stop = llite_dump_pgcache_seq_stop,
800 .next = llite_dump_pgcache_seq_next,
801 .show = llite_dump_pgcache_seq_show,
804 /* we're displaying llaps in a list_head list. we don't want to hold a lock
805 * while we walk the entire list, and we don't want to have to seek into
806 * the right position in the list as an app advances with many syscalls. we
807 * allocate a dummy llap and hang it off file->private. its position in
808 * the list records where the app is currently displaying. this way our
809 * seq .start and .stop don't actually do anything. .next returns null
810 * when the dummy hits the end of the list which eventually leads to .release
811 * where we tear down. this kind of displaying is super-racey, so we put
812 * a generation counter on the list so the output shows when the list
813 * changes between reads.
815 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
817 struct proc_dir_entry *dp = PDE(inode);
818 struct ll_async_page *llap;
819 struct seq_file *seq;
820 struct ll_sb_info *sbi = dp->data;
823 OBD_ALLOC_GFP(llap, sizeof(*llap), GFP_KERNEL);
826 llap->llap_page = NULL;
827 llap->llap_cookie = sbi;
828 llap->llap_magic = 0;
830 rc = seq_open(file, &llite_dump_pgcache_seq_sops);
832 OBD_FREE(llap, sizeof(*llap));
835 seq = file->private_data;
838 spin_lock(&sbi->ll_lock);
839 list_add(&llap->llap_proc_item, &sbi->ll_pglist);
840 spin_unlock(&sbi->ll_lock);
845 static int llite_dump_pgcache_seq_release(struct inode *inode,
848 struct seq_file *seq = file->private_data;
849 struct ll_async_page *llap = seq->private;
850 struct ll_sb_info *sbi = llap->llap_cookie;
852 spin_lock(&sbi->ll_lock);
853 if (!list_empty(&llap->llap_proc_item))
854 list_del_init(&llap->llap_proc_item);
855 spin_unlock(&sbi->ll_lock);
856 OBD_FREE(llap, sizeof(*llap));
858 return seq_release(inode, file);
861 struct file_operations llite_dump_pgcache_fops = {
862 .owner = THIS_MODULE,
863 .open = llite_dump_pgcache_seq_open,
865 .release = llite_dump_pgcache_seq_release,
867 static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
870 struct ll_sb_info *sbi = seq->private;
871 struct ll_ra_info *ra = &sbi->ll_ra_info;
873 static char *ra_stat_strings[] = {
874 [RA_STAT_HIT] = "hits",
875 [RA_STAT_MISS] = "misses",
876 [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
877 [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
878 [RA_STAT_FAILED_MATCH] = "failed lock match",
879 [RA_STAT_DISCARDED] = "read but discarded",
880 [RA_STAT_ZERO_LEN] = "zero length file",
881 [RA_STAT_ZERO_WINDOW] = "zero size window",
882 [RA_STAT_EOF] = "read-ahead to EOF",
883 [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
886 do_gettimeofday(&now);
888 spin_lock(&sbi->ll_lock);
890 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
891 now.tv_sec, now.tv_usec);
892 seq_printf(seq, "pending issued pages: %lu\n",
895 for(i = 0; i < _NR_RA_STAT; i++)
896 seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i],
899 spin_unlock(&sbi->ll_lock);
904 static void *ll_ra_stats_seq_start(struct seq_file *p, loff_t *pos)
910 static void *ll_ra_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
915 static void ll_ra_stats_seq_stop(struct seq_file *p, void *v)
918 struct seq_operations ll_ra_stats_seq_sops = {
919 .start = ll_ra_stats_seq_start,
920 .stop = ll_ra_stats_seq_stop,
921 .next = ll_ra_stats_seq_next,
922 .show = ll_ra_stats_seq_show,
925 static int ll_ra_stats_seq_open(struct inode *inode, struct file *file)
927 struct proc_dir_entry *dp = PDE(inode);
928 struct seq_file *seq;
931 rc = seq_open(file, &ll_ra_stats_seq_sops);
934 seq = file->private_data;
935 seq->private = dp->data;
939 static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
940 size_t len, loff_t *off)
942 struct seq_file *seq = file->private_data;
943 struct ll_sb_info *sbi = seq->private;
944 struct ll_ra_info *ra = &sbi->ll_ra_info;
946 spin_lock(&sbi->ll_lock);
947 memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
948 spin_unlock(&sbi->ll_lock);
953 struct file_operations ll_ra_stats_fops = {
954 .owner = THIS_MODULE,
955 .open = ll_ra_stats_seq_open,
957 .write = ll_ra_stats_seq_write,
959 .release = seq_release,
962 #define PRINTF_STIME(stime) (unsigned long)(stime)->st_num, \
963 lprocfs_stime_avg_ms(stime), lprocfs_stime_avg_us(stime)
965 static int llite_wait_times_seq_show(struct seq_file *seq, void *v)
967 struct ll_sb_info *sbi = seq->private;
970 do_gettimeofday(&now);
972 spin_lock(&sbi->ll_lock);
974 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n\n",
975 now.tv_sec, now.tv_usec);
977 seq_printf(seq, "lock wait times: (num, average ms)\n");
978 seq_printf(seq, "\tread\t%lu\t%lu.%04lu\n",
979 PRINTF_STIME(&sbi->ll_read_stime));
980 seq_printf(seq, "\twrite\t%lu\t%lu.%04lu\n",
981 PRINTF_STIME(&sbi->ll_write_stime));
982 seq_printf(seq, "\tgroup\t%lu\t%lu.%04lu\n",
983 PRINTF_STIME(&sbi->ll_grouplock_stime));
984 seq_printf(seq, "\tseek\t%lu\t%lu.%04lu\n",
985 PRINTF_STIME(&sbi->ll_seek_stime));
986 seq_printf(seq, "\tsetattr\t%lu\t%lu.%04lu\n\n",
987 PRINTF_STIME(&sbi->ll_setattr_stime));
989 seq_printf(seq, "io path wait times: (num, average ms)\n");
990 seq_printf(seq, "\tll_brw\t%lu\t%lu.%04lu\n",
991 PRINTF_STIME(&sbi->ll_brw_stime));
993 seq_printf(seq, "\tdone\t%lu\t%lu.%04lu\n",
994 PRINTF_STIME(&sbi->ll_done_stime));
997 spin_unlock(&sbi->ll_lock);
1003 static void *llite_wait_times_seq_start(struct seq_file *p, loff_t *pos)
1009 static void *llite_wait_times_seq_next(struct seq_file *p, void *v, loff_t *pos)
1014 static void llite_wait_times_seq_stop(struct seq_file *p, void *v)
1017 struct seq_operations llite_wait_times_seq_sops = {
1018 .start = llite_wait_times_seq_start,
1019 .stop = llite_wait_times_seq_stop,
1020 .next = llite_wait_times_seq_next,
1021 .show = llite_wait_times_seq_show,
1024 static int llite_wait_times_seq_open(struct inode *inode, struct file *file)
1026 struct proc_dir_entry *dp = PDE(inode);
1027 struct seq_file *seq;
1030 rc = seq_open(file, &llite_wait_times_seq_sops);
1033 seq = file->private_data;
1034 seq->private = dp->data;
1038 static ssize_t llite_wait_times_seq_write(struct file *file, const char *buf,
1039 size_t len, loff_t *off)
1041 struct seq_file *seq = file->private_data;
1042 struct ll_sb_info *sbi = seq->private;
1044 spin_lock(&sbi->ll_lock);
1045 memset(&sbi->ll_read_stime, 0, sizeof(sbi->ll_read_stime));
1046 memset(&sbi->ll_write_stime, 0, sizeof(sbi->ll_write_stime));
1047 memset(&sbi->ll_grouplock_stime, 0, sizeof(sbi->ll_grouplock_stime));
1048 memset(&sbi->ll_seek_stime, 0, sizeof(sbi->ll_seek_stime));
1049 memset(&sbi->ll_setattr_stime, 0, sizeof(sbi->ll_setattr_stime));
1050 memset(&sbi->ll_brw_stime, 0, sizeof(sbi->ll_brw_stime));
1051 // memset(&sbi->ll_done_stime, 0, sizeof(sbi->ll_done_stime));
1052 spin_unlock(&sbi->ll_lock);
1057 struct file_operations llite_wait_times_fops = {
1058 .owner = THIS_MODULE,
1059 .open = llite_wait_times_seq_open,
1061 .write = llite_wait_times_seq_write,
1062 .llseek = seq_lseek,
1063 .release = seq_release,
1066 #endif /* LPROCFS */