Whamcloud - gitweb
LU-7243 misc: update Intel copyright messages 2015
[fs/lustre-release.git] / lustre / obdclass / linux / linux-sysctl.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2015, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #include <linux/module.h>
38 #include <linux/sysctl.h>
39 #include <linux/sched.h>
40 #include <linux/mm.h>
41 #include <linux/sysctl.h>
42 #include <linux/version.h>
43 #include <linux/proc_fs.h>
44 #include <linux/slab.h>
45 #include <linux/stat.h>
46 #include <linux/ctype.h>
47 #include <asm/bitops.h>
48 #include <asm/uaccess.h>
49 #include <linux/utsname.h>
50
51 #define DEBUG_SUBSYSTEM S_CLASS
52
53 #include <obd_support.h>
54 #include <lprocfs_status.h>
55 #include <obd_class.h>
56
57 #ifdef CONFIG_SYSCTL
58 static struct ctl_table_header *obd_table_header;
59 #endif
60
61 static int
62 proc_set_timeout(struct ctl_table *table, int write, void __user *buffer,
63                  size_t *lenp, loff_t *ppos)
64 {
65         int rc;
66
67         rc = proc_dointvec(table, write, buffer, lenp, ppos);
68         if (ldlm_timeout >= obd_timeout)
69                 ldlm_timeout = max(obd_timeout / 3, 1U);
70         return rc;
71 }
72
73 static int
74 proc_memory_alloc(struct ctl_table *table, int write, void __user *buffer,
75                   size_t *lenp, loff_t *ppos)
76 {
77         char buf[22];
78         int len;
79
80         if (!*lenp || (*ppos && !write)) {
81                 *lenp = 0;
82                 return 0;
83         }
84         if (write)
85                 return -EINVAL;
86
87         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_sum());
88         if (len > *lenp)
89                 len = *lenp;
90         buf[len] = '\0';
91         if (copy_to_user(buffer, buf, len))
92                 return -EFAULT;
93         *lenp = len;
94         *ppos += *lenp;
95         return 0;
96 }
97
98 static int
99 proc_mem_max(struct ctl_table *table, int write, void __user *buffer,
100              size_t *lenp, loff_t *ppos)
101 {
102         char buf[22];
103         int len;
104
105         if (!*lenp || (*ppos && !write)) {
106                 *lenp = 0;
107                 return 0;
108         }
109         if (write)
110                 return -EINVAL;
111
112         len = snprintf(buf, sizeof(buf), LPU64"\n", obd_memory_max());
113         if (len > *lenp)
114                 len = *lenp;
115         buf[len] = '\0';
116         if (copy_to_user(buffer, buf, len))
117                 return -EFAULT;
118         *lenp = len;
119         *ppos += *lenp;
120         return 0;
121 }
122
123 static int
124 proc_max_dirty_pages_in_mb(struct ctl_table *table, int write,
125                            void __user *buffer, size_t *lenp, loff_t *ppos)
126 {
127         __u64 val;
128         int rc = 0;
129
130         if (!table->data || !table->maxlen || !*lenp || (*ppos && !write)) {
131                 *lenp = 0;
132                 return 0;
133         }
134         if (write) {
135                 rc = lprocfs_write_frac_u64_helper(buffer, *lenp, &val,
136                                                1 << (20 - PAGE_CACHE_SHIFT));
137
138                 /* Don't allow them to let dirty pages exceed 90% of system
139                  * memory and set a hard minimum of 4MB. */
140                 if (val > ((totalram_pages / 10) * 9)) {
141                         CERROR("Refusing to set max dirty pages to "LPU64", "
142                                "which is more than 90%% of available RAM; "
143                                "setting to %lu\n", val,
144                                ((totalram_pages / 10) * 9));
145                         obd_max_dirty_pages = ((totalram_pages / 10) * 9);
146                 } else if (val < 4 << (20 - PAGE_CACHE_SHIFT)) {
147                         obd_max_dirty_pages = 4 << (20 - PAGE_CACHE_SHIFT);
148                 } else {
149                         obd_max_dirty_pages = val;
150                 }
151         } else {
152                 char buf[21];
153                 int len;
154
155                 len = lprocfs_read_frac_helper(buf, sizeof(buf),
156                                                *(unsigned long *)table->data,
157                                                1 << (20 - PAGE_CACHE_SHIFT));
158                 if (len > *lenp)
159                         len = *lenp;
160                 buf[len] = '\0';
161                 if (copy_to_user(buffer, buf, len))
162                         return -EFAULT;
163                 *lenp = len;
164         }
165         *ppos += *lenp;
166         return rc;
167 }
168
169 #ifdef CONFIG_SYSCTL
170 static struct ctl_table obd_table[] = {
171         {
172                 INIT_CTL_NAME
173                 .procname       = "timeout",
174                 .data           = &obd_timeout,
175                 .maxlen         = sizeof(int),
176                 .mode           = 0644,
177                 .proc_handler   = &proc_set_timeout
178         },
179         {
180                 INIT_CTL_NAME
181                 .procname       = "debug_peer_on_timeout",
182                 .data           = &obd_debug_peer_on_timeout,
183                 .maxlen         = sizeof(int),
184                 .mode           = 0644,
185                 .proc_handler   = &proc_dointvec
186         },
187         {
188                 INIT_CTL_NAME
189                 .procname       = "dump_on_timeout",
190                 .data           = &obd_dump_on_timeout,
191                 .maxlen         = sizeof(int),
192                 .mode           = 0644,
193                 .proc_handler   = &proc_dointvec
194         },
195         {
196                 INIT_CTL_NAME
197                 .procname       = "dump_on_eviction",
198                 .data           = &obd_dump_on_eviction,
199                 .maxlen         = sizeof(int),
200                 .mode           = 0644,
201                 .proc_handler   = &proc_dointvec
202         },
203         {
204                 INIT_CTL_NAME
205                 .procname       = "memused",
206                 .data           = NULL,
207                 .maxlen         = 0,
208                 .mode           = 0444,
209                 .proc_handler   = &proc_memory_alloc
210         },
211         {
212                 INIT_CTL_NAME
213                 .procname       = "memused_max",
214                 .data           = NULL,
215                 .maxlen         = 0,
216                 .mode           = 0444,
217                 .proc_handler   = &proc_mem_max
218         },
219         {
220                 INIT_CTL_NAME
221                 .procname       = "ldlm_timeout",
222                 .data           = &ldlm_timeout,
223                 .maxlen         = sizeof(int),
224                 .mode           = 0644,
225                 .proc_handler   = &proc_set_timeout
226         },
227         {
228                 INIT_CTL_NAME
229                 .procname       = "max_dirty_mb",
230                 .data           = &obd_max_dirty_pages,
231                 .maxlen         = sizeof(unsigned long),
232                 .mode           = 0644,
233                 .proc_handler   = &proc_max_dirty_pages_in_mb
234         },
235         {
236                 INIT_CTL_NAME
237                 .procname       = "bulk_timeout",
238                 .data           = &bulk_timeout,
239                 .maxlen         = sizeof(int),
240                 .mode           = 0644,
241                 .proc_handler   = &proc_dointvec
242         },
243         {
244                 INIT_CTL_NAME
245                 .procname       = "at_min",
246                 .data           = &at_min,
247                 .maxlen         = sizeof(int),
248                 .mode           = 0644,
249                 .proc_handler   = &proc_dointvec
250         },
251         {
252                 INIT_CTL_NAME
253                 .procname       = "at_max",
254                 .data           = &at_max,
255                 .maxlen         = sizeof(int),
256                 .mode           = 0644,
257                 .proc_handler   = &proc_dointvec
258         },
259         {
260                 INIT_CTL_NAME
261                 .procname       = "at_extra",
262                 .data           = &at_extra,
263                 .maxlen         = sizeof(int),
264                 .mode           = 0644,
265                 .proc_handler   = &proc_dointvec
266         },
267         {
268                 INIT_CTL_NAME
269                 .procname       = "at_early_margin",
270                 .data           = &at_early_margin,
271                 .maxlen         = sizeof(int),
272                 .mode           = 0644,
273                 .proc_handler   = &proc_dointvec
274         },
275         {
276                 INIT_CTL_NAME
277                 .procname       = "at_history",
278                 .data           = &at_history,
279                 .maxlen         = sizeof(int),
280                 .mode           = 0644,
281                 .proc_handler   = &proc_dointvec
282         },
283         { 0 }
284 };
285
286 static struct ctl_table parent_table[] = {
287         {
288                 INIT_CTL_NAME
289                 .procname       = "lustre",
290                 .data           = NULL,
291                 .maxlen         = 0,
292                 .mode           = 0555,
293                 .child          = obd_table
294         },
295         { 0 }
296 };
297 #endif
298
299 void obd_sysctl_init (void)
300 {
301 #ifdef CONFIG_SYSCTL
302         if ( !obd_table_header )
303                 obd_table_header = register_sysctl_table(parent_table);
304 #endif
305 }
306
307 void obd_sysctl_clean (void)
308 {
309 #ifdef CONFIG_SYSCTL
310         if ( obd_table_header )
311                 unregister_sysctl_table(obd_table_header);
312         obd_table_header = NULL;
313 #endif
314 }