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