blob: 0ef88d0e67d9d34c798de8248654439a12515e29 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Process version 2 NFS requests.
3 *
4 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
5 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/namei.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Boaz Harrosh9a74af22009-12-03 20:30:56 +02009#include "cache.h"
10#include "xdr.h"
J. Bruce Fields0a3adad2009-11-04 18:12:35 -050011#include "vfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13typedef struct svc_rqst svc_rqst;
14typedef struct svc_buf svc_buf;
15
16#define NFSDDBG_FACILITY NFSDDBG_PROC
17
18
Al Viro7111c662006-10-19 23:28:45 -070019static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020020nfsd_proc_null(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
22 return nfs_ok;
23}
24
Al Viroc4d987b2006-10-19 23:29:00 -070025static __be32
26nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp)
David Shaw846f2fc2006-01-18 17:43:51 -080027{
28 if (err) return err;
Al Viro3dadecc2013-01-24 02:18:08 -050029 return fh_getattr(&resp->fh, &resp->stat);
David Shaw846f2fc2006-01-18 17:43:51 -080030}
Al Viroc4d987b2006-10-19 23:29:00 -070031static __be32
32nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp)
David Shaw846f2fc2006-01-18 17:43:51 -080033{
34 if (err) return err;
Al Viro3dadecc2013-01-24 02:18:08 -050035 return fh_getattr(&resp->fh, &resp->stat);
David Shaw846f2fc2006-01-18 17:43:51 -080036}
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/*
38 * Get a file's attributes
39 * N.B. After this call resp->fh needs an fh_put
40 */
Al Viro7111c662006-10-19 23:28:45 -070041static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020042nfsd_proc_getattr(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
Christoph Hellwiga6beb732017-05-08 17:35:49 +020044 struct nfsd_fhandle *argp = rqstp->rq_argp;
45 struct nfsd_attrstat *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -070046 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
48
49 fh_copy(&resp->fh, &argp->fh);
J. Bruce Fields04716e62008-08-07 13:00:20 -040050 nfserr = fh_verify(rqstp, &resp->fh, 0,
51 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
David Shaw846f2fc2006-01-18 17:43:51 -080052 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
55/*
56 * Set a file's attributes
57 * N.B. After this call resp->fh needs an fh_put
58 */
Al Viro7111c662006-10-19 23:28:45 -070059static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +020060nfsd_proc_setattr(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Christoph Hellwiga6beb732017-05-08 17:35:49 +020062 struct nfsd_sattrargs *argp = rqstp->rq_argp;
63 struct nfsd_attrstat *resp = rqstp->rq_resp;
Andreas Gruenbachercc265082015-05-09 00:37:57 +020064 struct iattr *iap = &argp->attrs;
65 struct svc_fh *fhp;
Al Viroc4d987b2006-10-19 23:29:00 -070066 __be32 nfserr;
Andreas Gruenbachercc265082015-05-09 00:37:57 +020067
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
69 SVCFH_fmt(&argp->fh),
70 argp->attrs.ia_valid, (long) argp->attrs.ia_size);
71
Andreas Gruenbachercc265082015-05-09 00:37:57 +020072 fhp = fh_copy(&resp->fh, &argp->fh);
73
74 /*
75 * NFSv2 does not differentiate between "set-[ac]time-to-now"
76 * which only requires access, and "set-[ac]time-to-X" which
77 * requires ownership.
78 * So if it looks like it might be "set both to the same time which
Jan Kara31051c82016-05-26 16:55:18 +020079 * is close to now", and if setattr_prepare fails, then we
Andreas Gruenbachercc265082015-05-09 00:37:57 +020080 * convert to "set to now" instead of "set to explicit time"
81 *
Jan Kara31051c82016-05-26 16:55:18 +020082 * We only call setattr_prepare as the last test as technically
Andreas Gruenbachercc265082015-05-09 00:37:57 +020083 * it is not an interface that we should be using.
84 */
85#define BOTH_TIME_SET (ATTR_ATIME_SET | ATTR_MTIME_SET)
86#define MAX_TOUCH_TIME_ERROR (30*60)
87 if ((iap->ia_valid & BOTH_TIME_SET) == BOTH_TIME_SET &&
88 iap->ia_mtime.tv_sec == iap->ia_atime.tv_sec) {
89 /*
90 * Looks probable.
91 *
92 * Now just make sure time is in the right ballpark.
93 * Solaris, at least, doesn't seem to care what the time
94 * request is. We require it be within 30 minutes of now.
95 */
96 time_t delta = iap->ia_atime.tv_sec - get_seconds();
Andreas Gruenbachercc265082015-05-09 00:37:57 +020097
98 nfserr = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
99 if (nfserr)
100 goto done;
Andreas Gruenbachercc265082015-05-09 00:37:57 +0200101
102 if (delta < 0)
103 delta = -delta;
104 if (delta < MAX_TOUCH_TIME_ERROR &&
Jan Kara31051c82016-05-26 16:55:18 +0200105 setattr_prepare(fhp->fh_dentry, iap) != 0) {
Andreas Gruenbachercc265082015-05-09 00:37:57 +0200106 /*
107 * Turn off ATTR_[AM]TIME_SET but leave ATTR_[AM]TIME.
108 * This will cause notify_change to set these times
109 * to "now"
110 */
111 iap->ia_valid &= ~BOTH_TIME_SET;
112 }
113 }
114
115 nfserr = nfsd_setattr(rqstp, fhp, iap, 0, (time_t)0);
116done:
David Shaw846f2fc2006-01-18 17:43:51 -0800117 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118}
119
120/*
121 * Look up a path name component
122 * Note: the dentry in the resp->fh may be negative if the file
123 * doesn't exist yet.
124 * N.B. After this call resp->fh needs an fh_put
125 */
Al Viro7111c662006-10-19 23:28:45 -0700126static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200127nfsd_proc_lookup(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200129 struct nfsd_diropargs *argp = rqstp->rq_argp;
130 struct nfsd_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700131 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 dprintk("nfsd: LOOKUP %s %.*s\n",
134 SVCFH_fmt(&argp->fh), argp->len, argp->name);
135
136 fh_init(&resp->fh, NFS_FHSIZE);
137 nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
138 &resp->fh);
139
140 fh_put(&argp->fh);
David Shaw846f2fc2006-01-18 17:43:51 -0800141 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142}
143
144/*
145 * Read a symlink.
146 */
Al Viro7111c662006-10-19 23:28:45 -0700147static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200148nfsd_proc_readlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200150 struct nfsd_readlinkargs *argp = rqstp->rq_argp;
151 struct nfsd_readlinkres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700152 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
155
156 /* Read the symlink. */
157 resp->len = NFS_MAXPATHLEN;
158 nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
159
160 fh_put(&argp->fh);
161 return nfserr;
162}
163
164/*
165 * Read a portion of a file.
166 * N.B. After this call resp->fh needs an fh_put
167 */
Al Viro7111c662006-10-19 23:28:45 -0700168static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200169nfsd_proc_read(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200171 struct nfsd_readargs *argp = rqstp->rq_argp;
172 struct nfsd_readres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700173 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 dprintk("nfsd: READ %s %d bytes at %d\n",
176 SVCFH_fmt(&argp->fh),
177 argp->count, argp->offset);
178
179 /* Obtain buffer pointer for payload. 19 is 1 word for
180 * status, 17 words for fattr, and 1 word for the byte count.
181 */
182
Greg Banks7adae482006-10-04 02:15:47 -0700183 if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
Chuck Leverad06e4b2007-02-12 00:53:32 -0800184 char buf[RPC_MAX_ADDRBUFLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 printk(KERN_NOTICE
Chuck Leverad06e4b2007-02-12 00:53:32 -0800186 "oversized read request from %s (%d bytes)\n",
187 svc_print_addr(rqstp, buf, sizeof(buf)),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 argp->count);
Greg Banks7adae482006-10-04 02:15:47 -0700189 argp->count = NFSSVC_MAXBLKSIZE_V2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 }
Jeff Laytoncd123012007-05-09 02:34:50 -0700191 svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 resp->count = argp->count;
J. Bruce Fields039a87c2010-07-30 11:33:32 -0400194 nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 argp->offset,
NeilBrown3cc03b12006-10-04 02:15:47 -0700196 rqstp->rq_vec, argp->vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 &resp->count);
198
David Shaw846f2fc2006-01-18 17:43:51 -0800199 if (nfserr) return nfserr;
Al Viro3dadecc2013-01-24 02:18:08 -0500200 return fh_getattr(&resp->fh, &resp->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
203/*
204 * Write data to a file
205 * N.B. After this call resp->fh needs an fh_put
206 */
Al Viro7111c662006-10-19 23:28:45 -0700207static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200208nfsd_proc_write(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200210 struct nfsd_writeargs *argp = rqstp->rq_argp;
211 struct nfsd_attrstat *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700212 __be32 nfserr;
David Shaw31dec252009-03-05 20:16:14 -0500213 unsigned long cnt = argp->len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 dprintk("nfsd: WRITE %s %d bytes at %d\n",
216 SVCFH_fmt(&argp->fh),
217 argp->len, argp->offset);
218
Kinglong Mee52e380e2016-12-31 21:00:13 +0800219 nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), argp->offset,
220 rqstp->rq_vec, argp->vlen, &cnt, NFS_DATA_SYNC);
David Shaw846f2fc2006-01-18 17:43:51 -0800221 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
224/*
225 * CREATE processing is complicated. The keyword here is `overloaded.'
226 * The parent directory is kept locked between the check for existence
227 * and the actual create() call in compliance with VFS protocols.
228 * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
229 */
Al Viro7111c662006-10-19 23:28:45 -0700230static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200231nfsd_proc_create(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200233 struct nfsd_createargs *argp = rqstp->rq_argp;
234 struct nfsd_diropres *resp = rqstp->rq_resp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 svc_fh *dirfhp = &argp->fh;
236 svc_fh *newfhp = &resp->fh;
237 struct iattr *attr = &argp->attrs;
238 struct inode *inode;
239 struct dentry *dchild;
Al Viroc4d987b2006-10-19 23:29:00 -0700240 int type, mode;
241 __be32 nfserr;
Jan Kara4a55c102012-06-12 16:20:33 +0200242 int hosterr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
244
245 dprintk("nfsd: CREATE %s %.*s\n",
246 SVCFH_fmt(dirfhp), argp->len, argp->name);
247
248 /* First verify the parent file handle */
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200249 nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 if (nfserr)
251 goto done; /* must fh_put dirfhp even on error */
252
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200253 /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 nfserr = nfserr_exist;
256 if (isdotent(argp->name, argp->len))
257 goto done;
Jan Kara4a55c102012-06-12 16:20:33 +0200258 hosterr = fh_want_write(dirfhp);
259 if (hosterr) {
260 nfserr = nfserrno(hosterr);
261 goto done;
262 }
263
NeilBrown7ed94292006-10-04 02:15:43 -0700264 fh_lock_nested(dirfhp, I_MUTEX_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
266 if (IS_ERR(dchild)) {
267 nfserr = nfserrno(PTR_ERR(dchild));
268 goto out_unlock;
269 }
270 fh_init(newfhp, NFS_FHSIZE);
271 nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
David Howells2b0143b2015-03-17 22:25:59 +0000272 if (!nfserr && d_really_is_negative(dchild))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 nfserr = nfserr_noent;
274 dput(dchild);
275 if (nfserr) {
276 if (nfserr != nfserr_noent)
277 goto out_unlock;
278 /*
279 * If the new file handle wasn't verified, we can't tell
280 * whether the file exists or not. Time to bail ...
281 */
282 nfserr = nfserr_acces;
283 if (!newfhp->fh_dentry) {
284 printk(KERN_WARNING
285 "nfsd_proc_create: file handle not verified\n");
286 goto out_unlock;
287 }
288 }
289
David Howells2b0143b2015-03-17 22:25:59 +0000290 inode = d_inode(newfhp->fh_dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 /* Unfudge the mode bits */
293 if (attr->ia_valid & ATTR_MODE) {
294 type = attr->ia_mode & S_IFMT;
295 mode = attr->ia_mode & ~S_IFMT;
296 if (!type) {
297 /* no type, so if target exists, assume same as that,
298 * else assume a file */
299 if (inode) {
300 type = inode->i_mode & S_IFMT;
301 switch(type) {
302 case S_IFCHR:
303 case S_IFBLK:
304 /* reserve rdev for later checking */
305 rdev = inode->i_rdev;
306 attr->ia_valid |= ATTR_SIZE;
307
308 /* FALLTHROUGH */
309 case S_IFIFO:
310 /* this is probably a permission check..
311 * at least IRIX implements perm checking on
312 * echo thing > device-special-file-or-pipe
313 * by doing a CREATE with type==0
314 */
J. Bruce Fields0ec757d2007-07-17 04:04:48 -0700315 nfserr = nfsd_permission(rqstp,
316 newfhp->fh_export,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 newfhp->fh_dentry,
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200318 NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 if (nfserr && nfserr != nfserr_rofs)
320 goto out_unlock;
321 }
322 } else
323 type = S_IFREG;
324 }
325 } else if (inode) {
326 type = inode->i_mode & S_IFMT;
327 mode = inode->i_mode & ~S_IFMT;
328 } else {
329 type = S_IFREG;
330 mode = 0; /* ??? */
331 }
332
333 attr->ia_valid |= ATTR_MODE;
334 attr->ia_mode = mode;
335
336 /* Special treatment for non-regular files according to the
337 * gospel of sun micro
338 */
339 if (type != S_IFREG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 if (type != S_IFBLK && type != S_IFCHR) {
341 rdev = 0;
342 } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
343 /* If you think you've seen the worst, grok this. */
344 type = S_IFIFO;
345 } else {
346 /* Okay, char or block special */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (!rdev)
348 rdev = wanted;
349 }
350
351 /* we've used the SIZE information, so discard it */
352 attr->ia_valid &= ~ATTR_SIZE;
353
354 /* Make sure the type and device matches */
355 nfserr = nfserr_exist;
356 if (inode && type != (inode->i_mode & S_IFMT))
357 goto out_unlock;
358 }
359
360 nfserr = 0;
361 if (!inode) {
362 /* File doesn't exist. Create it and set attrs */
J. Bruce Fieldsb44061d2016-07-20 16:16:06 -0400363 nfserr = nfsd_create_locked(rqstp, dirfhp, argp->name,
364 argp->len, attr, type, rdev, newfhp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 } else if (type == S_IFREG) {
366 dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
367 argp->name, attr->ia_valid, (long) attr->ia_size);
368 /* File already exists. We ignore all attributes except
369 * size, so that creat() behaves exactly like
370 * open(..., O_CREAT|O_TRUNC|O_WRONLY).
371 */
372 attr->ia_valid &= ATTR_SIZE;
373 if (attr->ia_valid)
374 nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0);
375 }
376
377out_unlock:
378 /* We don't really need to unlock, as fh_put does it. */
379 fh_unlock(dirfhp);
Jan Kara4a55c102012-06-12 16:20:33 +0200380 fh_drop_write(dirfhp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381done:
382 fh_put(dirfhp);
David Shaw846f2fc2006-01-18 17:43:51 -0800383 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
Al Viro7111c662006-10-19 23:28:45 -0700386static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200387nfsd_proc_remove(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200389 struct nfsd_diropargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700390 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
393 argp->len, argp->name);
394
395 /* Unlink. -SIFDIR means file must not be a directory */
396 nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
397 fh_put(&argp->fh);
398 return nfserr;
399}
400
Al Viro7111c662006-10-19 23:28:45 -0700401static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200402nfsd_proc_rename(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200404 struct nfsd_renameargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700405 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407 dprintk("nfsd: RENAME %s %.*s -> \n",
408 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
409 dprintk("nfsd: -> %s %.*s\n",
410 SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
411
412 nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
413 &argp->tfh, argp->tname, argp->tlen);
414 fh_put(&argp->ffh);
415 fh_put(&argp->tfh);
416 return nfserr;
417}
418
Al Viro7111c662006-10-19 23:28:45 -0700419static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200420nfsd_proc_link(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200422 struct nfsd_linkargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700423 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
425 dprintk("nfsd: LINK %s ->\n",
426 SVCFH_fmt(&argp->ffh));
427 dprintk("nfsd: %s %.*s\n",
428 SVCFH_fmt(&argp->tfh),
429 argp->tlen,
430 argp->tname);
431
432 nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
433 &argp->ffh);
434 fh_put(&argp->ffh);
435 fh_put(&argp->tfh);
436 return nfserr;
437}
438
Al Viro7111c662006-10-19 23:28:45 -0700439static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200440nfsd_proc_symlink(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200442 struct nfsd_symlinkargs *argp = rqstp->rq_argp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 struct svc_fh newfh;
Al Viroc4d987b2006-10-19 23:29:00 -0700444 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446 dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
447 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
448 argp->tlen, argp->tname);
449
450 fh_init(&newfh, NFS_FHSIZE);
451 /*
J. Bruce Fields0aeae332014-06-20 11:49:49 -0400452 * Crazy hack: the request fits in a page, and already-decoded
453 * attributes follow argp->tname, so it's safe to just write a
454 * null to ensure it's null-terminated:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 */
J. Bruce Fields0aeae332014-06-20 11:49:49 -0400456 argp->tname[argp->tlen] = '\0';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
Kinglong Mee1e444f52014-07-01 17:48:02 +0800458 argp->tname, &newfh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 fh_put(&argp->ffh);
461 fh_put(&newfh);
462 return nfserr;
463}
464
465/*
466 * Make directory. This operation is not idempotent.
467 * N.B. After this call resp->fh needs an fh_put
468 */
Al Viro7111c662006-10-19 23:28:45 -0700469static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200470nfsd_proc_mkdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200472 struct nfsd_createargs *argp = rqstp->rq_argp;
473 struct nfsd_diropres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700474 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
477
478 if (resp->fh.fh_dentry) {
479 printk(KERN_WARNING
480 "nfsd_proc_mkdir: response already verified??\n");
481 }
482
483 argp->attrs.ia_valid &= ~ATTR_SIZE;
484 fh_init(&resp->fh, NFS_FHSIZE);
485 nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
486 &argp->attrs, S_IFDIR, 0, &resp->fh);
487 fh_put(&argp->fh);
David Shaw846f2fc2006-01-18 17:43:51 -0800488 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489}
490
491/*
492 * Remove a directory
493 */
Al Viro7111c662006-10-19 23:28:45 -0700494static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200495nfsd_proc_rmdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200497 struct nfsd_diropargs *argp = rqstp->rq_argp;
Al Viroc4d987b2006-10-19 23:29:00 -0700498 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
501
502 nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
503 fh_put(&argp->fh);
504 return nfserr;
505}
506
507/*
508 * Read a portion of a directory.
509 */
Al Viro7111c662006-10-19 23:28:45 -0700510static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200511nfsd_proc_readdir(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200513 struct nfsd_readdirargs *argp = rqstp->rq_argp;
514 struct nfsd_readdirres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700515 int count;
516 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 loff_t offset;
518
519 dprintk("nfsd: READDIR %s %d bytes at %d\n",
520 SVCFH_fmt(&argp->fh),
521 argp->count, argp->cookie);
522
523 /* Shrink to the client read size */
524 count = (argp->count >> 2) - 2;
525
526 /* Make sure we've room for the NULL ptr & eof flag */
527 count -= 2;
528 if (count < 0)
529 count = 0;
530
531 resp->buffer = argp->buffer;
532 resp->offset = NULL;
533 resp->buflen = count;
534 resp->common.err = nfs_ok;
535 /* Read directory and encode entries on the fly */
536 offset = argp->cookie;
537 nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
538 &resp->common, nfssvc_encode_entry);
539
540 resp->count = resp->buffer - argp->buffer;
541 if (resp->offset)
542 *resp->offset = htonl(offset);
543
544 fh_put(&argp->fh);
545 return nfserr;
546}
547
548/*
549 * Get file system info
550 */
Al Viro7111c662006-10-19 23:28:45 -0700551static __be32
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200552nfsd_proc_statfs(struct svc_rqst *rqstp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200554 struct nfsd_fhandle *argp = rqstp->rq_argp;
555 struct nfsd_statfsres *resp = rqstp->rq_resp;
Al Viroc4d987b2006-10-19 23:29:00 -0700556 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
558 dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
559
J. Bruce Fields04716e62008-08-07 13:00:20 -0400560 nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
561 NFSD_MAY_BYPASS_GSS_ON_ROOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 fh_put(&argp->fh);
563 return nfserr;
564}
565
566/*
567 * NFSv2 Server procedures.
568 * Only the results of non-idempotent operations are cached.
569 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570struct nfsd_void { int dummy; };
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#define ST 1 /* status */
573#define FH 8 /* filehandle */
574#define AT 18 /* attributes */
575
576static struct svc_procedure nfsd_procedures2[18] = {
Yu Zhiguob9081d92009-06-09 17:33:34 +0800577 [NFSPROC_NULL] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200578 .pc_func = nfsd_proc_null,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200579 .pc_decode = nfssvc_decode_void,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200580 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800581 .pc_argsize = sizeof(struct nfsd_void),
582 .pc_ressize = sizeof(struct nfsd_void),
583 .pc_cachetype = RC_NOCACHE,
584 .pc_xdrressize = ST,
585 },
586 [NFSPROC_GETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200587 .pc_func = nfsd_proc_getattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200588 .pc_decode = nfssvc_decode_fhandle,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200589 .pc_encode = nfssvc_encode_attrstat,
Christoph Hellwig85374882017-05-08 18:48:24 +0200590 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800591 .pc_argsize = sizeof(struct nfsd_fhandle),
592 .pc_ressize = sizeof(struct nfsd_attrstat),
593 .pc_cachetype = RC_NOCACHE,
594 .pc_xdrressize = ST+AT,
595 },
596 [NFSPROC_SETATTR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200597 .pc_func = nfsd_proc_setattr,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200598 .pc_decode = nfssvc_decode_sattrargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200599 .pc_encode = nfssvc_encode_attrstat,
Christoph Hellwig85374882017-05-08 18:48:24 +0200600 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800601 .pc_argsize = sizeof(struct nfsd_sattrargs),
602 .pc_ressize = sizeof(struct nfsd_attrstat),
603 .pc_cachetype = RC_REPLBUFF,
604 .pc_xdrressize = ST+AT,
605 },
606 [NFSPROC_ROOT] = {
Christoph Hellwig026fec72017-05-08 19:01:48 +0200607 .pc_decode = nfssvc_decode_void,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200608 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800609 .pc_argsize = sizeof(struct nfsd_void),
610 .pc_ressize = sizeof(struct nfsd_void),
611 .pc_cachetype = RC_NOCACHE,
612 .pc_xdrressize = ST,
613 },
614 [NFSPROC_LOOKUP] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200615 .pc_func = nfsd_proc_lookup,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200616 .pc_decode = nfssvc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200617 .pc_encode = nfssvc_encode_diropres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200618 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800619 .pc_argsize = sizeof(struct nfsd_diropargs),
620 .pc_ressize = sizeof(struct nfsd_diropres),
621 .pc_cachetype = RC_NOCACHE,
622 .pc_xdrressize = ST+FH+AT,
623 },
624 [NFSPROC_READLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200625 .pc_func = nfsd_proc_readlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200626 .pc_decode = nfssvc_decode_readlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200627 .pc_encode = nfssvc_encode_readlinkres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800628 .pc_argsize = sizeof(struct nfsd_readlinkargs),
629 .pc_ressize = sizeof(struct nfsd_readlinkres),
630 .pc_cachetype = RC_NOCACHE,
631 .pc_xdrressize = ST+1+NFS_MAXPATHLEN/4,
632 },
633 [NFSPROC_READ] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200634 .pc_func = nfsd_proc_read,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200635 .pc_decode = nfssvc_decode_readargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200636 .pc_encode = nfssvc_encode_readres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200637 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800638 .pc_argsize = sizeof(struct nfsd_readargs),
639 .pc_ressize = sizeof(struct nfsd_readres),
640 .pc_cachetype = RC_NOCACHE,
641 .pc_xdrressize = ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4,
642 },
643 [NFSPROC_WRITECACHE] = {
Christoph Hellwig026fec72017-05-08 19:01:48 +0200644 .pc_decode = nfssvc_decode_void,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200645 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800646 .pc_argsize = sizeof(struct nfsd_void),
647 .pc_ressize = sizeof(struct nfsd_void),
648 .pc_cachetype = RC_NOCACHE,
649 .pc_xdrressize = ST,
650 },
651 [NFSPROC_WRITE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200652 .pc_func = nfsd_proc_write,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200653 .pc_decode = nfssvc_decode_writeargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200654 .pc_encode = nfssvc_encode_attrstat,
Christoph Hellwig85374882017-05-08 18:48:24 +0200655 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800656 .pc_argsize = sizeof(struct nfsd_writeargs),
657 .pc_ressize = sizeof(struct nfsd_attrstat),
658 .pc_cachetype = RC_REPLBUFF,
659 .pc_xdrressize = ST+AT,
660 },
661 [NFSPROC_CREATE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200662 .pc_func = nfsd_proc_create,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200663 .pc_decode = nfssvc_decode_createargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200664 .pc_encode = nfssvc_encode_diropres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200665 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800666 .pc_argsize = sizeof(struct nfsd_createargs),
667 .pc_ressize = sizeof(struct nfsd_diropres),
668 .pc_cachetype = RC_REPLBUFF,
669 .pc_xdrressize = ST+FH+AT,
670 },
671 [NFSPROC_REMOVE] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200672 .pc_func = nfsd_proc_remove,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200673 .pc_decode = nfssvc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200674 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800675 .pc_argsize = sizeof(struct nfsd_diropargs),
676 .pc_ressize = sizeof(struct nfsd_void),
677 .pc_cachetype = RC_REPLSTAT,
678 .pc_xdrressize = ST,
679 },
680 [NFSPROC_RENAME] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200681 .pc_func = nfsd_proc_rename,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200682 .pc_decode = nfssvc_decode_renameargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200683 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800684 .pc_argsize = sizeof(struct nfsd_renameargs),
685 .pc_ressize = sizeof(struct nfsd_void),
686 .pc_cachetype = RC_REPLSTAT,
687 .pc_xdrressize = ST,
688 },
689 [NFSPROC_LINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200690 .pc_func = nfsd_proc_link,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200691 .pc_decode = nfssvc_decode_linkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200692 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800693 .pc_argsize = sizeof(struct nfsd_linkargs),
694 .pc_ressize = sizeof(struct nfsd_void),
695 .pc_cachetype = RC_REPLSTAT,
696 .pc_xdrressize = ST,
697 },
698 [NFSPROC_SYMLINK] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200699 .pc_func = nfsd_proc_symlink,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200700 .pc_decode = nfssvc_decode_symlinkargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200701 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800702 .pc_argsize = sizeof(struct nfsd_symlinkargs),
703 .pc_ressize = sizeof(struct nfsd_void),
704 .pc_cachetype = RC_REPLSTAT,
705 .pc_xdrressize = ST,
706 },
707 [NFSPROC_MKDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200708 .pc_func = nfsd_proc_mkdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200709 .pc_decode = nfssvc_decode_createargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200710 .pc_encode = nfssvc_encode_diropres,
Christoph Hellwig85374882017-05-08 18:48:24 +0200711 .pc_release = nfssvc_release_fhandle,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800712 .pc_argsize = sizeof(struct nfsd_createargs),
713 .pc_ressize = sizeof(struct nfsd_diropres),
714 .pc_cachetype = RC_REPLBUFF,
715 .pc_xdrressize = ST+FH+AT,
716 },
717 [NFSPROC_RMDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200718 .pc_func = nfsd_proc_rmdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200719 .pc_decode = nfssvc_decode_diropargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200720 .pc_encode = nfssvc_encode_void,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800721 .pc_argsize = sizeof(struct nfsd_diropargs),
722 .pc_ressize = sizeof(struct nfsd_void),
723 .pc_cachetype = RC_REPLSTAT,
724 .pc_xdrressize = ST,
725 },
726 [NFSPROC_READDIR] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200727 .pc_func = nfsd_proc_readdir,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200728 .pc_decode = nfssvc_decode_readdirargs,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200729 .pc_encode = nfssvc_encode_readdirres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800730 .pc_argsize = sizeof(struct nfsd_readdirargs),
731 .pc_ressize = sizeof(struct nfsd_readdirres),
732 .pc_cachetype = RC_NOCACHE,
733 },
734 [NFSPROC_STATFS] = {
Christoph Hellwiga6beb732017-05-08 17:35:49 +0200735 .pc_func = nfsd_proc_statfs,
Christoph Hellwig026fec72017-05-08 19:01:48 +0200736 .pc_decode = nfssvc_decode_fhandle,
Christoph Hellwig63f8de32017-05-08 19:42:02 +0200737 .pc_encode = nfssvc_encode_statfsres,
Yu Zhiguob9081d92009-06-09 17:33:34 +0800738 .pc_argsize = sizeof(struct nfsd_fhandle),
739 .pc_ressize = sizeof(struct nfsd_statfsres),
740 .pc_cachetype = RC_NOCACHE,
741 .pc_xdrressize = ST+5,
742 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743};
744
745
746struct svc_version nfsd_version2 = {
747 .vs_vers = 2,
748 .vs_nproc = 18,
749 .vs_proc = nfsd_procedures2,
750 .vs_dispatch = nfsd_dispatch,
751 .vs_xdrsize = NFS2_SVC_XDRSIZE,
752};
753
754/*
755 * Map errnos to NFS errnos.
756 */
Al Viro63f103112006-10-19 23:28:54 -0700757__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758nfserrno (int errno)
759{
760 static struct {
Al Viro63f103112006-10-19 23:28:54 -0700761 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 int syserr;
763 } nfs_errtbl[] = {
764 { nfs_ok, 0 },
765 { nfserr_perm, -EPERM },
766 { nfserr_noent, -ENOENT },
767 { nfserr_io, -EIO },
768 { nfserr_nxio, -ENXIO },
Jeff Layton62814d62014-07-03 15:15:54 -0400769 { nfserr_fbig, -E2BIG },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 { nfserr_acces, -EACCES },
771 { nfserr_exist, -EEXIST },
772 { nfserr_xdev, -EXDEV },
773 { nfserr_mlink, -EMLINK },
774 { nfserr_nodev, -ENODEV },
775 { nfserr_notdir, -ENOTDIR },
776 { nfserr_isdir, -EISDIR },
777 { nfserr_inval, -EINVAL },
778 { nfserr_fbig, -EFBIG },
779 { nfserr_nospc, -ENOSPC },
780 { nfserr_rofs, -EROFS },
781 { nfserr_mlink, -EMLINK },
782 { nfserr_nametoolong, -ENAMETOOLONG },
783 { nfserr_notempty, -ENOTEMPTY },
784#ifdef EDQUOT
785 { nfserr_dquot, -EDQUOT },
786#endif
787 { nfserr_stale, -ESTALE },
788 { nfserr_jukebox, -ETIMEDOUT },
NeilBrown599eb302008-06-19 10:11:09 +1000789 { nfserr_jukebox, -ERESTARTSYS },
J. Bruce Fields062304a2011-01-02 22:05:33 -0500790 { nfserr_jukebox, -EAGAIN },
791 { nfserr_jukebox, -EWOULDBLOCK },
J. Bruce Fields3beb6cd2011-01-01 15:43:50 -0500792 { nfserr_jukebox, -ENOMEM },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 { nfserr_io, -ETXTBSY },
Andreas Gruenbachera838cc42005-06-22 17:16:24 +0000794 { nfserr_notsupp, -EOPNOTSUPP },
Dean Hildebrandb7aeda42008-12-15 19:40:15 +0200795 { nfserr_toosmall, -ETOOSMALL },
J. Bruce Fieldsf39bde22009-09-27 14:41:43 -0400796 { nfserr_serverfault, -ESERVERFAULT },
Jeff Laytonb3fbfe02014-07-29 21:37:44 -0400797 { nfserr_serverfault, -ENFILE },
J. Bruce Fields42e61612016-10-04 13:57:43 -0400798 { nfserr_io, -EUCLEAN },
Kinglong Meec952cd42017-03-10 09:52:20 +0800799 { nfserr_perm, -ENOKEY },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 };
801 int i;
802
Al Viro63f103112006-10-19 23:28:54 -0700803 for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 if (nfs_errtbl[i].syserr == errno)
805 return nfs_errtbl[i].nfserr;
806 }
J. Bruce Fieldsff30f082016-10-04 12:53:49 -0400807 WARN_ONCE(1, "nfsd: non-standard errno: %d\n", errno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return nfserr_io;
809}
810