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 "../../../include/linux/libcfs/libcfs.h"
65 #include <asm/div64.h>
66 #include "../tracefile.h"
68 static struct ctl_table_header *lnet_table_header = NULL;
69 extern char lnet_upcall[1024];
71 * The path of debug log dump upcall script.
73 extern char lnet_debug_log_upcall[1024];
75 #define CTL_LNET (0x100)
77 PSDEV_DEBUG = 1, /* control debugging */
78 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
79 PSDEV_PRINTK, /* force all messages to console */
80 PSDEV_CONSOLE_RATELIMIT, /* ratelimit console messages */
81 PSDEV_CONSOLE_MAX_DELAY_CS, /* maximum delay over which we skip messages */
82 PSDEV_CONSOLE_MIN_DELAY_CS, /* initial delay over which we skip messages */
83 PSDEV_CONSOLE_BACKOFF, /* delay increase factor */
84 PSDEV_DEBUG_PATH, /* crashdump log location */
85 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
86 PSDEV_CPT_TABLE, /* information about cpu partitions */
87 PSDEV_LNET_UPCALL, /* User mode upcall script */
88 PSDEV_LNET_MEMUSED, /* bytes currently PORTAL_ALLOCated */
89 PSDEV_LNET_CATASTROPHE, /* if we have LBUGged or panic'd */
90 PSDEV_LNET_PANIC_ON_LBUG, /* flag to panic on LBUG */
91 PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */
92 PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */
93 PSDEV_LNET_DEBUG_MB, /* size of debug buffer */
94 PSDEV_LNET_DEBUG_LOG_UPCALL, /* debug log upcall script */
95 PSDEV_LNET_WATCHDOG_RATELIMIT, /* ratelimit watchdog messages */
96 PSDEV_LNET_FORCE_LBUG, /* hook to force an LBUG */
97 PSDEV_LNET_FAIL_LOC, /* control test failures instrumentation */
98 PSDEV_LNET_FAIL_VAL, /* userdata for fail loc */
101 static int proc_call_handler(void *data, int write, loff_t *ppos, void *buffer,
102 size_t *lenp, int (*handler)(void *data, int write,
103 loff_t pos, void *buffer, int len))
105 int rc = handler(data, write, *ppos, buffer, *lenp);
119 static int __proc_dobitmasks(void *data, int write,
120 loff_t pos, void *buffer, int nob)
122 const int tmpstrlen = 512;
125 unsigned int *mask = data;
126 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
127 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
129 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
134 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
140 rc = cfs_trace_copyout_string(buffer, nob,
144 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
146 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
150 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
151 /* Always print LBUG/LASSERT to console, so keep this mask */
156 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
160 static int proc_dobitmasks(struct ctl_table *table, int write,
161 void __user *buffer, size_t *lenp, loff_t *ppos)
163 return proc_call_handler(table->data, write, ppos, buffer, lenp,
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 static int proc_dump_kernel(struct ctl_table *table, int write,
180 void __user *buffer, size_t *lenp, loff_t *ppos)
182 return proc_call_handler(table->data, write, ppos, buffer, lenp,
186 static int __proc_daemon_file(void *data, int write,
187 loff_t pos, void *buffer, int nob)
190 int len = strlen(cfs_tracefile);
195 return cfs_trace_copyout_string(buffer, nob,
196 cfs_tracefile + pos, "\n");
199 return cfs_trace_daemon_command_usrstr(buffer, nob);
202 static int proc_daemon_file(struct ctl_table *table, int write,
203 void __user *buffer, size_t *lenp, loff_t *ppos)
205 return proc_call_handler(table->data, write, ppos, buffer, lenp,
209 static int __proc_debug_mb(void *data, int write,
210 loff_t pos, void *buffer, int nob)
214 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
215 cfs_trace_get_debug_mb());
220 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
224 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
227 static int proc_debug_mb(struct ctl_table *table, int write,
228 void __user *buffer, size_t *lenp, loff_t *ppos)
230 return proc_call_handler(table->data, write, ppos, buffer, lenp,
234 int proc_console_max_delay_cs(struct ctl_table *table, int write,
235 void __user *buffer, size_t *lenp, loff_t *ppos)
237 int rc, max_delay_cs;
238 struct ctl_table dummy = *table;
241 dummy.data = &max_delay_cs;
242 dummy.proc_handler = &proc_dointvec;
244 if (!write) { /* read */
245 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
246 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
252 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
255 if (max_delay_cs <= 0)
258 d = cfs_time_seconds(max_delay_cs) / 100;
259 if (d == 0 || d < libcfs_console_min_delay)
261 libcfs_console_max_delay = d;
266 int proc_console_min_delay_cs(struct ctl_table *table, int write,
267 void __user *buffer, size_t *lenp, loff_t *ppos)
269 int rc, min_delay_cs;
270 struct ctl_table dummy = *table;
273 dummy.data = &min_delay_cs;
274 dummy.proc_handler = &proc_dointvec;
276 if (!write) { /* read */
277 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
278 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
284 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
287 if (min_delay_cs <= 0)
290 d = cfs_time_seconds(min_delay_cs) / 100;
291 if (d == 0 || d > libcfs_console_max_delay)
293 libcfs_console_min_delay = d;
298 int proc_console_backoff(struct ctl_table *table, int write,
299 void __user *buffer, size_t *lenp, loff_t *ppos)
302 struct ctl_table dummy = *table;
304 dummy.data = &backoff;
305 dummy.proc_handler = &proc_dointvec;
307 if (!write) { /* read */
308 backoff= libcfs_console_backoff;
309 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
315 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
321 libcfs_console_backoff = backoff;
326 int libcfs_force_lbug(struct ctl_table *table, int write, void __user *buffer,
327 size_t *lenp, loff_t *ppos)
334 int proc_fail_loc(struct ctl_table *table, int write, void __user *buffer,
335 size_t *lenp, loff_t *ppos)
338 long old_fail_loc = cfs_fail_loc;
340 rc = ll_proc_dolongvec(table, write, filp, buffer, lenp, ppos);
341 if (old_fail_loc != cfs_fail_loc)
342 wake_up(&cfs_race_waitq);
346 static int __proc_cpt_table(void *data, int write,
347 loff_t pos, void *buffer, int nob)
356 LASSERT(cfs_cpt_table != NULL);
359 LIBCFS_ALLOC(buf, len);
363 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
367 LIBCFS_FREE(buf, len);
380 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
383 LIBCFS_FREE(buf, len);
387 static int proc_cpt_table(struct ctl_table *table, int write,
388 void __user *buffer, size_t *lenp, loff_t *ppos)
390 return proc_call_handler(table->data, write, ppos, buffer, lenp,
394 static struct ctl_table lnet_table[] = {
396 * NB No .strategy entries have been provided since sysctl(8) prefers
397 * to go via /proc for portability.
401 .data = &libcfs_debug,
402 .maxlen = sizeof(int),
404 .proc_handler = &proc_dobitmasks,
407 .procname = "subsystem_debug",
408 .data = &libcfs_subsystem_debug,
409 .maxlen = sizeof(int),
411 .proc_handler = &proc_dobitmasks,
414 .procname = "printk",
415 .data = &libcfs_printk,
416 .maxlen = sizeof(int),
418 .proc_handler = &proc_dobitmasks,
421 .procname = "console_ratelimit",
422 .data = &libcfs_console_ratelimit,
423 .maxlen = sizeof(int),
425 .proc_handler = &proc_dointvec
428 .procname = "console_max_delay_centisecs",
429 .maxlen = sizeof(int),
431 .proc_handler = &proc_console_max_delay_cs
434 .procname = "console_min_delay_centisecs",
435 .maxlen = sizeof(int),
437 .proc_handler = &proc_console_min_delay_cs
440 .procname = "console_backoff",
441 .maxlen = sizeof(int),
443 .proc_handler = &proc_console_backoff
447 .procname = "debug_path",
448 .data = libcfs_debug_file_path_arr,
449 .maxlen = sizeof(libcfs_debug_file_path_arr),
451 .proc_handler = &proc_dostring,
455 .procname = "cpu_partition_table",
458 .proc_handler = &proc_cpt_table,
462 .procname = "upcall",
464 .maxlen = sizeof(lnet_upcall),
466 .proc_handler = &proc_dostring,
469 .procname = "debug_log_upcall",
470 .data = lnet_debug_log_upcall,
471 .maxlen = sizeof(lnet_debug_log_upcall),
473 .proc_handler = &proc_dostring,
476 .procname = "lnet_memused",
477 .data = (int *)&libcfs_kmemory.counter,
478 .maxlen = sizeof(int),
480 .proc_handler = &proc_dointvec,
483 .procname = "catastrophe",
484 .data = &libcfs_catastrophe,
485 .maxlen = sizeof(int),
487 .proc_handler = &proc_dointvec,
490 .procname = "panic_on_lbug",
491 .data = &libcfs_panic_on_lbug,
492 .maxlen = sizeof(int),
494 .proc_handler = &proc_dointvec,
497 .procname = "dump_kernel",
500 .proc_handler = &proc_dump_kernel,
503 .procname = "daemon_file",
506 .proc_handler = &proc_daemon_file,
509 .procname = "debug_mb",
511 .proc_handler = &proc_debug_mb,
514 .procname = "watchdog_ratelimit",
515 .data = &libcfs_watchdog_ratelimit,
516 .maxlen = sizeof(int),
518 .proc_handler = &proc_dointvec_minmax,
519 .extra1 = &min_watchdog_ratelimit,
520 .extra2 = &max_watchdog_ratelimit,
523 .procname = "force_lbug",
527 .proc_handler = &libcfs_force_lbug
530 .procname = "fail_loc",
531 .data = &cfs_fail_loc,
532 .maxlen = sizeof(cfs_fail_loc),
534 .proc_handler = &proc_fail_loc
537 .procname = "fail_val",
538 .data = &cfs_fail_val,
539 .maxlen = sizeof(int),
541 .proc_handler = &proc_dointvec
547 static struct ctl_table top_table[] = {
559 int insert_proc(void)
561 if (lnet_table_header == NULL)
562 lnet_table_header = register_sysctl_table(top_table);
566 void remove_proc(void)
568 if (lnet_table_header != NULL)
569 unregister_sysctl_table(lnet_table_header);
571 lnet_table_header = NULL;