Whamcloud - gitweb
e1415c6983b5d163b00a8ff381f0323ed7048d39
[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 cfs_sysctl_table_header_t *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         OBD_DEBUG_PEER_ON_TIMEOUT, /* dump peer debug when RPC times out */
62 };
63
64 int LL_PROC_PROTO(proc_fail_loc)
65 {
66         int rc;
67         int old_fail_loc = obd_fail_loc;
68
69         rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
70         if (old_fail_loc != obd_fail_loc)
71                 wake_up(&obd_race_waitq);
72         return rc;
73 }
74
75 int LL_PROC_PROTO(proc_set_timeout)
76 {
77         int rc;
78
79         rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
80         if (ldlm_timeout >= obd_timeout)
81                 ldlm_timeout = max(obd_timeout / 3, 1U);
82         return rc;
83 }
84
85 static cfs_sysctl_table_t obd_table[] = {
86         {
87                 .ctl_name = OBD_FAIL_LOC,
88                 .procname = "fail_loc",
89                 .data     = &obd_fail_loc,
90                 .maxlen   = sizeof(int),
91                 .mode     = 0644,
92                 .proc_handler = &proc_fail_loc
93         },
94         {
95                 .ctl_name = OBD_TIMEOUT,
96                 .procname = "timeout",
97                 .data     = &obd_timeout,
98                 .maxlen   = sizeof(int),
99                 .mode     = 0644,
100                 .proc_handler = &proc_set_timeout
101         },
102         {
103                 .ctl_name = OBD_DEBUG_PEER_ON_TIMEOUT,
104                 .procname = "debug_peer_on_timeout",
105                 .data     = &obd_debug_peer_on_timeout,
106                 .maxlen   = sizeof(int),
107                 .mode     = 0644,
108                 .proc_handler = &proc_dointvec
109         },
110         {
111                 .ctl_name = OBD_DUMP_ON_TIMEOUT,
112                 .procname = "dump_on_timeout",
113                 .data     = &obd_dump_on_timeout,
114                 .maxlen   = sizeof(int),
115                 .mode     = 0644,
116                 .proc_handler = &proc_dointvec
117         },
118         {
119                 .ctl_name = OBD_DUMP_ON_EVICTION,
120                 .procname = "dump_on_eviction",
121                 .data     = &obd_dump_on_eviction,
122                 .maxlen   = sizeof(int),
123                 .mode     = 0644,
124                 .proc_handler = &proc_dointvec
125         },
126         {
127                 .ctl_name = OBD_MEMUSED,
128                 .procname = "memused",
129                 .data     = (int *)&obd_memory.counter,
130                 .maxlen   = sizeof(int),
131                 .mode     = 0644,
132                 .proc_handler = &proc_dointvec
133         },
134         {
135                 .ctl_name = OBD_LDLM_TIMEOUT,
136                 .procname = "ldlm_timeout",
137                 .data     = &ldlm_timeout,
138                 .maxlen   = sizeof(int),
139                 .mode     = 0644,
140                 .proc_handler = &proc_set_timeout
141         },
142         { 0 }
143 };
144
145 static cfs_sysctl_table_t parent_table[] = {
146         {
147                 .ctl_name = OBD_SYSCTL,
148                 .procname = "lustre",
149                 .data     = NULL,
150                 .maxlen   = 0,
151                 .mode     = 0555,
152                 .child    = obd_table
153         },
154         {0}
155 };
156
157 void obd_sysctl_init (void)
158 {
159 #ifdef CONFIG_SYSCTL
160         if ( !obd_table_header )
161                 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
162 #endif
163 }
164
165 void obd_sysctl_clean (void)
166 {
167 #ifdef CONFIG_SYSCTL
168         if ( obd_table_header )
169                 cfs_unregister_sysctl_table(obd_table_header);
170         obd_table_header = NULL;
171 #endif
172 }