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/uaccess.h>
39 #include <linux/utsname.h>
41 #define DEBUG_SUBSYSTEM S_CLASS
43 #include <obd_support.h>
44 #include <lprocfs_status.h>
46 cfs_sysctl_table_header_t *obd_table_header = NULL;
48 #define OBD_SYSCTL 300
51 OBD_FAIL_LOC = 1, /* control test failures instrumentation */
52 OBD_FAIL_VAL, /* userdata for fail loc */
53 OBD_TIMEOUT, /* RPC timeout before recovery/intr */
54 OBD_DUMP_ON_TIMEOUT, /* dump kernel debug log upon eviction */
55 OBD_MEMUSED, /* bytes currently OBD_ALLOCated */
56 OBD_PAGESUSED, /* pages currently OBD_PAGE_ALLOCated */
57 OBD_MAXMEMUSED, /* maximum bytes OBD_ALLOCated concurrently */
58 OBD_MAXPAGESUSED, /* maximum pages OBD_PAGE_ALLOCated concurrently */
59 OBD_SYNCFILTER, /* XXX temporary, as we play with sync osts.. */
60 OBD_LDLM_TIMEOUT, /* LDLM timeout for ASTs before client eviction */
61 OBD_DUMP_ON_EVICTION, /* dump kernel debug log upon eviction */
62 OBD_DEBUG_PEER_ON_TIMEOUT, /* dump peer debug when RPC times out */
63 OBD_ALLOC_FAIL_RATE, /* memory allocation random failure rate */
66 int LL_PROC_PROTO(proc_fail_loc)
69 long old_fail_loc = obd_fail_loc;
71 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
72 if (old_fail_loc != obd_fail_loc)
73 wake_up(&obd_race_waitq);
77 int LL_PROC_PROTO(proc_set_timeout)
81 rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
82 if (ldlm_timeout >= obd_timeout)
83 ldlm_timeout = max(obd_timeout / 3, 1U);
87 int LL_PROC_PROTO(proc_memory_alloc)
91 DECLARE_LL_PROC_PPOS_DECL;
93 if (!*lenp || (*ppos && !write)) {
100 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
104 if (copy_to_user(buffer, buf, len))
111 int LL_PROC_PROTO(proc_pages_alloc)
115 DECLARE_LL_PROC_PPOS_DECL;
117 if (!*lenp || (*ppos && !write)) {
124 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
128 if (copy_to_user(buffer, buf, len))
135 int LL_PROC_PROTO(proc_mem_max)
139 DECLARE_LL_PROC_PPOS_DECL;
141 if (!*lenp || (*ppos && !write)) {
148 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
152 if (copy_to_user(buffer, buf, len))
159 int LL_PROC_PROTO(proc_pages_max)
163 DECLARE_LL_PROC_PPOS_DECL;
165 if (!*lenp || (*ppos && !write)) {
172 len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
176 if (copy_to_user(buffer, buf, len))
183 #ifdef RANDOM_FAIL_ALLOC
184 int LL_PROC_PROTO(proc_alloc_fail_rate)
187 DECLARE_LL_PROC_PPOS_DECL;
189 if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
194 rc = lprocfs_write_frac_helper(buffer, *lenp,
195 (unsigned int*)table->data,
196 OBD_ALLOC_FAIL_MULT);
201 len = lprocfs_read_frac_helper(buf, 21,
202 *(unsigned int*)table->data,
203 OBD_ALLOC_FAIL_MULT);
207 if (copy_to_user(buffer, buf, len))
216 static cfs_sysctl_table_t obd_table[] = {
218 .ctl_name = OBD_FAIL_LOC,
219 .procname = "fail_loc",
220 .data = &obd_fail_loc,
221 .maxlen = sizeof(int),
223 .proc_handler = &proc_fail_loc
226 .ctl_name = OBD_FAIL_VAL,
227 .procname = "fail_val",
228 .data = &obd_fail_val,
229 .maxlen = sizeof(int),
231 .proc_handler = &proc_dointvec
234 .ctl_name = OBD_TIMEOUT,
235 .procname = "timeout",
236 .data = &obd_timeout,
237 .maxlen = sizeof(int),
239 .proc_handler = &proc_set_timeout
242 .ctl_name = OBD_DEBUG_PEER_ON_TIMEOUT,
243 .procname = "debug_peer_on_timeout",
244 .data = &obd_debug_peer_on_timeout,
245 .maxlen = sizeof(int),
247 .proc_handler = &proc_dointvec
250 .ctl_name = OBD_DUMP_ON_TIMEOUT,
251 .procname = "dump_on_timeout",
252 .data = &obd_dump_on_timeout,
253 .maxlen = sizeof(int),
255 .proc_handler = &proc_dointvec
258 .ctl_name = OBD_DUMP_ON_EVICTION,
259 .procname = "dump_on_eviction",
260 .data = &obd_dump_on_eviction,
261 .maxlen = sizeof(int),
263 .proc_handler = &proc_dointvec
266 .ctl_name = OBD_MEMUSED,
267 .procname = "memused",
271 .proc_handler = &proc_memory_alloc
274 .ctl_name = OBD_PAGESUSED,
275 .procname = "pagesused",
279 .proc_handler = &proc_pages_alloc
282 .ctl_name = OBD_MAXMEMUSED,
283 .procname = "memused_max",
287 .proc_handler = &proc_mem_max
290 .ctl_name = OBD_MAXPAGESUSED,
291 .procname = "pagesused_max",
295 .proc_handler = &proc_pages_max
298 .ctl_name = OBD_LDLM_TIMEOUT,
299 .procname = "ldlm_timeout",
300 .data = &ldlm_timeout,
301 .maxlen = sizeof(int),
303 .proc_handler = &proc_set_timeout
305 #ifdef RANDOM_FAIL_LOC
307 .ctl_name = OBD_ALLOC_FAIL_RATE,
308 .procname = "alloc_fail_rate",
309 .data = &obd_alloc_fail_rate,
310 .maxlen = sizeof(int),
312 .proc_handler = &proc_alloc_fail_rate
318 static cfs_sysctl_table_t parent_table[] = {
320 .ctl_name = OBD_SYSCTL,
321 .procname = "lustre",
330 void obd_sysctl_init (void)
333 if ( !obd_table_header )
334 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
338 void obd_sysctl_clean (void)
341 if ( obd_table_header )
342 cfs_unregister_sysctl_table(obd_table_header);
343 obd_table_header = NULL;