1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * libcfs/libcfs/linux/linux-proc.c
40 * Author: Zach Brown <zab@zabbo.net>
41 * Author: Peter J. Braam <braam@clusterfs.com>
42 * Author: Phil Schwan <phil@clusterfs.com>
46 # define EXPORT_SYMTAB
49 #ifndef AUTOCONF_INCLUDED
50 #include <linux/config.h>
52 #include <linux/module.h>
53 #include <linux/kernel.h>
55 #include <linux/string.h>
56 #include <linux/stat.h>
57 #include <linux/errno.h>
58 #include <linux/smp_lock.h>
59 #include <linux/unistd.h>
61 #include <linux/uio.h>
63 #include <asm/system.h>
64 #include <asm/uaccess.h>
67 #include <linux/file.h>
68 #include <linux/stat.h>
69 #include <linux/list.h>
70 #include <asm/uaccess.h>
72 #include <linux/proc_fs.h>
73 #include <linux/sysctl.h>
75 # define DEBUG_SUBSYSTEM S_LNET
77 #include <libcfs/libcfs.h>
78 #include <asm/div64.h>
79 #include "tracefile.h"
82 static cfs_sysctl_table_header_t *lnet_table_header = NULL;
84 extern char lnet_upcall[1024];
86 * The path of debug log dump upcall script.
88 extern char lnet_debug_log_upcall[1024];
90 #ifndef HAVE_SYSCTL_UNNUMBERED
91 #define CTL_LNET (0x100)
93 PSDEV_DEBUG = 1, /* control debugging */
94 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
95 PSDEV_PRINTK, /* force all messages to console */
96 PSDEV_CONSOLE_RATELIMIT, /* ratelimit console messages */
97 PSDEV_CONSOLE_MAX_DELAY_CS, /* maximum delay over which we skip messages */
98 PSDEV_CONSOLE_MIN_DELAY_CS, /* initial delay over which we skip messages */
99 PSDEV_CONSOLE_BACKOFF, /* delay increase factor */
100 PSDEV_DEBUG_PATH, /* crashdump log location */
101 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
102 PSDEV_LNET_UPCALL, /* User mode upcall script */
103 PSDEV_LNET_MEMUSED, /* bytes currently PORTAL_ALLOCated */
104 PSDEV_LNET_CATASTROPHE, /* if we have LBUGged or panic'd */
105 PSDEV_LNET_PANIC_ON_LBUG, /* flag to panic on LBUG */
106 PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */
107 PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */
108 PSDEV_LNET_DEBUG_MB, /* size of debug buffer */
109 PSDEV_LNET_DEBUG_LOG_UPCALL, /* debug log upcall script */
110 PSDEV_LNET_WATCHDOG_RATELIMIT, /* ratelimit watchdog messages */
111 PSDEV_LNET_FORCE_LBUG, /* hook to force an LBUG */
112 PSDEV_LNET_FAIL_LOC, /* control test failures instrumentation */
113 PSDEV_LNET_FAIL_VAL, /* userdata for fail loc */
116 #define CTL_LNET CTL_UNNUMBERED
117 #define PSDEV_DEBUG CTL_UNNUMBERED
118 #define PSDEV_SUBSYSTEM_DEBUG CTL_UNNUMBERED
119 #define PSDEV_PRINTK CTL_UNNUMBERED
120 #define PSDEV_CONSOLE_RATELIMIT CTL_UNNUMBERED
121 #define PSDEV_CONSOLE_MAX_DELAY_CS CTL_UNNUMBERED
122 #define PSDEV_CONSOLE_MIN_DELAY_CS CTL_UNNUMBERED
123 #define PSDEV_CONSOLE_BACKOFF CTL_UNNUMBERED
124 #define PSDEV_DEBUG_PATH CTL_UNNUMBERED
125 #define PSDEV_DEBUG_DUMP_PATH CTL_UNNUMBERED
126 #define PSDEV_LNET_UPCALL CTL_UNNUMBERED
127 #define PSDEV_LNET_MEMUSED CTL_UNNUMBERED
128 #define PSDEV_LNET_CATASTROPHE CTL_UNNUMBERED
129 #define PSDEV_LNET_PANIC_ON_LBUG CTL_UNNUMBERED
130 #define PSDEV_LNET_DUMP_KERNEL CTL_UNNUMBERED
131 #define PSDEV_LNET_DAEMON_FILE CTL_UNNUMBERED
132 #define PSDEV_LNET_DEBUG_MB CTL_UNNUMBERED
133 #define PSDEV_LNET_DEBUG_LOG_UPCALL CTL_UNNUMBERED
134 #define PSDEV_LNET_WATCHDOG_RATELIMIT CTL_UNNUMBERED
135 #define PSDEV_LNET_FORCE_LBUG CTL_UNNUMBERED
136 #define PSDEV_LNET_FAIL_LOC CTL_UNNUMBERED
137 #define PSDEV_LNET_FAIL_VAL CTL_UNNUMBERED
141 proc_call_handler(void *data, int write,
142 loff_t *ppos, void *buffer, size_t *lenp,
143 int (*handler)(void *data, int write,
144 loff_t pos, void *buffer, int len))
146 int rc = handler(data, write, *ppos, buffer, *lenp);
159 EXPORT_SYMBOL(proc_call_handler);
161 static int __proc_dobitmasks(void *data, int write,
162 loff_t pos, void *buffer, int nob)
164 const int tmpstrlen = 512;
167 unsigned int *mask = data;
168 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
169 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
171 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
176 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
182 rc = cfs_trace_copyout_string(buffer, nob,
186 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
190 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
191 /* Always print LBUG/LASSERT to console, so keep this mask */
196 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
200 DECLARE_PROC_HANDLER(proc_dobitmasks)
202 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
203 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
205 static int __proc_dump_kernel(void *data, int write,
206 loff_t pos, void *buffer, int nob)
211 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
214 DECLARE_PROC_HANDLER(proc_dump_kernel)
216 static int __proc_daemon_file(void *data, int write,
217 loff_t pos, void *buffer, int nob)
220 int len = strlen(cfs_tracefile);
225 return cfs_trace_copyout_string(buffer, nob,
226 cfs_tracefile + pos, "\n");
229 return cfs_trace_daemon_command_usrstr(buffer, nob);
232 DECLARE_PROC_HANDLER(proc_daemon_file)
234 static int __proc_debug_mb(void *data, int write,
235 loff_t pos, void *buffer, int nob)
239 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
240 cfs_trace_get_debug_mb());
245 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
249 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
252 DECLARE_PROC_HANDLER(proc_debug_mb)
254 int LL_PROC_PROTO(proc_console_max_delay_cs)
256 int rc, max_delay_cs;
257 cfs_sysctl_table_t dummy = *table;
260 dummy.data = &max_delay_cs;
261 dummy.proc_handler = &proc_dointvec;
263 if (!write) { /* read */
264 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
265 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
271 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
274 if (max_delay_cs <= 0)
277 d = cfs_time_seconds(max_delay_cs) / 100;
278 if (d == 0 || d < libcfs_console_min_delay)
280 libcfs_console_max_delay = d;
285 int LL_PROC_PROTO(proc_console_min_delay_cs)
287 int rc, min_delay_cs;
288 cfs_sysctl_table_t dummy = *table;
291 dummy.data = &min_delay_cs;
292 dummy.proc_handler = &proc_dointvec;
294 if (!write) { /* read */
295 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
296 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
302 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
305 if (min_delay_cs <= 0)
308 d = cfs_time_seconds(min_delay_cs) / 100;
309 if (d == 0 || d > libcfs_console_max_delay)
311 libcfs_console_min_delay = d;
316 int LL_PROC_PROTO(proc_console_backoff)
319 cfs_sysctl_table_t dummy = *table;
321 dummy.data = &backoff;
322 dummy.proc_handler = &proc_dointvec;
324 if (!write) { /* read */
325 backoff= libcfs_console_backoff;
326 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
332 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
338 libcfs_console_backoff = backoff;
343 int LL_PROC_PROTO(libcfs_force_lbug)
350 int LL_PROC_PROTO(proc_fail_loc)
353 long old_fail_loc = cfs_fail_loc;
355 rc = ll_proc_dolongvec(table, write, filp, buffer, lenp, ppos);
356 if (old_fail_loc != cfs_fail_loc)
357 cfs_waitq_signal(&cfs_race_waitq);
361 static cfs_sysctl_table_t lnet_table[] = {
363 * NB No .strategy entries have been provided since sysctl(8) prefers
364 * to go via /proc for portability.
367 INIT_CTL_NAME(PSDEV_DEBUG)
369 .data = &libcfs_debug,
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dobitmasks,
375 INIT_CTL_NAME(PSDEV_SUBSYSTEM_DEBUG)
376 .procname = "subsystem_debug",
377 .data = &libcfs_subsystem_debug,
378 .maxlen = sizeof(int),
380 .proc_handler = &proc_dobitmasks,
383 INIT_CTL_NAME(PSDEV_PRINTK)
384 .procname = "printk",
385 .data = &libcfs_printk,
386 .maxlen = sizeof(int),
388 .proc_handler = &proc_dobitmasks,
391 INIT_CTL_NAME(PSDEV_CONSOLE_RATELIMIT)
392 .procname = "console_ratelimit",
393 .data = &libcfs_console_ratelimit,
394 .maxlen = sizeof(int),
396 .proc_handler = &proc_dointvec
399 INIT_CTL_NAME(PSDEV_CONSOLE_MAX_DELAY_CS)
400 .procname = "console_max_delay_centisecs",
401 .maxlen = sizeof(int),
403 .proc_handler = &proc_console_max_delay_cs
406 INIT_CTL_NAME(PSDEV_CONSOLE_MIN_DELAY_CS)
407 .procname = "console_min_delay_centisecs",
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_console_min_delay_cs
413 INIT_CTL_NAME(PSDEV_CONSOLE_BACKOFF)
414 .procname = "console_backoff",
415 .maxlen = sizeof(int),
417 .proc_handler = &proc_console_backoff
421 INIT_CTL_NAME(PSDEV_DEBUG_PATH)
422 .procname = "debug_path",
423 .data = libcfs_debug_file_path_arr,
424 .maxlen = sizeof(libcfs_debug_file_path_arr),
426 .proc_handler = &proc_dostring,
430 INIT_CTL_NAME(PSDEV_LNET_UPCALL)
431 .procname = "upcall",
433 .maxlen = sizeof(lnet_upcall),
435 .proc_handler = &proc_dostring,
438 INIT_CTL_NAME(PSDEV_LNET_DEBUG_LOG_UPCALL)
439 .procname = "debug_log_upcall",
440 .data = lnet_debug_log_upcall,
441 .maxlen = sizeof(lnet_debug_log_upcall),
443 .proc_handler = &proc_dostring,
446 INIT_CTL_NAME(PSDEV_LNET_MEMUSED)
447 .procname = "lnet_memused",
448 .data = (int *)&libcfs_kmemory.counter,
449 .maxlen = sizeof(int),
451 .proc_handler = &proc_dointvec,
452 INIT_STRATEGY(&sysctl_intvec)
455 INIT_CTL_NAME(PSDEV_LNET_CATASTROPHE)
456 .procname = "catastrophe",
457 .data = &libcfs_catastrophe,
458 .maxlen = sizeof(int),
460 .proc_handler = &proc_dointvec,
461 INIT_STRATEGY(&sysctl_intvec)
464 INIT_CTL_NAME(PSDEV_LNET_PANIC_ON_LBUG)
465 .procname = "panic_on_lbug",
466 .data = &libcfs_panic_on_lbug,
467 .maxlen = sizeof(int),
469 .proc_handler = &proc_dointvec,
470 INIT_STRATEGY(&sysctl_intvec)
473 INIT_CTL_NAME(PSDEV_LNET_DUMP_KERNEL)
474 .procname = "dump_kernel",
477 .proc_handler = &proc_dump_kernel,
480 INIT_CTL_NAME(PSDEV_LNET_DAEMON_FILE)
481 .procname = "daemon_file",
484 .proc_handler = &proc_daemon_file,
487 INIT_CTL_NAME(PSDEV_LNET_DEBUG_MB)
488 .procname = "debug_mb",
490 .proc_handler = &proc_debug_mb,
493 INIT_CTL_NAME(PSDEV_LNET_WATCHDOG_RATELIMIT)
494 .procname = "watchdog_ratelimit",
495 .data = &libcfs_watchdog_ratelimit,
496 .maxlen = sizeof(int),
498 .proc_handler = &proc_dointvec_minmax,
499 .extra1 = &min_watchdog_ratelimit,
500 .extra2 = &max_watchdog_ratelimit,
502 { INIT_CTL_NAME(PSDEV_LNET_FORCE_LBUG)
503 .procname = "force_lbug",
507 .proc_handler = &libcfs_force_lbug
510 INIT_CTL_NAME(PSDEV_LNET_FAIL_LOC)
511 .procname = "fail_loc",
512 .data = &cfs_fail_loc,
513 .maxlen = sizeof(cfs_fail_loc),
515 .proc_handler = &proc_fail_loc
518 INIT_CTL_NAME(PSDEV_LNET_FAIL_VAL)
519 .procname = "fail_val",
520 .data = &cfs_fail_val,
521 .maxlen = sizeof(int),
523 .proc_handler = &proc_dointvec
531 static cfs_sysctl_table_t top_table[] = {
533 INIT_CTL_NAME(CTL_LNET)
545 int insert_proc(void)
547 if (lnet_table_header == NULL)
548 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
553 void remove_proc(void)
556 if (lnet_table_header != NULL)
557 cfs_unregister_sysctl_table(lnet_table_header);
559 lnet_table_header = NULL;