Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * nfsproc2.c Process version 2 NFS requests. |
| 3 | * linux/fs/nfsd/nfs2proc.c |
| 4 | * |
| 5 | * Process version 2 NFS requests. |
| 6 | * |
| 7 | * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de> |
| 8 | */ |
| 9 | |
| 10 | #include <linux/linkage.h> |
| 11 | #include <linux/time.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/fs.h> |
| 14 | #include <linux/stat.h> |
| 15 | #include <linux/fcntl.h> |
| 16 | #include <linux/net.h> |
| 17 | #include <linux/in.h> |
| 18 | #include <linux/namei.h> |
| 19 | #include <linux/unistd.h> |
| 20 | #include <linux/slab.h> |
| 21 | |
Chuck Lever | ad06e4b | 2007-02-12 00:53:32 -0800 | [diff] [blame] | 22 | #include <linux/sunrpc/clnt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/sunrpc/svc.h> |
| 24 | #include <linux/nfsd/nfsd.h> |
| 25 | #include <linux/nfsd/cache.h> |
| 26 | #include <linux/nfsd/xdr.h> |
J. Bruce Fields | 0a3adad | 2009-11-04 18:12:35 -0500 | [diff] [blame^] | 27 | #include "vfs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
| 29 | typedef struct svc_rqst svc_rqst; |
| 30 | typedef struct svc_buf svc_buf; |
| 31 | |
| 32 | #define NFSDDBG_FACILITY NFSDDBG_PROC |
| 33 | |
| 34 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 35 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | nfsd_proc_null(struct svc_rqst *rqstp, void *argp, void *resp) |
| 37 | { |
| 38 | return nfs_ok; |
| 39 | } |
| 40 | |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 41 | static __be32 |
| 42 | nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp) |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 43 | { |
| 44 | if (err) return err; |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 45 | return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt, |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 46 | resp->fh.fh_dentry, |
| 47 | &resp->stat)); |
| 48 | } |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 49 | static __be32 |
| 50 | nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp) |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 51 | { |
| 52 | if (err) return err; |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 53 | return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt, |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 54 | resp->fh.fh_dentry, |
| 55 | &resp->stat)); |
| 56 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* |
| 58 | * Get a file's attributes |
| 59 | * N.B. After this call resp->fh needs an fh_put |
| 60 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 61 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp, |
| 63 | struct nfsd_attrstat *resp) |
| 64 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 65 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh)); |
| 67 | |
| 68 | fh_copy(&resp->fh, &argp->fh); |
J. Bruce Fields | 04716e6 | 2008-08-07 13:00:20 -0400 | [diff] [blame] | 69 | nfserr = fh_verify(rqstp, &resp->fh, 0, |
| 70 | NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT); |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 71 | return nfsd_return_attrs(nfserr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | /* |
| 75 | * Set a file's attributes |
| 76 | * N.B. After this call resp->fh needs an fh_put |
| 77 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 78 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | nfsd_proc_setattr(struct svc_rqst *rqstp, struct nfsd_sattrargs *argp, |
| 80 | struct nfsd_attrstat *resp) |
| 81 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 82 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n", |
| 84 | SVCFH_fmt(&argp->fh), |
| 85 | argp->attrs.ia_valid, (long) argp->attrs.ia_size); |
| 86 | |
| 87 | fh_copy(&resp->fh, &argp->fh); |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 88 | nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,0, (time_t)0); |
| 89 | return nfsd_return_attrs(nfserr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Look up a path name component |
| 94 | * Note: the dentry in the resp->fh may be negative if the file |
| 95 | * doesn't exist yet. |
| 96 | * N.B. After this call resp->fh needs an fh_put |
| 97 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 98 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | nfsd_proc_lookup(struct svc_rqst *rqstp, struct nfsd_diropargs *argp, |
| 100 | struct nfsd_diropres *resp) |
| 101 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 102 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | dprintk("nfsd: LOOKUP %s %.*s\n", |
| 105 | SVCFH_fmt(&argp->fh), argp->len, argp->name); |
| 106 | |
| 107 | fh_init(&resp->fh, NFS_FHSIZE); |
| 108 | nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len, |
| 109 | &resp->fh); |
| 110 | |
| 111 | fh_put(&argp->fh); |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 112 | return nfsd_return_dirop(nfserr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* |
| 116 | * Read a symlink. |
| 117 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 118 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | nfsd_proc_readlink(struct svc_rqst *rqstp, struct nfsd_readlinkargs *argp, |
| 120 | struct nfsd_readlinkres *resp) |
| 121 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 122 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh)); |
| 125 | |
| 126 | /* Read the symlink. */ |
| 127 | resp->len = NFS_MAXPATHLEN; |
| 128 | nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len); |
| 129 | |
| 130 | fh_put(&argp->fh); |
| 131 | return nfserr; |
| 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Read a portion of a file. |
| 136 | * N.B. After this call resp->fh needs an fh_put |
| 137 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 138 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp, |
| 140 | struct nfsd_readres *resp) |
| 141 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 142 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
| 144 | dprintk("nfsd: READ %s %d bytes at %d\n", |
| 145 | SVCFH_fmt(&argp->fh), |
| 146 | argp->count, argp->offset); |
| 147 | |
| 148 | /* Obtain buffer pointer for payload. 19 is 1 word for |
| 149 | * status, 17 words for fattr, and 1 word for the byte count. |
| 150 | */ |
| 151 | |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 152 | if (NFSSVC_MAXBLKSIZE_V2 < argp->count) { |
Chuck Lever | ad06e4b | 2007-02-12 00:53:32 -0800 | [diff] [blame] | 153 | char buf[RPC_MAX_ADDRBUFLEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | printk(KERN_NOTICE |
Chuck Lever | ad06e4b | 2007-02-12 00:53:32 -0800 | [diff] [blame] | 155 | "oversized read request from %s (%d bytes)\n", |
| 156 | svc_print_addr(rqstp, buf, sizeof(buf)), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | argp->count); |
Greg Banks | 7adae48 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 158 | argp->count = NFSSVC_MAXBLKSIZE_V2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
Jeff Layton | cd12301 | 2007-05-09 02:34:50 -0700 | [diff] [blame] | 160 | svc_reserve_auth(rqstp, (19<<2) + argp->count + 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | resp->count = argp->count; |
| 163 | nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL, |
| 164 | argp->offset, |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 165 | rqstp->rq_vec, argp->vlen, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | &resp->count); |
| 167 | |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 168 | if (nfserr) return nfserr; |
Jan Blunck | 5477549 | 2008-02-14 19:38:39 -0800 | [diff] [blame] | 169 | return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt, |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 170 | resp->fh.fh_dentry, |
| 171 | &resp->stat)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* |
| 175 | * Write data to a file |
| 176 | * N.B. After this call resp->fh needs an fh_put |
| 177 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 178 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp, |
| 180 | struct nfsd_attrstat *resp) |
| 181 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 182 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | int stable = 1; |
David Shaw | 31dec25 | 2009-03-05 20:16:14 -0500 | [diff] [blame] | 184 | unsigned long cnt = argp->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | dprintk("nfsd: WRITE %s %d bytes at %d\n", |
| 187 | SVCFH_fmt(&argp->fh), |
| 188 | argp->len, argp->offset); |
| 189 | |
| 190 | nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL, |
| 191 | argp->offset, |
NeilBrown | 3cc03b1 | 2006-10-04 02:15:47 -0700 | [diff] [blame] | 192 | rqstp->rq_vec, argp->vlen, |
David Shaw | 31dec25 | 2009-03-05 20:16:14 -0500 | [diff] [blame] | 193 | &cnt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | &stable); |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 195 | return nfsd_return_attrs(nfserr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /* |
| 199 | * CREATE processing is complicated. The keyword here is `overloaded.' |
| 200 | * The parent directory is kept locked between the check for existence |
| 201 | * and the actual create() call in compliance with VFS protocols. |
| 202 | * N.B. After this call _both_ argp->fh and resp->fh need an fh_put |
| 203 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 204 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp, |
| 206 | struct nfsd_diropres *resp) |
| 207 | { |
| 208 | svc_fh *dirfhp = &argp->fh; |
| 209 | svc_fh *newfhp = &resp->fh; |
| 210 | struct iattr *attr = &argp->attrs; |
| 211 | struct inode *inode; |
| 212 | struct dentry *dchild; |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 213 | int type, mode; |
| 214 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size); |
| 216 | |
| 217 | dprintk("nfsd: CREATE %s %.*s\n", |
| 218 | SVCFH_fmt(dirfhp), argp->len, argp->name); |
| 219 | |
| 220 | /* First verify the parent file handle */ |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 221 | nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (nfserr) |
| 223 | goto done; /* must fh_put dirfhp even on error */ |
| 224 | |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 225 | /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | nfserr = nfserr_acces; |
| 228 | if (!argp->len) |
| 229 | goto done; |
| 230 | nfserr = nfserr_exist; |
| 231 | if (isdotent(argp->name, argp->len)) |
| 232 | goto done; |
NeilBrown | 7ed9429 | 2006-10-04 02:15:43 -0700 | [diff] [blame] | 233 | fh_lock_nested(dirfhp, I_MUTEX_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len); |
| 235 | if (IS_ERR(dchild)) { |
| 236 | nfserr = nfserrno(PTR_ERR(dchild)); |
| 237 | goto out_unlock; |
| 238 | } |
| 239 | fh_init(newfhp, NFS_FHSIZE); |
| 240 | nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp); |
| 241 | if (!nfserr && !dchild->d_inode) |
| 242 | nfserr = nfserr_noent; |
| 243 | dput(dchild); |
| 244 | if (nfserr) { |
| 245 | if (nfserr != nfserr_noent) |
| 246 | goto out_unlock; |
| 247 | /* |
| 248 | * If the new file handle wasn't verified, we can't tell |
| 249 | * whether the file exists or not. Time to bail ... |
| 250 | */ |
| 251 | nfserr = nfserr_acces; |
| 252 | if (!newfhp->fh_dentry) { |
| 253 | printk(KERN_WARNING |
| 254 | "nfsd_proc_create: file handle not verified\n"); |
| 255 | goto out_unlock; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | inode = newfhp->fh_dentry->d_inode; |
| 260 | |
| 261 | /* Unfudge the mode bits */ |
| 262 | if (attr->ia_valid & ATTR_MODE) { |
| 263 | type = attr->ia_mode & S_IFMT; |
| 264 | mode = attr->ia_mode & ~S_IFMT; |
| 265 | if (!type) { |
| 266 | /* no type, so if target exists, assume same as that, |
| 267 | * else assume a file */ |
| 268 | if (inode) { |
| 269 | type = inode->i_mode & S_IFMT; |
| 270 | switch(type) { |
| 271 | case S_IFCHR: |
| 272 | case S_IFBLK: |
| 273 | /* reserve rdev for later checking */ |
| 274 | rdev = inode->i_rdev; |
| 275 | attr->ia_valid |= ATTR_SIZE; |
| 276 | |
| 277 | /* FALLTHROUGH */ |
| 278 | case S_IFIFO: |
| 279 | /* this is probably a permission check.. |
| 280 | * at least IRIX implements perm checking on |
| 281 | * echo thing > device-special-file-or-pipe |
| 282 | * by doing a CREATE with type==0 |
| 283 | */ |
J. Bruce Fields | 0ec757d | 2007-07-17 04:04:48 -0700 | [diff] [blame] | 284 | nfserr = nfsd_permission(rqstp, |
| 285 | newfhp->fh_export, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | newfhp->fh_dentry, |
Miklos Szeredi | 8837abc | 2008-06-16 13:20:29 +0200 | [diff] [blame] | 287 | NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (nfserr && nfserr != nfserr_rofs) |
| 289 | goto out_unlock; |
| 290 | } |
| 291 | } else |
| 292 | type = S_IFREG; |
| 293 | } |
| 294 | } else if (inode) { |
| 295 | type = inode->i_mode & S_IFMT; |
| 296 | mode = inode->i_mode & ~S_IFMT; |
| 297 | } else { |
| 298 | type = S_IFREG; |
| 299 | mode = 0; /* ??? */ |
| 300 | } |
| 301 | |
| 302 | attr->ia_valid |= ATTR_MODE; |
| 303 | attr->ia_mode = mode; |
| 304 | |
| 305 | /* Special treatment for non-regular files according to the |
| 306 | * gospel of sun micro |
| 307 | */ |
| 308 | if (type != S_IFREG) { |
| 309 | int is_borc = 0; |
| 310 | if (type != S_IFBLK && type != S_IFCHR) { |
| 311 | rdev = 0; |
| 312 | } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) { |
| 313 | /* If you think you've seen the worst, grok this. */ |
| 314 | type = S_IFIFO; |
| 315 | } else { |
| 316 | /* Okay, char or block special */ |
| 317 | is_borc = 1; |
| 318 | if (!rdev) |
| 319 | rdev = wanted; |
| 320 | } |
| 321 | |
| 322 | /* we've used the SIZE information, so discard it */ |
| 323 | attr->ia_valid &= ~ATTR_SIZE; |
| 324 | |
| 325 | /* Make sure the type and device matches */ |
| 326 | nfserr = nfserr_exist; |
| 327 | if (inode && type != (inode->i_mode & S_IFMT)) |
| 328 | goto out_unlock; |
| 329 | } |
| 330 | |
| 331 | nfserr = 0; |
| 332 | if (!inode) { |
| 333 | /* File doesn't exist. Create it and set attrs */ |
| 334 | nfserr = nfsd_create(rqstp, dirfhp, argp->name, argp->len, |
| 335 | attr, type, rdev, newfhp); |
| 336 | } else if (type == S_IFREG) { |
| 337 | dprintk("nfsd: existing %s, valid=%x, size=%ld\n", |
| 338 | argp->name, attr->ia_valid, (long) attr->ia_size); |
| 339 | /* File already exists. We ignore all attributes except |
| 340 | * size, so that creat() behaves exactly like |
| 341 | * open(..., O_CREAT|O_TRUNC|O_WRONLY). |
| 342 | */ |
| 343 | attr->ia_valid &= ATTR_SIZE; |
| 344 | if (attr->ia_valid) |
| 345 | nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0); |
| 346 | } |
| 347 | |
| 348 | out_unlock: |
| 349 | /* We don't really need to unlock, as fh_put does it. */ |
| 350 | fh_unlock(dirfhp); |
| 351 | |
| 352 | done: |
| 353 | fh_put(dirfhp); |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 354 | return nfsd_return_dirop(nfserr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 357 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp, |
| 359 | void *resp) |
| 360 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 361 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh), |
| 364 | argp->len, argp->name); |
| 365 | |
| 366 | /* Unlink. -SIFDIR means file must not be a directory */ |
| 367 | nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len); |
| 368 | fh_put(&argp->fh); |
| 369 | return nfserr; |
| 370 | } |
| 371 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 372 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp, |
| 374 | void *resp) |
| 375 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 376 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | dprintk("nfsd: RENAME %s %.*s -> \n", |
| 379 | SVCFH_fmt(&argp->ffh), argp->flen, argp->fname); |
| 380 | dprintk("nfsd: -> %s %.*s\n", |
| 381 | SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname); |
| 382 | |
| 383 | nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen, |
| 384 | &argp->tfh, argp->tname, argp->tlen); |
| 385 | fh_put(&argp->ffh); |
| 386 | fh_put(&argp->tfh); |
| 387 | return nfserr; |
| 388 | } |
| 389 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 390 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp, |
| 392 | void *resp) |
| 393 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 394 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
| 396 | dprintk("nfsd: LINK %s ->\n", |
| 397 | SVCFH_fmt(&argp->ffh)); |
| 398 | dprintk("nfsd: %s %.*s\n", |
| 399 | SVCFH_fmt(&argp->tfh), |
| 400 | argp->tlen, |
| 401 | argp->tname); |
| 402 | |
| 403 | nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen, |
| 404 | &argp->ffh); |
| 405 | fh_put(&argp->ffh); |
| 406 | fh_put(&argp->tfh); |
| 407 | return nfserr; |
| 408 | } |
| 409 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 410 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp, |
| 412 | void *resp) |
| 413 | { |
| 414 | struct svc_fh newfh; |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 415 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n", |
| 418 | SVCFH_fmt(&argp->ffh), argp->flen, argp->fname, |
| 419 | argp->tlen, argp->tname); |
| 420 | |
| 421 | fh_init(&newfh, NFS_FHSIZE); |
| 422 | /* |
| 423 | * Create the link, look up new file and set attrs. |
| 424 | */ |
| 425 | nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen, |
| 426 | argp->tname, argp->tlen, |
| 427 | &newfh, &argp->attrs); |
| 428 | |
| 429 | |
| 430 | fh_put(&argp->ffh); |
| 431 | fh_put(&newfh); |
| 432 | return nfserr; |
| 433 | } |
| 434 | |
| 435 | /* |
| 436 | * Make directory. This operation is not idempotent. |
| 437 | * N.B. After this call resp->fh needs an fh_put |
| 438 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 439 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp, |
| 441 | struct nfsd_diropres *resp) |
| 442 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 443 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name); |
| 446 | |
| 447 | if (resp->fh.fh_dentry) { |
| 448 | printk(KERN_WARNING |
| 449 | "nfsd_proc_mkdir: response already verified??\n"); |
| 450 | } |
| 451 | |
| 452 | argp->attrs.ia_valid &= ~ATTR_SIZE; |
| 453 | fh_init(&resp->fh, NFS_FHSIZE); |
| 454 | nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len, |
| 455 | &argp->attrs, S_IFDIR, 0, &resp->fh); |
| 456 | fh_put(&argp->fh); |
David Shaw | 846f2fc | 2006-01-18 17:43:51 -0800 | [diff] [blame] | 457 | return nfsd_return_dirop(nfserr, resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /* |
| 461 | * Remove a directory |
| 462 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 463 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp, |
| 465 | void *resp) |
| 466 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 467 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
| 469 | dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name); |
| 470 | |
| 471 | nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len); |
| 472 | fh_put(&argp->fh); |
| 473 | return nfserr; |
| 474 | } |
| 475 | |
| 476 | /* |
| 477 | * Read a portion of a directory. |
| 478 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 479 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp, |
| 481 | struct nfsd_readdirres *resp) |
| 482 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 483 | int count; |
| 484 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | loff_t offset; |
| 486 | |
| 487 | dprintk("nfsd: READDIR %s %d bytes at %d\n", |
| 488 | SVCFH_fmt(&argp->fh), |
| 489 | argp->count, argp->cookie); |
| 490 | |
| 491 | /* Shrink to the client read size */ |
| 492 | count = (argp->count >> 2) - 2; |
| 493 | |
| 494 | /* Make sure we've room for the NULL ptr & eof flag */ |
| 495 | count -= 2; |
| 496 | if (count < 0) |
| 497 | count = 0; |
| 498 | |
| 499 | resp->buffer = argp->buffer; |
| 500 | resp->offset = NULL; |
| 501 | resp->buflen = count; |
| 502 | resp->common.err = nfs_ok; |
| 503 | /* Read directory and encode entries on the fly */ |
| 504 | offset = argp->cookie; |
| 505 | nfserr = nfsd_readdir(rqstp, &argp->fh, &offset, |
| 506 | &resp->common, nfssvc_encode_entry); |
| 507 | |
| 508 | resp->count = resp->buffer - argp->buffer; |
| 509 | if (resp->offset) |
| 510 | *resp->offset = htonl(offset); |
| 511 | |
| 512 | fh_put(&argp->fh); |
| 513 | return nfserr; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * Get file system info |
| 518 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 519 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp, |
| 521 | struct nfsd_statfsres *resp) |
| 522 | { |
Al Viro | c4d987b | 2006-10-19 23:29:00 -0700 | [diff] [blame] | 523 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
| 525 | dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh)); |
| 526 | |
J. Bruce Fields | 04716e6 | 2008-08-07 13:00:20 -0400 | [diff] [blame] | 527 | nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, |
| 528 | NFSD_MAY_BYPASS_GSS_ON_ROOT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | fh_put(&argp->fh); |
| 530 | return nfserr; |
| 531 | } |
| 532 | |
| 533 | /* |
| 534 | * NFSv2 Server procedures. |
| 535 | * Only the results of non-idempotent operations are cached. |
| 536 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | struct nfsd_void { int dummy; }; |
| 538 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | #define ST 1 /* status */ |
| 540 | #define FH 8 /* filehandle */ |
| 541 | #define AT 18 /* attributes */ |
| 542 | |
| 543 | static struct svc_procedure nfsd_procedures2[18] = { |
Yu Zhiguo | b9081d9 | 2009-06-09 17:33:34 +0800 | [diff] [blame] | 544 | [NFSPROC_NULL] = { |
| 545 | .pc_func = (svc_procfunc) nfsd_proc_null, |
| 546 | .pc_decode = (kxdrproc_t) nfssvc_decode_void, |
| 547 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 548 | .pc_argsize = sizeof(struct nfsd_void), |
| 549 | .pc_ressize = sizeof(struct nfsd_void), |
| 550 | .pc_cachetype = RC_NOCACHE, |
| 551 | .pc_xdrressize = ST, |
| 552 | }, |
| 553 | [NFSPROC_GETATTR] = { |
| 554 | .pc_func = (svc_procfunc) nfsd_proc_getattr, |
| 555 | .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle, |
| 556 | .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat, |
| 557 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, |
| 558 | .pc_argsize = sizeof(struct nfsd_fhandle), |
| 559 | .pc_ressize = sizeof(struct nfsd_attrstat), |
| 560 | .pc_cachetype = RC_NOCACHE, |
| 561 | .pc_xdrressize = ST+AT, |
| 562 | }, |
| 563 | [NFSPROC_SETATTR] = { |
| 564 | .pc_func = (svc_procfunc) nfsd_proc_setattr, |
| 565 | .pc_decode = (kxdrproc_t) nfssvc_decode_sattrargs, |
| 566 | .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat, |
| 567 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, |
| 568 | .pc_argsize = sizeof(struct nfsd_sattrargs), |
| 569 | .pc_ressize = sizeof(struct nfsd_attrstat), |
| 570 | .pc_cachetype = RC_REPLBUFF, |
| 571 | .pc_xdrressize = ST+AT, |
| 572 | }, |
| 573 | [NFSPROC_ROOT] = { |
| 574 | .pc_decode = (kxdrproc_t) nfssvc_decode_void, |
| 575 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 576 | .pc_argsize = sizeof(struct nfsd_void), |
| 577 | .pc_ressize = sizeof(struct nfsd_void), |
| 578 | .pc_cachetype = RC_NOCACHE, |
| 579 | .pc_xdrressize = ST, |
| 580 | }, |
| 581 | [NFSPROC_LOOKUP] = { |
| 582 | .pc_func = (svc_procfunc) nfsd_proc_lookup, |
| 583 | .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs, |
| 584 | .pc_encode = (kxdrproc_t) nfssvc_encode_diropres, |
| 585 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, |
| 586 | .pc_argsize = sizeof(struct nfsd_diropargs), |
| 587 | .pc_ressize = sizeof(struct nfsd_diropres), |
| 588 | .pc_cachetype = RC_NOCACHE, |
| 589 | .pc_xdrressize = ST+FH+AT, |
| 590 | }, |
| 591 | [NFSPROC_READLINK] = { |
| 592 | .pc_func = (svc_procfunc) nfsd_proc_readlink, |
| 593 | .pc_decode = (kxdrproc_t) nfssvc_decode_readlinkargs, |
| 594 | .pc_encode = (kxdrproc_t) nfssvc_encode_readlinkres, |
| 595 | .pc_argsize = sizeof(struct nfsd_readlinkargs), |
| 596 | .pc_ressize = sizeof(struct nfsd_readlinkres), |
| 597 | .pc_cachetype = RC_NOCACHE, |
| 598 | .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4, |
| 599 | }, |
| 600 | [NFSPROC_READ] = { |
| 601 | .pc_func = (svc_procfunc) nfsd_proc_read, |
| 602 | .pc_decode = (kxdrproc_t) nfssvc_decode_readargs, |
| 603 | .pc_encode = (kxdrproc_t) nfssvc_encode_readres, |
| 604 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, |
| 605 | .pc_argsize = sizeof(struct nfsd_readargs), |
| 606 | .pc_ressize = sizeof(struct nfsd_readres), |
| 607 | .pc_cachetype = RC_NOCACHE, |
| 608 | .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4, |
| 609 | }, |
| 610 | [NFSPROC_WRITECACHE] = { |
| 611 | .pc_decode = (kxdrproc_t) nfssvc_decode_void, |
| 612 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 613 | .pc_argsize = sizeof(struct nfsd_void), |
| 614 | .pc_ressize = sizeof(struct nfsd_void), |
| 615 | .pc_cachetype = RC_NOCACHE, |
| 616 | .pc_xdrressize = ST, |
| 617 | }, |
| 618 | [NFSPROC_WRITE] = { |
| 619 | .pc_func = (svc_procfunc) nfsd_proc_write, |
| 620 | .pc_decode = (kxdrproc_t) nfssvc_decode_writeargs, |
| 621 | .pc_encode = (kxdrproc_t) nfssvc_encode_attrstat, |
| 622 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, |
| 623 | .pc_argsize = sizeof(struct nfsd_writeargs), |
| 624 | .pc_ressize = sizeof(struct nfsd_attrstat), |
| 625 | .pc_cachetype = RC_REPLBUFF, |
| 626 | .pc_xdrressize = ST+AT, |
| 627 | }, |
| 628 | [NFSPROC_CREATE] = { |
| 629 | .pc_func = (svc_procfunc) nfsd_proc_create, |
| 630 | .pc_decode = (kxdrproc_t) nfssvc_decode_createargs, |
| 631 | .pc_encode = (kxdrproc_t) nfssvc_encode_diropres, |
| 632 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, |
| 633 | .pc_argsize = sizeof(struct nfsd_createargs), |
| 634 | .pc_ressize = sizeof(struct nfsd_diropres), |
| 635 | .pc_cachetype = RC_REPLBUFF, |
| 636 | .pc_xdrressize = ST+FH+AT, |
| 637 | }, |
| 638 | [NFSPROC_REMOVE] = { |
| 639 | .pc_func = (svc_procfunc) nfsd_proc_remove, |
| 640 | .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs, |
| 641 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 642 | .pc_argsize = sizeof(struct nfsd_diropargs), |
| 643 | .pc_ressize = sizeof(struct nfsd_void), |
| 644 | .pc_cachetype = RC_REPLSTAT, |
| 645 | .pc_xdrressize = ST, |
| 646 | }, |
| 647 | [NFSPROC_RENAME] = { |
| 648 | .pc_func = (svc_procfunc) nfsd_proc_rename, |
| 649 | .pc_decode = (kxdrproc_t) nfssvc_decode_renameargs, |
| 650 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 651 | .pc_argsize = sizeof(struct nfsd_renameargs), |
| 652 | .pc_ressize = sizeof(struct nfsd_void), |
| 653 | .pc_cachetype = RC_REPLSTAT, |
| 654 | .pc_xdrressize = ST, |
| 655 | }, |
| 656 | [NFSPROC_LINK] = { |
| 657 | .pc_func = (svc_procfunc) nfsd_proc_link, |
| 658 | .pc_decode = (kxdrproc_t) nfssvc_decode_linkargs, |
| 659 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 660 | .pc_argsize = sizeof(struct nfsd_linkargs), |
| 661 | .pc_ressize = sizeof(struct nfsd_void), |
| 662 | .pc_cachetype = RC_REPLSTAT, |
| 663 | .pc_xdrressize = ST, |
| 664 | }, |
| 665 | [NFSPROC_SYMLINK] = { |
| 666 | .pc_func = (svc_procfunc) nfsd_proc_symlink, |
| 667 | .pc_decode = (kxdrproc_t) nfssvc_decode_symlinkargs, |
| 668 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 669 | .pc_argsize = sizeof(struct nfsd_symlinkargs), |
| 670 | .pc_ressize = sizeof(struct nfsd_void), |
| 671 | .pc_cachetype = RC_REPLSTAT, |
| 672 | .pc_xdrressize = ST, |
| 673 | }, |
| 674 | [NFSPROC_MKDIR] = { |
| 675 | .pc_func = (svc_procfunc) nfsd_proc_mkdir, |
| 676 | .pc_decode = (kxdrproc_t) nfssvc_decode_createargs, |
| 677 | .pc_encode = (kxdrproc_t) nfssvc_encode_diropres, |
| 678 | .pc_release = (kxdrproc_t) nfssvc_release_fhandle, |
| 679 | .pc_argsize = sizeof(struct nfsd_createargs), |
| 680 | .pc_ressize = sizeof(struct nfsd_diropres), |
| 681 | .pc_cachetype = RC_REPLBUFF, |
| 682 | .pc_xdrressize = ST+FH+AT, |
| 683 | }, |
| 684 | [NFSPROC_RMDIR] = { |
| 685 | .pc_func = (svc_procfunc) nfsd_proc_rmdir, |
| 686 | .pc_decode = (kxdrproc_t) nfssvc_decode_diropargs, |
| 687 | .pc_encode = (kxdrproc_t) nfssvc_encode_void, |
| 688 | .pc_argsize = sizeof(struct nfsd_diropargs), |
| 689 | .pc_ressize = sizeof(struct nfsd_void), |
| 690 | .pc_cachetype = RC_REPLSTAT, |
| 691 | .pc_xdrressize = ST, |
| 692 | }, |
| 693 | [NFSPROC_READDIR] = { |
| 694 | .pc_func = (svc_procfunc) nfsd_proc_readdir, |
| 695 | .pc_decode = (kxdrproc_t) nfssvc_decode_readdirargs, |
| 696 | .pc_encode = (kxdrproc_t) nfssvc_encode_readdirres, |
| 697 | .pc_argsize = sizeof(struct nfsd_readdirargs), |
| 698 | .pc_ressize = sizeof(struct nfsd_readdirres), |
| 699 | .pc_cachetype = RC_NOCACHE, |
| 700 | }, |
| 701 | [NFSPROC_STATFS] = { |
| 702 | .pc_func = (svc_procfunc) nfsd_proc_statfs, |
| 703 | .pc_decode = (kxdrproc_t) nfssvc_decode_fhandle, |
| 704 | .pc_encode = (kxdrproc_t) nfssvc_encode_statfsres, |
| 705 | .pc_argsize = sizeof(struct nfsd_fhandle), |
| 706 | .pc_ressize = sizeof(struct nfsd_statfsres), |
| 707 | .pc_cachetype = RC_NOCACHE, |
| 708 | .pc_xdrressize = ST+5, |
| 709 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | }; |
| 711 | |
| 712 | |
| 713 | struct svc_version nfsd_version2 = { |
| 714 | .vs_vers = 2, |
| 715 | .vs_nproc = 18, |
| 716 | .vs_proc = nfsd_procedures2, |
| 717 | .vs_dispatch = nfsd_dispatch, |
| 718 | .vs_xdrsize = NFS2_SVC_XDRSIZE, |
| 719 | }; |
| 720 | |
| 721 | /* |
| 722 | * Map errnos to NFS errnos. |
| 723 | */ |
Al Viro | 63f10311 | 2006-10-19 23:28:54 -0700 | [diff] [blame] | 724 | __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | nfserrno (int errno) |
| 726 | { |
| 727 | static struct { |
Al Viro | 63f10311 | 2006-10-19 23:28:54 -0700 | [diff] [blame] | 728 | __be32 nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | int syserr; |
| 730 | } nfs_errtbl[] = { |
| 731 | { nfs_ok, 0 }, |
| 732 | { nfserr_perm, -EPERM }, |
| 733 | { nfserr_noent, -ENOENT }, |
| 734 | { nfserr_io, -EIO }, |
| 735 | { nfserr_nxio, -ENXIO }, |
| 736 | { nfserr_acces, -EACCES }, |
| 737 | { nfserr_exist, -EEXIST }, |
| 738 | { nfserr_xdev, -EXDEV }, |
| 739 | { nfserr_mlink, -EMLINK }, |
| 740 | { nfserr_nodev, -ENODEV }, |
| 741 | { nfserr_notdir, -ENOTDIR }, |
| 742 | { nfserr_isdir, -EISDIR }, |
| 743 | { nfserr_inval, -EINVAL }, |
| 744 | { nfserr_fbig, -EFBIG }, |
| 745 | { nfserr_nospc, -ENOSPC }, |
| 746 | { nfserr_rofs, -EROFS }, |
| 747 | { nfserr_mlink, -EMLINK }, |
| 748 | { nfserr_nametoolong, -ENAMETOOLONG }, |
| 749 | { nfserr_notempty, -ENOTEMPTY }, |
| 750 | #ifdef EDQUOT |
| 751 | { nfserr_dquot, -EDQUOT }, |
| 752 | #endif |
| 753 | { nfserr_stale, -ESTALE }, |
| 754 | { nfserr_jukebox, -ETIMEDOUT }, |
NeilBrown | 599eb30 | 2008-06-19 10:11:09 +1000 | [diff] [blame] | 755 | { nfserr_jukebox, -ERESTARTSYS }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | { nfserr_dropit, -EAGAIN }, |
| 757 | { nfserr_dropit, -ENOMEM }, |
| 758 | { nfserr_badname, -ESRCH }, |
| 759 | { nfserr_io, -ETXTBSY }, |
Andreas Gruenbacher | a838cc4 | 2005-06-22 17:16:24 +0000 | [diff] [blame] | 760 | { nfserr_notsupp, -EOPNOTSUPP }, |
Dean Hildebrand | b7aeda4 | 2008-12-15 19:40:15 +0200 | [diff] [blame] | 761 | { nfserr_toosmall, -ETOOSMALL }, |
J. Bruce Fields | f39bde2 | 2009-09-27 14:41:43 -0400 | [diff] [blame] | 762 | { nfserr_serverfault, -ESERVERFAULT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | }; |
| 764 | int i; |
| 765 | |
Al Viro | 63f10311 | 2006-10-19 23:28:54 -0700 | [diff] [blame] | 766 | for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | if (nfs_errtbl[i].syserr == errno) |
| 768 | return nfs_errtbl[i].nfserr; |
| 769 | } |
| 770 | printk (KERN_INFO "nfsd: non-standard errno: %d\n", errno); |
| 771 | return nfserr_io; |
| 772 | } |
| 773 | |