Whamcloud - gitweb
remove unneed include.
[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/uaccess.h>
39 #include <linux/utsname.h>
40
41 #define DEBUG_SUBSYSTEM S_CLASS
42
43 #include <obd_support.h>
44 #include <lprocfs_status.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         OBD_ALLOC_FAIL_RATE,    /* memory allocation random failure rate */
64 };
65
66 int LL_PROC_PROTO(proc_fail_loc)
67 {
68         int rc;
69         long old_fail_loc = obd_fail_loc;
70
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);
74         return rc;
75 }
76
77 int LL_PROC_PROTO(proc_set_timeout)
78 {
79         int rc;
80
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);
84         return rc;
85 }
86
87 int LL_PROC_PROTO(proc_memory_alloc)
88 {
89         char buf[22];
90         int len;
91         DECLARE_LL_PROC_PPOS_DECL;
92
93         if (!*lenp || (*ppos && !write)) {
94                 *lenp = 0;
95                 return 0;
96         }
97         if (write) 
98                 return -EINVAL;
99         
100         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
101         if (len > *lenp)
102                 len = *lenp;
103         buf[len] = '\0';
104         if (copy_to_user(buffer, buf, len))
105                 return -EFAULT;
106         *lenp = len;
107         *ppos += *lenp;
108         return 0;
109 }
110
111 int LL_PROC_PROTO(proc_pages_alloc)
112 {
113         char buf[22];
114         int len;
115         DECLARE_LL_PROC_PPOS_DECL;
116
117         if (!*lenp || (*ppos && !write)) {
118                 *lenp = 0;
119                 return 0;
120         }
121         if (write)
122                 return -EINVAL;
123
124         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_sum());
125         if (len > *lenp)
126                 len = *lenp;
127         buf[len] = '\0';
128         if (copy_to_user(buffer, buf, len))
129                 return -EFAULT;
130         *lenp = len;
131         *ppos += *lenp;
132         return 0;
133 }
134
135 int LL_PROC_PROTO(proc_mem_max)
136 {
137         char buf[22];
138         int len;
139         DECLARE_LL_PROC_PPOS_DECL;
140
141         if (!*lenp || (*ppos && !write)) {
142                 *lenp = 0;
143                 return 0;
144         }
145         if (write)
146                 return -EINVAL;
147
148         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
149         if (len > *lenp)
150                 len = *lenp;
151         buf[len] = '\0';
152         if (copy_to_user(buffer, buf, len))
153                 return -EFAULT;
154         *lenp = len;
155         *ppos += *lenp;
156         return 0;
157 }
158
159 int LL_PROC_PROTO(proc_pages_max)
160 {
161         char buf[22];
162         int len;
163         DECLARE_LL_PROC_PPOS_DECL;
164
165         if (!*lenp || (*ppos && !write)) {
166                 *lenp = 0;
167                 return 0;
168         }
169         if (write)
170                 return -EINVAL;
171
172         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_pages_max());
173         if (len > *lenp)
174                 len = *lenp;
175         buf[len] = '\0';
176         if (copy_to_user(buffer, buf, len))
177                 return -EFAULT;
178         *lenp = len;
179         *ppos += *lenp;
180         return 0;
181 }
182
183 #ifdef RANDOM_FAIL_ALLOC
184 int LL_PROC_PROTO(proc_alloc_fail_rate)
185 {
186         int rc          = 0;
187         DECLARE_LL_PROC_PPOS_DECL;
188
189         if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
190                 *lenp = 0;
191                 return 0;
192         }
193         if (write) {
194                 rc = lprocfs_write_frac_helper(buffer, *lenp, 
195                                                (unsigned int*)table->data,
196                                                OBD_ALLOC_FAIL_MULT);
197         } else {
198                 char buf[21];
199                 int  len;
200
201                 len = lprocfs_read_frac_helper(buf, 21,
202                                                *(unsigned int*)table->data,
203                                                OBD_ALLOC_FAIL_MULT);
204                 if (len > *lenp)
205                         len = *lenp;
206                 buf[len] = '\0';
207                 if (copy_to_user(buffer, buf, len))
208                         return -EFAULT;
209                 *lenp = len;
210         }
211         *ppos += *lenp;
212         return rc;
213 }
214 #endif
215
216 static cfs_sysctl_table_t obd_table[] = {
217         {
218                 .ctl_name = OBD_FAIL_LOC,
219                 .procname = "fail_loc",
220                 .data     = &obd_fail_loc,
221                 .maxlen   = sizeof(int),
222                 .mode     = 0644,
223                 .proc_handler = &proc_fail_loc
224         },
225         {
226                 .ctl_name = OBD_FAIL_VAL,
227                 .procname = "fail_val",
228                 .data     = &obd_fail_val,
229                 .maxlen   = sizeof(int),
230                 .mode     = 0644,
231                 .proc_handler = &proc_dointvec
232         },
233         {
234                 .ctl_name = OBD_TIMEOUT,
235                 .procname = "timeout",
236                 .data     = &obd_timeout,
237                 .maxlen   = sizeof(int),
238                 .mode     = 0644,
239                 .proc_handler = &proc_set_timeout
240         },
241         {
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),
246                 .mode     = 0644,
247                 .proc_handler = &proc_dointvec
248         },
249         {
250                 .ctl_name = OBD_DUMP_ON_TIMEOUT,
251                 .procname = "dump_on_timeout",
252                 .data     = &obd_dump_on_timeout,
253                 .maxlen   = sizeof(int),
254                 .mode     = 0644,
255                 .proc_handler = &proc_dointvec
256         },
257         {
258                 .ctl_name = OBD_DUMP_ON_EVICTION,
259                 .procname = "dump_on_eviction",
260                 .data     = &obd_dump_on_eviction,
261                 .maxlen   = sizeof(int),
262                 .mode     = 0644,
263                 .proc_handler = &proc_dointvec
264         },
265         {
266                 .ctl_name = OBD_MEMUSED,
267                 .procname = "memused",
268                 .data     = NULL,
269                 .maxlen   = 0,
270                 .mode     = 0444,
271                 .proc_handler = &proc_memory_alloc
272         },
273         {
274                 .ctl_name = OBD_PAGESUSED,
275                 .procname = "pagesused",
276                 .data     = NULL,
277                 .maxlen   = 0,
278                 .mode     = 0444,
279                 .proc_handler = &proc_pages_alloc
280         },
281         {
282                 .ctl_name = OBD_MAXMEMUSED,
283                 .procname = "memused_max",
284                 .data     = NULL,
285                 .maxlen   = 0,
286                 .mode     = 0444,
287                 .proc_handler = &proc_mem_max
288         },
289         {
290                 .ctl_name = OBD_MAXPAGESUSED,
291                 .procname = "pagesused_max",
292                 .data     = NULL,
293                 .maxlen   = 0,
294                 .mode     = 0444,
295                 .proc_handler = &proc_pages_max
296         },
297         {
298                 .ctl_name = OBD_LDLM_TIMEOUT,
299                 .procname = "ldlm_timeout",
300                 .data     = &ldlm_timeout,
301                 .maxlen   = sizeof(int),
302                 .mode     = 0644,
303                 .proc_handler = &proc_set_timeout
304         },
305 #ifdef RANDOM_FAIL_LOC
306         {
307                 .ctl_name = OBD_ALLOC_FAIL_RATE,
308                 .procname = "alloc_fail_rate",
309                 .data     = &obd_alloc_fail_rate,
310                 .maxlen   = sizeof(int),
311                 .mode     = 0644,
312                 .proc_handler = &proc_alloc_fail_rate
313         },
314 #endif
315         { 0 }
316 };
317
318 static cfs_sysctl_table_t parent_table[] = {
319         {
320                 .ctl_name = OBD_SYSCTL,
321                 .procname = "lustre",
322                 .data     = NULL,
323                 .maxlen   = 0,
324                 .mode     = 0555,
325                 .child    = obd_table
326         },
327         {0}
328 };
329
330 void obd_sysctl_init (void)
331 {
332 #ifdef CONFIG_SYSCTL
333         if ( !obd_table_header )
334                 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
335 #endif
336 }
337
338 void obd_sysctl_clean (void)
339 {
340 #ifdef CONFIG_SYSCTL
341         if ( obd_table_header )
342                 cfs_unregister_sysctl_table(obd_table_header);
343         obd_table_header = NULL;
344 #endif
345 }