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>
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>
55 #include <linux/nfs4_acl.h>
57 #define NFSDDBG_FACILITY NFSDDBG_PROC
60 fh_dup2(struct svc_fh
*dst
, struct svc_fh
*src
)
65 cache_get(&src
->fh_export
->h
);
70 do_open_permission(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
)
74 if (open
->op_truncate
&&
75 !(open
->op_share_access
& NFS4_SHARE_ACCESS_WRITE
))
79 if (open
->op_share_access
& NFS4_SHARE_ACCESS_READ
)
81 if (open
->op_share_deny
& NFS4_SHARE_ACCESS_WRITE
)
82 accmode
|= (MAY_WRITE
| MAY_TRUNC
);
83 accmode
|= MAY_OWNER_OVERRIDE
;
85 status
= fh_verify(rqstp
, current_fh
, S_IFREG
, accmode
);
91 do_open_lookup(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
)
96 fh_init(&resfh
, NFS4_FHSIZE
);
97 open
->op_truncate
= 0;
99 if (open
->op_create
) {
101 * Note: create modes (UNCHECKED,GUARDED...) are the same
104 status
= nfsd_create_v3(rqstp
, current_fh
, open
->op_fname
.data
,
105 open
->op_fname
.len
, &open
->op_iattr
,
106 &resfh
, open
->op_createmode
,
107 (u32
*)open
->op_verf
.data
, &open
->op_truncate
);
110 status
= nfsd_lookup(rqstp
, current_fh
,
111 open
->op_fname
.data
, open
->op_fname
.len
, &resfh
);
112 fh_unlock(current_fh
);
116 set_change_info(&open
->op_cinfo
, current_fh
);
118 /* set reply cache */
119 fh_dup2(current_fh
, &resfh
);
120 /* XXXJBF: keep a saved svc_fh struct instead?? */
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
;
158 status
= do_open_permission(rqstp
, current_fh
, open
);
165 * nfs4_unlock_state() called in encode
168 nfsd4_open(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_open
*open
)
171 dprintk("NFSD: nfsd4_open filename %.*s op_stateowner %p\n",
172 (int)open
->op_fname
.len
, open
->op_fname
.data
,
173 open
->op_stateowner
);
175 if (nfs4_in_grace() && open
->op_claim_type
!= NFS4_OPEN_CLAIM_PREVIOUS
)
178 if (!nfs4_in_grace() && open
->op_claim_type
== NFS4_OPEN_CLAIM_PREVIOUS
)
179 return nfserr_no_grace
;
181 /* This check required by spec. */
182 if (open
->op_create
&& open
->op_claim_type
!= NFS4_OPEN_CLAIM_NULL
)
185 open
->op_stateowner
= NULL
;
188 /* check seqid for replay. set nfs4_owner */
189 status
= nfsd4_process_open1(open
);
190 if (status
== NFSERR_REPLAY_ME
) {
191 struct nfs4_replay
*rp
= &open
->op_stateowner
->so_replay
;
193 current_fh
->fh_handle
.fh_size
= rp
->rp_openfh_len
;
194 memcpy(¤t_fh
->fh_handle
.fh_base
, rp
->rp_openfh
,
196 status
= fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
198 dprintk("nfsd4_open: replay failed"
199 " restoring previous filehandle\n");
201 status
= NFSERR_REPLAY_ME
;
205 if (open
->op_claim_type
== NFS4_OPEN_CLAIM_NULL
) {
207 * This block of code will (1) set CURRENT_FH to the file being opened,
208 * creating it if necessary, (2) set open->op_cinfo,
209 * (3) set open->op_truncate if the file is to be truncated
210 * after opening, (4) do permission checking.
212 status
= do_open_lookup(rqstp
, current_fh
, open
);
215 } else if (open
->op_claim_type
== NFS4_OPEN_CLAIM_PREVIOUS
) {
217 * The CURRENT_FH is already set to the file being opened. This
218 * block of code will (1) set open->op_cinfo, (2) set
219 * open->op_truncate if the file is to be truncated after opening,
220 * (3) do permission checking.
222 status
= do_open_fhandle(rqstp
, current_fh
, open
);
226 printk("NFSD: unsupported OPEN claim type\n");
230 * nfsd4_process_open2() does the actual opening of the file. If
231 * successful, it (1) truncates the file if open->op_truncate was
232 * set, (2) sets open->op_stateid, (3) sets open->op_delegation.
234 status
= nfsd4_process_open2(rqstp
, current_fh
, open
);
241 * filehandle-manipulating ops.
244 nfsd4_getfh(struct svc_fh
*current_fh
, struct svc_fh
**getfh
)
246 if (!current_fh
->fh_dentry
)
247 return nfserr_nofilehandle
;
254 nfsd4_putfh(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_putfh
*putfh
)
257 current_fh
->fh_handle
.fh_size
= putfh
->pf_fhlen
;
258 memcpy(¤t_fh
->fh_handle
.fh_base
, putfh
->pf_fhval
, putfh
->pf_fhlen
);
259 return fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
263 nfsd4_putrootfh(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
)
268 status
= exp_pseudoroot(rqstp
->rq_client
, current_fh
,
271 status
= nfsd_setuser(rqstp
, current_fh
->fh_export
);
276 nfsd4_restorefh(struct svc_fh
*current_fh
, struct svc_fh
*save_fh
)
278 if (!save_fh
->fh_dentry
)
279 return nfserr_restorefh
;
281 fh_dup2(current_fh
, save_fh
);
286 nfsd4_savefh(struct svc_fh
*current_fh
, struct svc_fh
*save_fh
)
288 if (!current_fh
->fh_dentry
)
289 return nfserr_nofilehandle
;
291 fh_dup2(save_fh
, current_fh
);
299 nfsd4_access(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_access
*access
)
301 if (access
->ac_req_access
& ~NFS3_ACCESS_FULL
)
304 access
->ac_resp_access
= access
->ac_req_access
;
305 return nfsd_access(rqstp
, current_fh
, &access
->ac_resp_access
, &access
->ac_supported
);
309 nfsd4_commit(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_commit
*commit
)
313 u32
*p
= (u32
*)commit
->co_verf
.data
;
314 *p
++ = nfssvc_boot
.tv_sec
;
315 *p
++ = nfssvc_boot
.tv_usec
;
317 status
= nfsd_commit(rqstp
, current_fh
, commit
->co_offset
, commit
->co_count
);
318 if (status
== nfserr_symlink
)
319 status
= nfserr_inval
;
324 nfsd4_create(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_create
*create
)
330 fh_init(&resfh
, NFS4_FHSIZE
);
332 status
= fh_verify(rqstp
, current_fh
, S_IFDIR
, MAY_CREATE
);
333 if (status
== nfserr_symlink
)
334 status
= nfserr_notdir
;
338 switch (create
->cr_type
) {
340 /* ugh! we have to null-terminate the linktext, or
341 * vfs_symlink() will choke. it is always safe to
342 * null-terminate by brute force, since at worst we
343 * will overwrite the first byte of the create namelen
344 * in the XDR buffer, which has already been extracted
347 create
->cr_linkname
[create
->cr_linklen
] = 0;
349 status
= nfsd_symlink(rqstp
, current_fh
, create
->cr_name
,
350 create
->cr_namelen
, create
->cr_linkname
,
351 create
->cr_linklen
, &resfh
, &create
->cr_iattr
);
355 rdev
= MKDEV(create
->cr_specdata1
, create
->cr_specdata2
);
356 if (MAJOR(rdev
) != create
->cr_specdata1
||
357 MINOR(rdev
) != create
->cr_specdata2
)
359 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
360 create
->cr_namelen
, &create
->cr_iattr
,
361 S_IFBLK
, rdev
, &resfh
);
365 rdev
= MKDEV(create
->cr_specdata1
, create
->cr_specdata2
);
366 if (MAJOR(rdev
) != create
->cr_specdata1
||
367 MINOR(rdev
) != create
->cr_specdata2
)
369 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
370 create
->cr_namelen
, &create
->cr_iattr
,
371 S_IFCHR
, rdev
, &resfh
);
375 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
376 create
->cr_namelen
, &create
->cr_iattr
,
377 S_IFSOCK
, 0, &resfh
);
381 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
382 create
->cr_namelen
, &create
->cr_iattr
,
387 create
->cr_iattr
.ia_valid
&= ~ATTR_SIZE
;
388 status
= nfsd_create(rqstp
, current_fh
, create
->cr_name
,
389 create
->cr_namelen
, &create
->cr_iattr
,
394 status
= nfserr_badtype
;
398 fh_unlock(current_fh
);
399 set_change_info(&create
->cr_cinfo
, current_fh
);
400 fh_dup2(current_fh
, &resfh
);
408 nfsd4_getattr(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_getattr
*getattr
)
412 status
= fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
416 if (getattr
->ga_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
)
419 getattr
->ga_bmval
[0] &= NFSD_SUPPORTED_ATTRS_WORD0
;
420 getattr
->ga_bmval
[1] &= NFSD_SUPPORTED_ATTRS_WORD1
;
422 getattr
->ga_fhp
= current_fh
;
427 nfsd4_link(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
,
428 struct svc_fh
*save_fh
, struct nfsd4_link
*link
)
430 int status
= nfserr_nofilehandle
;
432 if (!save_fh
->fh_dentry
)
434 status
= nfsd_link(rqstp
, current_fh
, link
->li_name
, link
->li_namelen
, save_fh
);
436 set_change_info(&link
->li_cinfo
, current_fh
);
441 nfsd4_lookupp(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
)
443 struct svc_fh tmp_fh
;
446 fh_init(&tmp_fh
, NFS4_FHSIZE
);
447 if((ret
= exp_pseudoroot(rqstp
->rq_client
, &tmp_fh
,
448 &rqstp
->rq_chandle
)) != 0)
450 if (tmp_fh
.fh_dentry
== current_fh
->fh_dentry
) {
455 return nfsd_lookup(rqstp
, current_fh
, "..", 2, current_fh
);
459 nfsd4_lookup(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_lookup
*lookup
)
461 return nfsd_lookup(rqstp
, current_fh
, lookup
->lo_name
, lookup
->lo_len
, current_fh
);
465 access_bits_permit_read(unsigned long access_bmap
)
467 return test_bit(NFS4_SHARE_ACCESS_READ
, &access_bmap
) ||
468 test_bit(NFS4_SHARE_ACCESS_BOTH
, &access_bmap
);
472 access_bits_permit_write(unsigned long access_bmap
)
474 return test_bit(NFS4_SHARE_ACCESS_WRITE
, &access_bmap
) ||
475 test_bit(NFS4_SHARE_ACCESS_BOTH
, &access_bmap
);
479 nfsd4_read(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_read
*read
)
481 struct nfs4_stateid
*stp
;
484 /* no need to check permission - this will be done in nfsd_read() */
488 if (read
->rd_offset
>= OFFSET_MAX
)
493 /* For stateid -1, we don't check share reservations. */
494 if (ONE_STATEID(&read
->rd_stateid
)) {
495 dprintk("NFSD: nfsd4_read: -1 stateid...\n");
499 * For stateid 0, the client doesn't have to have the file open, but
500 * we still check for share reservation conflicts.
502 if (ZERO_STATEID(&read
->rd_stateid
)) {
503 dprintk("NFSD: nfsd4_read: zero stateid...\n");
504 if ((status
= nfs4_share_conflict(current_fh
, NFS4_SHARE_DENY_READ
))) {
505 dprintk("NFSD: nfsd4_read: conflicting share reservation!\n");
512 if ((status
= nfs4_preprocess_stateid_op(current_fh
, &read
->rd_stateid
,
513 CHECK_FH
| RDWR_STATE
, &stp
))) {
514 dprintk("NFSD: nfsd4_read: couldn't process stateid!\n");
517 status
= nfserr_openmode
;
518 if (!access_bits_permit_read(stp
->st_access_bmap
)) {
519 dprintk("NFSD: nfsd4_read: file not opened for read!\n");
525 read
->rd_rqstp
= rqstp
;
526 read
->rd_fhp
= current_fh
;
531 nfsd4_readdir(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_readdir
*readdir
)
533 u64 cookie
= readdir
->rd_cookie
;
534 static const nfs4_verifier zeroverf
;
536 /* no need to check permission - this will be done in nfsd_readdir() */
538 if (readdir
->rd_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
)
541 readdir
->rd_bmval
[0] &= NFSD_SUPPORTED_ATTRS_WORD0
;
542 readdir
->rd_bmval
[1] &= NFSD_SUPPORTED_ATTRS_WORD1
;
544 if ((cookie
> ~(u32
)0) || (cookie
== 1) || (cookie
== 2) ||
545 (cookie
== 0 && memcmp(readdir
->rd_verf
.data
, zeroverf
.data
, NFS4_VERIFIER_SIZE
)))
546 return nfserr_bad_cookie
;
548 readdir
->rd_rqstp
= rqstp
;
549 readdir
->rd_fhp
= current_fh
;
554 nfsd4_readlink(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_readlink
*readlink
)
556 readlink
->rl_rqstp
= rqstp
;
557 readlink
->rl_fhp
= current_fh
;
562 nfsd4_remove(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_remove
*remove
)
566 status
= nfsd_unlink(rqstp
, current_fh
, 0, remove
->rm_name
, remove
->rm_namelen
);
567 if (status
== nfserr_symlink
)
568 return nfserr_notdir
;
570 fh_unlock(current_fh
);
571 set_change_info(&remove
->rm_cinfo
, current_fh
);
577 nfsd4_rename(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
,
578 struct svc_fh
*save_fh
, struct nfsd4_rename
*rename
)
580 int status
= nfserr_nofilehandle
;
582 if (!save_fh
->fh_dentry
)
584 status
= nfsd_rename(rqstp
, save_fh
, rename
->rn_sname
,
585 rename
->rn_snamelen
, current_fh
,
586 rename
->rn_tname
, rename
->rn_tnamelen
);
588 /* the underlying filesystem returns different error's than required
589 * by NFSv4. both save_fh and current_fh have been verified.. */
590 if (status
== nfserr_isdir
)
591 status
= nfserr_exist
;
592 else if ((status
== nfserr_notdir
) &&
593 (S_ISDIR(save_fh
->fh_dentry
->d_inode
->i_mode
) &&
594 S_ISDIR(current_fh
->fh_dentry
->d_inode
->i_mode
)))
595 status
= nfserr_exist
;
596 else if (status
== nfserr_symlink
)
597 status
= nfserr_notdir
;
600 set_change_info(&rename
->rn_sinfo
, current_fh
);
601 set_change_info(&rename
->rn_tinfo
, save_fh
);
607 nfsd4_setattr(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_setattr
*setattr
)
609 struct nfs4_stateid
*stp
;
615 if (!current_fh
->fh_dentry
)
616 return nfserr_nofilehandle
;
619 if (setattr
->sa_iattr
.ia_valid
& ATTR_SIZE
) {
621 status
= nfserr_bad_stateid
;
622 if (ZERO_STATEID(&setattr
->sa_stateid
) || ONE_STATEID(&setattr
->sa_stateid
)) {
623 dprintk("NFSD: nfsd4_setattr: magic stateid!\n");
628 if ((status
= nfs4_preprocess_stateid_op(current_fh
,
629 &setattr
->sa_stateid
,
630 CHECK_FH
| RDWR_STATE
, &stp
))) {
631 dprintk("NFSD: nfsd4_setattr: couldn't process stateid!\n");
634 status
= nfserr_openmode
;
635 if (!access_bits_permit_write(stp
->st_access_bmap
)) {
636 dprintk("NFSD: nfsd4_setattr: not opened for write!\n");
642 if (setattr
->sa_acl
!= NULL
)
643 status
= nfsd4_set_nfs4_acl(rqstp
, current_fh
, setattr
->sa_acl
);
646 status
= nfsd_setattr(rqstp
, current_fh
, &setattr
->sa_iattr
,
656 nfsd4_write(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_write
*write
)
658 struct nfs4_stateid
*stp
;
659 stateid_t
*stateid
= &write
->wr_stateid
;
666 /* no need to check permission - this will be done in nfsd_write() */
668 if (write
->wr_offset
>= OFFSET_MAX
)
672 if (ZERO_STATEID(stateid
) || ONE_STATEID(stateid
)) {
673 dprintk("NFSD: nfsd4_write: zero stateid...\n");
674 if ((status
= nfs4_share_conflict(current_fh
, NFS4_SHARE_DENY_WRITE
))) {
675 dprintk("NFSD: nfsd4_write: conflicting share reservation!\n");
680 if ((status
= nfs4_preprocess_stateid_op(current_fh
, stateid
,
681 CHECK_FH
| RDWR_STATE
, &stp
))) {
682 dprintk("NFSD: nfsd4_write: couldn't process stateid!\n");
686 status
= nfserr_openmode
;
687 if (!access_bits_permit_write(stp
->st_access_bmap
)) {
688 dprintk("NFSD: nfsd4_write: file not open for write!\n");
694 write
->wr_bytes_written
= write
->wr_buflen
;
695 write
->wr_how_written
= write
->wr_stable_how
;
696 p
= (u32
*)write
->wr_verifier
.data
;
697 *p
++ = nfssvc_boot
.tv_sec
;
698 *p
++ = nfssvc_boot
.tv_usec
;
700 status
= nfsd_write(rqstp
, current_fh
, write
->wr_offset
,
701 write
->wr_vec
, write
->wr_vlen
, write
->wr_buflen
,
702 &write
->wr_how_written
);
703 if (status
== nfserr_symlink
)
704 status
= nfserr_inval
;
711 /* This routine never returns NFS_OK! If there are no other errors, it
712 * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
713 * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
714 * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
717 nfsd4_verify(struct svc_rqst
*rqstp
, struct svc_fh
*current_fh
, struct nfsd4_verify
*verify
)
723 status
= fh_verify(rqstp
, current_fh
, 0, MAY_NOP
);
727 if ((verify
->ve_bmval
[0] & ~NFSD_SUPPORTED_ATTRS_WORD0
)
728 || (verify
->ve_bmval
[1] & ~NFSD_SUPPORTED_ATTRS_WORD1
))
729 return nfserr_attrnotsupp
;
730 if ((verify
->ve_bmval
[0] & FATTR4_WORD0_RDATTR_ERROR
)
731 || (verify
->ve_bmval
[1] & NFSD_WRITEONLY_ATTRS_WORD1
))
733 if (verify
->ve_attrlen
& 3)
737 * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
739 count
= 4 + (verify
->ve_attrlen
>> 2);
740 buf
= kmalloc(count
<< 2, GFP_KERNEL
);
742 return nfserr_resource
;
744 status
= nfsd4_encode_fattr(current_fh
, current_fh
->fh_export
,
745 current_fh
->fh_dentry
, buf
,
746 &count
, verify
->ve_bmval
,
749 /* this means that nfsd4_encode_fattr() ran out of space */
750 if (status
== nfserr_resource
&& count
== 0)
751 status
= nfserr_not_same
;
756 status
= nfserr_not_same
;
757 if (ntohl(*p
++) != verify
->ve_attrlen
)
759 if (!memcmp(p
, verify
->ve_attrval
, verify
->ve_attrlen
))
760 status
= nfserr_same
;
771 nfsd4_proc_null(struct svc_rqst
*rqstp
, void *argp
, void *resp
)
781 nfsd4_proc_compound(struct svc_rqst
*rqstp
,
782 struct nfsd4_compoundargs
*args
,
783 struct nfsd4_compoundres
*resp
)
786 struct svc_fh
*current_fh
= NULL
;
787 struct svc_fh
*save_fh
= NULL
;
788 int slack_space
; /* in words, not bytes! */
791 status
= nfserr_resource
;
792 current_fh
= kmalloc(sizeof(*current_fh
), GFP_KERNEL
);
793 if (current_fh
== NULL
)
795 fh_init(current_fh
, NFS4_FHSIZE
);
796 save_fh
= kmalloc(sizeof(*save_fh
), GFP_KERNEL
);
799 fh_init(save_fh
, NFS4_FHSIZE
);
801 resp
->xbuf
= &rqstp
->rq_res
;
802 resp
->p
= rqstp
->rq_res
.head
[0].iov_base
+ rqstp
->rq_res
.head
[0].iov_len
;
803 resp
->tagp
= resp
->p
;
804 /* reserve space for: taglen, tag, and opcnt */
805 resp
->p
+= 2 + XDR_QUADLEN(args
->taglen
);
806 resp
->end
= rqstp
->rq_res
.head
[0].iov_base
+ PAGE_SIZE
;
807 resp
->taglen
= args
->taglen
;
808 resp
->tag
= args
->tag
;
813 * According to RFC3010, this takes precedence over all other errors.
815 status
= nfserr_minor_vers_mismatch
;
816 if (args
->minorversion
> NFSD_SUPPORTED_MINOR_VERSION
)
820 while (!status
&& resp
->opcnt
< args
->opcnt
) {
821 op
= &args
->ops
[resp
->opcnt
++];
824 * The XDR decode routines may have pre-set op->status;
825 * for example, if there is a miscellaneous XDR error
826 * it will be set to nfserr_bad_xdr.
831 /* We must be able to encode a successful response to
832 * this operation, with enough room left over to encode a
833 * failed response to the next operation. If we don't
834 * have enough room, fail with ERR_RESOURCE.
836 /* FIXME - is slack_space *really* words, or bytes??? - neilb */
837 slack_space
= (char *)resp
->end
- (char *)resp
->p
;
838 if (slack_space
< COMPOUND_SLACK_SPACE
+ COMPOUND_ERR_SLACK_SPACE
) {
839 BUG_ON(slack_space
< COMPOUND_ERR_SLACK_SPACE
);
840 op
->status
= nfserr_resource
;
844 /* All operations except RENEW, SETCLIENTID, RESTOREFH
845 * SETCLIENTID_CONFIRM, PUTFH and PUTROOTFH
846 * require a valid current filehandle
848 * SETATTR NOFILEHANDLE error handled in nfsd4_setattr
849 * due to required returned bitmap argument
851 if ((!current_fh
->fh_dentry
) &&
852 !((op
->opnum
== OP_PUTFH
) || (op
->opnum
== OP_PUTROOTFH
) ||
853 (op
->opnum
== OP_SETCLIENTID
) ||
854 (op
->opnum
== OP_SETCLIENTID_CONFIRM
) ||
855 (op
->opnum
== OP_RENEW
) || (op
->opnum
== OP_RESTOREFH
) ||
856 (op
->opnum
== OP_RELEASE_LOCKOWNER
) ||
857 (op
->opnum
== OP_SETATTR
))) {
858 op
->status
= nfserr_nofilehandle
;
863 op
->status
= nfsd4_access(rqstp
, current_fh
, &op
->u
.access
);
866 op
->status
= nfsd4_close(rqstp
, current_fh
, &op
->u
.close
);
867 if (op
->u
.close
.cl_stateowner
)
869 &op
->u
.close
.cl_stateowner
->so_replay
;
872 op
->status
= nfsd4_commit(rqstp
, current_fh
, &op
->u
.commit
);
875 op
->status
= nfsd4_create(rqstp
, current_fh
, &op
->u
.create
);
878 op
->status
= nfsd4_getattr(rqstp
, current_fh
, &op
->u
.getattr
);
881 op
->status
= nfsd4_getfh(current_fh
, &op
->u
.getfh
);
884 op
->status
= nfsd4_link(rqstp
, current_fh
, save_fh
, &op
->u
.link
);
887 op
->status
= nfsd4_lock(rqstp
, current_fh
, &op
->u
.lock
);
888 if (op
->u
.lock
.lk_stateowner
)
890 &op
->u
.lock
.lk_stateowner
->so_replay
;
893 op
->status
= nfsd4_lockt(rqstp
, current_fh
, &op
->u
.lockt
);
896 op
->status
= nfsd4_locku(rqstp
, current_fh
, &op
->u
.locku
);
897 if (op
->u
.locku
.lu_stateowner
)
899 &op
->u
.locku
.lu_stateowner
->so_replay
;
902 op
->status
= nfsd4_lookup(rqstp
, current_fh
, &op
->u
.lookup
);
905 op
->status
= nfsd4_lookupp(rqstp
, current_fh
);
908 op
->status
= nfsd4_verify(rqstp
, current_fh
, &op
->u
.nverify
);
909 if (op
->status
== nfserr_not_same
)
913 op
->status
= nfsd4_open(rqstp
, current_fh
, &op
->u
.open
);
914 if (op
->u
.open
.op_stateowner
)
916 &op
->u
.open
.op_stateowner
->so_replay
;
918 case OP_OPEN_CONFIRM
:
919 op
->status
= nfsd4_open_confirm(rqstp
, current_fh
, &op
->u
.open_confirm
);
920 if (op
->u
.open_confirm
.oc_stateowner
)
922 &op
->u
.open_confirm
.oc_stateowner
->so_replay
;
924 case OP_OPEN_DOWNGRADE
:
925 op
->status
= nfsd4_open_downgrade(rqstp
, current_fh
, &op
->u
.open_downgrade
);
926 if (op
->u
.open_downgrade
.od_stateowner
)
928 &op
->u
.open_downgrade
.od_stateowner
->so_replay
;
931 op
->status
= nfsd4_putfh(rqstp
, current_fh
, &op
->u
.putfh
);
934 op
->status
= nfsd4_putrootfh(rqstp
, current_fh
);
937 op
->status
= nfsd4_read(rqstp
, current_fh
, &op
->u
.read
);
940 op
->status
= nfsd4_readdir(rqstp
, current_fh
, &op
->u
.readdir
);
943 op
->status
= nfsd4_readlink(rqstp
, current_fh
, &op
->u
.readlink
);
946 op
->status
= nfsd4_remove(rqstp
, current_fh
, &op
->u
.remove
);
949 op
->status
= nfsd4_rename(rqstp
, current_fh
, save_fh
, &op
->u
.rename
);
952 op
->status
= nfsd4_renew(&op
->u
.renew
);
955 op
->status
= nfsd4_restorefh(current_fh
, save_fh
);
958 op
->status
= nfsd4_savefh(current_fh
, save_fh
);
961 op
->status
= nfsd4_setattr(rqstp
, current_fh
, &op
->u
.setattr
);
964 op
->status
= nfsd4_setclientid(rqstp
, &op
->u
.setclientid
);
966 case OP_SETCLIENTID_CONFIRM
:
967 op
->status
= nfsd4_setclientid_confirm(rqstp
, &op
->u
.setclientid_confirm
);
970 op
->status
= nfsd4_verify(rqstp
, current_fh
, &op
->u
.verify
);
971 if (op
->status
== nfserr_same
)
975 op
->status
= nfsd4_write(rqstp
, current_fh
, &op
->u
.write
);
977 case OP_RELEASE_LOCKOWNER
:
978 op
->status
= nfsd4_release_lockowner(rqstp
, &op
->u
.release_lockowner
);
981 BUG_ON(op
->status
== nfs_ok
);
986 if (op
->status
== NFSERR_REPLAY_ME
) {
987 nfsd4_encode_replay(resp
, op
);
988 status
= op
->status
= op
->replay
->rp_status
;
990 nfsd4_encode_operation(resp
, op
);
996 nfsd4_release_compoundargs(args
);
1006 #define nfs4svc_decode_voidargs NULL
1007 #define nfs4svc_release_void NULL
1008 #define nfsd4_voidres nfsd4_voidargs
1009 #define nfs4svc_release_compound NULL
1010 struct nfsd4_voidargs
{ int dummy
; };
1012 #define PROC(name, argt, rest, relt, cache, respsize) \
1013 { (svc_procfunc) nfsd4_proc_##name, \
1014 (kxdrproc_t) nfs4svc_decode_##argt##args, \
1015 (kxdrproc_t) nfs4svc_encode_##rest##res, \
1016 (kxdrproc_t) nfs4svc_release_##relt, \
1017 sizeof(struct nfsd4_##argt##args), \
1018 sizeof(struct nfsd4_##rest##res), \
1025 * TODO: At the present time, the NFSv4 server does not do XID caching
1026 * of requests. Implementing XID caching would not be a serious problem,
1027 * although it would require a mild change in interfaces since one
1028 * doesn't know whether an NFSv4 request is idempotent until after the
1029 * XDR decode. However, XID caching totally confuses pynfs (Peter
1030 * Astrand's regression testsuite for NFSv4 servers), which reuses
1031 * XID's liberally, so I've left it unimplemented until pynfs generates
1034 static struct svc_procedure nfsd_procedures4
[2] = {
1035 PROC(null
, void, void, void, RC_NOCACHE
, 1),
1036 PROC(compound
, compound
, compound
, compound
, RC_NOCACHE
, NFSD_BUFSIZE
)
1039 struct svc_version nfsd_version4
= {
1042 .vs_proc
= nfsd_procedures4
,
1043 .vs_dispatch
= nfsd_dispatch
,
1044 .vs_xdrsize
= NFS4_SVC_XDRSIZE
,