xref: /linux/fs/afs/misc.c (revision 06d07429858317ded2db7986113a9e0129cd599b)
12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2ec26815aSDavid Howells /* miscellaneous bits
31da177e4SLinus Torvalds  *
408e0e7c8SDavid Howells  * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
51da177e4SLinus Torvalds  * Written by David Howells (dhowells@redhat.com)
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #include <linux/kernel.h>
91da177e4SLinus Torvalds #include <linux/module.h>
101da177e4SLinus Torvalds #include <linux/errno.h>
111da177e4SLinus Torvalds #include "internal.h"
1208e0e7c8SDavid Howells #include "afs_fs.h"
131eda8babSDavid Howells #include "protocol_uae.h"
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds /*
161da177e4SLinus Torvalds  * convert an AFS abort code to a Linux error number
171da177e4SLinus Torvalds  */
afs_abort_to_error(u32 abort_code)1808e0e7c8SDavid Howells int afs_abort_to_error(u32 abort_code)
191da177e4SLinus Torvalds {
2008e0e7c8SDavid Howells 	switch (abort_code) {
21f780c8eaSDavid Howells 		/* Low errno codes inserted into abort namespace */
2208e0e7c8SDavid Howells 	case 13:		return -EACCES;
23416351f2SDavid Howells 	case 27:		return -EFBIG;
24260a9803SDavid Howells 	case 30:		return -EROFS;
2553d5864bSNathaniel Wesley Filardo 
2653d5864bSNathaniel Wesley Filardo 		/* VICE "special error" codes; 101 - 111 */
271da177e4SLinus Torvalds 	case VSALVAGE:		return -EIO;
281da177e4SLinus Torvalds 	case VNOVNODE:		return -ENOENT;
2908e0e7c8SDavid Howells 	case VNOVOL:		return -ENOMEDIUM;
301da177e4SLinus Torvalds 	case VVOLEXISTS:	return -EEXIST;
311da177e4SLinus Torvalds 	case VNOSERVICE:	return -EIO;
321da177e4SLinus Torvalds 	case VOFFLINE:		return -ENOENT;
331da177e4SLinus Torvalds 	case VONLINE:		return -EEXIST;
341da177e4SLinus Torvalds 	case VDISKFULL:		return -ENOSPC;
351da177e4SLinus Torvalds 	case VOVERQUOTA:	return -EDQUOT;
361da177e4SLinus Torvalds 	case VBUSY:		return -EBUSY;
371da177e4SLinus Torvalds 	case VMOVED:		return -ENXIO;
3853d5864bSNathaniel Wesley Filardo 
39f780c8eaSDavid Howells 		/* Volume Location server errors */
40f780c8eaSDavid Howells 	case AFSVL_IDEXIST:		return -EEXIST;
41f780c8eaSDavid Howells 	case AFSVL_IO:			return -EREMOTEIO;
42f780c8eaSDavid Howells 	case AFSVL_NAMEEXIST:		return -EEXIST;
43f780c8eaSDavid Howells 	case AFSVL_CREATEFAIL:		return -EREMOTEIO;
44f780c8eaSDavid Howells 	case AFSVL_NOENT:		return -ENOMEDIUM;
45f780c8eaSDavid Howells 	case AFSVL_EMPTY:		return -ENOMEDIUM;
46f780c8eaSDavid Howells 	case AFSVL_ENTDELETED:		return -ENOMEDIUM;
47f780c8eaSDavid Howells 	case AFSVL_BADNAME:		return -EINVAL;
48f780c8eaSDavid Howells 	case AFSVL_BADINDEX:		return -EINVAL;
49f780c8eaSDavid Howells 	case AFSVL_BADVOLTYPE:		return -EINVAL;
50f780c8eaSDavid Howells 	case AFSVL_BADSERVER:		return -EINVAL;
51f780c8eaSDavid Howells 	case AFSVL_BADPARTITION:	return -EINVAL;
52f780c8eaSDavid Howells 	case AFSVL_REPSFULL:		return -EFBIG;
53f780c8eaSDavid Howells 	case AFSVL_NOREPSERVER:		return -ENOENT;
54f780c8eaSDavid Howells 	case AFSVL_DUPREPSERVER:	return -EEXIST;
55f780c8eaSDavid Howells 	case AFSVL_RWNOTFOUND:		return -ENOENT;
56f780c8eaSDavid Howells 	case AFSVL_BADREFCOUNT:		return -EINVAL;
57f780c8eaSDavid Howells 	case AFSVL_SIZEEXCEEDED:	return -EINVAL;
58f780c8eaSDavid Howells 	case AFSVL_BADENTRY:		return -EINVAL;
59f780c8eaSDavid Howells 	case AFSVL_BADVOLIDBUMP:	return -EINVAL;
60f780c8eaSDavid Howells 	case AFSVL_IDALREADYHASHED:	return -EINVAL;
61f780c8eaSDavid Howells 	case AFSVL_ENTRYLOCKED:		return -EBUSY;
62f780c8eaSDavid Howells 	case AFSVL_BADVOLOPER:		return -EBADRQC;
63f780c8eaSDavid Howells 	case AFSVL_BADRELLOCKTYPE:	return -EINVAL;
64f780c8eaSDavid Howells 	case AFSVL_RERELEASE:		return -EREMOTEIO;
65f780c8eaSDavid Howells 	case AFSVL_BADSERVERFLAG:	return -EINVAL;
66f780c8eaSDavid Howells 	case AFSVL_PERM:		return -EACCES;
67f780c8eaSDavid Howells 	case AFSVL_NOMEM:		return -EREMOTEIO;
68f780c8eaSDavid Howells 
691eda8babSDavid Howells 		/* Unified AFS error table */
701eda8babSDavid Howells 	case UAEPERM:			return -EPERM;
711eda8babSDavid Howells 	case UAENOENT:			return -ENOENT;
720066f1b0SDavid Howells 	case UAEAGAIN:			return -EAGAIN;
731eda8babSDavid Howells 	case UAEACCES:			return -EACCES;
741eda8babSDavid Howells 	case UAEBUSY:			return -EBUSY;
751eda8babSDavid Howells 	case UAEEXIST:			return -EEXIST;
761eda8babSDavid Howells 	case UAENOTDIR:			return -ENOTDIR;
771eda8babSDavid Howells 	case UAEISDIR:			return -EISDIR;
781eda8babSDavid Howells 	case UAEFBIG:			return -EFBIG;
791eda8babSDavid Howells 	case UAENOSPC:			return -ENOSPC;
801eda8babSDavid Howells 	case UAEROFS:			return -EROFS;
811eda8babSDavid Howells 	case UAEMLINK:			return -EMLINK;
821eda8babSDavid Howells 	case UAEDEADLK:			return -EDEADLK;
831eda8babSDavid Howells 	case UAENAMETOOLONG:		return -ENAMETOOLONG;
841eda8babSDavid Howells 	case UAENOLCK:			return -ENOLCK;
851eda8babSDavid Howells 	case UAENOTEMPTY:		return -ENOTEMPTY;
861eda8babSDavid Howells 	case UAELOOP:			return -ELOOP;
874ec89596SDavid Howells 	case UAEOVERFLOW:		return -EOVERFLOW;
881eda8babSDavid Howells 	case UAENOMEDIUM:		return -ENOMEDIUM;
891eda8babSDavid Howells 	case UAEDQUOT:			return -EDQUOT;
90005411c3SDavid Howells 
9153d5864bSNathaniel Wesley Filardo 		/* RXKAD abort codes; from include/rxrpc/packet.h.  ET "RXK" == 0x1260B00 */
92005411c3SDavid Howells 	case RXKADINCONSISTENCY: return -EPROTO;
93005411c3SDavid Howells 	case RXKADPACKETSHORT:	return -EPROTO;
94005411c3SDavid Howells 	case RXKADLEVELFAIL:	return -EKEYREJECTED;
95005411c3SDavid Howells 	case RXKADTICKETLEN:	return -EKEYREJECTED;
96005411c3SDavid Howells 	case RXKADOUTOFSEQUENCE: return -EPROTO;
97005411c3SDavid Howells 	case RXKADNOAUTH:	return -EKEYREJECTED;
98005411c3SDavid Howells 	case RXKADBADKEY:	return -EKEYREJECTED;
99005411c3SDavid Howells 	case RXKADBADTICKET:	return -EKEYREJECTED;
100005411c3SDavid Howells 	case RXKADUNKNOWNKEY:	return -EKEYREJECTED;
101005411c3SDavid Howells 	case RXKADEXPIRED:	return -EKEYEXPIRED;
102005411c3SDavid Howells 	case RXKADSEALEDINCON:	return -EKEYREJECTED;
103005411c3SDavid Howells 	case RXKADDATALEN:	return -EKEYREJECTED;
104005411c3SDavid Howells 	case RXKADILLEGALLEVEL:	return -EKEYREJECTED;
105005411c3SDavid Howells 
1061157f153SDavid Howells 	case RXGEN_OPCODE:	return -ENOTSUPP;
1071157f153SDavid Howells 
108260a9803SDavid Howells 	default:		return -EREMOTEIO;
1091da177e4SLinus Torvalds 	}
110ec26815aSDavid Howells }
1114584ae96SDavid Howells 
1124584ae96SDavid Howells /*
1134584ae96SDavid Howells  * Select the error to report from a set of errors.
1144584ae96SDavid Howells  */
afs_prioritise_error(struct afs_error * e,int error,u32 abort_code)1154584ae96SDavid Howells void afs_prioritise_error(struct afs_error *e, int error, u32 abort_code)
1164584ae96SDavid Howells {
1174584ae96SDavid Howells 	switch (error) {
1184584ae96SDavid Howells 	case 0:
119*aa453becSDavid Howells 		e->aborted = false;
120*aa453becSDavid Howells 		e->error = 0;
1214584ae96SDavid Howells 		return;
1224584ae96SDavid Howells 	default:
1234584ae96SDavid Howells 		if (e->error == -ETIMEDOUT ||
1244584ae96SDavid Howells 		    e->error == -ETIME)
1254584ae96SDavid Howells 			return;
126df561f66SGustavo A. R. Silva 		fallthrough;
1274584ae96SDavid Howells 	case -ETIMEDOUT:
1284584ae96SDavid Howells 	case -ETIME:
1294584ae96SDavid Howells 		if (e->error == -ENOMEM ||
1304584ae96SDavid Howells 		    e->error == -ENONET)
1314584ae96SDavid Howells 			return;
132df561f66SGustavo A. R. Silva 		fallthrough;
1334584ae96SDavid Howells 	case -ENOMEM:
1344584ae96SDavid Howells 	case -ENONET:
1354584ae96SDavid Howells 		if (e->error == -ERFKILL)
1364584ae96SDavid Howells 			return;
137df561f66SGustavo A. R. Silva 		fallthrough;
1384584ae96SDavid Howells 	case -ERFKILL:
1394584ae96SDavid Howells 		if (e->error == -EADDRNOTAVAIL)
1404584ae96SDavid Howells 			return;
141df561f66SGustavo A. R. Silva 		fallthrough;
1424584ae96SDavid Howells 	case -EADDRNOTAVAIL:
1434584ae96SDavid Howells 		if (e->error == -ENETUNREACH)
1444584ae96SDavid Howells 			return;
145df561f66SGustavo A. R. Silva 		fallthrough;
1464584ae96SDavid Howells 	case -ENETUNREACH:
1474584ae96SDavid Howells 		if (e->error == -EHOSTUNREACH)
1484584ae96SDavid Howells 			return;
149df561f66SGustavo A. R. Silva 		fallthrough;
1504584ae96SDavid Howells 	case -EHOSTUNREACH:
1514584ae96SDavid Howells 		if (e->error == -EHOSTDOWN)
1524584ae96SDavid Howells 			return;
153df561f66SGustavo A. R. Silva 		fallthrough;
1544584ae96SDavid Howells 	case -EHOSTDOWN:
1554584ae96SDavid Howells 		if (e->error == -ECONNREFUSED)
1564584ae96SDavid Howells 			return;
157df561f66SGustavo A. R. Silva 		fallthrough;
1584584ae96SDavid Howells 	case -ECONNREFUSED:
1594584ae96SDavid Howells 		if (e->error == -ECONNRESET)
1604584ae96SDavid Howells 			return;
161df561f66SGustavo A. R. Silva 		fallthrough;
1624584ae96SDavid Howells 	case -ECONNRESET: /* Responded, but call expired. */
1634584ae96SDavid Howells 		if (e->responded)
1644584ae96SDavid Howells 			return;
1654584ae96SDavid Howells 		e->error = error;
166*aa453becSDavid Howells 		e->aborted = false;
1674584ae96SDavid Howells 		return;
1684584ae96SDavid Howells 
1694584ae96SDavid Howells 	case -ECONNABORTED:
170*aa453becSDavid Howells 		e->error = afs_abort_to_error(abort_code);
171*aa453becSDavid Howells 		e->aborted = true;
172*aa453becSDavid Howells 		e->responded = true;
173*aa453becSDavid Howells 		return;
174adc9613fSDavid Howells 	case -ENETRESET: /* Responded, but we seem to have changed address */
175*aa453becSDavid Howells 		e->aborted = false;
1764584ae96SDavid Howells 		e->responded = true;
177adc9613fSDavid Howells 		e->error = error;
1784584ae96SDavid Howells 		return;
1794584ae96SDavid Howells 	}
1804584ae96SDavid Howells }
181