]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/nfsd/nfs3proc.c
Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[mirror_ubuntu-artful-kernel.git] / fs / nfsd / nfs3proc.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Process version 3 NFS requests.
3 *
4 * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de>
5 */
6
1da177e4
LT
7#include <linux/fs.h>
8#include <linux/ext2_fs.h>
12214cb7 9#include <linux/magic.h>
1da177e4 10
9a74af21
BH
11#include "cache.h"
12#include "xdr3.h"
0a3adade 13#include "vfs.h"
1da177e4
LT
14
15#define NFSDDBG_FACILITY NFSDDBG_PROC
16
17#define RETURN_STATUS(st) { resp->status = (st); return (st); }
18
19static int nfs3_ftypes[] = {
20 0, /* NF3NON */
21 S_IFREG, /* NF3REG */
22 S_IFDIR, /* NF3DIR */
23 S_IFBLK, /* NF3BLK */
24 S_IFCHR, /* NF3CHR */
25 S_IFLNK, /* NF3LNK */
26 S_IFSOCK, /* NF3SOCK */
27 S_IFIFO, /* NF3FIFO */
28};
29
30/*
31 * NULL call.
32 */
7111c66e 33static __be32
a6beb732 34nfsd3_proc_null(struct svc_rqst *rqstp)
1da177e4
LT
35{
36 return nfs_ok;
37}
38
39/*
40 * Get a file's attributes
41 */
7111c66e 42static __be32
a6beb732 43nfsd3_proc_getattr(struct svc_rqst *rqstp)
1da177e4 44{
a6beb732
CH
45 struct nfsd_fhandle *argp = rqstp->rq_argp;
46 struct nfsd3_attrstat *resp = rqstp->rq_resp;
c4d987ba 47 __be32 nfserr;
1da177e4
LT
48
49 dprintk("nfsd: GETATTR(3) %s\n",
a334de28 50 SVCFH_fmt(&argp->fh));
1da177e4
LT
51
52 fh_copy(&resp->fh, &argp->fh);
04716e66
BF
53 nfserr = fh_verify(rqstp, &resp->fh, 0,
54 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
a334de28
DS
55 if (nfserr)
56 RETURN_STATUS(nfserr);
57
3dadecce 58 nfserr = fh_getattr(&resp->fh, &resp->stat);
a334de28 59
1da177e4
LT
60 RETURN_STATUS(nfserr);
61}
62
63/*
64 * Set a file's attributes
65 */
7111c66e 66static __be32
a6beb732 67nfsd3_proc_setattr(struct svc_rqst *rqstp)
1da177e4 68{
a6beb732
CH
69 struct nfsd3_sattrargs *argp = rqstp->rq_argp;
70 struct nfsd3_attrstat *resp = rqstp->rq_resp;
c4d987ba 71 __be32 nfserr;
1da177e4
LT
72
73 dprintk("nfsd: SETATTR(3) %s\n",
74 SVCFH_fmt(&argp->fh));
75
76 fh_copy(&resp->fh, &argp->fh);
77 nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
78 argp->check_guard, argp->guardtime);
79 RETURN_STATUS(nfserr);
80}
81
82/*
83 * Look up a path name component
84 */
7111c66e 85static __be32
a6beb732 86nfsd3_proc_lookup(struct svc_rqst *rqstp)
1da177e4 87{
a6beb732
CH
88 struct nfsd3_diropargs *argp = rqstp->rq_argp;
89 struct nfsd3_diropres *resp = rqstp->rq_resp;
c4d987ba 90 __be32 nfserr;
1da177e4
LT
91
92 dprintk("nfsd: LOOKUP(3) %s %.*s\n",
93 SVCFH_fmt(&argp->fh),
94 argp->len,
95 argp->name);
96
97 fh_copy(&resp->dirfh, &argp->fh);
98 fh_init(&resp->fh, NFS3_FHSIZE);
99
100 nfserr = nfsd_lookup(rqstp, &resp->dirfh,
101 argp->name,
102 argp->len,
103 &resp->fh);
104 RETURN_STATUS(nfserr);
105}
106
107/*
108 * Check file access
109 */
7111c66e 110static __be32
a6beb732 111nfsd3_proc_access(struct svc_rqst *rqstp)
1da177e4 112{
a6beb732
CH
113 struct nfsd3_accessargs *argp = rqstp->rq_argp;
114 struct nfsd3_accessres *resp = rqstp->rq_resp;
c4d987ba 115 __be32 nfserr;
1da177e4
LT
116
117 dprintk("nfsd: ACCESS(3) %s 0x%x\n",
118 SVCFH_fmt(&argp->fh),
119 argp->access);
120
121 fh_copy(&resp->fh, &argp->fh);
122 resp->access = argp->access;
123 nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
124 RETURN_STATUS(nfserr);
125}
126
127/*
128 * Read a symlink.
129 */
7111c66e 130static __be32
a6beb732 131nfsd3_proc_readlink(struct svc_rqst *rqstp)
1da177e4 132{
a6beb732
CH
133 struct nfsd3_readlinkargs *argp = rqstp->rq_argp;
134 struct nfsd3_readlinkres *resp = rqstp->rq_resp;
c4d987ba 135 __be32 nfserr;
1da177e4
LT
136
137 dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh));
138
139 /* Read the symlink. */
140 fh_copy(&resp->fh, &argp->fh);
141 resp->len = NFS3_MAXPATHLEN;
142 nfserr = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
143 RETURN_STATUS(nfserr);
144}
145
146/*
147 * Read a portion of a file.
148 */
7111c66e 149static __be32
a6beb732 150nfsd3_proc_read(struct svc_rqst *rqstp)
1da177e4 151{
a6beb732
CH
152 struct nfsd3_readargs *argp = rqstp->rq_argp;
153 struct nfsd3_readres *resp = rqstp->rq_resp;
c4d987ba 154 __be32 nfserr;
7adae489 155 u32 max_blocksize = svc_max_payload(rqstp);
ac503e4a 156 unsigned long cnt = min(argp->count, max_blocksize);
1da177e4 157
18b631f8 158 dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
1da177e4
LT
159 SVCFH_fmt(&argp->fh),
160 (unsigned long) argp->count,
18b631f8 161 (unsigned long long) argp->offset);
1da177e4
LT
162
163 /* Obtain buffer pointer for payload.
164 * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
165 * + 1 (xdr opaque byte count) = 26
166 */
ac503e4a 167 resp->count = cnt;
cd123012 168 svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
1da177e4
LT
169
170 fh_copy(&resp->fh, &argp->fh);
039a87ca 171 nfserr = nfsd_read(rqstp, &resp->fh,
1da177e4 172 argp->offset,
3cc03b16 173 rqstp->rq_vec, argp->vlen,
1da177e4
LT
174 &resp->count);
175 if (nfserr == 0) {
2b0143b5 176 struct inode *inode = d_inode(resp->fh.fh_dentry);
ac503e4a
BC
177 resp->eof = nfsd_eof_on_read(cnt, resp->count, argp->offset,
178 inode->i_size);
1da177e4
LT
179 }
180
181 RETURN_STATUS(nfserr);
182}
183
184/*
185 * Write data to a file
186 */
7111c66e 187static __be32
a6beb732 188nfsd3_proc_write(struct svc_rqst *rqstp)
1da177e4 189{
a6beb732
CH
190 struct nfsd3_writeargs *argp = rqstp->rq_argp;
191 struct nfsd3_writeres *resp = rqstp->rq_resp;
c4d987ba 192 __be32 nfserr;
31dec253 193 unsigned long cnt = argp->len;
1da177e4 194
18b631f8 195 dprintk("nfsd: WRITE(3) %s %d bytes at %Lu%s\n",
1da177e4
LT
196 SVCFH_fmt(&argp->fh),
197 argp->len,
18b631f8 198 (unsigned long long) argp->offset,
1da177e4
LT
199 argp->stable? " stable" : "");
200
201 fh_copy(&resp->fh, &argp->fh);
202 resp->committed = argp->stable;
52e380e0
KM
203 nfserr = nfsd_write(rqstp, &resp->fh, argp->offset,
204 rqstp->rq_vec, argp->vlen,
205 &cnt, resp->committed);
31dec253 206 resp->count = cnt;
1da177e4
LT
207 RETURN_STATUS(nfserr);
208}
209
210/*
211 * With NFSv3, CREATE processing is a lot easier than with NFSv2.
212 * At least in theory; we'll see how it fares in practice when the
213 * first reports about SunOS compatibility problems start to pour in...
214 */
7111c66e 215static __be32
a6beb732 216nfsd3_proc_create(struct svc_rqst *rqstp)
1da177e4 217{
a6beb732
CH
218 struct nfsd3_createargs *argp = rqstp->rq_argp;
219 struct nfsd3_diropres *resp = rqstp->rq_resp;
1da177e4
LT
220 svc_fh *dirfhp, *newfhp = NULL;
221 struct iattr *attr;
c4d987ba 222 __be32 nfserr;
1da177e4
LT
223
224 dprintk("nfsd: CREATE(3) %s %.*s\n",
225 SVCFH_fmt(&argp->fh),
226 argp->len,
227 argp->name);
228
229 dirfhp = fh_copy(&resp->dirfh, &argp->fh);
230 newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
231 attr = &argp->attrs;
232
1da177e4
LT
233 /* Unfudge the mode bits */
234 attr->ia_mode &= ~S_IFMT;
235 if (!(attr->ia_valid & ATTR_MODE)) {
236 attr->ia_valid |= ATTR_MODE;
237 attr->ia_mode = S_IFREG;
238 } else {
239 attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
240 }
241
242 /* Now create the file and set attributes */
ac6721a1 243 nfserr = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
1da177e4 244 attr, newfhp,
95c7a20a 245 argp->createmode, (u32 *)argp->verf, NULL, NULL);
1da177e4
LT
246
247 RETURN_STATUS(nfserr);
248}
249
250/*
251 * Make directory. This operation is not idempotent.
252 */
7111c66e 253static __be32
a6beb732 254nfsd3_proc_mkdir(struct svc_rqst *rqstp)
1da177e4 255{
a6beb732
CH
256 struct nfsd3_createargs *argp = rqstp->rq_argp;
257 struct nfsd3_diropres *resp = rqstp->rq_resp;
c4d987ba 258 __be32 nfserr;
1da177e4
LT
259
260 dprintk("nfsd: MKDIR(3) %s %.*s\n",
261 SVCFH_fmt(&argp->fh),
262 argp->len,
263 argp->name);
264
265 argp->attrs.ia_valid &= ~ATTR_SIZE;
266 fh_copy(&resp->dirfh, &argp->fh);
267 fh_init(&resp->fh, NFS3_FHSIZE);
268 nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
269 &argp->attrs, S_IFDIR, 0, &resp->fh);
43a9aa64 270 fh_unlock(&resp->dirfh);
1da177e4
LT
271 RETURN_STATUS(nfserr);
272}
273
7111c66e 274static __be32
a6beb732 275nfsd3_proc_symlink(struct svc_rqst *rqstp)
1da177e4 276{
a6beb732
CH
277 struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
278 struct nfsd3_diropres *resp = rqstp->rq_resp;
c4d987ba 279 __be32 nfserr;
1da177e4
LT
280
281 dprintk("nfsd: SYMLINK(3) %s %.*s -> %.*s\n",
282 SVCFH_fmt(&argp->ffh),
283 argp->flen, argp->fname,
284 argp->tlen, argp->tname);
285
286 fh_copy(&resp->dirfh, &argp->ffh);
287 fh_init(&resp->fh, NFS3_FHSIZE);
288 nfserr = nfsd_symlink(rqstp, &resp->dirfh, argp->fname, argp->flen,
1e444f5b 289 argp->tname, &resp->fh);
1da177e4
LT
290 RETURN_STATUS(nfserr);
291}
292
293/*
294 * Make socket/fifo/device.
295 */
7111c66e 296static __be32
a6beb732 297nfsd3_proc_mknod(struct svc_rqst *rqstp)
1da177e4 298{
a6beb732
CH
299 struct nfsd3_mknodargs *argp = rqstp->rq_argp;
300 struct nfsd3_diropres *resp = rqstp->rq_resp;
c4d987ba
AV
301 __be32 nfserr;
302 int type;
1da177e4
LT
303 dev_t rdev = 0;
304
305 dprintk("nfsd: MKNOD(3) %s %.*s\n",
306 SVCFH_fmt(&argp->fh),
307 argp->len,
308 argp->name);
309
310 fh_copy(&resp->dirfh, &argp->fh);
311 fh_init(&resp->fh, NFS3_FHSIZE);
312
313 if (argp->ftype == 0 || argp->ftype >= NF3BAD)
314 RETURN_STATUS(nfserr_inval);
315 if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
316 rdev = MKDEV(argp->major, argp->minor);
317 if (MAJOR(rdev) != argp->major ||
318 MINOR(rdev) != argp->minor)
319 RETURN_STATUS(nfserr_inval);
320 } else
321 if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO)
322 RETURN_STATUS(nfserr_inval);
323
324 type = nfs3_ftypes[argp->ftype];
325 nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
326 &argp->attrs, type, rdev, &resp->fh);
43a9aa64 327 fh_unlock(&resp->dirfh);
1da177e4
LT
328 RETURN_STATUS(nfserr);
329}
330
331/*
332 * Remove file/fifo/socket etc.
333 */
7111c66e 334static __be32
a6beb732 335nfsd3_proc_remove(struct svc_rqst *rqstp)
1da177e4 336{
a6beb732
CH
337 struct nfsd3_diropargs *argp = rqstp->rq_argp;
338 struct nfsd3_attrstat *resp = rqstp->rq_resp;
c4d987ba 339 __be32 nfserr;
1da177e4
LT
340
341 dprintk("nfsd: REMOVE(3) %s %.*s\n",
342 SVCFH_fmt(&argp->fh),
343 argp->len,
344 argp->name);
345
346 /* Unlink. -S_IFDIR means file must not be a directory */
347 fh_copy(&resp->fh, &argp->fh);
348 nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len);
43a9aa64 349 fh_unlock(&resp->fh);
1da177e4
LT
350 RETURN_STATUS(nfserr);
351}
352
353/*
354 * Remove a directory
355 */
7111c66e 356static __be32
a6beb732 357nfsd3_proc_rmdir(struct svc_rqst *rqstp)
1da177e4 358{
a6beb732
CH
359 struct nfsd3_diropargs *argp = rqstp->rq_argp;
360 struct nfsd3_attrstat *resp = rqstp->rq_resp;
c4d987ba 361 __be32 nfserr;
1da177e4
LT
362
363 dprintk("nfsd: RMDIR(3) %s %.*s\n",
364 SVCFH_fmt(&argp->fh),
365 argp->len,
366 argp->name);
367
368 fh_copy(&resp->fh, &argp->fh);
369 nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len);
43a9aa64 370 fh_unlock(&resp->fh);
1da177e4
LT
371 RETURN_STATUS(nfserr);
372}
373
7111c66e 374static __be32
a6beb732 375nfsd3_proc_rename(struct svc_rqst *rqstp)
1da177e4 376{
a6beb732
CH
377 struct nfsd3_renameargs *argp = rqstp->rq_argp;
378 struct nfsd3_renameres *resp = rqstp->rq_resp;
c4d987ba 379 __be32 nfserr;
1da177e4
LT
380
381 dprintk("nfsd: RENAME(3) %s %.*s ->\n",
382 SVCFH_fmt(&argp->ffh),
383 argp->flen,
384 argp->fname);
385 dprintk("nfsd: -> %s %.*s\n",
386 SVCFH_fmt(&argp->tfh),
387 argp->tlen,
388 argp->tname);
389
390 fh_copy(&resp->ffh, &argp->ffh);
391 fh_copy(&resp->tfh, &argp->tfh);
392 nfserr = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
393 &resp->tfh, argp->tname, argp->tlen);
394 RETURN_STATUS(nfserr);
395}
396
7111c66e 397static __be32
a6beb732 398nfsd3_proc_link(struct svc_rqst *rqstp)
1da177e4 399{
a6beb732
CH
400 struct nfsd3_linkargs *argp = rqstp->rq_argp;
401 struct nfsd3_linkres *resp = rqstp->rq_resp;
c4d987ba 402 __be32 nfserr;
1da177e4
LT
403
404 dprintk("nfsd: LINK(3) %s ->\n",
405 SVCFH_fmt(&argp->ffh));
406 dprintk("nfsd: -> %s %.*s\n",
407 SVCFH_fmt(&argp->tfh),
408 argp->tlen,
409 argp->tname);
410
411 fh_copy(&resp->fh, &argp->ffh);
412 fh_copy(&resp->tfh, &argp->tfh);
413 nfserr = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
414 &resp->fh);
415 RETURN_STATUS(nfserr);
416}
417
418/*
419 * Read a portion of a directory.
420 */
7111c66e 421static __be32
a6beb732 422nfsd3_proc_readdir(struct svc_rqst *rqstp)
1da177e4 423{
a6beb732
CH
424 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
425 struct nfsd3_readdirres *resp = rqstp->rq_resp;
c4d987ba
AV
426 __be32 nfserr;
427 int count;
1da177e4
LT
428
429 dprintk("nfsd: READDIR(3) %s %d bytes at %d\n",
430 SVCFH_fmt(&argp->fh),
431 argp->count, (u32) argp->cookie);
432
433 /* Make sure we've room for the NULL ptr & eof flag, and shrink to
434 * client read size */
435 count = (argp->count >> 2) - 2;
436
437 /* Read directory and encode entries on the fly */
438 fh_copy(&resp->fh, &argp->fh);
439
440 resp->buflen = count;
441 resp->common.err = nfs_ok;
442 resp->buffer = argp->buffer;
443 resp->rqstp = rqstp;
444 nfserr = nfsd_readdir(rqstp, &resp->fh, (loff_t*) &argp->cookie,
445 &resp->common, nfs3svc_encode_entry);
446 memcpy(resp->verf, argp->verf, 8);
447 resp->count = resp->buffer - argp->buffer;
448 if (resp->offset)
449 xdr_encode_hyper(resp->offset, argp->cookie);
450
451 RETURN_STATUS(nfserr);
452}
453
454/*
455 * Read a portion of a directory, including file handles and attrs.
456 * For now, we choose to ignore the dircount parameter.
457 */
7111c66e 458static __be32
a6beb732 459nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
1da177e4 460{
a6beb732
CH
461 struct nfsd3_readdirargs *argp = rqstp->rq_argp;
462 struct nfsd3_readdirres *resp = rqstp->rq_resp;
c4d987ba
AV
463 __be32 nfserr;
464 int count = 0;
1da177e4 465 loff_t offset;
afc59400 466 struct page **p;
1da177e4
LT
467 caddr_t page_addr = NULL;
468
469 dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
470 SVCFH_fmt(&argp->fh),
471 argp->count, (u32) argp->cookie);
472
473 /* Convert byte count to number of words (i.e. >> 2),
474 * and reserve room for the NULL ptr & eof flag (-2 words) */
475 resp->count = (argp->count >> 2) - 2;
476
477 /* Read directory and encode entries on the fly */
478 fh_copy(&resp->fh, &argp->fh);
479
480 resp->common.err = nfs_ok;
481 resp->buffer = argp->buffer;
482 resp->buflen = resp->count;
483 resp->rqstp = rqstp;
484 offset = argp->cookie;
18c01ab3
RG
485
486 nfserr = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
487 if (nfserr)
488 RETURN_STATUS(nfserr);
489
490 if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS)
491 RETURN_STATUS(nfserr_notsupp);
492
1da177e4
LT
493 nfserr = nfsd_readdir(rqstp, &resp->fh,
494 &offset,
495 &resp->common,
496 nfs3svc_encode_entry_plus);
497 memcpy(resp->verf, argp->verf, 8);
afc59400
BF
498 for (p = rqstp->rq_respages + 1; p < rqstp->rq_next_page; p++) {
499 page_addr = page_address(*p);
1da177e4
LT
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 */
7111c66e 526static __be32
a6beb732 527nfsd3_proc_fsstat(struct svc_rqst *rqstp)
1da177e4 528{
a6beb732
CH
529 struct nfsd_fhandle *argp = rqstp->rq_argp;
530 struct nfsd3_fsstatres *resp = rqstp->rq_resp;
c4d987ba 531 __be32 nfserr;
1da177e4
LT
532
533 dprintk("nfsd: FSSTAT(3) %s\n",
534 SVCFH_fmt(&argp->fh));
535
04716e66 536 nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
1da177e4
LT
537 fh_put(&argp->fh);
538 RETURN_STATUS(nfserr);
539}
540
541/*
542 * Get file system info
543 */
7111c66e 544static __be32
a6beb732 545nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
1da177e4 546{
a6beb732
CH
547 struct nfsd_fhandle *argp = rqstp->rq_argp;
548 struct nfsd3_fsinfores *resp = rqstp->rq_resp;
c4d987ba 549 __be32 nfserr;
7adae489 550 u32 max_blocksize = svc_max_payload(rqstp);
1da177e4
LT
551
552 dprintk("nfsd: FSINFO(3) %s\n",
553 SVCFH_fmt(&argp->fh));
554
7adae489
GB
555 resp->f_rtmax = max_blocksize;
556 resp->f_rtpref = max_blocksize;
1da177e4 557 resp->f_rtmult = PAGE_SIZE;
7adae489
GB
558 resp->f_wtmax = max_blocksize;
559 resp->f_wtpref = max_blocksize;
1da177e4
LT
560 resp->f_wtmult = PAGE_SIZE;
561 resp->f_dtpref = PAGE_SIZE;
562 resp->f_maxfilesize = ~(u32) 0;
563 resp->f_properties = NFS3_FSF_DEFAULT;
564
04716e66
BF
565 nfserr = fh_verify(rqstp, &argp->fh, 0,
566 NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
1da177e4
LT
567
568 /* Check special features of the file system. May request
569 * different read/write sizes for file systems known to have
570 * problems with large blocks */
571 if (nfserr == 0) {
fc64005c 572 struct super_block *sb = argp->fh.fh_dentry->d_sb;
1da177e4
LT
573
574 /* Note that we don't care for remote fs's here */
12214cb7 575 if (sb->s_magic == MSDOS_SUPER_MAGIC) {
1da177e4
LT
576 resp->f_properties = NFS3_FSF_BILLYBOY;
577 }
578 resp->f_maxfilesize = sb->s_maxbytes;
579 }
580
581 fh_put(&argp->fh);
582 RETURN_STATUS(nfserr);
583}
584
585/*
586 * Get pathconf info for the specified file
587 */
7111c66e 588static __be32
a6beb732 589nfsd3_proc_pathconf(struct svc_rqst *rqstp)
1da177e4 590{
a6beb732
CH
591 struct nfsd_fhandle *argp = rqstp->rq_argp;
592 struct nfsd3_pathconfres *resp = rqstp->rq_resp;
c4d987ba 593 __be32 nfserr;
1da177e4
LT
594
595 dprintk("nfsd: PATHCONF(3) %s\n",
596 SVCFH_fmt(&argp->fh));
597
598 /* Set default pathconf */
599 resp->p_link_max = 255; /* at least */
600 resp->p_name_max = 255; /* at least */
601 resp->p_no_trunc = 0;
602 resp->p_chown_restricted = 1;
603 resp->p_case_insensitive = 0;
604 resp->p_case_preserving = 1;
605
8837abca 606 nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
1da177e4
LT
607
608 if (nfserr == 0) {
fc64005c 609 struct super_block *sb = argp->fh.fh_dentry->d_sb;
1da177e4
LT
610
611 /* Note that we don't care for remote fs's here */
612 switch (sb->s_magic) {
613 case EXT2_SUPER_MAGIC:
614 resp->p_link_max = EXT2_LINK_MAX;
615 resp->p_name_max = EXT2_NAME_LEN;
616 break;
12214cb7 617 case MSDOS_SUPER_MAGIC:
1da177e4
LT
618 resp->p_case_insensitive = 1;
619 resp->p_case_preserving = 0;
620 break;
621 }
622 }
623
624 fh_put(&argp->fh);
625 RETURN_STATUS(nfserr);
626}
627
628
629/*
630 * Commit a file (range) to stable storage.
631 */
7111c66e 632static __be32
a6beb732 633nfsd3_proc_commit(struct svc_rqst *rqstp)
1da177e4 634{
a6beb732
CH
635 struct nfsd3_commitargs *argp = rqstp->rq_argp;
636 struct nfsd3_commitres *resp = rqstp->rq_resp;
c4d987ba 637 __be32 nfserr;
1da177e4
LT
638
639 dprintk("nfsd: COMMIT(3) %s %u@%Lu\n",
640 SVCFH_fmt(&argp->fh),
641 argp->count,
642 (unsigned long long) argp->offset);
643
644 if (argp->offset > NFS_OFFSET_MAX)
645 RETURN_STATUS(nfserr_inval);
646
647 fh_copy(&resp->fh, &argp->fh);
648 nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count);
649
650 RETURN_STATUS(nfserr);
651}
652
653
654/*
655 * NFSv3 Server procedures.
656 * Only the results of non-idempotent operations are cached.
657 */
1da177e4
LT
658#define nfs3svc_decode_fhandleargs nfs3svc_decode_fhandle
659#define nfs3svc_encode_attrstatres nfs3svc_encode_attrstat
660#define nfs3svc_encode_wccstatres nfs3svc_encode_wccstat
661#define nfsd3_mkdirargs nfsd3_createargs
662#define nfsd3_readdirplusargs nfsd3_readdirargs
663#define nfsd3_fhandleargs nfsd_fhandle
664#define nfsd3_fhandleres nfsd3_attrstat
665#define nfsd3_attrstatres nfsd3_attrstat
666#define nfsd3_wccstatres nfsd3_attrstat
667#define nfsd3_createres nfsd3_diropres
668#define nfsd3_voidres nfsd3_voidargs
669struct nfsd3_voidargs { int dummy; };
670
1da177e4
LT
671#define ST 1 /* status*/
672#define FH 17 /* filehandle with length */
673#define AT 21 /* attributes */
674#define pAT (1+AT) /* post attributes - conditional */
675#define WC (7+pAT) /* WCC attributes */
676
860bda29 677static const struct svc_procedure nfsd_procedures3[22] = {
b9081d90 678 [NFS3PROC_NULL] = {
a6beb732 679 .pc_func = nfsd3_proc_null,
63f8de37 680 .pc_encode = nfs3svc_encode_voidres,
b9081d90
YZ
681 .pc_argsize = sizeof(struct nfsd3_voidargs),
682 .pc_ressize = sizeof(struct nfsd3_voidres),
683 .pc_cachetype = RC_NOCACHE,
684 .pc_xdrressize = ST,
685 },
686 [NFS3PROC_GETATTR] = {
a6beb732 687 .pc_func = nfsd3_proc_getattr,
026fec7e 688 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 689 .pc_encode = nfs3svc_encode_attrstatres,
8537488b 690 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
691 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
692 .pc_ressize = sizeof(struct nfsd3_attrstatres),
693 .pc_cachetype = RC_NOCACHE,
694 .pc_xdrressize = ST+AT,
695 },
696 [NFS3PROC_SETATTR] = {
a6beb732 697 .pc_func = nfsd3_proc_setattr,
026fec7e 698 .pc_decode = nfs3svc_decode_sattrargs,
63f8de37 699 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 700 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
701 .pc_argsize = sizeof(struct nfsd3_sattrargs),
702 .pc_ressize = sizeof(struct nfsd3_wccstatres),
703 .pc_cachetype = RC_REPLBUFF,
704 .pc_xdrressize = ST+WC,
705 },
706 [NFS3PROC_LOOKUP] = {
a6beb732 707 .pc_func = nfsd3_proc_lookup,
026fec7e 708 .pc_decode = nfs3svc_decode_diropargs,
63f8de37 709 .pc_encode = nfs3svc_encode_diropres,
8537488b 710 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
711 .pc_argsize = sizeof(struct nfsd3_diropargs),
712 .pc_ressize = sizeof(struct nfsd3_diropres),
713 .pc_cachetype = RC_NOCACHE,
714 .pc_xdrressize = ST+FH+pAT+pAT,
715 },
716 [NFS3PROC_ACCESS] = {
a6beb732 717 .pc_func = nfsd3_proc_access,
026fec7e 718 .pc_decode = nfs3svc_decode_accessargs,
63f8de37 719 .pc_encode = nfs3svc_encode_accessres,
8537488b 720 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
721 .pc_argsize = sizeof(struct nfsd3_accessargs),
722 .pc_ressize = sizeof(struct nfsd3_accessres),
723 .pc_cachetype = RC_NOCACHE,
724 .pc_xdrressize = ST+pAT+1,
725 },
726 [NFS3PROC_READLINK] = {
a6beb732 727 .pc_func = nfsd3_proc_readlink,
026fec7e 728 .pc_decode = nfs3svc_decode_readlinkargs,
63f8de37 729 .pc_encode = nfs3svc_encode_readlinkres,
8537488b 730 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
731 .pc_argsize = sizeof(struct nfsd3_readlinkargs),
732 .pc_ressize = sizeof(struct nfsd3_readlinkres),
733 .pc_cachetype = RC_NOCACHE,
734 .pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
735 },
736 [NFS3PROC_READ] = {
a6beb732 737 .pc_func = nfsd3_proc_read,
026fec7e 738 .pc_decode = nfs3svc_decode_readargs,
63f8de37 739 .pc_encode = nfs3svc_encode_readres,
8537488b 740 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
741 .pc_argsize = sizeof(struct nfsd3_readargs),
742 .pc_ressize = sizeof(struct nfsd3_readres),
743 .pc_cachetype = RC_NOCACHE,
744 .pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
745 },
746 [NFS3PROC_WRITE] = {
a6beb732 747 .pc_func = nfsd3_proc_write,
026fec7e 748 .pc_decode = nfs3svc_decode_writeargs,
63f8de37 749 .pc_encode = nfs3svc_encode_writeres,
8537488b 750 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
751 .pc_argsize = sizeof(struct nfsd3_writeargs),
752 .pc_ressize = sizeof(struct nfsd3_writeres),
753 .pc_cachetype = RC_REPLBUFF,
754 .pc_xdrressize = ST+WC+4,
755 },
756 [NFS3PROC_CREATE] = {
a6beb732 757 .pc_func = nfsd3_proc_create,
026fec7e 758 .pc_decode = nfs3svc_decode_createargs,
63f8de37 759 .pc_encode = nfs3svc_encode_createres,
8537488b 760 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
761 .pc_argsize = sizeof(struct nfsd3_createargs),
762 .pc_ressize = sizeof(struct nfsd3_createres),
763 .pc_cachetype = RC_REPLBUFF,
764 .pc_xdrressize = ST+(1+FH+pAT)+WC,
765 },
766 [NFS3PROC_MKDIR] = {
a6beb732 767 .pc_func = nfsd3_proc_mkdir,
026fec7e 768 .pc_decode = nfs3svc_decode_mkdirargs,
63f8de37 769 .pc_encode = nfs3svc_encode_createres,
8537488b 770 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
771 .pc_argsize = sizeof(struct nfsd3_mkdirargs),
772 .pc_ressize = sizeof(struct nfsd3_createres),
773 .pc_cachetype = RC_REPLBUFF,
774 .pc_xdrressize = ST+(1+FH+pAT)+WC,
775 },
776 [NFS3PROC_SYMLINK] = {
a6beb732 777 .pc_func = nfsd3_proc_symlink,
026fec7e 778 .pc_decode = nfs3svc_decode_symlinkargs,
63f8de37 779 .pc_encode = nfs3svc_encode_createres,
8537488b 780 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
781 .pc_argsize = sizeof(struct nfsd3_symlinkargs),
782 .pc_ressize = sizeof(struct nfsd3_createres),
783 .pc_cachetype = RC_REPLBUFF,
784 .pc_xdrressize = ST+(1+FH+pAT)+WC,
785 },
786 [NFS3PROC_MKNOD] = {
a6beb732 787 .pc_func = nfsd3_proc_mknod,
026fec7e 788 .pc_decode = nfs3svc_decode_mknodargs,
63f8de37 789 .pc_encode = nfs3svc_encode_createres,
8537488b 790 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
791 .pc_argsize = sizeof(struct nfsd3_mknodargs),
792 .pc_ressize = sizeof(struct nfsd3_createres),
793 .pc_cachetype = RC_REPLBUFF,
794 .pc_xdrressize = ST+(1+FH+pAT)+WC,
795 },
796 [NFS3PROC_REMOVE] = {
a6beb732 797 .pc_func = nfsd3_proc_remove,
026fec7e 798 .pc_decode = nfs3svc_decode_diropargs,
63f8de37 799 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 800 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
801 .pc_argsize = sizeof(struct nfsd3_diropargs),
802 .pc_ressize = sizeof(struct nfsd3_wccstatres),
803 .pc_cachetype = RC_REPLBUFF,
804 .pc_xdrressize = ST+WC,
805 },
806 [NFS3PROC_RMDIR] = {
a6beb732 807 .pc_func = nfsd3_proc_rmdir,
026fec7e 808 .pc_decode = nfs3svc_decode_diropargs,
63f8de37 809 .pc_encode = nfs3svc_encode_wccstatres,
8537488b 810 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
811 .pc_argsize = sizeof(struct nfsd3_diropargs),
812 .pc_ressize = sizeof(struct nfsd3_wccstatres),
813 .pc_cachetype = RC_REPLBUFF,
814 .pc_xdrressize = ST+WC,
815 },
816 [NFS3PROC_RENAME] = {
a6beb732 817 .pc_func = nfsd3_proc_rename,
026fec7e 818 .pc_decode = nfs3svc_decode_renameargs,
63f8de37 819 .pc_encode = nfs3svc_encode_renameres,
8537488b 820 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
821 .pc_argsize = sizeof(struct nfsd3_renameargs),
822 .pc_ressize = sizeof(struct nfsd3_renameres),
823 .pc_cachetype = RC_REPLBUFF,
824 .pc_xdrressize = ST+WC+WC,
825 },
826 [NFS3PROC_LINK] = {
a6beb732 827 .pc_func = nfsd3_proc_link,
026fec7e 828 .pc_decode = nfs3svc_decode_linkargs,
63f8de37 829 .pc_encode = nfs3svc_encode_linkres,
8537488b 830 .pc_release = nfs3svc_release_fhandle2,
b9081d90
YZ
831 .pc_argsize = sizeof(struct nfsd3_linkargs),
832 .pc_ressize = sizeof(struct nfsd3_linkres),
833 .pc_cachetype = RC_REPLBUFF,
834 .pc_xdrressize = ST+pAT+WC,
835 },
836 [NFS3PROC_READDIR] = {
a6beb732 837 .pc_func = nfsd3_proc_readdir,
026fec7e 838 .pc_decode = nfs3svc_decode_readdirargs,
63f8de37 839 .pc_encode = nfs3svc_encode_readdirres,
8537488b 840 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
841 .pc_argsize = sizeof(struct nfsd3_readdirargs),
842 .pc_ressize = sizeof(struct nfsd3_readdirres),
843 .pc_cachetype = RC_NOCACHE,
844 },
845 [NFS3PROC_READDIRPLUS] = {
a6beb732 846 .pc_func = nfsd3_proc_readdirplus,
026fec7e 847 .pc_decode = nfs3svc_decode_readdirplusargs,
63f8de37 848 .pc_encode = nfs3svc_encode_readdirres,
8537488b 849 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
850 .pc_argsize = sizeof(struct nfsd3_readdirplusargs),
851 .pc_ressize = sizeof(struct nfsd3_readdirres),
852 .pc_cachetype = RC_NOCACHE,
853 },
854 [NFS3PROC_FSSTAT] = {
a6beb732 855 .pc_func = nfsd3_proc_fsstat,
026fec7e 856 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 857 .pc_encode = nfs3svc_encode_fsstatres,
b9081d90
YZ
858 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
859 .pc_ressize = sizeof(struct nfsd3_fsstatres),
860 .pc_cachetype = RC_NOCACHE,
861 .pc_xdrressize = ST+pAT+2*6+1,
862 },
863 [NFS3PROC_FSINFO] = {
a6beb732 864 .pc_func = nfsd3_proc_fsinfo,
026fec7e 865 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 866 .pc_encode = nfs3svc_encode_fsinfores,
b9081d90
YZ
867 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
868 .pc_ressize = sizeof(struct nfsd3_fsinfores),
869 .pc_cachetype = RC_NOCACHE,
870 .pc_xdrressize = ST+pAT+12,
871 },
872 [NFS3PROC_PATHCONF] = {
a6beb732 873 .pc_func = nfsd3_proc_pathconf,
026fec7e 874 .pc_decode = nfs3svc_decode_fhandleargs,
63f8de37 875 .pc_encode = nfs3svc_encode_pathconfres,
b9081d90
YZ
876 .pc_argsize = sizeof(struct nfsd3_fhandleargs),
877 .pc_ressize = sizeof(struct nfsd3_pathconfres),
878 .pc_cachetype = RC_NOCACHE,
879 .pc_xdrressize = ST+pAT+6,
880 },
881 [NFS3PROC_COMMIT] = {
a6beb732 882 .pc_func = nfsd3_proc_commit,
026fec7e 883 .pc_decode = nfs3svc_decode_commitargs,
63f8de37 884 .pc_encode = nfs3svc_encode_commitres,
8537488b 885 .pc_release = nfs3svc_release_fhandle,
b9081d90
YZ
886 .pc_argsize = sizeof(struct nfsd3_commitargs),
887 .pc_ressize = sizeof(struct nfsd3_commitres),
888 .pc_cachetype = RC_NOCACHE,
889 .pc_xdrressize = ST+WC+2,
890 },
1da177e4
LT
891};
892
7fd38af9 893static unsigned int nfsd_count3[ARRAY_SIZE(nfsd_procedures3)];
e9679189
CH
894const struct svc_version nfsd_version3 = {
895 .vs_vers = 3,
896 .vs_nproc = 22,
897 .vs_proc = nfsd_procedures3,
898 .vs_dispatch = nfsd_dispatch,
899 .vs_count = nfsd_count3,
900 .vs_xdrsize = NFS3_SVC_XDRSIZE,
1da177e4 901};