blob: 579ce8c69daab35ff20481231f179eefb18b5db9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfsd/nfs3proc.c
3 *
4 * Process version 3 NFS requests.
5 *
6 * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de>
7 */
8
9#include <linux/linkage.h>
10#include <linux/time.h>
11#include <linux/errno.h>
12#include <linux/fs.h>
13#include <linux/ext2_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/unistd.h>
19#include <linux/slab.h>
20#include <linux/major.h>
Qinghuang Feng12214cb2009-01-12 03:13:53 +080021#include <linux/magic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include <linux/sunrpc/svc.h>
24#include <linux/nfsd/nfsd.h>
25#include <linux/nfsd/cache.h>
26#include <linux/nfsd/xdr3.h>
27#include <linux/nfs3.h>
28
29#define NFSDDBG_FACILITY NFSDDBG_PROC
30
31#define RETURN_STATUS(st) { resp->status = (st); return (st); }
32
33static int nfs3_ftypes[] = {
34 0, /* NF3NON */
35 S_IFREG, /* NF3REG */
36 S_IFDIR, /* NF3DIR */
37 S_IFBLK, /* NF3BLK */
38 S_IFCHR, /* NF3CHR */
39 S_IFLNK, /* NF3LNK */
40 S_IFSOCK, /* NF3SOCK */
41 S_IFIFO, /* NF3FIFO */
42};
43
44/*
45 * NULL call.
46 */
Al Viro7111c662006-10-19 23:28:45 -070047static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070048nfsd3_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
49{
50 return nfs_ok;
51}
52
53/*
54 * Get a file's attributes
55 */
Al Viro7111c662006-10-19 23:28:45 -070056static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070057nfsd3_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle *argp,
58 struct nfsd3_attrstat *resp)
59{
Al Viroc4d987b2006-10-19 23:29:00 -070060 int err;
61 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63 dprintk("nfsd: GETATTR(3) %s\n",
David Shawa334de22006-01-06 00:19:58 -080064 SVCFH_fmt(&argp->fh));
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66 fh_copy(&resp->fh, &argp->fh);
J. Bruce Fields04716e62008-08-07 13:00:20 -040067 nfserr = fh_verify(rqstp, &resp->fh, 0,
68 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
David Shawa334de22006-01-06 00:19:58 -080069 if (nfserr)
70 RETURN_STATUS(nfserr);
71
Jan Blunck54775492008-02-14 19:38:39 -080072 err = vfs_getattr(resp->fh.fh_export->ex_path.mnt,
David Shawa334de22006-01-06 00:19:58 -080073 resp->fh.fh_dentry, &resp->stat);
74 nfserr = nfserrno(err);
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 RETURN_STATUS(nfserr);
77}
78
79/*
80 * Set a file's attributes
81 */
Al Viro7111c662006-10-19 23:28:45 -070082static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -070083nfsd3_proc_setattr(struct svc_rqst *rqstp, struct nfsd3_sattrargs *argp,
84 struct nfsd3_attrstat *resp)
85{
Al Viroc4d987b2006-10-19 23:29:00 -070086 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 dprintk("nfsd: SETATTR(3) %s\n",
89 SVCFH_fmt(&argp->fh));
90
91 fh_copy(&resp->fh, &argp->fh);
92 nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
93 argp->check_guard, argp->guardtime);
94 RETURN_STATUS(nfserr);
95}
96
97/*
98 * Look up a path name component
99 */
Al Viro7111c662006-10-19 23:28:45 -0700100static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101nfsd3_proc_lookup(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
102 struct nfsd3_diropres *resp)
103{
Al Viroc4d987b2006-10-19 23:29:00 -0700104 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 dprintk("nfsd: LOOKUP(3) %s %.*s\n",
107 SVCFH_fmt(&argp->fh),
108 argp->len,
109 argp->name);
110
111 fh_copy(&resp->dirfh, &argp->fh);
112 fh_init(&resp->fh, NFS3_FHSIZE);
113
114 nfserr = nfsd_lookup(rqstp, &resp->dirfh,
115 argp->name,
116 argp->len,
117 &resp->fh);
118 RETURN_STATUS(nfserr);
119}
120
121/*
122 * Check file access
123 */
Al Viro7111c662006-10-19 23:28:45 -0700124static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125nfsd3_proc_access(struct svc_rqst *rqstp, struct nfsd3_accessargs *argp,
126 struct nfsd3_accessres *resp)
127{
Al Viroc4d987b2006-10-19 23:29:00 -0700128 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 dprintk("nfsd: ACCESS(3) %s 0x%x\n",
131 SVCFH_fmt(&argp->fh),
132 argp->access);
133
134 fh_copy(&resp->fh, &argp->fh);
135 resp->access = argp->access;
136 nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
137 RETURN_STATUS(nfserr);
138}
139
140/*
141 * Read a symlink.
142 */
Al Viro7111c662006-10-19 23:28:45 -0700143static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144nfsd3_proc_readlink(struct svc_rqst *rqstp, struct nfsd3_readlinkargs *argp,
145 struct nfsd3_readlinkres *resp)
146{
Al Viroc4d987b2006-10-19 23:29:00 -0700147 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh));
150
151 /* Read the symlink. */
152 fh_copy(&resp->fh, &argp->fh);
153 resp->len = NFS3_MAXPATHLEN;
154 nfserr = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
155 RETURN_STATUS(nfserr);
156}
157
158/*
159 * Read a portion of a file.
160 */
Al Viro7111c662006-10-19 23:28:45 -0700161static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp,
163 struct nfsd3_readres *resp)
164{
Al Viroc4d987b2006-10-19 23:29:00 -0700165 __be32 nfserr;
Greg Banks7adae482006-10-04 02:15:47 -0700166 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 dprintk("nfsd: READ(3) %s %lu bytes at %lu\n",
169 SVCFH_fmt(&argp->fh),
170 (unsigned long) argp->count,
171 (unsigned long) argp->offset);
172
173 /* Obtain buffer pointer for payload.
174 * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
175 * + 1 (xdr opaque byte count) = 26
176 */
177
178 resp->count = argp->count;
Greg Banks7adae482006-10-04 02:15:47 -0700179 if (max_blocksize < resp->count)
180 resp->count = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Jeff Laytoncd123012007-05-09 02:34:50 -0700182 svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 fh_copy(&resp->fh, &argp->fh);
185 nfserr = nfsd_read(rqstp, &resp->fh, NULL,
186 argp->offset,
NeilBrown3cc03b12006-10-04 02:15:47 -0700187 rqstp->rq_vec, argp->vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 &resp->count);
189 if (nfserr == 0) {
190 struct inode *inode = resp->fh.fh_dentry->d_inode;
191
192 resp->eof = (argp->offset + resp->count) >= inode->i_size;
193 }
194
195 RETURN_STATUS(nfserr);
196}
197
198/*
199 * Write data to a file
200 */
Al Viro7111c662006-10-19 23:28:45 -0700201static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202nfsd3_proc_write(struct svc_rqst *rqstp, struct nfsd3_writeargs *argp,
203 struct nfsd3_writeres *resp)
204{
Al Viroc4d987b2006-10-19 23:29:00 -0700205 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
207 dprintk("nfsd: WRITE(3) %s %d bytes at %ld%s\n",
208 SVCFH_fmt(&argp->fh),
209 argp->len,
210 (unsigned long) argp->offset,
211 argp->stable? " stable" : "");
212
213 fh_copy(&resp->fh, &argp->fh);
214 resp->committed = argp->stable;
215 nfserr = nfsd_write(rqstp, &resp->fh, NULL,
216 argp->offset,
NeilBrown3cc03b12006-10-04 02:15:47 -0700217 rqstp->rq_vec, argp->vlen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 argp->len,
219 &resp->committed);
220 resp->count = argp->count;
221 RETURN_STATUS(nfserr);
222}
223
224/*
225 * With NFSv3, CREATE processing is a lot easier than with NFSv2.
226 * At least in theory; we'll see how it fares in practice when the
227 * first reports about SunOS compatibility problems start to pour in...
228 */
Al Viro7111c662006-10-19 23:28:45 -0700229static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230nfsd3_proc_create(struct svc_rqst *rqstp, struct nfsd3_createargs *argp,
231 struct nfsd3_diropres *resp)
232{
233 svc_fh *dirfhp, *newfhp = NULL;
234 struct iattr *attr;
Al Viroc4d987b2006-10-19 23:29:00 -0700235 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 dprintk("nfsd: CREATE(3) %s %.*s\n",
238 SVCFH_fmt(&argp->fh),
239 argp->len,
240 argp->name);
241
242 dirfhp = fh_copy(&resp->dirfh, &argp->fh);
243 newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
244 attr = &argp->attrs;
245
246 /* Get the directory inode */
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200247 nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_CREATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 if (nfserr)
249 RETURN_STATUS(nfserr);
250
251 /* Unfudge the mode bits */
252 attr->ia_mode &= ~S_IFMT;
253 if (!(attr->ia_valid & ATTR_MODE)) {
254 attr->ia_valid |= ATTR_MODE;
255 attr->ia_mode = S_IFREG;
256 } else {
257 attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
258 }
259
260 /* Now create the file and set attributes */
261 nfserr = nfsd_create_v3(rqstp, dirfhp, argp->name, argp->len,
262 attr, newfhp,
J. Bruce Fields81ac95c2006-11-08 17:44:40 -0800263 argp->createmode, argp->verf, NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 RETURN_STATUS(nfserr);
266}
267
268/*
269 * Make directory. This operation is not idempotent.
270 */
Al Viro7111c662006-10-19 23:28:45 -0700271static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272nfsd3_proc_mkdir(struct svc_rqst *rqstp, struct nfsd3_createargs *argp,
273 struct nfsd3_diropres *resp)
274{
Al Viroc4d987b2006-10-19 23:29:00 -0700275 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 dprintk("nfsd: MKDIR(3) %s %.*s\n",
278 SVCFH_fmt(&argp->fh),
279 argp->len,
280 argp->name);
281
282 argp->attrs.ia_valid &= ~ATTR_SIZE;
283 fh_copy(&resp->dirfh, &argp->fh);
284 fh_init(&resp->fh, NFS3_FHSIZE);
285 nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
286 &argp->attrs, S_IFDIR, 0, &resp->fh);
287
288 RETURN_STATUS(nfserr);
289}
290
Al Viro7111c662006-10-19 23:28:45 -0700291static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292nfsd3_proc_symlink(struct svc_rqst *rqstp, struct nfsd3_symlinkargs *argp,
293 struct nfsd3_diropres *resp)
294{
Al Viroc4d987b2006-10-19 23:29:00 -0700295 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
297 dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n",
298 SVCFH_fmt(&argp->ffh),
299 argp->flen, argp->fname,
300 argp->tlen, argp->tname);
301
302 fh_copy(&resp->dirfh, &argp->ffh);
303 fh_init(&resp->fh, NFS3_FHSIZE);
304 nfserr = nfsd_symlink(rqstp, &resp->dirfh, argp->fname, argp->flen,
305 argp->tname, argp->tlen,
306 &resp->fh, &argp->attrs);
307 RETURN_STATUS(nfserr);
308}
309
310/*
311 * Make socket/fifo/device.
312 */
Al Viro7111c662006-10-19 23:28:45 -0700313static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314nfsd3_proc_mknod(struct svc_rqst *rqstp, struct nfsd3_mknodargs *argp,
315 struct nfsd3_diropres *resp)
316{
Al Viroc4d987b2006-10-19 23:29:00 -0700317 __be32 nfserr;
318 int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 dev_t rdev = 0;
320
321 dprintk("nfsd: MKNOD(3) %s %.*s\n",
322 SVCFH_fmt(&argp->fh),
323 argp->len,
324 argp->name);
325
326 fh_copy(&resp->dirfh, &argp->fh);
327 fh_init(&resp->fh, NFS3_FHSIZE);
328
329 if (argp->ftype == 0 || argp->ftype >= NF3BAD)
330 RETURN_STATUS(nfserr_inval);
331 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
332 rdev = MKDEV(argp->major, argp->minor);
333 if (MAJOR(rdev) != argp->major ||
334 MINOR(rdev) != argp->minor)
335 RETURN_STATUS(nfserr_inval);
336 } else
337 if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO)
338 RETURN_STATUS(nfserr_inval);
339
340 type = nfs3_ftypes[argp->ftype];
341 nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
342 &argp->attrs, type, rdev, &resp->fh);
343
344 RETURN_STATUS(nfserr);
345}
346
347/*
348 * Remove file/fifo/socket etc.
349 */
Al Viro7111c662006-10-19 23:28:45 -0700350static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351nfsd3_proc_remove(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
352 struct nfsd3_attrstat *resp)
353{
Al Viroc4d987b2006-10-19 23:29:00 -0700354 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 dprintk("nfsd: REMOVE(3) %s %.*s\n",
357 SVCFH_fmt(&argp->fh),
358 argp->len,
359 argp->name);
360
361 /* Unlink. -S_IFDIR means file must not be a directory */
362 fh_copy(&resp->fh, &argp->fh);
363 nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len);
364 RETURN_STATUS(nfserr);
365}
366
367/*
368 * Remove a directory
369 */
Al Viro7111c662006-10-19 23:28:45 -0700370static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371nfsd3_proc_rmdir(struct svc_rqst *rqstp, struct nfsd3_diropargs *argp,
372 struct nfsd3_attrstat *resp)
373{
Al Viroc4d987b2006-10-19 23:29:00 -0700374 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 dprintk("nfsd: RMDIR(3) %s %.*s\n",
377 SVCFH_fmt(&argp->fh),
378 argp->len,
379 argp->name);
380
381 fh_copy(&resp->fh, &argp->fh);
382 nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len);
383 RETURN_STATUS(nfserr);
384}
385
Al Viro7111c662006-10-19 23:28:45 -0700386static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387nfsd3_proc_rename(struct svc_rqst *rqstp, struct nfsd3_renameargs *argp,
388 struct nfsd3_renameres *resp)
389{
Al Viroc4d987b2006-10-19 23:29:00 -0700390 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 dprintk("nfsd: RENAME(3) %s %.*s ->\n",
393 SVCFH_fmt(&argp->ffh),
394 argp->flen,
395 argp->fname);
396 dprintk("nfsd: -> %s %.*s\n",
397 SVCFH_fmt(&argp->tfh),
398 argp->tlen,
399 argp->tname);
400
401 fh_copy(&resp->ffh, &argp->ffh);
402 fh_copy(&resp->tfh, &argp->tfh);
403 nfserr = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
404 &resp->tfh, argp->tname, argp->tlen);
405 RETURN_STATUS(nfserr);
406}
407
Al Viro7111c662006-10-19 23:28:45 -0700408static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409nfsd3_proc_link(struct svc_rqst *rqstp, struct nfsd3_linkargs *argp,
410 struct nfsd3_linkres *resp)
411{
Al Viroc4d987b2006-10-19 23:29:00 -0700412 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 dprintk("nfsd: LINK(3) %s ->\n",
415 SVCFH_fmt(&argp->ffh));
416 dprintk("nfsd: -> %s %.*s\n",
417 SVCFH_fmt(&argp->tfh),
418 argp->tlen,
419 argp->tname);
420
421 fh_copy(&resp->fh, &argp->ffh);
422 fh_copy(&resp->tfh, &argp->tfh);
423 nfserr = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
424 &resp->fh);
425 RETURN_STATUS(nfserr);
426}
427
428/*
429 * Read a portion of a directory.
430 */
Al Viro7111c662006-10-19 23:28:45 -0700431static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432nfsd3_proc_readdir(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp,
433 struct nfsd3_readdirres *resp)
434{
Al Viroc4d987b2006-10-19 23:29:00 -0700435 __be32 nfserr;
436 int count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
438 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
439 SVCFH_fmt(&argp->fh),
440 argp->count, (u32) argp->cookie);
441
442 /* Make sure we've room for the NULL ptr & eof flag, and shrink to
443 * client read size */
444 count = (argp->count >> 2) - 2;
445
446 /* Read directory and encode entries on the fly */
447 fh_copy(&resp->fh, &argp->fh);
448
449 resp->buflen = count;
450 resp->common.err = nfs_ok;
451 resp->buffer = argp->buffer;
452 resp->rqstp = rqstp;
453 nfserr = nfsd_readdir(rqstp, &resp->fh, (loff_t*) &argp->cookie,
454 &resp->common, nfs3svc_encode_entry);
455 memcpy(resp->verf, argp->verf, 8);
456 resp->count = resp->buffer - argp->buffer;
457 if (resp->offset)
458 xdr_encode_hyper(resp->offset, argp->cookie);
459
460 RETURN_STATUS(nfserr);
461}
462
463/*
464 * Read a portion of a directory, including file handles and attrs.
465 * For now, we choose to ignore the dircount parameter.
466 */
Al Viro7111c662006-10-19 23:28:45 -0700467static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468nfsd3_proc_readdirplus(struct svc_rqst *rqstp, struct nfsd3_readdirargs *argp,
469 struct nfsd3_readdirres *resp)
470{
Al Viroc4d987b2006-10-19 23:29:00 -0700471 __be32 nfserr;
472 int count = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 loff_t offset;
474 int i;
475 caddr_t page_addr = NULL;
476
477 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
478 SVCFH_fmt(&argp->fh),
479 argp->count, (u32) argp->cookie);
480
481 /* Convert byte count to number of words (i.e. >> 2),
482 * and reserve room for the NULL ptr & eof flag (-2 words) */
483 resp->count = (argp->count >> 2) - 2;
484
485 /* Read directory and encode entries on the fly */
486 fh_copy(&resp->fh, &argp->fh);
487
488 resp->common.err = nfs_ok;
489 resp->buffer = argp->buffer;
490 resp->buflen = resp->count;
491 resp->rqstp = rqstp;
492 offset = argp->cookie;
493 nfserr = nfsd_readdir(rqstp, &resp->fh,
494 &offset,
495 &resp->common,
496 nfs3svc_encode_entry_plus);
497 memcpy(resp->verf, argp->verf, 8);
498 for (i=1; i<rqstp->rq_resused ; i++) {
499 page_addr = page_address(rqstp->rq_respages[i]);
500
501 if (((caddr_t)resp->buffer >= page_addr) &&
502 ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) {
503 count += (caddr_t)resp->buffer - page_addr;
504 break;
505 }
506 count += PAGE_SIZE;
507 }
508 resp->count = count >> 2;
509 if (resp->offset) {
510 if (unlikely(resp->offset1)) {
511 /* we ended up with offset on a page boundary */
512 *resp->offset = htonl(offset >> 32);
513 *resp->offset1 = htonl(offset & 0xffffffff);
514 resp->offset1 = NULL;
515 } else {
516 xdr_encode_hyper(resp->offset, offset);
517 }
518 }
519
520 RETURN_STATUS(nfserr);
521}
522
523/*
524 * Get file system stats
525 */
Al Viro7111c662006-10-19 23:28:45 -0700526static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527nfsd3_proc_fsstat(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
528 struct nfsd3_fsstatres *resp)
529{
Al Viroc4d987b2006-10-19 23:29:00 -0700530 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 dprintk("nfsd: FSSTAT(3) %s\n",
533 SVCFH_fmt(&argp->fh));
534
J. Bruce Fields04716e62008-08-07 13:00:20 -0400535 nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 fh_put(&argp->fh);
537 RETURN_STATUS(nfserr);
538}
539
540/*
541 * Get file system info
542 */
Al Viro7111c662006-10-19 23:28:45 -0700543static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544nfsd3_proc_fsinfo(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
545 struct nfsd3_fsinfores *resp)
546{
Al Viroc4d987b2006-10-19 23:29:00 -0700547 __be32 nfserr;
Greg Banks7adae482006-10-04 02:15:47 -0700548 u32 max_blocksize = svc_max_payload(rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 dprintk("nfsd: FSINFO(3) %s\n",
551 SVCFH_fmt(&argp->fh));
552
Greg Banks7adae482006-10-04 02:15:47 -0700553 resp->f_rtmax = max_blocksize;
554 resp->f_rtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 resp->f_rtmult = PAGE_SIZE;
Greg Banks7adae482006-10-04 02:15:47 -0700556 resp->f_wtmax = max_blocksize;
557 resp->f_wtpref = max_blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 resp->f_wtmult = PAGE_SIZE;
559 resp->f_dtpref = PAGE_SIZE;
560 resp->f_maxfilesize = ~(u32) 0;
561 resp->f_properties = NFS3_FSF_DEFAULT;
562
J. Bruce Fields04716e62008-08-07 13:00:20 -0400563 nfserr = fh_verify(rqstp, &argp->fh, 0,
564 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 /* Check special features of the file system. May request
567 * different read/write sizes for file systems known to have
568 * problems with large blocks */
569 if (nfserr == 0) {
570 struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb;
571
572 /* Note that we don't care for remote fs's here */
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800573 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 resp->f_properties = NFS3_FSF_BILLYBOY;
575 }
576 resp->f_maxfilesize = sb->s_maxbytes;
577 }
578
579 fh_put(&argp->fh);
580 RETURN_STATUS(nfserr);
581}
582
583/*
584 * Get pathconf info for the specified file
585 */
Al Viro7111c662006-10-19 23:28:45 -0700586static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587nfsd3_proc_pathconf(struct svc_rqst * rqstp, struct nfsd_fhandle *argp,
588 struct nfsd3_pathconfres *resp)
589{
Al Viroc4d987b2006-10-19 23:29:00 -0700590 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 dprintk("nfsd: PATHCONF(3) %s\n",
593 SVCFH_fmt(&argp->fh));
594
595 /* Set default pathconf */
596 resp->p_link_max = 255; /* at least */
597 resp->p_name_max = 255; /* at least */
598 resp->p_no_trunc = 0;
599 resp->p_chown_restricted = 1;
600 resp->p_case_insensitive = 0;
601 resp->p_case_preserving = 1;
602
Miklos Szeredi8837abc2008-06-16 13:20:29 +0200603 nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (nfserr == 0) {
606 struct super_block *sb = argp->fh.fh_dentry->d_inode->i_sb;
607
608 /* Note that we don't care for remote fs's here */
609 switch (sb->s_magic) {
610 case EXT2_SUPER_MAGIC:
611 resp->p_link_max = EXT2_LINK_MAX;
612 resp->p_name_max = EXT2_NAME_LEN;
613 break;
Qinghuang Feng12214cb2009-01-12 03:13:53 +0800614 case MSDOS_SUPER_MAGIC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 resp->p_case_insensitive = 1;
616 resp->p_case_preserving = 0;
617 break;
618 }
619 }
620
621 fh_put(&argp->fh);
622 RETURN_STATUS(nfserr);
623}
624
625
626/*
627 * Commit a file (range) to stable storage.
628 */
Al Viro7111c662006-10-19 23:28:45 -0700629static __be32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630nfsd3_proc_commit(struct svc_rqst * rqstp, struct nfsd3_commitargs *argp,
631 struct nfsd3_commitres *resp)
632{
Al Viroc4d987b2006-10-19 23:29:00 -0700633 __be32 nfserr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
636 SVCFH_fmt(&argp->fh),
637 argp->count,
638 (unsigned long long) argp->offset);
639
640 if (argp->offset > NFS_OFFSET_MAX)
641 RETURN_STATUS(nfserr_inval);
642
643 fh_copy(&resp->fh, &argp->fh);
644 nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count);
645
646 RETURN_STATUS(nfserr);
647}
648
649
650/*
651 * NFSv3 Server procedures.
652 * Only the results of non-idempotent operations are cached.
653 */
654#define nfs3svc_decode_voidargs NULL
655#define nfs3svc_release_void NULL
656#define nfs3svc_decode_fhandleargs nfs3svc_decode_fhandle
657#define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
658#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
659#define nfsd3_mkdirargs nfsd3_createargs
660#define nfsd3_readdirplusargs nfsd3_readdirargs
661#define nfsd3_fhandleargs nfsd_fhandle
662#define nfsd3_fhandleres nfsd3_attrstat
663#define nfsd3_attrstatres nfsd3_attrstat
664#define nfsd3_wccstatres nfsd3_attrstat
665#define nfsd3_createres nfsd3_diropres
666#define nfsd3_voidres nfsd3_voidargs
667struct nfsd3_voidargs { int dummy; };
668
669#define PROC(name, argt, rest, relt, cache, respsize) \
670 { (svc_procfunc) nfsd3_proc_##name, \
671 (kxdrproc_t) nfs3svc_decode_##argt##args, \
672 (kxdrproc_t) nfs3svc_encode_##rest##res, \
673 (kxdrproc_t) nfs3svc_release_##relt, \
674 sizeof(struct nfsd3_##argt##args), \
675 sizeof(struct nfsd3_##rest##res), \
676 0, \
677 cache, \
678 respsize, \
679 }
680
681#define ST 1 /* status*/
682#define FH 17 /* filehandle with length */
683#define AT 21 /* attributes */
684#define pAT (1+AT) /* post attributes - conditional */
685#define WC (7+pAT) /* WCC attributes */
686
687static struct svc_procedure nfsd_procedures3[22] = {
688 PROC(null, void, void, void, RC_NOCACHE, ST),
689 PROC(getattr, fhandle, attrstat, fhandle, RC_NOCACHE, ST+AT),
690 PROC(setattr, sattr, wccstat, fhandle, RC_REPLBUFF, ST+WC),
691 PROC(lookup, dirop, dirop, fhandle2, RC_NOCACHE, ST+FH+pAT+pAT),
692 PROC(access, access, access, fhandle, RC_NOCACHE, ST+pAT+1),
693 PROC(readlink, readlink, readlink, fhandle, RC_NOCACHE, ST+pAT+1+NFS3_MAXPATHLEN/4),
NeilBrown7775f4c2006-04-10 22:55:20 -0700694 PROC(read, read, read, fhandle, RC_NOCACHE, ST+pAT+4+NFSSVC_MAXBLKSIZE/4),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 PROC(write, write, write, fhandle, RC_REPLBUFF, ST+WC+4),
696 PROC(create, create, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
697 PROC(mkdir, mkdir, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
698 PROC(symlink, symlink, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
699 PROC(mknod, mknod, create, fhandle2, RC_REPLBUFF, ST+(1+FH+pAT)+WC),
700 PROC(remove, dirop, wccstat, fhandle, RC_REPLBUFF, ST+WC),
701 PROC(rmdir, dirop, wccstat, fhandle, RC_REPLBUFF, ST+WC),
702 PROC(rename, rename, rename, fhandle2, RC_REPLBUFF, ST+WC+WC),
703 PROC(link, link, link, fhandle2, RC_REPLBUFF, ST+pAT+WC),
704 PROC(readdir, readdir, readdir, fhandle, RC_NOCACHE, 0),
705 PROC(readdirplus,readdirplus, readdir, fhandle, RC_NOCACHE, 0),
706 PROC(fsstat, fhandle, fsstat, void, RC_NOCACHE, ST+pAT+2*6+1),
707 PROC(fsinfo, fhandle, fsinfo, void, RC_NOCACHE, ST+pAT+12),
708 PROC(pathconf, fhandle, pathconf, void, RC_NOCACHE, ST+pAT+6),
709 PROC(commit, commit, commit, fhandle, RC_NOCACHE, ST+WC+2),
710};
711
712struct svc_version nfsd_version3 = {
713 .vs_vers = 3,
714 .vs_nproc = 22,
715 .vs_proc = nfsd_procedures3,
716 .vs_dispatch = nfsd_dispatch,
717 .vs_xdrsize = NFS3_SVC_XDRSIZE,
718};