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 int ll_rd_read_ahead(char *page, char **start, off_t off, int count,
168 int *eof, void *data)
170 struct super_block *sb = (struct super_block*)data;
171 struct ll_sb_info *sbi = ll_s2sbi(sb);
176 val = (sbi->ll_flags & LL_SBI_READAHEAD) ? 1 : 0;
177 rc = snprintf(page, count, "%d\n", val);
181 static int ll_wr_read_ahead(struct file *file, const char *buffer,
182 unsigned long count, void *data)
184 struct super_block *sb = (struct super_block*)data;
185 struct ll_sb_info *sbi = ll_s2sbi(sb);
189 if (1 != sscanf(buffer, "%d", &readahead))
193 sbi->ll_flags |= LL_SBI_READAHEAD;
195 sbi->ll_flags &= ~LL_SBI_READAHEAD;
200 static struct lprocfs_vars lprocfs_obd_vars[] = {
201 { "uuid", ll_rd_sb_uuid, 0, 0 },
202 //{ "mntpt_path", ll_rd_path, 0, 0 },
203 { "fstype", ll_rd_fstype, 0, 0 },
204 { "blocksize", ll_rd_blksize, 0, 0 },
205 { "kbytestotal", ll_rd_kbytestotal, 0, 0 },
206 { "kbytesfree", ll_rd_kbytesfree, 0, 0 },
207 { "filestotal", ll_rd_filestotal, 0, 0 },
208 { "filesfree", ll_rd_filesfree, 0, 0 },
209 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
210 { "read_ahead", ll_rd_read_ahead, ll_wr_read_ahead, 0 },
214 #define MAX_STRING_SIZE 128
216 struct llite_file_opcode {
220 } llite_opcode_table[LPROC_LL_FILE_OPCODES] = {
222 { LPROC_LL_DIRTY_HITS, LPROCFS_TYPE_REGS, "dirty_pages_hits" },
223 { LPROC_LL_DIRTY_MISSES, LPROCFS_TYPE_REGS, "dirty_pages_misses" },
224 { LPROC_LL_WB_WRITEPAGE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
225 "writeback_from_writepage" },
226 { LPROC_LL_WB_PRESSURE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
227 "writeback_from_pressure" },
228 { LPROC_LL_WB_OK, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
229 "writeback_ok_pages" },
230 { LPROC_LL_WB_FAIL, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
231 "writeback_failed_pages" },
232 { LPROC_LL_READ_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
234 { LPROC_LL_WRITE_BYTES, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_BYTES,
236 { LPROC_LL_BRW_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
238 { LPROC_LL_BRW_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
241 { LPROC_LL_IOCTL, LPROCFS_TYPE_REGS, "ioctl" },
242 { LPROC_LL_OPEN, LPROCFS_TYPE_REGS, "open" },
243 { LPROC_LL_RELEASE, LPROCFS_TYPE_REGS, "close" },
244 { LPROC_LL_MAP, LPROCFS_TYPE_REGS, "mmap" },
245 { LPROC_LL_LLSEEK, LPROCFS_TYPE_REGS, "seek" },
246 { LPROC_LL_FSYNC, LPROCFS_TYPE_REGS, "fsync" },
247 /* inode operation */
248 { LPROC_LL_SETATTR, LPROCFS_TYPE_REGS, "setattr" },
249 { LPROC_LL_TRUNC, LPROCFS_TYPE_REGS, "punch" },
250 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
251 { LPROC_LL_GETATTR, LPROCFS_TYPE_REGS, "getattr" },
253 { LPROC_LL_REVALIDATE, LPROCFS_TYPE_REGS, "getattr" },
255 /* special inode operation */
256 { LPROC_LL_STAFS, LPROCFS_TYPE_REGS, "statfs" },
257 { LPROC_LL_ALLOC_INODE, LPROCFS_TYPE_REGS, "alloc_inode" },
258 { LPROC_LL_DIRECT_READ, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
260 { LPROC_LL_DIRECT_WRITE, LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
265 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
266 struct super_block *sb, char *osc, char *mdc)
268 struct lprocfs_vars lvars[2];
269 struct ll_sb_info *sbi = ll_s2sbi(sb);
270 struct obd_device *obd;
271 char name[MAX_STRING_SIZE + 1];
273 struct lprocfs_stats *svc_stats = NULL;
276 memset(lvars, 0, sizeof(lvars));
278 name[MAX_STRING_SIZE] = '\0';
279 lvars[0].name = name;
281 LASSERT(sbi != NULL);
282 LASSERT(mdc != NULL);
283 LASSERT(osc != NULL);
286 snprintf(name, MAX_STRING_SIZE, "fs%llu", mnt_instance);
289 sbi->ll_proc_root = lprocfs_register(name, parent, NULL, NULL);
290 if (IS_ERR(sbi->ll_proc_root)) {
291 err = PTR_ERR(sbi->ll_proc_root);
292 sbi->ll_proc_root = NULL;
296 svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
297 if (svc_stats == NULL) {
301 /* do counter init */
302 for (id = 0; id < LPROC_LL_FILE_OPCODES; id++) {
303 __u32 type = llite_opcode_table[id].type;
305 if (type & LPROCFS_TYPE_REGS)
308 if (type & LPROCFS_TYPE_BYTES)
311 if (type & LPROCFS_TYPE_PAGES)
315 lprocfs_counter_init(svc_stats, llite_opcode_table[id].opcode,
316 (type & LPROCFS_CNTR_AVGMINMAX),
317 llite_opcode_table[id].opname, ptr);
319 err = lprocfs_register_stats(sbi->ll_proc_root, "stats", svc_stats);
323 sbi->ll_stats = svc_stats;
324 /* need place to keep svc_stats */
326 /* Static configuration info */
327 err = lprocfs_add_vars(sbi->ll_proc_root, lprocfs_obd_vars, sb);
332 obd = class_name2obd(mdc);
334 LASSERT(obd != NULL);
335 LASSERT(obd->obd_type != NULL);
336 LASSERT(obd->obd_type->typ_name != NULL);
338 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
339 obd->obd_type->typ_name);
340 lvars[0].read_fptr = lprocfs_rd_name;
341 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
345 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
346 lvars[0].read_fptr = lprocfs_rd_uuid;
347 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
352 obd = class_name2obd(osc);
354 LASSERT(obd != NULL);
355 LASSERT(obd->obd_type != NULL);
356 LASSERT(obd->obd_type->typ_name != NULL);
358 snprintf(name, MAX_STRING_SIZE, "%s/common_name",
359 obd->obd_type->typ_name);
360 lvars[0].read_fptr = lprocfs_rd_name;
361 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
365 snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
366 lvars[0].read_fptr = lprocfs_rd_uuid;
367 err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
371 lprocfs_free_stats(svc_stats);
372 if (sbi->ll_proc_root)
373 lprocfs_remove(sbi->ll_proc_root);
378 void lprocfs_unregister_mountpoint(struct ll_sb_info *sbi)
380 if (sbi->ll_proc_root) {
381 struct proc_dir_entry *file_stats =
382 lprocfs_srch(sbi->ll_proc_root, "stats");
385 lprocfs_free_stats(sbi->ll_stats);
386 lprocfs_remove(file_stats);
390 #undef MAX_STRING_SIZE