blob: db3b1a9c9a5b9d7ea36075a0d5e1d9df320ebb00 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Sysctl operations for Coda filesystem
3 * Original version: (C) 1996 P. Braam and M. Callahan
4 * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University
5 *
6 * Carnegie Mellon encourages users to contribute improvements to
7 * the Coda project. Contact Peter Braam (coda@cs.cmu.edu).
8 *
9 * CODA operation statistics
10 * (c) March, 1998 Zhanyong Wan <zhanyong.wan@yale.edu>
11 *
12 */
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/time.h>
15#include <linux/mm.h>
16#include <linux/sysctl.h>
17#include <linux/proc_fs.h>
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -080018#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/slab.h>
20#include <linux/stat.h>
21#include <linux/ctype.h>
22#include <linux/bitops.h>
23#include <asm/uaccess.h>
24#include <linux/utsname.h>
25#include <linux/module.h>
26
27#include <linux/coda.h>
28#include <linux/coda_linux.h>
29#include <linux/coda_fs_i.h>
30#include <linux/coda_psdev.h>
31#include <linux/coda_cache.h>
32#include <linux/coda_proc.h>
33
34static struct ctl_table_header *fs_table_header;
35
36#define FS_CODA 1 /* Coda file system */
37
38#define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */
39#define CODA_HARD 5 /* mount type "hard" or "soft" */
40#define CODA_VFS 6 /* vfs statistics */
41#define CODA_CACHE_INV 9 /* cache invalidation statistics */
42#define CODA_FAKE_STATFS 10 /* don't query venus for actual cache usage */
43
44struct coda_vfs_stats coda_vfs_stat;
45static struct coda_cache_inv_stats coda_cache_inv_stat;
46
47static void reset_coda_vfs_stats( void )
48{
49 memset( &coda_vfs_stat, 0, sizeof( coda_vfs_stat ) );
50}
51
52static void reset_coda_cache_inv_stats( void )
53{
54 memset( &coda_cache_inv_stat, 0, sizeof( coda_cache_inv_stat ) );
55}
56
57static int do_reset_coda_vfs_stats( ctl_table * table, int write,
58 struct file * filp, void __user * buffer,
59 size_t * lenp, loff_t * ppos )
60{
61 if ( write ) {
62 reset_coda_vfs_stats();
63
64 *ppos += *lenp;
65 } else {
66 *lenp = 0;
67 }
68
69 return 0;
70}
71
72static int do_reset_coda_cache_inv_stats( ctl_table * table, int write,
73 struct file * filp,
74 void __user * buffer,
75 size_t * lenp, loff_t * ppos )
76{
77 if ( write ) {
78 reset_coda_cache_inv_stats();
79
80 *ppos += *lenp;
81 } else {
82 *lenp = 0;
83 }
84
85 return 0;
86}
87
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -080088static int proc_vfs_stats_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 struct coda_vfs_stats * ps = & coda_vfs_stat;
91
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -080092 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 "Coda VFS statistics\n"
94 "===================\n\n"
95 "File Operations:\n"
96 "\topen\t\t%9d\n"
97 "\tflush\t\t%9d\n"
98 "\trelease\t\t%9d\n"
99 "\tfsync\t\t%9d\n\n"
100 "Dir Operations:\n"
101 "\treaddir\t\t%9d\n\n"
102 "Inode Operations\n"
103 "\tcreate\t\t%9d\n"
104 "\tlookup\t\t%9d\n"
105 "\tlink\t\t%9d\n"
106 "\tunlink\t\t%9d\n"
107 "\tsymlink\t\t%9d\n"
108 "\tmkdir\t\t%9d\n"
109 "\trmdir\t\t%9d\n"
110 "\trename\t\t%9d\n"
111 "\tpermission\t%9d\n",
112
113 /* file operations */
114 ps->open,
115 ps->flush,
116 ps->release,
117 ps->fsync,
118
119 /* dir operations */
120 ps->readdir,
121
122 /* inode operations */
123 ps->create,
124 ps->lookup,
125 ps->link,
126 ps->unlink,
127 ps->symlink,
128 ps->mkdir,
129 ps->rmdir,
130 ps->rename,
131 ps->permission);
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -0800132 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -0800135static int proc_cache_inv_stats_show(struct seq_file *m, void *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 struct coda_cache_inv_stats * ps = & coda_cache_inv_stat;
138
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -0800139 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 "Coda cache invalidation statistics\n"
141 "==================================\n\n"
142 "flush\t\t%9d\n"
143 "purge user\t%9d\n"
144 "zap_dir\t\t%9d\n"
145 "zap_file\t%9d\n"
146 "zap_vnode\t%9d\n"
147 "purge_fid\t%9d\n"
148 "replace\t\t%9d\n",
149 ps->flush,
150 ps->purge_user,
151 ps->zap_dir,
152 ps->zap_file,
153 ps->zap_vnode,
154 ps->purge_fid,
155 ps->replace );
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -0800156 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157}
158
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -0800159static int proc_vfs_stats_open(struct inode *inode, struct file *file)
160{
161 return single_open(file, proc_vfs_stats_show, NULL);
162}
163
164static int proc_cache_inv_stats_open(struct inode *inode, struct file *file)
165{
166 return single_open(file, proc_cache_inv_stats_show, NULL);
167}
168
169static const struct file_operations proc_vfs_stats_fops = {
170 .owner = THIS_MODULE,
171 .open = proc_vfs_stats_open,
172 .read = seq_read,
173 .llseek = seq_lseek,
174 .release = single_release,
175};
176
177static const struct file_operations proc_cache_inv_stats_fops = {
178 .owner = THIS_MODULE,
179 .open = proc_cache_inv_stats_open,
180 .read = seq_read,
181 .llseek = seq_lseek,
182 .release = single_release,
183};
184
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185static ctl_table coda_table[] = {
186 {CODA_TIMEOUT, "timeout", &coda_timeout, sizeof(int), 0644, NULL, &proc_dointvec},
187 {CODA_HARD, "hard", &coda_hard, sizeof(int), 0644, NULL, &proc_dointvec},
188 {CODA_VFS, "vfs_stats", NULL, 0, 0644, NULL, &do_reset_coda_vfs_stats},
189 {CODA_CACHE_INV, "cache_inv_stats", NULL, 0, 0644, NULL, &do_reset_coda_cache_inv_stats},
190 {CODA_FAKE_STATFS, "fake_statfs", &coda_fake_statfs, sizeof(int), 0600, NULL, &proc_dointvec},
191 { 0 }
192};
193
194static ctl_table fs_table[] = {
195 {FS_CODA, "coda", NULL, 0, 0555, coda_table},
196 {0}
197};
198
199
200#ifdef CONFIG_PROC_FS
201
202/*
203 target directory structure:
204 /proc/fs (see linux/fs/proc/root.c)
205 /proc/fs/coda
206 /proc/fs/coda/{vfs_stats,
207
208*/
209
210static struct proc_dir_entry* proc_fs_coda;
211
212#endif
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214void coda_sysctl_init(void)
215{
216 reset_coda_vfs_stats();
217 reset_coda_cache_inv_stats();
218
219#ifdef CONFIG_PROC_FS
220 proc_fs_coda = proc_mkdir("coda", proc_root_fs);
221 if (proc_fs_coda) {
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -0800222 struct proc_dir_entry *pde;
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 proc_fs_coda->owner = THIS_MODULE;
Alexey Dobriyan9bbf81e2007-02-10 01:46:11 -0800225 pde = create_proc_entry("vfs_stats", 0, proc_fs_coda);
226 if (pde)
227 pde->proc_fops = &proc_vfs_stats_fops;
228 pde = create_proc_entry("cache_inv_stats", 0, proc_fs_coda);
229 if (pde)
230 pde->proc_fops = &proc_cache_inv_stats_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232#endif
233
234#ifdef CONFIG_SYSCTL
235 if ( !fs_table_header )
236 fs_table_header = register_sysctl_table(fs_table, 0);
237#endif
238}
239
240void coda_sysctl_clean(void)
241{
242
243#ifdef CONFIG_SYSCTL
244 if ( fs_table_header ) {
245 unregister_sysctl_table(fs_table_header);
246 fs_table_header = NULL;
247 }
248#endif
249
250#ifdef CONFIG_PROC_FS
251 remove_proc_entry("cache_inv_stats", proc_fs_coda);
252 remove_proc_entry("vfs_stats", proc_fs_coda);
253 remove_proc_entry("coda", proc_root_fs);
254#endif
255}