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 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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>
44 # define EXPORT_SYMTAB
47 #ifndef AUTOCONF_INCLUDED
48 #include <linux/config.h>
50 #include <linux/module.h>
51 #include <linux/kernel.h>
53 #include <linux/string.h>
54 #include <linux/stat.h>
55 #include <linux/errno.h>
56 #include <linux/smp_lock.h>
57 #include <linux/unistd.h>
59 #include <linux/uio.h>
61 #include <asm/system.h>
62 #include <asm/uaccess.h>
65 #include <linux/file.h>
66 #include <linux/stat.h>
67 #include <linux/list.h>
68 #include <asm/uaccess.h>
70 #include <linux/proc_fs.h>
71 #include <linux/sysctl.h>
73 # define DEBUG_SUBSYSTEM S_LNET
75 #include <libcfs/libcfs.h>
76 #include <asm/div64.h>
77 #include "tracefile.h"
79 static cfs_sysctl_table_header_t *lnet_table_header = NULL;
80 extern char lnet_upcall[1024];
82 * The path of debug log dump upcall script.
84 extern char lnet_debug_log_upcall[1024];
86 #ifndef HAVE_SYSCTL_UNNUMBERED
87 #define CTL_LNET (0x100)
89 PSDEV_DEBUG = 1, /* control debugging */
90 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
91 PSDEV_PRINTK, /* force all messages to console */
92 PSDEV_CONSOLE_RATELIMIT, /* ratelimit console messages */
93 PSDEV_CONSOLE_MAX_DELAY_CS, /* maximum delay over which we skip messages */
94 PSDEV_CONSOLE_MIN_DELAY_CS, /* initial delay over which we skip messages */
95 PSDEV_CONSOLE_BACKOFF, /* delay increase factor */
96 PSDEV_DEBUG_PATH, /* crashdump log location */
97 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
98 PSDEV_LNET_UPCALL, /* User mode upcall script */
99 PSDEV_LNET_MEMUSED, /* bytes currently PORTAL_ALLOCated */
100 PSDEV_LNET_CATASTROPHE, /* if we have LBUGged or panic'd */
101 PSDEV_LNET_PANIC_ON_LBUG, /* flag to panic on LBUG */
102 PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */
103 PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */
104 PSDEV_LNET_DEBUG_MB, /* size of debug buffer */
105 PSDEV_LNET_DEBUG_LOG_UPCALL, /* debug log upcall script */
106 PSDEV_LNET_WATCHDOG_RATELIMIT, /* ratelimit watchdog messages */
107 PSDEV_LNET_FORCE_LBUG, /* hook to force an LBUG */
110 #define CTL_LNET CTL_UNNUMBERED
111 #define PSDEV_DEBUG CTL_UNNUMBERED
112 #define PSDEV_SUBSYSTEM_DEBUG CTL_UNNUMBERED
113 #define PSDEV_PRINTK CTL_UNNUMBERED
114 #define PSDEV_CONSOLE_RATELIMIT CTL_UNNUMBERED
115 #define PSDEV_CONSOLE_MAX_DELAY_CS CTL_UNNUMBERED
116 #define PSDEV_CONSOLE_MIN_DELAY_CS CTL_UNNUMBERED
117 #define PSDEV_CONSOLE_BACKOFF CTL_UNNUMBERED
118 #define PSDEV_DEBUG_PATH CTL_UNNUMBERED
119 #define PSDEV_DEBUG_DUMP_PATH CTL_UNNUMBERED
120 #define PSDEV_LNET_UPCALL CTL_UNNUMBERED
121 #define PSDEV_LNET_MEMUSED CTL_UNNUMBERED
122 #define PSDEV_LNET_CATASTROPHE CTL_UNNUMBERED
123 #define PSDEV_LNET_PANIC_ON_LBUG CTL_UNNUMBERED
124 #define PSDEV_LNET_DUMP_KERNEL CTL_UNNUMBERED
125 #define PSDEV_LNET_DAEMON_FILE CTL_UNNUMBERED
126 #define PSDEV_LNET_DEBUG_MB CTL_UNNUMBERED
127 #define PSDEV_LNET_DEBUG_LOG_UPCALL CTL_UNNUMBERED
128 #define PSDEV_LNET_WATCHDOG_RATELIMIT CTL_UNNUMBERED
133 proc_call_handler(void *data, int write,
134 loff_t *ppos, void *buffer, size_t *lenp,
135 int (*handler)(void *data, int write,
136 loff_t pos, void *buffer, int len))
138 int rc = handler(data, write, *ppos, buffer, *lenp);
151 EXPORT_SYMBOL(proc_call_handler);
153 static int __proc_dobitmasks(void *data, int write,
154 loff_t pos, void *buffer, int nob)
156 const int tmpstrlen = 512;
159 unsigned int *mask = data;
160 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
161 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
163 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
168 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
174 rc = cfs_trace_copyout_string(buffer, nob,
178 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
182 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
183 /* Always print LBUG/LASSERT to console, so keep this mask */
188 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
192 DECLARE_PROC_HANDLER(proc_dobitmasks)
194 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
195 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
197 static int __proc_dump_kernel(void *data, int write,
198 loff_t pos, void *buffer, int nob)
203 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
206 DECLARE_PROC_HANDLER(proc_dump_kernel)
208 static int __proc_daemon_file(void *data, int write,
209 loff_t pos, void *buffer, int nob)
212 int len = strlen(cfs_tracefile);
217 return cfs_trace_copyout_string(buffer, nob,
218 cfs_tracefile + pos, "\n");
221 return cfs_trace_daemon_command_usrstr(buffer, nob);
224 DECLARE_PROC_HANDLER(proc_daemon_file)
226 static int __proc_debug_mb(void *data, int write,
227 loff_t pos, void *buffer, int nob)
231 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
232 cfs_trace_get_debug_mb());
237 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
241 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
244 DECLARE_PROC_HANDLER(proc_debug_mb)
246 int LL_PROC_PROTO(proc_console_max_delay_cs)
248 int rc, max_delay_cs;
249 cfs_sysctl_table_t dummy = *table;
252 dummy.data = &max_delay_cs;
253 dummy.proc_handler = &proc_dointvec;
255 if (!write) { /* read */
256 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
257 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
263 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
266 if (max_delay_cs <= 0)
269 d = cfs_time_seconds(max_delay_cs) / 100;
270 if (d == 0 || d < libcfs_console_min_delay)
272 libcfs_console_max_delay = d;
277 int LL_PROC_PROTO(proc_console_min_delay_cs)
279 int rc, min_delay_cs;
280 cfs_sysctl_table_t dummy = *table;
283 dummy.data = &min_delay_cs;
284 dummy.proc_handler = &proc_dointvec;
286 if (!write) { /* read */
287 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
288 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
294 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
297 if (min_delay_cs <= 0)
300 d = cfs_time_seconds(min_delay_cs) / 100;
301 if (d == 0 || d > libcfs_console_max_delay)
303 libcfs_console_min_delay = d;
308 int LL_PROC_PROTO(proc_console_backoff)
311 cfs_sysctl_table_t dummy = *table;
313 dummy.data = &backoff;
314 dummy.proc_handler = &proc_dointvec;
316 if (!write) { /* read */
317 backoff= libcfs_console_backoff;
318 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
324 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
330 libcfs_console_backoff = backoff;
335 int LL_PROC_PROTO(libcfs_force_lbug)
342 static cfs_sysctl_table_t lnet_table[] = {
344 * NB No .strategy entries have been provided since sysctl(8) prefers
345 * to go via /proc for portability.
348 .ctl_name = PSDEV_DEBUG,
350 .data = &libcfs_debug,
351 .maxlen = sizeof(int),
353 .proc_handler = &proc_dobitmasks,
356 .ctl_name = PSDEV_SUBSYSTEM_DEBUG,
357 .procname = "subsystem_debug",
358 .data = &libcfs_subsystem_debug,
359 .maxlen = sizeof(int),
361 .proc_handler = &proc_dobitmasks,
364 .ctl_name = PSDEV_PRINTK,
365 .procname = "printk",
366 .data = &libcfs_printk,
367 .maxlen = sizeof(int),
369 .proc_handler = &proc_dobitmasks,
372 .ctl_name = PSDEV_CONSOLE_RATELIMIT,
373 .procname = "console_ratelimit",
374 .data = &libcfs_console_ratelimit,
375 .maxlen = sizeof(int),
377 .proc_handler = &proc_dointvec
380 .ctl_name = PSDEV_CONSOLE_MAX_DELAY_CS,
381 .procname = "console_max_delay_centisecs",
382 .maxlen = sizeof(int),
384 .proc_handler = &proc_console_max_delay_cs
387 .ctl_name = PSDEV_CONSOLE_MIN_DELAY_CS,
388 .procname = "console_min_delay_centisecs",
389 .maxlen = sizeof(int),
391 .proc_handler = &proc_console_min_delay_cs
394 .ctl_name = PSDEV_CONSOLE_BACKOFF,
395 .procname = "console_backoff",
396 .maxlen = sizeof(int),
398 .proc_handler = &proc_console_backoff
402 .ctl_name = PSDEV_DEBUG_PATH,
403 .procname = "debug_path",
404 .data = libcfs_debug_file_path_arr,
405 .maxlen = sizeof(libcfs_debug_file_path_arr),
407 .proc_handler = &proc_dostring,
411 .ctl_name = PSDEV_LNET_UPCALL,
412 .procname = "upcall",
414 .maxlen = sizeof(lnet_upcall),
416 .proc_handler = &proc_dostring,
419 .ctl_name = PSDEV_LNET_DEBUG_LOG_UPCALL,
420 .procname = "debug_log_upcall",
421 .data = lnet_debug_log_upcall,
422 .maxlen = sizeof(lnet_debug_log_upcall),
424 .proc_handler = &proc_dostring,
427 .ctl_name = PSDEV_LNET_MEMUSED,
428 .procname = "memused",
429 .data = (int *)&libcfs_kmemory.counter,
430 .maxlen = sizeof(int),
432 .proc_handler = &proc_dointvec,
433 .strategy = &sysctl_intvec,
436 .ctl_name = PSDEV_LNET_CATASTROPHE,
437 .procname = "catastrophe",
438 .data = &libcfs_catastrophe,
439 .maxlen = sizeof(int),
441 .proc_handler = &proc_dointvec,
442 .strategy = &sysctl_intvec,
445 .ctl_name = PSDEV_LNET_PANIC_ON_LBUG,
446 .procname = "panic_on_lbug",
447 .data = &libcfs_panic_on_lbug,
448 .maxlen = sizeof(int),
450 .proc_handler = &proc_dointvec,
451 .strategy = &sysctl_intvec,
454 .ctl_name = PSDEV_LNET_DUMP_KERNEL,
455 .procname = "dump_kernel",
458 .proc_handler = &proc_dump_kernel,
461 .ctl_name = PSDEV_LNET_DAEMON_FILE,
462 .procname = "daemon_file",
465 .proc_handler = &proc_daemon_file,
468 .ctl_name = PSDEV_LNET_DEBUG_MB,
469 .procname = "debug_mb",
471 .proc_handler = &proc_debug_mb,
474 .ctl_name = PSDEV_LNET_WATCHDOG_RATELIMIT,
475 .procname = "watchdog_ratelimit",
476 .data = &libcfs_watchdog_ratelimit,
477 .maxlen = sizeof(int),
479 .proc_handler = &proc_dointvec_minmax,
480 .extra1 = &min_watchdog_ratelimit,
481 .extra2 = &max_watchdog_ratelimit,
483 { .ctl_name = PSDEV_LNET_FORCE_LBUG,
484 .procname = "force_lbug",
488 .proc_handler = &libcfs_force_lbug
493 static cfs_sysctl_table_t top_table[] = {
495 .ctl_name = CTL_LNET,
507 int insert_proc(void)
510 if (lnet_table_header == NULL)
511 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
516 void remove_proc(void)
519 if (lnet_table_header != NULL)
520 cfs_unregister_sysctl_table(lnet_table_header);
522 lnet_table_header = NULL;