4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2014, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/libcfs/linux/linux-proc.c
38 * Author: Zach Brown <zab@zabbo.net>
39 * Author: Peter J. Braam <braam@clusterfs.com>
40 * Author: Phil Schwan <phil@clusterfs.com>
43 #include <linux/module.h>
44 #include <linux/kernel.h>
46 #include <linux/string.h>
47 #include <linux/stat.h>
48 #include <linux/errno.h>
49 #include <linux/unistd.h>
51 #include <linux/uio.h>
53 #include <asm/uaccess.h>
56 #include <linux/file.h>
57 #include <linux/stat.h>
58 #include <linux/list.h>
59 #include <asm/uaccess.h>
61 #include <linux/proc_fs.h>
62 #include <linux/sysctl.h>
64 # define DEBUG_SUBSYSTEM S_LNET
66 #include <libcfs/libcfs.h>
67 #include <asm/div64.h>
68 #include "tracefile.h"
71 static struct ctl_table_header *lnet_table_header = NULL;
74 int lprocfs_call_handler(void *data, int write, loff_t *ppos,
75 void __user *buffer, size_t *lenp,
76 int (*handler)(void *data, int write, loff_t pos,
77 void __user *buffer, int len))
79 int rc = handler(data, write, *ppos, buffer, *lenp);
92 EXPORT_SYMBOL(lprocfs_call_handler);
94 static int __proc_dobitmasks(void *data, int write,
95 loff_t pos, void __user *buffer, int nob)
97 const int tmpstrlen = 512;
100 unsigned int *mask = data;
101 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
102 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
104 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
109 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
115 rc = cfs_trace_copyout_string(buffer, nob,
119 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
121 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
125 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
126 /* Always print LBUG/LASSERT to console, so keep this mask */
131 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
136 proc_dobitmasks(struct ctl_table *table, int write,
137 void __user *buffer, size_t *lenp, loff_t *ppos)
139 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
143 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
144 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
146 static int __proc_dump_kernel(void *data, int write,
147 loff_t pos, void __user *buffer, int nob)
152 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
156 proc_dump_kernel(struct ctl_table *table, int write, void __user *buffer,
157 size_t *lenp, loff_t *ppos)
159 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
163 static int __proc_daemon_file(void *data, int write,
164 loff_t pos, void __user *buffer, int nob)
167 int len = strlen(cfs_tracefile);
172 return cfs_trace_copyout_string(buffer, nob,
173 cfs_tracefile + pos, "\n");
176 return cfs_trace_daemon_command_usrstr(buffer, nob);
180 proc_daemon_file(struct ctl_table *table, int write, void __user *buffer,
181 size_t *lenp, loff_t *ppos)
183 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
187 static int __proc_debug_mb(void *data, int write,
188 loff_t pos, void __user *buffer, int nob)
192 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
193 cfs_trace_get_debug_mb());
198 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
202 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
206 proc_debug_mb(struct ctl_table *table, int write, void __user *buffer,
207 size_t *lenp, loff_t *ppos)
209 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
214 proc_console_max_delay_cs(struct ctl_table *table, int write,
215 void __user *buffer, size_t *lenp, loff_t *ppos)
217 int rc, max_delay_cs;
218 struct ctl_table dummy = *table;
221 dummy.data = &max_delay_cs;
222 dummy.proc_handler = &proc_dointvec;
224 if (!write) { /* read */
225 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
226 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
232 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
235 if (max_delay_cs <= 0)
238 d = cfs_time_seconds(max_delay_cs) / 100;
239 if (d == 0 || d < libcfs_console_min_delay)
241 libcfs_console_max_delay = d;
247 proc_console_min_delay_cs(struct ctl_table *table, int write,
248 void __user *buffer, size_t *lenp, loff_t *ppos)
250 int rc, min_delay_cs;
251 struct ctl_table dummy = *table;
254 dummy.data = &min_delay_cs;
255 dummy.proc_handler = &proc_dointvec;
257 if (!write) { /* read */
258 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
259 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
265 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
268 if (min_delay_cs <= 0)
271 d = cfs_time_seconds(min_delay_cs) / 100;
272 if (d == 0 || d > libcfs_console_max_delay)
274 libcfs_console_min_delay = d;
280 proc_console_backoff(struct ctl_table *table, int write, void __user *buffer,
281 size_t *lenp, loff_t *ppos)
284 struct ctl_table dummy = *table;
286 dummy.data = &backoff;
287 dummy.proc_handler = &proc_dointvec;
289 if (!write) { /* read */
290 backoff= libcfs_console_backoff;
291 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
297 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
303 libcfs_console_backoff = backoff;
309 libcfs_force_lbug(struct ctl_table *table, int write, void __user *buffer,
310 size_t *lenp, loff_t *ppos)
318 proc_fail_loc(struct ctl_table *table, int write, void __user *buffer,
319 size_t *lenp, loff_t *ppos)
322 long old_fail_loc = cfs_fail_loc;
324 rc = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
325 if (old_fail_loc != cfs_fail_loc)
326 wake_up(&cfs_race_waitq);
330 static int __proc_cpt_table(void *data, int write,
331 loff_t pos, void __user *buffer, int nob)
340 LASSERT(cfs_cpt_table != NULL);
343 LIBCFS_ALLOC(buf, len);
347 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
352 LIBCFS_FREE(buf, len);
364 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
367 LIBCFS_FREE(buf, len);
372 proc_cpt_table(struct ctl_table *table, int write, void __user *buffer,
373 size_t *lenp, loff_t *ppos)
375 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
379 static struct ctl_table lnet_table[] = {
381 * NB No .strategy entries have been provided since sysctl(8) prefers
382 * to go via /proc for portability.
387 .data = &libcfs_debug,
388 .maxlen = sizeof(int),
390 .proc_handler = &proc_dobitmasks,
394 .procname = "subsystem_debug",
395 .data = &libcfs_subsystem_debug,
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_dobitmasks,
402 .procname = "printk",
403 .data = &libcfs_printk,
404 .maxlen = sizeof(int),
406 .proc_handler = &proc_dobitmasks,
410 .procname = "console_ratelimit",
411 .data = &libcfs_console_ratelimit,
412 .maxlen = sizeof(int),
414 .proc_handler = &proc_dointvec
418 .procname = "console_max_delay_centisecs",
419 .maxlen = sizeof(int),
421 .proc_handler = &proc_console_max_delay_cs
425 .procname = "console_min_delay_centisecs",
426 .maxlen = sizeof(int),
428 .proc_handler = &proc_console_min_delay_cs
432 .procname = "console_backoff",
433 .maxlen = sizeof(int),
435 .proc_handler = &proc_console_backoff
439 .procname = "debug_path",
440 .data = libcfs_debug_file_path_arr,
441 .maxlen = sizeof(libcfs_debug_file_path_arr),
443 .proc_handler = &proc_dostring,
447 .procname = "cpu_partition_table",
450 .proc_handler = &proc_cpt_table,
454 .procname = "upcall",
456 .maxlen = sizeof(lnet_upcall),
458 .proc_handler = &proc_dostring,
462 .procname = "debug_log_upcall",
463 .data = lnet_debug_log_upcall,
464 .maxlen = sizeof(lnet_debug_log_upcall),
466 .proc_handler = &proc_dostring,
470 .procname = "lnet_memused",
471 .data = (int *)&libcfs_kmemory.counter,
472 .maxlen = sizeof(int),
474 .proc_handler = &proc_dointvec,
479 .procname = "catastrophe",
480 .data = &libcfs_catastrophe,
481 .maxlen = sizeof(int),
483 .proc_handler = &proc_dointvec,
488 .procname = "panic_on_lbug",
489 .data = &libcfs_panic_on_lbug,
490 .maxlen = sizeof(int),
492 .proc_handler = &proc_dointvec,
497 .procname = "dump_kernel",
500 .proc_handler = &proc_dump_kernel,
504 .procname = "daemon_file",
507 .proc_handler = &proc_daemon_file,
511 .procname = "debug_mb",
513 .proc_handler = &proc_debug_mb,
517 .procname = "watchdog_ratelimit",
518 .data = &libcfs_watchdog_ratelimit,
519 .maxlen = sizeof(int),
521 .proc_handler = &proc_dointvec_minmax,
522 .extra1 = &min_watchdog_ratelimit,
523 .extra2 = &max_watchdog_ratelimit,
527 .procname = "force_lbug",
531 .proc_handler = &libcfs_force_lbug
535 .procname = "fail_loc",
536 .data = &cfs_fail_loc,
537 .maxlen = sizeof(cfs_fail_loc),
539 .proc_handler = &proc_fail_loc
543 .procname = "fail_val",
544 .data = &cfs_fail_val,
545 .maxlen = sizeof(int),
547 .proc_handler = &proc_dointvec
551 .procname = "fail_err",
552 .data = &cfs_fail_err,
553 .maxlen = sizeof(cfs_fail_err),
555 .proc_handler = &proc_dointvec,
561 static struct ctl_table top_table[] = {
574 int insert_proc(void)
577 if (lnet_table_header == NULL)
578 lnet_table_header = register_sysctl_table(top_table);
583 void remove_proc(void)
586 if (lnet_table_header != NULL)
587 unregister_sysctl_table(lnet_table_header);
589 lnet_table_header = NULL;