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