Whamcloud - gitweb
* updates to HEAD lustre since landing b_port_step on portals
[fs/lustre-release.git] / lnet / libcfs / linux / linux-debug.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002 Cluster File Systems, Inc.
5  *   Author: Phil Schwan <phil@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #ifndef EXPORT_SYMTAB
24 # define EXPORT_SYMTAB
25 #endif
26
27 #include <linux/config.h>
28 #include <linux/module.h>
29 #include <linux/kmod.h>
30 #include <linux/notifier.h>
31 #include <linux/kernel.h>
32 #include <linux/mm.h>
33 #include <linux/string.h>
34 #include <linux/stat.h>
35 #include <linux/errno.h>
36 #include <linux/smp_lock.h>
37 #include <linux/unistd.h>
38 #include <linux/interrupt.h>
39 #include <asm/system.h>
40 #include <asm/uaccess.h>
41 #include <linux/completion.h>
42
43 #include <linux/fs.h>
44 #include <linux/stat.h>
45 #include <asm/uaccess.h>
46 #include <asm/segment.h>
47 #include <linux/miscdevice.h>
48 #include <linux/version.h>
49
50 # define DEBUG_SUBSYSTEM S_PORTALS
51
52 #include <libcfs/kp30.h>
53 #include <libcfs/linux/portals_compat25.h>
54 #include <libcfs/libcfs.h>
55
56 #include "tracefile.h"
57
58 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
59 #include <linux/kallsyms.h>
60 #endif
61
62 char portals_upcall[1024] = "/usr/lib/lustre/portals_upcall";
63
64 void portals_run_upcall(char **argv)
65 {
66         int   rc;
67         int   argc;
68         char *envp[] = {
69                 "HOME=/",
70                 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
71                 NULL};
72         ENTRY;
73
74         argv[0] = portals_upcall;
75         argc = 1;
76         while (argv[argc] != NULL)
77                 argc++;
78
79         LASSERT(argc >= 2);
80
81         rc = USERMODEHELPER(argv[0], argv, envp);
82         if (rc < 0) {
83                 CERROR("Error %d invoking portals upcall %s %s%s%s%s%s%s%s%s; "
84                        "check /proc/sys/portals/upcall\n",
85                        rc, argv[0], argv[1],
86                        argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
87                        argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
88                        argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
89                        argc < 6 ? "" : ",...");
90         } else {
91                 CERROR("Invoked portals upcall %s %s%s%s%s%s%s%s%s\n",
92                        argv[0], argv[1],
93                        argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
94                        argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
95                        argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
96                        argc < 6 ? "" : ",...");
97         }
98 }
99
100 void portals_run_lbug_upcall(char *file, const char *fn, const int line)
101 {
102         char *argv[6];
103         char buf[32];
104
105         ENTRY;
106         snprintf (buf, sizeof buf, "%d", line);
107
108         argv[1] = "LBUG";
109         argv[2] = file;
110         argv[3] = (char *)fn;
111         argv[4] = buf;
112         argv[5] = NULL;
113
114         portals_run_upcall (argv);
115 }
116
117 #ifdef __KERNEL__
118
119 void portals_debug_dumpstack(struct task_struct *tsk)
120 {
121 #if defined(__arch_um__) 
122         if (tsk != NULL) 
123                 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n", 
124                       tsk->pid, UML_PID(tsk)); 
125         asm("int $3");
126 #elif defined(HAVE_SHOW_TASK) 
127         /* this is exported by lustre kernel version 42 */ 
128         extern void show_task(struct task_struct *); 
129
130         if (tsk == NULL) 
131                 tsk = current; 
132         CWARN("showing stack for process %d\n", tsk->pid); 
133         show_task(tsk); 
134 #else 
135         CWARN("can't show stack: kernel doesn't export show_task\n");
136 #endif
137 }
138
139 cfs_task_t *portals_current(void)
140
141         CWARN("current task struct is %p\n", current);
142         return current;
143 }
144 EXPORT_SYMBOL(portals_debug_dumpstack);
145 EXPORT_SYMBOL(portals_current);
146
147 #endif /* __KERNEL__ */
148
149 EXPORT_SYMBOL(portals_run_upcall);
150 EXPORT_SYMBOL(portals_run_lbug_upcall);