blob: ec983b777680ded981c59dbb65c81ebb0c5637dc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * nfsproc2.c Process version 2 NFS requests.
3 * linux/fs/nfsd/nfs2proc.c
4 *
5 * Process version 2 NFS requests.
6 *
7 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
8 */
9
10#include <linux/linkage.h>
11#include <linux/time.h>
12#include <linux/errno.h>
13#include <linux/fs.h>
14#include <linux/stat.h>
15#include <linux/fcntl.h>
16#include <linux/net.h>
17#include <linux/in.h>
18#include <linux/namei.h>
19#include <linux/unistd.h>
20#include <linux/slab.h>
21
22#include <linux/sunrpc/svc.h>
23#include <linux/nfsd/nfsd.h>
24#include <linux/nfsd/cache.h>
25#include <linux/nfsd/xdr.h>
26
27typedef struct svc_rqst svc_rqst;
28typedef struct svc_buf svc_buf;
29
30#define NFSDDBG_FACILITY NFSDDBG_PROC
31
32
Al Viro7111c662006-10-19 23:28:45 -070033static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070034nfsd_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
35{
36 return nfs_ok;
37}
38
Al Viroc4d987b2006-10-19 23:29:00 -070039static __be32
40nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp)
David Shaw846f2fc2006-01-18 17:43:51 -080041{
42 if (err) return err;
43 return nfserrno(vfs_getattr(resp->fh.fh_export->ex_mnt,
44 resp->fh.fh_dentry,
45 &resp->stat));
46}
Al Viroc4d987b2006-10-19 23:29:00 -070047static __be32
48nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp)
David Shaw846f2fc2006-01-18 17:43:51 -080049{
50 if (err) return err;
51 return nfserrno(vfs_getattr(resp->fh.fh_export->ex_mnt,
52 resp->fh.fh_dentry,
53 &resp->stat));
54}
Linus Torvalds1da177e2005-04-16 15:20:36 -070055/*
56 * Get 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070060nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp,
61 struct nfsd_attrstat *resp)
62{
Al Viroc4d987b2006-10-19 23:29:00 -070063 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 dprintk("nfsd: GETATTR %s\n", SVCFH_fmt(&argp->fh));
65
66 fh_copy(&resp->fh, &argp->fh);
David Shaw846f2fc2006-01-18 17:43:51 -080067 nfserr = fh_verify(rqstp, &resp->fh, 0, MAY_NOP);
68 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069}
70
71/*
72 * Set a file's attributes
73 * N.B. After this call resp->fh needs an fh_put
74 */
Al Viro7111c662006-10-19 23:28:45 -070075static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070076nfsd_proc_setattr(struct svc_rqst *rqstp, struct nfsd_sattrargs *argp,
77 struct nfsd_attrstat *resp)
78{
Al Viroc4d987b2006-10-19 23:29:00 -070079 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 dprintk("nfsd: SETATTR %s, valid=%x, size=%ld\n",
81 SVCFH_fmt(&argp->fh),
82 argp->attrs.ia_valid, (long) argp->attrs.ia_size);
83
84 fh_copy(&resp->fh, &argp->fh);
David Shaw846f2fc2006-01-18 17:43:51 -080085 nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,0, (time_t)0);
86 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
89/*
90 * Look up a path name component
91 * Note: the dentry in the resp->fh may be negative if the file
92 * doesn't exist yet.
93 * N.B. After this call resp->fh needs an fh_put
94 */
Al Viro7111c662006-10-19 23:28:45 -070095static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070096nfsd_proc_lookup(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
97 struct nfsd_diropres *resp)
98{
Al Viroc4d987b2006-10-19 23:29:00 -070099 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101 dprintk("nfsd: LOOKUP %s %.*s\n",
102 SVCFH_fmt(&argp->fh), argp->len, argp->name);
103
104 fh_init(&resp->fh, NFS_FHSIZE);
105 nfserr = nfsd_lookup(rqstp, &argp->fh, argp->name, argp->len,
106 &resp->fh);
107
108 fh_put(&argp->fh);
David Shaw846f2fc2006-01-18 17:43:51 -0800109 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
112/*
113 * Read a symlink.
114 */
Al Viro7111c662006-10-19 23:28:45 -0700115static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116nfsd_proc_readlink(struct svc_rqst *rqstp, struct nfsd_readlinkargs *argp,
117 struct nfsd_readlinkres *resp)
118{
Al Viroc4d987b2006-10-19 23:29:00 -0700119 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
122
123 /* Read the symlink. */
124 resp->len = NFS_MAXPATHLEN;
125 nfserr = nfsd_readlink(rqstp, &argp->fh, argp->buffer, &resp->len);
126
127 fh_put(&argp->fh);
128 return nfserr;
129}
130
131/*
132 * Read a portion of a file.
133 * N.B. After this call resp->fh needs an fh_put
134 */
Al Viro7111c662006-10-19 23:28:45 -0700135static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
137 struct nfsd_readres *resp)
138{
Al Viroc4d987b2006-10-19 23:29:00 -0700139 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 dprintk("nfsd: READ %s %d bytes at %d\n",
142 SVCFH_fmt(&argp->fh),
143 argp->count, argp->offset);
144
145 /* Obtain buffer pointer for payload. 19 is 1 word for
146 * status, 17 words for fattr, and 1 word for the byte count.
147 */
148
Greg Banks7adae482006-10-04 02:15:47 -0700149 if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 printk(KERN_NOTICE
151 "oversized read request from %u.%u.%u.%u:%d (%d bytes)\n",
152 NIPQUAD(rqstp->rq_addr.sin_addr.s_addr),
153 ntohs(rqstp->rq_addr.sin_port),
154 argp->count);
Greg Banks7adae482006-10-04 02:15:47 -0700155 argp->count = NFSSVC_MAXBLKSIZE_V2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157 svc_reserve(rqstp, (19<<2) + argp->count + 4);
158
159 resp->count = argp->count;
160 nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
161 argp->offset,
NeilBrown3cc03b12006-10-04 02:15:47 -0700162 rqstp->rq_vec, argp->vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 &resp->count);
164
David Shaw846f2fc2006-01-18 17:43:51 -0800165 if (nfserr) return nfserr;
166 return nfserrno(vfs_getattr(resp->fh.fh_export->ex_mnt,
167 resp->fh.fh_dentry,
168 &resp->stat));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
171/*
172 * Write data to a file
173 * N.B. After this call resp->fh needs an fh_put
174 */
Al Viro7111c662006-10-19 23:28:45 -0700175static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
177 struct nfsd_attrstat *resp)
178{
Al Viroc4d987b2006-10-19 23:29:00 -0700179 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 int stable = 1;
181
182 dprintk("nfsd: WRITE %s %d bytes at %d\n",
183 SVCFH_fmt(&argp->fh),
184 argp->len, argp->offset);
185
186 nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
187 argp->offset,
NeilBrown3cc03b12006-10-04 02:15:47 -0700188 rqstp->rq_vec, argp->vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 argp->len,
190 &stable);
David Shaw846f2fc2006-01-18 17:43:51 -0800191 return nfsd_return_attrs(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192}
193
194/*
195 * CREATE processing is complicated. The keyword here is `overloaded.'
196 * The parent directory is kept locked between the check for existence
197 * and the actual create() call in compliance with VFS protocols.
198 * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
199 */
Al Viro7111c662006-10-19 23:28:45 -0700200static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
202 struct nfsd_diropres *resp)
203{
204 svc_fh *dirfhp = &argp->fh;
205 svc_fh *newfhp = &resp->fh;
206 struct iattr *attr = &argp->attrs;
207 struct inode *inode;
208 struct dentry *dchild;
Al Viroc4d987b2006-10-19 23:29:00 -0700209 int type, mode;
210 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 dev_t rdev = 0, wanted = new_decode_dev(attr->ia_size);
212
213 dprintk("nfsd: CREATE %s %.*s\n",
214 SVCFH_fmt(dirfhp), argp->len, argp->name);
215
216 /* First verify the parent file handle */
217 nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, MAY_EXEC);
218 if (nfserr)
219 goto done; /* must fh_put dirfhp even on error */
220
221 /* Check for MAY_WRITE in nfsd_create if necessary */
222
223 nfserr = nfserr_acces;
224 if (!argp->len)
225 goto done;
226 nfserr = nfserr_exist;
227 if (isdotent(argp->name, argp->len))
228 goto done;
NeilBrown7ed94292006-10-04 02:15:43 -0700229 fh_lock_nested(dirfhp, I_MUTEX_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
231 if (IS_ERR(dchild)) {
232 nfserr = nfserrno(PTR_ERR(dchild));
233 goto out_unlock;
234 }
235 fh_init(newfhp, NFS_FHSIZE);
236 nfserr = fh_compose(newfhp, dirfhp->fh_export, dchild, dirfhp);
237 if (!nfserr && !dchild->d_inode)
238 nfserr = nfserr_noent;
239 dput(dchild);
240 if (nfserr) {
241 if (nfserr != nfserr_noent)
242 goto out_unlock;
243 /*
244 * If the new file handle wasn't verified, we can't tell
245 * whether the file exists or not. Time to bail ...
246 */
247 nfserr = nfserr_acces;
248 if (!newfhp->fh_dentry) {
249 printk(KERN_WARNING
250 "nfsd_proc_create: file handle not verified\n");
251 goto out_unlock;
252 }
253 }
254
255 inode = newfhp->fh_dentry->d_inode;
256
257 /* Unfudge the mode bits */
258 if (attr->ia_valid & ATTR_MODE) {
259 type = attr->ia_mode & S_IFMT;
260 mode = attr->ia_mode & ~S_IFMT;
261 if (!type) {
262 /* no type, so if target exists, assume same as that,
263 * else assume a file */
264 if (inode) {
265 type = inode->i_mode & S_IFMT;
266 switch(type) {
267 case S_IFCHR:
268 case S_IFBLK:
269 /* reserve rdev for later checking */
270 rdev = inode->i_rdev;
271 attr->ia_valid |= ATTR_SIZE;
272
273 /* FALLTHROUGH */
274 case S_IFIFO:
275 /* this is probably a permission check..
276 * at least IRIX implements perm checking on
277 * echo thing > device-special-file-or-pipe
278 * by doing a CREATE with type==0
279 */
280 nfserr = nfsd_permission(newfhp->fh_export,
281 newfhp->fh_dentry,
282 MAY_WRITE|MAY_LOCAL_ACCESS);
283 if (nfserr && nfserr != nfserr_rofs)
284 goto out_unlock;
285 }
286 } else
287 type = S_IFREG;
288 }
289 } else if (inode) {
290 type = inode->i_mode & S_IFMT;
291 mode = inode->i_mode & ~S_IFMT;
292 } else {
293 type = S_IFREG;
294 mode = 0; /* ??? */
295 }
296
297 attr->ia_valid |= ATTR_MODE;
298 attr->ia_mode = mode;
299
300 /* Special treatment for non-regular files according to the
301 * gospel of sun micro
302 */
303 if (type != S_IFREG) {
304 int is_borc = 0;
305 if (type != S_IFBLK && type != S_IFCHR) {
306 rdev = 0;
307 } else if (type == S_IFCHR && !(attr->ia_valid & ATTR_SIZE)) {
308 /* If you think you've seen the worst, grok this. */
309 type = S_IFIFO;
310 } else {
311 /* Okay, char or block special */
312 is_borc = 1;
313 if (!rdev)
314 rdev = wanted;
315 }
316
317 /* we've used the SIZE information, so discard it */
318 attr->ia_valid &= ~ATTR_SIZE;
319
320 /* Make sure the type and device matches */
321 nfserr = nfserr_exist;
322 if (inode && type != (inode->i_mode & S_IFMT))
323 goto out_unlock;
324 }
325
326 nfserr = 0;
327 if (!inode) {
328 /* File doesn't exist. Create it and set attrs */
329 nfserr = nfsd_create(rqstp, dirfhp, argp->name, argp->len,
330 attr, type, rdev, newfhp);
331 } else if (type == S_IFREG) {
332 dprintk("nfsd: existing %s, valid=%x, size=%ld\n",
333 argp->name, attr->ia_valid, (long) attr->ia_size);
334 /* File already exists. We ignore all attributes except
335 * size, so that creat() behaves exactly like
336 * open(..., O_CREAT|O_TRUNC|O_WRONLY).
337 */
338 attr->ia_valid &= ATTR_SIZE;
339 if (attr->ia_valid)
340 nfserr = nfsd_setattr(rqstp, newfhp, attr, 0, (time_t)0);
341 }
342
343out_unlock:
344 /* We don't really need to unlock, as fh_put does it. */
345 fh_unlock(dirfhp);
346
347done:
348 fh_put(dirfhp);
David Shaw846f2fc2006-01-18 17:43:51 -0800349 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
Al Viro7111c662006-10-19 23:28:45 -0700352static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
354 void *resp)
355{
Al Viroc4d987b2006-10-19 23:29:00 -0700356 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 dprintk("nfsd: REMOVE %s %.*s\n", SVCFH_fmt(&argp->fh),
359 argp->len, argp->name);
360
361 /* Unlink. -SIFDIR means file must not be a directory */
362 nfserr = nfsd_unlink(rqstp, &argp->fh, -S_IFDIR, argp->name, argp->len);
363 fh_put(&argp->fh);
364 return nfserr;
365}
366
Al Viro7111c662006-10-19 23:28:45 -0700367static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp,
369 void *resp)
370{
Al Viroc4d987b2006-10-19 23:29:00 -0700371 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 dprintk("nfsd: RENAME %s %.*s -> \n",
374 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
375 dprintk("nfsd: -> %s %.*s\n",
376 SVCFH_fmt(&argp->tfh), argp->tlen, argp->tname);
377
378 nfserr = nfsd_rename(rqstp, &argp->ffh, argp->fname, argp->flen,
379 &argp->tfh, argp->tname, argp->tlen);
380 fh_put(&argp->ffh);
381 fh_put(&argp->tfh);
382 return nfserr;
383}
384
Al Viro7111c662006-10-19 23:28:45 -0700385static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp,
387 void *resp)
388{
Al Viroc4d987b2006-10-19 23:29:00 -0700389 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391 dprintk("nfsd: LINK %s ->\n",
392 SVCFH_fmt(&argp->ffh));
393 dprintk("nfsd: %s %.*s\n",
394 SVCFH_fmt(&argp->tfh),
395 argp->tlen,
396 argp->tname);
397
398 nfserr = nfsd_link(rqstp, &argp->tfh, argp->tname, argp->tlen,
399 &argp->ffh);
400 fh_put(&argp->ffh);
401 fh_put(&argp->tfh);
402 return nfserr;
403}
404
Al Viro7111c662006-10-19 23:28:45 -0700405static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp,
407 void *resp)
408{
409 struct svc_fh newfh;
Al Viroc4d987b2006-10-19 23:29:00 -0700410 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 dprintk("nfsd: SYMLINK %s %.*s -> %.*s\n",
413 SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
414 argp->tlen, argp->tname);
415
416 fh_init(&newfh, NFS_FHSIZE);
417 /*
418 * Create the link, look up new file and set attrs.
419 */
420 nfserr = nfsd_symlink(rqstp, &argp->ffh, argp->fname, argp->flen,
421 argp->tname, argp->tlen,
422 &newfh, &argp->attrs);
423
424
425 fh_put(&argp->ffh);
426 fh_put(&newfh);
427 return nfserr;
428}
429
430/*
431 * Make directory. This operation is not idempotent.
432 * N.B. After this call resp->fh needs an fh_put
433 */
Al Viro7111c662006-10-19 23:28:45 -0700434static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
436 struct nfsd_diropres *resp)
437{
Al Viroc4d987b2006-10-19 23:29:00 -0700438 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
440 dprintk("nfsd: MKDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
441
442 if (resp->fh.fh_dentry) {
443 printk(KERN_WARNING
444 "nfsd_proc_mkdir: response already verified??\n");
445 }
446
447 argp->attrs.ia_valid &= ~ATTR_SIZE;
448 fh_init(&resp->fh, NFS_FHSIZE);
449 nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
450 &argp->attrs, S_IFDIR, 0, &resp->fh);
451 fh_put(&argp->fh);
David Shaw846f2fc2006-01-18 17:43:51 -0800452 return nfsd_return_dirop(nfserr, resp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
454
455/*
456 * Remove a directory
457 */
Al Viro7111c662006-10-19 23:28:45 -0700458static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
460 void *resp)
461{
Al Viroc4d987b2006-10-19 23:29:00 -0700462 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 dprintk("nfsd: RMDIR %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
465
466 nfserr = nfsd_unlink(rqstp, &argp->fh, S_IFDIR, argp->name, argp->len);
467 fh_put(&argp->fh);
468 return nfserr;
469}
470
471/*
472 * Read a portion of a directory.
473 */
Al Viro7111c662006-10-19 23:28:45 -0700474static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp,
476 struct nfsd_readdirres *resp)
477{
Al Viroc4d987b2006-10-19 23:29:00 -0700478 int count;
479 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 loff_t offset;
481
482 dprintk("nfsd: READDIR %s %d bytes at %d\n",
483 SVCFH_fmt(&argp->fh),
484 argp->count, argp->cookie);
485
486 /* Shrink to the client read size */
487 count = (argp->count >> 2) - 2;
488
489 /* Make sure we've room for the NULL ptr & eof flag */
490 count -= 2;
491 if (count < 0)
492 count = 0;
493
494 resp->buffer = argp->buffer;
495 resp->offset = NULL;
496 resp->buflen = count;
497 resp->common.err = nfs_ok;
498 /* Read directory and encode entries on the fly */
499 offset = argp->cookie;
500 nfserr = nfsd_readdir(rqstp, &argp->fh, &offset,
501 &resp->common, nfssvc_encode_entry);
502
503 resp->count = resp->buffer - argp->buffer;
504 if (resp->offset)
505 *resp->offset = htonl(offset);
506
507 fh_put(&argp->fh);
508 return nfserr;
509}
510
511/*
512 * Get file system info
513 */
Al Viro7111c662006-10-19 23:28:45 -0700514static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
516 struct nfsd_statfsres *resp)
517{
Al Viroc4d987b2006-10-19 23:29:00 -0700518 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520 dprintk("nfsd: STATFS %s\n", SVCFH_fmt(&argp->fh));
521
522 nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats);
523 fh_put(&argp->fh);
524 return nfserr;
525}
526
527/*
528 * NFSv2 Server procedures.
529 * Only the results of non-idempotent operations are cached.
530 */
531#define nfsd_proc_none NULL
532#define nfssvc_release_none NULL
533struct nfsd_void { int dummy; };
534
535#define PROC(name, argt, rest, relt, cache, respsize) \
536 { (svc_procfunc) nfsd_proc_##name, \
537 (kxdrproc_t) nfssvc_decode_##argt, \
538 (kxdrproc_t) nfssvc_encode_##rest, \
539 (kxdrproc_t) nfssvc_release_##relt, \
540 sizeof(struct nfsd_##argt), \
541 sizeof(struct nfsd_##rest), \
542 0, \
543 cache, \
544 respsize, \
545 }
546
547#define ST 1 /* status */
548#define FH 8 /* filehandle */
549#define AT 18 /* attributes */
550
551static struct svc_procedure nfsd_procedures2[18] = {
552 PROC(null, void, void, none, RC_NOCACHE, ST),
553 PROC(getattr, fhandle, attrstat, fhandle, RC_NOCACHE, ST+AT),
554 PROC(setattr, sattrargs, attrstat, fhandle, RC_REPLBUFF, ST+AT),
555 PROC(none, void, void, none, RC_NOCACHE, ST),
556 PROC(lookup, diropargs, diropres, fhandle, RC_NOCACHE, ST+FH+AT),
557 PROC(readlink, readlinkargs, readlinkres, none, RC_NOCACHE, ST+1+NFS_MAXPATHLEN/4),
Greg Banks7adae482006-10-04 02:15:47 -0700558 PROC(read, readargs, readres, fhandle, RC_NOCACHE, ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 PROC(none, void, void, none, RC_NOCACHE, ST),
560 PROC(write, writeargs, attrstat, fhandle, RC_REPLBUFF, ST+AT),
561 PROC(create, createargs, diropres, fhandle, RC_REPLBUFF, ST+FH+AT),
562 PROC(remove, diropargs, void, none, RC_REPLSTAT, ST),
563 PROC(rename, renameargs, void, none, RC_REPLSTAT, ST),
564 PROC(link, linkargs, void, none, RC_REPLSTAT, ST),
565 PROC(symlink, symlinkargs, void, none, RC_REPLSTAT, ST),
566 PROC(mkdir, createargs, diropres, fhandle, RC_REPLBUFF, ST+FH+AT),
567 PROC(rmdir, diropargs, void, none, RC_REPLSTAT, ST),
568 PROC(readdir, readdirargs, readdirres, none, RC_NOCACHE, 0),
569 PROC(statfs, fhandle, statfsres, none, RC_NOCACHE, ST+5),
570};
571
572
573struct svc_version nfsd_version2 = {
574 .vs_vers = 2,
575 .vs_nproc = 18,
576 .vs_proc = nfsd_procedures2,
577 .vs_dispatch = nfsd_dispatch,
578 .vs_xdrsize = NFS2_SVC_XDRSIZE,
579};
580
581/*
582 * Map errnos to NFS errnos.
583 */
Al Viro63f103112006-10-19 23:28:54 -0700584__be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585nfserrno (int errno)
586{
587 static struct {
Al Viro63f103112006-10-19 23:28:54 -0700588 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 int syserr;
590 } nfs_errtbl[] = {
591 { nfs_ok, 0 },
592 { nfserr_perm, -EPERM },
593 { nfserr_noent, -ENOENT },
594 { nfserr_io, -EIO },
595 { nfserr_nxio, -ENXIO },
596 { nfserr_acces, -EACCES },
597 { nfserr_exist, -EEXIST },
598 { nfserr_xdev, -EXDEV },
599 { nfserr_mlink, -EMLINK },
600 { nfserr_nodev, -ENODEV },
601 { nfserr_notdir, -ENOTDIR },
602 { nfserr_isdir, -EISDIR },
603 { nfserr_inval, -EINVAL },
604 { nfserr_fbig, -EFBIG },
605 { nfserr_nospc, -ENOSPC },
606 { nfserr_rofs, -EROFS },
607 { nfserr_mlink, -EMLINK },
608 { nfserr_nametoolong, -ENAMETOOLONG },
609 { nfserr_notempty, -ENOTEMPTY },
610#ifdef EDQUOT
611 { nfserr_dquot, -EDQUOT },
612#endif
613 { nfserr_stale, -ESTALE },
614 { nfserr_jukebox, -ETIMEDOUT },
615 { nfserr_dropit, -EAGAIN },
616 { nfserr_dropit, -ENOMEM },
617 { nfserr_badname, -ESRCH },
618 { nfserr_io, -ETXTBSY },
Andreas Gruenbachera838cc42005-06-22 17:16:24 +0000619 { nfserr_notsupp, -EOPNOTSUPP },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 };
621 int i;
622
Al Viro63f103112006-10-19 23:28:54 -0700623 for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (nfs_errtbl[i].syserr == errno)
625 return nfs_errtbl[i].nfserr;
626 }
627 printk (KERN_INFO "nfsd: non-standard errno: %d\n", errno);
628 return nfserr_io;
629}
630