4 * Server-side procedures for NFSv4.
6 * Copyright (c) 2002 The Regents of the University of Michigan.
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
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
45 #include <linux/param.h>
46 #include <linux/major.h>
47 #include <linux/slab.h>
48 #include <linux/file.h>
50 #include <linux/sunrpc/svc.h>
51 #include <linux/nfsd/nfsd.h>
52 #include <linux/nfsd/cache.h>
53 #include <linux/nfs4.h>
54 #include <linux/nfsd/state.h>
55 #include <linux/nfsd/xdr4.h>
56 #include <linux/nfs4_acl.h>
58 #define NFSDDBG_FACILITY NFSDDBG_PROC
61 fh_dup2(struct svc_fh
*dst
, struct svc_fh
*src
)
66 cache_get(&src
->fh_export
->h
);
71 do_open_permission(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
)
75 if (open
->op_truncate
&&
76 !(open
->op_share_access
& NFS4_SHARE_ACCESS_WRITE
))
80 if (open
->op_share_access
& NFS4_SHARE_ACCESS_READ
)
82 if (open
->op_share_deny
& NFS4_SHARE_ACCESS_WRITE
)
83 accmode
|= (MAY_WRITE
| MAY_TRUNC
);
84 accmode
|= MAY_OWNER_OVERRIDE
;
86 status
= fh_verify(rqstp
, current_fh
, S_IFREG
, accmode
);
92 do_open_lookup(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
)
97 fh_init(&resfh
, NFS4_FHSIZE
);
98 open
->op_truncate
= 0;
100 if (open
->op_create
) {
102 * Note: create modes (UNCHECKED,GUARDED...) are the same
105 status
= nfsd_create_v3(rqstp
, current_fh
, open
->op_fname
.data
,
106 open
->op_fname
.len
, &open
->op_iattr
,
107 &resfh
, open
->op_createmode
,
108 (u32
*)open
->op_verf
.data
, &open
->op_truncate
);
111 status
= nfsd_lookup(rqstp
, current_fh
,
112 open
->op_fname
.data
, open
->op_fname
.len
, &resfh
);
113 fh_unlock(current_fh
);
117 set_change_info(&open
->op_cinfo
, current_fh
);
119 /* set reply cache */
120 fh_dup2(current_fh
, &resfh
);
121 open
->op_stateowner
->so_replay
.rp_openfh_len
=
122 resfh
.fh_handle
.fh_size
;
123 memcpy(open
->op_stateowner
->so_replay
.rp_openfh
,
124 &resfh
.fh_handle
.fh_base
,
125 resfh
.fh_handle
.fh_size
);
127 status
= do_open_permission(rqstp
, current_fh
, open
);
135 do_open_fhandle(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
)
139 /* Only reclaims from previously confirmed clients are valid */
140 if ((status
= nfs4_check_open_reclaim(&open
->op_clientid
)))
143 /* We don't know the target directory, and therefore can not
144 * set the change info
147 memset(&open
->op_cinfo
, 0, sizeof(struct nfsd4_change_info
));
149 /* set replay cache */
150 open
->op_stateowner
->so_replay
.rp_openfh_len
= current_fh
->fh_handle
.fh_size
;
151 memcpy(open
->op_stateowner
->so_replay
.rp_openfh
,
152 ¤t_fh
->fh_handle
.fh_base
,
153 current_fh
->fh_handle
.fh_size
);
155 open
->op_truncate
= (open
->op_iattr
.ia_valid
& ATTR_SIZE
) &&
156 (open
->op_iattr
.ia_size
== 0);
158 status
= do_open_permission(rqstp
, current_fh
, open
);
165 nfsd4_open(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
, struct nfs4_stateowner
**replay_owner
)
168 dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n",
169 (int)open
->op_fname
.len
, open
->op_fname
.data
,
170 open
->op_stateowner
);
172 /* This check required by spec. */
173 if (open
->op_create
&& open
->op_claim_type
!= NFS4_OPEN_CLAIM_NULL
)
178 /* check seqid for replay. set nfs4_owner */
179 status
= nfsd4_process_open1(open
);
180 if (status
== NFSERR_REPLAY_ME
) {
181 struct nfs4_replay
*rp
= &open
->op_stateowner
->so_replay
;
183 current_fh
->fh_handle
.fh_size
= rp
->rp_openfh_len
;
184 memcpy(¤t_fh
->fh_handle
.fh_base
, rp
->rp_openfh
,
186 status
= fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
188 dprintk("nfsd4_open: replay failed"
189 " restoring previous filehandle\n");
191 status
= NFSERR_REPLAY_ME
;
196 /* Openowner is now set, so sequence id will get bumped. Now we need
197 * these checks before we do any creates: */
198 status
= nfserr_grace
;
199 if (nfs4_in_grace() && open
->op_claim_type
!= NFS4_OPEN_CLAIM_PREVIOUS
)
201 status
= nfserr_no_grace
;
202 if (!nfs4_in_grace() && open
->op_claim_type
== NFS4_OPEN_CLAIM_PREVIOUS
)
205 switch (open
->op_claim_type
) {
206 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
207 status
= nfserr_inval
;
211 case NFS4_OPEN_CLAIM_NULL
:
213 * (1) set CURRENT_FH to the file being opened,
214 * creating it if necessary, (2) set open->op_cinfo,
215 * (3) set open->op_truncate if the file is to be
216 * truncated after opening, (4) do permission checking.
218 status
= do_open_lookup(rqstp
, current_fh
, open
);
222 case NFS4_OPEN_CLAIM_PREVIOUS
:
223 open
->op_stateowner
->so_confirmed
= 1;
225 * The CURRENT_FH is already set to the file being
226 * opened. (1) set open->op_cinfo, (2) set
227 * open->op_truncate if the file is to be truncated
228 * after opening, (3) do permission checking.
230 status
= do_open_fhandle(rqstp
, current_fh
, open
);
234 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
235 open
->op_stateowner
->so_confirmed
= 1;
236 printk("NFSD: unsupported OPEN claim type %d\n",
237 open
->op_claim_type
);
238 status
= nfserr_notsupp
;
241 printk("NFSD: Invalid OPEN claim type %d\n",
242 open
->op_claim_type
);
243 status
= nfserr_inval
;
247 * nfsd4_process_open2() does the actual opening of the file. If
248 * successful, it (1) truncates the file if open->op_truncate was
249 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
251 status
= nfsd4_process_open2(rqstp
, current_fh
, open
);
253 if (open
->op_stateowner
) {
254 nfs4_get_stateowner(open
->op_stateowner
);
255 *replay_owner
= open
->op_stateowner
;
262 * filehandle-manipulating ops.
265 nfsd4_getfh(struct svc_fh
*current_fh
, struct svc_fh
**getfh
)
267 if (!current_fh
->fh_dentry
)
268 return nfserr_nofilehandle
;
275 nfsd4_putfh(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_putfh
*putfh
)
278 current_fh
->fh_handle
.fh_size
= putfh
->pf_fhlen
;
279 memcpy(¤t_fh
->fh_handle
.fh_base
, putfh
->pf_fhval
, putfh
->pf_fhlen
);
280 return fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
284 nfsd4_putrootfh(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
)
289 status
= exp_pseudoroot(rqstp
->rq_client
, current_fh
,
292 status
= nfserrno(nfsd_setuser(rqstp
, current_fh
->fh_export
));
297 nfsd4_restorefh(struct svc_fh
*current_fh
, struct svc_fh
*save_fh
)
299 if (!save_fh
->fh_dentry
)
300 return nfserr_restorefh
;
302 fh_dup2(current_fh
, save_fh
);
307 nfsd4_savefh(struct svc_fh
*current_fh
, struct svc_fh
*save_fh
)
309 if (!current_fh
->fh_dentry
)
310 return nfserr_nofilehandle
;
312 fh_dup2(save_fh
, current_fh
);
320 nfsd4_access(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_access
*access
)
322 if (access
->ac_req_access
& ~NFS3_ACCESS_FULL
)
325 access
->ac_resp_access
= access
->ac_req_access
;
326 return nfsd_access(rqstp
, current_fh
, &access
->ac_resp_access
, &access
->ac_supported
);
330 nfsd4_commit(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_commit
*commit
)
334 u32
*p
= (u32
*)commit
->co_verf
.data
;
335 *p
++ = nfssvc_boot
.tv_sec
;
336 *p
++ = nfssvc_boot
.tv_usec
;
338 status
= nfsd_commit(rqstp
, current_fh
, commit
->co_offset
, commit
->co_count
);
339 if (status
== nfserr_symlink
)
340 status
= nfserr_inval
;
345 nfsd4_create(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_create
*create
)
351 fh_init(&resfh
, NFS4_FHSIZE
);
353 status
= fh_verify(rqstp
, current_fh
, S_IFDIR
, MAY_CREATE
);
354 if (status
== nfserr_symlink
)
355 status
= nfserr_notdir
;
359 switch (create
->cr_type
) {
361 /* ugh! we have to null-terminate the linktext, or
362 * vfs_symlink() will choke. it is always safe to
363 * null-terminate by brute force, since at worst we
364 * will overwrite the first byte of the create namelen
365 * in the XDR buffer, which has already been extracted
368 create
->cr_linkname
[create
->cr_linklen
] = 0;
370 status
= nfsd_symlink(rqstp
, current_fh
, create
->cr_name
,
371 create
->cr_namelen
, create
->cr_linkname
,
372 create
->cr_linklen
, &resfh
, &create
->cr_iattr
);
376 rdev
= MKDEV(create
->cr_specdata1
, create
->cr_specdata2
);
377 if (MAJOR(rdev
) != create
->cr_specdata1
||
378 MINOR(rdev
) != create
->cr_specdata2
)
380 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
381 create
->cr_namelen
, &create
->cr_iattr
,
382 S_IFBLK
, rdev
, &resfh
);
386 rdev
= MKDEV(create
->cr_specdata1
, create
->cr_specdata2
);
387 if (MAJOR(rdev
) != create
->cr_specdata1
||
388 MINOR(rdev
) != create
->cr_specdata2
)
390 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
391 create
->cr_namelen
, &create
->cr_iattr
,
392 S_IFCHR
, rdev
, &resfh
);
396 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
397 create
->cr_namelen
, &create
->cr_iattr
,
398 S_IFSOCK
, 0, &resfh
);
402 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
403 create
->cr_namelen
, &create
->cr_iattr
,
408 create
->cr_iattr
.ia_valid
&= ~ATTR_SIZE
;
409 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
410 create
->cr_namelen
, &create
->cr_iattr
,
415 status
= nfserr_badtype
;
419 fh_unlock(current_fh
);
420 set_change_info(&create
->cr_cinfo
, current_fh
);
421 fh_dup2(current_fh
, &resfh
);
429 nfsd4_getattr(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_getattr
*getattr
)
433 status
= fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
437 if (getattr
->ga_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
)
440 getattr
->ga_bmval
[0] &= NFSD_SUPPORTED_ATTRS_WORD0
;
441 getattr
->ga_bmval
[1] &= NFSD_SUPPORTED_ATTRS_WORD1
;
443 getattr
->ga_fhp
= current_fh
;
448 nfsd4_link(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
,
449 struct svc_fh
*save_fh
, struct nfsd4_link
*link
)
451 int status
= nfserr_nofilehandle
;
453 if (!save_fh
->fh_dentry
)
455 status
= nfsd_link(rqstp
, current_fh
, link
->li_name
, link
->li_namelen
, save_fh
);
457 set_change_info(&link
->li_cinfo
, current_fh
);
462 nfsd4_lookupp(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
)
464 struct svc_fh tmp_fh
;
467 fh_init(&tmp_fh
, NFS4_FHSIZE
);
468 if((ret
= exp_pseudoroot(rqstp
->rq_client
, &tmp_fh
,
469 &rqstp
->rq_chandle
)) != 0)
471 if (tmp_fh
.fh_dentry
== current_fh
->fh_dentry
) {
476 return nfsd_lookup(rqstp
, current_fh
, "..", 2, current_fh
);
480 nfsd4_lookup(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_lookup
*lookup
)
482 return nfsd_lookup(rqstp
, current_fh
, lookup
->lo_name
, lookup
->lo_len
, current_fh
);
486 nfsd4_read(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_read
*read
)
490 /* no need to check permission - this will be done in nfsd_read() */
492 read
->rd_filp
= NULL
;
493 if (read
->rd_offset
>= OFFSET_MAX
)
498 if ((status
= nfs4_preprocess_stateid_op(current_fh
, &read
->rd_stateid
,
499 CHECK_FH
| RD_STATE
, &read
->rd_filp
))) {
500 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
504 get_file(read
->rd_filp
);
508 read
->rd_rqstp
= rqstp
;
509 read
->rd_fhp
= current_fh
;
514 nfsd4_readdir(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_readdir
*readdir
)
516 u64 cookie
= readdir
->rd_cookie
;
517 static const nfs4_verifier zeroverf
;
519 /* no need to check permission - this will be done in nfsd_readdir() */
521 if (readdir
->rd_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
)
524 readdir
->rd_bmval
[0] &= NFSD_SUPPORTED_ATTRS_WORD0
;
525 readdir
->rd_bmval
[1] &= NFSD_SUPPORTED_ATTRS_WORD1
;
527 if ((cookie
> ~(u32
)0) || (cookie
== 1) || (cookie
== 2) ||
528 (cookie
== 0 && memcmp(readdir
->rd_verf
.data
, zeroverf
.data
, NFS4_VERIFIER_SIZE
)))
529 return nfserr_bad_cookie
;
531 readdir
->rd_rqstp
= rqstp
;
532 readdir
->rd_fhp
= current_fh
;
537 nfsd4_readlink(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_readlink
*readlink
)
539 readlink
->rl_rqstp
= rqstp
;
540 readlink
->rl_fhp
= current_fh
;
545 nfsd4_remove(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_remove
*remove
)
551 status
= nfsd_unlink(rqstp
, current_fh
, 0, remove
->rm_name
, remove
->rm_namelen
);
552 if (status
== nfserr_symlink
)
553 return nfserr_notdir
;
555 fh_unlock(current_fh
);
556 set_change_info(&remove
->rm_cinfo
, current_fh
);
562 nfsd4_rename(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
,
563 struct svc_fh
*save_fh
, struct nfsd4_rename
*rename
)
565 int status
= nfserr_nofilehandle
;
567 if (!save_fh
->fh_dentry
)
569 if (nfs4_in_grace() && !(save_fh
->fh_export
->ex_flags
570 & NFSEXP_NOSUBTREECHECK
))
572 status
= nfsd_rename(rqstp
, save_fh
, rename
->rn_sname
,
573 rename
->rn_snamelen
, current_fh
,
574 rename
->rn_tname
, rename
->rn_tnamelen
);
576 /* the underlying filesystem returns different error's than required
577 * by NFSv4. both save_fh and current_fh have been verified.. */
578 if (status
== nfserr_isdir
)
579 status
= nfserr_exist
;
580 else if ((status
== nfserr_notdir
) &&
581 (S_ISDIR(save_fh
->fh_dentry
->d_inode
->i_mode
) &&
582 S_ISDIR(current_fh
->fh_dentry
->d_inode
->i_mode
)))
583 status
= nfserr_exist
;
584 else if (status
== nfserr_symlink
)
585 status
= nfserr_notdir
;
588 set_change_info(&rename
->rn_sinfo
, current_fh
);
589 set_change_info(&rename
->rn_tinfo
, save_fh
);
595 nfsd4_setattr(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_setattr
*setattr
)
599 if (setattr
->sa_iattr
.ia_valid
& ATTR_SIZE
) {
601 status
= nfs4_preprocess_stateid_op(current_fh
,
602 &setattr
->sa_stateid
, CHECK_FH
| WR_STATE
, NULL
);
605 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!");
610 if (setattr
->sa_acl
!= NULL
)
611 status
= nfsd4_set_nfs4_acl(rqstp
, current_fh
, setattr
->sa_acl
);
614 status
= nfsd_setattr(rqstp
, current_fh
, &setattr
->sa_iattr
,
620 nfsd4_write(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_write
*write
)
622 stateid_t
*stateid
= &write
->wr_stateid
;
623 struct file
*filp
= NULL
;
627 /* no need to check permission - this will be done in nfsd_write() */
629 if (write
->wr_offset
>= OFFSET_MAX
)
633 status
= nfs4_preprocess_stateid_op(current_fh
, stateid
,
634 CHECK_FH
| WR_STATE
, &filp
);
640 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
644 write
->wr_bytes_written
= write
->wr_buflen
;
645 write
->wr_how_written
= write
->wr_stable_how
;
646 p
= (u32
*)write
->wr_verifier
.data
;
647 *p
++ = nfssvc_boot
.tv_sec
;
648 *p
++ = nfssvc_boot
.tv_usec
;
650 status
= nfsd_write(rqstp
, current_fh
, filp
, write
->wr_offset
,
651 write
->wr_vec
, write
->wr_vlen
, write
->wr_buflen
,
652 &write
->wr_how_written
);
656 if (status
== nfserr_symlink
)
657 status
= nfserr_inval
;
661 /* This routine never returns NFS_OK! If there are no other errors, it
662 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
663 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
664 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
667 nfsd4_verify(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_verify
*verify
)
673 status
= fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
677 if ((verify
->ve_bmval
[0] & ~NFSD_SUPPORTED_ATTRS_WORD0
)
678 || (verify
->ve_bmval
[1] & ~NFSD_SUPPORTED_ATTRS_WORD1
))
679 return nfserr_attrnotsupp
;
680 if ((verify
->ve_bmval
[0] & FATTR4_WORD0_RDATTR_ERROR
)
681 || (verify
->ve_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
))
683 if (verify
->ve_attrlen
& 3)
687 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
689 count
= 4 + (verify
->ve_attrlen
>> 2);
690 buf
= kmalloc(count
<< 2, GFP_KERNEL
);
692 return nfserr_resource
;
694 status
= nfsd4_encode_fattr(current_fh
, current_fh
->fh_export
,
695 current_fh
->fh_dentry
, buf
,
696 &count
, verify
->ve_bmval
,
699 /* this means that nfsd4_encode_fattr() ran out of space */
700 if (status
== nfserr_resource
&& count
== 0)
701 status
= nfserr_not_same
;
706 status
= nfserr_not_same
;
707 if (ntohl(*p
++) != verify
->ve_attrlen
)
709 if (!memcmp(p
, verify
->ve_attrval
, verify
->ve_attrlen
))
710 status
= nfserr_same
;
721 nfsd4_proc_null(struct svc_rqst
*rqstp
, void *argp
, void *resp
)
731 nfsd4_proc_compound(struct svc_rqst
*rqstp
,
732 struct nfsd4_compoundargs
*args
,
733 struct nfsd4_compoundres
*resp
)
736 struct svc_fh
*current_fh
= NULL
;
737 struct svc_fh
*save_fh
= NULL
;
738 struct nfs4_stateowner
*replay_owner
= NULL
;
739 int slack_space
; /* in words, not bytes! */
742 status
= nfserr_resource
;
743 current_fh
= kmalloc(sizeof(*current_fh
), GFP_KERNEL
);
744 if (current_fh
== NULL
)
746 fh_init(current_fh
, NFS4_FHSIZE
);
747 save_fh
= kmalloc(sizeof(*save_fh
), GFP_KERNEL
);
750 fh_init(save_fh
, NFS4_FHSIZE
);
752 resp
->xbuf
= &rqstp
->rq_res
;
753 resp
->p
= rqstp
->rq_res
.head
[0].iov_base
+ rqstp
->rq_res
.head
[0].iov_len
;
754 resp
->tagp
= resp
->p
;
755 /* reserve space for: taglen, tag, and opcnt */
756 resp
->p
+= 2 + XDR_QUADLEN(args
->taglen
);
757 resp
->end
= rqstp
->rq_res
.head
[0].iov_base
+ PAGE_SIZE
;
758 resp
->taglen
= args
->taglen
;
759 resp
->tag
= args
->tag
;
764 * According to RFC3010, this takes precedence over all other errors.
766 status
= nfserr_minor_vers_mismatch
;
767 if (args
->minorversion
> NFSD_SUPPORTED_MINOR_VERSION
)
771 while (!status
&& resp
->opcnt
< args
->opcnt
) {
772 op
= &args
->ops
[resp
->opcnt
++];
774 dprintk("nfsv4 compound op #%d: %d\n", resp
->opcnt
, op
->opnum
);
777 * The XDR decode routines may have pre-set op->status;
778 * for example, if there is a miscellaneous XDR error
779 * it will be set to nfserr_bad_xdr.
784 /* We must be able to encode a successful response to
785 * this operation, with enough room left over to encode a
786 * failed response to the next operation. If we don't
787 * have enough room, fail with ERR_RESOURCE.
789 /* FIXME - is slack_space *really* words, or bytes??? - neilb */
790 slack_space
= (char *)resp
->end
- (char *)resp
->p
;
791 if (slack_space
< COMPOUND_SLACK_SPACE
+ COMPOUND_ERR_SLACK_SPACE
) {
792 BUG_ON(slack_space
< COMPOUND_ERR_SLACK_SPACE
);
793 op
->status
= nfserr_resource
;
797 /* All operations except RENEW, SETCLIENTID, RESTOREFH
798 * SETCLIENTID_CONFIRM, PUTFH and PUTROOTFH
799 * require a valid current filehandle
801 if ((!current_fh
->fh_dentry
) &&
802 !((op
->opnum
== OP_PUTFH
) || (op
->opnum
== OP_PUTROOTFH
) ||
803 (op
->opnum
== OP_SETCLIENTID
) ||
804 (op
->opnum
== OP_SETCLIENTID_CONFIRM
) ||
805 (op
->opnum
== OP_RENEW
) || (op
->opnum
== OP_RESTOREFH
) ||
806 (op
->opnum
== OP_RELEASE_LOCKOWNER
))) {
807 op
->status
= nfserr_nofilehandle
;
812 op
->status
= nfsd4_access(rqstp
, current_fh
, &op
->u
.access
);
815 op
->status
= nfsd4_close(rqstp
, current_fh
, &op
->u
.close
, &replay_owner
);
818 op
->status
= nfsd4_commit(rqstp
, current_fh
, &op
->u
.commit
);
821 op
->status
= nfsd4_create(rqstp
, current_fh
, &op
->u
.create
);
824 op
->status
= nfsd4_delegreturn(rqstp
, current_fh
, &op
->u
.delegreturn
);
827 op
->status
= nfsd4_getattr(rqstp
, current_fh
, &op
->u
.getattr
);
830 op
->status
= nfsd4_getfh(current_fh
, &op
->u
.getfh
);
833 op
->status
= nfsd4_link(rqstp
, current_fh
, save_fh
, &op
->u
.link
);
836 op
->status
= nfsd4_lock(rqstp
, current_fh
, &op
->u
.lock
, &replay_owner
);
839 op
->status
= nfsd4_lockt(rqstp
, current_fh
, &op
->u
.lockt
);
842 op
->status
= nfsd4_locku(rqstp
, current_fh
, &op
->u
.locku
, &replay_owner
);
845 op
->status
= nfsd4_lookup(rqstp
, current_fh
, &op
->u
.lookup
);
848 op
->status
= nfsd4_lookupp(rqstp
, current_fh
);
851 op
->status
= nfsd4_verify(rqstp
, current_fh
, &op
->u
.nverify
);
852 if (op
->status
== nfserr_not_same
)
856 op
->status
= nfsd4_open(rqstp
, current_fh
, &op
->u
.open
, &replay_owner
);
858 case OP_OPEN_CONFIRM
:
859 op
->status
= nfsd4_open_confirm(rqstp
, current_fh
, &op
->u
.open_confirm
, &replay_owner
);
861 case OP_OPEN_DOWNGRADE
:
862 op
->status
= nfsd4_open_downgrade(rqstp
, current_fh
, &op
->u
.open_downgrade
, &replay_owner
);
865 op
->status
= nfsd4_putfh(rqstp
, current_fh
, &op
->u
.putfh
);
868 op
->status
= nfsd4_putrootfh(rqstp
, current_fh
);
871 op
->status
= nfsd4_read(rqstp
, current_fh
, &op
->u
.read
);
874 op
->status
= nfsd4_readdir(rqstp
, current_fh
, &op
->u
.readdir
);
877 op
->status
= nfsd4_readlink(rqstp
, current_fh
, &op
->u
.readlink
);
880 op
->status
= nfsd4_remove(rqstp
, current_fh
, &op
->u
.remove
);
883 op
->status
= nfsd4_rename(rqstp
, current_fh
, save_fh
, &op
->u
.rename
);
886 op
->status
= nfsd4_renew(&op
->u
.renew
);
889 op
->status
= nfsd4_restorefh(current_fh
, save_fh
);
892 op
->status
= nfsd4_savefh(current_fh
, save_fh
);
895 op
->status
= nfsd4_setattr(rqstp
, current_fh
, &op
->u
.setattr
);
898 op
->status
= nfsd4_setclientid(rqstp
, &op
->u
.setclientid
);
900 case OP_SETCLIENTID_CONFIRM
:
901 op
->status
= nfsd4_setclientid_confirm(rqstp
, &op
->u
.setclientid_confirm
);
904 op
->status
= nfsd4_verify(rqstp
, current_fh
, &op
->u
.verify
);
905 if (op
->status
== nfserr_same
)
909 op
->status
= nfsd4_write(rqstp
, current_fh
, &op
->u
.write
);
911 case OP_RELEASE_LOCKOWNER
:
912 op
->status
= nfsd4_release_lockowner(rqstp
, &op
->u
.release_lockowner
);
915 BUG_ON(op
->status
== nfs_ok
);
920 if (op
->status
== NFSERR_REPLAY_ME
) {
921 op
->replay
= &replay_owner
->so_replay
;
922 nfsd4_encode_replay(resp
, op
);
923 status
= op
->status
= op
->replay
->rp_status
;
925 nfsd4_encode_operation(resp
, op
);
928 if (replay_owner
&& (replay_owner
!= (void *)(-1))) {
929 nfs4_put_stateowner(replay_owner
);
932 /* XXX Ugh, we need to get rid of this kind of special case: */
933 if (op
->opnum
== OP_READ
&& op
->u
.read
.rd_filp
)
934 fput(op
->u
.read
.rd_filp
);
938 nfsd4_release_compoundargs(args
);
948 #define nfs4svc_decode_voidargs NULL
949 #define nfs4svc_release_void NULL
950 #define nfsd4_voidres nfsd4_voidargs
951 #define nfs4svc_release_compound NULL
952 struct nfsd4_voidargs
{ int dummy
; };
954 #define PROC(name, argt, rest, relt, cache, respsize) \
955 { (svc_procfunc) nfsd4_proc_##name, \
956 (kxdrproc_t) nfs4svc_decode_##argt##args, \
957 (kxdrproc_t) nfs4svc_encode_##rest##res, \
958 (kxdrproc_t) nfs4svc_release_##relt, \
959 sizeof(struct nfsd4_##argt##args), \
960 sizeof(struct nfsd4_##rest##res), \
967 * TODO: At the present time, the NFSv4 server does not do XID caching
968 * of requests. Implementing XID caching would not be a serious problem,
969 * although it would require a mild change in interfaces since one
970 * doesn't know whether an NFSv4 request is idempotent until after the
971 * XDR decode. However, XID caching totally confuses pynfs (Peter
972 * Astrand's regression testsuite for NFSv4 servers), which reuses
973 * XID's liberally, so I've left it unimplemented until pynfs generates
976 static struct svc_procedure nfsd_procedures4
[2] = {
977 PROC(null
, void, void, void, RC_NOCACHE
, 1),
978 PROC(compound
, compound
, compound
, compound
, RC_NOCACHE
, NFSD_BUFSIZE
/4)
981 struct svc_version nfsd_version4
= {
984 .vs_proc
= nfsd_procedures4
,
985 .vs_dispatch
= nfsd_dispatch
,
986 .vs_xdrsize
= NFS4_SVC_XDRSIZE
,