Whamcloud - gitweb
* Landed portals:b_port_step as follows...
[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 static int handled_panic; /* to avoid recursive calls to notifiers */
63 char portals_upcall[1024] = "/usr/lib/lustre/portals_upcall";
64
65 void portals_run_upcall(char **argv)
66 {
67         int   rc;
68         int   argc;
69         char *envp[] = {
70                 "HOME=/",
71                 "PATH=/sbin:/bin:/usr/sbin:/usr/bin",
72                 NULL};
73         ENTRY;
74
75         argv[0] = portals_upcall;
76         argc = 1;
77         while (argv[argc] != NULL)
78                 argc++;
79
80         LASSERT(argc >= 2);
81
82         rc = USERMODEHELPER(argv[0], argv, envp);
83         if (rc < 0) {
84                 CERROR("Error %d invoking portals upcall %s %s%s%s%s%s%s%s%s; "
85                        "check /proc/sys/portals/upcall\n",
86                        rc, argv[0], argv[1],
87                        argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
88                        argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
89                        argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
90                        argc < 6 ? "" : ",...");
91         } else {
92                 CERROR("Invoked portals upcall %s %s%s%s%s%s%s%s%s\n",
93                        argv[0], argv[1],
94                        argc < 3 ? "" : ",", argc < 3 ? "" : argv[2],
95                        argc < 4 ? "" : ",", argc < 4 ? "" : argv[3],
96                        argc < 5 ? "" : ",", argc < 5 ? "" : argv[4],
97                        argc < 6 ? "" : ",...");
98         }
99 }
100
101 void portals_run_lbug_upcall(char *file, const char *fn, const int line)
102 {
103         char *argv[6];
104         char buf[32];
105
106         ENTRY;
107         snprintf (buf, sizeof buf, "%d", line);
108
109         argv[1] = "LBUG";
110         argv[2] = file;
111         argv[3] = (char *)fn;
112         argv[4] = buf;
113         argv[5] = NULL;
114
115         portals_run_upcall (argv);
116 }
117
118 #ifdef __KERNEL__
119
120 void portals_debug_dumpstack(struct task_struct *tsk)
121 {
122 #if defined(__arch_um__) 
123         if (tsk != NULL) 
124                 CWARN("stack dump for pid %d (%d) requested; wake up gdb.\n", 
125                       tsk->pid, UML_PID(tsk)); 
126         asm("int $3");
127 #elif defined(HAVE_SHOW_TASK) 
128         /* this is exported by lustre kernel version 42 */ 
129         extern void show_task(struct task_struct *); 
130
131         if (tsk == NULL) 
132                 tsk = current; 
133         CWARN("showing stack for process %d\n", tsk->pid); 
134         show_task(tsk); 
135 #else 
136         CWARN("can't show stack: kernel doesn't export show_task\n");
137 #endif
138 }
139
140 cfs_task_t *portals_current(void)
141
142         CWARN("current task struct is %p\n", current);
143         return current;
144 }
145 EXPORT_SYMBOL(portals_debug_dumpstack);
146 EXPORT_SYMBOL(portals_current);
147
148 #endif /* __KERNEL__ */
149
150 EXPORT_SYMBOL(portals_run_upcall);
151 EXPORT_SYMBOL(portals_run_lbug_upcall);