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/list.h>
59 #include <linux/proc_fs.h>
60 #include <linux/sysctl.h>
62 # define DEBUG_SUBSYSTEM S_LNET
64 #include <linux/libcfs/libcfs.h>
65 #include <asm/div64.h>
66 #include "tracefile.h"
69 static ctl_table_header_t *lnet_table_header = NULL;
71 extern char lnet_upcall[1024];
73 * The path of debug log dump upcall script.
75 extern char lnet_debug_log_upcall[1024];
77 #define CTL_LNET (0x100)
79 PSDEV_DEBUG = 1, /* control debugging */
80 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
81 PSDEV_PRINTK, /* force all messages to console */
82 PSDEV_CONSOLE_RATELIMIT, /* ratelimit console messages */
83 PSDEV_CONSOLE_MAX_DELAY_CS, /* maximum delay over which we skip messages */
84 PSDEV_CONSOLE_MIN_DELAY_CS, /* initial delay over which we skip messages */
85 PSDEV_CONSOLE_BACKOFF, /* delay increase factor */
86 PSDEV_DEBUG_PATH, /* crashdump log location */
87 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
88 PSDEV_CPT_TABLE, /* information about cpu partitions */
89 PSDEV_LNET_UPCALL, /* User mode upcall script */
90 PSDEV_LNET_MEMUSED, /* bytes currently PORTAL_ALLOCated */
91 PSDEV_LNET_CATASTROPHE, /* if we have LBUGged or panic'd */
92 PSDEV_LNET_PANIC_ON_LBUG, /* flag to panic on LBUG */
93 PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */
94 PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */
95 PSDEV_LNET_DEBUG_MB, /* size of debug buffer */
96 PSDEV_LNET_DEBUG_LOG_UPCALL, /* debug log upcall script */
97 PSDEV_LNET_WATCHDOG_RATELIMIT, /* ratelimit watchdog messages */
98 PSDEV_LNET_FORCE_LBUG, /* hook to force an LBUG */
99 PSDEV_LNET_FAIL_LOC, /* control test failures instrumentation */
100 PSDEV_LNET_FAIL_VAL, /* userdata for fail loc */
104 proc_call_handler(void *data, int write,
105 loff_t *ppos, void *buffer, size_t *lenp,
106 int (*handler)(void *data, int write,
107 loff_t pos, void *buffer, int len))
109 int rc = handler(data, write, *ppos, buffer, *lenp);
122 EXPORT_SYMBOL(proc_call_handler);
124 static int __proc_dobitmasks(void *data, int write,
125 loff_t pos, void *buffer, int nob)
127 const int tmpstrlen = 512;
130 unsigned int *mask = data;
131 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
132 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
134 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
139 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
145 rc = cfs_trace_copyout_string(buffer, nob,
149 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
151 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
155 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
156 /* Always print LBUG/LASSERT to console, so keep this mask */
161 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
165 DECLARE_PROC_HANDLER(proc_dobitmasks)
167 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
168 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
170 static int __proc_dump_kernel(void *data, int write,
171 loff_t pos, void *buffer, int nob)
176 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
179 DECLARE_PROC_HANDLER(proc_dump_kernel)
181 static int __proc_daemon_file(void *data, int write,
182 loff_t pos, void *buffer, int nob)
185 int len = strlen(cfs_tracefile);
190 return cfs_trace_copyout_string(buffer, nob,
191 cfs_tracefile + pos, "\n");
194 return cfs_trace_daemon_command_usrstr(buffer, nob);
197 DECLARE_PROC_HANDLER(proc_daemon_file)
199 static int __proc_debug_mb(void *data, int write,
200 loff_t pos, void *buffer, int nob)
204 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
205 cfs_trace_get_debug_mb());
210 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
214 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
217 DECLARE_PROC_HANDLER(proc_debug_mb)
219 int LL_PROC_PROTO(proc_console_max_delay_cs)
221 int rc, max_delay_cs;
222 ctl_table_t dummy = *table;
225 dummy.data = &max_delay_cs;
226 dummy.proc_handler = &proc_dointvec;
228 if (!write) { /* read */
229 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
230 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
236 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
239 if (max_delay_cs <= 0)
242 d = cfs_time_seconds(max_delay_cs) / 100;
243 if (d == 0 || d < libcfs_console_min_delay)
245 libcfs_console_max_delay = d;
250 int LL_PROC_PROTO(proc_console_min_delay_cs)
252 int rc, min_delay_cs;
253 ctl_table_t dummy = *table;
256 dummy.data = &min_delay_cs;
257 dummy.proc_handler = &proc_dointvec;
259 if (!write) { /* read */
260 min_delay_cs = cfs_duration_sec(libcfs_console_min_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 (min_delay_cs <= 0)
273 d = cfs_time_seconds(min_delay_cs) / 100;
274 if (d == 0 || d > libcfs_console_max_delay)
276 libcfs_console_min_delay = d;
281 int LL_PROC_PROTO(proc_console_backoff)
284 ctl_table_t dummy = *table;
286 dummy.data = &backoff;
287 dummy.proc_handler = &proc_dointvec;
289 if (!write) { /* read */
290 backoff= libcfs_console_backoff;
291 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
297 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
303 libcfs_console_backoff = backoff;
308 int LL_PROC_PROTO(libcfs_force_lbug)
315 int LL_PROC_PROTO(proc_fail_loc)
318 long old_fail_loc = cfs_fail_loc;
320 rc = ll_proc_dolongvec(table, write, filp, buffer, lenp, ppos);
321 if (old_fail_loc != cfs_fail_loc)
322 wake_up(&cfs_race_waitq);
326 static int __proc_cpt_table(void *data, int write,
327 loff_t pos, void *buffer, int nob)
336 LASSERT(cfs_cpt_table != NULL);
339 LIBCFS_ALLOC(buf, len);
343 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
347 LIBCFS_FREE(buf, len);
360 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
363 LIBCFS_FREE(buf, len);
366 DECLARE_PROC_HANDLER(proc_cpt_table)
368 static ctl_table_t lnet_table[] = {
370 * NB No .strategy entries have been provided since sysctl(8) prefers
371 * to go via /proc for portability.
375 .data = &libcfs_debug,
376 .maxlen = sizeof(int),
378 .proc_handler = &proc_dobitmasks,
381 .procname = "subsystem_debug",
382 .data = &libcfs_subsystem_debug,
383 .maxlen = sizeof(int),
385 .proc_handler = &proc_dobitmasks,
388 .procname = "printk",
389 .data = &libcfs_printk,
390 .maxlen = sizeof(int),
392 .proc_handler = &proc_dobitmasks,
395 .procname = "console_ratelimit",
396 .data = &libcfs_console_ratelimit,
397 .maxlen = sizeof(int),
399 .proc_handler = &proc_dointvec
402 .procname = "console_max_delay_centisecs",
403 .maxlen = sizeof(int),
405 .proc_handler = &proc_console_max_delay_cs
408 .procname = "console_min_delay_centisecs",
409 .maxlen = sizeof(int),
411 .proc_handler = &proc_console_min_delay_cs
414 .procname = "console_backoff",
415 .maxlen = sizeof(int),
417 .proc_handler = &proc_console_backoff
421 .procname = "debug_path",
422 .data = libcfs_debug_file_path_arr,
423 .maxlen = sizeof(libcfs_debug_file_path_arr),
425 .proc_handler = &proc_dostring,
429 .procname = "cpu_partition_table",
432 .proc_handler = &proc_cpt_table,
436 .procname = "upcall",
438 .maxlen = sizeof(lnet_upcall),
440 .proc_handler = &proc_dostring,
443 .procname = "debug_log_upcall",
444 .data = lnet_debug_log_upcall,
445 .maxlen = sizeof(lnet_debug_log_upcall),
447 .proc_handler = &proc_dostring,
450 .procname = "lnet_memused",
451 .data = (int *)&libcfs_kmemory.counter,
452 .maxlen = sizeof(int),
454 .proc_handler = &proc_dointvec,
457 .procname = "catastrophe",
458 .data = &libcfs_catastrophe,
459 .maxlen = sizeof(int),
461 .proc_handler = &proc_dointvec,
464 .procname = "panic_on_lbug",
465 .data = &libcfs_panic_on_lbug,
466 .maxlen = sizeof(int),
468 .proc_handler = &proc_dointvec,
471 .procname = "dump_kernel",
474 .proc_handler = &proc_dump_kernel,
477 .procname = "daemon_file",
480 .proc_handler = &proc_daemon_file,
483 .procname = "debug_mb",
485 .proc_handler = &proc_debug_mb,
488 .procname = "watchdog_ratelimit",
489 .data = &libcfs_watchdog_ratelimit,
490 .maxlen = sizeof(int),
492 .proc_handler = &proc_dointvec_minmax,
493 .extra1 = &min_watchdog_ratelimit,
494 .extra2 = &max_watchdog_ratelimit,
497 .procname = "force_lbug",
501 .proc_handler = &libcfs_force_lbug
504 .procname = "fail_loc",
505 .data = &cfs_fail_loc,
506 .maxlen = sizeof(cfs_fail_loc),
508 .proc_handler = &proc_fail_loc
511 .procname = "fail_val",
512 .data = &cfs_fail_val,
513 .maxlen = sizeof(int),
515 .proc_handler = &proc_dointvec
522 static ctl_table_t top_table[] = {
535 int insert_proc(void)
538 if (lnet_table_header == NULL)
539 lnet_table_header = register_sysctl_table(top_table);
544 void remove_proc(void)
547 if (lnet_table_header != NULL)
548 unregister_sysctl_table(lnet_table_header);
550 lnet_table_header = NULL;