Whamcloud - gitweb
LU-2456 lnet: DLC Feature dynamic net config
[fs/lustre-release.git] / libcfs / include / libcfs / darwin / 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  * Copyright (c) 2012, Intel Corporation.
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_DARWIN_LIBCFS_H__
38 #define __LIBCFS_DARWIN_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 #include <mach/mach_types.h>
45 #include <sys/errno.h>
46 #include <string.h>
47 #include <libcfs/darwin/darwin-types.h>
48 #include <libcfs/darwin/darwin-time.h>
49 #include <libcfs/darwin/darwin-prim.h>
50 #include <libcfs/darwin/darwin-mem.h>
51 #include <libcfs/darwin/darwin-lock.h>
52 #include <libcfs/darwin/darwin-fs.h>
53 #include <libcfs/darwin/darwin-tcpip.h>
54 #include <libcfs/darwin/kp30.h>
55
56 #ifdef __KERNEL__
57 # include <sys/types.h>
58 # include <sys/time.h>
59 # define do_gettimeofday(tv) microuptime(tv)
60 #else
61 # include <sys/time.h>
62 # define do_gettimeofday(tv) gettimeofday(tv, NULL);
63 typedef unsigned long long cycles_t;
64 #endif
65
66 #define __cpu_to_le64(x)                        OSSwapHostToLittleInt64(x)
67 #define __cpu_to_le32(x)                        OSSwapHostToLittleInt32(x)
68 #define __cpu_to_le16(x)                        OSSwapHostToLittleInt16(x)
69
70 #define __le16_to_cpu(x)                        OSSwapLittleToHostInt16(x)
71 #define __le32_to_cpu(x)                        OSSwapLittleToHostInt32(x)
72 #define __le64_to_cpu(x)                        OSSwapLittleToHostInt64(x)
73
74 #define cpu_to_le64(x)                          __cpu_to_le64(x)
75 #define cpu_to_le32(x)                          __cpu_to_le32(x)
76 #define cpu_to_le16(x)                          __cpu_to_le16(x)
77
78 #define le64_to_cpu(x)                          __le64_to_cpu(x)
79 #define le32_to_cpu(x)                          __le32_to_cpu(x)
80 #define le16_to_cpu(x)                          __le16_to_cpu(x)
81
82 #define __swab16(x)                             OSSwapInt16(x)
83 #define __swab32(x)                             OSSwapInt32(x)
84 #define __swab64(x)                             OSSwapInt64(x)
85 #define __swab16s(x)                            do { *(x) = __swab16(*(x)); } while (0)
86 #define __swab32s(x)                            do { *(x) = __swab32(*(x)); } while (0)
87 #define __swab64s(x)                            do { *(x) = __swab64(*(x)); } while (0)
88
89
90 #ifdef __KERNEL__
91 # include <sys/systm.h>
92 # include <pexpert/pexpert.h>
93 /* Fix me */
94 # define THREAD_SIZE 8192
95 #else
96 # define THREAD_SIZE 8192
97 #endif
98
99 #define CHECK_STACK(msgdata, mask, cdls) do {} while(0)
100 #define CDEBUG_STACK() (0L)
101
102 /* Darwin has defined RETURN, so we have to undef it in lustre */
103 #ifdef RETURN
104 #undef RETURN
105 #endif
106
107 /*
108  * When this is enabled debugging messages are indented according to the
109  * current "nesting level". Nesting level in increased when ENTRY macro
110  * is executed, and decreased on EXIT and RETURN.
111  */
112 #ifdef __KERNEL__
113 #define ENTRY_NESTING_SUPPORT (0)
114 #endif
115
116 #if ENTRY_NESTING_SUPPORT
117
118 /*
119  * Currently ENTRY_NESTING_SUPPORT is only supported for XNU port. Basic
120  * idea is to keep per-thread pointer to small data structure (struct
121  * cfs_debug_data) describing current nesting level. In XNU unused
122  * proc->p_wmegs field in hijacked for this. On Linux
123  * current->journal_info can be used. In user space
124  * pthread_{g,s}etspecific().
125  *
126  * ENTRY macro allocates new cfs_debug_data on stack, and installs it as
127  * a current nesting level, storing old data in cfs_debug_data it just
128  * created.
129  *
130  * EXIT pops old value back.
131  *
132  */
133
134 /*
135  * One problem with this approach is that there is a lot of code that
136  * does ENTRY and then escapes scope without doing EXIT/RETURN. In this
137  * case per-thread current nesting level pointer is dangling (it points
138  * to the stack area that is possible already overridden). To detect
139  * such cases, we add two magic fields to the cfs_debug_data and check
140  * them whenever current nesting level pointer is dereferenced. While
141  * looking flaky this works because stack is always consumed
142  * "continously".
143  */
144 enum {
145         CDD_MAGIC1 = 0x02128506,
146         CDD_MAGIC2 = 0x42424242
147 };
148
149 struct cfs_debug_data {
150         unsigned int           magic1;
151         struct cfs_debug_data *parent;
152         int                    nesting_level;
153         unsigned int           magic2;
154 };
155
156 void __entry_nesting(struct cfs_debug_data *child);
157 void __exit_nesting(struct cfs_debug_data *child);
158 unsigned int __current_nesting_level(void);
159
160 #define ENTRY_NESTING                                           \
161 struct cfs_debug_data __cdd = { .magic1        = CDD_MAGIC1,    \
162                                 .parent        = NULL,          \
163                                 .nesting_level = 0,             \
164                                 .magic2        = CDD_MAGIC2 };  \
165 __entry_nesting(&__cdd);
166
167 #define EXIT_NESTING __exit_nesting(&__cdd)
168
169 /* ENTRY_NESTING_SUPPORT */
170 #else
171
172 #define ENTRY_NESTING   do {;} while (0)
173 #define EXIT_NESTING   do {;} while (0)
174 #define __current_nesting_level() (0)
175
176 /* ENTRY_NESTING_SUPPORT */
177 #endif
178
179 #define LUSTRE_LNET_PID          12345
180
181 #define _XNU_LIBCFS_H
182
183 /*
184  * Platform specific declarations for cfs_curproc API (libcfs/curproc.h)
185  *
186  * Implementation is in darwin-curproc.c
187  */
188 #define CFS_CURPROC_COMM_MAX    MAXCOMLEN
189 /*
190  * XNU has no capabilities
191  */
192 typedef __u32 kernel_cap_t;
193
194 #ifdef __KERNEL__
195 enum {
196         /* if you change this, update darwin-util.c:cfs_stack_trace_fill() */
197         CFS_STACK_TRACE_DEPTH = 16
198 };
199
200 struct cfs_stack_trace {
201         void *frame[CFS_STACK_TRACE_DEPTH];
202 };
203
204 #define printk(format, args...)                 printf(format, ## args)
205
206 #ifdef WITH_WATCHDOG
207 #undef WITH_WATCHDOG
208 #endif
209
210 /*
211  * Portable API to access common characteristics of "current" UNIX process.
212  */
213 uid_t  current_uid(void);
214 gid_t  current_gid(void);
215 uid_t  current_euid(void);
216 gid_t  current_egid(void);
217 uid_t  current_fsuid(void);
218 gid_t  current_fsgid(void);
219 pid_t  current_pid(void);
220 int    in_group_p(gid_t group);
221 mode_t current_umask(void);
222 char  *current_comm(void);
223
224 /* check if task is running in compat mode.*/
225 int current_is_32bit(void);
226
227 #endif /* __KERNEL__ */
228
229 #endif /* _XNU_LIBCFS_H */