Commit 9bbf81e4830db873300c1d0503b371b4f8a932ce
Committed by
Linus Torvalds
1 parent
85cc9b1144
Exists in
master
and in
7 other branches
[PATCH] seq_file conversion: coda
Compile-tested. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Cc: <jaharkes@cs.cmu.edu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 39 additions and 37 deletions Inline Diff
fs/coda/sysctl.c
1 | /* | 1 | /* |
2 | * Sysctl operations for Coda filesystem | 2 | * Sysctl operations for Coda filesystem |
3 | * Original version: (C) 1996 P. Braam and M. Callahan | 3 | * Original version: (C) 1996 P. Braam and M. Callahan |
4 | * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University | 4 | * Rewritten for Linux 2.1. (C) 1997 Carnegie Mellon University |
5 | * | 5 | * |
6 | * Carnegie Mellon encourages users to contribute improvements to | 6 | * Carnegie Mellon encourages users to contribute improvements to |
7 | * the Coda project. Contact Peter Braam (coda@cs.cmu.edu). | 7 | * the Coda project. Contact Peter Braam (coda@cs.cmu.edu). |
8 | * | 8 | * |
9 | * CODA operation statistics | 9 | * CODA operation statistics |
10 | * (c) March, 1998 Zhanyong Wan <zhanyong.wan@yale.edu> | 10 | * (c) March, 1998 Zhanyong Wan <zhanyong.wan@yale.edu> |
11 | * | 11 | * |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/time.h> | 14 | #include <linux/time.h> |
15 | #include <linux/mm.h> | 15 | #include <linux/mm.h> |
16 | #include <linux/sysctl.h> | 16 | #include <linux/sysctl.h> |
17 | #include <linux/proc_fs.h> | 17 | #include <linux/proc_fs.h> |
18 | #include <linux/seq_file.h> | ||
18 | #include <linux/slab.h> | 19 | #include <linux/slab.h> |
19 | #include <linux/stat.h> | 20 | #include <linux/stat.h> |
20 | #include <linux/ctype.h> | 21 | #include <linux/ctype.h> |
21 | #include <linux/bitops.h> | 22 | #include <linux/bitops.h> |
22 | #include <asm/uaccess.h> | 23 | #include <asm/uaccess.h> |
23 | #include <linux/utsname.h> | 24 | #include <linux/utsname.h> |
24 | #include <linux/module.h> | 25 | #include <linux/module.h> |
25 | 26 | ||
26 | #include <linux/coda.h> | 27 | #include <linux/coda.h> |
27 | #include <linux/coda_linux.h> | 28 | #include <linux/coda_linux.h> |
28 | #include <linux/coda_fs_i.h> | 29 | #include <linux/coda_fs_i.h> |
29 | #include <linux/coda_psdev.h> | 30 | #include <linux/coda_psdev.h> |
30 | #include <linux/coda_cache.h> | 31 | #include <linux/coda_cache.h> |
31 | #include <linux/coda_proc.h> | 32 | #include <linux/coda_proc.h> |
32 | 33 | ||
33 | static struct ctl_table_header *fs_table_header; | 34 | static struct ctl_table_header *fs_table_header; |
34 | 35 | ||
35 | #define FS_CODA 1 /* Coda file system */ | 36 | #define FS_CODA 1 /* Coda file system */ |
36 | 37 | ||
37 | #define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */ | 38 | #define CODA_TIMEOUT 3 /* timeout on upcalls to become intrble */ |
38 | #define CODA_HARD 5 /* mount type "hard" or "soft" */ | 39 | #define CODA_HARD 5 /* mount type "hard" or "soft" */ |
39 | #define CODA_VFS 6 /* vfs statistics */ | 40 | #define CODA_VFS 6 /* vfs statistics */ |
40 | #define CODA_CACHE_INV 9 /* cache invalidation statistics */ | 41 | #define CODA_CACHE_INV 9 /* cache invalidation statistics */ |
41 | #define CODA_FAKE_STATFS 10 /* don't query venus for actual cache usage */ | 42 | #define CODA_FAKE_STATFS 10 /* don't query venus for actual cache usage */ |
42 | 43 | ||
43 | struct coda_vfs_stats coda_vfs_stat; | 44 | struct coda_vfs_stats coda_vfs_stat; |
44 | static struct coda_cache_inv_stats coda_cache_inv_stat; | 45 | static struct coda_cache_inv_stats coda_cache_inv_stat; |
45 | 46 | ||
46 | static void reset_coda_vfs_stats( void ) | 47 | static void reset_coda_vfs_stats( void ) |
47 | { | 48 | { |
48 | memset( &coda_vfs_stat, 0, sizeof( coda_vfs_stat ) ); | 49 | memset( &coda_vfs_stat, 0, sizeof( coda_vfs_stat ) ); |
49 | } | 50 | } |
50 | 51 | ||
51 | static void reset_coda_cache_inv_stats( void ) | 52 | static void reset_coda_cache_inv_stats( void ) |
52 | { | 53 | { |
53 | memset( &coda_cache_inv_stat, 0, sizeof( coda_cache_inv_stat ) ); | 54 | memset( &coda_cache_inv_stat, 0, sizeof( coda_cache_inv_stat ) ); |
54 | } | 55 | } |
55 | 56 | ||
56 | static int do_reset_coda_vfs_stats( ctl_table * table, int write, | 57 | static int do_reset_coda_vfs_stats( ctl_table * table, int write, |
57 | struct file * filp, void __user * buffer, | 58 | struct file * filp, void __user * buffer, |
58 | size_t * lenp, loff_t * ppos ) | 59 | size_t * lenp, loff_t * ppos ) |
59 | { | 60 | { |
60 | if ( write ) { | 61 | if ( write ) { |
61 | reset_coda_vfs_stats(); | 62 | reset_coda_vfs_stats(); |
62 | 63 | ||
63 | *ppos += *lenp; | 64 | *ppos += *lenp; |
64 | } else { | 65 | } else { |
65 | *lenp = 0; | 66 | *lenp = 0; |
66 | } | 67 | } |
67 | 68 | ||
68 | return 0; | 69 | return 0; |
69 | } | 70 | } |
70 | 71 | ||
71 | static int do_reset_coda_cache_inv_stats( ctl_table * table, int write, | 72 | static int do_reset_coda_cache_inv_stats( ctl_table * table, int write, |
72 | struct file * filp, | 73 | struct file * filp, |
73 | void __user * buffer, | 74 | void __user * buffer, |
74 | size_t * lenp, loff_t * ppos ) | 75 | size_t * lenp, loff_t * ppos ) |
75 | { | 76 | { |
76 | if ( write ) { | 77 | if ( write ) { |
77 | reset_coda_cache_inv_stats(); | 78 | reset_coda_cache_inv_stats(); |
78 | 79 | ||
79 | *ppos += *lenp; | 80 | *ppos += *lenp; |
80 | } else { | 81 | } else { |
81 | *lenp = 0; | 82 | *lenp = 0; |
82 | } | 83 | } |
83 | 84 | ||
84 | return 0; | 85 | return 0; |
85 | } | 86 | } |
86 | 87 | ||
87 | static int coda_vfs_stats_get_info( char * buffer, char ** start, | 88 | static int proc_vfs_stats_show(struct seq_file *m, void *v) |
88 | off_t offset, int length) | ||
89 | { | 89 | { |
90 | int len=0; | ||
91 | off_t begin; | ||
92 | struct coda_vfs_stats * ps = & coda_vfs_stat; | 90 | struct coda_vfs_stats * ps = & coda_vfs_stat; |
93 | 91 | ||
94 | /* this works as long as we are below 1024 characters! */ | 92 | seq_printf(m, |
95 | len += sprintf( buffer, | ||
96 | "Coda VFS statistics\n" | 93 | "Coda VFS statistics\n" |
97 | "===================\n\n" | 94 | "===================\n\n" |
98 | "File Operations:\n" | 95 | "File Operations:\n" |
99 | "\topen\t\t%9d\n" | 96 | "\topen\t\t%9d\n" |
100 | "\tflush\t\t%9d\n" | 97 | "\tflush\t\t%9d\n" |
101 | "\trelease\t\t%9d\n" | 98 | "\trelease\t\t%9d\n" |
102 | "\tfsync\t\t%9d\n\n" | 99 | "\tfsync\t\t%9d\n\n" |
103 | "Dir Operations:\n" | 100 | "Dir Operations:\n" |
104 | "\treaddir\t\t%9d\n\n" | 101 | "\treaddir\t\t%9d\n\n" |
105 | "Inode Operations\n" | 102 | "Inode Operations\n" |
106 | "\tcreate\t\t%9d\n" | 103 | "\tcreate\t\t%9d\n" |
107 | "\tlookup\t\t%9d\n" | 104 | "\tlookup\t\t%9d\n" |
108 | "\tlink\t\t%9d\n" | 105 | "\tlink\t\t%9d\n" |
109 | "\tunlink\t\t%9d\n" | 106 | "\tunlink\t\t%9d\n" |
110 | "\tsymlink\t\t%9d\n" | 107 | "\tsymlink\t\t%9d\n" |
111 | "\tmkdir\t\t%9d\n" | 108 | "\tmkdir\t\t%9d\n" |
112 | "\trmdir\t\t%9d\n" | 109 | "\trmdir\t\t%9d\n" |
113 | "\trename\t\t%9d\n" | 110 | "\trename\t\t%9d\n" |
114 | "\tpermission\t%9d\n", | 111 | "\tpermission\t%9d\n", |
115 | 112 | ||
116 | /* file operations */ | 113 | /* file operations */ |
117 | ps->open, | 114 | ps->open, |
118 | ps->flush, | 115 | ps->flush, |
119 | ps->release, | 116 | ps->release, |
120 | ps->fsync, | 117 | ps->fsync, |
121 | 118 | ||
122 | /* dir operations */ | 119 | /* dir operations */ |
123 | ps->readdir, | 120 | ps->readdir, |
124 | 121 | ||
125 | /* inode operations */ | 122 | /* inode operations */ |
126 | ps->create, | 123 | ps->create, |
127 | ps->lookup, | 124 | ps->lookup, |
128 | ps->link, | 125 | ps->link, |
129 | ps->unlink, | 126 | ps->unlink, |
130 | ps->symlink, | 127 | ps->symlink, |
131 | ps->mkdir, | 128 | ps->mkdir, |
132 | ps->rmdir, | 129 | ps->rmdir, |
133 | ps->rename, | 130 | ps->rename, |
134 | ps->permission); | 131 | ps->permission); |
135 | 132 | return 0; | |
136 | begin = offset; | ||
137 | *start = buffer + begin; | ||
138 | len -= begin; | ||
139 | |||
140 | if ( len > length ) | ||
141 | len = length; | ||
142 | if ( len < 0 ) | ||
143 | len = 0; | ||
144 | |||
145 | return len; | ||
146 | } | 133 | } |
147 | 134 | ||
148 | static int coda_cache_inv_stats_get_info( char * buffer, char ** start, | 135 | static int proc_cache_inv_stats_show(struct seq_file *m, void *v) |
149 | off_t offset, int length) | ||
150 | { | 136 | { |
151 | int len=0; | ||
152 | off_t begin; | ||
153 | struct coda_cache_inv_stats * ps = & coda_cache_inv_stat; | 137 | struct coda_cache_inv_stats * ps = & coda_cache_inv_stat; |
154 | 138 | ||
155 | /* this works as long as we are below 1024 characters! */ | 139 | seq_printf(m, |
156 | len += sprintf( buffer, | ||
157 | "Coda cache invalidation statistics\n" | 140 | "Coda cache invalidation statistics\n" |
158 | "==================================\n\n" | 141 | "==================================\n\n" |
159 | "flush\t\t%9d\n" | 142 | "flush\t\t%9d\n" |
160 | "purge user\t%9d\n" | 143 | "purge user\t%9d\n" |
161 | "zap_dir\t\t%9d\n" | 144 | "zap_dir\t\t%9d\n" |
162 | "zap_file\t%9d\n" | 145 | "zap_file\t%9d\n" |
163 | "zap_vnode\t%9d\n" | 146 | "zap_vnode\t%9d\n" |
164 | "purge_fid\t%9d\n" | 147 | "purge_fid\t%9d\n" |
165 | "replace\t\t%9d\n", | 148 | "replace\t\t%9d\n", |
166 | ps->flush, | 149 | ps->flush, |
167 | ps->purge_user, | 150 | ps->purge_user, |
168 | ps->zap_dir, | 151 | ps->zap_dir, |
169 | ps->zap_file, | 152 | ps->zap_file, |
170 | ps->zap_vnode, | 153 | ps->zap_vnode, |
171 | ps->purge_fid, | 154 | ps->purge_fid, |
172 | ps->replace ); | 155 | ps->replace ); |
173 | 156 | return 0; | |
174 | begin = offset; | 157 | } |
175 | *start = buffer + begin; | ||
176 | len -= begin; | ||
177 | 158 | ||
178 | if ( len > length ) | 159 | static int proc_vfs_stats_open(struct inode *inode, struct file *file) |
179 | len = length; | 160 | { |
180 | if ( len < 0 ) | 161 | return single_open(file, proc_vfs_stats_show, NULL); |
181 | len = 0; | 162 | } |
182 | 163 | ||
183 | return len; | 164 | static int proc_cache_inv_stats_open(struct inode *inode, struct file *file) |
165 | { | ||
166 | return single_open(file, proc_cache_inv_stats_show, NULL); | ||
184 | } | 167 | } |
185 | 168 | ||
169 | static 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 | |||
177 | static 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 | |||
186 | static ctl_table coda_table[] = { | 185 | static ctl_table coda_table[] = { |
187 | {CODA_TIMEOUT, "timeout", &coda_timeout, sizeof(int), 0644, NULL, &proc_dointvec}, | 186 | {CODA_TIMEOUT, "timeout", &coda_timeout, sizeof(int), 0644, NULL, &proc_dointvec}, |
188 | {CODA_HARD, "hard", &coda_hard, sizeof(int), 0644, NULL, &proc_dointvec}, | 187 | {CODA_HARD, "hard", &coda_hard, sizeof(int), 0644, NULL, &proc_dointvec}, |
189 | {CODA_VFS, "vfs_stats", NULL, 0, 0644, NULL, &do_reset_coda_vfs_stats}, | 188 | {CODA_VFS, "vfs_stats", NULL, 0, 0644, NULL, &do_reset_coda_vfs_stats}, |
190 | {CODA_CACHE_INV, "cache_inv_stats", NULL, 0, 0644, NULL, &do_reset_coda_cache_inv_stats}, | 189 | {CODA_CACHE_INV, "cache_inv_stats", NULL, 0, 0644, NULL, &do_reset_coda_cache_inv_stats}, |
191 | {CODA_FAKE_STATFS, "fake_statfs", &coda_fake_statfs, sizeof(int), 0600, NULL, &proc_dointvec}, | 190 | {CODA_FAKE_STATFS, "fake_statfs", &coda_fake_statfs, sizeof(int), 0600, NULL, &proc_dointvec}, |
192 | { 0 } | 191 | { 0 } |
193 | }; | 192 | }; |
194 | 193 | ||
195 | static ctl_table fs_table[] = { | 194 | static ctl_table fs_table[] = { |
196 | {FS_CODA, "coda", NULL, 0, 0555, coda_table}, | 195 | {FS_CODA, "coda", NULL, 0, 0555, coda_table}, |
197 | {0} | 196 | {0} |
198 | }; | 197 | }; |
199 | 198 | ||
200 | 199 | ||
201 | #ifdef CONFIG_PROC_FS | 200 | #ifdef CONFIG_PROC_FS |
202 | 201 | ||
203 | /* | 202 | /* |
204 | target directory structure: | 203 | target directory structure: |
205 | /proc/fs (see linux/fs/proc/root.c) | 204 | /proc/fs (see linux/fs/proc/root.c) |
206 | /proc/fs/coda | 205 | /proc/fs/coda |
207 | /proc/fs/coda/{vfs_stats, | 206 | /proc/fs/coda/{vfs_stats, |
208 | 207 | ||
209 | */ | 208 | */ |
210 | 209 | ||
211 | static struct proc_dir_entry* proc_fs_coda; | 210 | static struct proc_dir_entry* proc_fs_coda; |
212 | 211 | ||
213 | #endif | 212 | #endif |
214 | 213 | ||
215 | #define coda_proc_create(name,get_info) \ | ||
216 | create_proc_info_entry(name, 0, proc_fs_coda, get_info) | ||
217 | |||
218 | void coda_sysctl_init(void) | 214 | void coda_sysctl_init(void) |
219 | { | 215 | { |
220 | reset_coda_vfs_stats(); | 216 | reset_coda_vfs_stats(); |
221 | reset_coda_cache_inv_stats(); | 217 | reset_coda_cache_inv_stats(); |
222 | 218 | ||
223 | #ifdef CONFIG_PROC_FS | 219 | #ifdef CONFIG_PROC_FS |
224 | proc_fs_coda = proc_mkdir("coda", proc_root_fs); | 220 | proc_fs_coda = proc_mkdir("coda", proc_root_fs); |
225 | if (proc_fs_coda) { | 221 | if (proc_fs_coda) { |
222 | struct proc_dir_entry *pde; | ||
223 | |||
226 | proc_fs_coda->owner = THIS_MODULE; | 224 | proc_fs_coda->owner = THIS_MODULE; |
227 | coda_proc_create("vfs_stats", coda_vfs_stats_get_info); | 225 | pde = create_proc_entry("vfs_stats", 0, proc_fs_coda); |
228 | coda_proc_create("cache_inv_stats", coda_cache_inv_stats_get_info); | 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; | ||
229 | } | 231 | } |
230 | #endif | 232 | #endif |
231 | 233 |