Whamcloud - gitweb
dee91d9275a937e1e5aea5d6f69b68b25427a5a4
[fs/lustre-release.git] / libcfs / include / libcfs / linux / libcfs.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef __LIBCFS_LINUX_LIBCFS_H__
38 #define __LIBCFS_LINUX_LIBCFS_H__
39
40 #ifndef __LIBCFS_LIBCFS_H__
41 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
42 #endif
43
44 #ifndef __KERNEL__
45 #error This include is only for kernel use.
46 #endif
47
48
49 #include <stdarg.h>
50 #include <libcfs/linux/linux-time.h>
51 #include <libcfs/linux/linux-mem.h>
52 #include <libcfs/linux/linux-prim.h>
53 #include <libcfs/linux/linux-lock.h>
54 #include <libcfs/linux/linux-fs.h>
55 #include <libcfs/linux/linux-tcpip.h>
56 #include <libcfs/linux/linux-bitops.h>
57 #include <libcfs/linux/linux-types.h>
58 #include <libcfs/linux/kp30.h>
59
60 #ifdef HAVE_ASM_TYPES_H
61 #include <asm/types.h>
62 #endif
63 #include <linux/types.h>
64 #include <asm/timex.h>
65 #include <linux/sched.h> /* THREAD_SIZE */
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_stack = CDEBUG_STACK();                          \
85                 (msgdata)->msg_mask = D_WARNING;                        \
86                 (msgdata)->msg_cdls = NULL;                             \
87                 libcfs_debug_msg(msgdata,                               \
88                                  "maximum lustre stack %lu\n",          \
89                                  CDEBUG_STACK());                       \
90                 (msgdata)->msg_mask = mask;                             \
91                 (msgdata)->msg_cdls = cdls;                             \
92                 dump_stack();                                           \
93               /*panic("LBUG");*/                                        \
94         }                                                               \
95 } while (0)
96 #define CFS_CHECK_STACK(msgdata, mask, cdls)  __CHECK_STACK(msgdata, mask, cdls)
97 #else /* __x86_64__ */
98 #define CFS_CHECK_STACK(msgdata, mask, cdls) do {} while(0)
99 #define CDEBUG_STACK() (0L)
100 #endif /* __x86_64__ */
101
102 /* initial pid  */
103 #define LUSTRE_LNET_PID          12345
104
105 #define ENTRY_NESTING_SUPPORT (1)
106 #define ENTRY_NESTING   do {;} while (0)
107 #define EXIT_NESTING   do {;} while (0)
108 #define __current_nesting_level() (0)
109
110 /**
111  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
112  *
113  * Implementation is in linux-curproc.c
114  */
115 #define CFS_CURPROC_COMM_MAX (sizeof ((struct task_struct *)0)->comm)
116
117 #include <linux/capability.h>
118 typedef kernel_cap_t cfs_kernel_cap_t;
119
120 /*
121  * No stack-back-tracing in Linux for now.
122  */
123 struct cfs_stack_trace {
124 };
125
126 /* long integer with size equal to pointer */
127 typedef unsigned long ulong_ptr_t;
128 typedef long long_ptr_t;
129
130 #ifndef WITH_WATCHDOG
131 #define WITH_WATCHDOG
132 #endif
133
134 #ifndef HAVE_STRUCT_CRED
135
136 #define current_cred() (current)
137
138 #define current_cred_xxx(xxx)                   \
139 ({                                              \
140         current->xxx;                     \
141 })
142
143 #ifndef HAVE_CRED_WRAPPERS
144
145 #define current_uid()           (current_cred_xxx(uid))
146 #define current_gid()           (current_cred_xxx(gid))
147 #define current_euid()          (current_cred_xxx(euid))
148 #define current_egid()          (current_cred_xxx(egid))
149 #define current_suid()          (current_cred_xxx(suid))
150 #define current_sgid()          (current_cred_xxx(sgid))
151 #define current_fsuid()         (current_cred_xxx(fsuid))
152 #define current_fsgid()         (current_cred_xxx(fsgid))
153 #define current_cap()           (current_cred_xxx(cap_effective))
154
155 #endif /* HAVE_LINUX_CRED_H */
156
157 #define current_user()          (current_cred_xxx(user))
158 #define current_user_ns()       (current_cred_xxx(user)->user_ns)
159 #define current_security()      (current_cred_xxx(security))
160
161 #define cred task_struct
162
163 #define prepare_creds() (current)
164 #define commit_creds(a)
165
166 #endif /* HAVE_STRUCT_CRED */
167
168 #endif /* _LINUX_LIBCFS_H */