Whamcloud - gitweb
LU-5162 mdc: Add exception entry check for radix_tree
[fs/lustre-release.git] / lustre / ptlrpc / errno.c
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.gnu.org/licenses/gpl-2.0.txt
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (C) 2011 FUJITSU LIMITED.  All rights reserved.
24  *
25  * Copyright (c) 2013, Intel Corporation.
26  */
27
28 #include <libcfs/libcfs.h>
29 #include <lustre/lustre_errno.h>
30
31 #ifdef LUSTRE_TRANSLATE_ERRNOS
32
33 /*
34  * The two translation tables below must define a one-to-one mapping between
35  * host and network errnos.
36  *
37  * EWOULDBLOCK is equal to EAGAIN on all architectures except for parisc, which
38  * appears irrelevant.  Thus, existing references to EWOULDBLOCK are fine.
39  *
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.
44  */
45 static int lustre_errno_hton_mapping[] = {
46         [EPERM]                 = LUSTRE_EPERM,
47         [ENOENT]                = LUSTRE_ENOENT,
48         [ESRCH]                 = LUSTRE_ESRCH,
49         [EINTR]                 = LUSTRE_EINTR,
50         [EIO]                   = LUSTRE_EIO,
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,
78         [EDOM]                  = LUSTRE_EDOM,
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 #ifdef __KERNEL__
176         [ERESTARTSYS]           = LUSTRE_ERESTARTSYS,
177         [ERESTARTNOINTR]        = LUSTRE_ERESTARTNOINTR,
178         [ERESTARTNOHAND]        = LUSTRE_ERESTARTNOHAND,
179         [ENOIOCTLCMD]           = LUSTRE_ENOIOCTLCMD,
180         [ERESTART_RESTARTBLOCK] = LUSTRE_ERESTART_RESTARTBLOCK,
181         [EBADHANDLE]            = LUSTRE_EBADHANDLE,
182         [ENOTSYNC]              = LUSTRE_ENOTSYNC,
183         [EBADCOOKIE]            = LUSTRE_EBADCOOKIE,
184         [ENOTSUPP]              = LUSTRE_ENOTSUPP,
185         [ETOOSMALL]             = LUSTRE_ETOOSMALL,
186         [ESERVERFAULT]          = LUSTRE_ESERVERFAULT,
187         [EBADTYPE]              = LUSTRE_EBADTYPE,
188         [EJUKEBOX]              = LUSTRE_EJUKEBOX,
189         [EIOCBQUEUED]           = LUSTRE_EIOCBQUEUED,
190         [EIOCBRETRY]            = LUSTRE_EIOCBRETRY
191 #endif
192 };
193
194 static int lustre_errno_ntoh_mapping[] = {
195         [LUSTRE_EPERM]                  = EPERM,
196         [LUSTRE_ENOENT]                 = ENOENT,
197         [LUSTRE_ESRCH]                  = ESRCH,
198         [LUSTRE_EINTR]                  = EINTR,
199         [LUSTRE_EIO]                    = EIO,
200         [LUSTRE_ENXIO]                  = ENXIO,
201         [LUSTRE_E2BIG]                  = E2BIG,
202         [LUSTRE_ENOEXEC]                = ENOEXEC,
203         [LUSTRE_EBADF]                  = EBADF,
204         [LUSTRE_ECHILD]                 = ECHILD,
205         [LUSTRE_EAGAIN]                 = EAGAIN,
206         [LUSTRE_ENOMEM]                 = ENOMEM,
207         [LUSTRE_EACCES]                 = EACCES,
208         [LUSTRE_EFAULT]                 = EFAULT,
209         [LUSTRE_ENOTBLK]                = ENOTBLK,
210         [LUSTRE_EBUSY]                  = EBUSY,
211         [LUSTRE_EEXIST]                 = EEXIST,
212         [LUSTRE_EXDEV]                  = EXDEV,
213         [LUSTRE_ENODEV]                 = ENODEV,
214         [LUSTRE_ENOTDIR]                = ENOTDIR,
215         [LUSTRE_EISDIR]                 = EISDIR,
216         [LUSTRE_EINVAL]                 = EINVAL,
217         [LUSTRE_ENFILE]                 = ENFILE,
218         [LUSTRE_EMFILE]                 = EMFILE,
219         [LUSTRE_ENOTTY]                 = ENOTTY,
220         [LUSTRE_ETXTBSY]                = ETXTBSY,
221         [LUSTRE_EFBIG]                  = EFBIG,
222         [LUSTRE_ENOSPC]                 = ENOSPC,
223         [LUSTRE_ESPIPE]                 = ESPIPE,
224         [LUSTRE_EROFS]                  = EROFS,
225         [LUSTRE_EMLINK]                 = EMLINK,
226         [LUSTRE_EPIPE]                  = EPIPE,
227         [LUSTRE_EDOM]                   = EDOM,
228         [LUSTRE_ERANGE]                 = ERANGE,
229         [LUSTRE_EDEADLK]                = EDEADLK,
230         [LUSTRE_ENAMETOOLONG]           = ENAMETOOLONG,
231         [LUSTRE_ENOLCK]                 = ENOLCK,
232         [LUSTRE_ENOSYS]                 = ENOSYS,
233         [LUSTRE_ENOTEMPTY]              = ENOTEMPTY,
234         [LUSTRE_ELOOP]                  = ELOOP,
235         [LUSTRE_ENOMSG]                 = ENOMSG,
236         [LUSTRE_EIDRM]                  = EIDRM,
237         [LUSTRE_ECHRNG]                 = ECHRNG,
238         [LUSTRE_EL2NSYNC]               = EL2NSYNC,
239         [LUSTRE_EL3HLT]                 = EL3HLT,
240         [LUSTRE_EL3RST]                 = EL3RST,
241         [LUSTRE_ELNRNG]                 = ELNRNG,
242         [LUSTRE_EUNATCH]                = EUNATCH,
243         [LUSTRE_ENOCSI]                 = ENOCSI,
244         [LUSTRE_EL2HLT]                 = EL2HLT,
245         [LUSTRE_EBADE]                  = EBADE,
246         [LUSTRE_EBADR]                  = EBADR,
247         [LUSTRE_EXFULL]                 = EXFULL,
248         [LUSTRE_ENOANO]                 = ENOANO,
249         [LUSTRE_EBADRQC]                = EBADRQC,
250         [LUSTRE_EBADSLT]                = EBADSLT,
251         [LUSTRE_EBFONT]                 = EBFONT,
252         [LUSTRE_ENOSTR]                 = ENOSTR,
253         [LUSTRE_ENODATA]                = ENODATA,
254         [LUSTRE_ETIME]                  = ETIME,
255         [LUSTRE_ENOSR]                  = ENOSR,
256         [LUSTRE_ENONET]                 = ENONET,
257         [LUSTRE_ENOPKG]                 = ENOPKG,
258         [LUSTRE_EREMOTE]                = EREMOTE,
259         [LUSTRE_ENOLINK]                = ENOLINK,
260         [LUSTRE_EADV]                   = EADV,
261         [LUSTRE_ESRMNT]                 = ESRMNT,
262         [LUSTRE_ECOMM]                  = ECOMM,
263         [LUSTRE_EPROTO]                 = EPROTO,
264         [LUSTRE_EMULTIHOP]              = EMULTIHOP,
265         [LUSTRE_EDOTDOT]                = EDOTDOT,
266         [LUSTRE_EBADMSG]                = EBADMSG,
267         [LUSTRE_EOVERFLOW]              = EOVERFLOW,
268         [LUSTRE_ENOTUNIQ]               = ENOTUNIQ,
269         [LUSTRE_EBADFD]                 = EBADFD,
270         [LUSTRE_EREMCHG]                = EREMCHG,
271         [LUSTRE_ELIBACC]                = ELIBACC,
272         [LUSTRE_ELIBBAD]                = ELIBBAD,
273         [LUSTRE_ELIBSCN]                = ELIBSCN,
274         [LUSTRE_ELIBMAX]                = ELIBMAX,
275         [LUSTRE_ELIBEXEC]               = ELIBEXEC,
276         [LUSTRE_EILSEQ]                 = EILSEQ,
277         [LUSTRE_ERESTART]               = ERESTART,
278         [LUSTRE_ESTRPIPE]               = ESTRPIPE,
279         [LUSTRE_EUSERS]                 = EUSERS,
280         [LUSTRE_ENOTSOCK]               = ENOTSOCK,
281         [LUSTRE_EDESTADDRREQ]           = EDESTADDRREQ,
282         [LUSTRE_EMSGSIZE]               = EMSGSIZE,
283         [LUSTRE_EPROTOTYPE]             = EPROTOTYPE,
284         [LUSTRE_ENOPROTOOPT]            = ENOPROTOOPT,
285         [LUSTRE_EPROTONOSUPPORT]        = EPROTONOSUPPORT,
286         [LUSTRE_ESOCKTNOSUPPORT]        = ESOCKTNOSUPPORT,
287         [LUSTRE_EOPNOTSUPP]             = EOPNOTSUPP,
288         [LUSTRE_EPFNOSUPPORT]           = EPFNOSUPPORT,
289         [LUSTRE_EAFNOSUPPORT]           = EAFNOSUPPORT,
290         [LUSTRE_EADDRINUSE]             = EADDRINUSE,
291         [LUSTRE_EADDRNOTAVAIL]          = EADDRNOTAVAIL,
292         [LUSTRE_ENETDOWN]               = ENETDOWN,
293         [LUSTRE_ENETUNREACH]            = ENETUNREACH,
294         [LUSTRE_ENETRESET]              = ENETRESET,
295         [LUSTRE_ECONNABORTED]           = ECONNABORTED,
296         [LUSTRE_ECONNRESET]             = ECONNRESET,
297         [LUSTRE_ENOBUFS]                = ENOBUFS,
298         [LUSTRE_EISCONN]                = EISCONN,
299         [LUSTRE_ENOTCONN]               = ENOTCONN,
300         [LUSTRE_ESHUTDOWN]              = ESHUTDOWN,
301         [LUSTRE_ETOOMANYREFS]           = ETOOMANYREFS,
302         [LUSTRE_ETIMEDOUT]              = ETIMEDOUT,
303         [LUSTRE_ECONNREFUSED]           = ECONNREFUSED,
304         [LUSTRE_EHOSTDOWN]              = EHOSTDOWN,
305         [LUSTRE_EHOSTUNREACH]           = EHOSTUNREACH,
306         [LUSTRE_EALREADY]               = EALREADY,
307         [LUSTRE_EINPROGRESS]            = EINPROGRESS,
308         [LUSTRE_ESTALE]                 = ESTALE,
309         [LUSTRE_EUCLEAN]                = EUCLEAN,
310         [LUSTRE_ENOTNAM]                = ENOTNAM,
311         [LUSTRE_ENAVAIL]                = ENAVAIL,
312         [LUSTRE_EISNAM]                 = EISNAM,
313         [LUSTRE_EREMOTEIO]              = EREMOTEIO,
314         [LUSTRE_EDQUOT]                 = EDQUOT,
315         [LUSTRE_ENOMEDIUM]              = ENOMEDIUM,
316         [LUSTRE_EMEDIUMTYPE]            = EMEDIUMTYPE,
317         [LUSTRE_ECANCELED]              = ECANCELED,
318         [LUSTRE_ENOKEY]                 = ENOKEY,
319         [LUSTRE_EKEYEXPIRED]            = EKEYEXPIRED,
320         [LUSTRE_EKEYREVOKED]            = EKEYREVOKED,
321         [LUSTRE_EKEYREJECTED]           = EKEYREJECTED,
322         [LUSTRE_EOWNERDEAD]             = EOWNERDEAD,
323         [LUSTRE_ENOTRECOVERABLE]        = ENOTRECOVERABLE,
324 #ifdef __KERNEL__
325         [LUSTRE_ERESTARTSYS]            = ERESTARTSYS,
326         [LUSTRE_ERESTARTNOINTR]         = ERESTARTNOINTR,
327         [LUSTRE_ERESTARTNOHAND]         = ERESTARTNOHAND,
328         [LUSTRE_ENOIOCTLCMD]            = ENOIOCTLCMD,
329         [LUSTRE_ERESTART_RESTARTBLOCK]  = ERESTART_RESTARTBLOCK,
330         [LUSTRE_EBADHANDLE]             = EBADHANDLE,
331         [LUSTRE_ENOTSYNC]               = ENOTSYNC,
332         [LUSTRE_EBADCOOKIE]             = EBADCOOKIE,
333         [LUSTRE_ENOTSUPP]               = ENOTSUPP,
334         [LUSTRE_ETOOSMALL]              = ETOOSMALL,
335         [LUSTRE_ESERVERFAULT]           = ESERVERFAULT,
336         [LUSTRE_EBADTYPE]               = EBADTYPE,
337         [LUSTRE_EJUKEBOX]               = EJUKEBOX,
338         [LUSTRE_EIOCBQUEUED]            = EIOCBQUEUED,
339         [LUSTRE_EIOCBRETRY]             = EIOCBRETRY
340 #endif
341 };
342
343 unsigned int lustre_errno_hton(unsigned int h)
344 {
345         unsigned int n;
346
347         if (h == 0) {
348                 n = 0;
349         } else if (h < ARRAY_SIZE(lustre_errno_hton_mapping)) {
350                 n = lustre_errno_hton_mapping[h];
351                 if (n == 0)
352                         goto generic;
353         } else {
354 generic:
355                 /*
356                  * A generic errno is better than the unknown one that could
357                  * mean anything to a different host.
358                  */
359                 n = LUSTRE_EIO;
360         }
361
362         return n;
363 }
364 EXPORT_SYMBOL(lustre_errno_hton);
365
366 unsigned int lustre_errno_ntoh(unsigned int n)
367 {
368         unsigned int h;
369
370         if (n == 0) {
371                 h = 0;
372         } else if (n < ARRAY_SIZE(lustre_errno_ntoh_mapping)) {
373                 h = lustre_errno_ntoh_mapping[n];
374                 if (h == 0)
375                         goto generic;
376         } else {
377 generic:
378                 /*
379                  * Similar to the situation in lustre_errno_hton(), an unknown
380                  * network errno could coincide with anything.  Hence, it is
381                  * better to return a generic errno.
382                  */
383                 h = EIO;
384         }
385
386         return h;
387 }
388 EXPORT_SYMBOL(lustre_errno_ntoh);
389
390 #endif /* LUSTRE_TRANSLATE_ERRNOS */