Whamcloud - gitweb
LU-1408 debug: initialize debug_msg_data if needed
[fs/lustre-release.git] / libcfs / include / libcfs / linux / libcfs.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #ifndef __LIBCFS_LINUX_LIBCFS_H__
36 #define __LIBCFS_LINUX_LIBCFS_H__
37
38 #ifndef __LIBCFS_LIBCFS_H__
39 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
40 #endif
41
42 #ifndef __KERNEL__
43 #error This include is only for kernel use.
44 #endif
45
46
47 #include <stdarg.h>
48 #include <libcfs/linux/linux-cpu.h>
49 #include <libcfs/linux/linux-time.h>
50 #include <libcfs/linux/linux-mem.h>
51 #include <libcfs/linux/linux-prim.h>
52 #include <libcfs/linux/linux-lock.h>
53 #include <libcfs/linux/linux-fs.h>
54 #include <libcfs/linux/linux-tcpip.h>
55 #include <libcfs/linux/linux-bitops.h>
56 #include <libcfs/linux/linux-types.h>
57 #include <libcfs/linux/kp30.h>
58
59 #ifdef HAVE_ASM_TYPES_H
60 #include <asm/types.h>
61 #endif
62 #include <linux/types.h>
63 #include <asm/timex.h>
64 #include <linux/sched.h> /* THREAD_SIZE */
65
66 #define CFS_THREAD_SIZE   THREAD_SIZE
67 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
68
69 #if !defined(__x86_64__)
70 # ifdef  __ia64__
71 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
72                           ((unsigned long)__builtin_dwarf_cfa() &       \
73                            (THREAD_SIZE - 1)))
74 # else
75 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
76                           ((unsigned long)__builtin_frame_address(0) &  \
77                            (THREAD_SIZE - 1)))
78 # endif /* __ia64__ */
79
80 #define __CHECK_STACK(msgdata, mask, cdls)                              \
81 do {                                                                    \
82         if (unlikely(CDEBUG_STACK() > libcfs_stack)) {                  \
83                 LIBCFS_DEBUG_MSG_DATA_INIT(msgdata, D_WARNING, NULL);   \
84                 libcfs_stack = CDEBUG_STACK();                          \
85                 libcfs_debug_msg(msgdata,                               \
86                                  "maximum lustre stack %lu\n",          \
87                                  CDEBUG_STACK());                       \
88                 (msgdata)->msg_mask = mask;                             \
89                 (msgdata)->msg_cdls = cdls;                             \
90                 dump_stack();                                           \
91               /*panic("LBUG");*/                                        \
92         }                                                               \
93 } while (0)
94 #define CFS_CHECK_STACK(msgdata, mask, cdls)  __CHECK_STACK(msgdata, mask, cdls)
95 #else /* __x86_64__ */
96 #define CFS_CHECK_STACK(msgdata, mask, cdls) do {} while(0)
97 #define CDEBUG_STACK() (0L)
98 #endif /* __x86_64__ */
99
100 /* initial pid  */
101 #define LUSTRE_LNET_PID          12345
102
103 #define ENTRY_NESTING_SUPPORT (1)
104 #define ENTRY_NESTING   do {;} while (0)
105 #define EXIT_NESTING   do {;} while (0)
106 #define __current_nesting_level() (0)
107
108 /**
109  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
110  *
111  * Implementation is in linux-curproc.c
112  */
113 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
114
115 #include <linux/capability.h>
116 typedef kernel_cap_t cfs_kernel_cap_t;
117
118 /*
119  * No stack-back-tracing in Linux for now.
120  */
121 struct cfs_stack_trace {
122 };
123
124 /* long integer with size equal to pointer */
125 typedef unsigned long ulong_ptr_t;
126 typedef long long_ptr_t;
127
128 #ifndef WITH_WATCHDOG
129 #define WITH_WATCHDOG
130 #endif
131
132 #ifndef HAVE_STRUCT_CRED
133
134 #define current_cred() (current)
135
136 #define current_cred_xxx(xxx)                   \
137 ({                                              \
138         current->xxx;                     \
139 })
140
141 #ifndef HAVE_CRED_WRAPPERS
142
143 #define current_uid()           (current_cred_xxx(uid))
144 #define current_gid()           (current_cred_xxx(gid))
145 #define current_euid()          (current_cred_xxx(euid))
146 #define current_egid()          (current_cred_xxx(egid))
147 #define current_suid()          (current_cred_xxx(suid))
148 #define current_sgid()          (current_cred_xxx(sgid))
149 #define current_fsuid()         (current_cred_xxx(fsuid))
150 #define current_fsgid()         (current_cred_xxx(fsgid))
151 #define current_cap()           (current_cred_xxx(cap_effective))
152
153 #endif /* HAVE_LINUX_CRED_H */
154
155 #define current_user()          (current_cred_xxx(user))
156 #define current_user_ns()       (current_cred_xxx(user)->user_ns)
157 #define current_security()      (current_cred_xxx(security))
158
159 #define cred task_struct
160
161 #define prepare_creds() (current)
162 #define commit_creds(a)
163
164 #endif /* HAVE_STRUCT_CRED */
165
166 #endif /* _LINUX_LIBCFS_H */