1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5 * Author: Zach Brown <zab@zabbo.net>
6 * Author: Peter J. Braam <braam@clusterfs.com>
7 * Author: Phil Schwan <phil@clusterfs.com>
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # define EXPORT_SYMTAB
29 #ifndef AUTOCONF_INCLUDED
30 #include <linux/config.h>
32 #include <linux/module.h>
33 #include <linux/kernel.h>
35 #include <linux/string.h>
36 #include <linux/stat.h>
37 #include <linux/errno.h>
38 #include <linux/smp_lock.h>
39 #include <linux/unistd.h>
41 #include <linux/uio.h>
43 #include <asm/system.h>
44 #include <asm/uaccess.h>
47 #include <linux/file.h>
48 #include <linux/stat.h>
49 #include <linux/list.h>
50 #include <asm/uaccess.h>
51 #include <asm/segment.h>
53 #include <linux/proc_fs.h>
54 #include <linux/sysctl.h>
56 # define DEBUG_SUBSYSTEM S_LNET
58 #include <libcfs/kp30.h>
59 #include <asm/div64.h>
60 #include "tracefile.h"
62 static cfs_sysctl_table_header_t *lnet_table_header = NULL;
63 extern char lnet_upcall[1024];
65 #define PSDEV_LNET (0x100)
67 PSDEV_DEBUG = 1, /* control debugging */
68 PSDEV_SUBSYSTEM_DEBUG, /* control debugging */
69 PSDEV_PRINTK, /* force all messages to console */
70 PSDEV_CONSOLE_RATELIMIT, /* ratelimit console messages */
71 PSDEV_CONSOLE_MAX_DELAY_CS, /* maximum delay over which we skip messages */
72 PSDEV_CONSOLE_MIN_DELAY_CS, /* initial delay over which we skip messages */
73 PSDEV_CONSOLE_BACKOFF, /* delay increase factor */
74 PSDEV_DEBUG_PATH, /* crashdump log location */
75 PSDEV_DEBUG_DUMP_PATH, /* crashdump tracelog location */
76 PSDEV_LNET_UPCALL, /* User mode upcall script */
77 PSDEV_LNET_MEMUSED, /* bytes currently PORTAL_ALLOCated */
78 PSDEV_LNET_CATASTROPHE, /* if we have LBUGged or panic'd */
79 PSDEV_LNET_PANIC_ON_LBUG, /* flag to panic on LBUG */
80 PSDEV_LNET_DUMP_KERNEL, /* snapshot kernel debug buffer to file */
81 PSDEV_LNET_DAEMON_FILE, /* spool kernel debug buffer to file */
82 PSDEV_LNET_DEBUG_MB, /* size of debug buffer */
86 proc_call_handler(void *data, int write,
87 loff_t *ppos, void *buffer, size_t *lenp,
88 int (*handler)(void *data, int write,
89 loff_t pos, void *buffer, int len))
91 int rc = handler(data, write, *ppos, buffer, *lenp);
105 #define DECLARE_PROC_HANDLER(name) \
107 LL_PROC_PROTO(name) \
109 DECLARE_LL_PROC_PPOS_DECL; \
111 return proc_call_handler(table->data, write, \
112 ppos, buffer, lenp, \
116 static int __proc_dobitmasks(void *data, int write,
117 loff_t pos, void *buffer, int nob)
119 const int tmpstrlen = 512;
122 unsigned int *mask = data;
123 int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
124 int is_printk = (mask == &libcfs_printk) ? 1 : 0;
126 rc = trace_allocate_string_buffer(&tmpstr, tmpstrlen);
131 libcfs_debug_mask2str(tmpstr, tmpstrlen, *mask, is_subsys);
137 rc = trace_copyout_string(buffer, nob,
141 rc = trace_copyin_string(tmpstr, tmpstrlen, buffer, nob);
145 rc = libcfs_debug_str2mask(mask, tmpstr, is_subsys);
146 /* Always print LBUG/LASSERT to console, so keep this mask */
151 trace_free_string_buffer(tmpstr, tmpstrlen);
155 DECLARE_PROC_HANDLER(proc_dobitmasks)
157 static int __proc_dump_kernel(void *data, int write,
158 loff_t pos, void *buffer, int nob)
163 return trace_dump_debug_buffer_usrstr(buffer, nob);
166 DECLARE_PROC_HANDLER(proc_dump_kernel)
168 static int __proc_daemon_file(void *data, int write,
169 loff_t pos, void *buffer, int nob)
172 int len = strlen(tracefile);
177 return trace_copyout_string(buffer, nob,
178 tracefile + pos, "\n");
181 return trace_daemon_command_usrstr(buffer, nob);
184 DECLARE_PROC_HANDLER(proc_daemon_file)
186 static int __proc_debug_mb(void *data, int write,
187 loff_t pos, void *buffer, int nob)
191 int len = snprintf(tmpstr, sizeof(tmpstr), "%d",
192 trace_get_debug_mb());
197 return trace_copyout_string(buffer, nob, tmpstr + pos, "\n");
200 return trace_set_debug_mb_usrstr(buffer, nob);
203 DECLARE_PROC_HANDLER(proc_debug_mb)
205 int LL_PROC_PROTO(proc_console_max_delay_cs)
207 int rc, max_delay_cs;
208 cfs_sysctl_table_t dummy = *table;
211 dummy.data = &max_delay_cs;
212 dummy.proc_handler = &proc_dointvec;
214 if (!write) { /* read */
215 max_delay_cs = cfs_duration_sec(libcfs_console_max_delay * 100);
216 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
222 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
225 if (max_delay_cs <= 0)
228 d = cfs_time_seconds(max_delay_cs) / 100;
229 if (d == 0 || d < libcfs_console_min_delay)
231 libcfs_console_max_delay = d;
236 int LL_PROC_PROTO(proc_console_min_delay_cs)
238 int rc, min_delay_cs;
239 cfs_sysctl_table_t dummy = *table;
242 dummy.data = &min_delay_cs;
243 dummy.proc_handler = &proc_dointvec;
245 if (!write) { /* read */
246 min_delay_cs = cfs_duration_sec(libcfs_console_min_delay * 100);
247 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
253 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
256 if (min_delay_cs <= 0)
259 d = cfs_time_seconds(min_delay_cs) / 100;
260 if (d == 0 || d > libcfs_console_max_delay)
262 libcfs_console_min_delay = d;
267 int LL_PROC_PROTO(proc_console_backoff)
270 cfs_sysctl_table_t dummy = *table;
272 dummy.data = &backoff;
273 dummy.proc_handler = &proc_dointvec;
275 if (!write) { /* read */
276 backoff= libcfs_console_backoff;
277 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
283 rc = ll_proc_dointvec(&dummy, write, filp, buffer, lenp, ppos);
289 libcfs_console_backoff = backoff;
294 static cfs_sysctl_table_t lnet_table[] = {
296 * NB No .strategy entries have been provided since sysctl(8) prefers
297 * to go via /proc for portability.
300 .ctl_name = PSDEV_DEBUG,
302 .data = &libcfs_debug,
303 .maxlen = sizeof(int),
305 .proc_handler = &proc_dobitmasks
308 .ctl_name = PSDEV_SUBSYSTEM_DEBUG,
309 .procname = "subsystem_debug",
310 .data = &libcfs_subsystem_debug,
311 .maxlen = sizeof(int),
313 .proc_handler = &proc_dobitmasks
316 .ctl_name = PSDEV_PRINTK,
317 .procname = "printk",
318 .data = &libcfs_printk,
319 .maxlen = sizeof(int),
321 .proc_handler = &proc_dobitmasks
324 .ctl_name = PSDEV_CONSOLE_RATELIMIT,
325 .procname = "console_ratelimit",
326 .data = &libcfs_console_ratelimit,
327 .maxlen = sizeof(int),
329 .proc_handler = &proc_dointvec
332 .ctl_name = PSDEV_CONSOLE_MAX_DELAY_CS,
333 .procname = "console_max_delay_centisecs",
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_console_max_delay_cs
339 .ctl_name = PSDEV_CONSOLE_MIN_DELAY_CS,
340 .procname = "console_min_delay_centisecs",
341 .maxlen = sizeof(int),
343 .proc_handler = &proc_console_min_delay_cs
346 .ctl_name = PSDEV_CONSOLE_BACKOFF,
347 .procname = "console_backoff",
348 .maxlen = sizeof(int),
350 .proc_handler = &proc_console_backoff
354 .ctl_name = PSDEV_DEBUG_PATH,
355 .procname = "debug_path",
356 .data = debug_file_path,
357 .maxlen = sizeof(debug_file_path),
359 .proc_handler = &proc_dostring,
363 .ctl_name = PSDEV_LNET_UPCALL,
364 .procname = "upcall",
366 .maxlen = sizeof(lnet_upcall),
368 .proc_handler = &proc_dostring,
371 .ctl_name = PSDEV_LNET_MEMUSED,
372 .procname = "memused",
373 .data = (int *)&libcfs_kmemory.counter,
374 .maxlen = sizeof(int),
376 .proc_handler = &proc_dointvec
379 .ctl_name = PSDEV_LNET_CATASTROPHE,
380 .procname = "catastrophe",
381 .data = &libcfs_catastrophe,
382 .maxlen = sizeof(int),
384 .proc_handler = &proc_dointvec
387 .ctl_name = PSDEV_LNET_PANIC_ON_LBUG,
388 .procname = "panic_on_lbug",
389 .data = &libcfs_panic_on_lbug,
390 .maxlen = sizeof(int),
392 .proc_handler = &proc_dointvec
395 .ctl_name = PSDEV_LNET_DUMP_KERNEL,
396 .procname = "dump_kernel",
398 .proc_handler = &proc_dump_kernel,
401 .ctl_name = PSDEV_LNET_DAEMON_FILE,
402 .procname = "daemon_file",
404 .proc_handler = &proc_daemon_file,
407 .ctl_name = PSDEV_LNET_DEBUG_MB,
408 .procname = "debug_mb",
410 .proc_handler = &proc_debug_mb,
415 static cfs_sysctl_table_t top_table[2] = {
417 .ctl_name = PSDEV_LNET,
427 int insert_proc(void)
430 if (lnet_table_header == NULL)
431 lnet_table_header = cfs_register_sysctl_table(top_table, 0);
436 void remove_proc(void)
439 if (lnet_table_header != NULL)
440 cfs_unregister_sysctl_table(lnet_table_header);
442 lnet_table_header = NULL;