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>
28 #include "llite_internal.h"
30 /* /proc/lustre/llite mount point registration */
31 struct proc_dir_entry *proc_lustre_fs_root;
34 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
35 struct super_block *sb, char *osc, char *mdc)
39 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi){}
42 long long mnt_instance;
44 static int ll_rd_blksize(char *page, char **start, off_t off, int count,
47 struct super_block *sb = (struct super_block *)data;
48 struct obd_statfs osfs;
52 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
55 rc = snprintf(page, count, "%u\n", osfs.os_bsize);
61 static int ll_rd_kbytestotal(char *page, char **start, off_t off, int count,
64 struct super_block *sb = (struct super_block *)data;
65 struct obd_statfs osfs;
69 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
71 __u32 blk_size = osfs.os_bsize >> 10;
72 __u64 result = osfs.os_blocks;
74 while (blk_size >>= 1)
78 rc = snprintf(page, count, LPU64"\n", result);
84 static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
87 struct super_block *sb = (struct super_block *)data;
88 struct obd_statfs osfs;
92 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
94 __u32 blk_size = osfs.os_bsize >> 10;
95 __u64 result = osfs.os_bfree;
97 while (blk_size >>= 1)
101 rc = snprintf(page, count, LPU64"\n", result);
106 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
107 int *eof, void *data)
109 struct super_block *sb = (struct super_block *)data;
110 struct obd_statfs osfs;
114 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
117 rc = snprintf(page, count, LPU64"\n", osfs.os_files);
122 static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
123 int *eof, void *data)
125 struct super_block *sb = (struct super_block *)data;
126 struct obd_statfs osfs;
130 rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
133 rc = snprintf(page, count, LPU64"\n", osfs.os_ffree);
140 static int ll_rd_path(char *page, char **start, off_t off, int count, int *eof,
147 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
148 int *eof, void *data)
150 struct super_block *sb = (struct super_block*)data;
154 return snprintf(page, count, "%s\n", sb->s_type->name);
157 static int ll_rd_sb_uuid(char *page, char **start, off_t off, int count,
158 int *eof, void *data)
160 struct super_block *sb = (struct super_block *)data;
164 return snprintf(page, count, "%s\n", ll_s2sbi(sb)->ll_sb_uuid.uuid);
167 static struct lprocfs_vars lprocfs_obd_vars[] = {
168 { "uuid", ll_rd_sb_uuid, 0, 0 },
169 //{ "mntpt_path", ll_rd_path, 0, 0 },
170 { "fstype", ll_rd_fstype, 0, 0 },
171 { "blocksize", ll_rd_blksize, 0, 0 },
172 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
173 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
174 { "filestotal", ll_rd_filestotal, 0, 0 },
175 { "filesfree", ll_rd_filesfree, 0, 0 },
176 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
177 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
178 { "dirty_pages", ll_rd_dirty_pages, 0, 0},
179 { "max_dirty_pages", ll_rd_max_dirty_pages, ll_wr_max_dirty_pages, 0},
184 #define MAX_STRING_SIZE 128
186 struct llite_file_opcode {
190 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
192 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
193 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
194 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
195 "writeback_from_writepage" },
196 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
197 "writeback_from_pressure" },
198 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
199 "writeback_ok_pages" },
200 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
201 "writeback_failed_pages" },
202 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
204 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
206 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
208 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
211 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
212 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
213 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
214 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
215 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
216 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
217 /* inode operation */
218 { LPROC_LL_SETATTR_RAW, LPROCFS_TYPE_REGS, "setattr_raw" },
219 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
220 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "punch" },
221 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
222 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
224 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
226 /* special inode operation */
227 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
228 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
229 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
231 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
236 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
237 struct super_block *sb, char *osc, char *mdc)
239 struct lprocfs_vars lvars[2];
240 struct ll_sb_info *sbi = ll_s2sbi(sb);
241 struct obd_device *obd;
242 char name[MAX_STRING_SIZE + 1];
244 struct lprocfs_stats *svc_stats = NULL;
247 memset(lvars, 0, sizeof(lvars));
249 name[MAX_STRING_SIZE] = '\0';
250 lvars[0].name = name;
252 LASSERT(sbi != NULL);
253 LASSERT(mdc != NULL);
254 LASSERT(osc != NULL);
257 snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
260 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
261 if (IS_ERR(sbi->ll_proc_root)) {
262 err = PTR_ERR(sbi->ll_proc_root);
263 sbi->ll_proc_root = NULL;
267 svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
268 if (svc_stats == NULL) {
272 /* do counter init */
273 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
274 __u32 type = llite_opcode_table[id].type;
276 if (type & LPROCFS_TYPE_REGS)
279 if (type & LPROCFS_TYPE_BYTES)
282 if (type & LPROCFS_TYPE_PAGES)
286 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
287 (type & LPROCFS_CNTR_AVGMINMAX),
288 llite_opcode_table[id].opname, ptr);
290 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
294 sbi->ll_stats = svc_stats;
295 /* need place to keep svc_stats */
297 /* Static configuration info */
298 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
303 obd = class_name2obd(mdc);
305 LASSERT(obd != NULL);
306 LASSERT(obd->obd_type != NULL);
307 LASSERT(obd->obd_type->typ_name != NULL);
309 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
310 obd->obd_type->typ_name);
311 lvars[0].read_fptr = lprocfs_rd_name;
312 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
316 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
317 lvars[0].read_fptr = lprocfs_rd_uuid;
318 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
323 obd = class_name2obd(osc);
325 LASSERT(obd != NULL);
326 LASSERT(obd->obd_type != NULL);
327 LASSERT(obd->obd_type->typ_name != NULL);
329 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
330 obd->obd_type->typ_name);
331 lvars[0].read_fptr = lprocfs_rd_name;
332 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
336 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
337 lvars[0].read_fptr = lprocfs_rd_uuid;
338 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
342 lprocfs_free_stats(svc_stats);
343 if (sbi->ll_proc_root)
344 lprocfs_remove(sbi->ll_proc_root);
349 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
351 if (sbi->ll_proc_root) {
352 struct proc_dir_entry *file_stats =
353 lprocfs_srch(sbi->ll_proc_root, "stats");
356 lprocfs_free_stats(sbi->ll_stats);
357 lprocfs_remove(file_stats);
361 #undef MAX_STRING_SIZE