1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
26 #include <linux/module.h>
27 #include <linux/autoconf.h>
28 #include <linux/sysctl.h>
29 #include <linux/sched.h>
31 #include <linux/sysctl.h>
32 #include <linux/version.h>
33 #include <linux/proc_fs.h>
34 #include <linux/slab.h>
35 #include <linux/stat.h>
36 #include <linux/ctype.h>
37 #include <asm/bitops.h>
39 # include <asm/segment.h>
41 #include <asm/uaccess.h>
42 #include <linux/utsname.h>
44 #define DEBUG_SUBSYSTEM S_CLASS
46 #include <obd_support.h>
47 #include <lprocfs_status.h>
49 cfs_sysctl_table_header_t *obd_table_header = NULL;
51 #define OBD_SYSCTL 300
54 OBD_FAIL_LOC = 1, /* control test failures instrumentation */
55 OBD_FAIL_VAL, /* userdata for fail loc */
56 OBD_TIMEOUT, /* RPC timeout before recovery/intr */
57 OBD_DUMP_ON_TIMEOUT, /* dump kernel debug log upon eviction */
58 OBD_MEMUSED, /* bytes currently OBD_ALLOCated */
59 OBD_PAGESUSED, /* pages currently OBD_PAGE_ALLOCated */
60 OBD_MAXMEMUSED, /* maximum bytes OBD_ALLOCated concurrently */
61 OBD_MAXPAGESUSED, /* maximum pages OBD_PAGE_ALLOCated concurrently */
62 OBD_SYNCFILTER, /* XXX temporary, as we play with sync osts.. */
63 OBD_LDLM_TIMEOUT, /* LDLM timeout for ASTs before client eviction */
64 OBD_DUMP_ON_EVICTION, /* dump kernel debug log upon eviction */
65 OBD_DEBUG_PEER_ON_TIMEOUT, /* dump peer debug when RPC times out */
66 OBD_ALLOC_FAIL_RATE, /* memory allocation random failure rate */
69 int LL_PROC_PROTO(proc_fail_loc)
72 long old_fail_loc = obd_fail_loc;
74 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
75 if (old_fail_loc != obd_fail_loc)
76 wake_up(&obd_race_waitq);
80 int LL_PROC_PROTO(proc_set_timeout)
84 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
85 if (ldlm_timeout >= obd_timeout)
86 ldlm_timeout = max(obd_timeout / 3, 1U);
90 int LL_PROC_PROTO(proc_memory_alloc)
94 DECLARE_LL_PROC_PPOS_DECL;
96 if (!*lenp || (*ppos && !write)) {
103 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
107 if (copy_to_user(buffer, buf, len))
114 int LL_PROC_PROTO(proc_pages_alloc)
118 DECLARE_LL_PROC_PPOS_DECL;
120 if (!*lenp || (*ppos && !write)) {
127 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
131 if (copy_to_user(buffer, buf, len))
138 int LL_PROC_PROTO(proc_mem_max)
142 DECLARE_LL_PROC_PPOS_DECL;
144 if (!*lenp || (*ppos && !write)) {
151 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
155 if (copy_to_user(buffer, buf, len))
162 int LL_PROC_PROTO(proc_pages_max)
166 DECLARE_LL_PROC_PPOS_DECL;
168 if (!*lenp || (*ppos && !write)) {
175 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
179 if (copy_to_user(buffer, buf, len))
186 #ifdef RANDOM_FAIL_ALLOC
187 int LL_PROC_PROTO(proc_alloc_fail_rate)
190 DECLARE_LL_PROC_PPOS_DECL;
192 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
197 rc = lprocfs_write_frac_helper(buffer, *lenp,
198 (unsigned int*)table->data,
199 OBD_ALLOC_FAIL_MULT);
204 len = lprocfs_read_frac_helper(buf, 21,
205 *(unsigned int*)table->data,
206 OBD_ALLOC_FAIL_MULT);
210 if (copy_to_user(buffer, buf, len))
219 static cfs_sysctl_table_t obd_table[] = {
221 .ctl_name = OBD_FAIL_LOC,
222 .procname = "fail_loc",
223 .data = &obd_fail_loc,
224 .maxlen = sizeof(int),
226 .proc_handler = &proc_fail_loc
229 .ctl_name = OBD_FAIL_VAL,
230 .procname = "fail_val",
231 .data = &obd_fail_val,
232 .maxlen = sizeof(int),
234 .proc_handler = &proc_dointvec
237 .ctl_name = OBD_TIMEOUT,
238 .procname = "timeout",
239 .data = &obd_timeout,
240 .maxlen = sizeof(int),
242 .proc_handler = &proc_set_timeout
245 .ctl_name = OBD_DEBUG_PEER_ON_TIMEOUT,
246 .procname = "debug_peer_on_timeout",
247 .data = &obd_debug_peer_on_timeout,
248 .maxlen = sizeof(int),
250 .proc_handler = &proc_dointvec
253 .ctl_name = OBD_DUMP_ON_TIMEOUT,
254 .procname = "dump_on_timeout",
255 .data = &obd_dump_on_timeout,
256 .maxlen = sizeof(int),
258 .proc_handler = &proc_dointvec
261 .ctl_name = OBD_DUMP_ON_EVICTION,
262 .procname = "dump_on_eviction",
263 .data = &obd_dump_on_eviction,
264 .maxlen = sizeof(int),
266 .proc_handler = &proc_dointvec
269 .ctl_name = OBD_MEMUSED,
270 .procname = "memused",
274 .proc_handler = &proc_memory_alloc
277 .ctl_name = OBD_PAGESUSED,
278 .procname = "pagesused",
282 .proc_handler = &proc_pages_alloc
285 .ctl_name = OBD_MAXMEMUSED,
286 .procname = "memused_max",
290 .proc_handler = &proc_mem_max
293 .ctl_name = OBD_MAXPAGESUSED,
294 .procname = "pagesused_max",
298 .proc_handler = &proc_pages_max
301 .ctl_name = OBD_LDLM_TIMEOUT,
302 .procname = "ldlm_timeout",
303 .data = &ldlm_timeout,
304 .maxlen = sizeof(int),
306 .proc_handler = &proc_set_timeout
308 #ifdef RANDOM_FAIL_LOC
310 .ctl_name = OBD_ALLOC_FAIL_RATE,
311 .procname = "alloc_fail_rate",
312 .data = &obd_alloc_fail_rate,
313 .maxlen = sizeof(int),
315 .proc_handler = &proc_alloc_fail_rate
321 static cfs_sysctl_table_t parent_table[] = {
323 .ctl_name = OBD_SYSCTL,
324 .procname = "lustre",
333 void obd_sysctl_init (void)
336 if ( !obd_table_header )
337 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
341 void obd_sysctl_clean (void)
344 if ( obd_table_header )
345 cfs_unregister_sysctl_table(obd_table_header);
346 obd_table_header = NULL;