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, Whamcloud, Inc.
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 #ifndef AUTOCONF_INCLUDED
44 #include <linux/config.h>
46 #include <linux/module.h>
47 #include <linux/kernel.h>
49 #include <linux/string.h>
50 #include <linux/stat.h>
51 #include <linux/errno.h>
52 #include <linux/smp_lock.h>
53 #include <linux/unistd.h>
55 #include <linux/uio.h>
57 #include <asm/system.h>
58 #include <asm/uaccess.h>
61 #include <linux/file.h>
62 #include <linux/stat.h>
63 #include <linux/list.h>
64 #include <asm/uaccess.h>
66 #include <linux/proc_fs.h>
67 #include <linux/sysctl.h>
69 # define DEBUG_SUBSYSTEM S_LNET
71 #include <libcfs/libcfs.h>
72 #include <asm/div64.h>
73 #include "tracefile.h"
76 static cfs_sysctl_table_header_t *lnet_table_header = NULL;
78 extern char lnet_upcall[1024];
80 * The path of debug log dump upcall script.
82 extern char lnet_debug_log_upcall[1024];
84 #ifndef HAVE_SYSCTL_UNNUMBERED
85 #define CTL_LNET (0x100)
87 PSDEV_DEBUG = 1, /* control debugging */
88 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
89 PSDEV_PRINTK, /* force all messages to console */
90 PSDEV_CONSOLE_RATELIMIT, /* ratelimit console messages */
91 PSDEV_CONSOLE_MAX_DELAY_CS, /* maximum delay over which we skip messages */
92 PSDEV_CONSOLE_MIN_DELAY_CS, /* initial delay over which we skip messages */
93 PSDEV_CONSOLE_BACKOFF, /* delay increase factor */
94 PSDEV_DEBUG_PATH, /* crashdump log location */
95 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
96 PSDEV_CPT_TABLE, /* information about cpu partitions */
97 PSDEV_LNET_UPCALL, /* User mode upcall script */
98 PSDEV_LNET_MEMUSED, /* bytes currently PORTAL_ALLOCated */
99 PSDEV_LNET_CATASTROPHE, /* if we have LBUGged or panic'd */
100 PSDEV_LNET_PANIC_ON_LBUG, /* flag to panic on LBUG */
101 PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */
102 PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */
103 PSDEV_LNET_DEBUG_MB, /* size of debug buffer */
104 PSDEV_LNET_DEBUG_LOG_UPCALL, /* debug log upcall script */
105 PSDEV_LNET_WATCHDOG_RATELIMIT, /* ratelimit watchdog messages */
106 PSDEV_LNET_FORCE_LBUG, /* hook to force an LBUG */
107 PSDEV_LNET_FAIL_LOC, /* control test failures instrumentation */
108 PSDEV_LNET_FAIL_VAL, /* userdata for fail loc */
111 #define CTL_LNET CTL_UNNUMBERED
112 #define PSDEV_DEBUG CTL_UNNUMBERED
113 #define PSDEV_SUBSYSTEM_DEBUG CTL_UNNUMBERED
114 #define PSDEV_PRINTK CTL_UNNUMBERED
115 #define PSDEV_CONSOLE_RATELIMIT CTL_UNNUMBERED
116 #define PSDEV_CONSOLE_MAX_DELAY_CS CTL_UNNUMBERED
117 #define PSDEV_CONSOLE_MIN_DELAY_CS CTL_UNNUMBERED
118 #define PSDEV_CONSOLE_BACKOFF CTL_UNNUMBERED
119 #define PSDEV_DEBUG_PATH CTL_UNNUMBERED
120 #define PSDEV_DEBUG_DUMP_PATH CTL_UNNUMBERED
121 #define PSDEV_CPT_TABLE CTL_UNNUMBERED
122 #define PSDEV_LNET_UPCALL CTL_UNNUMBERED
123 #define PSDEV_LNET_MEMUSED CTL_UNNUMBERED
124 #define PSDEV_LNET_CATASTROPHE CTL_UNNUMBERED
125 #define PSDEV_LNET_PANIC_ON_LBUG CTL_UNNUMBERED
126 #define PSDEV_LNET_DUMP_KERNEL CTL_UNNUMBERED
127 #define PSDEV_LNET_DAEMON_FILE CTL_UNNUMBERED
128 #define PSDEV_LNET_DEBUG_MB CTL_UNNUMBERED
129 #define PSDEV_LNET_DEBUG_LOG_UPCALL CTL_UNNUMBERED
130 #define PSDEV_LNET_WATCHDOG_RATELIMIT CTL_UNNUMBERED
131 #define PSDEV_LNET_FORCE_LBUG CTL_UNNUMBERED
132 #define PSDEV_LNET_FAIL_LOC CTL_UNNUMBERED
133 #define PSDEV_LNET_FAIL_VAL CTL_UNNUMBERED
137 proc_call_handler(void *data, int write,
138 loff_t *ppos, void *buffer, size_t *lenp,
139 int (*handler)(void *data, int write,
140 loff_t pos, void *buffer, int len))
142 int rc = handler(data, write, *ppos, buffer, *lenp);
155 EXPORT_SYMBOL(proc_call_handler);
157 static int __proc_dobitmasks(void *data, int write,
158 loff_t pos, void *buffer, int nob)
160 const int tmpstrlen = 512;
163 unsigned int *mask = data;
164 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
165 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
167 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
172 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
178 rc = cfs_trace_copyout_string(buffer, nob,
182 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
186 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
187 /* Always print LBUG/LASSERT to console, so keep this mask */
192 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
196 DECLARE_PROC_HANDLER(proc_dobitmasks)
198 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
199 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
201 static int __proc_dump_kernel(void *data, int write,
202 loff_t pos, void *buffer, int nob)
207 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
210 DECLARE_PROC_HANDLER(proc_dump_kernel)
212 static int __proc_daemon_file(void *data, int write,
213 loff_t pos, void *buffer, int nob)
216 int len = strlen(cfs_tracefile);
221 return cfs_trace_copyout_string(buffer, nob,
222 cfs_tracefile + pos, "\n");
225 return cfs_trace_daemon_command_usrstr(buffer, nob);
228 DECLARE_PROC_HANDLER(proc_daemon_file)
230 static int __proc_debug_mb(void *data, int write,
231 loff_t pos, void *buffer, int nob)
235 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
236 cfs_trace_get_debug_mb());
241 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
245 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
248 DECLARE_PROC_HANDLER(proc_debug_mb)
250 int LL_PROC_PROTO(proc_console_max_delay_cs)
252 int rc, max_delay_cs;
253 cfs_sysctl_table_t dummy = *table;
256 dummy.data = &max_delay_cs;
257 dummy.proc_handler = &proc_dointvec;
259 if (!write) { /* read */
260 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
261 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
267 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
270 if (max_delay_cs <= 0)
273 d = cfs_time_seconds(max_delay_cs) / 100;
274 if (d == 0 || d < libcfs_console_min_delay)
276 libcfs_console_max_delay = d;
281 int LL_PROC_PROTO(proc_console_min_delay_cs)
283 int rc, min_delay_cs;
284 cfs_sysctl_table_t dummy = *table;
287 dummy.data = &min_delay_cs;
288 dummy.proc_handler = &proc_dointvec;
290 if (!write) { /* read */
291 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
292 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
298 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
301 if (min_delay_cs <= 0)
304 d = cfs_time_seconds(min_delay_cs) / 100;
305 if (d == 0 || d > libcfs_console_max_delay)
307 libcfs_console_min_delay = d;
312 int LL_PROC_PROTO(proc_console_backoff)
315 cfs_sysctl_table_t dummy = *table;
317 dummy.data = &backoff;
318 dummy.proc_handler = &proc_dointvec;
320 if (!write) { /* read */
321 backoff= libcfs_console_backoff;
322 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
328 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
334 libcfs_console_backoff = backoff;
339 int LL_PROC_PROTO(libcfs_force_lbug)
346 int LL_PROC_PROTO(proc_fail_loc)
349 long old_fail_loc = cfs_fail_loc;
351 rc = ll_proc_dolongvec(table, write, filp, buffer, lenp, ppos);
352 if (old_fail_loc != cfs_fail_loc)
353 cfs_waitq_signal(&cfs_race_waitq);
357 static int __proc_cpt_table(void *data, int write,
358 loff_t pos, void *buffer, int nob)
367 LASSERT(cfs_cpt_table != NULL);
370 LIBCFS_ALLOC(buf, len);
374 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
378 LIBCFS_FREE(buf, len);
391 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
394 LIBCFS_FREE(buf, len);
397 DECLARE_PROC_HANDLER(proc_cpt_table)
399 static cfs_sysctl_table_t lnet_table[] = {
401 * NB No .strategy entries have been provided since sysctl(8) prefers
402 * to go via /proc for portability.
405 INIT_CTL_NAME(PSDEV_DEBUG)
407 .data = &libcfs_debug,
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_dobitmasks,
413 INIT_CTL_NAME(PSDEV_SUBSYSTEM_DEBUG)
414 .procname = "subsystem_debug",
415 .data = &libcfs_subsystem_debug,
416 .maxlen = sizeof(int),
418 .proc_handler = &proc_dobitmasks,
421 INIT_CTL_NAME(PSDEV_PRINTK)
422 .procname = "printk",
423 .data = &libcfs_printk,
424 .maxlen = sizeof(int),
426 .proc_handler = &proc_dobitmasks,
429 INIT_CTL_NAME(PSDEV_CONSOLE_RATELIMIT)
430 .procname = "console_ratelimit",
431 .data = &libcfs_console_ratelimit,
432 .maxlen = sizeof(int),
434 .proc_handler = &proc_dointvec
437 INIT_CTL_NAME(PSDEV_CONSOLE_MAX_DELAY_CS)
438 .procname = "console_max_delay_centisecs",
439 .maxlen = sizeof(int),
441 .proc_handler = &proc_console_max_delay_cs
444 INIT_CTL_NAME(PSDEV_CONSOLE_MIN_DELAY_CS)
445 .procname = "console_min_delay_centisecs",
446 .maxlen = sizeof(int),
448 .proc_handler = &proc_console_min_delay_cs
451 INIT_CTL_NAME(PSDEV_CONSOLE_BACKOFF)
452 .procname = "console_backoff",
453 .maxlen = sizeof(int),
455 .proc_handler = &proc_console_backoff
459 INIT_CTL_NAME(PSDEV_DEBUG_PATH)
460 .procname = "debug_path",
461 .data = libcfs_debug_file_path_arr,
462 .maxlen = sizeof(libcfs_debug_file_path_arr),
464 .proc_handler = &proc_dostring,
468 .ctl_name = PSDEV_CPT_TABLE,
469 .procname = "cpu_partition_table",
472 .proc_handler = &proc_cpt_table,
476 INIT_CTL_NAME(PSDEV_LNET_UPCALL)
477 .procname = "upcall",
479 .maxlen = sizeof(lnet_upcall),
481 .proc_handler = &proc_dostring,
484 INIT_CTL_NAME(PSDEV_LNET_DEBUG_LOG_UPCALL)
485 .procname = "debug_log_upcall",
486 .data = lnet_debug_log_upcall,
487 .maxlen = sizeof(lnet_debug_log_upcall),
489 .proc_handler = &proc_dostring,
492 INIT_CTL_NAME(PSDEV_LNET_MEMUSED)
493 .procname = "lnet_memused",
494 .data = (int *)&libcfs_kmemory.counter,
495 .maxlen = sizeof(int),
497 .proc_handler = &proc_dointvec,
498 INIT_STRATEGY(&sysctl_intvec)
501 INIT_CTL_NAME(PSDEV_LNET_CATASTROPHE)
502 .procname = "catastrophe",
503 .data = &libcfs_catastrophe,
504 .maxlen = sizeof(int),
506 .proc_handler = &proc_dointvec,
507 INIT_STRATEGY(&sysctl_intvec)
510 INIT_CTL_NAME(PSDEV_LNET_PANIC_ON_LBUG)
511 .procname = "panic_on_lbug",
512 .data = &libcfs_panic_on_lbug,
513 .maxlen = sizeof(int),
515 .proc_handler = &proc_dointvec,
516 INIT_STRATEGY(&sysctl_intvec)
519 INIT_CTL_NAME(PSDEV_LNET_DUMP_KERNEL)
520 .procname = "dump_kernel",
523 .proc_handler = &proc_dump_kernel,
526 INIT_CTL_NAME(PSDEV_LNET_DAEMON_FILE)
527 .procname = "daemon_file",
530 .proc_handler = &proc_daemon_file,
533 INIT_CTL_NAME(PSDEV_LNET_DEBUG_MB)
534 .procname = "debug_mb",
536 .proc_handler = &proc_debug_mb,
539 INIT_CTL_NAME(PSDEV_LNET_WATCHDOG_RATELIMIT)
540 .procname = "watchdog_ratelimit",
541 .data = &libcfs_watchdog_ratelimit,
542 .maxlen = sizeof(int),
544 .proc_handler = &proc_dointvec_minmax,
545 .extra1 = &min_watchdog_ratelimit,
546 .extra2 = &max_watchdog_ratelimit,
548 { INIT_CTL_NAME(PSDEV_LNET_FORCE_LBUG)
549 .procname = "force_lbug",
553 .proc_handler = &libcfs_force_lbug
556 INIT_CTL_NAME(PSDEV_LNET_FAIL_LOC)
557 .procname = "fail_loc",
558 .data = &cfs_fail_loc,
559 .maxlen = sizeof(cfs_fail_loc),
561 .proc_handler = &proc_fail_loc
564 INIT_CTL_NAME(PSDEV_LNET_FAIL_VAL)
565 .procname = "fail_val",
566 .data = &cfs_fail_val,
567 .maxlen = sizeof(int),
569 .proc_handler = &proc_dointvec
577 static cfs_sysctl_table_t top_table[] = {
579 INIT_CTL_NAME(CTL_LNET)
591 int insert_proc(void)
593 if (lnet_table_header == NULL)
594 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
599 void remove_proc(void)
602 if (lnet_table_header != NULL)
603 cfs_unregister_sysctl_table(lnet_table_header);
605 lnet_table_header = NULL;