nfs3proc.c 24.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8
/*
 * Process version 3 NFS requests.
 *
 * Copyright (C) 1996, 1997, 1998 Olaf Kirch <okir@monad.swb.de>
 */

#include <linux/fs.h>
#include <linux/ext2_fs.h>
Q
Qinghuang Feng 已提交
9
#include <linux/magic.h>
L
Linus Torvalds 已提交
10

11 12
#include "cache.h"
#include "xdr3.h"
13
#include "vfs.h"
L
Linus Torvalds 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

#define NFSDDBG_FACILITY		NFSDDBG_PROC

#define RETURN_STATUS(st)	{ resp->status = (st); return (st); }

static int	nfs3_ftypes[] = {
	0,			/* NF3NON */
	S_IFREG,		/* NF3REG */
	S_IFDIR,		/* NF3DIR */
	S_IFBLK,		/* NF3BLK */
	S_IFCHR,		/* NF3CHR */
	S_IFLNK,		/* NF3LNK */
	S_IFSOCK,		/* NF3SOCK */
	S_IFIFO,		/* NF3FIFO */
};

/*
 * NULL call.
 */
A
Al Viro 已提交
33
static __be32
34
nfsd3_proc_null(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
35 36 37 38 39 40 41
{
	return nfs_ok;
}

/*
 * Get a file's attributes
 */
A
Al Viro 已提交
42
static __be32
43
nfsd3_proc_getattr(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
44
{
45 46
	struct nfsd_fhandle *argp = rqstp->rq_argp;
	struct nfsd3_attrstat *resp = rqstp->rq_resp;
47
	__be32	nfserr;
L
Linus Torvalds 已提交
48 49

	dprintk("nfsd: GETATTR(3)  %s\n",
50
		SVCFH_fmt(&argp->fh));
L
Linus Torvalds 已提交
51 52

	fh_copy(&resp->fh, &argp->fh);
53 54
	nfserr = fh_verify(rqstp, &resp->fh, 0,
			NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
55 56 57
	if (nfserr)
		RETURN_STATUS(nfserr);

A
Al Viro 已提交
58
	nfserr = fh_getattr(&resp->fh, &resp->stat);
59

L
Linus Torvalds 已提交
60 61 62 63 64 65
	RETURN_STATUS(nfserr);
}

/*
 * Set a file's attributes
 */
A
Al Viro 已提交
66
static __be32
67
nfsd3_proc_setattr(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
68
{
69 70
	struct nfsd3_sattrargs *argp = rqstp->rq_argp;
	struct nfsd3_attrstat *resp = rqstp->rq_resp;
71
	__be32	nfserr;
L
Linus Torvalds 已提交
72 73 74 75 76 77 78 79 80 81 82 83 84

	dprintk("nfsd: SETATTR(3)  %s\n",
				SVCFH_fmt(&argp->fh));

	fh_copy(&resp->fh, &argp->fh);
	nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,
			      argp->check_guard, argp->guardtime);
	RETURN_STATUS(nfserr);
}

/*
 * Look up a path name component
 */
A
Al Viro 已提交
85
static __be32
86
nfsd3_proc_lookup(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
87
{
88 89
	struct nfsd3_diropargs *argp = rqstp->rq_argp;
	struct nfsd3_diropres  *resp = rqstp->rq_resp;
90
	__be32	nfserr;
L
Linus Torvalds 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

	dprintk("nfsd: LOOKUP(3)   %s %.*s\n",
				SVCFH_fmt(&argp->fh),
				argp->len,
				argp->name);

	fh_copy(&resp->dirfh, &argp->fh);
	fh_init(&resp->fh, NFS3_FHSIZE);

	nfserr = nfsd_lookup(rqstp, &resp->dirfh,
				    argp->name,
				    argp->len,
				    &resp->fh);
	RETURN_STATUS(nfserr);
}

/*
 * Check file access
 */
A
Al Viro 已提交
110
static __be32
111
nfsd3_proc_access(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
112
{
113 114
	struct nfsd3_accessargs *argp = rqstp->rq_argp;
	struct nfsd3_accessres *resp = rqstp->rq_resp;
115
	__be32	nfserr;
L
Linus Torvalds 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129

	dprintk("nfsd: ACCESS(3)   %s 0x%x\n",
				SVCFH_fmt(&argp->fh),
				argp->access);

	fh_copy(&resp->fh, &argp->fh);
	resp->access = argp->access;
	nfserr = nfsd_access(rqstp, &resp->fh, &resp->access, NULL);
	RETURN_STATUS(nfserr);
}

/*
 * Read a symlink.
 */
A
Al Viro 已提交
130
static __be32
131
nfsd3_proc_readlink(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
132
{
133 134
	struct nfsd3_readlinkargs *argp = rqstp->rq_argp;
	struct nfsd3_readlinkres *resp = rqstp->rq_resp;
135
	__be32 nfserr;
L
Linus Torvalds 已提交
136 137 138 139 140 141 142 143 144 145 146 147 148

	dprintk("nfsd: READLINK(3) %s\n", SVCFH_fmt(&argp->fh));

	/* Read the symlink. */
	fh_copy(&resp->fh, &argp->fh);
	resp->len = NFS3_MAXPATHLEN;
	nfserr = nfsd_readlink(rqstp, &resp->fh, argp->buffer, &resp->len);
	RETURN_STATUS(nfserr);
}

/*
 * Read a portion of a file.
 */
A
Al Viro 已提交
149
static __be32
150
nfsd3_proc_read(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
151
{
152 153
	struct nfsd3_readargs *argp = rqstp->rq_argp;
	struct nfsd3_readres *resp = rqstp->rq_resp;
154
	__be32	nfserr;
155
	u32	max_blocksize = svc_max_payload(rqstp);
156
	unsigned long cnt = min(argp->count, max_blocksize);
L
Linus Torvalds 已提交
157

158
	dprintk("nfsd: READ(3) %s %lu bytes at %Lu\n",
L
Linus Torvalds 已提交
159 160
				SVCFH_fmt(&argp->fh),
				(unsigned long) argp->count,
161
				(unsigned long long) argp->offset);
L
Linus Torvalds 已提交
162 163 164 165 166

	/* Obtain buffer pointer for payload.
	 * 1 (status) + 22 (post_op_attr) + 1 (count) + 1 (eof)
	 * + 1 (xdr opaque byte count) = 26
	 */
167
	resp->count = cnt;
168
	svc_reserve_auth(rqstp, ((1 + NFS3_POST_OP_ATTR_WORDS + 3)<<2) + resp->count +4);
L
Linus Torvalds 已提交
169 170

	fh_copy(&resp->fh, &argp->fh);
171
	nfserr = nfsd_read(rqstp, &resp->fh,
L
Linus Torvalds 已提交
172
				  argp->offset,
173
			   	  rqstp->rq_vec, argp->vlen,
L
Linus Torvalds 已提交
174 175
				  &resp->count);
	if (nfserr == 0) {
176
		struct inode	*inode = d_inode(resp->fh.fh_dentry);
177 178
		resp->eof = nfsd_eof_on_read(cnt, resp->count, argp->offset,
							inode->i_size);
L
Linus Torvalds 已提交
179 180 181 182 183 184 185 186
	}

	RETURN_STATUS(nfserr);
}

/*
 * Write data to a file
 */
A
Al Viro 已提交
187
static __be32
188
nfsd3_proc_write(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
189
{
190 191
	struct nfsd3_writeargs *argp = rqstp->rq_argp;
	struct nfsd3_writeres *resp = rqstp->rq_resp;
192
	__be32	nfserr;
193
	unsigned long cnt = argp->len;
L
Linus Torvalds 已提交
194

195
	dprintk("nfsd: WRITE(3)    %s %d bytes at %Lu%s\n",
L
Linus Torvalds 已提交
196 197
				SVCFH_fmt(&argp->fh),
				argp->len,
198
				(unsigned long long) argp->offset,
L
Linus Torvalds 已提交
199 200 201 202
				argp->stable? " stable" : "");

	fh_copy(&resp->fh, &argp->fh);
	resp->committed = argp->stable;
203 204 205
	nfserr = nfsd_write(rqstp, &resp->fh, argp->offset,
				rqstp->rq_vec, argp->vlen,
				&cnt, resp->committed);
206
	resp->count = cnt;
L
Linus Torvalds 已提交
207 208 209 210 211 212 213 214
	RETURN_STATUS(nfserr);
}

/*
 * With NFSv3, CREATE processing is a lot easier than with NFSv2.
 * At least in theory; we'll see how it fares in practice when the
 * first reports about SunOS compatibility problems start to pour in...
 */
A
Al Viro 已提交
215
static __be32
216
nfsd3_proc_create(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
217
{
218 219
	struct nfsd3_createargs *argp = rqstp->rq_argp;
	struct nfsd3_diropres *resp = rqstp->rq_resp;
L
Linus Torvalds 已提交
220 221
	svc_fh		*dirfhp, *newfhp = NULL;
	struct iattr	*attr;
222
	__be32		nfserr;
L
Linus Torvalds 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242

	dprintk("nfsd: CREATE(3)   %s %.*s\n",
				SVCFH_fmt(&argp->fh),
				argp->len,
				argp->name);

	dirfhp = fh_copy(&resp->dirfh, &argp->fh);
	newfhp = fh_init(&resp->fh, NFS3_FHSIZE);
	attr   = &argp->attrs;

	/* Unfudge the mode bits */
	attr->ia_mode &= ~S_IFMT;
	if (!(attr->ia_valid & ATTR_MODE)) { 
		attr->ia_valid |= ATTR_MODE;
		attr->ia_mode = S_IFREG;
	} else {
		attr->ia_mode = (attr->ia_mode & ~S_IFMT) | S_IFREG;
	}

	/* Now create the file and set attributes */
243
	nfserr = do_nfsd_create(rqstp, dirfhp, argp->name, argp->len,
L
Linus Torvalds 已提交
244
				attr, newfhp,
245
				argp->createmode, (u32 *)argp->verf, NULL, NULL);
L
Linus Torvalds 已提交
246 247 248 249 250 251 252

	RETURN_STATUS(nfserr);
}

/*
 * Make directory. This operation is not idempotent.
 */
A
Al Viro 已提交
253
static __be32
254
nfsd3_proc_mkdir(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
255
{
256 257
	struct nfsd3_createargs *argp = rqstp->rq_argp;
	struct nfsd3_diropres *resp = rqstp->rq_resp;
258
	__be32	nfserr;
L
Linus Torvalds 已提交
259 260 261 262 263 264 265 266 267 268 269

	dprintk("nfsd: MKDIR(3)    %s %.*s\n",
				SVCFH_fmt(&argp->fh),
				argp->len,
				argp->name);

	argp->attrs.ia_valid &= ~ATTR_SIZE;
	fh_copy(&resp->dirfh, &argp->fh);
	fh_init(&resp->fh, NFS3_FHSIZE);
	nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
				    &argp->attrs, S_IFDIR, 0, &resp->fh);
270
	fh_unlock(&resp->dirfh);
L
Linus Torvalds 已提交
271 272 273
	RETURN_STATUS(nfserr);
}

A
Al Viro 已提交
274
static __be32
275
nfsd3_proc_symlink(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
276
{
277 278
	struct nfsd3_symlinkargs *argp = rqstp->rq_argp;
	struct nfsd3_diropres *resp = rqstp->rq_resp;
279
	__be32	nfserr;
L
Linus Torvalds 已提交
280 281 282 283 284 285 286 287 288

	dprintk("nfsd: SYMLINK(3)  %s %.*s -> %.*s\n",
				SVCFH_fmt(&argp->ffh),
				argp->flen, argp->fname,
				argp->tlen, argp->tname);

	fh_copy(&resp->dirfh, &argp->ffh);
	fh_init(&resp->fh, NFS3_FHSIZE);
	nfserr = nfsd_symlink(rqstp, &resp->dirfh, argp->fname, argp->flen,
289
						   argp->tname, &resp->fh);
L
Linus Torvalds 已提交
290 291 292 293 294 295
	RETURN_STATUS(nfserr);
}

/*
 * Make socket/fifo/device.
 */
A
Al Viro 已提交
296
static __be32
297
nfsd3_proc_mknod(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
298
{
299 300
	struct nfsd3_mknodargs *argp = rqstp->rq_argp;
	struct nfsd3_diropres  *resp = rqstp->rq_resp;
301 302
	__be32	nfserr;
	int type;
L
Linus Torvalds 已提交
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
	dev_t	rdev = 0;

	dprintk("nfsd: MKNOD(3)    %s %.*s\n",
				SVCFH_fmt(&argp->fh),
				argp->len,
				argp->name);

	fh_copy(&resp->dirfh, &argp->fh);
	fh_init(&resp->fh, NFS3_FHSIZE);

	if (argp->ftype == 0 || argp->ftype >= NF3BAD)
		RETURN_STATUS(nfserr_inval);
	if (argp->ftype == NF3CHR || argp->ftype == NF3BLK) {
		rdev = MKDEV(argp->major, argp->minor);
		if (MAJOR(rdev) != argp->major ||
		    MINOR(rdev) != argp->minor)
			RETURN_STATUS(nfserr_inval);
	} else
		if (argp->ftype != NF3SOCK && argp->ftype != NF3FIFO)
			RETURN_STATUS(nfserr_inval);

	type = nfs3_ftypes[argp->ftype];
	nfserr = nfsd_create(rqstp, &resp->dirfh, argp->name, argp->len,
				    &argp->attrs, type, rdev, &resp->fh);
327
	fh_unlock(&resp->dirfh);
L
Linus Torvalds 已提交
328 329 330 331 332 333
	RETURN_STATUS(nfserr);
}

/*
 * Remove file/fifo/socket etc.
 */
A
Al Viro 已提交
334
static __be32
335
nfsd3_proc_remove(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
336
{
337 338
	struct nfsd3_diropargs *argp = rqstp->rq_argp;
	struct nfsd3_attrstat *resp = rqstp->rq_resp;
339
	__be32	nfserr;
L
Linus Torvalds 已提交
340 341 342 343 344 345 346 347 348

	dprintk("nfsd: REMOVE(3)   %s %.*s\n",
				SVCFH_fmt(&argp->fh),
				argp->len,
				argp->name);

	/* Unlink. -S_IFDIR means file must not be a directory */
	fh_copy(&resp->fh, &argp->fh);
	nfserr = nfsd_unlink(rqstp, &resp->fh, -S_IFDIR, argp->name, argp->len);
349
	fh_unlock(&resp->fh);
L
Linus Torvalds 已提交
350 351 352 353 354 355
	RETURN_STATUS(nfserr);
}

/*
 * Remove a directory
 */
A
Al Viro 已提交
356
static __be32
357
nfsd3_proc_rmdir(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
358
{
359 360
	struct nfsd3_diropargs *argp = rqstp->rq_argp;
	struct nfsd3_attrstat *resp = rqstp->rq_resp;
361
	__be32	nfserr;
L
Linus Torvalds 已提交
362 363 364 365 366 367 368 369

	dprintk("nfsd: RMDIR(3)    %s %.*s\n",
				SVCFH_fmt(&argp->fh),
				argp->len,
				argp->name);

	fh_copy(&resp->fh, &argp->fh);
	nfserr = nfsd_unlink(rqstp, &resp->fh, S_IFDIR, argp->name, argp->len);
370
	fh_unlock(&resp->fh);
L
Linus Torvalds 已提交
371 372 373
	RETURN_STATUS(nfserr);
}

A
Al Viro 已提交
374
static __be32
375
nfsd3_proc_rename(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
376
{
377 378
	struct nfsd3_renameargs *argp = rqstp->rq_argp;
	struct nfsd3_renameres *resp = rqstp->rq_resp;
379
	__be32	nfserr;
L
Linus Torvalds 已提交
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396

	dprintk("nfsd: RENAME(3)   %s %.*s ->\n",
				SVCFH_fmt(&argp->ffh),
				argp->flen,
				argp->fname);
	dprintk("nfsd: -> %s %.*s\n",
				SVCFH_fmt(&argp->tfh),
				argp->tlen,
				argp->tname);

	fh_copy(&resp->ffh, &argp->ffh);
	fh_copy(&resp->tfh, &argp->tfh);
	nfserr = nfsd_rename(rqstp, &resp->ffh, argp->fname, argp->flen,
				    &resp->tfh, argp->tname, argp->tlen);
	RETURN_STATUS(nfserr);
}

A
Al Viro 已提交
397
static __be32
398
nfsd3_proc_link(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
399
{
400 401
	struct nfsd3_linkargs *argp = rqstp->rq_argp;
	struct nfsd3_linkres  *resp = rqstp->rq_resp;
402
	__be32	nfserr;
L
Linus Torvalds 已提交
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420

	dprintk("nfsd: LINK(3)     %s ->\n",
				SVCFH_fmt(&argp->ffh));
	dprintk("nfsd:   -> %s %.*s\n",
				SVCFH_fmt(&argp->tfh),
				argp->tlen,
				argp->tname);

	fh_copy(&resp->fh,  &argp->ffh);
	fh_copy(&resp->tfh, &argp->tfh);
	nfserr = nfsd_link(rqstp, &resp->tfh, argp->tname, argp->tlen,
				  &resp->fh);
	RETURN_STATUS(nfserr);
}

/*
 * Read a portion of a directory.
 */
A
Al Viro 已提交
421
static __be32
422
nfsd3_proc_readdir(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
423
{
424 425
	struct nfsd3_readdirargs *argp = rqstp->rq_argp;
	struct nfsd3_readdirres  *resp = rqstp->rq_resp;
426 427
	__be32		nfserr;
	int		count;
L
Linus Torvalds 已提交
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457

	dprintk("nfsd: READDIR(3)  %s %d bytes at %d\n",
				SVCFH_fmt(&argp->fh),
				argp->count, (u32) argp->cookie);

	/* Make sure we've room for the NULL ptr & eof flag, and shrink to
	 * client read size */
	count = (argp->count >> 2) - 2;

	/* Read directory and encode entries on the fly */
	fh_copy(&resp->fh, &argp->fh);

	resp->buflen = count;
	resp->common.err = nfs_ok;
	resp->buffer = argp->buffer;
	resp->rqstp = rqstp;
	nfserr = nfsd_readdir(rqstp, &resp->fh, (loff_t*) &argp->cookie, 
					&resp->common, nfs3svc_encode_entry);
	memcpy(resp->verf, argp->verf, 8);
	resp->count = resp->buffer - argp->buffer;
	if (resp->offset)
		xdr_encode_hyper(resp->offset, argp->cookie);

	RETURN_STATUS(nfserr);
}

/*
 * Read a portion of a directory, including file handles and attrs.
 * For now, we choose to ignore the dircount parameter.
 */
A
Al Viro 已提交
458
static __be32
459
nfsd3_proc_readdirplus(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
460
{
461 462
	struct nfsd3_readdirargs *argp = rqstp->rq_argp;
	struct nfsd3_readdirres  *resp = rqstp->rq_resp;
463 464
	__be32	nfserr;
	int	count = 0;
L
Linus Torvalds 已提交
465
	loff_t	offset;
466
	struct page **p;
L
Linus Torvalds 已提交
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
	caddr_t	page_addr = NULL;

	dprintk("nfsd: READDIR+(3) %s %d bytes at %d\n",
				SVCFH_fmt(&argp->fh),
				argp->count, (u32) argp->cookie);

	/* Convert byte count to number of words (i.e. >> 2),
	 * and reserve room for the NULL ptr & eof flag (-2 words) */
	resp->count = (argp->count >> 2) - 2;

	/* Read directory and encode entries on the fly */
	fh_copy(&resp->fh, &argp->fh);

	resp->common.err = nfs_ok;
	resp->buffer = argp->buffer;
	resp->buflen = resp->count;
	resp->rqstp = rqstp;
	offset = argp->cookie;
485 486 487 488 489 490 491 492

	nfserr = fh_verify(rqstp, &resp->fh, S_IFDIR, NFSD_MAY_NOP);
	if (nfserr)
		RETURN_STATUS(nfserr);

	if (resp->fh.fh_export->ex_flags & NFSEXP_NOREADDIRPLUS)
		RETURN_STATUS(nfserr_notsupp);

L
Linus Torvalds 已提交
493 494 495 496 497
	nfserr = nfsd_readdir(rqstp, &resp->fh,
				     &offset,
				     &resp->common,
				     nfs3svc_encode_entry_plus);
	memcpy(resp->verf, argp->verf, 8);
498 499
	for (p = rqstp->rq_respages + 1; p < rqstp->rq_next_page; p++) {
		page_addr = page_address(*p);
L
Linus Torvalds 已提交
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525

		if (((caddr_t)resp->buffer >= page_addr) &&
		    ((caddr_t)resp->buffer < page_addr + PAGE_SIZE)) {
			count += (caddr_t)resp->buffer - page_addr;
			break;
		}
		count += PAGE_SIZE;
	}
	resp->count = count >> 2;
	if (resp->offset) {
		if (unlikely(resp->offset1)) {
			/* we ended up with offset on a page boundary */
			*resp->offset = htonl(offset >> 32);
			*resp->offset1 = htonl(offset & 0xffffffff);
			resp->offset1 = NULL;
		} else {
			xdr_encode_hyper(resp->offset, offset);
		}
	}

	RETURN_STATUS(nfserr);
}

/*
 * Get file system stats
 */
A
Al Viro 已提交
526
static __be32
527
nfsd3_proc_fsstat(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
528
{
529 530
	struct nfsd_fhandle *argp = rqstp->rq_argp;
	struct nfsd3_fsstatres *resp = rqstp->rq_resp;
531
	__be32	nfserr;
L
Linus Torvalds 已提交
532 533 534 535

	dprintk("nfsd: FSSTAT(3)   %s\n",
				SVCFH_fmt(&argp->fh));

536
	nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
L
Linus Torvalds 已提交
537 538 539 540 541 542 543
	fh_put(&argp->fh);
	RETURN_STATUS(nfserr);
}

/*
 * Get file system info
 */
A
Al Viro 已提交
544
static __be32
545
nfsd3_proc_fsinfo(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
546
{
547 548
	struct nfsd_fhandle *argp = rqstp->rq_argp;
	struct nfsd3_fsinfores *resp = rqstp->rq_resp;
549
	__be32	nfserr;
550
	u32	max_blocksize = svc_max_payload(rqstp);
L
Linus Torvalds 已提交
551 552 553 554

	dprintk("nfsd: FSINFO(3)   %s\n",
				SVCFH_fmt(&argp->fh));

555 556
	resp->f_rtmax  = max_blocksize;
	resp->f_rtpref = max_blocksize;
L
Linus Torvalds 已提交
557
	resp->f_rtmult = PAGE_SIZE;
558 559
	resp->f_wtmax  = max_blocksize;
	resp->f_wtpref = max_blocksize;
L
Linus Torvalds 已提交
560 561 562 563 564
	resp->f_wtmult = PAGE_SIZE;
	resp->f_dtpref = PAGE_SIZE;
	resp->f_maxfilesize = ~(u32) 0;
	resp->f_properties = NFS3_FSF_DEFAULT;

565 566
	nfserr = fh_verify(rqstp, &argp->fh, 0,
			NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
L
Linus Torvalds 已提交
567 568 569 570 571

	/* Check special features of the file system. May request
	 * different read/write sizes for file systems known to have
	 * problems with large blocks */
	if (nfserr == 0) {
572
		struct super_block *sb = argp->fh.fh_dentry->d_sb;
L
Linus Torvalds 已提交
573 574

		/* Note that we don't care for remote fs's here */
Q
Qinghuang Feng 已提交
575
		if (sb->s_magic == MSDOS_SUPER_MAGIC) {
L
Linus Torvalds 已提交
576 577 578 579 580 581 582 583 584 585 586 587
			resp->f_properties = NFS3_FSF_BILLYBOY;
		}
		resp->f_maxfilesize = sb->s_maxbytes;
	}

	fh_put(&argp->fh);
	RETURN_STATUS(nfserr);
}

/*
 * Get pathconf info for the specified file
 */
A
Al Viro 已提交
588
static __be32
589
nfsd3_proc_pathconf(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
590
{
591 592
	struct nfsd_fhandle *argp = rqstp->rq_argp;
	struct nfsd3_pathconfres *resp = rqstp->rq_resp;
593
	__be32	nfserr;
L
Linus Torvalds 已提交
594 595 596 597 598 599 600 601 602 603 604 605

	dprintk("nfsd: PATHCONF(3) %s\n",
				SVCFH_fmt(&argp->fh));

	/* Set default pathconf */
	resp->p_link_max = 255;		/* at least */
	resp->p_name_max = 255;		/* at least */
	resp->p_no_trunc = 0;
	resp->p_chown_restricted = 1;
	resp->p_case_insensitive = 0;
	resp->p_case_preserving = 1;

M
Miklos Szeredi 已提交
606
	nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
L
Linus Torvalds 已提交
607 608

	if (nfserr == 0) {
609
		struct super_block *sb = argp->fh.fh_dentry->d_sb;
L
Linus Torvalds 已提交
610 611 612 613 614 615 616

		/* Note that we don't care for remote fs's here */
		switch (sb->s_magic) {
		case EXT2_SUPER_MAGIC:
			resp->p_link_max = EXT2_LINK_MAX;
			resp->p_name_max = EXT2_NAME_LEN;
			break;
Q
Qinghuang Feng 已提交
617
		case MSDOS_SUPER_MAGIC:
L
Linus Torvalds 已提交
618 619 620 621 622 623 624 625 626 627 628 629 630 631
			resp->p_case_insensitive = 1;
			resp->p_case_preserving  = 0;
			break;
		}
	}

	fh_put(&argp->fh);
	RETURN_STATUS(nfserr);
}


/*
 * Commit a file (range) to stable storage.
 */
A
Al Viro 已提交
632
static __be32
633
nfsd3_proc_commit(struct svc_rqst *rqstp)
L
Linus Torvalds 已提交
634
{
635 636
	struct nfsd3_commitargs *argp = rqstp->rq_argp;
	struct nfsd3_commitres *resp = rqstp->rq_resp;
637
	__be32	nfserr;
L
Linus Torvalds 已提交
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677

	dprintk("nfsd: COMMIT(3)   %s %u@%Lu\n",
				SVCFH_fmt(&argp->fh),
				argp->count,
				(unsigned long long) argp->offset);

	if (argp->offset > NFS_OFFSET_MAX)
		RETURN_STATUS(nfserr_inval);

	fh_copy(&resp->fh, &argp->fh);
	nfserr = nfsd_commit(rqstp, &resp->fh, argp->offset, argp->count);

	RETURN_STATUS(nfserr);
}


/*
 * NFSv3 Server procedures.
 * Only the results of non-idempotent operations are cached.
 */
#define nfs3svc_decode_fhandleargs	nfs3svc_decode_fhandle
#define nfs3svc_encode_attrstatres	nfs3svc_encode_attrstat
#define nfs3svc_encode_wccstatres	nfs3svc_encode_wccstat
#define nfsd3_mkdirargs			nfsd3_createargs
#define nfsd3_readdirplusargs		nfsd3_readdirargs
#define nfsd3_fhandleargs		nfsd_fhandle
#define nfsd3_fhandleres		nfsd3_attrstat
#define nfsd3_attrstatres		nfsd3_attrstat
#define nfsd3_wccstatres		nfsd3_attrstat
#define nfsd3_createres			nfsd3_diropres
#define nfsd3_voidres			nfsd3_voidargs
struct nfsd3_voidargs { int dummy; };

#define ST 1		/* status*/
#define FH 17		/* filehandle with length */
#define AT 21		/* attributes */
#define pAT (1+AT)	/* post attributes - conditional */
#define WC (7+pAT)	/* WCC attributes */

static struct svc_procedure		nfsd_procedures3[22] = {
678
	[NFS3PROC_NULL] = {
679
		.pc_func = nfsd3_proc_null,
680 681 682 683 684 685 686
		.pc_encode = (kxdrproc_t) nfs3svc_encode_voidres,
		.pc_argsize = sizeof(struct nfsd3_voidargs),
		.pc_ressize = sizeof(struct nfsd3_voidres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST,
	},
	[NFS3PROC_GETATTR] = {
687
		.pc_func = nfsd3_proc_getattr,
688 689 690 691 692 693 694 695 696
		.pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_attrstatres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_fhandleargs),
		.pc_ressize = sizeof(struct nfsd3_attrstatres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+AT,
	},
	[NFS3PROC_SETATTR] = {
697
		.pc_func = nfsd3_proc_setattr,
698 699 700 701 702 703 704 705 706
		.pc_decode = (kxdrproc_t) nfs3svc_decode_sattrargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_wccstatres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_sattrargs),
		.pc_ressize = sizeof(struct nfsd3_wccstatres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+WC,
	},
	[NFS3PROC_LOOKUP] = {
707
		.pc_func = nfsd3_proc_lookup,
708 709 710 711 712 713 714 715 716
		.pc_decode = (kxdrproc_t) nfs3svc_decode_diropargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_diropres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
		.pc_argsize = sizeof(struct nfsd3_diropargs),
		.pc_ressize = sizeof(struct nfsd3_diropres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+FH+pAT+pAT,
	},
	[NFS3PROC_ACCESS] = {
717
		.pc_func = nfsd3_proc_access,
718 719 720 721 722 723 724 725 726
		.pc_decode = (kxdrproc_t) nfs3svc_decode_accessargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_accessres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_accessargs),
		.pc_ressize = sizeof(struct nfsd3_accessres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+pAT+1,
	},
	[NFS3PROC_READLINK] = {
727
		.pc_func = nfsd3_proc_readlink,
728 729 730 731 732 733 734 735 736
		.pc_decode = (kxdrproc_t) nfs3svc_decode_readlinkargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_readlinkres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_readlinkargs),
		.pc_ressize = sizeof(struct nfsd3_readlinkres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+pAT+1+NFS3_MAXPATHLEN/4,
	},
	[NFS3PROC_READ] = {
737
		.pc_func = nfsd3_proc_read,
738 739 740 741 742 743 744 745 746
		.pc_decode = (kxdrproc_t) nfs3svc_decode_readargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_readres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_readargs),
		.pc_ressize = sizeof(struct nfsd3_readres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+pAT+4+NFSSVC_MAXBLKSIZE/4,
	},
	[NFS3PROC_WRITE] = {
747
		.pc_func = nfsd3_proc_write,
748 749 750 751 752 753 754 755 756
		.pc_decode = (kxdrproc_t) nfs3svc_decode_writeargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_writeres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_writeargs),
		.pc_ressize = sizeof(struct nfsd3_writeres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+WC+4,
	},
	[NFS3PROC_CREATE] = {
757
		.pc_func = nfsd3_proc_create,
758 759 760 761 762 763 764 765 766
		.pc_decode = (kxdrproc_t) nfs3svc_decode_createargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
		.pc_argsize = sizeof(struct nfsd3_createargs),
		.pc_ressize = sizeof(struct nfsd3_createres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+(1+FH+pAT)+WC,
	},
	[NFS3PROC_MKDIR] = {
767
		.pc_func = nfsd3_proc_mkdir,
768 769 770 771 772 773 774 775 776
		.pc_decode = (kxdrproc_t) nfs3svc_decode_mkdirargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
		.pc_argsize = sizeof(struct nfsd3_mkdirargs),
		.pc_ressize = sizeof(struct nfsd3_createres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+(1+FH+pAT)+WC,
	},
	[NFS3PROC_SYMLINK] = {
777
		.pc_func = nfsd3_proc_symlink,
778 779 780 781 782 783 784 785 786
		.pc_decode = (kxdrproc_t) nfs3svc_decode_symlinkargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
		.pc_argsize = sizeof(struct nfsd3_symlinkargs),
		.pc_ressize = sizeof(struct nfsd3_createres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+(1+FH+pAT)+WC,
	},
	[NFS3PROC_MKNOD] = {
787
		.pc_func = nfsd3_proc_mknod,
788 789 790 791 792 793 794 795 796
		.pc_decode = (kxdrproc_t) nfs3svc_decode_mknodargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_createres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
		.pc_argsize = sizeof(struct nfsd3_mknodargs),
		.pc_ressize = sizeof(struct nfsd3_createres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+(1+FH+pAT)+WC,
	},
	[NFS3PROC_REMOVE] = {
797
		.pc_func = nfsd3_proc_remove,
798 799 800 801 802 803 804 805 806
		.pc_decode = (kxdrproc_t) nfs3svc_decode_diropargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_wccstatres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_diropargs),
		.pc_ressize = sizeof(struct nfsd3_wccstatres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+WC,
	},
	[NFS3PROC_RMDIR] = {
807
		.pc_func = nfsd3_proc_rmdir,
808 809 810 811 812 813 814 815 816
		.pc_decode = (kxdrproc_t) nfs3svc_decode_diropargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_wccstatres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_diropargs),
		.pc_ressize = sizeof(struct nfsd3_wccstatres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+WC,
	},
	[NFS3PROC_RENAME] = {
817
		.pc_func = nfsd3_proc_rename,
818 819 820 821 822 823 824 825 826
		.pc_decode = (kxdrproc_t) nfs3svc_decode_renameargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_renameres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
		.pc_argsize = sizeof(struct nfsd3_renameargs),
		.pc_ressize = sizeof(struct nfsd3_renameres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+WC+WC,
	},
	[NFS3PROC_LINK] = {
827
		.pc_func = nfsd3_proc_link,
828 829 830 831 832 833 834 835 836
		.pc_decode = (kxdrproc_t) nfs3svc_decode_linkargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_linkres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle2,
		.pc_argsize = sizeof(struct nfsd3_linkargs),
		.pc_ressize = sizeof(struct nfsd3_linkres),
		.pc_cachetype = RC_REPLBUFF,
		.pc_xdrressize = ST+pAT+WC,
	},
	[NFS3PROC_READDIR] = {
837
		.pc_func = nfsd3_proc_readdir,
838 839 840 841 842 843 844 845
		.pc_decode = (kxdrproc_t) nfs3svc_decode_readdirargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_readdirres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_readdirargs),
		.pc_ressize = sizeof(struct nfsd3_readdirres),
		.pc_cachetype = RC_NOCACHE,
	},
	[NFS3PROC_READDIRPLUS] = {
846
		.pc_func = nfsd3_proc_readdirplus,
847 848 849 850 851 852 853 854
		.pc_decode = (kxdrproc_t) nfs3svc_decode_readdirplusargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_readdirres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_readdirplusargs),
		.pc_ressize = sizeof(struct nfsd3_readdirres),
		.pc_cachetype = RC_NOCACHE,
	},
	[NFS3PROC_FSSTAT] = {
855
		.pc_func = nfsd3_proc_fsstat,
856 857 858 859 860 861 862 863
		.pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_fsstatres,
		.pc_argsize = sizeof(struct nfsd3_fhandleargs),
		.pc_ressize = sizeof(struct nfsd3_fsstatres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+pAT+2*6+1,
	},
	[NFS3PROC_FSINFO] = {
864
		.pc_func = nfsd3_proc_fsinfo,
865 866 867 868 869 870 871 872
		.pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_fsinfores,
		.pc_argsize = sizeof(struct nfsd3_fhandleargs),
		.pc_ressize = sizeof(struct nfsd3_fsinfores),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+pAT+12,
	},
	[NFS3PROC_PATHCONF] = {
873
		.pc_func = nfsd3_proc_pathconf,
874 875 876 877 878 879 880 881
		.pc_decode = (kxdrproc_t) nfs3svc_decode_fhandleargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_pathconfres,
		.pc_argsize = sizeof(struct nfsd3_fhandleargs),
		.pc_ressize = sizeof(struct nfsd3_pathconfres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+pAT+6,
	},
	[NFS3PROC_COMMIT] = {
882
		.pc_func = nfsd3_proc_commit,
883 884 885 886 887 888 889 890
		.pc_decode = (kxdrproc_t) nfs3svc_decode_commitargs,
		.pc_encode = (kxdrproc_t) nfs3svc_encode_commitres,
		.pc_release = (kxdrproc_t) nfs3svc_release_fhandle,
		.pc_argsize = sizeof(struct nfsd3_commitargs),
		.pc_ressize = sizeof(struct nfsd3_commitres),
		.pc_cachetype = RC_NOCACHE,
		.pc_xdrressize = ST+WC+2,
	},
L
Linus Torvalds 已提交
891 892 893 894 895 896 897 898 899
};

struct svc_version	nfsd_version3 = {
		.vs_vers	= 3,
		.vs_nproc	= 22,
		.vs_proc	= nfsd_procedures3,
		.vs_dispatch	= nfsd_dispatch,
		.vs_xdrsize	= NFS3_SVC_XDRSIZE,
};