blob: 43c0419b8ddbd0ead78fabce06be943ace1439ae [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Process version 2 NFS requests.
4 *
5 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
6 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/namei.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Boaz Harrosh9a74af22009-12-03 20:30:56 +020010#include "cache.h"
11#include "xdr.h"
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050012#include "vfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14typedef struct svc_rqst svc_rqst;
15typedef struct svc_buf svc_buf;
16
17#define NFSDDBG_FACILITY NFSDDBG_PROC
18
19
Al Viro7111c662006-10-19 23:28:45 -070020static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020021nfsd_proc_null(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
23 return nfs_ok;
24}
25
Al Viroc4d987b2006-10-19 23:29:00 -070026static __be32
27nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp)
David Shaw846f2fc2006-01-18 17:43:51 -080028{
29 if (err) return err;
Al Viro3dadecc2013-01-24 02:18:08 -050030 return fh_getattr(&resp->fh, &resp->stat);
David Shaw846f2fc2006-01-18 17:43:51 -080031}
Al Viroc4d987b2006-10-19 23:29:00 -070032static __be32
33nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp)
David Shaw846f2fc2006-01-18 17:43:51 -080034{
35 if (err) return err;
Al Viro3dadecc2013-01-24 02:18:08 -050036 return fh_getattr(&resp->fh, &resp->stat);
David Shaw846f2fc2006-01-18 17:43:51 -080037}
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * Get a file's attributes
40 * N.B. After this call resp->fh needs an fh_put
41 */
Al Viro7111c662006-10-19 23:28:45 -070042static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020043nfsd_proc_getattr(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Christoph Hellwiga6beb732017-05-08 17:35:49 +020045 struct nfsd_fhandle *argp = rqstp->rq_argp;
46 struct nfsd_attrstat *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -070047 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
49
50 fh_copy(&resp->fh, &argp->fh);
J. Bruce Fields04716e62008-08-07 13:00:20 -040051 nfserr = fh_verify(rqstp, &resp->fh, 0,
52 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
David Shaw846f2fc2006-01-18 17:43:51 -080053 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
56/*
57 * Set a file's attributes
58 * N.B. After this call resp->fh needs an fh_put
59 */
Al Viro7111c662006-10-19 23:28:45 -070060static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020061nfsd_proc_setattr(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Christoph Hellwiga6beb732017-05-08 17:35:49 +020063 struct nfsd_sattrargs *argp = rqstp->rq_argp;
64 struct nfsd_attrstat *resp = rqstp->rq_resp;
Andreas Gruenbachercc265082015-05-09 00:37:57 +020065 struct iattr *iap = &argp->attrs;
66 struct svc_fh *fhp;
Al Viroc4d987b2006-10-19 23:29:00 -070067 __be32 nfserr;
Andreas Gruenbachercc265082015-05-09 00:37:57 +020068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 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 Gruenbachercc265082015-05-09 00:37:57 +020073 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 Kara31051c82016-05-26 16:55:18 +020080 * is close to now", and if setattr_prepare fails, then we
Andreas Gruenbachercc265082015-05-09 00:37:57 +020081 * convert to "set to now" instead of "set to explicit time"
82 *
Jan Kara31051c82016-05-26 16:55:18 +020083 * We only call setattr_prepare as the last test as technically
Andreas Gruenbachercc265082015-05-09 00:37:57 +020084 * 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 */
97 time_t delta = iap->ia_atime.tv_sec - get_seconds();
Andreas Gruenbachercc265082015-05-09 00:37:57 +020098
99 nfserr = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
100 if (nfserr)
101 goto done;
Andreas Gruenbachercc265082015-05-09 00:37:57 +0200102
103 if (delta < 0)
104 delta = -delta;
105 if (delta < MAX_TOUCH_TIME_ERROR &&
Jan Kara31051c82016-05-26 16:55:18 +0200106 setattr_prepare(fhp->fh_dentry, iap) != 0) {
Andreas Gruenbachercc265082015-05-09 00:37:57 +0200107 /*
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
116 nfserr = nfsd_setattr(rqstp, fhp, iap, 0, (time_t)0);
117done:
David Shaw846f2fc2006-01-18 17:43:51 -0800118 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
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 Viro7111c662006-10-19 23:28:45 -0700127static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200128nfsd_proc_lookup(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200130 struct nfsd_diropargs *argp = rqstp->rq_argp;
131 struct nfsd_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700132 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
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 Shaw846f2fc2006-01-18 17:43:51 -0800142 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143}
144
145/*
146 * Read a symlink.
147 */
Al Viro7111c662006-10-19 23:28:45 -0700148static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200149nfsd_proc_readlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200151 struct nfsd_readlinkargs *argp = rqstp->rq_argp;
152 struct nfsd_readlinkres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700153 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
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 Viro7111c662006-10-19 23:28:45 -0700169static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200170nfsd_proc_read(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200172 struct nfsd_readargs *argp = rqstp->rq_argp;
173 struct nfsd_readres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700174 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 dprintk("nfsd: READ %s %d bytes at %d\n",
177 SVCFH_fmt(&argp->fh),
178 argp->count, argp->offset);
179
180 /* Obtain buffer pointer for payload. 19 is 1 word for
181 * status, 17 words for fattr, and 1 word for the byte count.
182 */
183
Greg Banks7adae482006-10-04 02:15:47 -0700184 if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
Chuck Leverad06e4b2007-02-12 00:53:32 -0800185 char buf[RPC_MAX_ADDRBUFLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 printk(KERN_NOTICE
Chuck Leverad06e4b2007-02-12 00:53:32 -0800187 "oversized read request from %s (%d bytes)\n",
188 svc_print_addr(rqstp, buf, sizeof(buf)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 argp->count);
Greg Banks7adae482006-10-04 02:15:47 -0700190 argp->count = NFSSVC_MAXBLKSIZE_V2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 }
Jeff Laytoncd123012007-05-09 02:34:50 -0700192 svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 resp->count = argp->count;
J. Bruce Fields039a87c2010-07-30 11:33:32 -0400195 nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 argp->offset,
NeilBrown3cc03b12006-10-04 02:15:47 -0700197 rqstp->rq_vec, argp->vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 &resp->count);
199
David Shaw846f2fc2006-01-18 17:43:51 -0800200 if (nfserr) return nfserr;
Al Viro3dadecc2013-01-24 02:18:08 -0500201 return fh_getattr(&resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202}
203
204/*
205 * Write data to a file
206 * N.B. After this call resp->fh needs an fh_put
207 */
Al Viro7111c662006-10-19 23:28:45 -0700208static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200209nfsd_proc_write(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200211 struct nfsd_writeargs *argp = rqstp->rq_argp;
212 struct nfsd_attrstat *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700213 __be32 nfserr;
David Shaw31dec252009-03-05 20:16:14 -0500214 unsigned long cnt = argp->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 dprintk("nfsd: WRITE %s %d bytes at %d\n",
217 SVCFH_fmt(&argp->fh),
218 argp->len, argp->offset);
219
Kinglong Mee52e380e2016-12-31 21:00:13 +0800220 nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), argp->offset,
221 rqstp->rq_vec, argp->vlen, &cnt, NFS_DATA_SYNC);
David Shaw846f2fc2006-01-18 17:43:51 -0800222 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223}
224
225/*
226 * CREATE processing is complicated. The keyword here is `overloaded.'
227 * The parent directory is kept locked between the check for existence
228 * and the actual create() call in compliance with VFS protocols.
229 * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
230 */
Al Viro7111c662006-10-19 23:28:45 -0700231static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200232nfsd_proc_create(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200234 struct nfsd_createargs *argp = rqstp->rq_argp;
235 struct nfsd_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 svc_fh *dirfhp = &argp->fh;
237 svc_fh *newfhp = &resp->fh;
238 struct iattr *attr = &argp->attrs;
239 struct inode *inode;
240 struct dentry *dchild;
Al Viroc4d987b2006-10-19 23:29:00 -0700241 int type, mode;
242 __be32 nfserr;
Jan Kara4a55c102012-06-12 16:20:33 +0200243 int hosterr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
245
246 dprintk("nfsd: CREATE %s %.*s\n",
247 SVCFH_fmt(dirfhp), argp->len, argp->name);
248
249 /* First verify the parent file handle */
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200250 nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (nfserr)
252 goto done; /* must fh_put dirfhp even on error */
253
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200254 /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 nfserr = nfserr_exist;
257 if (isdotent(argp->name, argp->len))
258 goto done;
Jan Kara4a55c102012-06-12 16:20:33 +0200259 hosterr = fh_want_write(dirfhp);
260 if (hosterr) {
261 nfserr = nfserrno(hosterr);
262 goto done;
263 }
264
NeilBrown7ed94292006-10-04 02:15:43 -0700265 fh_lock_nested(dirfhp, I_MUTEX_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
267 if (IS_ERR(dchild)) {
268 nfserr = nfserrno(PTR_ERR(dchild));
269 goto out_unlock;
270 }
271 fh_init(newfhp, NFS_FHSIZE);
272 nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
David Howells2b0143b2015-03-17 22:25:59 +0000273 if (!nfserr && d_really_is_negative(dchild))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 nfserr = nfserr_noent;
275 dput(dchild);
276 if (nfserr) {
277 if (nfserr != nfserr_noent)
278 goto out_unlock;
279 /*
280 * If the new file handle wasn't verified, we can't tell
281 * whether the file exists or not. Time to bail ...
282 */
283 nfserr = nfserr_acces;
284 if (!newfhp->fh_dentry) {
285 printk(KERN_WARNING
286 "nfsd_proc_create: file handle not verified\n");
287 goto out_unlock;
288 }
289 }
290
David Howells2b0143b2015-03-17 22:25:59 +0000291 inode = d_inode(newfhp->fh_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* Unfudge the mode bits */
294 if (attr->ia_valid & ATTR_MODE) {
295 type = attr->ia_mode & S_IFMT;
296 mode = attr->ia_mode & ~S_IFMT;
297 if (!type) {
298 /* no type, so if target exists, assume same as that,
299 * else assume a file */
300 if (inode) {
301 type = inode->i_mode & S_IFMT;
302 switch(type) {
303 case S_IFCHR:
304 case S_IFBLK:
305 /* reserve rdev for later checking */
306 rdev = inode->i_rdev;
307 attr->ia_valid |= ATTR_SIZE;
308
309 /* FALLTHROUGH */
310 case S_IFIFO:
311 /* this is probably a permission check..
312 * at least IRIX implements perm checking on
313 * echo thing > device-special-file-or-pipe
314 * by doing a CREATE with type==0
315 */
J. Bruce Fields0ec757d2007-07-17 04:04:48 -0700316 nfserr = nfsd_permission(rqstp,
317 newfhp->fh_export,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 newfhp->fh_dentry,
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200319 NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 if (nfserr && nfserr != nfserr_rofs)
321 goto out_unlock;
322 }
323 } else
324 type = S_IFREG;
325 }
326 } else if (inode) {
327 type = inode->i_mode & S_IFMT;
328 mode = inode->i_mode & ~S_IFMT;
329 } else {
330 type = S_IFREG;
331 mode = 0; /* ??? */
332 }
333
334 attr->ia_valid |= ATTR_MODE;
335 attr->ia_mode = mode;
336
337 /* Special treatment for non-regular files according to the
338 * gospel of sun micro
339 */
340 if (type != S_IFREG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 if (type != S_IFBLK && type != S_IFCHR) {
342 rdev = 0;
343 } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
344 /* If you think you've seen the worst, grok this. */
345 type = S_IFIFO;
346 } else {
347 /* Okay, char or block special */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 if (!rdev)
349 rdev = wanted;
350 }
351
352 /* we've used the SIZE information, so discard it */
353 attr->ia_valid &= ~ATTR_SIZE;
354
355 /* Make sure the type and device matches */
356 nfserr = nfserr_exist;
357 if (inode && type != (inode->i_mode & S_IFMT))
358 goto out_unlock;
359 }
360
361 nfserr = 0;
362 if (!inode) {
363 /* File doesn't exist. Create it and set attrs */
J. Bruce Fieldsb44061d2016-07-20 16:16:06 -0400364 nfserr = nfsd_create_locked(rqstp, dirfhp, argp->name,
365 argp->len, attr, type, rdev, newfhp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 } else if (type == S_IFREG) {
367 dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
368 argp->name, attr->ia_valid, (long) attr->ia_size);
369 /* File already exists. We ignore all attributes except
370 * size, so that creat() behaves exactly like
371 * open(..., O_CREAT|O_TRUNC|O_WRONLY).
372 */
373 attr->ia_valid &= ATTR_SIZE;
374 if (attr->ia_valid)
375 nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0);
376 }
377
378out_unlock:
379 /* We don't really need to unlock, as fh_put does it. */
380 fh_unlock(dirfhp);
Jan Kara4a55c102012-06-12 16:20:33 +0200381 fh_drop_write(dirfhp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382done:
383 fh_put(dirfhp);
David Shaw846f2fc2006-01-18 17:43:51 -0800384 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385}
386
Al Viro7111c662006-10-19 23:28:45 -0700387static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200388nfsd_proc_remove(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200390 struct nfsd_diropargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700391 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393 dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
394 argp->len, argp->name);
395
396 /* Unlink. -SIFDIR means file must not be a directory */
397 nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
398 fh_put(&argp->fh);
399 return nfserr;
400}
401
Al Viro7111c662006-10-19 23:28:45 -0700402static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200403nfsd_proc_rename(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200405 struct nfsd_renameargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700406 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408 dprintk("nfsd: RENAME %s %.*s -> \n",
409 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
410 dprintk("nfsd: -> %s %.*s\n",
411 SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
412
413 nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
414 &argp->tfh, argp->tname, argp->tlen);
415 fh_put(&argp->ffh);
416 fh_put(&argp->tfh);
417 return nfserr;
418}
419
Al Viro7111c662006-10-19 23:28:45 -0700420static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200421nfsd_proc_link(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200423 struct nfsd_linkargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700424 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426 dprintk("nfsd: LINK %s ->\n",
427 SVCFH_fmt(&argp->ffh));
428 dprintk("nfsd: %s %.*s\n",
429 SVCFH_fmt(&argp->tfh),
430 argp->tlen,
431 argp->tname);
432
433 nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
434 &argp->ffh);
435 fh_put(&argp->ffh);
436 fh_put(&argp->tfh);
437 return nfserr;
438}
439
Al Viro7111c662006-10-19 23:28:45 -0700440static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200441nfsd_proc_symlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200443 struct nfsd_symlinkargs *argp = rqstp->rq_argp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 struct svc_fh newfh;
Al Viroc4d987b2006-10-19 23:29:00 -0700445 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
448 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
449 argp->tlen, argp->tname);
450
451 fh_init(&newfh, NFS_FHSIZE);
452 /*
J. Bruce Fields0aeae332014-06-20 11:49:49 -0400453 * Crazy hack: the request fits in a page, and already-decoded
454 * attributes follow argp->tname, so it's safe to just write a
455 * null to ensure it's null-terminated:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 */
J. Bruce Fields0aeae332014-06-20 11:49:49 -0400457 argp->tname[argp->tlen] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
Kinglong Mee1e444f52014-07-01 17:48:02 +0800459 argp->tname, &newfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 fh_put(&argp->ffh);
462 fh_put(&newfh);
463 return nfserr;
464}
465
466/*
467 * Make directory. This operation is not idempotent.
468 * N.B. After this call resp->fh needs an fh_put
469 */
Al Viro7111c662006-10-19 23:28:45 -0700470static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200471nfsd_proc_mkdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200473 struct nfsd_createargs *argp = rqstp->rq_argp;
474 struct nfsd_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700475 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
478
479 if (resp->fh.fh_dentry) {
480 printk(KERN_WARNING
481 "nfsd_proc_mkdir: response already verified??\n");
482 }
483
484 argp->attrs.ia_valid &= ~ATTR_SIZE;
485 fh_init(&resp->fh, NFS_FHSIZE);
486 nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
487 &argp->attrs, S_IFDIR, 0, &resp->fh);
488 fh_put(&argp->fh);
David Shaw846f2fc2006-01-18 17:43:51 -0800489 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
492/*
493 * Remove a directory
494 */
Al Viro7111c662006-10-19 23:28:45 -0700495static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200496nfsd_proc_rmdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200498 struct nfsd_diropargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700499 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
502
503 nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
504 fh_put(&argp->fh);
505 return nfserr;
506}
507
508/*
509 * Read a portion of a directory.
510 */
Al Viro7111c662006-10-19 23:28:45 -0700511static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200512nfsd_proc_readdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200514 struct nfsd_readdirargs *argp = rqstp->rq_argp;
515 struct nfsd_readdirres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700516 int count;
517 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 loff_t offset;
519
520 dprintk("nfsd: READDIR %s %d bytes at %d\n",
521 SVCFH_fmt(&argp->fh),
522 argp->count, argp->cookie);
523
524 /* Shrink to the client read size */
525 count = (argp->count >> 2) - 2;
526
527 /* Make sure we've room for the NULL ptr & eof flag */
528 count -= 2;
529 if (count < 0)
530 count = 0;
531
532 resp->buffer = argp->buffer;
533 resp->offset = NULL;
534 resp->buflen = count;
535 resp->common.err = nfs_ok;
536 /* Read directory and encode entries on the fly */
537 offset = argp->cookie;
538 nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
539 &resp->common, nfssvc_encode_entry);
540
541 resp->count = resp->buffer - argp->buffer;
542 if (resp->offset)
543 *resp->offset = htonl(offset);
544
545 fh_put(&argp->fh);
546 return nfserr;
547}
548
549/*
550 * Get file system info
551 */
Al Viro7111c662006-10-19 23:28:45 -0700552static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200553nfsd_proc_statfs(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200555 struct nfsd_fhandle *argp = rqstp->rq_argp;
556 struct nfsd_statfsres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700557 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
559 dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
560
J. Bruce Fields04716e62008-08-07 13:00:20 -0400561 nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
562 NFSD_MAY_BYPASS_GSS_ON_ROOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 fh_put(&argp->fh);
564 return nfserr;
565}
566
567/*
568 * NFSv2 Server procedures.
569 * Only the results of non-idempotent operations are cached.
570 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571struct nfsd_void { int dummy; };
572
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573#define ST 1 /* status */
574#define FH 8 /* filehandle */
575#define AT 18 /* attributes */
576
Christoph Hellwig860bda22017-05-12 16:11:49 +0200577static const struct svc_procedure nfsd_procedures2[18] = {
Yu Zhiguob9081d92009-06-09 17:33:34 +0800578 [NFSPROC_NULL] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200579 .pc_func = nfsd_proc_null,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200580 .pc_decode = nfssvc_decode_void,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200581 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800582 .pc_argsize = sizeof(struct nfsd_void),
583 .pc_ressize = sizeof(struct nfsd_void),
584 .pc_cachetype = RC_NOCACHE,
585 .pc_xdrressize = ST,
586 },
587 [NFSPROC_GETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200588 .pc_func = nfsd_proc_getattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200589 .pc_decode = nfssvc_decode_fhandle,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200590 .pc_encode = nfssvc_encode_attrstat,
Christoph Hellwig85374882017-05-08 18:48:24 +0200591 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800592 .pc_argsize = sizeof(struct nfsd_fhandle),
593 .pc_ressize = sizeof(struct nfsd_attrstat),
594 .pc_cachetype = RC_NOCACHE,
595 .pc_xdrressize = ST+AT,
596 },
597 [NFSPROC_SETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200598 .pc_func = nfsd_proc_setattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200599 .pc_decode = nfssvc_decode_sattrargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200600 .pc_encode = nfssvc_encode_attrstat,
Christoph Hellwig85374882017-05-08 18:48:24 +0200601 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800602 .pc_argsize = sizeof(struct nfsd_sattrargs),
603 .pc_ressize = sizeof(struct nfsd_attrstat),
604 .pc_cachetype = RC_REPLBUFF,
605 .pc_xdrressize = ST+AT,
606 },
607 [NFSPROC_ROOT] = {
Christoph Hellwig026fec72017-05-08 19:01:48 +0200608 .pc_decode = nfssvc_decode_void,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200609 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800610 .pc_argsize = sizeof(struct nfsd_void),
611 .pc_ressize = sizeof(struct nfsd_void),
612 .pc_cachetype = RC_NOCACHE,
613 .pc_xdrressize = ST,
614 },
615 [NFSPROC_LOOKUP] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200616 .pc_func = nfsd_proc_lookup,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200617 .pc_decode = nfssvc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200618 .pc_encode = nfssvc_encode_diropres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200619 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800620 .pc_argsize = sizeof(struct nfsd_diropargs),
621 .pc_ressize = sizeof(struct nfsd_diropres),
622 .pc_cachetype = RC_NOCACHE,
623 .pc_xdrressize = ST+FH+AT,
624 },
625 [NFSPROC_READLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200626 .pc_func = nfsd_proc_readlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200627 .pc_decode = nfssvc_decode_readlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200628 .pc_encode = nfssvc_encode_readlinkres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800629 .pc_argsize = sizeof(struct nfsd_readlinkargs),
630 .pc_ressize = sizeof(struct nfsd_readlinkres),
631 .pc_cachetype = RC_NOCACHE,
632 .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
633 },
634 [NFSPROC_READ] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200635 .pc_func = nfsd_proc_read,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200636 .pc_decode = nfssvc_decode_readargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200637 .pc_encode = nfssvc_encode_readres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200638 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800639 .pc_argsize = sizeof(struct nfsd_readargs),
640 .pc_ressize = sizeof(struct nfsd_readres),
641 .pc_cachetype = RC_NOCACHE,
642 .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
643 },
644 [NFSPROC_WRITECACHE] = {
Christoph Hellwig026fec72017-05-08 19:01:48 +0200645 .pc_decode = nfssvc_decode_void,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200646 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800647 .pc_argsize = sizeof(struct nfsd_void),
648 .pc_ressize = sizeof(struct nfsd_void),
649 .pc_cachetype = RC_NOCACHE,
650 .pc_xdrressize = ST,
651 },
652 [NFSPROC_WRITE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200653 .pc_func = nfsd_proc_write,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200654 .pc_decode = nfssvc_decode_writeargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200655 .pc_encode = nfssvc_encode_attrstat,
Christoph Hellwig85374882017-05-08 18:48:24 +0200656 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800657 .pc_argsize = sizeof(struct nfsd_writeargs),
658 .pc_ressize = sizeof(struct nfsd_attrstat),
659 .pc_cachetype = RC_REPLBUFF,
660 .pc_xdrressize = ST+AT,
661 },
662 [NFSPROC_CREATE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200663 .pc_func = nfsd_proc_create,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200664 .pc_decode = nfssvc_decode_createargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200665 .pc_encode = nfssvc_encode_diropres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200666 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800667 .pc_argsize = sizeof(struct nfsd_createargs),
668 .pc_ressize = sizeof(struct nfsd_diropres),
669 .pc_cachetype = RC_REPLBUFF,
670 .pc_xdrressize = ST+FH+AT,
671 },
672 [NFSPROC_REMOVE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200673 .pc_func = nfsd_proc_remove,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200674 .pc_decode = nfssvc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200675 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800676 .pc_argsize = sizeof(struct nfsd_diropargs),
677 .pc_ressize = sizeof(struct nfsd_void),
678 .pc_cachetype = RC_REPLSTAT,
679 .pc_xdrressize = ST,
680 },
681 [NFSPROC_RENAME] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200682 .pc_func = nfsd_proc_rename,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200683 .pc_decode = nfssvc_decode_renameargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200684 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800685 .pc_argsize = sizeof(struct nfsd_renameargs),
686 .pc_ressize = sizeof(struct nfsd_void),
687 .pc_cachetype = RC_REPLSTAT,
688 .pc_xdrressize = ST,
689 },
690 [NFSPROC_LINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200691 .pc_func = nfsd_proc_link,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200692 .pc_decode = nfssvc_decode_linkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200693 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800694 .pc_argsize = sizeof(struct nfsd_linkargs),
695 .pc_ressize = sizeof(struct nfsd_void),
696 .pc_cachetype = RC_REPLSTAT,
697 .pc_xdrressize = ST,
698 },
699 [NFSPROC_SYMLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200700 .pc_func = nfsd_proc_symlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200701 .pc_decode = nfssvc_decode_symlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200702 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800703 .pc_argsize = sizeof(struct nfsd_symlinkargs),
704 .pc_ressize = sizeof(struct nfsd_void),
705 .pc_cachetype = RC_REPLSTAT,
706 .pc_xdrressize = ST,
707 },
708 [NFSPROC_MKDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200709 .pc_func = nfsd_proc_mkdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200710 .pc_decode = nfssvc_decode_createargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200711 .pc_encode = nfssvc_encode_diropres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200712 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800713 .pc_argsize = sizeof(struct nfsd_createargs),
714 .pc_ressize = sizeof(struct nfsd_diropres),
715 .pc_cachetype = RC_REPLBUFF,
716 .pc_xdrressize = ST+FH+AT,
717 },
718 [NFSPROC_RMDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200719 .pc_func = nfsd_proc_rmdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200720 .pc_decode = nfssvc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200721 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800722 .pc_argsize = sizeof(struct nfsd_diropargs),
723 .pc_ressize = sizeof(struct nfsd_void),
724 .pc_cachetype = RC_REPLSTAT,
725 .pc_xdrressize = ST,
726 },
727 [NFSPROC_READDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200728 .pc_func = nfsd_proc_readdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200729 .pc_decode = nfssvc_decode_readdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200730 .pc_encode = nfssvc_encode_readdirres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800731 .pc_argsize = sizeof(struct nfsd_readdirargs),
732 .pc_ressize = sizeof(struct nfsd_readdirres),
733 .pc_cachetype = RC_NOCACHE,
734 },
735 [NFSPROC_STATFS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200736 .pc_func = nfsd_proc_statfs,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200737 .pc_decode = nfssvc_decode_fhandle,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200738 .pc_encode = nfssvc_encode_statfsres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800739 .pc_argsize = sizeof(struct nfsd_fhandle),
740 .pc_ressize = sizeof(struct nfsd_statfsres),
741 .pc_cachetype = RC_NOCACHE,
742 .pc_xdrressize = ST+5,
743 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744};
745
746
Christoph Hellwig7fd38af2017-05-08 23:40:27 +0200747static unsigned int nfsd_count2[ARRAY_SIZE(nfsd_procedures2)];
Christoph Hellwige9679182017-05-12 16:21:37 +0200748const struct svc_version nfsd_version2 = {
749 .vs_vers = 2,
750 .vs_nproc = 18,
751 .vs_proc = nfsd_procedures2,
752 .vs_count = nfsd_count2,
753 .vs_dispatch = nfsd_dispatch,
754 .vs_xdrsize = NFS2_SVC_XDRSIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755};
756
757/*
758 * Map errnos to NFS errnos.
759 */
Al Viro63f103112006-10-19 23:28:54 -0700760__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761nfserrno (int errno)
762{
763 static struct {
Al Viro63f103112006-10-19 23:28:54 -0700764 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 int syserr;
766 } nfs_errtbl[] = {
767 { nfs_ok, 0 },
768 { nfserr_perm, -EPERM },
769 { nfserr_noent, -ENOENT },
770 { nfserr_io, -EIO },
771 { nfserr_nxio, -ENXIO },
Jeff Layton62814d62014-07-03 15:15:54 -0400772 { nfserr_fbig, -E2BIG },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 { nfserr_acces, -EACCES },
774 { nfserr_exist, -EEXIST },
775 { nfserr_xdev, -EXDEV },
776 { nfserr_mlink, -EMLINK },
777 { nfserr_nodev, -ENODEV },
778 { nfserr_notdir, -ENOTDIR },
779 { nfserr_isdir, -EISDIR },
780 { nfserr_inval, -EINVAL },
781 { nfserr_fbig, -EFBIG },
782 { nfserr_nospc, -ENOSPC },
783 { nfserr_rofs, -EROFS },
784 { nfserr_mlink, -EMLINK },
785 { nfserr_nametoolong, -ENAMETOOLONG },
786 { nfserr_notempty, -ENOTEMPTY },
787#ifdef EDQUOT
788 { nfserr_dquot, -EDQUOT },
789#endif
790 { nfserr_stale, -ESTALE },
791 { nfserr_jukebox, -ETIMEDOUT },
NeilBrown599eb302008-06-19 10:11:09 +1000792 { nfserr_jukebox, -ERESTARTSYS },
J. Bruce Fields062304a2011-01-02 22:05:33 -0500793 { nfserr_jukebox, -EAGAIN },
794 { nfserr_jukebox, -EWOULDBLOCK },
J. Bruce Fields3beb6cd2011-01-01 15:43:50 -0500795 { nfserr_jukebox, -ENOMEM },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 { nfserr_io, -ETXTBSY },
Andreas Gruenbachera838cc42005-06-22 17:16:24 +0000797 { nfserr_notsupp, -EOPNOTSUPP },
Dean Hildebrandb7aeda42008-12-15 19:40:15 +0200798 { nfserr_toosmall, -ETOOSMALL },
J. Bruce Fieldsf39bde22009-09-27 14:41:43 -0400799 { nfserr_serverfault, -ESERVERFAULT },
Jeff Laytonb3fbfe02014-07-29 21:37:44 -0400800 { nfserr_serverfault, -ENFILE },
J. Bruce Fields42e61612016-10-04 13:57:43 -0400801 { nfserr_io, -EUCLEAN },
Kinglong Meec952cd42017-03-10 09:52:20 +0800802 { nfserr_perm, -ENOKEY },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 };
804 int i;
805
Al Viro63f103112006-10-19 23:28:54 -0700806 for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 if (nfs_errtbl[i].syserr == errno)
808 return nfs_errtbl[i].nfserr;
809 }
J. Bruce Fieldsff30f082016-10-04 12:53:49 -0400810 WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 return nfserr_io;
812}
813