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 "llite_internal.h"
32 /* /proc/lustre/llite mount point registration */
33 struct proc_dir_entry *proc_lustre_fs_root;
34 struct file_operations llite_dump_pgcache_fops;
37 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
38 struct super_block *sb, char *osc, char *mdc)
42 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
45 long long mnt_instance;
47 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
50 struct super_block *sb = (struct super_block *)data;
51 struct obd_statfs osfs;
55 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
58 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
64 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
67 struct super_block *sb = (struct super_block *)data;
68 struct obd_statfs osfs;
72 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
74 __u32 blk_size = osfs.os_bsize >> 10;
75 __u64 result = osfs.os_blocks;
77 while (blk_size >>= 1)
81 rc = snprintf(page, count, LPU64"\n", result);
87 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
90 struct super_block *sb = (struct super_block *)data;
91 struct obd_statfs osfs;
95 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
97 __u32 blk_size = osfs.os_bsize >> 10;
98 __u64 result = osfs.os_bfree;
100 while (blk_size >>= 1)
104 rc = snprintf(page, count, LPU64"\n", result);
109 static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
110 int *eof, void *data)
112 struct super_block *sb = (struct super_block *)data;
113 struct obd_statfs osfs;
117 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
119 __u32 blk_size = osfs.os_bsize >> 10;
120 __u64 result = osfs.os_bavail;
122 while (blk_size >>= 1)
126 rc = snprintf(page, count, LPU64"\n", result);
131 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
132 int *eof, void *data)
134 struct super_block *sb = (struct super_block *)data;
135 struct obd_statfs osfs;
139 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
142 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
147 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
148 int *eof, void *data)
150 struct super_block *sb = (struct super_block *)data;
151 struct obd_statfs osfs;
155 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
158 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
164 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
165 int *eof, void *data)
167 struct super_block *sb = (struct super_block*)data;
171 return snprintf(page, count, "%s\n", sb->s_type->name);
174 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
175 int *eof, void *data)
177 struct super_block *sb = (struct super_block *)data;
181 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
184 static int ll_rd_read_ahead(char *page, char **start, off_t off, int count,
185 int *eof, void *data)
187 struct super_block *sb = (struct super_block*)data;
188 struct ll_sb_info *sbi = ll_s2sbi(sb);
193 val = (sbi->ll_flags & LL_SBI_READAHEAD) ? 1 : 0;
194 rc = snprintf(page, count, "%d\n", val);
198 static int ll_wr_read_ahead(struct file *file, const char *buffer,
199 unsigned long count, void *data)
201 struct super_block *sb = (struct super_block*)data;
202 struct ll_sb_info *sbi = ll_s2sbi(sb);
206 if (1 != sscanf(buffer, "%d", &readahead))
210 sbi->ll_flags |= LL_SBI_READAHEAD;
212 sbi->ll_flags &= ~LL_SBI_READAHEAD;
217 static int ll_wr_config_update(struct file *file, const char *buffer,
218 unsigned long count, void *data)
220 struct super_block *sb = (struct super_block*)data;
221 struct ll_sb_info *sbi = ll_s2sbi(sb);
224 CWARN("Starting a LOV/OST update !\n");
225 RETURN(ll_process_config_update(sbi, 0));
228 static int ll_rd_max_read_ahead_mb(char *page, char **start, off_t off,
229 int count, int *eof, void *data)
231 struct super_block *sb = data;
232 struct ll_sb_info *sbi = ll_s2sbi(sb);
235 spin_lock(&sbi->ll_lock);
236 val = (sbi->ll_max_read_ahead_pages << PAGE_CACHE_SHIFT) >> 20;
237 spin_unlock(&sbi->ll_lock);
239 return snprintf(page, count, "%u\n", val);
242 static int ll_wr_max_read_ahead_mb(struct file *file, const char *buffer,
243 unsigned long count, void *data)
245 struct super_block *sb = data;
246 struct ll_sb_info *sbi = ll_s2sbi(sb);
249 rc = lprocfs_write_helper(buffer, count, &val);
253 if (val < 0 || val > (num_physpages << PAGE_SHIFT) >> 20)
256 spin_lock(&sbi->ll_lock);
257 sbi->ll_max_read_ahead_pages = (val << 20) >> PAGE_CACHE_SHIFT;
258 spin_unlock(&sbi->ll_lock);
263 static struct lprocfs_vars lprocfs_obd_vars[] = {
264 { "uuid", ll_rd_sb_uuid, 0, 0 },
265 //{ "mntpt_path", ll_rd_path, 0, 0 },
266 { "fstype", ll_rd_fstype, 0, 0 },
267 { "blocksize", ll_rd_blksize, 0, 0 },
268 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
269 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
270 { "kbytesavail", ll_rd_kbytesavail, 0, 0 },
271 { "filestotal", ll_rd_filestotal, 0, 0 },
272 { "filesfree", ll_rd_filesfree, 0, 0 },
273 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
274 { "read_ahead", ll_rd_read_ahead, ll_wr_read_ahead, 0 },
275 { "config_update", 0, ll_wr_config_update, 0 },
276 { "max_read_ahead_mb", ll_rd_max_read_ahead_mb,
277 ll_wr_max_read_ahead_mb, 0 },
281 #define MAX_STRING_SIZE 128
283 struct llite_file_opcode {
287 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
289 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
290 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
291 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
292 "writeback_from_writepage" },
293 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
294 "writeback_from_pressure" },
295 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
296 "writeback_ok_pages" },
297 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
298 "writeback_failed_pages" },
299 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
301 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
303 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
305 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
308 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
309 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
310 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
311 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
312 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
313 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
314 /* inode operation */
315 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
316 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "punch" },
317 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
318 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
320 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
322 /* special inode operation */
323 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
324 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
325 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
327 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
332 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
333 struct super_block *sb, char *osc, char *mdc)
335 struct lprocfs_vars lvars[2];
336 struct ll_sb_info *sbi = ll_s2sbi(sb);
337 struct obd_device *obd;
338 char name[MAX_STRING_SIZE + 1];
340 struct lprocfs_stats *svc_stats = NULL;
341 struct proc_dir_entry *entry;
344 memset(lvars, 0, sizeof(lvars));
346 name[MAX_STRING_SIZE] = '\0';
347 lvars[0].name = name;
349 LASSERT(sbi != NULL);
350 LASSERT(mdc != NULL);
351 LASSERT(osc != NULL);
354 snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
357 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
358 if (IS_ERR(sbi->ll_proc_root)) {
359 err = PTR_ERR(sbi->ll_proc_root);
360 sbi->ll_proc_root = NULL;
364 entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
366 GOTO(out, err = -ENOMEM);
367 entry->proc_fops = &llite_dump_pgcache_fops;
370 svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
371 if (svc_stats == NULL) {
375 /* do counter init */
376 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
377 __u32 type = llite_opcode_table[id].type;
379 if (type & LPROCFS_TYPE_REGS)
382 if (type & LPROCFS_TYPE_BYTES)
385 if (type & LPROCFS_TYPE_PAGES)
389 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
390 (type & LPROCFS_CNTR_AVGMINMAX),
391 llite_opcode_table[id].opname, ptr);
393 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
397 sbi->ll_stats = svc_stats;
398 /* need place to keep svc_stats */
400 /* Static configuration info */
401 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
406 obd = class_name2obd(mdc);
408 LASSERT(obd != NULL);
409 LASSERT(obd->obd_type != NULL);
410 LASSERT(obd->obd_type->typ_name != NULL);
412 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
413 obd->obd_type->typ_name);
414 lvars[0].read_fptr = lprocfs_rd_name;
415 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
419 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
420 lvars[0].read_fptr = lprocfs_rd_uuid;
421 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
426 obd = class_name2obd(osc);
428 LASSERT(obd != NULL);
429 LASSERT(obd->obd_type != NULL);
430 LASSERT(obd->obd_type->typ_name != NULL);
432 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
433 obd->obd_type->typ_name);
434 lvars[0].read_fptr = lprocfs_rd_name;
435 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
439 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
440 lvars[0].read_fptr = lprocfs_rd_uuid;
441 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
445 lprocfs_free_stats(svc_stats);
446 if (sbi->ll_proc_root)
447 lprocfs_remove(sbi->ll_proc_root);
452 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
454 if (sbi->ll_proc_root) {
455 struct proc_dir_entry *file_stats =
456 lprocfs_srch(sbi->ll_proc_root, "stats");
459 lprocfs_free_stats(sbi->ll_stats);
460 lprocfs_remove(file_stats);
464 #undef MAX_STRING_SIZE
466 static struct ll_async_page *llite_pglist_next_llap(struct ll_sb_info *sbi,
467 struct list_head *list)
469 struct ll_async_page *llap;
470 struct list_head *pos;
472 list_for_each(pos, list) {
473 if (pos == &sbi->ll_pglist)
475 llap = list_entry(pos, struct ll_async_page, llap_proc_item);
476 if (llap->llap_page == NULL)
484 #define seq_page_flag(seq, page, flag, has_flags) do { \
485 if (test_bit(PG_##flag, &(page)->flags)) { \
489 seq_putc(seq, '|'); \
490 seq_puts(seq, #flag); \
494 static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
496 struct ll_async_page *llap, *dummy_llap = seq->private;
497 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
499 /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
500 * it in our own state */
501 if (dummy_llap->llap_magic == 0) {
502 seq_printf(seq, "generation | llap .cookie | page ");
503 seq_printf(seq, "inode .index [ page flags ]\n");
507 spin_lock(&sbi->ll_lock);
509 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
512 struct page *page = llap->llap_page;
514 seq_printf(seq, "%lu | %p %p | %p %p %lu [",
516 llap, llap->llap_cookie,
517 page, page->mapping->host, page->index);
518 seq_page_flag(seq, page, locked, has_flags);
519 seq_page_flag(seq, page, error, has_flags);
520 seq_page_flag(seq, page, referenced, has_flags);
521 seq_page_flag(seq, page, uptodate, has_flags);
522 seq_page_flag(seq, page, dirty, has_flags);
523 seq_page_flag(seq, page, highmem, has_flags);
525 seq_puts(seq, "-]\n");
527 seq_puts(seq, "]\n");
530 spin_unlock(&sbi->ll_lock);
535 static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
537 struct ll_async_page *llap = seq->private;
539 if (llap->llap_magic == 2)
545 static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
548 struct ll_async_page *llap, *dummy_llap = seq->private;
549 struct ll_sb_info *sbi = dummy_llap->llap_cookie;
551 /* bail if we just displayed the banner */
552 if (dummy_llap->llap_magic == 0) {
553 dummy_llap->llap_magic = 1;
557 /* we've just displayed the llap that is after us in the list.
558 * we advance to a position beyond it, returning null if there
559 * isn't another llap in the list beyond that new position. */
560 spin_lock(&sbi->ll_lock);
561 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
562 list_del_init(&dummy_llap->llap_proc_item);
564 list_add(&dummy_llap->llap_proc_item, &llap->llap_proc_item);
565 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
567 spin_unlock(&sbi->ll_lock);
571 dummy_llap->llap_magic = 2;
577 static void llite_dump_pgcache_seq_stop(struct seq_file *seq, void *v)
581 struct seq_operations llite_dump_pgcache_seq_sops = {
582 .start = llite_dump_pgcache_seq_start,
583 .stop = llite_dump_pgcache_seq_stop,
584 .next = llite_dump_pgcache_seq_next,
585 .show = llite_dump_pgcache_seq_show,
588 /* we're displaying llaps in a list_head list. we don't want to hold a lock
589 * while we walk the entire list, and we don't want to have to seek into
590 * the right position in the list as an app advances with many syscalls. we
591 * allocate a dummy llap and hang it off file->private. its position in
592 * the list records where the app is currently displaying. this way our
593 * seq .start and .stop don't actually do anything. .next returns null
594 * when the dummy hits the end of the list which eventually leads to .release
595 * where we tear down. this kind of displaying is super-racey, so we put
596 * a generation counter on the list so the output shows when the list
597 * changes between reads.
599 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
601 struct proc_dir_entry *dp = PDE(inode);
602 struct ll_async_page *llap;
603 struct seq_file *seq;
604 struct ll_sb_info *sbi = dp->data;
607 OBD_ALLOC_GFP(llap, sizeof(*llap), GFP_KERNEL);
610 llap->llap_page = NULL;
611 llap->llap_cookie = sbi;
612 llap->llap_magic = 0;
614 rc = seq_open(file, &llite_dump_pgcache_seq_sops);
616 OBD_FREE(llap, sizeof(*llap));
619 seq = file->private_data;
622 spin_lock(&sbi->ll_lock);
623 list_add(&llap->llap_proc_item, &sbi->ll_pglist);
624 spin_unlock(&sbi->ll_lock);
629 static int llite_dump_pgcache_seq_release(struct inode *inode,
632 struct seq_file *seq = file->private_data;
633 struct ll_async_page *llap = seq->private;
634 struct ll_sb_info *sbi = llap->llap_cookie;
636 spin_lock(&sbi->ll_lock);
637 if (!list_empty(&llap->llap_proc_item))
638 list_del_init(&llap->llap_proc_item);
639 spin_unlock(&sbi->ll_lock);
640 OBD_FREE(llap, sizeof(*llap));
642 return seq_release(inode, file);
645 struct file_operations llite_dump_pgcache_fops = {
646 .owner = THIS_MODULE,
647 .open = llite_dump_pgcache_seq_open,
649 .release = llite_dump_pgcache_seq_release,