]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/compat.h
import ceph 14.2.5
[ceph.git] / ceph / src / include / compat.h
1 /*
2 * Ceph - scalable distributed file system
3 *
4 * Copyright (C) 2011 Stanislav Sedov <stas@FreeBSD.org>
5 *
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
10 */
11
12 #ifndef CEPH_COMPAT_H
13 #define CEPH_COMPAT_H
14
15 #include "acconfig.h"
16 #include <sys/types.h>
17
18 #if defined(__linux__)
19 #define PROCPREFIX
20 #endif
21
22 #include <sys/stat.h>
23 #ifndef ACCESSPERMS
24 #define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO)
25 #endif
26
27 #if defined(__FreeBSD__)
28
29 // FreeBSD supports Linux procfs with its compatibility module
30 // And all compatibility stuff is standard mounted on this
31 #define PROCPREFIX "/compat/linux"
32
33 #ifndef MSG_MORE
34 #define MSG_MORE 0
35 #endif
36
37 #ifndef O_DSYNC
38 #define O_DSYNC O_SYNC
39 #endif
40
41 /* And include the extra required include file */
42 #include <pthread_np.h>
43
44 #include <sys/param.h>
45 #include <sys/cpuset.h>
46 #define cpu_set_t cpuset_t
47 int sched_setaffinity(pid_t pid, size_t cpusetsize,
48 cpu_set_t *mask);
49
50 #endif /* __FreeBSD__ */
51
52 #if defined(__APPLE__) || defined(__FreeBSD__)
53 /* Make sure that ENODATA is defined in the correct way */
54 #ifdef ENODATA
55 #if (ENODATA == 9919)
56 // #warning ENODATA already defined to be 9919, redefining to fix
57 // Silencing this warning because it fires at all files where compat.h
58 // is included after boost files.
59 //
60 // This value stems from the definition in the boost library
61 // And when this case occurs it is due to the fact that boost files
62 // are included before this file. Redefinition might not help in this
63 // case since already parsed code has evaluated to the wrong value.
64 // This would warrrant for d definition that would actually be evaluated
65 // at the location of usage and report a possible conflict.
66 // This is left up to a future improvement
67 #elif (ENODATA != 87)
68 // #warning ENODATA already defined to a value different from 87 (ENOATRR), refining to fix
69 #endif
70 #undef ENODATA
71 #endif
72 #define ENODATA ENOATTR
73
74 // Fix clock accuracy
75 #if !defined(CLOCK_MONOTONIC_COARSE)
76 #if defined(CLOCK_MONOTONIC_FAST)
77 #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC_FAST
78 #else
79 #define CLOCK_MONOTONIC_COARSE CLOCK_MONOTONIC
80 #endif
81 #endif
82 #if !defined(CLOCK_REALTIME_COARSE)
83 #if defined(CLOCK_REALTIME_FAST)
84 #define CLOCK_REALTIME_COARSE CLOCK_REALTIME_FAST
85 #else
86 #define CLOCK_REALTIME_COARSE CLOCK_REALTIME
87 #endif
88 #endif
89
90 /* get PATH_MAX */
91 #include <limits.h>
92
93 #ifndef EUCLEAN
94 #define EUCLEAN 117
95 #endif
96 #ifndef EREMOTEIO
97 #define EREMOTEIO 121
98 #endif
99 #ifndef EKEYREJECTED
100 #define EKEYREJECTED 129
101 #endif
102 #ifndef XATTR_CREATE
103 #define XATTR_CREATE 1
104 #endif
105
106 #ifndef HOST_NAME_MAX
107 #ifdef MAXHOSTNAMELEN
108 #define HOST_NAME_MAX MAXHOSTNAMELEN
109 #else
110 #define HOST_NAME_MAX 255
111 #endif
112 #endif
113
114 #endif /* __APPLE__ */
115
116 /* O_LARGEFILE is not defined/required on OSX/FreeBSD */
117 #ifndef O_LARGEFILE
118 #define O_LARGEFILE 0
119 #endif
120
121 /* Could be relevant for other platforms */
122 #ifndef ERESTART
123 #define ERESTART EINTR
124 #endif
125
126 #ifndef TEMP_FAILURE_RETRY
127 #define TEMP_FAILURE_RETRY(expression) ({ \
128 __typeof(expression) __result; \
129 do { \
130 __result = (expression); \
131 } while (__result == -1 && errno == EINTR); \
132 __result; })
133 #endif
134
135 #ifdef __cplusplus
136 # define VOID_TEMP_FAILURE_RETRY(expression) \
137 static_cast<void>(TEMP_FAILURE_RETRY(expression))
138 #else
139 # define VOID_TEMP_FAILURE_RETRY(expression) \
140 do { (void)TEMP_FAILURE_RETRY(expression); } while (0)
141 #endif
142
143 #if defined(__FreeBSD__) || defined(__APPLE__)
144 #define lseek64(fd, offset, whence) lseek(fd, offset, whence)
145 #endif
146
147 #if defined(__sun) || defined(_AIX)
148 #define LOG_AUTHPRIV (10<<3)
149 #define LOG_FTP (11<<3)
150 #define __STRING(x) "x"
151 #define IFTODT(mode) (((mode) & 0170000) >> 12)
152 #endif
153
154 #if defined(_AIX)
155 #define MSG_DONTWAIT MSG_NONBLOCK
156 #endif
157
158 #if defined(HAVE_PTHREAD_SETNAME_NP)
159 #if defined(__APPLE__)
160 #define ceph_pthread_setname(thread, name) ({ \
161 int __result = 0; \
162 if (thread == pthread_self()) \
163 __result = pthread_setname_np(name); \
164 __result; })
165 #else
166 #define ceph_pthread_setname pthread_setname_np
167 #endif
168 #elif defined(HAVE_PTHREAD_SET_NAME_NP)
169 /* Fix a small name diff and return 0 */
170 #define ceph_pthread_setname(thread, name) ({ \
171 pthread_set_name_np(thread, name); \
172 0; })
173 #else
174 /* compiler warning free success noop */
175 #define ceph_pthread_setname(thread, name) ({ \
176 int __i = 0; \
177 __i; })
178 #endif
179
180 #if defined(HAVE_PTHREAD_GETNAME_NP)
181 #define ceph_pthread_getname pthread_getname_np
182 #elif defined(HAVE_PTHREAD_GET_NAME_NP)
183 #define ceph_pthread_getname(thread, name, len) ({ \
184 pthread_get_name_np(thread, name, len); \
185 0; })
186 #else
187 /* compiler warning free success noop */
188 #define ceph_pthread_getname(thread, name, len) ({ \
189 if (name != NULL) \
190 *name = '\0'; \
191 0; })
192 #endif
193
194 int ceph_posix_fallocate(int fd, off_t offset, off_t len);
195
196 int pipe_cloexec(int pipefd[2]);
197
198 #endif /* !CEPH_COMPAT_H */