staging: lustre: mdc: remove ccflags from Makefile
[deliverable/linux.git] / drivers / staging / lustre / lustre / obdclass / linux / linux-sysctl.c
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, Intel Corporation.
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36
37#include <linux/module.h>
38#include <linux/sysctl.h>
39#include <linux/sched.h>
40#include <linux/mm.h>
d7e09d03
PT
41#include <linux/proc_fs.h>
42#include <linux/slab.h>
43#include <linux/stat.h>
44#include <linux/ctype.h>
87822e41
AS
45#include <linux/bitops.h>
46#include <linux/uaccess.h>
d7e09d03
PT
47#include <linux/utsname.h>
48
49#define DEBUG_SUBSYSTEM S_CLASS
50
51#include <obd_support.h>
52#include <lprocfs_status.h>
53
54#ifdef CONFIG_SYSCTL
55ctl_table_header_t *obd_table_header = NULL;
56#endif
57
58
59#define OBD_SYSCTL 300
60
61enum {
62 OBD_TIMEOUT = 3, /* RPC timeout before recovery/intr */
63 OBD_DUMP_ON_TIMEOUT, /* dump kernel debug log upon eviction */
64 OBD_MEMUSED, /* bytes currently OBD_ALLOCated */
65 OBD_PAGESUSED, /* pages currently OBD_PAGE_ALLOCated */
66 OBD_MAXMEMUSED, /* maximum bytes OBD_ALLOCated concurrently */
67 OBD_MAXPAGESUSED, /* maximum pages OBD_PAGE_ALLOCated concurrently */
68 OBD_SYNCFILTER, /* XXX temporary, as we play with sync osts.. */
69 OBD_LDLM_TIMEOUT, /* LDLM timeout for ASTs before client eviction */
70 OBD_DUMP_ON_EVICTION, /* dump kernel debug log upon eviction */
71 OBD_DEBUG_PEER_ON_TIMEOUT, /* dump peer debug when RPC times out */
72 OBD_ALLOC_FAIL_RATE, /* memory allocation random failure rate */
73 OBD_MAX_DIRTY_PAGES, /* maximum dirty pages */
74 OBD_AT_MIN, /* Adaptive timeouts params */
75 OBD_AT_MAX,
76 OBD_AT_EXTRA,
77 OBD_AT_EARLY_MARGIN,
78 OBD_AT_HISTORY,
79};
80
81
82int LL_PROC_PROTO(proc_set_timeout)
83{
84 int rc;
85
86 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
87 if (ldlm_timeout >= obd_timeout)
88 ldlm_timeout = max(obd_timeout / 3, 1U);
89 return rc;
90}
91
92int LL_PROC_PROTO(proc_memory_alloc)
93{
94 char buf[22];
95 int len;
96 DECLARE_LL_PROC_PPOS_DECL;
97
98 if (!*lenp || (*ppos && !write)) {
99 *lenp = 0;
100 return 0;
101 }
102 if (write)
103 return -EINVAL;
104
105 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
106 if (len > *lenp)
107 len = *lenp;
108 buf[len] = '\0';
109 if (copy_to_user(buffer, buf, len))
110 return -EFAULT;
111 *lenp = len;
112 *ppos += *lenp;
113 return 0;
114}
115
116int LL_PROC_PROTO(proc_pages_alloc)
117{
118 char buf[22];
119 int len;
120 DECLARE_LL_PROC_PPOS_DECL;
121
122 if (!*lenp || (*ppos && !write)) {
123 *lenp = 0;
124 return 0;
125 }
126 if (write)
127 return -EINVAL;
128
129 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
130 if (len > *lenp)
131 len = *lenp;
132 buf[len] = '\0';
133 if (copy_to_user(buffer, buf, len))
134 return -EFAULT;
135 *lenp = len;
136 *ppos += *lenp;
137 return 0;
138}
139
140int LL_PROC_PROTO(proc_mem_max)
141{
142 char buf[22];
143 int len;
144 DECLARE_LL_PROC_PPOS_DECL;
145
146 if (!*lenp || (*ppos && !write)) {
147 *lenp = 0;
148 return 0;
149 }
150 if (write)
151 return -EINVAL;
152
153 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
154 if (len > *lenp)
155 len = *lenp;
156 buf[len] = '\0';
157 if (copy_to_user(buffer, buf, len))
158 return -EFAULT;
159 *lenp = len;
160 *ppos += *lenp;
161 return 0;
162}
163
164int LL_PROC_PROTO(proc_pages_max)
165{
166 char buf[22];
167 int len;
168 DECLARE_LL_PROC_PPOS_DECL;
169
170 if (!*lenp || (*ppos && !write)) {
171 *lenp = 0;
172 return 0;
173 }
174 if (write)
175 return -EINVAL;
176
177 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
178 if (len > *lenp)
179 len = *lenp;
180 buf[len] = '\0';
181 if (copy_to_user(buffer, buf, len))
182 return -EFAULT;
183 *lenp = len;
184 *ppos += *lenp;
185 return 0;
186}
187
188int LL_PROC_PROTO(proc_max_dirty_pages_in_mb)
189{
190 int rc = 0;
191 DECLARE_LL_PROC_PPOS_DECL;
192
193 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
194 *lenp = 0;
195 return 0;
196 }
197 if (write) {
198 rc = lprocfs_write_frac_helper(buffer, *lenp,
260cdf5d 199 (unsigned int *)table->data,
d7e09d03
PT
200 1 << (20 - PAGE_CACHE_SHIFT));
201 /* Don't allow them to let dirty pages exceed 90% of system
202 * memory and set a hard minimum of 4MB. */
4f6cc9ab 203 if (obd_max_dirty_pages > ((totalram_pages / 10) * 9)) {
d7e09d03
PT
204 CERROR("Refusing to set max dirty pages to %u, which "
205 "is more than 90%% of available RAM; setting "
206 "to %lu\n", obd_max_dirty_pages,
4f6cc9ab
PT
207 ((totalram_pages / 10) * 9));
208 obd_max_dirty_pages = ((totalram_pages / 10) * 9);
d7e09d03
PT
209 } else if (obd_max_dirty_pages < 4 << (20 - PAGE_CACHE_SHIFT)) {
210 obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
211 }
212 } else {
213 char buf[21];
214 int len;
215
216 len = lprocfs_read_frac_helper(buf, sizeof(buf),
260cdf5d 217 *(unsigned int *)table->data,
d7e09d03
PT
218 1 << (20 - PAGE_CACHE_SHIFT));
219 if (len > *lenp)
220 len = *lenp;
221 buf[len] = '\0';
222 if (copy_to_user(buffer, buf, len))
223 return -EFAULT;
224 *lenp = len;
225 }
226 *ppos += *lenp;
227 return rc;
228}
229
230int LL_PROC_PROTO(proc_alloc_fail_rate)
231{
232 int rc = 0;
233 DECLARE_LL_PROC_PPOS_DECL;
234
235 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
236 *lenp = 0;
237 return 0;
238 }
239 if (write) {
240 rc = lprocfs_write_frac_helper(buffer, *lenp,
260cdf5d 241 (unsigned int *)table->data,
d7e09d03
PT
242 OBD_ALLOC_FAIL_MULT);
243 } else {
244 char buf[21];
245 int len;
246
247 len = lprocfs_read_frac_helper(buf, 21,
260cdf5d 248 *(unsigned int *)table->data,
d7e09d03
PT
249 OBD_ALLOC_FAIL_MULT);
250 if (len > *lenp)
251 len = *lenp;
252 buf[len] = '\0';
253 if (copy_to_user(buffer, buf, len))
254 return -EFAULT;
255 *lenp = len;
256 }
257 *ppos += *lenp;
258 return rc;
259}
260
261int LL_PROC_PROTO(proc_at_min)
262{
263 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
264}
265int LL_PROC_PROTO(proc_at_max)
266{
267 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
268}
269int LL_PROC_PROTO(proc_at_extra)
270{
271 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
272}
273int LL_PROC_PROTO(proc_at_early_margin)
274{
275 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
276}
277int LL_PROC_PROTO(proc_at_history)
278{
279 return ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
280}
281
282#ifdef CONFIG_SYSCTL
283static ctl_table_t obd_table[] = {
284 {
d7e09d03
PT
285 .procname = "timeout",
286 .data = &obd_timeout,
287 .maxlen = sizeof(int),
288 .mode = 0644,
289 .proc_handler = &proc_set_timeout
290 },
291 {
d7e09d03
PT
292 .procname = "debug_peer_on_timeout",
293 .data = &obd_debug_peer_on_timeout,
294 .maxlen = sizeof(int),
295 .mode = 0644,
296 .proc_handler = &proc_dointvec
297 },
298 {
d7e09d03
PT
299 .procname = "dump_on_timeout",
300 .data = &obd_dump_on_timeout,
301 .maxlen = sizeof(int),
302 .mode = 0644,
303 .proc_handler = &proc_dointvec
304 },
305 {
d7e09d03
PT
306 .procname = "dump_on_eviction",
307 .data = &obd_dump_on_eviction,
308 .maxlen = sizeof(int),
309 .mode = 0644,
310 .proc_handler = &proc_dointvec
311 },
312 {
d7e09d03
PT
313 .procname = "memused",
314 .data = NULL,
315 .maxlen = 0,
316 .mode = 0444,
317 .proc_handler = &proc_memory_alloc
318 },
319 {
d7e09d03
PT
320 .procname = "pagesused",
321 .data = NULL,
322 .maxlen = 0,
323 .mode = 0444,
324 .proc_handler = &proc_pages_alloc
325 },
326 {
d7e09d03
PT
327 .procname = "memused_max",
328 .data = NULL,
329 .maxlen = 0,
330 .mode = 0444,
331 .proc_handler = &proc_mem_max
332 },
333 {
d7e09d03
PT
334 .procname = "pagesused_max",
335 .data = NULL,
336 .maxlen = 0,
337 .mode = 0444,
338 .proc_handler = &proc_pages_max
339 },
340 {
d7e09d03
PT
341 .procname = "ldlm_timeout",
342 .data = &ldlm_timeout,
343 .maxlen = sizeof(int),
344 .mode = 0644,
345 .proc_handler = &proc_set_timeout
346 },
347 {
d7e09d03
PT
348 .procname = "alloc_fail_rate",
349 .data = &obd_alloc_fail_rate,
350 .maxlen = sizeof(int),
351 .mode = 0644,
352 .proc_handler = &proc_alloc_fail_rate
353 },
354 {
d7e09d03
PT
355 .procname = "max_dirty_mb",
356 .data = &obd_max_dirty_pages,
357 .maxlen = sizeof(int),
358 .mode = 0644,
359 .proc_handler = &proc_max_dirty_pages_in_mb
360 },
361 {
d7e09d03
PT
362 .procname = "at_min",
363 .data = &at_min,
364 .maxlen = sizeof(int),
365 .mode = 0644,
366 .proc_handler = &proc_at_min
367 },
368 {
d7e09d03
PT
369 .procname = "at_max",
370 .data = &at_max,
371 .maxlen = sizeof(int),
372 .mode = 0644,
373 .proc_handler = &proc_at_max
374 },
375 {
d7e09d03
PT
376 .procname = "at_extra",
377 .data = &at_extra,
378 .maxlen = sizeof(int),
379 .mode = 0644,
380 .proc_handler = &proc_at_extra
381 },
382 {
d7e09d03
PT
383 .procname = "at_early_margin",
384 .data = &at_early_margin,
385 .maxlen = sizeof(int),
386 .mode = 0644,
387 .proc_handler = &proc_at_early_margin
388 },
389 {
d7e09d03
PT
390 .procname = "at_history",
391 .data = &at_history,
392 .maxlen = sizeof(int),
393 .mode = 0644,
394 .proc_handler = &proc_at_history
e780e3de
PT
395 },
396 {}
d7e09d03
PT
397};
398
399static ctl_table_t parent_table[] = {
400 {
d7e09d03
PT
401 .procname = "lustre",
402 .data = NULL,
403 .maxlen = 0,
404 .mode = 0555,
405 .child = obd_table
e780e3de
PT
406 },
407 {}
d7e09d03
PT
408};
409#endif
410
e4f3771f 411void obd_sysctl_init(void)
d7e09d03
PT
412{
413#ifdef CONFIG_SYSCTL
e4f3771f 414 if (!obd_table_header)
a7f24447 415 obd_table_header = register_sysctl_table(parent_table);
d7e09d03
PT
416#endif
417}
418
e4f3771f 419void obd_sysctl_clean(void)
d7e09d03
PT
420{
421#ifdef CONFIG_SYSCTL
e4f3771f 422 if (obd_table_header)
d7e09d03
PT
423 unregister_sysctl_table(obd_table_header);
424 obd_table_header = NULL;
425#endif
426}
This page took 0.172376 seconds and 5 git commands to generate.