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, 2012, 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;
73 extern char lnet_upcall[1024];
75 * The path of debug log dump upcall script.
77 extern char lnet_debug_log_upcall[1024];
80 proc_call_handler(void *data, int write,
81 loff_t *ppos, void *buffer, size_t *lenp,
82 int (*handler)(void *data, int write,
83 loff_t pos, void *buffer, int len))
85 int rc = handler(data, write, *ppos, buffer, *lenp);
98 EXPORT_SYMBOL(proc_call_handler);
100 static int __proc_dobitmasks(void *data, int write,
101 loff_t pos, void *buffer, int nob)
103 const int tmpstrlen = 512;
106 unsigned int *mask = data;
107 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
108 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
110 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
115 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
121 rc = cfs_trace_copyout_string(buffer, nob,
125 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
127 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
131 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
132 /* Always print LBUG/LASSERT to console, so keep this mask */
137 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
141 DECLARE_PROC_HANDLER(proc_dobitmasks)
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 *buffer, int nob)
152 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
155 DECLARE_PROC_HANDLER(proc_dump_kernel)
157 static int __proc_daemon_file(void *data, int write,
158 loff_t pos, void *buffer, int nob)
161 int len = strlen(cfs_tracefile);
166 return cfs_trace_copyout_string(buffer, nob,
167 cfs_tracefile + pos, "\n");
170 return cfs_trace_daemon_command_usrstr(buffer, nob);
173 DECLARE_PROC_HANDLER(proc_daemon_file)
175 static int __proc_debug_mb(void *data, int write,
176 loff_t pos, void *buffer, int nob)
180 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
181 cfs_trace_get_debug_mb());
186 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
190 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
193 DECLARE_PROC_HANDLER(proc_debug_mb)
195 int LL_PROC_PROTO(proc_console_max_delay_cs)
197 int rc, max_delay_cs;
198 struct ctl_table dummy = *table;
201 dummy.data = &max_delay_cs;
202 dummy.proc_handler = &proc_dointvec;
204 if (!write) { /* read */
205 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
206 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
212 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
215 if (max_delay_cs <= 0)
218 d = cfs_time_seconds(max_delay_cs) / 100;
219 if (d == 0 || d < libcfs_console_min_delay)
221 libcfs_console_max_delay = d;
226 int LL_PROC_PROTO(proc_console_min_delay_cs)
228 int rc, min_delay_cs;
229 struct ctl_table dummy = *table;
232 dummy.data = &min_delay_cs;
233 dummy.proc_handler = &proc_dointvec;
235 if (!write) { /* read */
236 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
237 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
243 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
246 if (min_delay_cs <= 0)
249 d = cfs_time_seconds(min_delay_cs) / 100;
250 if (d == 0 || d > libcfs_console_max_delay)
252 libcfs_console_min_delay = d;
257 int LL_PROC_PROTO(proc_console_backoff)
260 struct ctl_table dummy = *table;
262 dummy.data = &backoff;
263 dummy.proc_handler = &proc_dointvec;
265 if (!write) { /* read */
266 backoff= libcfs_console_backoff;
267 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
273 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
279 libcfs_console_backoff = backoff;
284 int LL_PROC_PROTO(libcfs_force_lbug)
291 int LL_PROC_PROTO(proc_fail_loc)
294 long old_fail_loc = cfs_fail_loc;
296 rc = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
297 if (old_fail_loc != cfs_fail_loc)
298 wake_up(&cfs_race_waitq);
302 static int __proc_cpt_table(void *data, int write,
303 loff_t pos, void *buffer, int nob)
312 LASSERT(cfs_cpt_table != NULL);
315 LIBCFS_ALLOC(buf, len);
319 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
323 LIBCFS_FREE(buf, len);
336 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
339 LIBCFS_FREE(buf, len);
342 DECLARE_PROC_HANDLER(proc_cpt_table)
344 static struct ctl_table lnet_table[] = {
346 * NB No .strategy entries have been provided since sysctl(8) prefers
347 * to go via /proc for portability.
352 .data = &libcfs_debug,
353 .maxlen = sizeof(int),
355 .proc_handler = &proc_dobitmasks,
359 .procname = "subsystem_debug",
360 .data = &libcfs_subsystem_debug,
361 .maxlen = sizeof(int),
363 .proc_handler = &proc_dobitmasks,
367 .procname = "printk",
368 .data = &libcfs_printk,
369 .maxlen = sizeof(int),
371 .proc_handler = &proc_dobitmasks,
375 .procname = "console_ratelimit",
376 .data = &libcfs_console_ratelimit,
377 .maxlen = sizeof(int),
379 .proc_handler = &proc_dointvec
383 .procname = "console_max_delay_centisecs",
384 .maxlen = sizeof(int),
386 .proc_handler = &proc_console_max_delay_cs
390 .procname = "console_min_delay_centisecs",
391 .maxlen = sizeof(int),
393 .proc_handler = &proc_console_min_delay_cs
397 .procname = "console_backoff",
398 .maxlen = sizeof(int),
400 .proc_handler = &proc_console_backoff
404 .procname = "debug_path",
405 .data = libcfs_debug_file_path_arr,
406 .maxlen = sizeof(libcfs_debug_file_path_arr),
408 .proc_handler = &proc_dostring,
412 .procname = "cpu_partition_table",
415 .proc_handler = &proc_cpt_table,
419 .procname = "upcall",
421 .maxlen = sizeof(lnet_upcall),
423 .proc_handler = &proc_dostring,
427 .procname = "debug_log_upcall",
428 .data = lnet_debug_log_upcall,
429 .maxlen = sizeof(lnet_debug_log_upcall),
431 .proc_handler = &proc_dostring,
435 .procname = "lnet_memused",
436 .data = (int *)&libcfs_kmemory.counter,
437 .maxlen = sizeof(int),
439 .proc_handler = &proc_dointvec,
444 .procname = "catastrophe",
445 .data = &libcfs_catastrophe,
446 .maxlen = sizeof(int),
448 .proc_handler = &proc_dointvec,
453 .procname = "panic_on_lbug",
454 .data = &libcfs_panic_on_lbug,
455 .maxlen = sizeof(int),
457 .proc_handler = &proc_dointvec,
462 .procname = "dump_kernel",
465 .proc_handler = &proc_dump_kernel,
469 .procname = "daemon_file",
472 .proc_handler = &proc_daemon_file,
476 .procname = "debug_mb",
478 .proc_handler = &proc_debug_mb,
482 .procname = "watchdog_ratelimit",
483 .data = &libcfs_watchdog_ratelimit,
484 .maxlen = sizeof(int),
486 .proc_handler = &proc_dointvec_minmax,
487 .extra1 = &min_watchdog_ratelimit,
488 .extra2 = &max_watchdog_ratelimit,
492 .procname = "force_lbug",
496 .proc_handler = &libcfs_force_lbug
500 .procname = "fail_loc",
501 .data = &cfs_fail_loc,
502 .maxlen = sizeof(cfs_fail_loc),
504 .proc_handler = &proc_fail_loc
508 .procname = "fail_val",
509 .data = &cfs_fail_val,
510 .maxlen = sizeof(int),
512 .proc_handler = &proc_dointvec
516 .procname = "fail_err",
517 .data = &cfs_fail_err,
518 .maxlen = sizeof(cfs_fail_err),
520 .proc_handler = &proc_dointvec,
526 static struct ctl_table top_table[] = {
539 int insert_proc(void)
542 if (lnet_table_header == NULL)
543 lnet_table_header = register_sysctl_table(top_table);
548 void remove_proc(void)
551 if (lnet_table_header != NULL)
552 unregister_sysctl_table(lnet_table_header);
554 lnet_table_header = NULL;