Whamcloud - gitweb
05b4bafa9a22efec5ca0b6b22f855027a7cb62aa
[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_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 };
64
65 int LL_PROC_PROTO(proc_fail_loc)
66 {
67         int rc;
68         int old_fail_loc = obd_fail_loc;
69
70         rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
71         if (old_fail_loc != obd_fail_loc)
72                 wake_up(&obd_race_waitq);
73         return rc;
74 }
75
76 int LL_PROC_PROTO(proc_set_timeout)
77 {
78         int rc;
79
80         rc = ll_proc_dointvec(table, write, filp, buffer, lenp, ppos);
81         if (ldlm_timeout >= obd_timeout)
82                 ldlm_timeout = max(obd_timeout / 3, 1U);
83         return rc;
84 }
85
86 int LL_PROC_PROTO(proc_memory_alloc)
87 {
88         char buf[22];
89         int len;
90         DECLARE_LL_PROC_PPOS_DECL;
91
92         if (!*lenp || (*ppos && !write)) {
93                 *lenp = 0;
94                 return 0;
95         }
96         if (write) 
97                 return -EINVAL;
98         
99         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
100         if (len > *lenp)
101                 len = *lenp;
102         buf[len] = '\0';
103         if (copy_to_user(buffer, buf, len))
104                 return -EFAULT;
105         *lenp = len;
106         *ppos += *lenp;
107         return 0;
108 }
109
110 int LL_PROC_PROTO(proc_pages_alloc)
111 {
112         char buf[22];
113         int len;
114         DECLARE_LL_PROC_PPOS_DECL;
115
116         if (!*lenp || (*ppos && !write)) {
117                 *lenp = 0;
118                 return 0;
119         }
120         if (write)
121                 return -EINVAL;
122
123         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
124         if (len > *lenp)
125                 len = *lenp;
126         buf[len] = '\0';
127         if (copy_to_user(buffer, buf, len))
128                 return -EFAULT;
129         *lenp = len;
130         *ppos += *lenp;
131         return 0;
132 }
133
134 int LL_PROC_PROTO(proc_mem_max)
135 {
136         char buf[22];
137         int len;
138         DECLARE_LL_PROC_PPOS_DECL;
139
140         if (!*lenp || (*ppos && !write)) {
141                 *lenp = 0;
142                 return 0;
143         }
144         if (write)
145                 return -EINVAL;
146
147         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
148         if (len > *lenp)
149                 len = *lenp;
150         buf[len] = '\0';
151         if (copy_to_user(buffer, buf, len))
152                 return -EFAULT;
153         *lenp = len;
154         *ppos += *lenp;
155         return 0;
156 }
157
158 int LL_PROC_PROTO(proc_pages_max)
159 {
160         char buf[22];
161         int len;
162         DECLARE_LL_PROC_PPOS_DECL;
163
164         if (!*lenp || (*ppos && !write)) {
165                 *lenp = 0;
166                 return 0;
167         }
168         if (write)
169                 return -EINVAL;
170
171         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
172         if (len > *lenp)
173                 len = *lenp;
174         buf[len] = '\0';
175         if (copy_to_user(buffer, buf, len))
176                 return -EFAULT;
177         *lenp = len;
178         *ppos += *lenp;
179         return 0;
180 }
181
182 static cfs_sysctl_table_t obd_table[] = {
183         {
184                 .ctl_name = OBD_FAIL_LOC,
185                 .procname = "fail_loc",
186                 .data     = &obd_fail_loc,
187                 .maxlen   = sizeof(int),
188                 .mode     = 0644,
189                 .proc_handler = &proc_fail_loc
190         },
191         {
192                 .ctl_name = OBD_FAIL_VAL,
193                 .procname = "fail_val",
194                 .data     = &obd_fail_val,
195                 .maxlen   = sizeof(int),
196                 .mode     = 0644,
197                 .proc_handler = &proc_dointvec
198         },
199         {
200                 .ctl_name = OBD_TIMEOUT,
201                 .procname = "timeout",
202                 .data     = &obd_timeout,
203                 .maxlen   = sizeof(int),
204                 .mode     = 0644,
205                 .proc_handler = &proc_set_timeout
206         },
207         {
208                 .ctl_name = OBD_DEBUG_PEER_ON_TIMEOUT,
209                 .procname = "debug_peer_on_timeout",
210                 .data     = &obd_debug_peer_on_timeout,
211                 .maxlen   = sizeof(int),
212                 .mode     = 0644,
213                 .proc_handler = &proc_dointvec
214         },
215         {
216                 .ctl_name = OBD_DUMP_ON_TIMEOUT,
217                 .procname = "dump_on_timeout",
218                 .data     = &obd_dump_on_timeout,
219                 .maxlen   = sizeof(int),
220                 .mode     = 0644,
221                 .proc_handler = &proc_dointvec
222         },
223         {
224                 .ctl_name = OBD_DUMP_ON_EVICTION,
225                 .procname = "dump_on_eviction",
226                 .data     = &obd_dump_on_eviction,
227                 .maxlen   = sizeof(int),
228                 .mode     = 0644,
229                 .proc_handler = &proc_dointvec
230         },
231         {
232                 .ctl_name = OBD_MEMUSED,
233                 .procname = "memused",
234                 .data     = NULL,
235                 .maxlen   = 0,
236                 .mode     = 0444,
237                 .proc_handler = &proc_memory_alloc
238         },
239         {
240                 .ctl_name = OBD_PAGESUSED,
241                 .procname = "pagesused",
242                 .data     = NULL,
243                 .maxlen   = 0,
244                 .mode     = 0444,
245                 .proc_handler = &proc_pages_alloc
246         },
247         {
248                 .ctl_name = OBD_MAXMEMUSED,
249                 .procname = "memused_max",
250                 .data     = NULL,
251                 .maxlen   = 0,
252                 .mode     = 0444,
253                 .proc_handler = &proc_mem_max
254         },
255         {
256                 .ctl_name = OBD_MAXPAGESUSED,
257                 .procname = "pagesused_max",
258                 .data     = NULL,
259                 .maxlen   = 0,
260                 .mode     = 0444,
261                 .proc_handler = &proc_pages_max
262         },
263         {
264                 .ctl_name = OBD_LDLM_TIMEOUT,
265                 .procname = "ldlm_timeout",
266                 .data     = &ldlm_timeout,
267                 .maxlen   = sizeof(int),
268                 .mode     = 0644,
269                 .proc_handler = &proc_set_timeout
270         },
271         { 0 }
272 };
273
274 static cfs_sysctl_table_t parent_table[] = {
275         {
276                 .ctl_name = OBD_SYSCTL,
277                 .procname = "lustre",
278                 .data     = NULL,
279                 .maxlen   = 0,
280                 .mode     = 0555,
281                 .child    = obd_table
282         },
283         {0}
284 };
285
286 void obd_sysctl_init (void)
287 {
288 #ifdef CONFIG_SYSCTL
289         if ( !obd_table_header )
290                 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
291 #endif
292 }
293
294 void obd_sysctl_clean (void)
295 {
296 #ifdef CONFIG_SYSCTL
297         if ( obd_table_header )
298                 cfs_unregister_sysctl_table(obd_table_header);
299         obd_table_header = NULL;
300 #endif
301 }