4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.txt
23 * Copyright (C) 2011 FUJITSU LIMITED. All rights reserved.
25 * Copyright (c) 2013, 2014, Intel Corporation.
28 #include <libcfs/libcfs.h>
29 #include <lustre/lustre_errno.h>
31 #ifdef LUSTRE_TRANSLATE_ERRNOS
34 * The two translation tables below must define a one-to-one mapping between
35 * host and network errnos.
37 * EWOULDBLOCK is equal to EAGAIN on all architectures except for parisc, which
38 * appears irrelevant. Thus, existing references to EWOULDBLOCK are fine.
40 * EDEADLOCK is equal to EDEADLK on x86 but not on sparc, at least. A sparc
41 * host has no context-free way to determine if a LUSTRE_EDEADLK represents an
42 * EDEADLK or an EDEADLOCK. Therefore, all existing references to EDEADLOCK
43 * that need to be transferred on wire have been replaced with EDEADLK.
45 static int lustre_errno_hton_mapping[] = {
46 [EPERM] = LUSTRE_EPERM,
47 [ENOENT] = LUSTRE_ENOENT,
48 [ESRCH] = LUSTRE_ESRCH,
49 [EINTR] = LUSTRE_EINTR,
51 [ENXIO] = LUSTRE_ENXIO,
52 [E2BIG] = LUSTRE_E2BIG,
53 [ENOEXEC] = LUSTRE_ENOEXEC,
54 [EBADF] = LUSTRE_EBADF,
55 [ECHILD] = LUSTRE_ECHILD,
56 [EAGAIN] = LUSTRE_EAGAIN,
57 [ENOMEM] = LUSTRE_ENOMEM,
58 [EACCES] = LUSTRE_EACCES,
59 [EFAULT] = LUSTRE_EFAULT,
60 [ENOTBLK] = LUSTRE_ENOTBLK,
61 [EBUSY] = LUSTRE_EBUSY,
62 [EEXIST] = LUSTRE_EEXIST,
63 [EXDEV] = LUSTRE_EXDEV,
64 [ENODEV] = LUSTRE_ENODEV,
65 [ENOTDIR] = LUSTRE_ENOTDIR,
66 [EISDIR] = LUSTRE_EISDIR,
67 [EINVAL] = LUSTRE_EINVAL,
68 [ENFILE] = LUSTRE_ENFILE,
69 [EMFILE] = LUSTRE_EMFILE,
70 [ENOTTY] = LUSTRE_ENOTTY,
71 [ETXTBSY] = LUSTRE_ETXTBSY,
72 [EFBIG] = LUSTRE_EFBIG,
73 [ENOSPC] = LUSTRE_ENOSPC,
74 [ESPIPE] = LUSTRE_ESPIPE,
75 [EROFS] = LUSTRE_EROFS,
76 [EMLINK] = LUSTRE_EMLINK,
77 [EPIPE] = LUSTRE_EPIPE,
79 [ERANGE] = LUSTRE_ERANGE,
80 [EDEADLK] = LUSTRE_EDEADLK,
81 [ENAMETOOLONG] = LUSTRE_ENAMETOOLONG,
82 [ENOLCK] = LUSTRE_ENOLCK,
83 [ENOSYS] = LUSTRE_ENOSYS,
84 [ENOTEMPTY] = LUSTRE_ENOTEMPTY,
85 [ELOOP] = LUSTRE_ELOOP,
86 [ENOMSG] = LUSTRE_ENOMSG,
87 [EIDRM] = LUSTRE_EIDRM,
88 [ECHRNG] = LUSTRE_ECHRNG,
89 [EL2NSYNC] = LUSTRE_EL2NSYNC,
90 [EL3HLT] = LUSTRE_EL3HLT,
91 [EL3RST] = LUSTRE_EL3RST,
92 [ELNRNG] = LUSTRE_ELNRNG,
93 [EUNATCH] = LUSTRE_EUNATCH,
94 [ENOCSI] = LUSTRE_ENOCSI,
95 [EL2HLT] = LUSTRE_EL2HLT,
96 [EBADE] = LUSTRE_EBADE,
97 [EBADR] = LUSTRE_EBADR,
98 [EXFULL] = LUSTRE_EXFULL,
99 [ENOANO] = LUSTRE_ENOANO,
100 [EBADRQC] = LUSTRE_EBADRQC,
101 [EBADSLT] = LUSTRE_EBADSLT,
102 [EBFONT] = LUSTRE_EBFONT,
103 [ENOSTR] = LUSTRE_ENOSTR,
104 [ENODATA] = LUSTRE_ENODATA,
105 [ETIME] = LUSTRE_ETIME,
106 [ENOSR] = LUSTRE_ENOSR,
107 [ENONET] = LUSTRE_ENONET,
108 [ENOPKG] = LUSTRE_ENOPKG,
109 [EREMOTE] = LUSTRE_EREMOTE,
110 [ENOLINK] = LUSTRE_ENOLINK,
111 [EADV] = LUSTRE_EADV,
112 [ESRMNT] = LUSTRE_ESRMNT,
113 [ECOMM] = LUSTRE_ECOMM,
114 [EPROTO] = LUSTRE_EPROTO,
115 [EMULTIHOP] = LUSTRE_EMULTIHOP,
116 [EDOTDOT] = LUSTRE_EDOTDOT,
117 [EBADMSG] = LUSTRE_EBADMSG,
118 [EOVERFLOW] = LUSTRE_EOVERFLOW,
119 [ENOTUNIQ] = LUSTRE_ENOTUNIQ,
120 [EBADFD] = LUSTRE_EBADFD,
121 [EREMCHG] = LUSTRE_EREMCHG,
122 [ELIBACC] = LUSTRE_ELIBACC,
123 [ELIBBAD] = LUSTRE_ELIBBAD,
124 [ELIBSCN] = LUSTRE_ELIBSCN,
125 [ELIBMAX] = LUSTRE_ELIBMAX,
126 [ELIBEXEC] = LUSTRE_ELIBEXEC,
127 [EILSEQ] = LUSTRE_EILSEQ,
128 [ERESTART] = LUSTRE_ERESTART,
129 [ESTRPIPE] = LUSTRE_ESTRPIPE,
130 [EUSERS] = LUSTRE_EUSERS,
131 [ENOTSOCK] = LUSTRE_ENOTSOCK,
132 [EDESTADDRREQ] = LUSTRE_EDESTADDRREQ,
133 [EMSGSIZE] = LUSTRE_EMSGSIZE,
134 [EPROTOTYPE] = LUSTRE_EPROTOTYPE,
135 [ENOPROTOOPT] = LUSTRE_ENOPROTOOPT,
136 [EPROTONOSUPPORT] = LUSTRE_EPROTONOSUPPORT,
137 [ESOCKTNOSUPPORT] = LUSTRE_ESOCKTNOSUPPORT,
138 [EOPNOTSUPP] = LUSTRE_EOPNOTSUPP,
139 [EPFNOSUPPORT] = LUSTRE_EPFNOSUPPORT,
140 [EAFNOSUPPORT] = LUSTRE_EAFNOSUPPORT,
141 [EADDRINUSE] = LUSTRE_EADDRINUSE,
142 [EADDRNOTAVAIL] = LUSTRE_EADDRNOTAVAIL,
143 [ENETDOWN] = LUSTRE_ENETDOWN,
144 [ENETUNREACH] = LUSTRE_ENETUNREACH,
145 [ENETRESET] = LUSTRE_ENETRESET,
146 [ECONNABORTED] = LUSTRE_ECONNABORTED,
147 [ECONNRESET] = LUSTRE_ECONNRESET,
148 [ENOBUFS] = LUSTRE_ENOBUFS,
149 [EISCONN] = LUSTRE_EISCONN,
150 [ENOTCONN] = LUSTRE_ENOTCONN,
151 [ESHUTDOWN] = LUSTRE_ESHUTDOWN,
152 [ETOOMANYREFS] = LUSTRE_ETOOMANYREFS,
153 [ETIMEDOUT] = LUSTRE_ETIMEDOUT,
154 [ECONNREFUSED] = LUSTRE_ECONNREFUSED,
155 [EHOSTDOWN] = LUSTRE_EHOSTDOWN,
156 [EHOSTUNREACH] = LUSTRE_EHOSTUNREACH,
157 [EALREADY] = LUSTRE_EALREADY,
158 [EINPROGRESS] = LUSTRE_EINPROGRESS,
159 [ESTALE] = LUSTRE_ESTALE,
160 [EUCLEAN] = LUSTRE_EUCLEAN,
161 [ENOTNAM] = LUSTRE_ENOTNAM,
162 [ENAVAIL] = LUSTRE_ENAVAIL,
163 [EISNAM] = LUSTRE_EISNAM,
164 [EREMOTEIO] = LUSTRE_EREMOTEIO,
165 [EDQUOT] = LUSTRE_EDQUOT,
166 [ENOMEDIUM] = LUSTRE_ENOMEDIUM,
167 [EMEDIUMTYPE] = LUSTRE_EMEDIUMTYPE,
168 [ECANCELED] = LUSTRE_ECANCELED,
169 [ENOKEY] = LUSTRE_ENOKEY,
170 [EKEYEXPIRED] = LUSTRE_EKEYEXPIRED,
171 [EKEYREVOKED] = LUSTRE_EKEYREVOKED,
172 [EKEYREJECTED] = LUSTRE_EKEYREJECTED,
173 [EOWNERDEAD] = LUSTRE_EOWNERDEAD,
174 [ENOTRECOVERABLE] = LUSTRE_ENOTRECOVERABLE,
175 [ERESTARTSYS] = LUSTRE_ERESTARTSYS,
176 [ERESTARTNOINTR] = LUSTRE_ERESTARTNOINTR,
177 [ERESTARTNOHAND] = LUSTRE_ERESTARTNOHAND,
178 [ENOIOCTLCMD] = LUSTRE_ENOIOCTLCMD,
179 [ERESTART_RESTARTBLOCK] = LUSTRE_ERESTART_RESTARTBLOCK,
180 [EBADHANDLE] = LUSTRE_EBADHANDLE,
181 [ENOTSYNC] = LUSTRE_ENOTSYNC,
182 [EBADCOOKIE] = LUSTRE_EBADCOOKIE,
183 [ENOTSUPP] = LUSTRE_ENOTSUPP,
184 [ETOOSMALL] = LUSTRE_ETOOSMALL,
185 [ESERVERFAULT] = LUSTRE_ESERVERFAULT,
186 [EBADTYPE] = LUSTRE_EBADTYPE,
187 [EJUKEBOX] = LUSTRE_EJUKEBOX,
188 [EIOCBQUEUED] = LUSTRE_EIOCBQUEUED,
189 [EIOCBRETRY] = LUSTRE_EIOCBRETRY
192 static int lustre_errno_ntoh_mapping[] = {
193 [LUSTRE_EPERM] = EPERM,
194 [LUSTRE_ENOENT] = ENOENT,
195 [LUSTRE_ESRCH] = ESRCH,
196 [LUSTRE_EINTR] = EINTR,
198 [LUSTRE_ENXIO] = ENXIO,
199 [LUSTRE_E2BIG] = E2BIG,
200 [LUSTRE_ENOEXEC] = ENOEXEC,
201 [LUSTRE_EBADF] = EBADF,
202 [LUSTRE_ECHILD] = ECHILD,
203 [LUSTRE_EAGAIN] = EAGAIN,
204 [LUSTRE_ENOMEM] = ENOMEM,
205 [LUSTRE_EACCES] = EACCES,
206 [LUSTRE_EFAULT] = EFAULT,
207 [LUSTRE_ENOTBLK] = ENOTBLK,
208 [LUSTRE_EBUSY] = EBUSY,
209 [LUSTRE_EEXIST] = EEXIST,
210 [LUSTRE_EXDEV] = EXDEV,
211 [LUSTRE_ENODEV] = ENODEV,
212 [LUSTRE_ENOTDIR] = ENOTDIR,
213 [LUSTRE_EISDIR] = EISDIR,
214 [LUSTRE_EINVAL] = EINVAL,
215 [LUSTRE_ENFILE] = ENFILE,
216 [LUSTRE_EMFILE] = EMFILE,
217 [LUSTRE_ENOTTY] = ENOTTY,
218 [LUSTRE_ETXTBSY] = ETXTBSY,
219 [LUSTRE_EFBIG] = EFBIG,
220 [LUSTRE_ENOSPC] = ENOSPC,
221 [LUSTRE_ESPIPE] = ESPIPE,
222 [LUSTRE_EROFS] = EROFS,
223 [LUSTRE_EMLINK] = EMLINK,
224 [LUSTRE_EPIPE] = EPIPE,
225 [LUSTRE_EDOM] = EDOM,
226 [LUSTRE_ERANGE] = ERANGE,
227 [LUSTRE_EDEADLK] = EDEADLK,
228 [LUSTRE_ENAMETOOLONG] = ENAMETOOLONG,
229 [LUSTRE_ENOLCK] = ENOLCK,
230 [LUSTRE_ENOSYS] = ENOSYS,
231 [LUSTRE_ENOTEMPTY] = ENOTEMPTY,
232 [LUSTRE_ELOOP] = ELOOP,
233 [LUSTRE_ENOMSG] = ENOMSG,
234 [LUSTRE_EIDRM] = EIDRM,
235 [LUSTRE_ECHRNG] = ECHRNG,
236 [LUSTRE_EL2NSYNC] = EL2NSYNC,
237 [LUSTRE_EL3HLT] = EL3HLT,
238 [LUSTRE_EL3RST] = EL3RST,
239 [LUSTRE_ELNRNG] = ELNRNG,
240 [LUSTRE_EUNATCH] = EUNATCH,
241 [LUSTRE_ENOCSI] = ENOCSI,
242 [LUSTRE_EL2HLT] = EL2HLT,
243 [LUSTRE_EBADE] = EBADE,
244 [LUSTRE_EBADR] = EBADR,
245 [LUSTRE_EXFULL] = EXFULL,
246 [LUSTRE_ENOANO] = ENOANO,
247 [LUSTRE_EBADRQC] = EBADRQC,
248 [LUSTRE_EBADSLT] = EBADSLT,
249 [LUSTRE_EBFONT] = EBFONT,
250 [LUSTRE_ENOSTR] = ENOSTR,
251 [LUSTRE_ENODATA] = ENODATA,
252 [LUSTRE_ETIME] = ETIME,
253 [LUSTRE_ENOSR] = ENOSR,
254 [LUSTRE_ENONET] = ENONET,
255 [LUSTRE_ENOPKG] = ENOPKG,
256 [LUSTRE_EREMOTE] = EREMOTE,
257 [LUSTRE_ENOLINK] = ENOLINK,
258 [LUSTRE_EADV] = EADV,
259 [LUSTRE_ESRMNT] = ESRMNT,
260 [LUSTRE_ECOMM] = ECOMM,
261 [LUSTRE_EPROTO] = EPROTO,
262 [LUSTRE_EMULTIHOP] = EMULTIHOP,
263 [LUSTRE_EDOTDOT] = EDOTDOT,
264 [LUSTRE_EBADMSG] = EBADMSG,
265 [LUSTRE_EOVERFLOW] = EOVERFLOW,
266 [LUSTRE_ENOTUNIQ] = ENOTUNIQ,
267 [LUSTRE_EBADFD] = EBADFD,
268 [LUSTRE_EREMCHG] = EREMCHG,
269 [LUSTRE_ELIBACC] = ELIBACC,
270 [LUSTRE_ELIBBAD] = ELIBBAD,
271 [LUSTRE_ELIBSCN] = ELIBSCN,
272 [LUSTRE_ELIBMAX] = ELIBMAX,
273 [LUSTRE_ELIBEXEC] = ELIBEXEC,
274 [LUSTRE_EILSEQ] = EILSEQ,
275 [LUSTRE_ERESTART] = ERESTART,
276 [LUSTRE_ESTRPIPE] = ESTRPIPE,
277 [LUSTRE_EUSERS] = EUSERS,
278 [LUSTRE_ENOTSOCK] = ENOTSOCK,
279 [LUSTRE_EDESTADDRREQ] = EDESTADDRREQ,
280 [LUSTRE_EMSGSIZE] = EMSGSIZE,
281 [LUSTRE_EPROTOTYPE] = EPROTOTYPE,
282 [LUSTRE_ENOPROTOOPT] = ENOPROTOOPT,
283 [LUSTRE_EPROTONOSUPPORT] = EPROTONOSUPPORT,
284 [LUSTRE_ESOCKTNOSUPPORT] = ESOCKTNOSUPPORT,
285 [LUSTRE_EOPNOTSUPP] = EOPNOTSUPP,
286 [LUSTRE_EPFNOSUPPORT] = EPFNOSUPPORT,
287 [LUSTRE_EAFNOSUPPORT] = EAFNOSUPPORT,
288 [LUSTRE_EADDRINUSE] = EADDRINUSE,
289 [LUSTRE_EADDRNOTAVAIL] = EADDRNOTAVAIL,
290 [LUSTRE_ENETDOWN] = ENETDOWN,
291 [LUSTRE_ENETUNREACH] = ENETUNREACH,
292 [LUSTRE_ENETRESET] = ENETRESET,
293 [LUSTRE_ECONNABORTED] = ECONNABORTED,
294 [LUSTRE_ECONNRESET] = ECONNRESET,
295 [LUSTRE_ENOBUFS] = ENOBUFS,
296 [LUSTRE_EISCONN] = EISCONN,
297 [LUSTRE_ENOTCONN] = ENOTCONN,
298 [LUSTRE_ESHUTDOWN] = ESHUTDOWN,
299 [LUSTRE_ETOOMANYREFS] = ETOOMANYREFS,
300 [LUSTRE_ETIMEDOUT] = ETIMEDOUT,
301 [LUSTRE_ECONNREFUSED] = ECONNREFUSED,
302 [LUSTRE_EHOSTDOWN] = EHOSTDOWN,
303 [LUSTRE_EHOSTUNREACH] = EHOSTUNREACH,
304 [LUSTRE_EALREADY] = EALREADY,
305 [LUSTRE_EINPROGRESS] = EINPROGRESS,
306 [LUSTRE_ESTALE] = ESTALE,
307 [LUSTRE_EUCLEAN] = EUCLEAN,
308 [LUSTRE_ENOTNAM] = ENOTNAM,
309 [LUSTRE_ENAVAIL] = ENAVAIL,
310 [LUSTRE_EISNAM] = EISNAM,
311 [LUSTRE_EREMOTEIO] = EREMOTEIO,
312 [LUSTRE_EDQUOT] = EDQUOT,
313 [LUSTRE_ENOMEDIUM] = ENOMEDIUM,
314 [LUSTRE_EMEDIUMTYPE] = EMEDIUMTYPE,
315 [LUSTRE_ECANCELED] = ECANCELED,
316 [LUSTRE_ENOKEY] = ENOKEY,
317 [LUSTRE_EKEYEXPIRED] = EKEYEXPIRED,
318 [LUSTRE_EKEYREVOKED] = EKEYREVOKED,
319 [LUSTRE_EKEYREJECTED] = EKEYREJECTED,
320 [LUSTRE_EOWNERDEAD] = EOWNERDEAD,
321 [LUSTRE_ENOTRECOVERABLE] = ENOTRECOVERABLE,
322 [LUSTRE_ERESTARTSYS] = ERESTARTSYS,
323 [LUSTRE_ERESTARTNOINTR] = ERESTARTNOINTR,
324 [LUSTRE_ERESTARTNOHAND] = ERESTARTNOHAND,
325 [LUSTRE_ENOIOCTLCMD] = ENOIOCTLCMD,
326 [LUSTRE_ERESTART_RESTARTBLOCK] = ERESTART_RESTARTBLOCK,
327 [LUSTRE_EBADHANDLE] = EBADHANDLE,
328 [LUSTRE_ENOTSYNC] = ENOTSYNC,
329 [LUSTRE_EBADCOOKIE] = EBADCOOKIE,
330 [LUSTRE_ENOTSUPP] = ENOTSUPP,
331 [LUSTRE_ETOOSMALL] = ETOOSMALL,
332 [LUSTRE_ESERVERFAULT] = ESERVERFAULT,
333 [LUSTRE_EBADTYPE] = EBADTYPE,
334 [LUSTRE_EJUKEBOX] = EJUKEBOX,
335 [LUSTRE_EIOCBQUEUED] = EIOCBQUEUED,
336 [LUSTRE_EIOCBRETRY] = EIOCBRETRY
339 unsigned int lustre_errno_hton(unsigned int h)
345 } else if (h < ARRAY_SIZE(lustre_errno_hton_mapping)) {
346 n = lustre_errno_hton_mapping[h];
352 * A generic errno is better than the unknown one that could
353 * mean anything to a different host.
360 EXPORT_SYMBOL(lustre_errno_hton);
362 unsigned int lustre_errno_ntoh(unsigned int n)
368 } else if (n < ARRAY_SIZE(lustre_errno_ntoh_mapping)) {
369 h = lustre_errno_ntoh_mapping[n];
375 * Similar to the situation in lustre_errno_hton(), an unknown
376 * network errno could coincide with anything. Hence, it is
377 * better to return a generic errno.
384 EXPORT_SYMBOL(lustre_errno_ntoh);
386 #endif /* LUSTRE_TRANSLATE_ERRNOS */