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