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 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
26 #include <asm/statfs.h>
28 #include <linux/lustre_lite.h>
29 #include <linux/lprocfs_status.h>
31 #include "llite_internal.h"
33 /* /proc/lustre/llite mount point registration */
36 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
37 struct super_block *sb, char *osc, char *mdc)
41 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
44 #define LPROC_LLITE_STAT_FCT(fct_name, get_statfs_fct) \
45 int fct_name(char *page, char **start, off_t off, \
46 int count, int *eof, void *data) \
50 LASSERT(data != NULL); \
51 rc = get_statfs_fct((struct super_block*)data, &sfs); \
53 ? lprocfs_##fct_name (page, start, off, count, eof, &sfs) \
57 long long mnt_instance;
59 LPROC_LLITE_STAT_FCT(rd_blksize, vfs_statfs);
60 LPROC_LLITE_STAT_FCT(rd_kbytestotal, vfs_statfs);
61 LPROC_LLITE_STAT_FCT(rd_kbytesfree, vfs_statfs);
62 LPROC_LLITE_STAT_FCT(rd_filestotal, vfs_statfs);
63 LPROC_LLITE_STAT_FCT(rd_filesfree, vfs_statfs);
64 LPROC_LLITE_STAT_FCT(rd_filegroups, vfs_statfs);
66 int rd_path(char *page, char **start, off_t off, int count, int *eof,
72 int rd_fstype(char *page, char **start, off_t off, int count, int *eof,
75 struct super_block *sb = (struct super_block*)data;
79 return snprintf(page, count, "%s\n", sb->s_type->name);
82 int rd_sb_uuid(char *page, char **start, off_t off, int count, int *eof,
85 struct super_block *sb = (struct super_block *)data;
89 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
92 struct lprocfs_vars lprocfs_obd_vars[] = {
93 { "uuid", rd_sb_uuid, 0, 0 },
94 { "mntpt_path", rd_path, 0, 0 },
95 { "fstype", rd_fstype, 0, 0 },
96 { "blocksize", rd_blksize, 0, 0 },
97 { "kbytestotal", rd_kbytestotal, 0, 0 },
98 { "kbytesfree", rd_kbytesfree, 0, 0 },
99 { "filestotal", rd_filestotal, 0, 0 },
100 { "filesfree", rd_filesfree, 0, 0 },
101 { "filegroups", rd_filegroups, 0, 0 },
102 { "dirty_pages", ll_rd_dirty_pages, 0, 0},
103 { "max_dirty_pages", ll_rd_max_dirty_pages, ll_wr_max_dirty_pages, 0},
107 #define MAX_STRING_SIZE 128
109 struct llite_file_opcode {
113 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
115 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
116 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
117 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
118 "writeback_from_writepage" },
119 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
120 "writeback_from_pressure" },
121 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
122 "writeback_ok_pages" },
123 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
124 "writeback_failed_pages" },
125 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
127 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
129 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
131 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
134 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
135 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
136 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
137 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
138 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
139 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
140 /* inode operation */
141 { LPROC_LL_SETATTR_RAW, LPROCFS_TYPE_REGS, "setattr_raw" },
142 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
143 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "punch" },
144 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
145 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
147 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
149 /* special inode operation */
150 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
151 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
152 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
154 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
159 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
160 struct super_block *sb, char *osc, char *mdc)
162 struct lprocfs_vars lvars[2];
163 struct ll_sb_info *sbi = ll_s2sbi(sb);
164 struct obd_device *obd;
165 char name[MAX_STRING_SIZE + 1];
167 struct lprocfs_stats *svc_stats = NULL;
170 memset(lvars, 0, sizeof(lvars));
172 name[MAX_STRING_SIZE] = '\0';
173 lvars[0].name = name;
175 LASSERT(sbi != NULL);
176 LASSERT(mdc != NULL);
177 LASSERT(osc != NULL);
180 snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
183 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
184 if (IS_ERR(sbi->ll_proc_root)) {
185 err = PTR_ERR(sbi->ll_proc_root);
186 sbi->ll_proc_root = NULL;
190 svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
191 if (svc_stats == NULL) {
195 /* do counter init */
196 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
197 __u32 type = llite_opcode_table[id].type;
199 if (type & LPROCFS_TYPE_REGS)
202 if (type & LPROCFS_TYPE_BYTES)
205 if (type & LPROCFS_TYPE_PAGES)
209 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
210 (type & LPROCFS_CNTR_AVGMINMAX),
211 llite_opcode_table[id].opname, ptr);
213 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
217 sbi->ll_stats = svc_stats;
218 /* need place to keep svc_stats */
220 /* Static configuration info */
221 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
226 obd = class_name2obd(mdc);
228 LASSERT(obd != NULL);
229 LASSERT(obd->obd_type != NULL);
230 LASSERT(obd->obd_type->typ_name != NULL);
232 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
233 obd->obd_type->typ_name);
234 lvars[0].read_fptr = lprocfs_rd_name;
235 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
239 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
240 lvars[0].read_fptr = lprocfs_rd_uuid;
241 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
246 obd = class_name2obd(osc);
248 LASSERT(obd != NULL);
249 LASSERT(obd->obd_type != NULL);
250 LASSERT(obd->obd_type->typ_name != NULL);
252 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
253 obd->obd_type->typ_name);
254 lvars[0].read_fptr = lprocfs_rd_name;
255 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
259 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
260 lvars[0].read_fptr = lprocfs_rd_uuid;
261 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
265 lprocfs_free_stats(svc_stats);
266 if (sbi->ll_proc_root)
267 lprocfs_remove(sbi->ll_proc_root);
272 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
274 if (sbi->ll_proc_root) {
275 struct proc_dir_entry *file_stats =
276 lprocfs_srch(sbi->ll_proc_root, "stats");
279 lprocfs_free_stats(sbi->ll_stats);
280 lprocfs_remove(file_stats);
284 #undef MAX_STRING_SIZE