2005-09-10 04:04:24 +08:00
|
|
|
/*
|
2007-07-11 06:57:28 +08:00
|
|
|
* linux/fs/9p/error.c
|
2005-09-10 04:04:24 +08:00
|
|
|
*
|
2007-07-11 06:57:28 +08:00
|
|
|
* Error string handling
|
2005-09-10 04:04:24 +08:00
|
|
|
*
|
2007-07-11 06:57:28 +08:00
|
|
|
* Plan 9 uses error strings, Unix uses error numbers. These functions
|
|
|
|
* try to help manage that and provide for dynamically adding error
|
|
|
|
* mappings.
|
2005-09-10 04:04:24 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
|
|
|
|
* Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2006-03-25 19:07:28 +08:00
|
|
|
* it under the terms of the GNU General Public License version 2
|
|
|
|
* as published by the Free Software Foundation.
|
2005-09-10 04:04:24 +08:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to:
|
|
|
|
* Free Software Foundation
|
|
|
|
* 51 Franklin Street, Fifth Floor
|
|
|
|
* Boston, MA 02111-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-11-29 02:40:46 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-07-11 06:57:28 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/jhash.h>
|
2005-09-10 04:04:24 +08:00
|
|
|
#include <linux/errno.h>
|
2007-07-11 06:57:28 +08:00
|
|
|
#include <net/9p/9p.h>
|
2005-09-10 04:04:24 +08:00
|
|
|
|
2008-03-05 21:08:09 +08:00
|
|
|
/**
|
|
|
|
* struct errormap - map string errors from Plan 9 to Linux numeric ids
|
|
|
|
* @name: string sent over 9P
|
|
|
|
* @val: numeric id most closely representing @name
|
|
|
|
* @namelen: length of string
|
|
|
|
* @list: hash-table list for string lookup
|
|
|
|
*/
|
2005-09-10 04:04:24 +08:00
|
|
|
struct errormap {
|
|
|
|
char *name;
|
|
|
|
int val;
|
|
|
|
|
2006-01-08 17:05:00 +08:00
|
|
|
int namelen;
|
2005-09-10 04:04:24 +08:00
|
|
|
struct hlist_node list;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ERRHASHSZ 32
|
|
|
|
static struct hlist_head hash_errmap[ERRHASHSZ];
|
|
|
|
|
|
|
|
/* FixMe - reduce to a reasonable size */
|
|
|
|
static struct errormap errmap[] = {
|
2005-09-10 04:04:25 +08:00
|
|
|
{"Operation not permitted", EPERM},
|
|
|
|
{"wstat prohibited", EPERM},
|
|
|
|
{"No such file or directory", ENOENT},
|
2005-09-10 04:04:28 +08:00
|
|
|
{"directory entry not found", ENOENT},
|
2005-09-10 04:04:25 +08:00
|
|
|
{"file not found", ENOENT},
|
|
|
|
{"Interrupted system call", EINTR},
|
|
|
|
{"Input/output error", EIO},
|
|
|
|
{"No such device or address", ENXIO},
|
|
|
|
{"Argument list too long", E2BIG},
|
|
|
|
{"Bad file descriptor", EBADF},
|
|
|
|
{"Resource temporarily unavailable", EAGAIN},
|
|
|
|
{"Cannot allocate memory", ENOMEM},
|
|
|
|
{"Permission denied", EACCES},
|
|
|
|
{"Bad address", EFAULT},
|
|
|
|
{"Block device required", ENOTBLK},
|
|
|
|
{"Device or resource busy", EBUSY},
|
|
|
|
{"File exists", EEXIST},
|
|
|
|
{"Invalid cross-device link", EXDEV},
|
|
|
|
{"No such device", ENODEV},
|
|
|
|
{"Not a directory", ENOTDIR},
|
|
|
|
{"Is a directory", EISDIR},
|
|
|
|
{"Invalid argument", EINVAL},
|
|
|
|
{"Too many open files in system", ENFILE},
|
|
|
|
{"Too many open files", EMFILE},
|
|
|
|
{"Text file busy", ETXTBSY},
|
|
|
|
{"File too large", EFBIG},
|
|
|
|
{"No space left on device", ENOSPC},
|
|
|
|
{"Illegal seek", ESPIPE},
|
|
|
|
{"Read-only file system", EROFS},
|
|
|
|
{"Too many links", EMLINK},
|
|
|
|
{"Broken pipe", EPIPE},
|
|
|
|
{"Numerical argument out of domain", EDOM},
|
|
|
|
{"Numerical result out of range", ERANGE},
|
|
|
|
{"Resource deadlock avoided", EDEADLK},
|
|
|
|
{"File name too long", ENAMETOOLONG},
|
|
|
|
{"No locks available", ENOLCK},
|
|
|
|
{"Function not implemented", ENOSYS},
|
|
|
|
{"Directory not empty", ENOTEMPTY},
|
|
|
|
{"Too many levels of symbolic links", ELOOP},
|
|
|
|
{"No message of desired type", ENOMSG},
|
|
|
|
{"Identifier removed", EIDRM},
|
|
|
|
{"No data available", ENODATA},
|
|
|
|
{"Machine is not on the network", ENONET},
|
|
|
|
{"Package not installed", ENOPKG},
|
|
|
|
{"Object is remote", EREMOTE},
|
|
|
|
{"Link has been severed", ENOLINK},
|
|
|
|
{"Communication error on send", ECOMM},
|
|
|
|
{"Protocol error", EPROTO},
|
|
|
|
{"Bad message", EBADMSG},
|
|
|
|
{"File descriptor in bad state", EBADFD},
|
|
|
|
{"Streams pipe error", ESTRPIPE},
|
|
|
|
{"Too many users", EUSERS},
|
|
|
|
{"Socket operation on non-socket", ENOTSOCK},
|
|
|
|
{"Message too long", EMSGSIZE},
|
|
|
|
{"Protocol not available", ENOPROTOOPT},
|
|
|
|
{"Protocol not supported", EPROTONOSUPPORT},
|
|
|
|
{"Socket type not supported", ESOCKTNOSUPPORT},
|
|
|
|
{"Operation not supported", EOPNOTSUPP},
|
|
|
|
{"Protocol family not supported", EPFNOSUPPORT},
|
|
|
|
{"Network is down", ENETDOWN},
|
|
|
|
{"Network is unreachable", ENETUNREACH},
|
|
|
|
{"Network dropped connection on reset", ENETRESET},
|
|
|
|
{"Software caused connection abort", ECONNABORTED},
|
|
|
|
{"Connection reset by peer", ECONNRESET},
|
|
|
|
{"No buffer space available", ENOBUFS},
|
|
|
|
{"Transport endpoint is already connected", EISCONN},
|
|
|
|
{"Transport endpoint is not connected", ENOTCONN},
|
|
|
|
{"Cannot send after transport endpoint shutdown", ESHUTDOWN},
|
|
|
|
{"Connection timed out", ETIMEDOUT},
|
|
|
|
{"Connection refused", ECONNREFUSED},
|
|
|
|
{"Host is down", EHOSTDOWN},
|
|
|
|
{"No route to host", EHOSTUNREACH},
|
|
|
|
{"Operation already in progress", EALREADY},
|
|
|
|
{"Operation now in progress", EINPROGRESS},
|
|
|
|
{"Is a named type file", EISNAM},
|
|
|
|
{"Remote I/O error", EREMOTEIO},
|
|
|
|
{"Disk quota exceeded", EDQUOT},
|
2005-09-10 04:04:24 +08:00
|
|
|
/* errors from fossil, vacfs, and u9fs */
|
|
|
|
{"fid unknown or out of range", EBADF},
|
|
|
|
{"permission denied", EACCES},
|
|
|
|
{"file does not exist", ENOENT},
|
|
|
|
{"authentication failed", ECONNREFUSED},
|
|
|
|
{"bad offset in directory read", ESPIPE},
|
|
|
|
{"bad use of fid", EBADF},
|
|
|
|
{"wstat can't convert between files and directories", EPERM},
|
|
|
|
{"directory is not empty", ENOTEMPTY},
|
|
|
|
{"file exists", EEXIST},
|
|
|
|
{"file already exists", EEXIST},
|
|
|
|
{"file or directory already exists", EEXIST},
|
|
|
|
{"fid already in use", EBADF},
|
|
|
|
{"file in use", ETXTBSY},
|
|
|
|
{"i/o error", EIO},
|
|
|
|
{"file already open for I/O", ETXTBSY},
|
|
|
|
{"illegal mode", EINVAL},
|
|
|
|
{"illegal name", ENAMETOOLONG},
|
|
|
|
{"not a directory", ENOTDIR},
|
2005-09-10 04:04:26 +08:00
|
|
|
{"not a member of proposed group", EPERM},
|
2005-09-10 04:04:24 +08:00
|
|
|
{"not owner", EACCES},
|
|
|
|
{"only owner can change group in wstat", EACCES},
|
|
|
|
{"read only file system", EROFS},
|
|
|
|
{"no access to special file", EPERM},
|
|
|
|
{"i/o count too large", EIO},
|
|
|
|
{"unknown group", EINVAL},
|
|
|
|
{"unknown user", EINVAL},
|
|
|
|
{"bogus wstat buffer", EPROTO},
|
|
|
|
{"exclusive use file already open", EAGAIN},
|
|
|
|
{"corrupted directory entry", EIO},
|
|
|
|
{"corrupted file entry", EIO},
|
|
|
|
{"corrupted block label", EIO},
|
|
|
|
{"corrupted meta data", EIO},
|
|
|
|
{"illegal offset", EINVAL},
|
|
|
|
{"illegal path element", ENOENT},
|
|
|
|
{"root of file system is corrupted", EIO},
|
|
|
|
{"corrupted super block", EIO},
|
|
|
|
{"protocol botch", EPROTO},
|
|
|
|
{"file system is full", ENOSPC},
|
|
|
|
{"file is in use", EAGAIN},
|
|
|
|
{"directory entry is not allocated", ENOENT},
|
|
|
|
{"file is read only", EROFS},
|
|
|
|
{"file has been removed", EIDRM},
|
|
|
|
{"only support truncation to zero length", EPERM},
|
|
|
|
{"cannot remove root", EPERM},
|
|
|
|
{"file too big", EFBIG},
|
|
|
|
{"venti i/o error", EIO},
|
|
|
|
/* these are not errors */
|
|
|
|
{"u9fs rhostsauth: no authentication required", 0},
|
|
|
|
{"u9fs authnone: no authentication required", 0},
|
|
|
|
{NULL, -1}
|
|
|
|
};
|
|
|
|
|
2007-07-11 06:57:28 +08:00
|
|
|
/**
|
2008-03-05 21:08:09 +08:00
|
|
|
* p9_error_init - preload mappings into hash list
|
2007-07-11 06:57:28 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int p9_error_init(void)
|
|
|
|
{
|
|
|
|
struct errormap *c;
|
|
|
|
int bucket;
|
|
|
|
|
|
|
|
/* initialize hash table */
|
|
|
|
for (bucket = 0; bucket < ERRHASHSZ; bucket++)
|
|
|
|
INIT_HLIST_HEAD(&hash_errmap[bucket]);
|
|
|
|
|
|
|
|
/* load initial error map into hash table */
|
|
|
|
for (c = errmap; c->name != NULL; c++) {
|
|
|
|
c->namelen = strlen(c->name);
|
|
|
|
bucket = jhash(c->name, c->namelen, 0) % ERRHASHSZ;
|
|
|
|
INIT_HLIST_NODE(&c->list);
|
|
|
|
hlist_add_head(&c->list, &hash_errmap[bucket]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(p9_error_init);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* errstr2errno - convert error string to error number
|
|
|
|
* @errstr: error string
|
2008-03-05 21:08:09 +08:00
|
|
|
* @len: length of error string
|
2007-07-11 06:57:28 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int p9_errstr2errno(char *errstr, int len)
|
|
|
|
{
|
|
|
|
int errno;
|
|
|
|
struct errormap *c;
|
|
|
|
int bucket;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
c = NULL;
|
|
|
|
bucket = jhash(errstr, len, 0) % ERRHASHSZ;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 09:06:00 +08:00
|
|
|
hlist_for_each_entry(c, &hash_errmap[bucket], list) {
|
2007-07-11 06:57:28 +08:00
|
|
|
if (c->namelen == len && !memcmp(c->name, errstr, len)) {
|
|
|
|
errno = c->val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errno == 0) {
|
|
|
|
/* TODO: if error isn't found, add it dynamically */
|
|
|
|
errstr[len] = 0;
|
2011-11-29 02:40:46 +08:00
|
|
|
pr_err("%s: server reported unknown error %s\n",
|
|
|
|
__func__, errstr);
|
2009-08-18 05:38:45 +08:00
|
|
|
errno = ESERVERFAULT;
|
2007-07-11 06:57:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(p9_errstr2errno);
|