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/stat.h>
58 #include <linux/list.h>
59 #include <asm/uaccess.h>
61 #include <linux/proc_fs.h>
62 #include <linux/sysctl.h>
64 # define DEBUG_SUBSYSTEM S_LNET
66 #include <libcfs/libcfs.h>
67 #include <asm/div64.h>
68 #include "tracefile.h"
71 static struct ctl_table_header *lnet_table_header = NULL;
73 extern char lnet_upcall[1024];
75 * The path of debug log dump upcall script.
77 extern char lnet_debug_log_upcall[1024];
79 int lprocfs_call_handler(void *data, int write, loff_t *ppos,
80 void __user *buffer, size_t *lenp,
81 int (*handler)(void *data, int write, loff_t pos,
82 void __user *buffer, int len))
84 int rc = handler(data, write, *ppos, buffer, *lenp);
97 EXPORT_SYMBOL(lprocfs_call_handler);
99 static int __proc_dobitmasks(void *data, int write,
100 loff_t pos, void __user *buffer, int nob)
102 const int tmpstrlen = 512;
105 unsigned int *mask = data;
106 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
107 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
109 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
114 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
120 rc = cfs_trace_copyout_string(buffer, nob,
124 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
126 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
130 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
131 /* Always print LBUG/LASSERT to console, so keep this mask */
136 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
141 proc_dobitmasks(struct ctl_table *table, int write,
142 void __user *buffer, size_t *lenp, loff_t *ppos)
144 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
148 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
149 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
151 static int __proc_dump_kernel(void *data, int write,
152 loff_t pos, void __user *buffer, int nob)
157 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
161 proc_dump_kernel(struct ctl_table *table, int write, void __user *buffer,
162 size_t *lenp, loff_t *ppos)
164 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
168 static int __proc_daemon_file(void *data, int write,
169 loff_t pos, void __user *buffer, int nob)
172 int len = strlen(cfs_tracefile);
177 return cfs_trace_copyout_string(buffer, nob,
178 cfs_tracefile + pos, "\n");
181 return cfs_trace_daemon_command_usrstr(buffer, nob);
185 proc_daemon_file(struct ctl_table *table, int write, void __user *buffer,
186 size_t *lenp, loff_t *ppos)
188 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
192 static int __proc_debug_mb(void *data, int write,
193 loff_t pos, void __user *buffer, int nob)
197 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
198 cfs_trace_get_debug_mb());
203 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
207 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
211 proc_debug_mb(struct ctl_table *table, int write, void __user *buffer,
212 size_t *lenp, loff_t *ppos)
214 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
219 proc_console_max_delay_cs(struct ctl_table *table, int write,
220 void __user *buffer, size_t *lenp, loff_t *ppos)
222 int rc, max_delay_cs;
223 struct ctl_table dummy = *table;
226 dummy.data = &max_delay_cs;
227 dummy.proc_handler = &proc_dointvec;
229 if (!write) { /* read */
230 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
231 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
237 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
240 if (max_delay_cs <= 0)
243 d = cfs_time_seconds(max_delay_cs) / 100;
244 if (d == 0 || d < libcfs_console_min_delay)
246 libcfs_console_max_delay = d;
252 proc_console_min_delay_cs(struct ctl_table *table, int write,
253 void __user *buffer, size_t *lenp, loff_t *ppos)
255 int rc, min_delay_cs;
256 struct ctl_table dummy = *table;
259 dummy.data = &min_delay_cs;
260 dummy.proc_handler = &proc_dointvec;
262 if (!write) { /* read */
263 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
264 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
270 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
273 if (min_delay_cs <= 0)
276 d = cfs_time_seconds(min_delay_cs) / 100;
277 if (d == 0 || d > libcfs_console_max_delay)
279 libcfs_console_min_delay = d;
285 proc_console_backoff(struct ctl_table *table, int write, void __user *buffer,
286 size_t *lenp, loff_t *ppos)
289 struct ctl_table dummy = *table;
291 dummy.data = &backoff;
292 dummy.proc_handler = &proc_dointvec;
294 if (!write) { /* read */
295 backoff= libcfs_console_backoff;
296 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
302 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
308 libcfs_console_backoff = backoff;
314 libcfs_force_lbug(struct ctl_table *table, int write, void __user *buffer,
315 size_t *lenp, loff_t *ppos)
323 proc_fail_loc(struct ctl_table *table, int write, void __user *buffer,
324 size_t *lenp, loff_t *ppos)
327 long old_fail_loc = cfs_fail_loc;
329 rc = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
330 if (old_fail_loc != cfs_fail_loc)
331 wake_up(&cfs_race_waitq);
335 static int __proc_cpt_table(void *data, int write,
336 loff_t pos, void __user *buffer, int nob)
345 LASSERT(cfs_cpt_table != NULL);
348 LIBCFS_ALLOC(buf, len);
352 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
356 LIBCFS_FREE(buf, len);
369 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
372 LIBCFS_FREE(buf, len);
377 proc_cpt_table(struct ctl_table *table, int write, void __user *buffer,
378 size_t *lenp, loff_t *ppos)
380 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
384 static struct ctl_table lnet_table[] = {
386 * NB No .strategy entries have been provided since sysctl(8) prefers
387 * to go via /proc for portability.
392 .data = &libcfs_debug,
393 .maxlen = sizeof(int),
395 .proc_handler = &proc_dobitmasks,
399 .procname = "subsystem_debug",
400 .data = &libcfs_subsystem_debug,
401 .maxlen = sizeof(int),
403 .proc_handler = &proc_dobitmasks,
407 .procname = "printk",
408 .data = &libcfs_printk,
409 .maxlen = sizeof(int),
411 .proc_handler = &proc_dobitmasks,
415 .procname = "console_ratelimit",
416 .data = &libcfs_console_ratelimit,
417 .maxlen = sizeof(int),
419 .proc_handler = &proc_dointvec
423 .procname = "console_max_delay_centisecs",
424 .maxlen = sizeof(int),
426 .proc_handler = &proc_console_max_delay_cs
430 .procname = "console_min_delay_centisecs",
431 .maxlen = sizeof(int),
433 .proc_handler = &proc_console_min_delay_cs
437 .procname = "console_backoff",
438 .maxlen = sizeof(int),
440 .proc_handler = &proc_console_backoff
444 .procname = "debug_path",
445 .data = libcfs_debug_file_path_arr,
446 .maxlen = sizeof(libcfs_debug_file_path_arr),
448 .proc_handler = &proc_dostring,
452 .procname = "cpu_partition_table",
455 .proc_handler = &proc_cpt_table,
459 .procname = "upcall",
461 .maxlen = sizeof(lnet_upcall),
463 .proc_handler = &proc_dostring,
467 .procname = "debug_log_upcall",
468 .data = lnet_debug_log_upcall,
469 .maxlen = sizeof(lnet_debug_log_upcall),
471 .proc_handler = &proc_dostring,
475 .procname = "lnet_memused",
476 .data = (int *)&libcfs_kmemory.counter,
477 .maxlen = sizeof(int),
479 .proc_handler = &proc_dointvec,
484 .procname = "catastrophe",
485 .data = &libcfs_catastrophe,
486 .maxlen = sizeof(int),
488 .proc_handler = &proc_dointvec,
493 .procname = "panic_on_lbug",
494 .data = &libcfs_panic_on_lbug,
495 .maxlen = sizeof(int),
497 .proc_handler = &proc_dointvec,
502 .procname = "dump_kernel",
505 .proc_handler = &proc_dump_kernel,
509 .procname = "daemon_file",
512 .proc_handler = &proc_daemon_file,
516 .procname = "debug_mb",
518 .proc_handler = &proc_debug_mb,
522 .procname = "watchdog_ratelimit",
523 .data = &libcfs_watchdog_ratelimit,
524 .maxlen = sizeof(int),
526 .proc_handler = &proc_dointvec_minmax,
527 .extra1 = &min_watchdog_ratelimit,
528 .extra2 = &max_watchdog_ratelimit,
532 .procname = "force_lbug",
536 .proc_handler = &libcfs_force_lbug
540 .procname = "fail_loc",
541 .data = &cfs_fail_loc,
542 .maxlen = sizeof(cfs_fail_loc),
544 .proc_handler = &proc_fail_loc
548 .procname = "fail_val",
549 .data = &cfs_fail_val,
550 .maxlen = sizeof(int),
552 .proc_handler = &proc_dointvec
556 .procname = "fail_err",
557 .data = &cfs_fail_err,
558 .maxlen = sizeof(cfs_fail_err),
560 .proc_handler = &proc_dointvec,
566 static struct ctl_table top_table[] = {
579 int insert_proc(void)
582 if (lnet_table_header == NULL)
583 lnet_table_header = register_sysctl_table(top_table);
588 void remove_proc(void)
591 if (lnet_table_header != NULL)
592 unregister_sysctl_table(lnet_table_header);
594 lnet_table_header = NULL;