1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #include <linux/module.h>
38 #include <linux/autoconf.h>
39 #include <linux/sysctl.h>
40 #include <linux/sched.h>
42 #include <linux/sysctl.h>
43 #include <linux/version.h>
44 #include <linux/proc_fs.h>
45 #include <linux/slab.h>
46 #include <linux/stat.h>
47 #include <linux/ctype.h>
48 #include <asm/bitops.h>
49 #include <asm/uaccess.h>
50 #include <linux/utsname.h>
52 #define DEBUG_SUBSYSTEM S_CLASS
54 #include <obd_support.h>
55 #include <lprocfs_status.h>
57 cfs_sysctl_table_header_t *obd_table_header = NULL;
59 #define OBD_SYSCTL 300
62 OBD_FAIL_LOC = 1, /* control test failures instrumentation */
63 OBD_FAIL_VAL, /* userdata for fail loc */
64 OBD_TIMEOUT, /* RPC timeout before recovery/intr */
65 OBD_DUMP_ON_TIMEOUT, /* dump kernel debug log upon eviction */
66 OBD_MEMUSED, /* bytes currently OBD_ALLOCated */
67 OBD_PAGESUSED, /* pages currently OBD_PAGE_ALLOCated */
68 OBD_MAXMEMUSED, /* maximum bytes OBD_ALLOCated concurrently */
69 OBD_MAXPAGESUSED, /* maximum pages OBD_PAGE_ALLOCated concurrently */
70 OBD_SYNCFILTER, /* XXX temporary, as we play with sync osts.. */
71 OBD_LDLM_TIMEOUT, /* LDLM timeout for ASTs before client eviction */
72 OBD_DUMP_ON_EVICTION, /* dump kernel debug log upon eviction */
73 OBD_DEBUG_PEER_ON_TIMEOUT, /* dump peer debug when RPC times out */
74 OBD_ALLOC_FAIL_RATE, /* memory allocation random failure rate */
75 OBD_MAX_DIRTY_PAGES, /* maximum dirty pages */
78 int LL_PROC_PROTO(proc_fail_loc)
81 long old_fail_loc = obd_fail_loc;
83 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
84 if (old_fail_loc != obd_fail_loc)
85 wake_up(&obd_race_waitq);
89 int LL_PROC_PROTO(proc_set_timeout)
93 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
94 if (ldlm_timeout >= obd_timeout)
95 ldlm_timeout = max(obd_timeout / 3, 1U);
99 int LL_PROC_PROTO(proc_memory_alloc)
103 DECLARE_LL_PROC_PPOS_DECL;
105 if (!*lenp || (*ppos && !write)) {
112 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
116 if (copy_to_user(buffer, buf, len))
123 int LL_PROC_PROTO(proc_pages_alloc)
127 DECLARE_LL_PROC_PPOS_DECL;
129 if (!*lenp || (*ppos && !write)) {
136 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
140 if (copy_to_user(buffer, buf, len))
147 int LL_PROC_PROTO(proc_mem_max)
151 DECLARE_LL_PROC_PPOS_DECL;
153 if (!*lenp || (*ppos && !write)) {
160 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
164 if (copy_to_user(buffer, buf, len))
171 int LL_PROC_PROTO(proc_pages_max)
175 DECLARE_LL_PROC_PPOS_DECL;
177 if (!*lenp || (*ppos && !write)) {
184 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
188 if (copy_to_user(buffer, buf, len))
195 int LL_PROC_PROTO(proc_max_dirty_pages_in_mb)
198 DECLARE_LL_PROC_PPOS_DECL;
200 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
205 rc = lprocfs_write_frac_helper(buffer, *lenp,
206 (unsigned int*)table->data,
207 1 << (20 - CFS_PAGE_SHIFT));
208 /* Don't allow them to let dirty pages exceed 90% of system memory,
209 * and set a hard minimum of 4MB. */
210 if (obd_max_dirty_pages > ((num_physpages / 10) * 9)) {
211 CERROR("Refusing to set max dirty pages to %u, which "
212 "is more than 90%% of available RAM; setting to %lu\n",
213 obd_max_dirty_pages, ((num_physpages / 10) * 9));
214 obd_max_dirty_pages = ((num_physpages / 10) * 9);
215 } else if (obd_max_dirty_pages < 4 << (20 - CFS_PAGE_SHIFT)) {
216 obd_max_dirty_pages = 4 << (20 - CFS_PAGE_SHIFT);
222 len = lprocfs_read_frac_helper(buf, sizeof(buf),
223 *(unsigned int*)table->data,
224 1 << (20 - CFS_PAGE_SHIFT));
228 if (copy_to_user(buffer, buf, len))
236 #ifdef RANDOM_FAIL_ALLOC
237 int LL_PROC_PROTO(proc_alloc_fail_rate)
240 DECLARE_LL_PROC_PPOS_DECL;
242 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
247 rc = lprocfs_write_frac_helper(buffer, *lenp,
248 (unsigned int*)table->data,
249 OBD_ALLOC_FAIL_MULT);
254 len = lprocfs_read_frac_helper(buf, 21,
255 *(unsigned int*)table->data,
256 OBD_ALLOC_FAIL_MULT);
260 if (copy_to_user(buffer, buf, len))
269 static cfs_sysctl_table_t obd_table[] = {
271 .ctl_name = OBD_FAIL_LOC,
272 .procname = "fail_loc",
273 .data = &obd_fail_loc,
274 .maxlen = sizeof(int),
276 .proc_handler = &proc_fail_loc
279 .ctl_name = OBD_FAIL_VAL,
280 .procname = "fail_val",
281 .data = &obd_fail_val,
282 .maxlen = sizeof(int),
284 .proc_handler = &proc_dointvec
287 .ctl_name = OBD_TIMEOUT,
288 .procname = "timeout",
289 .data = &obd_timeout,
290 .maxlen = sizeof(int),
292 .proc_handler = &proc_set_timeout
295 .ctl_name = OBD_DEBUG_PEER_ON_TIMEOUT,
296 .procname = "debug_peer_on_timeout",
297 .data = &obd_debug_peer_on_timeout,
298 .maxlen = sizeof(int),
300 .proc_handler = &proc_dointvec
303 .ctl_name = OBD_DUMP_ON_TIMEOUT,
304 .procname = "dump_on_timeout",
305 .data = &obd_dump_on_timeout,
306 .maxlen = sizeof(int),
308 .proc_handler = &proc_dointvec
311 .ctl_name = OBD_DUMP_ON_EVICTION,
312 .procname = "dump_on_eviction",
313 .data = &obd_dump_on_eviction,
314 .maxlen = sizeof(int),
316 .proc_handler = &proc_dointvec
319 .ctl_name = OBD_MEMUSED,
320 .procname = "memused",
324 .proc_handler = &proc_memory_alloc
327 .ctl_name = OBD_PAGESUSED,
328 .procname = "pagesused",
332 .proc_handler = &proc_pages_alloc
335 .ctl_name = OBD_MAXMEMUSED,
336 .procname = "memused_max",
340 .proc_handler = &proc_mem_max
343 .ctl_name = OBD_MAXPAGESUSED,
344 .procname = "pagesused_max",
348 .proc_handler = &proc_pages_max
351 .ctl_name = OBD_LDLM_TIMEOUT,
352 .procname = "ldlm_timeout",
353 .data = &ldlm_timeout,
354 .maxlen = sizeof(int),
356 .proc_handler = &proc_set_timeout
358 #ifdef RANDOM_FAIL_ALLOC
360 .ctl_name = OBD_ALLOC_FAIL_RATE,
361 .procname = "alloc_fail_rate",
362 .data = &obd_alloc_fail_rate,
363 .maxlen = sizeof(int),
365 .proc_handler = &proc_alloc_fail_rate
369 .ctl_name = OBD_MAX_DIRTY_PAGES,
370 .procname = "max_dirty_mb",
371 .data = &obd_max_dirty_pages,
372 .maxlen = sizeof(int),
374 .proc_handler = &proc_max_dirty_pages_in_mb
379 static cfs_sysctl_table_t parent_table[] = {
381 .ctl_name = OBD_SYSCTL,
382 .procname = "lustre",
391 void obd_sysctl_init (void)
394 if ( !obd_table_header )
395 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
399 void obd_sysctl_clean (void)
402 if ( obd_table_header )
403 cfs_unregister_sysctl_table(obd_table_header);
404 obd_table_header = NULL;