Whamcloud - gitweb
f8453ceccdea92e6297f32cdb81fb6c84bf8e10f
[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 #include <linux/rbtree.h>
66
67 #define CFS_THREAD_SIZE   THREAD_SIZE
68 #define LUSTRE_TRACE_SIZE (THREAD_SIZE >> 5)
69
70 #if !defined(__x86_64__)
71 # ifdef  __ia64__
72 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
73                           ((unsigned long)__builtin_dwarf_cfa() &       \
74                            (THREAD_SIZE - 1)))
75 # else
76 #  define CDEBUG_STACK() (THREAD_SIZE -                                 \
77                           ((unsigned long)__builtin_frame_address(0) &  \
78                            (THREAD_SIZE - 1)))
79 # endif /* __ia64__ */
80
81 #define __CHECK_STACK(msgdata, mask, cdls)                              \
82 do {                                                                    \
83         if (unlikely(CDEBUG_STACK() > libcfs_stack)) {                  \
84                 LIBCFS_DEBUG_MSG_DATA_INIT(msgdata, D_WARNING, NULL);   \
85                 libcfs_stack = CDEBUG_STACK();                          \
86                 libcfs_debug_msg(msgdata,                               \
87                                  "maximum lustre stack %lu\n",          \
88                                  CDEBUG_STACK());                       \
89                 (msgdata)->msg_mask = mask;                             \
90                 (msgdata)->msg_cdls = cdls;                             \
91                 dump_stack();                                           \
92               /*panic("LBUG");*/                                        \
93         }                                                               \
94 } while (0)
95 #define CFS_CHECK_STACK(msgdata, mask, cdls)  __CHECK_STACK(msgdata, mask, cdls)
96 #else /* __x86_64__ */
97 #define CFS_CHECK_STACK(msgdata, mask, cdls) do {} while(0)
98 #define CDEBUG_STACK() (0L)
99 #endif /* __x86_64__ */
100
101 /* initial pid  */
102 #define LUSTRE_LNET_PID          12345
103
104 #define ENTRY_NESTING_SUPPORT (1)
105 #define ENTRY_NESTING   do {;} while (0)
106 #define EXIT_NESTING   do {;} while (0)
107 #define __current_nesting_level() (0)
108
109 /**
110  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
111  *
112  * Implementation is in linux-curproc.c
113  */
114 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
115
116 #include <linux/capability.h>
117 typedef kernel_cap_t cfs_kernel_cap_t;
118
119 /*
120  * No stack-back-tracing in Linux for now.
121  */
122 struct cfs_stack_trace {
123 };
124
125 /* long integer with size equal to pointer */
126 typedef unsigned long ulong_ptr_t;
127 typedef long long_ptr_t;
128
129 #ifndef WITH_WATCHDOG
130 #define WITH_WATCHDOG
131 #endif
132
133 #ifndef HAVE_STRUCT_CRED
134
135 #define current_cred() (current)
136
137 #define current_cred_xxx(xxx)                   \
138 ({                                              \
139         current->xxx;                     \
140 })
141
142 #ifndef HAVE_CRED_WRAPPERS
143
144 #define current_uid()           (current_cred_xxx(uid))
145 #define current_gid()           (current_cred_xxx(gid))
146 #define current_euid()          (current_cred_xxx(euid))
147 #define current_egid()          (current_cred_xxx(egid))
148 #define current_suid()          (current_cred_xxx(suid))
149 #define current_sgid()          (current_cred_xxx(sgid))
150 #define current_fsuid()         (current_cred_xxx(fsuid))
151 #define current_fsgid()         (current_cred_xxx(fsgid))
152 #define current_cap()           (current_cred_xxx(cap_effective))
153
154 #endif /* HAVE_LINUX_CRED_H */
155
156 #define current_user()          (current_cred_xxx(user))
157 #define current_user_ns()       (current_cred_xxx(user)->user_ns)
158 #define current_security()      (current_cred_xxx(security))
159
160 #define cred task_struct
161
162 #define prepare_creds() (current)
163 #define commit_creds(a)
164
165 #endif /* HAVE_STRUCT_CRED */
166
167 #ifndef HAVE_SCATTERLIST_INITTABLE
168 #define sg_init_table(sg, nents) memset(sg, 0, sizeof(*(sg))*(nents))
169 #endif
170
171 #ifndef HAVE_SCATTERLIST_SETPAGE
172 #define sg_set_page(sg, p, len, off) \
173         sg_set_buf(sg, page_address(p) + ((off) & ~CFS_PAGE_MASK), len)
174 #endif
175
176 #endif /* _LINUX_LIBCFS_H */