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,
102 void __user *buffer, size_t *lenp,
103 int (*handler)(void *data, int write,
104 loff_t pos, void __user *buffer, int len))
106 int rc = handler(data, write, *ppos, buffer, *lenp);
120 static int __proc_dobitmasks(void *data, int write,
121 loff_t pos, void __user *buffer, int nob)
123 const int tmpstrlen = 512;
126 unsigned int *mask = data;
127 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
128 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
130 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
135 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
141 rc = cfs_trace_copyout_string(buffer, nob,
145 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
147 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
151 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
152 /* Always print LBUG/LASSERT to console, so keep this mask */
157 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
161 static int proc_dobitmasks(struct ctl_table *table, int write,
162 void __user *buffer, size_t *lenp, loff_t *ppos)
164 return proc_call_handler(table->data, write, ppos, buffer, lenp,
168 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
169 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
171 static int __proc_dump_kernel(void *data, int write,
172 loff_t pos, void __user *buffer, int nob)
177 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
180 static int proc_dump_kernel(struct ctl_table *table, int write,
181 void __user *buffer, size_t *lenp, loff_t *ppos)
183 return proc_call_handler(table->data, write, ppos, buffer, lenp,
187 static int __proc_daemon_file(void *data, int write,
188 loff_t pos, void __user *buffer, int nob)
191 int len = strlen(cfs_tracefile);
196 return cfs_trace_copyout_string(buffer, nob,
197 cfs_tracefile + pos, "\n");
200 return cfs_trace_daemon_command_usrstr(buffer, nob);
203 static int proc_daemon_file(struct ctl_table *table, int write,
204 void __user *buffer, size_t *lenp, loff_t *ppos)
206 return proc_call_handler(table->data, write, ppos, buffer, lenp,
210 static int __proc_debug_mb(void *data, int write,
211 loff_t pos, void __user *buffer, int nob)
215 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
216 cfs_trace_get_debug_mb());
221 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
225 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
228 static int proc_debug_mb(struct ctl_table *table, int write,
229 void __user *buffer, size_t *lenp, loff_t *ppos)
231 return proc_call_handler(table->data, write, ppos, buffer, lenp,
235 static int proc_console_max_delay_cs(struct ctl_table *table, int write,
236 void __user *buffer, size_t *lenp,
239 int rc, max_delay_cs;
240 struct ctl_table dummy = *table;
243 dummy.data = &max_delay_cs;
244 dummy.proc_handler = &proc_dointvec;
246 if (!write) { /* read */
247 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
248 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
254 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
257 if (max_delay_cs <= 0)
260 d = cfs_time_seconds(max_delay_cs) / 100;
261 if (d == 0 || d < libcfs_console_min_delay)
263 libcfs_console_max_delay = d;
268 static int proc_console_min_delay_cs(struct ctl_table *table, int write,
269 void __user *buffer, size_t *lenp,
272 int rc, min_delay_cs;
273 struct ctl_table dummy = *table;
276 dummy.data = &min_delay_cs;
277 dummy.proc_handler = &proc_dointvec;
279 if (!write) { /* read */
280 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
281 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
287 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
290 if (min_delay_cs <= 0)
293 d = cfs_time_seconds(min_delay_cs) / 100;
294 if (d == 0 || d > libcfs_console_max_delay)
296 libcfs_console_min_delay = d;
301 static int proc_console_backoff(struct ctl_table *table, int write,
302 void __user *buffer, size_t *lenp, loff_t *ppos)
305 struct ctl_table dummy = *table;
307 dummy.data = &backoff;
308 dummy.proc_handler = &proc_dointvec;
310 if (!write) { /* read */
311 backoff= libcfs_console_backoff;
312 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
318 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
324 libcfs_console_backoff = backoff;
329 static int libcfs_force_lbug(struct ctl_table *table, int write,
331 size_t *lenp, loff_t *ppos)
338 static int proc_fail_loc(struct ctl_table *table, int write,
340 size_t *lenp, loff_t *ppos)
343 long old_fail_loc = cfs_fail_loc;
345 rc = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
346 if (old_fail_loc != cfs_fail_loc)
347 wake_up(&cfs_race_waitq);
351 static int __proc_cpt_table(void *data, int write,
352 loff_t pos, void __user *buffer, int nob)
361 LASSERT(cfs_cpt_table != NULL);
364 LIBCFS_ALLOC(buf, len);
368 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
373 LIBCFS_FREE(buf, len);
385 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
388 LIBCFS_FREE(buf, len);
392 static int proc_cpt_table(struct ctl_table *table, int write,
393 void __user *buffer, size_t *lenp, loff_t *ppos)
395 return proc_call_handler(table->data, write, ppos, buffer, lenp,
399 static struct ctl_table lnet_table[] = {
401 * NB No .strategy entries have been provided since sysctl(8) prefers
402 * to go via /proc for portability.
406 .data = &libcfs_debug,
407 .maxlen = sizeof(int),
409 .proc_handler = &proc_dobitmasks,
412 .procname = "subsystem_debug",
413 .data = &libcfs_subsystem_debug,
414 .maxlen = sizeof(int),
416 .proc_handler = &proc_dobitmasks,
419 .procname = "printk",
420 .data = &libcfs_printk,
421 .maxlen = sizeof(int),
423 .proc_handler = &proc_dobitmasks,
426 .procname = "console_ratelimit",
427 .data = &libcfs_console_ratelimit,
428 .maxlen = sizeof(int),
430 .proc_handler = &proc_dointvec
433 .procname = "console_max_delay_centisecs",
434 .maxlen = sizeof(int),
436 .proc_handler = &proc_console_max_delay_cs
439 .procname = "console_min_delay_centisecs",
440 .maxlen = sizeof(int),
442 .proc_handler = &proc_console_min_delay_cs
445 .procname = "console_backoff",
446 .maxlen = sizeof(int),
448 .proc_handler = &proc_console_backoff
452 .procname = "debug_path",
453 .data = libcfs_debug_file_path_arr,
454 .maxlen = sizeof(libcfs_debug_file_path_arr),
456 .proc_handler = &proc_dostring,
460 .procname = "cpu_partition_table",
463 .proc_handler = &proc_cpt_table,
467 .procname = "upcall",
469 .maxlen = sizeof(lnet_upcall),
471 .proc_handler = &proc_dostring,
474 .procname = "debug_log_upcall",
475 .data = lnet_debug_log_upcall,
476 .maxlen = sizeof(lnet_debug_log_upcall),
478 .proc_handler = &proc_dostring,
481 .procname = "lnet_memused",
482 .data = (int *)&libcfs_kmemory.counter,
483 .maxlen = sizeof(int),
485 .proc_handler = &proc_dointvec,
488 .procname = "catastrophe",
489 .data = &libcfs_catastrophe,
490 .maxlen = sizeof(int),
492 .proc_handler = &proc_dointvec,
495 .procname = "panic_on_lbug",
496 .data = &libcfs_panic_on_lbug,
497 .maxlen = sizeof(int),
499 .proc_handler = &proc_dointvec,
502 .procname = "dump_kernel",
505 .proc_handler = &proc_dump_kernel,
508 .procname = "daemon_file",
511 .proc_handler = &proc_daemon_file,
514 .procname = "debug_mb",
516 .proc_handler = &proc_debug_mb,
519 .procname = "watchdog_ratelimit",
520 .data = &libcfs_watchdog_ratelimit,
521 .maxlen = sizeof(int),
523 .proc_handler = &proc_dointvec_minmax,
524 .extra1 = &min_watchdog_ratelimit,
525 .extra2 = &max_watchdog_ratelimit,
528 .procname = "force_lbug",
532 .proc_handler = &libcfs_force_lbug
535 .procname = "fail_loc",
536 .data = &cfs_fail_loc,
537 .maxlen = sizeof(cfs_fail_loc),
539 .proc_handler = &proc_fail_loc
542 .procname = "fail_val",
543 .data = &cfs_fail_val,
544 .maxlen = sizeof(int),
546 .proc_handler = &proc_dointvec
552 static struct ctl_table top_table[] = {
564 int insert_proc(void)
566 if (lnet_table_header == NULL)
567 lnet_table_header = register_sysctl_table(top_table);
571 void remove_proc(void)
573 if (lnet_table_header != NULL)
574 unregister_sysctl_table(lnet_table_header);
576 lnet_table_header = NULL;