Merge with Linux 2.5.74.
[linux-2.6/linux-mips.git] / fs / nfsd / nfs4proc.c
blob5a7effdb8e657c65f93e0f69fac0c9f146ee1cd5
1 /*
2 * fs/nfsd/nfs4proc.c
4 * Server-side procedures for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 * Note: some routines in this file are just trivial wrappers
38 * (e.g. nfsd4_lookup()) defined solely for the sake of consistent
39 * naming. Since all such routines have been declared "inline",
40 * there shouldn't be any associated overhead. At some point in
41 * the future, I might inline these "by hand" to clean up a
42 * little.
45 #include <linux/param.h>
46 #include <linux/major.h>
47 #include <linux/slab.h>
49 #include <linux/sunrpc/svc.h>
50 #include <linux/nfsd/nfsd.h>
51 #include <linux/nfsd/cache.h>
52 #include <linux/nfs4.h>
53 #include <linux/nfsd/state.h>
54 #include <linux/nfsd/xdr4.h>
56 #define NFSDDBG_FACILITY NFSDDBG_PROC
58 /* Note: The organization of the OPEN code seems a little strange; it
59 * has been superfluously split into three routines, one of which is named
60 * nfsd4_process_open2() even though there is no nfsd4_process_open1()!
61 * This is because the code has been organized in anticipation of a
62 * subsequent patch which will implement more of the NFSv4 state model.
64 static int
65 do_open_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
67 struct svc_fh resfh;
68 int accmode, status;
70 fh_init(&resfh, NFS4_FHSIZE);
71 open->op_truncate = 0;
73 if (open->op_create) {
75 * Note: create modes (UNCHECKED,GUARDED...) are the same
76 * in NFSv4 as in v3.
78 status = nfsd_create_v3(rqstp, current_fh, open->op_fname.data,
79 open->op_fname.len, &open->op_iattr,
80 &resfh, open->op_createmode,
81 (u32 *)open->op_verf, &open->op_truncate);
83 else {
84 status = nfsd_lookup(rqstp, current_fh,
85 open->op_fname.data, open->op_fname.len, &resfh);
86 fh_unlock(current_fh);
89 if (!status) {
90 set_change_info(&open->op_cinfo, current_fh);
91 fh_dup2(current_fh, &resfh);
93 accmode = MAY_NOP;
94 if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
95 accmode = MAY_READ;
96 if (open->op_share_deny & NFS4_SHARE_ACCESS_WRITE)
97 accmode |= (MAY_WRITE | MAY_TRUNC);
98 status = fh_verify(rqstp, current_fh, S_IFREG, accmode);
101 fh_put(&resfh);
102 return status;
105 static inline int
106 nfsd4_open(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open)
108 int status;
109 dprintk("NFSD: nfsd4_open filename %.*s\n",open->op_fname.len, open->op_fname.data);
111 /* This check required by spec. */
112 if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
113 return nfserr_inval;
115 /* check seqid for replay. set nfs4_owner */
116 status = nfsd4_process_open1(open);
117 if (status)
118 return status;
120 * This block of code will (1) set CURRENT_FH to the file being opened,
121 * creating it if necessary, (2) set open->op_cinfo,
122 * (3) set open->op_truncate if the file is to be truncated
123 * after opening, (4) do permission checking.
125 status = do_open_lookup(rqstp, current_fh, open);
126 if (status)
127 return status;
130 * nfsd4_process_open2() does the actual opening of the file. If
131 * successful, it (1) truncates the file if open->op_truncate was
132 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
134 status = nfsd4_process_open2(rqstp, current_fh, open);
135 if (status)
136 return status;
137 return 0;
141 * filehandle-manipulating ops.
143 static inline int
144 nfsd4_getfh(struct svc_fh *current_fh, struct svc_fh **getfh)
146 if (!current_fh->fh_dentry)
147 return nfserr_nofilehandle;
149 *getfh = current_fh;
150 return nfs_ok;
153 static inline int
154 nfsd4_putfh(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_putfh *putfh)
156 fh_put(current_fh);
157 current_fh->fh_handle.fh_size = putfh->pf_fhlen;
158 memcpy(&current_fh->fh_handle.fh_base, putfh->pf_fhval, putfh->pf_fhlen);
159 return fh_verify(rqstp, current_fh, 0, MAY_NOP);
162 static inline int
163 nfsd4_putrootfh(struct svc_rqst *rqstp, struct svc_fh *current_fh)
165 fh_put(current_fh);
166 return exp_pseudoroot(rqstp->rq_client, current_fh,
167 &rqstp->rq_chandle);
170 static inline int
171 nfsd4_restorefh(struct svc_fh *current_fh, struct svc_fh *save_fh)
173 if (!save_fh->fh_dentry)
174 return nfserr_nofilehandle;
176 fh_dup2(current_fh, save_fh);
177 return nfs_ok;
180 static inline int
181 nfsd4_savefh(struct svc_fh *current_fh, struct svc_fh *save_fh)
183 if (!current_fh->fh_dentry)
184 return nfserr_nofilehandle;
186 fh_dup2(save_fh, current_fh);
187 return nfs_ok;
191 * misc nfsv4 ops
193 static inline int
194 nfsd4_access(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_access *access)
196 if (access->ac_req_access & ~NFS3_ACCESS_FULL)
197 return nfserr_inval;
199 access->ac_resp_access = access->ac_req_access;
200 return nfsd_access(rqstp, current_fh, &access->ac_resp_access, &access->ac_supported);
203 static inline int
204 nfsd4_commit(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_commit *commit)
206 u32 *p = (u32 *)commit->co_verf;
207 *p++ = nfssvc_boot.tv_sec;
208 *p++ = nfssvc_boot.tv_usec;
210 return nfsd_commit(rqstp, current_fh, commit->co_offset, commit->co_count);
213 static inline int
214 nfsd4_create(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_create *create)
216 struct svc_fh resfh;
217 int status;
218 dev_t rdev;
220 fh_init(&resfh, NFS4_FHSIZE);
222 status = fh_verify(rqstp, current_fh, S_IFDIR, MAY_CREATE);
223 if (status)
224 return status;
226 switch (create->cr_type) {
227 case NF4LNK:
228 /* ugh! we have to null-terminate the linktext, or
229 * vfs_symlink() will choke. it is always safe to
230 * null-terminate by brute force, since at worst we
231 * will overwrite the first byte of the create namelen
232 * in the XDR buffer, which has already been extracted
233 * during XDR decode.
235 create->cr_linkname[create->cr_linklen] = 0;
237 status = nfsd_symlink(rqstp, current_fh, create->cr_name,
238 create->cr_namelen, create->cr_linkname,
239 create->cr_linklen, &resfh, &create->cr_iattr);
240 break;
242 case NF4BLK:
243 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
244 if (MAJOR(rdev) != create->cr_specdata1 ||
245 MINOR(rdev) != create->cr_specdata2)
246 return nfserr_inval;
247 status = nfsd_create(rqstp, current_fh, create->cr_name,
248 create->cr_namelen, &create->cr_iattr,
249 S_IFBLK, rdev, &resfh);
250 break;
252 case NF4CHR:
253 rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
254 if (MAJOR(rdev) != create->cr_specdata1 ||
255 MINOR(rdev) != create->cr_specdata2)
256 return nfserr_inval;
257 status = nfsd_create(rqstp, current_fh, create->cr_name,
258 create->cr_namelen, &create->cr_iattr,
259 S_IFCHR, rdev, &resfh);
260 break;
262 case NF4SOCK:
263 status = nfsd_create(rqstp, current_fh, create->cr_name,
264 create->cr_namelen, &create->cr_iattr,
265 S_IFSOCK, 0, &resfh);
266 break;
268 case NF4FIFO:
269 status = nfsd_create(rqstp, current_fh, create->cr_name,
270 create->cr_namelen, &create->cr_iattr,
271 S_IFIFO, 0, &resfh);
272 break;
274 case NF4DIR:
275 create->cr_iattr.ia_valid &= ~ATTR_SIZE;
276 status = nfsd_create(rqstp, current_fh, create->cr_name,
277 create->cr_namelen, &create->cr_iattr,
278 S_IFDIR, 0, &resfh);
279 break;
281 default:
282 BUG();
285 if (!status) {
286 fh_unlock(current_fh);
287 set_change_info(&create->cr_cinfo, current_fh);
288 fh_dup2(current_fh, &resfh);
291 fh_put(&resfh);
292 return status;
295 static inline int
296 nfsd4_getattr(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_getattr *getattr)
298 int status;
300 status = fh_verify(rqstp, current_fh, 0, MAY_NOP);
301 if (status)
302 return status;
304 if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
305 return nfserr_inval;
307 getattr->ga_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0;
308 getattr->ga_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1;
310 getattr->ga_fhp = current_fh;
311 return nfs_ok;
314 static inline int
315 nfsd4_link(struct svc_rqst *rqstp, struct svc_fh *current_fh,
316 struct svc_fh *save_fh, struct nfsd4_link *link)
318 int status;
320 status = nfsd_link(rqstp, current_fh, link->li_name, link->li_namelen, save_fh);
321 if (!status)
322 set_change_info(&link->li_cinfo, current_fh);
323 return status;
326 static inline int
327 nfsd4_lookupp(struct svc_rqst *rqstp, struct svc_fh *current_fh)
330 * XXX: We currently violate the spec in one small respect
331 * here. If LOOKUPP is done at the root of the pseudofs,
332 * the spec requires us to return NFSERR_NOENT. Personally,
333 * I think that leaving the filehandle unchanged is more
334 * logical, but this is an academic question anyway, since
335 * no clients actually use LOOKUPP.
337 return nfsd_lookup(rqstp, current_fh, "..", 2, current_fh);
340 static inline int
341 nfsd4_lookup(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_lookup *lookup)
343 return nfsd_lookup(rqstp, current_fh, lookup->lo_name, lookup->lo_len, current_fh);
346 static inline int
347 nfsd4_read(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_read *read)
349 struct nfs4_stateid *stp;
350 int status;
352 /* no need to check permission - this will be done in nfsd_read() */
354 if (read->rd_offset >= OFFSET_MAX)
355 return nfserr_inval;
357 nfsd4_lock_state();
358 status = nfs_ok;
359 /* For stateid -1, we don't check share reservations. */
360 if (ONE_STATEID(&read->rd_stateid)) {
361 dprintk("NFSD: nfsd4_read: -1 stateid...\n");
362 goto out;
365 * For stateid 0, the client doesn't have to have the file open, but
366 * we still check for share reservation conflicts.
368 if (ZERO_STATEID(&read->rd_stateid)) {
369 dprintk("NFSD: nfsd4_read: zero stateid...\n");
370 if ((status = nfs4_share_conflict(current_fh, NFS4_SHARE_DENY_READ))) {
371 dprintk("NFSD: nfsd4_read: conflicting share reservation!\n");
372 goto out;
374 status = nfs_ok;
375 goto out;
377 /* check stateid */
378 if ((status = nfs4_preprocess_stateid_op(current_fh, &read->rd_stateid,
379 CHECK_FH, &stp))) {
380 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
381 goto out;
383 status = nfserr_openmode;
384 if (!(stp->st_share_access & NFS4_SHARE_ACCESS_READ)) {
385 dprintk("NFSD: nfsd4_read: file not opened for read!\n");
386 goto out;
388 status = nfs_ok;
389 out:
390 nfsd4_unlock_state();
391 read->rd_rqstp = rqstp;
392 read->rd_fhp = current_fh;
393 return status;
396 static inline int
397 nfsd4_readdir(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_readdir *readdir)
399 /* no need to check permission - this will be done in nfsd_readdir() */
401 if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
402 return nfserr_inval;
404 readdir->rd_bmval[0] &= NFSD_SUPPORTED_ATTRS_WORD0;
405 readdir->rd_bmval[1] &= NFSD_SUPPORTED_ATTRS_WORD1;
407 if (readdir->rd_cookie > ~(u32)0)
408 return nfserr_bad_cookie;
410 readdir->rd_rqstp = rqstp;
411 readdir->rd_fhp = current_fh;
412 return nfs_ok;
415 static inline int
416 nfsd4_readlink(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_readlink *readlink)
418 readlink->rl_rqstp = rqstp;
419 readlink->rl_fhp = current_fh;
420 return nfs_ok;
423 static inline int
424 nfsd4_remove(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_remove *remove)
426 int status;
428 status = nfsd_unlink(rqstp, current_fh, 0, remove->rm_name, remove->rm_namelen);
429 if (!status) {
430 fh_unlock(current_fh);
431 set_change_info(&remove->rm_cinfo, current_fh);
433 return status;
436 static inline int
437 nfsd4_rename(struct svc_rqst *rqstp, struct svc_fh *current_fh,
438 struct svc_fh *save_fh, struct nfsd4_rename *rename)
440 int status;
442 status = nfsd_rename(rqstp, save_fh, rename->rn_sname,
443 rename->rn_snamelen, current_fh,
444 rename->rn_tname, rename->rn_tnamelen);
445 if (!status) {
446 set_change_info(&rename->rn_sinfo, current_fh);
447 set_change_info(&rename->rn_tinfo, save_fh);
449 return status;
452 static inline int
453 nfsd4_setattr(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_setattr *setattr)
455 struct nfs4_stateid *stp;
456 int status = nfs_ok;
458 if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
460 status = nfserr_bad_stateid;
461 if (ZERO_STATEID(&setattr->sa_stateid) || ONE_STATEID(&setattr->sa_stateid)) {
462 dprintk("NFSD: nfsd4_setattr: magic stateid!\n");
463 return status;
466 nfsd4_lock_state();
467 if ((status = nfs4_preprocess_stateid_op(current_fh,
468 &setattr->sa_stateid,
469 CHECK_FH, &stp))) {
470 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
471 goto out;
473 status = nfserr_openmode;
474 if (!(stp->st_share_access & NFS4_SHARE_ACCESS_WRITE)) {
475 dprintk("NFSD: nfsd4_setattr: not opened for write!\n");
476 goto out;
478 nfsd4_unlock_state();
480 return (nfsd_setattr(rqstp, current_fh, &setattr->sa_iattr, 0, (time_t)0));
481 out:
482 nfsd4_unlock_state();
483 return status;
486 static inline int
487 nfsd4_write(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_write *write)
489 struct nfs4_stateid *stp;
490 stateid_t *stateid = &write->wr_stateid;
491 u32 *p;
492 int status = nfs_ok;
494 /* no need to check permission - this will be done in nfsd_write() */
496 if (write->wr_offset >= OFFSET_MAX)
497 return nfserr_inval;
499 nfsd4_lock_state();
500 if (ZERO_STATEID(stateid) || ONE_STATEID(stateid)) {
501 dprintk("NFSD: nfsd4_write: zero stateid...\n");
502 if ((status = nfs4_share_conflict(current_fh, NFS4_SHARE_DENY_WRITE))) {
503 dprintk("NFSD: nfsd4_write: conflicting share reservation!\n");
504 goto out;
506 goto zero_stateid;
508 if ((status = nfs4_preprocess_stateid_op(current_fh, stateid,
509 CHECK_FH, &stp))) {
510 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
511 goto out;
514 status = nfserr_openmode;
515 if (!(stp->st_share_access & NFS4_SHARE_ACCESS_WRITE)) {
516 dprintk("NFSD: nfsd4_write: file not open for write!\n");
517 goto out;
520 zero_stateid:
521 nfsd4_unlock_state();
522 write->wr_bytes_written = write->wr_buflen;
523 write->wr_how_written = write->wr_stable_how;
524 p = (u32 *)write->wr_verifier;
525 *p++ = nfssvc_boot.tv_sec;
526 *p++ = nfssvc_boot.tv_usec;
528 return (nfsd_write(rqstp, current_fh, write->wr_offset,
529 write->wr_vec, write->wr_vlen, write->wr_buflen,
530 &write->wr_how_written));
531 out:
532 nfsd4_unlock_state();
533 return status;
536 /* This routine never returns NFS_OK! If there are no other errors, it
537 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
538 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
539 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
541 static int
542 nfsd4_verify(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_verify *verify)
544 u32 *buf, *p;
545 int count;
546 int status;
548 status = fh_verify(rqstp, current_fh, 0, MAY_NOP);
549 if (status)
550 return status;
552 if ((verify->ve_bmval[0] & ~NFSD_SUPPORTED_ATTRS_WORD0)
553 || (verify->ve_bmval[1] & ~NFSD_SUPPORTED_ATTRS_WORD1))
554 return nfserr_notsupp;
555 if (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
556 return nfserr_inval;
557 if (verify->ve_attrlen & 3)
558 return nfserr_inval;
560 /* count in words:
561 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
563 count = 4 + (verify->ve_attrlen >> 2);
564 buf = kmalloc(count << 2, GFP_KERNEL);
565 if (!buf)
566 return nfserr_resource;
568 status = nfsd4_encode_fattr(current_fh, current_fh->fh_export,
569 current_fh->fh_dentry, buf,
570 &count, verify->ve_bmval);
572 /* this means that nfsd4_encode_fattr() ran out of space */
573 if (status == nfserr_resource && count == 0)
574 status = nfserr_not_same;
575 if (status)
576 goto out_kfree;
578 p = buf + 3;
579 status = nfserr_not_same;
580 if (ntohl(*p++) != verify->ve_attrlen)
581 goto out_kfree;
582 if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
583 status = nfserr_same;
585 out_kfree:
586 kfree(buf);
587 return status;
591 * NULL call.
593 static int
594 nfsd4_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
596 return nfs_ok;
601 * COMPOUND call.
603 static int
604 nfsd4_proc_compound(struct svc_rqst *rqstp,
605 struct nfsd4_compoundargs *args,
606 struct nfsd4_compoundres *resp)
608 struct nfsd4_op *op;
609 struct svc_fh current_fh;
610 struct svc_fh save_fh;
611 int slack_space; /* in words, not bytes! */
612 int status;
614 fh_init(&current_fh, NFS4_FHSIZE);
615 fh_init(&save_fh, NFS4_FHSIZE);
617 resp->xbuf = &rqstp->rq_res;
618 resp->p = rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len;
619 resp->tagp = resp->p;
620 /* reserve space for: taglen, tag, and opcnt */
621 resp->p += 2 + XDR_QUADLEN(args->taglen);
622 resp->end = rqstp->rq_res.head[0].iov_base + PAGE_SIZE;
623 resp->taglen = args->taglen;
624 resp->tag = args->tag;
625 resp->opcnt = 0;
626 resp->rqstp = rqstp;
629 * According to RFC3010, this takes precedence over all other errors.
631 status = nfserr_minor_vers_mismatch;
632 if (args->minorversion > NFSD_SUPPORTED_MINOR_VERSION)
633 goto out;
635 status = nfs_ok;
636 while (!status && resp->opcnt < args->opcnt) {
637 op = &args->ops[resp->opcnt++];
640 * The XDR decode routines may have pre-set op->status;
641 * for example, if there is a miscellaneous XDR error
642 * it will be set to nfserr_bad_xdr.
644 if (op->status)
645 goto encode_op;
647 /* We must be able to encode a successful response to
648 * this operation, with enough room left over to encode a
649 * failed response to the next operation. If we don't
650 * have enough room, fail with ERR_RESOURCE.
652 /* FIXME - is slack_space *really* words, or bytes??? - neilb */
653 slack_space = (char *)resp->end - (char *)resp->p;
654 if (slack_space < COMPOUND_SLACK_SPACE + COMPOUND_ERR_SLACK_SPACE) {
655 BUG_ON(slack_space < COMPOUND_ERR_SLACK_SPACE);
656 op->status = nfserr_resource;
657 goto encode_op;
660 switch (op->opnum) {
661 case OP_ACCESS:
662 op->status = nfsd4_access(rqstp, &current_fh, &op->u.access);
663 break;
664 case OP_CLOSE:
665 op->status = nfsd4_close(rqstp, &current_fh, &op->u.close);
666 break;
667 case OP_COMMIT:
668 op->status = nfsd4_commit(rqstp, &current_fh, &op->u.commit);
669 break;
670 case OP_CREATE:
671 op->status = nfsd4_create(rqstp, &current_fh, &op->u.create);
672 break;
673 case OP_GETATTR:
674 op->status = nfsd4_getattr(rqstp, &current_fh, &op->u.getattr);
675 break;
676 case OP_GETFH:
677 op->status = nfsd4_getfh(&current_fh, &op->u.getfh);
678 break;
679 case OP_LINK:
680 op->status = nfsd4_link(rqstp, &current_fh, &save_fh, &op->u.link);
681 break;
682 case OP_LOOKUP:
683 op->status = nfsd4_lookup(rqstp, &current_fh, &op->u.lookup);
684 break;
685 case OP_LOOKUPP:
686 op->status = nfsd4_lookupp(rqstp, &current_fh);
687 break;
688 case OP_NVERIFY:
689 op->status = nfsd4_verify(rqstp, &current_fh, &op->u.nverify);
690 if (op->status == nfserr_not_same)
691 op->status = nfs_ok;
692 break;
693 case OP_OPEN:
694 op->status = nfsd4_open(rqstp, &current_fh, &op->u.open);
695 break;
696 case OP_OPEN_CONFIRM:
697 op->status = nfsd4_open_confirm(rqstp, &current_fh, &op->u.open_confirm);
698 break;
699 case OP_OPEN_DOWNGRADE:
700 op->status = nfsd4_open_downgrade(rqstp, &current_fh, &op->u.open_downgrade);
701 break;
702 case OP_PUTFH:
703 op->status = nfsd4_putfh(rqstp, &current_fh, &op->u.putfh);
704 break;
705 case OP_PUTROOTFH:
706 op->status = nfsd4_putrootfh(rqstp, &current_fh);
707 break;
708 case OP_READ:
709 op->status = nfsd4_read(rqstp, &current_fh, &op->u.read);
710 break;
711 case OP_READDIR:
712 op->status = nfsd4_readdir(rqstp, &current_fh, &op->u.readdir);
713 break;
714 case OP_READLINK:
715 op->status = nfsd4_readlink(rqstp, &current_fh, &op->u.readlink);
716 break;
717 case OP_REMOVE:
718 op->status = nfsd4_remove(rqstp, &current_fh, &op->u.remove);
719 break;
720 case OP_RENAME:
721 op->status = nfsd4_rename(rqstp, &current_fh, &save_fh, &op->u.rename);
722 break;
723 case OP_RENEW:
724 op->status = nfsd4_renew(&op->u.renew);
725 break;
726 case OP_RESTOREFH:
727 op->status = nfsd4_restorefh(&current_fh, &save_fh);
728 break;
729 case OP_SAVEFH:
730 op->status = nfsd4_savefh(&current_fh, &save_fh);
731 break;
732 case OP_SETATTR:
733 op->status = nfsd4_setattr(rqstp, &current_fh, &op->u.setattr);
734 break;
735 case OP_SETCLIENTID:
736 op->status = nfsd4_setclientid(rqstp, &op->u.setclientid);
737 break;
738 case OP_SETCLIENTID_CONFIRM:
739 op->status = nfsd4_setclientid_confirm(rqstp, &op->u.setclientid_confirm);
740 break;
741 case OP_VERIFY:
742 op->status = nfsd4_verify(rqstp, &current_fh, &op->u.verify);
743 if (op->status == nfserr_same)
744 op->status = nfs_ok;
745 break;
746 case OP_WRITE:
747 op->status = nfsd4_write(rqstp, &current_fh, &op->u.write);
748 break;
749 default:
750 BUG_ON(op->status == nfs_ok);
751 break;
754 encode_op:
755 nfsd4_encode_operation(resp, op);
756 status = op->status;
759 out:
760 if (args->ops != args->iops) {
761 kfree(args->ops);
762 args->ops = args->iops;
764 if (args->tmpp) {
765 kfree(args->tmpp);
766 args->tmpp = NULL;
768 while (args->to_free) {
769 struct tmpbuf *tb = args->to_free;
770 args->to_free = tb->next;
771 kfree(tb->buf);
772 kfree(tb);
774 fh_put(&current_fh);
775 fh_put(&save_fh);
776 return status;
779 #define nfs4svc_decode_voidargs NULL
780 #define nfs4svc_release_void NULL
781 #define nfsd4_voidres nfsd4_voidargs
782 #define nfs4svc_release_compound NULL
783 struct nfsd4_voidargs { int dummy; };
785 #define PROC(name, argt, rest, relt, cache, respsize) \
786 { (svc_procfunc) nfsd4_proc_##name, \
787 (kxdrproc_t) nfs4svc_decode_##argt##args, \
788 (kxdrproc_t) nfs4svc_encode_##rest##res, \
789 (kxdrproc_t) nfs4svc_release_##relt, \
790 sizeof(struct nfsd4_##argt##args), \
791 sizeof(struct nfsd4_##rest##res), \
792 0, \
793 cache, \
794 respsize, \
798 * TODO: At the present time, the NFSv4 server does not do XID caching
799 * of requests. Implementing XID caching would not be a serious problem,
800 * although it would require a mild change in interfaces since one
801 * doesn't know whether an NFSv4 request is idempotent until after the
802 * XDR decode. However, XID caching totally confuses pynfs (Peter
803 * Astrand's regression testsuite for NFSv4 servers), which reuses
804 * XID's liberally, so I've left it unimplemented until pynfs generates
805 * better XID's.
807 static struct svc_procedure nfsd_procedures4[2] = {
808 PROC(null, void, void, void, RC_NOCACHE, 1),
809 PROC(compound, compound, compound, compound, RC_NOCACHE, NFSD_BUFSIZE)
812 struct svc_version nfsd_version4 = {
813 .vs_vers = 4,
814 .vs_nproc = 2,
815 .vs_proc = nfsd_procedures4,
816 .vs_dispatch = nfsd_dispatch,
817 .vs_xdrsize = NFS4_SVC_XDRSIZE,
821 * Local variables:
822 * c-basic-offset: 8
823 * End: