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, void *buffer,
80 size_t *lenp, int (*handler)(void *data, int write,
81 loff_t pos, void *buffer, int len))
83 int rc = handler(data, write, *ppos, buffer, *lenp);
96 EXPORT_SYMBOL(lprocfs_call_handler);
98 static int __proc_dobitmasks(void *data, int write,
99 loff_t pos, void *buffer, int nob)
101 const int tmpstrlen = 512;
104 unsigned int *mask = data;
105 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
106 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
108 rc = cfs_trace_allocate_string_buffer(&tmpstr, tmpstrlen);
113 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
119 rc = cfs_trace_copyout_string(buffer, nob,
123 rc = cfs_trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
125 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
129 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
130 /* Always print LBUG/LASSERT to console, so keep this mask */
135 cfs_trace_free_string_buffer(tmpstr, tmpstrlen);
140 proc_dobitmasks(struct ctl_table *table, int write,
141 void __user *buffer, size_t *lenp, loff_t *ppos)
143 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
147 static int min_watchdog_ratelimit = 0; /* disable ratelimiting */
148 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
150 static int __proc_dump_kernel(void *data, int write,
151 loff_t pos, void *buffer, int nob)
156 return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
160 proc_dump_kernel(struct ctl_table *table, int write, void __user *buffer,
161 size_t *lenp, loff_t *ppos)
163 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
167 static int __proc_daemon_file(void *data, int write,
168 loff_t pos, void *buffer, int nob)
171 int len = strlen(cfs_tracefile);
176 return cfs_trace_copyout_string(buffer, nob,
177 cfs_tracefile + pos, "\n");
180 return cfs_trace_daemon_command_usrstr(buffer, nob);
184 proc_daemon_file(struct ctl_table *table, int write, void __user *buffer,
185 size_t *lenp, loff_t *ppos)
187 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
191 static int __proc_debug_mb(void *data, int write,
192 loff_t pos, void *buffer, int nob)
196 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
197 cfs_trace_get_debug_mb());
202 return cfs_trace_copyout_string(buffer, nob, tmpstr + pos,
206 return cfs_trace_set_debug_mb_usrstr(buffer, nob);
210 proc_debug_mb(struct ctl_table *table, int write, void __user *buffer,
211 size_t *lenp, loff_t *ppos)
213 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
218 proc_console_max_delay_cs(struct ctl_table *table, int write,
219 void __user *buffer, size_t *lenp, loff_t *ppos)
221 int rc, max_delay_cs;
222 struct ctl_table 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 = proc_dointvec(&dummy, write, buffer, lenp, ppos);
236 rc = proc_dointvec(&dummy, write, 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;
251 proc_console_min_delay_cs(struct ctl_table *table, int write,
252 void __user *buffer, size_t *lenp, loff_t *ppos)
254 int rc, min_delay_cs;
255 struct ctl_table dummy = *table;
258 dummy.data = &min_delay_cs;
259 dummy.proc_handler = &proc_dointvec;
261 if (!write) { /* read */
262 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
263 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
269 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
272 if (min_delay_cs <= 0)
275 d = cfs_time_seconds(min_delay_cs) / 100;
276 if (d == 0 || d > libcfs_console_max_delay)
278 libcfs_console_min_delay = d;
284 proc_console_backoff(struct ctl_table *table, int write, void __user *buffer,
285 size_t *lenp, loff_t *ppos)
288 struct ctl_table dummy = *table;
290 dummy.data = &backoff;
291 dummy.proc_handler = &proc_dointvec;
293 if (!write) { /* read */
294 backoff= libcfs_console_backoff;
295 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
301 rc = proc_dointvec(&dummy, write, buffer, lenp, ppos);
307 libcfs_console_backoff = backoff;
313 libcfs_force_lbug(struct ctl_table *table, int write, void __user *buffer,
314 size_t *lenp, loff_t *ppos)
322 proc_fail_loc(struct ctl_table *table, int write, void __user *buffer,
323 size_t *lenp, loff_t *ppos)
326 long old_fail_loc = cfs_fail_loc;
328 rc = proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
329 if (old_fail_loc != cfs_fail_loc)
330 wake_up(&cfs_race_waitq);
334 static int __proc_cpt_table(void *data, int write,
335 loff_t pos, void *buffer, int nob)
344 LASSERT(cfs_cpt_table != NULL);
347 LIBCFS_ALLOC(buf, len);
351 rc = cfs_cpt_table_print(cfs_cpt_table, buf, len);
355 LIBCFS_FREE(buf, len);
368 rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL);
371 LIBCFS_FREE(buf, len);
376 proc_cpt_table(struct ctl_table *table, int write, void __user *buffer,
377 size_t *lenp, loff_t *ppos)
379 return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
383 static struct ctl_table lnet_table[] = {
385 * NB No .strategy entries have been provided since sysctl(8) prefers
386 * to go via /proc for portability.
391 .data = &libcfs_debug,
392 .maxlen = sizeof(int),
394 .proc_handler = &proc_dobitmasks,
398 .procname = "subsystem_debug",
399 .data = &libcfs_subsystem_debug,
400 .maxlen = sizeof(int),
402 .proc_handler = &proc_dobitmasks,
406 .procname = "printk",
407 .data = &libcfs_printk,
408 .maxlen = sizeof(int),
410 .proc_handler = &proc_dobitmasks,
414 .procname = "console_ratelimit",
415 .data = &libcfs_console_ratelimit,
416 .maxlen = sizeof(int),
418 .proc_handler = &proc_dointvec
422 .procname = "console_max_delay_centisecs",
423 .maxlen = sizeof(int),
425 .proc_handler = &proc_console_max_delay_cs
429 .procname = "console_min_delay_centisecs",
430 .maxlen = sizeof(int),
432 .proc_handler = &proc_console_min_delay_cs
436 .procname = "console_backoff",
437 .maxlen = sizeof(int),
439 .proc_handler = &proc_console_backoff
443 .procname = "debug_path",
444 .data = libcfs_debug_file_path_arr,
445 .maxlen = sizeof(libcfs_debug_file_path_arr),
447 .proc_handler = &proc_dostring,
451 .procname = "cpu_partition_table",
454 .proc_handler = &proc_cpt_table,
458 .procname = "upcall",
460 .maxlen = sizeof(lnet_upcall),
462 .proc_handler = &proc_dostring,
466 .procname = "debug_log_upcall",
467 .data = lnet_debug_log_upcall,
468 .maxlen = sizeof(lnet_debug_log_upcall),
470 .proc_handler = &proc_dostring,
474 .procname = "lnet_memused",
475 .data = (int *)&libcfs_kmemory.counter,
476 .maxlen = sizeof(int),
478 .proc_handler = &proc_dointvec,
483 .procname = "catastrophe",
484 .data = &libcfs_catastrophe,
485 .maxlen = sizeof(int),
487 .proc_handler = &proc_dointvec,
492 .procname = "panic_on_lbug",
493 .data = &libcfs_panic_on_lbug,
494 .maxlen = sizeof(int),
496 .proc_handler = &proc_dointvec,
501 .procname = "dump_kernel",
504 .proc_handler = &proc_dump_kernel,
508 .procname = "daemon_file",
511 .proc_handler = &proc_daemon_file,
515 .procname = "debug_mb",
517 .proc_handler = &proc_debug_mb,
521 .procname = "watchdog_ratelimit",
522 .data = &libcfs_watchdog_ratelimit,
523 .maxlen = sizeof(int),
525 .proc_handler = &proc_dointvec_minmax,
526 .extra1 = &min_watchdog_ratelimit,
527 .extra2 = &max_watchdog_ratelimit,
531 .procname = "force_lbug",
535 .proc_handler = &libcfs_force_lbug
539 .procname = "fail_loc",
540 .data = &cfs_fail_loc,
541 .maxlen = sizeof(cfs_fail_loc),
543 .proc_handler = &proc_fail_loc
547 .procname = "fail_val",
548 .data = &cfs_fail_val,
549 .maxlen = sizeof(int),
551 .proc_handler = &proc_dointvec
555 .procname = "fail_err",
556 .data = &cfs_fail_err,
557 .maxlen = sizeof(cfs_fail_err),
559 .proc_handler = &proc_dointvec,
565 static struct ctl_table top_table[] = {
578 int insert_proc(void)
581 if (lnet_table_header == NULL)
582 lnet_table_header = register_sysctl_table(top_table);
587 void remove_proc(void)
590 if (lnet_table_header != NULL)
591 unregister_sysctl_table(lnet_table_header);
593 lnet_table_header = NULL;