Whamcloud - gitweb
fixes for running in more user environments
[fs/lustre-release.git] / lustre / obdclass / linux / linux-sysctl.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
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.
13  *
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.
18  *
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.
23  *
24  */
25
26 #include <linux/module.h>
27 #include <linux/autoconf.h>
28 #include <linux/sysctl.h>
29 #include <linux/sched.h>
30 #include <linux/mm.h>
31 #include <linux/sysctl.h>
32 #include <linux/version.h>
33 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
34 #include <linux/swapctl.h>
35 #endif
36 #include <linux/proc_fs.h>
37 #include <linux/slab.h>
38 #include <linux/stat.h>
39 #include <linux/ctype.h>
40 #include <asm/bitops.h>
41 #include <asm/segment.h>
42 #include <asm/uaccess.h>
43 #include <linux/utsname.h>
44
45 #define DEBUG_SUBSYSTEM S_CLASS
46
47 #include <obd_support.h>
48
49 struct ctl_table_header *obd_table_header = NULL;
50
51 #define OBD_SYSCTL 300
52
53 enum {
54         OBD_FAIL_LOC = 1,       /* control test failures instrumentation */
55         OBD_TIMEOUT,            /* RPC timeout before recovery/intr */
56         OBD_DUMP_ON_TIMEOUT,    /* dump kernel debug log upon eviction */
57         OBD_MEMUSED,            /* bytes currently OBD_ALLOCated */
58         OBD_SYNCFILTER,         /* XXX temporary, as we play with sync osts.. */
59         OBD_LDLM_TIMEOUT,       /* LDLM timeout for ASTs before client eviction */
60         OBD_DUMP_ON_EVICTION,   /* dump kernel debug log upon eviction */
61 };
62
63 int LL_PROC_PROTO(proc_fail_loc)
64 {
65         int rc;
66         int old_fail_loc = obd_fail_loc;
67
68         rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
69         if (old_fail_loc != obd_fail_loc)
70                 wake_up(&obd_race_waitq);
71         return rc;
72 }
73
74 int LL_PROC_PROTO(proc_set_timeout)
75 {
76         int rc;
77
78         rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
79         if (ldlm_timeout >= obd_timeout)
80                 ldlm_timeout = max(obd_timeout / 3, 1U);
81         return rc;
82 }
83
84 static ctl_table obd_table[] = {
85         {OBD_FAIL_LOC, "fail_loc", &obd_fail_loc, sizeof(int), 0644, NULL,
86                 &proc_fail_loc},
87         {OBD_TIMEOUT, "timeout", &obd_timeout, sizeof(int), 0644, NULL,
88                 &proc_set_timeout},
89         {OBD_DUMP_ON_TIMEOUT, "dump_on_timeout", &obd_dump_on_timeout,
90                 sizeof(int), 0644, NULL, &proc_dointvec},
91         {OBD_DUMP_ON_EVICTION, "dump_on_eviction", &obd_dump_on_eviction,
92                 sizeof(int), 0644, NULL, &proc_dointvec},
93         {OBD_MEMUSED, "memused", (int *)&obd_memory.counter,
94                 sizeof(int), 0644, NULL, &proc_dointvec},
95         {OBD_LDLM_TIMEOUT, "ldlm_timeout", &ldlm_timeout, sizeof(int), 0644,
96                 NULL, &proc_set_timeout},
97         { 0 }
98 };
99
100 static ctl_table parent_table[] = {
101        {OBD_SYSCTL, "lustre", NULL, 0, 0555, obd_table},
102        {0}
103 };
104
105 void obd_sysctl_init (void)
106 {
107 #ifdef CONFIG_SYSCTL
108         if ( !obd_table_header )
109                 obd_table_header = register_sysctl_table(parent_table, 0);
110 #endif
111 }
112
113 void obd_sysctl_clean (void)
114 {
115 #ifdef CONFIG_SYSCTL
116         if ( obd_table_header )
117                 unregister_sysctl_table(obd_table_header);
118         obd_table_header = NULL;
119 #endif
120 }