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>
38 #include <asm/segment.h>
39 #include <asm/uaccess.h>
40 #include <linux/utsname.h>
42 #define DEBUG_SUBSYSTEM S_CLASS
44 #include <obd_support.h>
45 #include <lprocfs_status.h>
47 cfs_sysctl_table_header_t *obd_table_header = NULL;
49 #define OBD_SYSCTL 300
52 OBD_FAIL_LOC = 1, /* control test failures instrumentation */
53 OBD_FAIL_VAL, /* userdata for fail loc */
54 OBD_TIMEOUT, /* RPC timeout before recovery/intr */
55 OBD_DUMP_ON_TIMEOUT, /* dump kernel debug log upon eviction */
56 OBD_MEMUSED, /* bytes currently OBD_ALLOCated */
57 OBD_PAGESUSED, /* pages currently OBD_PAGE_ALLOCated */
58 OBD_MAXMEMUSED, /* maximum bytes OBD_ALLOCated concurrently */
59 OBD_MAXPAGESUSED, /* maximum pages OBD_PAGE_ALLOCated concurrently */
60 OBD_SYNCFILTER, /* XXX temporary, as we play with sync osts.. */
61 OBD_LDLM_TIMEOUT, /* LDLM timeout for ASTs before client eviction */
62 OBD_DUMP_ON_EVICTION, /* dump kernel debug log upon eviction */
63 OBD_DEBUG_PEER_ON_TIMEOUT, /* dump peer debug when RPC times out */
64 OBD_ALLOC_FAIL_RATE, /* memory allocation random failure rate */
67 int LL_PROC_PROTO(proc_fail_loc)
70 int old_fail_loc = obd_fail_loc;
72 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
73 if (old_fail_loc != obd_fail_loc)
74 wake_up(&obd_race_waitq);
78 int LL_PROC_PROTO(proc_set_timeout)
82 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
83 if (ldlm_timeout >= obd_timeout)
84 ldlm_timeout = max(obd_timeout / 3, 1U);
88 int LL_PROC_PROTO(proc_memory_alloc)
92 DECLARE_LL_PROC_PPOS_DECL;
94 if (!*lenp || (*ppos && !write)) {
101 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
105 if (copy_to_user(buffer, buf, len))
112 int LL_PROC_PROTO(proc_pages_alloc)
116 DECLARE_LL_PROC_PPOS_DECL;
118 if (!*lenp || (*ppos && !write)) {
125 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
129 if (copy_to_user(buffer, buf, len))
136 int LL_PROC_PROTO(proc_mem_max)
140 DECLARE_LL_PROC_PPOS_DECL;
142 if (!*lenp || (*ppos && !write)) {
149 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
153 if (copy_to_user(buffer, buf, len))
160 int LL_PROC_PROTO(proc_pages_max)
164 DECLARE_LL_PROC_PPOS_DECL;
166 if (!*lenp || (*ppos && !write)) {
173 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
177 if (copy_to_user(buffer, buf, len))
184 #ifdef RANDOM_FAIL_ALLOC
185 int LL_PROC_PROTO(proc_alloc_fail_rate)
187 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,8)
188 loff_t *ppos = &filp->f_pos;
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;