From 3ed8491c8a75cefe95b57f7f428a3e2ddd421e97 Mon Sep 17 00:00:00 2001 From: Eric Van Hensbergen Date: Fri, 9 Sep 2005 13:04:24 -0700 Subject: [PATCH] v9fs: debug and support routines This part of the patch contains debug and other misc routines. Signed-off-by: Eric Van Hensbergen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/9p/error.h | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 fs/9p/error.h (limited to 'fs/9p/error.h') diff --git a/fs/9p/error.h b/fs/9p/error.h new file mode 100644 index 000000000000..4bf2cf5aa1bb --- /dev/null +++ b/fs/9p/error.h @@ -0,0 +1,181 @@ +/* + * linux/fs/9p/error.h + * + * Huge Nasty Error Table + * + * Plan 9 uses error strings, Unix uses error numbers. This table tries to + * match UNIX strings and Plan 9 strings to unix error numbers. It is used + * to preload the dynamic error table which can also track user-specific error + * strings. + * + * Copyright (C) 2004 by Eric Van Hensbergen + * Copyright (C) 2002 by Ron Minnich + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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 + * + */ + +#include + +struct errormap { + char *name; + int val; + + struct hlist_node list; +}; + +#define ERRHASHSZ 32 +static struct hlist_head hash_errmap[ERRHASHSZ]; + +/* FixMe - reduce to a reasonable size */ +static struct errormap errmap[] = { + {"Operation not permitted", 1}, + {"wstat prohibited", 1}, + {"No such file or directory", 2}, + {"file not found", 2}, + {"Interrupted system call", 4}, + {"Input/output error", 5}, + {"No such device or address", 6}, + {"Argument list too long", 7}, + {"Bad file descriptor", 9}, + {"Resource temporarily unavailable", 11}, + {"Cannot allocate memory", 12}, + {"Permission denied", 13}, + {"Bad address", 14}, + {"Block device required", 15}, + {"Device or resource busy", 16}, + {"File exists", 17}, + {"Invalid cross-device link", 18}, + {"No such device", 19}, + {"Not a directory", 20}, + {"Is a directory", 21}, + {"Invalid argument", 22}, + {"Too many open files in system", 23}, + {"Too many open files", 24}, + {"Text file busy", 26}, + {"File too large", 27}, + {"No space left on device", 28}, + {"Illegal seek", 29}, + {"Read-only file system", 30}, + {"Too many links", 31}, + {"Broken pipe", 32}, + {"Numerical argument out of domain", 33}, + {"Numerical result out of range", 34}, + {"Resource deadlock avoided", 35}, + {"File name too long", 36}, + {"No locks available", 37}, + {"Function not implemented", 38}, + {"Directory not empty", 39}, + {"Too many levels of symbolic links", 40}, + {"Unknown error 41", 41}, + {"No message of desired type", 42}, + {"Identifier removed", 43}, + {"File locking deadlock error", 58}, + {"No data available", 61}, + {"Machine is not on the network", 64}, + {"Package not installed", 65}, + {"Object is remote", 66}, + {"Link has been severed", 67}, + {"Communication error on send", 70}, + {"Protocol error", 71}, + {"Bad message", 74}, + {"File descriptor in bad state", 77}, + {"Streams pipe error", 86}, + {"Too many users", 87}, + {"Socket operation on non-socket", 88}, + {"Message too long", 90}, + {"Protocol not available", 92}, + {"Protocol not supported", 93}, + {"Socket type not supported", 94}, + {"Operation not supported", 95}, + {"Protocol family not supported", 96}, + {"Network is down", 100}, + {"Network is unreachable", 101}, + {"Network dropped connection on reset", 102}, + {"Software caused connection abort", 103}, + {"Connection reset by peer", 104}, + {"No buffer space available", 105}, + {"Transport endpoint is already connected", 106}, + {"Transport endpoint is not connected", 107}, + {"Cannot send after transport endpoint shutdown", 108}, + {"Connection timed out", 110}, + {"Connection refused", 111}, + {"Host is down", 112}, + {"No route to host", 113}, + {"Operation already in progress", 114}, + {"Operation now in progress", 115}, + {"Is a named type file", 120}, + {"Remote I/O error", 121}, + {"Disk quota exceeded", 122}, + {"Operation canceled", 125}, + {"Unknown error 126", 126}, + {"Unknown error 127", 127}, +/* 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}, + {"not a member of proposed group", EINVAL}, + {"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} +}; + +extern int v9fs_error_init(void); +extern int v9fs_errstr2errno(char *errstr); -- cgit v1.2.3 From 1346f51ede71fc1e5021062898d150e192dc4dc8 Mon Sep 17 00:00:00 2001 From: Eric Van Hensbergen Date: Fri, 9 Sep 2005 13:04:25 -0700 Subject: [PATCH] v9fs: Change error magic numbers to defined constants Change magic error numbers to system defined constants in v9fs error.h As suggested by Jan-Benedict Glaw. Signed-off-by: Eric Van Hensbergen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/9p/error.h | 158 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 77 insertions(+), 81 deletions(-) (limited to 'fs/9p/error.h') diff --git a/fs/9p/error.h b/fs/9p/error.h index 4bf2cf5aa1bb..6dbb66f5b28f 100644 --- a/fs/9p/error.h +++ b/fs/9p/error.h @@ -30,6 +30,7 @@ */ #include +#include struct errormap { char *name; @@ -43,87 +44,82 @@ static struct hlist_head hash_errmap[ERRHASHSZ]; /* FixMe - reduce to a reasonable size */ static struct errormap errmap[] = { - {"Operation not permitted", 1}, - {"wstat prohibited", 1}, - {"No such file or directory", 2}, - {"file not found", 2}, - {"Interrupted system call", 4}, - {"Input/output error", 5}, - {"No such device or address", 6}, - {"Argument list too long", 7}, - {"Bad file descriptor", 9}, - {"Resource temporarily unavailable", 11}, - {"Cannot allocate memory", 12}, - {"Permission denied", 13}, - {"Bad address", 14}, - {"Block device required", 15}, - {"Device or resource busy", 16}, - {"File exists", 17}, - {"Invalid cross-device link", 18}, - {"No such device", 19}, - {"Not a directory", 20}, - {"Is a directory", 21}, - {"Invalid argument", 22}, - {"Too many open files in system", 23}, - {"Too many open files", 24}, - {"Text file busy", 26}, - {"File too large", 27}, - {"No space left on device", 28}, - {"Illegal seek", 29}, - {"Read-only file system", 30}, - {"Too many links", 31}, - {"Broken pipe", 32}, - {"Numerical argument out of domain", 33}, - {"Numerical result out of range", 34}, - {"Resource deadlock avoided", 35}, - {"File name too long", 36}, - {"No locks available", 37}, - {"Function not implemented", 38}, - {"Directory not empty", 39}, - {"Too many levels of symbolic links", 40}, - {"Unknown error 41", 41}, - {"No message of desired type", 42}, - {"Identifier removed", 43}, - {"File locking deadlock error", 58}, - {"No data available", 61}, - {"Machine is not on the network", 64}, - {"Package not installed", 65}, - {"Object is remote", 66}, - {"Link has been severed", 67}, - {"Communication error on send", 70}, - {"Protocol error", 71}, - {"Bad message", 74}, - {"File descriptor in bad state", 77}, - {"Streams pipe error", 86}, - {"Too many users", 87}, - {"Socket operation on non-socket", 88}, - {"Message too long", 90}, - {"Protocol not available", 92}, - {"Protocol not supported", 93}, - {"Socket type not supported", 94}, - {"Operation not supported", 95}, - {"Protocol family not supported", 96}, - {"Network is down", 100}, - {"Network is unreachable", 101}, - {"Network dropped connection on reset", 102}, - {"Software caused connection abort", 103}, - {"Connection reset by peer", 104}, - {"No buffer space available", 105}, - {"Transport endpoint is already connected", 106}, - {"Transport endpoint is not connected", 107}, - {"Cannot send after transport endpoint shutdown", 108}, - {"Connection timed out", 110}, - {"Connection refused", 111}, - {"Host is down", 112}, - {"No route to host", 113}, - {"Operation already in progress", 114}, - {"Operation now in progress", 115}, - {"Is a named type file", 120}, - {"Remote I/O error", 121}, - {"Disk quota exceeded", 122}, - {"Operation canceled", 125}, - {"Unknown error 126", 126}, - {"Unknown error 127", 127}, + {"Operation not permitted", EPERM}, + {"wstat prohibited", EPERM}, + {"No such file or directory", ENOENT}, + {"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}, /* errors from fossil, vacfs, and u9fs */ {"fid unknown or out of range", EBADF}, {"permission denied", EACCES}, -- cgit v1.2.3 From 73c592b9b844cc353bbaea690fb4aa652ac168a6 Mon Sep 17 00:00:00 2001 From: Eric Van Hensbergen Date: Fri, 9 Sep 2005 13:04:26 -0700 Subject: [PATCH] v9fs: Clean-up vfs_inode and setattr functions Cleanup code in v9fs vfs_inode as suggested by Alexey Dobriyan. Did some major revamping of the v9fs setattr code to remove unnecessary allocations and clean up some dead-code. Signed-off-by: Eric Van Hensbergen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/9p/error.h | 2 +- fs/9p/vfs_inode.c | 131 +++++++++++++++--------------------------------------- 2 files changed, 36 insertions(+), 97 deletions(-) (limited to 'fs/9p/error.h') diff --git a/fs/9p/error.h b/fs/9p/error.h index 6dbb66f5b28f..2eb5927d589e 100644 --- a/fs/9p/error.h +++ b/fs/9p/error.h @@ -139,7 +139,7 @@ static struct errormap errmap[] = { {"illegal mode", EINVAL}, {"illegal name", ENAMETOOLONG}, {"not a directory", ENOTDIR}, - {"not a member of proposed group", EINVAL}, + {"not a member of proposed group", EPERM}, {"not owner", EACCES}, {"only owner can change group in wstat", EACCES}, {"read only file system", EROFS}, diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c index ef78af7ef04b..6d2357d1dacd 100644 --- a/fs/9p/vfs_inode.c +++ b/fs/9p/vfs_inode.c @@ -1,7 +1,7 @@ /* * linux/fs/9p/vfs_inode.c * - * This file contians vfs inode ops for the 9P2000 protocol. + * This file contains vfs inode ops for the 9P2000 protocol. * * Copyright (C) 2004 by Eric Van Hensbergen * Copyright (C) 2002 by Ron Minnich @@ -54,7 +54,7 @@ static struct inode_operations v9fs_symlink_inode_operations; * */ -static inline int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) +static int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) { int res; res = mode & 0777; @@ -92,7 +92,7 @@ static inline int unixmode2p9mode(struct v9fs_session_info *v9ses, int mode) * */ -static inline int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) +static int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) { int res; @@ -132,7 +132,7 @@ static inline int p9mode2unixmode(struct v9fs_session_info *v9ses, int mode) * */ -static inline void +static void v9fs_blank_mistat(struct v9fs_session_info *v9ses, struct v9fs_stat *mistat) { mistat->type = ~0; @@ -160,7 +160,7 @@ v9fs_blank_mistat(struct v9fs_session_info *v9ses, struct v9fs_stat *mistat) /** * v9fs_mistat2unix - convert mistat to unix stat * @mistat: Plan 9 metadata (mistat) structure - * @stat: unix metadata (stat) structure to populate + * @buf: unix metadata (stat) structure to populate * @sb: superblock * */ @@ -177,22 +177,11 @@ v9fs_mistat2unix(struct v9fs_stat *mistat, struct stat *buf, buf->st_mtime = mistat->mtime; buf->st_ctime = mistat->mtime; - if (v9ses && v9ses->extended) { - /* TODO: string to uid mapping via user-space daemon */ - buf->st_uid = mistat->n_uid; - buf->st_gid = mistat->n_gid; - - sscanf(mistat->uid, "%x", (unsigned int *)&buf->st_uid); - sscanf(mistat->gid, "%x", (unsigned int *)&buf->st_gid); - } else { - buf->st_uid = v9ses->uid; - buf->st_gid = v9ses->gid; - } - buf->st_uid = (unsigned short)-1; buf->st_gid = (unsigned short)-1; if (v9ses && v9ses->extended) { + /* TODO: string to uid mapping via user-space daemon */ if (mistat->n_uid != -1) sscanf(mistat->uid, "%x", (unsigned int *)&buf->st_uid); @@ -290,7 +279,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode) * @dir: directory inode file is being created in * @file_dentry: dentry file is being created in * @perm: permissions file is being created with - * @open_mode: resulting open mode for file ??? + * @open_mode: resulting open mode for file * */ @@ -434,9 +423,9 @@ v9fs_create(struct inode *dir, /** * v9fs_remove - helper function to remove files and directories - * @inode: directory inode that is being deleted - * @dentry: dentry that is being deleted - * @rmdir: where we are a file or a directory + * @dir: directory inode that is being deleted + * @file: dentry that is being deleted + * @rmdir: removing a directory * */ @@ -502,7 +491,7 @@ v9fs_vfs_create(struct inode *inode, struct dentry *dentry, int perm, /** * v9fs_vfs_mkdir - VFS mkdir hook to create a directory - * @i: inode that is being unlinked + * @inode: inode that is being unlinked * @dentry: dentry that is being unlinked * @mode: mode for new directory * @@ -624,7 +613,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry, /** * v9fs_vfs_unlink - VFS unlink hook to delete an inode * @i: inode that is being unlinked - * @dentry: dentry that is being unlinked + * @d: dentry that is being unlinked * */ @@ -636,7 +625,7 @@ static int v9fs_vfs_unlink(struct inode *i, struct dentry *d) /** * v9fs_vfs_rmdir - VFS unlink hook to delete a directory * @i: inode that is being unlinked - * @dentry: dentry that is being unlinked + * @d: dentry that is being unlinked * */ @@ -674,6 +663,9 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry, dprintk(DEBUG_VFS, "\n"); + if (!mistat) + return -ENOMEM; + if ((!oldfid) || (!olddirfid) || (!newdirfid)) { dprintk(DEBUG_ERROR, "problem with arguments\n"); return -EBADF; @@ -771,20 +763,21 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) { struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dentry->d_inode); struct v9fs_fid *fid = v9fs_fid_lookup(dentry, FID_OP); - struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); struct v9fs_fcall *fcall = NULL; + struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); int res = -EPERM; dprintk(DEBUG_VFS, "\n"); + + if (!mistat) + return -ENOMEM; + if (!fid) { dprintk(DEBUG_ERROR, "Couldn't find fid associated with dentry\n"); return -EBADF; } - if (!mistat) - return -ENOMEM; - v9fs_blank_mistat(v9ses, mistat); if (iattr->ia_valid & ATTR_MODE) mistat->mode = unixmode2p9mode(v9ses, iattr->ia_mode); @@ -799,72 +792,19 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr) mistat->length = iattr->ia_size; if (v9ses->extended) { - char *uid = kmalloc(strlen(mistat->uid), GFP_KERNEL); - char *gid = kmalloc(strlen(mistat->gid), GFP_KERNEL); - char *muid = kmalloc(strlen(mistat->muid), GFP_KERNEL); - char *name = kmalloc(strlen(mistat->name), GFP_KERNEL); - char *extension = kmalloc(strlen(mistat->extension), - GFP_KERNEL); - - if ((!uid) || (!gid) || (!muid) || (!name) || (!extension)) { - kfree(uid); - kfree(gid); - kfree(muid); - kfree(name); - kfree(extension); - - return -ENOMEM; - } - - strcpy(uid, mistat->uid); - strcpy(gid, mistat->gid); - strcpy(muid, mistat->muid); - strcpy(name, mistat->name); - strcpy(extension, mistat->extension); + char *ptr = mistat->data+1; if (iattr->ia_valid & ATTR_UID) { - if (strlen(uid) != 8) { - dprintk(DEBUG_ERROR, "uid strlen is %u not 8\n", - (unsigned int)strlen(uid)); - sprintf(uid, "%08x", iattr->ia_uid); - } else { - kfree(uid); - uid = kmalloc(9, GFP_KERNEL); - } - - sprintf(uid, "%08x", iattr->ia_uid); + mistat->uid = ptr; + ptr += 1+sprintf(ptr, "%08x", iattr->ia_uid); mistat->n_uid = iattr->ia_uid; } if (iattr->ia_valid & ATTR_GID) { - if (strlen(gid) != 8) - dprintk(DEBUG_ERROR, "gid strlen is %u not 8\n", - (unsigned int)strlen(gid)); - else { - kfree(gid); - gid = kmalloc(9, GFP_KERNEL); - } - - sprintf(gid, "%08x", iattr->ia_gid); + mistat->gid = ptr; + ptr += 1+sprintf(ptr, "%08x", iattr->ia_gid); mistat->n_gid = iattr->ia_gid; } - - mistat->uid = mistat->data; - strcpy(mistat->uid, uid); - mistat->gid = mistat->data + strlen(uid) + 1; - strcpy(mistat->gid, gid); - mistat->muid = mistat->gid + strlen(gid) + 1; - strcpy(mistat->muid, muid); - mistat->name = mistat->muid + strlen(muid) + 1; - strcpy(mistat->name, name); - mistat->extension = mistat->name + strlen(name) + 1; - strcpy(mistat->extension, extension); - - kfree(uid); - kfree(gid); - kfree(muid); - kfree(name); - kfree(extension); } res = v9fs_t_wstat(v9ses, fid->fid, mistat, &fcall); @@ -985,17 +925,14 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) int retval = -EPERM; struct v9fs_fid *newfid; struct v9fs_session_info *v9ses = v9fs_inode2v9ses(dir); - struct super_block *sb = dir ? dir->i_sb : NULL; struct v9fs_fcall *fcall = NULL; struct v9fs_stat *mistat = kmalloc(v9ses->maxdata, GFP_KERNEL); dprintk(DEBUG_VFS, " %lu,%s,%s\n", dir->i_ino, dentry->d_name.name, symname); - if ((!dentry) || (!sb) || (!v9ses)) { - dprintk(DEBUG_ERROR, "problem with arguments\n"); - return -EBADF; - } + if (!mistat) + return -ENOMEM; if (!v9ses->extended) { dprintk(DEBUG_ERROR, "not extended\n"); @@ -1040,7 +977,7 @@ v9fs_vfs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) /** * v9fs_readlink - read a symlink's location (internal version) * @dentry: dentry for symlink - * @buf: buffer to load symlink location into + * @buffer: buffer to load symlink location into * @buflen: length of buffer * */ @@ -1179,7 +1116,7 @@ static void v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void * v9fs_vfs_link - create a hardlink * @old_dentry: dentry for file to link to * @dir: inode destination for new link - * @new_dentry: dentry for link + * @dentry: dentry for link * */ @@ -1274,6 +1211,9 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) dprintk(DEBUG_VFS, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino, dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev)); + if (!mistat) + return -ENOMEM; + if (!new_valid_dev(rdev)) { retval = -EINVAL; goto FreeMem; @@ -1302,7 +1242,8 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) sprintf(symname, "b %u %u", MAJOR(rdev), MINOR(rdev)); else if (S_ISCHR(mode)) sprintf(symname, "c %u %u", MAJOR(rdev), MINOR(rdev)); - else if (S_ISFIFO(mode)) ; /* DO NOTHING */ + else if (S_ISFIFO(mode)) + ; /* DO NOTHING */ else { retval = -EINVAL; goto FreeMem; @@ -1319,8 +1260,6 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev) FCALL_ERROR(fcall)); goto FreeMem; } - - kfree(fcall); } /* need to update dcache so we show up */ -- cgit v1.2.3 From cb2e87a65d6cd735eb06fa595bf90497af28c37b Mon Sep 17 00:00:00 2001 From: Eric Van Hensbergen Date: Fri, 9 Sep 2005 13:04:28 -0700 Subject: [PATCH] v9fs: fix handling of malformed 9P messages This patch attempts to do a better job of cleaning up after detecting errors on the transport. This should also improve error reporting on broken connections to servers. Signed-off-by: Latchesar Ionkov Signed-off-by: Eric Van Hensbergen Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/9p/error.h | 1 + fs/9p/mux.c | 53 ++++++++++++++++++++++++++++++++++------------------- fs/9p/mux.h | 1 + fs/9p/trans_sock.c | 12 ++++++++++-- 4 files changed, 46 insertions(+), 21 deletions(-) (limited to 'fs/9p/error.h') diff --git a/fs/9p/error.h b/fs/9p/error.h index 2eb5927d589e..78f89acf7c9a 100644 --- a/fs/9p/error.h +++ b/fs/9p/error.h @@ -47,6 +47,7 @@ static struct errormap errmap[] = { {"Operation not permitted", EPERM}, {"wstat prohibited", EPERM}, {"No such file or directory", ENOENT}, + {"directory entry not found", ENOENT}, {"file not found", ENOENT}, {"Interrupted system call", EINTR}, {"Input/output error", EIO}, diff --git a/fs/9p/mux.c b/fs/9p/mux.c index 0854bef58c16..8835b576f744 100644 --- a/fs/9p/mux.c +++ b/fs/9p/mux.c @@ -162,18 +162,21 @@ static int v9fs_recv(struct v9fs_session_info *v9ses, struct v9fs_rpcreq *req) dprintk(DEBUG_MUX, "waiting for response: %d\n", req->tcall->tag); ret = wait_event_interruptible(v9ses->read_wait, ((v9ses->transport->status != Connected) || - (req->rcall != 0) || dprintcond(v9ses, req))); + (req->rcall != 0) || (req->err < 0) || + dprintcond(v9ses, req))); dprintk(DEBUG_MUX, "got it: rcall %p\n", req->rcall); + + spin_lock(&v9ses->muxlock); + list_del(&req->next); + spin_unlock(&v9ses->muxlock); + + if (req->err < 0) + return req->err; + if (v9ses->transport->status == Disconnected) return -ECONNRESET; - if (ret == 0) { - spin_lock(&v9ses->muxlock); - list_del(&req->next); - spin_unlock(&v9ses->muxlock); - } - return ret; } @@ -245,6 +248,9 @@ v9fs_mux_rpc(struct v9fs_session_info *v9ses, struct v9fs_fcall *tcall, if (!v9ses) return -EINVAL; + if (!v9ses->transport || v9ses->transport->status != Connected) + return -EIO; + if (rcall) *rcall = NULL; @@ -257,6 +263,7 @@ v9fs_mux_rpc(struct v9fs_session_info *v9ses, struct v9fs_fcall *tcall, tcall->tag = tid; req.tcall = tcall; + req.err = 0; req.rcall = NULL; ret = v9fs_send(v9ses, &req); @@ -371,16 +378,21 @@ static int v9fs_recvproc(void *data) } err = read_message(v9ses, rcall, v9ses->maxdata + V9FS_IOHDRSZ); - if (err < 0) { - kfree(rcall); - break; - } spin_lock(&v9ses->muxlock); - list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { - if (rreq->tcall->tag == rcall->tag) { - req = rreq; - req->rcall = rcall; - break; + if (err < 0) { + list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { + rreq->err = err; + } + if(err != -ERESTARTSYS) + eprintk(KERN_ERR, + "Transport error while reading message %d\n", err); + } else { + list_for_each_entry_safe(rreq, rptr, &v9ses->mux_fcalls, next) { + if (rreq->tcall->tag == rcall->tag) { + req = rreq; + req->rcall = rcall; + break; + } } } @@ -399,9 +411,10 @@ static int v9fs_recvproc(void *data) spin_unlock(&v9ses->muxlock); if (!req) { - dprintk(DEBUG_ERROR, - "unexpected response: id %d tag %d\n", - rcall->id, rcall->tag); + if (err >= 0) + dprintk(DEBUG_ERROR, + "unexpected response: id %d tag %d\n", + rcall->id, rcall->tag); kfree(rcall); } @@ -410,6 +423,8 @@ static int v9fs_recvproc(void *data) set_current_state(TASK_INTERRUPTIBLE); } + v9ses->transport->close(v9ses->transport); + /* Inform all pending processes about the failure */ wake_up_all(&v9ses->read_wait); diff --git a/fs/9p/mux.h b/fs/9p/mux.h index 82ce793af1b5..4994cb10badf 100644 --- a/fs/9p/mux.h +++ b/fs/9p/mux.h @@ -28,6 +28,7 @@ struct v9fs_rpcreq { struct v9fs_fcall *tcall; struct v9fs_fcall *rcall; + int err; /* error code if response failed */ /* XXX - could we put scatter/gather buffers here? */ diff --git a/fs/9p/trans_sock.c b/fs/9p/trans_sock.c index 081d1c847803..01e26f0013ac 100644 --- a/fs/9p/trans_sock.c +++ b/fs/9p/trans_sock.c @@ -254,7 +254,12 @@ v9fs_unix_init(struct v9fs_session_info *v9ses, const char *dev_name, static void v9fs_sock_close(struct v9fs_transport *trans) { - struct v9fs_trans_sock *ts = trans ? trans->priv : NULL; + struct v9fs_trans_sock *ts; + + if (!trans) + return; + + ts = trans->priv; if ((ts) && (ts->s)) { dprintk(DEBUG_TRANS, "closing the socket %p\n", ts->s); @@ -264,7 +269,10 @@ static void v9fs_sock_close(struct v9fs_transport *trans) dprintk(DEBUG_TRANS, "socket closed\n"); } - kfree(ts); + if (ts) + kfree(ts); + + trans->priv = NULL; } struct v9fs_transport v9fs_trans_tcp = { -- cgit v1.2.3