blob: b67a9c38dfa6d2a6dfe9c57a2a02d8331d15e5df [file] [log] [blame]
David Howellsec268152007-04-26 15:49:28 -07001/* miscellaneous bits
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David Howells08e0e7c2007-04-26 15:55:03 -07003 * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Written by David Howells ([email protected])
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "internal.h"
David Howells08e0e7c2007-04-26 15:55:03 -070016#include "afs_fs.h"
David Howells1eda8ba2019-06-28 18:00:05 +010017#include "protocol_uae.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20 * convert an AFS abort code to a Linux error number
21 */
David Howells08e0e7c2007-04-26 15:55:03 -070022int afs_abort_to_error(u32 abort_code)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
David Howells08e0e7c2007-04-26 15:55:03 -070024 switch (abort_code) {
David Howellsf780c8e2017-11-02 15:27:48 +000025 /* Low errno codes inserted into abort namespace */
David Howells08e0e7c2007-04-26 15:55:03 -070026 case 13: return -EACCES;
David Howells416351f2007-05-09 02:33:45 -070027 case 27: return -EFBIG;
David Howells260a9802007-04-26 15:59:35 -070028 case 30: return -EROFS;
Nathaniel Wesley Filardo53d58642014-08-21 14:10:55 -040029
David Howellsf780c8e2017-11-02 15:27:48 +000030 /* VICE "special error" codes; 101 - 111 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 case VSALVAGE: return -EIO;
32 case VNOVNODE: return -ENOENT;
David Howells08e0e7c2007-04-26 15:55:03 -070033 case VNOVOL: return -ENOMEDIUM;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 case VVOLEXISTS: return -EEXIST;
35 case VNOSERVICE: return -EIO;
36 case VOFFLINE: return -ENOENT;
37 case VONLINE: return -EEXIST;
38 case VDISKFULL: return -ENOSPC;
39 case VOVERQUOTA: return -EDQUOT;
40 case VBUSY: return -EBUSY;
41 case VMOVED: return -ENXIO;
Nathaniel Wesley Filardo53d58642014-08-21 14:10:55 -040042
David Howellsf780c8e2017-11-02 15:27:48 +000043 /* Volume Location server errors */
44 case AFSVL_IDEXIST: return -EEXIST;
45 case AFSVL_IO: return -EREMOTEIO;
46 case AFSVL_NAMEEXIST: return -EEXIST;
47 case AFSVL_CREATEFAIL: return -EREMOTEIO;
48 case AFSVL_NOENT: return -ENOMEDIUM;
49 case AFSVL_EMPTY: return -ENOMEDIUM;
50 case AFSVL_ENTDELETED: return -ENOMEDIUM;
51 case AFSVL_BADNAME: return -EINVAL;
52 case AFSVL_BADINDEX: return -EINVAL;
53 case AFSVL_BADVOLTYPE: return -EINVAL;
54 case AFSVL_BADSERVER: return -EINVAL;
55 case AFSVL_BADPARTITION: return -EINVAL;
56 case AFSVL_REPSFULL: return -EFBIG;
57 case AFSVL_NOREPSERVER: return -ENOENT;
58 case AFSVL_DUPREPSERVER: return -EEXIST;
59 case AFSVL_RWNOTFOUND: return -ENOENT;
60 case AFSVL_BADREFCOUNT: return -EINVAL;
61 case AFSVL_SIZEEXCEEDED: return -EINVAL;
62 case AFSVL_BADENTRY: return -EINVAL;
63 case AFSVL_BADVOLIDBUMP: return -EINVAL;
64 case AFSVL_IDALREADYHASHED: return -EINVAL;
65 case AFSVL_ENTRYLOCKED: return -EBUSY;
66 case AFSVL_BADVOLOPER: return -EBADRQC;
67 case AFSVL_BADRELLOCKTYPE: return -EINVAL;
68 case AFSVL_RERELEASE: return -EREMOTEIO;
69 case AFSVL_BADSERVERFLAG: return -EINVAL;
70 case AFSVL_PERM: return -EACCES;
71 case AFSVL_NOMEM: return -EREMOTEIO;
72
David Howells1eda8ba2019-06-28 18:00:05 +010073 /* Unified AFS error table */
74 case UAEPERM: return -EPERM;
75 case UAENOENT: return -ENOENT;
76 case UAEACCES: return -EACCES;
77 case UAEBUSY: return -EBUSY;
78 case UAEEXIST: return -EEXIST;
79 case UAENOTDIR: return -ENOTDIR;
80 case UAEISDIR: return -EISDIR;
81 case UAEFBIG: return -EFBIG;
82 case UAENOSPC: return -ENOSPC;
83 case UAEROFS: return -EROFS;
84 case UAEMLINK: return -EMLINK;
85 case UAEDEADLK: return -EDEADLK;
86 case UAENAMETOOLONG: return -ENAMETOOLONG;
87 case UAENOLCK: return -ENOLCK;
88 case UAENOTEMPTY: return -ENOTEMPTY;
89 case UAELOOP: return -ELOOP;
90 case UAENOMEDIUM: return -ENOMEDIUM;
91 case UAEDQUOT: return -EDQUOT;
David Howells005411c2009-06-16 21:36:49 +010092
David Howellsf780c8e2017-11-02 15:27:48 +000093 /* RXKAD abort codes; from include/rxrpc/packet.h. ET "RXK" == 0x1260B00 */
David Howells005411c2009-06-16 21:36:49 +010094 case RXKADINCONSISTENCY: return -EPROTO;
95 case RXKADPACKETSHORT: return -EPROTO;
96 case RXKADLEVELFAIL: return -EKEYREJECTED;
97 case RXKADTICKETLEN: return -EKEYREJECTED;
98 case RXKADOUTOFSEQUENCE: return -EPROTO;
99 case RXKADNOAUTH: return -EKEYREJECTED;
100 case RXKADBADKEY: return -EKEYREJECTED;
101 case RXKADBADTICKET: return -EKEYREJECTED;
102 case RXKADUNKNOWNKEY: return -EKEYREJECTED;
103 case RXKADEXPIRED: return -EKEYEXPIRED;
104 case RXKADSEALEDINCON: return -EKEYREJECTED;
105 case RXKADDATALEN: return -EKEYREJECTED;
106 case RXKADILLEGALLEVEL: return -EKEYREJECTED;
107
David Howells1157f152017-03-16 16:27:47 +0000108 case RXGEN_OPCODE: return -ENOTSUPP;
109
David Howells260a9802007-04-26 15:59:35 -0700110 default: return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
David Howellsec268152007-04-26 15:49:28 -0700112}
David Howells4584ae92018-11-13 23:20:28 +0000113
114/*
115 * Select the error to report from a set of errors.
116 */
117void afs_prioritise_error(struct afs_error *e, int error, u32 abort_code)
118{
119 switch (error) {
120 case 0:
121 return;
122 default:
123 if (e->error == -ETIMEDOUT ||
124 e->error == -ETIME)
125 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600126 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000127 case -ETIMEDOUT:
128 case -ETIME:
129 if (e->error == -ENOMEM ||
130 e->error == -ENONET)
131 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600132 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000133 case -ENOMEM:
134 case -ENONET:
135 if (e->error == -ERFKILL)
136 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600137 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000138 case -ERFKILL:
139 if (e->error == -EADDRNOTAVAIL)
140 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600141 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000142 case -EADDRNOTAVAIL:
143 if (e->error == -ENETUNREACH)
144 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600145 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000146 case -ENETUNREACH:
147 if (e->error == -EHOSTUNREACH)
148 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600149 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000150 case -EHOSTUNREACH:
151 if (e->error == -EHOSTDOWN)
152 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600153 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000154 case -EHOSTDOWN:
155 if (e->error == -ECONNREFUSED)
156 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600157 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000158 case -ECONNREFUSED:
159 if (e->error == -ECONNRESET)
160 return;
Gustavo A. R. Silvae690c9e2019-01-10 15:52:25 -0600161 /* Fall through */
David Howells4584ae92018-11-13 23:20:28 +0000162 case -ECONNRESET: /* Responded, but call expired. */
163 if (e->responded)
164 return;
165 e->error = error;
166 return;
167
168 case -ECONNABORTED:
169 e->responded = true;
170 e->error = afs_abort_to_error(abort_code);
171 return;
172 }
173}