1 /*
2  * Copyright (c) 2001-2004 Silicon Graphics, Inc.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * Further, this software is distributed without any warranty that it is
13  * free of the rightful claim of any third person regarding infringement
14  * or the like.  Any license provided herein, whether implied or
15  * otherwise, applies only to this software file.  Patent licenses, if
16  * any, provided herein do not apply to combinations of this program with
17  * other software, or any other product whatsoever.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write the Free Software Foundation, Inc., 59
21  * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32 
33 #include "xfs.h"
34 #include "xfs_refcache.h"
35 #include <linux/sysctl.h>
36 #include <linux/proc_fs.h>
37 
38 
39 static struct ctl_table_header *xfs_table_header;
40 
41 
42 /* Custom proc handlers */
43 
44 STATIC int
xfs_refcache_resize_proc_handler(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)45 xfs_refcache_resize_proc_handler(
46 	ctl_table	*ctl,
47 	int		write,
48 	struct file	*filp,
49 	void		*buffer,
50 	size_t		*lenp)
51 {
52 	int		ret, *valp = ctl->data;
53 	int		xfs_refcache_new_size;
54 	int		xfs_refcache_old_size = *valp;
55 
56 	ret = proc_dointvec_minmax(ctl, write, filp, buffer, lenp);
57 	xfs_refcache_new_size = *valp;
58 
59 	if (!ret && write && xfs_refcache_new_size != xfs_refcache_old_size) {
60 		xfs_refcache_resize(xfs_refcache_new_size);
61 		/* Don't purge more than size of the cache */
62 		if (xfs_refcache_new_size < xfs_refcache_purge_count)
63 			xfs_refcache_purge_count = xfs_refcache_new_size;
64 	}
65 
66 	return ret;
67 }
68 
69 #ifdef CONFIG_PROC_FS
70 STATIC int
xfs_stats_clear_proc_handler(ctl_table * ctl,int write,struct file * filp,void * buffer,size_t * lenp)71 xfs_stats_clear_proc_handler(
72 	ctl_table	*ctl,
73 	int		write,
74 	struct file	*filp,
75 	void		*buffer,
76 	size_t		*lenp)
77 {
78 	int		ret, *valp = ctl->data;
79 	__uint32_t	vn_active;
80 
81 	ret = proc_dointvec_minmax(ctl, write, filp, buffer, lenp);
82 
83 	if (!ret && write && *valp) {
84 		printk("XFS Clearing xfsstats\n");
85 		/* save vn_active, it's a universal truth! */
86 		vn_active = xfsstats.vn_active;
87 		memset(&xfsstats, 0, sizeof(xfsstats));
88 		xfsstats.vn_active = vn_active;
89 		xfs_stats_clear = 0;
90 	}
91 
92 	return ret;
93 }
94 #endif /* CONFIG_PROC_FS */
95 
96 STATIC ctl_table xfs_table[] = {
97 	{XFS_REFCACHE_SIZE, "refcache_size", &xfs_params.refcache_size.val,
98 	sizeof(int), 0644, NULL, &xfs_refcache_resize_proc_handler,
99 	&sysctl_intvec, NULL,
100 	&xfs_params.refcache_size.min, &xfs_params.refcache_size.max},
101 
102 	/* Note, the max here is different, it is the current refcache size */
103 	{XFS_REFCACHE_PURGE, "refcache_purge", &xfs_params.refcache_purge.val,
104 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
105 	&sysctl_intvec, NULL,
106 	&xfs_params.refcache_purge.min, &xfs_params.refcache_size.val},
107 
108 	{XFS_RESTRICT_CHOWN, "restrict_chown", &xfs_params.restrict_chown.val,
109 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
110 	&sysctl_intvec, NULL,
111 	&xfs_params.restrict_chown.min, &xfs_params.restrict_chown.max},
112 
113 	{XFS_SGID_INHERIT, "irix_sgid_inherit", &xfs_params.sgid_inherit.val,
114 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
115 	&sysctl_intvec, NULL,
116 	&xfs_params.sgid_inherit.min, &xfs_params.sgid_inherit.max},
117 
118 	{XFS_SYMLINK_MODE, "irix_symlink_mode", &xfs_params.symlink_mode.val,
119 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
120 	&sysctl_intvec, NULL,
121 	&xfs_params.symlink_mode.min, &xfs_params.symlink_mode.max},
122 
123 	{XFS_PANIC_MASK, "panic_mask", &xfs_params.panic_mask.val,
124 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
125 	&sysctl_intvec, NULL,
126 	&xfs_params.panic_mask.min, &xfs_params.panic_mask.max},
127 
128 	{XFS_ERRLEVEL, "error_level", &xfs_params.error_level.val,
129 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
130 	&sysctl_intvec, NULL,
131 	&xfs_params.error_level.min, &xfs_params.error_level.max},
132 
133 	{XFS_SYNCD_TIMER, "xfssyncd_centisecs", &xfs_params.syncd_timer.val,
134 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
135 	&sysctl_intvec, NULL,
136 	&xfs_params.syncd_timer.min, &xfs_params.syncd_timer.max},
137 
138 	{XFS_INHERIT_SYNC, "inherit_sync", &xfs_params.inherit_sync.val,
139 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
140 	&sysctl_intvec, NULL,
141 	&xfs_params.inherit_sync.min, &xfs_params.inherit_sync.max},
142 
143 	{XFS_INHERIT_NODUMP, "inherit_nodump", &xfs_params.inherit_nodump.val,
144 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
145 	&sysctl_intvec, NULL,
146 	&xfs_params.inherit_nodump.min, &xfs_params.inherit_nodump.max},
147 
148 	{XFS_INHERIT_NOATIME, "inherit_noatime", &xfs_params.inherit_noatim.val,
149 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
150 	&sysctl_intvec, NULL,
151 	&xfs_params.inherit_noatim.min, &xfs_params.inherit_noatim.max},
152 
153 	{XFS_BUF_TIMER, "xfsbufd_centisecs", &xfs_params.xfs_buf_timer.val,
154 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
155 	&sysctl_intvec, NULL,
156 	&xfs_params.xfs_buf_timer.min, &xfs_params.xfs_buf_timer.max},
157 
158 	{XFS_BUF_AGE, "age_buffer_centisecs", &xfs_params.xfs_buf_age.val,
159 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
160 	&sysctl_intvec, NULL,
161 	&xfs_params.xfs_buf_age.min, &xfs_params.xfs_buf_age.max},
162 
163 	{XFS_INHERIT_NOSYM, "inherit_nosymlinks", &xfs_params.inherit_nosym.val,
164 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
165 	&sysctl_intvec, NULL,
166 	&xfs_params.inherit_nosym.min, &xfs_params.inherit_nosym.max},
167 
168 	{XFS_ROTORSTEP, "rotorstep", &xfs_params.rotorstep.val,
169 	sizeof(int), 0644, NULL, &proc_dointvec_minmax,
170 	&sysctl_intvec, NULL,
171 	&xfs_params.rotorstep.min, &xfs_params.rotorstep.max},
172 
173 	/* please keep this the last entry */
174 #ifdef CONFIG_PROC_FS
175 	{XFS_STATS_CLEAR, "stats_clear", &xfs_params.stats_clear.val,
176 	sizeof(int), 0644, NULL, &xfs_stats_clear_proc_handler,
177 	&sysctl_intvec, NULL,
178 	&xfs_params.stats_clear.min, &xfs_params.stats_clear.max},
179 #endif /* CONFIG_PROC_FS */
180 
181 	{0}
182 };
183 
184 STATIC ctl_table xfs_dir_table[] = {
185 	{FS_XFS, "xfs", NULL, 0, 0555, xfs_table},
186 	{0}
187 };
188 
189 STATIC ctl_table xfs_root_table[] = {
190 	{CTL_FS, "fs",  NULL, 0, 0555, xfs_dir_table},
191 	{0}
192 };
193 
194 void
xfs_sysctl_register(void)195 xfs_sysctl_register(void)
196 {
197 	xfs_table_header = register_sysctl_table(xfs_root_table, 1);
198 }
199 
200 void
xfs_sysctl_unregister(void)201 xfs_sysctl_unregister(void)
202 {
203 	if (xfs_table_header)
204 		unregister_sysctl_table(xfs_table_header);
205 }
206