Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / common / freebsd_errno.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2011 New Dream Network
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #include <errno.h>
16 #include "include/types.h"
17 #include "include/compat.h"
18
19 #define H2C_ERRNO(a,b) [a] = b
20 #define C2H_ERRNO(a,b) [a] = b
21
22 // Build a table with the FreeBSD error as index
23 // and the Linux error as value
24 // Use the fact that the arry is initialised per default on all 0's
25 // And we do not translate for 0's, but return the original value.
26 static const __s32 ceph_to_hostos_conv[256] = {
27 //       Linux errno  FreeBSD errno
28        C2H_ERRNO(11,  EAGAIN),  
29        C2H_ERRNO(35,  EDEADLK), 
30        C2H_ERRNO(36,  ENAMETOOLONG),    
31        C2H_ERRNO(37,  ENOLCK),  
32        C2H_ERRNO(38,  ENOSYS),  
33        C2H_ERRNO(39,  ENOTEMPTY),       
34        C2H_ERRNO(40,  ELOOP),   
35        C2H_ERRNO(42,  ENOMSG),  
36        C2H_ERRNO(43,  EIDRM),   
37        C2H_ERRNO(44,  EPERM),    //TODO ECHRNG   /* Channel number out of range */
38        C2H_ERRNO(45,  EPERM),    //TODO EL2NSYNC /* Level 2 not synchronized */
39        C2H_ERRNO(46,  EPERM),    //TODO EL3HLT   /* Level 3 halted */
40        C2H_ERRNO(47,  EPERM),    //TODO EL3RST   /* Level 3 reset */
41        C2H_ERRNO(48,  EPERM),    //TODO ELNRNG   /* Link number out of range */
42        C2H_ERRNO(49,  EPERM),    //TODO EUNATCH  /* Protocol driver not attached */
43        C2H_ERRNO(50,  EPERM),    //TODO ENOCSI   /* No CSI structure available */
44        C2H_ERRNO(51,  EPERM),    //TODO EL2HLT   /* Level 2 halted */
45        C2H_ERRNO(52,  EPERM),    //TODO EBADE    /* Invalid exchange */
46        C2H_ERRNO(53,  EPERM),    //TODO EBADR    /* Invalid request descriptor */
47        C2H_ERRNO(54,  EPERM),    //TODO EXFULL   /* Exchange full */
48        C2H_ERRNO(55,  EPERM),    //TODO ENOANO   /* No anode */
49        C2H_ERRNO(56,  EPERM),    //TODO EBADRQC  /* Invalid request code */
50        C2H_ERRNO(57,  EPERM),    //TODO EBADSLT  /* Invalid slot */
51        C2H_ERRNO(59,  EPERM),    //TODO EBFONT   /* Bad font file format */
52        C2H_ERRNO(60,  ENOSTR),  
53        C2H_ERRNO(61,  ENODATA), 
54        C2H_ERRNO(62,  ETIME),   
55        C2H_ERRNO(63,  ENOSR),   
56        C2H_ERRNO(64,  EPERM),    //TODO ENONET
57        C2H_ERRNO(65,  EPERM),    //TODO ENOPKG
58        C2H_ERRNO(66,  EREMOTE), 
59        C2H_ERRNO(67,  ENOLINK), 
60        C2H_ERRNO(68,  EPERM),    //TODO EADV
61        C2H_ERRNO(69,  EPERM),    //TODO ESRMNT
62        C2H_ERRNO(70,  EPERM),    //TODO ECOMM
63        C2H_ERRNO(71,  EPROTO),  
64        C2H_ERRNO(72,  EMULTIHOP),       
65        C2H_ERRNO(73,  EPERM),    //TODO EDOTDOT
66        C2H_ERRNO(74,  EBADMSG), 
67        C2H_ERRNO(75,  EOVERFLOW),       
68        C2H_ERRNO(76,  EPERM),    //TODO ENOTUNIQ
69        C2H_ERRNO(77,  EPERM),    //TODO EBADFD
70        C2H_ERRNO(78,  EPERM),    //TODO EREMCHG
71        C2H_ERRNO(79,  EPERM),    //TODO ELIBACC
72        C2H_ERRNO(80,  EPERM),    //TODO ELIBBAD
73        C2H_ERRNO(81,  EPERM),    //TODO ELIBSCN
74        C2H_ERRNO(82,  EPERM),    //TODO ELIBMAX
75        C2H_ERRNO(83,  EPERM),    //TODO ELIBEXEC
76        C2H_ERRNO(84,  EILSEQ),  
77        C2H_ERRNO(85,  EINTR),    /* not quite, since this is a syscll restart */
78        C2H_ERRNO(86,  EPERM),    //ESTRPIPE;
79        C2H_ERRNO(87,  EUSERS),  
80        C2H_ERRNO(88,  ENOTSOCK),        
81        C2H_ERRNO(89,  EDESTADDRREQ),    
82        C2H_ERRNO(90,  EMSGSIZE),        
83        C2H_ERRNO(91,  EPROTOTYPE),      
84        C2H_ERRNO(92,  ENOPROTOOPT),     
85        C2H_ERRNO(93,  EPROTONOSUPPORT), 
86        C2H_ERRNO(94,  ESOCKTNOSUPPORT), 
87        C2H_ERRNO(95,  EOPNOTSUPP),      
88        C2H_ERRNO(96,  EPFNOSUPPORT),    
89        C2H_ERRNO(97,  EAFNOSUPPORT),    
90        C2H_ERRNO(98,  EADDRINUSE),      
91        C2H_ERRNO(99,  EADDRNOTAVAIL),   
92        C2H_ERRNO(100, ENETDOWN),        
93        C2H_ERRNO(101, ENETUNREACH),     
94        C2H_ERRNO(102, ENETRESET),       
95        C2H_ERRNO(103, ECONNABORTED),    
96        C2H_ERRNO(104, ECONNRESET),      
97        C2H_ERRNO(105, ENOBUFS), 
98        C2H_ERRNO(106, EISCONN), 
99        C2H_ERRNO(107, ENOTCONN),        
100        C2H_ERRNO(108, ESHUTDOWN),       
101        C2H_ERRNO(109, ETOOMANYREFS),    
102        C2H_ERRNO(110, ETIMEDOUT),       
103        C2H_ERRNO(111, ECONNREFUSED),    
104        C2H_ERRNO(112, EHOSTDOWN),       
105        C2H_ERRNO(113, EHOSTUNREACH),    
106        C2H_ERRNO(114, EALREADY),        
107        C2H_ERRNO(115, EINPROGRESS),     
108        C2H_ERRNO(116, ESTALE),  
109        C2H_ERRNO(117, EPERM),    //TODO EUCLEAN
110        C2H_ERRNO(118, EPERM),    //TODO ENOTNAM
111        C2H_ERRNO(119, EPERM),    //TODO ENAVAIL
112        C2H_ERRNO(120, EPERM),    //TODO EISNAM
113        C2H_ERRNO(121, EREMOTEIO),       
114        C2H_ERRNO(122, EDQUOT),  
115        C2H_ERRNO(123, EPERM),    //TODO ENOMEDIUM
116        C2H_ERRNO(124, EPERM),    //TODO EMEDIUMTYPE - not used
117        C2H_ERRNO(125, ECANCELED),       
118        C2H_ERRNO(126, EPERM),    //TODO ENOKEY
119        C2H_ERRNO(127, EPERM),    //TODO EKEYEXPIRED
120        C2H_ERRNO(128, EPERM),    //TODO EKEYREVOKED
121        C2H_ERRNO(129, EPERM),    //TODO EKEYREJECTED
122        C2H_ERRNO(130, EOWNERDEAD),      
123        C2H_ERRNO(131, ENOTRECOVERABLE), 
124        C2H_ERRNO(132, EPERM),    //TODO ERFKILL
125        C2H_ERRNO(133, EPERM),    //TODO EHWPOISON
126     };
127
128 // Build a table with the FreeBSD error as index
129 // and the Linux error as value
130 // Use the fact that the arry is initialised per default on all 0's
131 // And we do not translate for 0's, but return the original value.
132 static const __s32 hostos_to_ceph_conv[256] = {
133         //        FreeBSD errno Linux errno
134         H2C_ERRNO(EDEADLK,      35),    /* Resource deadlock avoided */
135         H2C_ERRNO(EAGAIN,       11),    /* Resource temporarily unavailable */
136         H2C_ERRNO(EINPROGRESS,  115),   /* Operation now in progress */
137         H2C_ERRNO(EALREADY,     114),   /* Operation already in progress */
138         H2C_ERRNO(ENOTSOCK,     88),    /* Socket operation on non-socket */
139         H2C_ERRNO(EDESTADDRREQ, 89),    /* Destination address required */
140         H2C_ERRNO(EMSGSIZE,     90),    /* Message too long */
141         H2C_ERRNO(EPROTOTYPE,   91),    /* Protocol wrong type for socket */
142         H2C_ERRNO(ENOPROTOOPT,  92),    /* Protocol not available */
143         H2C_ERRNO(EPROTONOSUPPORT, 93), /* Protocol not supported */
144         H2C_ERRNO(ESOCKTNOSUPPORT, 94), /* Socket type not supported */
145         H2C_ERRNO(EOPNOTSUPP,   95),    /* Operation not supported */
146         H2C_ERRNO(EPFNOSUPPORT, 96),    /* Protocol family not supported */
147         H2C_ERRNO(EAFNOSUPPORT, 97),    /* Address family not supported by protocol family */
148         H2C_ERRNO(EADDRINUSE,   98),    /* Address already in use */
149         H2C_ERRNO(EADDRNOTAVAIL, 99),   /* Can't assign requested address */
150         H2C_ERRNO(ENETDOWN,     100),   /* Network is down */
151         H2C_ERRNO(ENETUNREACH,  101),   /* Network is unreachable */
152         H2C_ERRNO(ENETRESET,    102),   /* Network dropped connection on reset */
153         H2C_ERRNO(ECONNABORTED, 103),   /* Software caused connection abort */
154         H2C_ERRNO(ECONNRESET,   104),   /* Connection reset by peer */
155         H2C_ERRNO(ENOBUFS,      105),   /* No buffer space available */
156         H2C_ERRNO(EISCONN,      106),   /* Socket is already connected */
157         H2C_ERRNO(ENOTCONN,     107),   /* Socket is not connected */
158         H2C_ERRNO(ESHUTDOWN,    108),   /* Can't send after socket shutdown */
159         H2C_ERRNO(ETOOMANYREFS, 109),   /* Too many references: can't splice */
160         H2C_ERRNO(ETIMEDOUT,    110),   /* Operation timed out */
161         H2C_ERRNO(ECONNREFUSED, 111),   /* Connection refused */
162         H2C_ERRNO(ELOOP,        40),    /* Too many levels of symbolic links */
163         H2C_ERRNO(ENAMETOOLONG, 36),    /* File name too long */
164         H2C_ERRNO(EHOSTDOWN,    112),   /* Host is down */
165         H2C_ERRNO(EHOSTUNREACH, 113),   /* No route to host */
166         H2C_ERRNO(ENOTEMPTY,    39),    /* Directory not empty */
167         H2C_ERRNO(EPROCLIM,     EPERM), /* Too many processes */
168         H2C_ERRNO(EUSERS,       87),    /* Too many users */
169         H2C_ERRNO(EDQUOT,       122),   /* Disc quota exceeded */
170         H2C_ERRNO(ESTALE,       116),   /* Stale NFS file handle */
171         H2C_ERRNO(EREMOTE,      66),    /* Too many levels of remote in path */
172         H2C_ERRNO(EBADRPC,      EPERM), /* RPC struct is bad */
173         H2C_ERRNO(ERPCMISMATCH, EPERM), /* RPC version wrong */
174         H2C_ERRNO(EPROGUNAVAIL, EPERM), /* RPC prog. not avail */
175         H2C_ERRNO(EPROGMISMATCH, EPERM),/* Program version wrong */
176         H2C_ERRNO(EPROCUNAVAIL, EPERM), /* Bad procedure for program */
177         H2C_ERRNO(ENOLCK,       EPERM), /* No locks available */
178         H2C_ERRNO(ENOSYS,       EPERM), /* Function not implemented */
179         H2C_ERRNO(EFTYPE,       EPERM), /* Inappropriate file type or format */
180         H2C_ERRNO(EAUTH,        EPERM), /* Authentication error */
181         H2C_ERRNO(ENEEDAUTH,    EPERM), /* Need authenticator */
182         H2C_ERRNO(EIDRM,        43),    /* Identifier removed */
183         H2C_ERRNO(ENOMSG,       42),    /* No message of desired type */
184         H2C_ERRNO(EOVERFLOW,    75),    /* Value too large to be stored in data type */
185         H2C_ERRNO(ECANCELED,    125),   /* Operation canceled */
186         H2C_ERRNO(EILSEQ,       84),    /* Illegal byte sequence */
187         H2C_ERRNO(ENOATTR,      61),    /* Attribute not found */
188         H2C_ERRNO(EDOOFUS,      EPERM), /* Programming error */
189         H2C_ERRNO(EBADMSG,      74),    /* Bad message */
190         H2C_ERRNO(EMULTIHOP,    72),    /* Multihop attempted */
191         H2C_ERRNO(ENOLINK,      67),    /* Link has been severed */
192         H2C_ERRNO(EPROTO,       71),    /* Protocol error */
193         H2C_ERRNO(ENOTCAPABLE,  EPERM), /* Capabilities insufficient */
194         H2C_ERRNO(ECAPMODE,     EPERM), /* Not permitted in capability mode */
195         H2C_ERRNO(ENOTRECOVERABLE, 131),/* State not recoverable */
196         H2C_ERRNO(EOWNERDEAD,   130),   /* Previous owner died */
197         };
198
199 // converts from linux errno values to host values
200 __s32 ceph_to_hostos_errno(__s32 r)
201 {
202   int sign = (r < 0 ? -1 : 1);
203   int err = std::abs(r);
204   if (err < 256 && ceph_to_hostos_conv[err] !=0 ) {
205     err = ceph_to_hostos_conv[err];
206   }
207   return err * sign;
208 }
209
210 // converts Host OS errno values to linux/Ceph values
211 __s32 hostos_to_ceph_errno(__s32 r)
212 {
213   int sign = (r < 0 ? -1 : 1);
214   int err = std::abs(r);
215   if (err < 256 && hostos_to_ceph_conv[err] !=0 ) {
216     err = hostos_to_ceph_conv[err];
217   }
218   return err * sign;
219 }