4 * Server-side XDR 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 * TODO: Neil Brown made the following observation: We currently
38 * initially reserve NFSD_BUFSIZE space on the transmit queue and
39 * never release any of that until the request is complete.
40 * It would be good to calculate a new maximum response size while
41 * decoding the COMPOUND, and call svc_reserve with this number
42 * at the end of nfs4svc_decode_compoundargs.
45 #include <linux/param.h>
46 #include <linux/smp.h>
48 #include <linux/namei.h>
49 #include <linux/vfs.h>
50 #include <linux/sunrpc/xdr.h>
51 #include <linux/sunrpc/svc.h>
52 #include <linux/sunrpc/clnt.h>
53 #include <linux/nfsd/nfsd.h>
54 #include <linux/nfsd/state.h>
55 #include <linux/nfsd/xdr4.h>
56 #include <linux/nfsd_idmap.h>
57 #include <linux/nfs4.h>
58 #include <linux/nfs4_acl.h>
59 #include <linux/sunrpc/gss_api.h>
60 #include <linux/sunrpc/svcauth_gss.h>
62 #define NFSDDBG_FACILITY NFSDDBG_XDR
65 * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
66 * directory in order to indicate to the client that a filesystem boundary is present
67 * We use a fixed fsid for a referral
69 #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
70 #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
73 check_filename(char *str
, int len
, __be32 err
)
79 if (isdotent(str
, len
))
81 for (i
= 0; i
< len
; i
++)
88 * START OF "GENERIC" DECODE ROUTINES.
89 * These may look a little ugly since they are imported from a "generic"
90 * set of XDR encode/decode routines which are intended to be shared by
91 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
93 * If the pain of reading these is too great, it should be a straightforward
94 * task to translate them into Linux-specific versions which are more
95 * consistent with the style used in NFSv2/v3...
100 #define DECODE_TAIL \
105 dprintk("NFSD: xdr error (%s:%d)\n", \
106 __FILE__, __LINE__); \
107 status = nfserr_bad_xdr; \
110 #define READ32(x) (x) = ntohl(*p++)
111 #define READ64(x) do { \
112 (x) = (u64)ntohl(*p++) << 32; \
113 (x) |= ntohl(*p++); \
115 #define READTIME(x) do { \
120 #define READMEM(x,nbytes) do { \
122 p += XDR_QUADLEN(nbytes); \
124 #define SAVEMEM(x,nbytes) do { \
125 if (!(x = (p==argp->tmp || p == argp->tmpp) ? \
126 savemem(argp, p, nbytes) : \
128 dprintk("NFSD: xdr error (%s:%d)\n", \
129 __FILE__, __LINE__); \
132 p += XDR_QUADLEN(nbytes); \
134 #define COPYMEM(x,nbytes) do { \
135 memcpy((x), p, nbytes); \
136 p += XDR_QUADLEN(nbytes); \
139 /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */
140 #define READ_BUF(nbytes) do { \
141 if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \
143 argp->p += XDR_QUADLEN(nbytes); \
144 } else if (!(p = read_buf(argp, nbytes))) { \
145 dprintk("NFSD: xdr error (%s:%d)\n", \
146 __FILE__, __LINE__); \
151 static __be32
*read_buf(struct nfsd4_compoundargs
*argp
, u32 nbytes
)
153 /* We want more bytes than seem to be available.
154 * Maybe we need a new page, maybe we have just run out
156 unsigned int avail
= (char *)argp
->end
- (char *)argp
->p
;
158 if (avail
+ argp
->pagelen
< nbytes
)
160 if (avail
+ PAGE_SIZE
< nbytes
) /* need more than a page !! */
162 /* ok, we can do it with the current plus the next page */
163 if (nbytes
<= sizeof(argp
->tmp
))
167 p
= argp
->tmpp
= kmalloc(nbytes
, GFP_KERNEL
);
173 * The following memcpy is safe because read_buf is always
174 * called with nbytes > avail, and the two cases above both
175 * guarantee p points to at least nbytes bytes.
177 memcpy(p
, argp
->p
, avail
);
178 /* step to next page */
179 argp
->p
= page_address(argp
->pagelist
[0]);
181 if (argp
->pagelen
< PAGE_SIZE
) {
182 argp
->end
= p
+ (argp
->pagelen
>>2);
185 argp
->end
= p
+ (PAGE_SIZE
>>2);
186 argp
->pagelen
-= PAGE_SIZE
;
188 memcpy(((char*)p
)+avail
, argp
->p
, (nbytes
- avail
));
189 argp
->p
+= XDR_QUADLEN(nbytes
- avail
);
194 defer_free(struct nfsd4_compoundargs
*argp
,
195 void (*release
)(const void *), void *p
)
199 tb
= kmalloc(sizeof(*tb
), GFP_KERNEL
);
203 tb
->release
= release
;
204 tb
->next
= argp
->to_free
;
209 static char *savemem(struct nfsd4_compoundargs
*argp
, __be32
*p
, int nbytes
)
211 if (p
== argp
->tmp
) {
212 p
= kmalloc(nbytes
, GFP_KERNEL
);
215 memcpy(p
, argp
->tmp
, nbytes
);
217 BUG_ON(p
!= argp
->tmpp
);
220 if (defer_free(argp
, kfree
, p
)) {
228 nfsd4_decode_bitmap(struct nfsd4_compoundargs
*argp
, u32
*bmval
)
241 READ_BUF(bmlen
<< 2);
251 nfsd4_decode_fattr(struct nfsd4_compoundargs
*argp
, u32
*bmval
, struct iattr
*iattr
,
252 struct nfs4_acl
**acl
)
254 int expected_len
, len
= 0;
261 if ((status
= nfsd4_decode_bitmap(argp
, bmval
)))
265 * According to spec, unsupported attributes return ERR_ATTRNOTSUPP;
266 * read-only attributes return ERR_INVAL.
268 if ((bmval
[0] & ~NFSD_SUPPORTED_ATTRS_WORD0
) || (bmval
[1] & ~NFSD_SUPPORTED_ATTRS_WORD1
))
269 return nfserr_attrnotsupp
;
270 if ((bmval
[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
) || (bmval
[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
))
274 READ32(expected_len
);
276 if (bmval
[0] & FATTR4_WORD0_SIZE
) {
279 READ64(iattr
->ia_size
);
280 iattr
->ia_valid
|= ATTR_SIZE
;
282 if (bmval
[0] & FATTR4_WORD0_ACL
) {
284 struct nfs4_ace
*ace
;
286 READ_BUF(4); len
+= 4;
289 if (nace
> NFS4_ACL_MAX
)
290 return nfserr_resource
;
292 *acl
= nfs4_acl_new(nace
);
297 defer_free(argp
, kfree
, *acl
);
299 (*acl
)->naces
= nace
;
300 for (ace
= (*acl
)->aces
; ace
< (*acl
)->aces
+ nace
; ace
++) {
301 READ_BUF(16); len
+= 16;
304 READ32(ace
->access_mask
);
307 len
+= XDR_QUADLEN(dummy32
) << 2;
308 READMEM(buf
, dummy32
);
309 ace
->whotype
= nfs4_acl_get_whotype(buf
, dummy32
);
311 if (ace
->whotype
!= NFS4_ACL_WHO_NAMED
)
313 else if (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
)
314 host_err
= nfsd_map_name_to_gid(argp
->rqstp
,
315 buf
, dummy32
, &ace
->who
);
317 host_err
= nfsd_map_name_to_uid(argp
->rqstp
,
318 buf
, dummy32
, &ace
->who
);
324 if (bmval
[1] & FATTR4_WORD1_MODE
) {
327 READ32(iattr
->ia_mode
);
328 iattr
->ia_mode
&= (S_IFMT
| S_IALLUGO
);
329 iattr
->ia_valid
|= ATTR_MODE
;
331 if (bmval
[1] & FATTR4_WORD1_OWNER
) {
336 len
+= (XDR_QUADLEN(dummy32
) << 2);
337 READMEM(buf
, dummy32
);
338 if ((host_err
= nfsd_map_name_to_uid(argp
->rqstp
, buf
, dummy32
, &iattr
->ia_uid
)))
340 iattr
->ia_valid
|= ATTR_UID
;
342 if (bmval
[1] & FATTR4_WORD1_OWNER_GROUP
) {
347 len
+= (XDR_QUADLEN(dummy32
) << 2);
348 READMEM(buf
, dummy32
);
349 if ((host_err
= nfsd_map_name_to_gid(argp
->rqstp
, buf
, dummy32
, &iattr
->ia_gid
)))
351 iattr
->ia_valid
|= ATTR_GID
;
353 if (bmval
[1] & FATTR4_WORD1_TIME_ACCESS_SET
) {
358 case NFS4_SET_TO_CLIENT_TIME
:
359 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
360 all 32 bits of 'nseconds'. */
366 READ32(iattr
->ia_atime
.tv_sec
);
367 READ32(iattr
->ia_atime
.tv_nsec
);
368 if (iattr
->ia_atime
.tv_nsec
>= (u32
)1000000000)
370 iattr
->ia_valid
|= (ATTR_ATIME
| ATTR_ATIME_SET
);
372 case NFS4_SET_TO_SERVER_TIME
:
373 iattr
->ia_valid
|= ATTR_ATIME
;
379 if (bmval
[1] & FATTR4_WORD1_TIME_METADATA
) {
380 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
381 all 32 bits of 'nseconds'. */
387 READ32(iattr
->ia_ctime
.tv_sec
);
388 READ32(iattr
->ia_ctime
.tv_nsec
);
389 if (iattr
->ia_ctime
.tv_nsec
>= (u32
)1000000000)
391 iattr
->ia_valid
|= ATTR_CTIME
;
393 if (bmval
[1] & FATTR4_WORD1_TIME_MODIFY_SET
) {
398 case NFS4_SET_TO_CLIENT_TIME
:
399 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
400 all 32 bits of 'nseconds'. */
406 READ32(iattr
->ia_mtime
.tv_sec
);
407 READ32(iattr
->ia_mtime
.tv_nsec
);
408 if (iattr
->ia_mtime
.tv_nsec
>= (u32
)1000000000)
410 iattr
->ia_valid
|= (ATTR_MTIME
| ATTR_MTIME_SET
);
412 case NFS4_SET_TO_SERVER_TIME
:
413 iattr
->ia_valid
|= ATTR_MTIME
;
419 if (len
!= expected_len
)
425 status
= nfserrno(host_err
);
430 nfsd4_decode_access(struct nfsd4_compoundargs
*argp
, struct nfsd4_access
*access
)
435 READ32(access
->ac_req_access
);
441 nfsd4_decode_close(struct nfsd4_compoundargs
*argp
, struct nfsd4_close
*close
)
445 close
->cl_stateowner
= NULL
;
446 READ_BUF(4 + sizeof(stateid_t
));
447 READ32(close
->cl_seqid
);
448 READ32(close
->cl_stateid
.si_generation
);
449 COPYMEM(&close
->cl_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
456 nfsd4_decode_commit(struct nfsd4_compoundargs
*argp
, struct nfsd4_commit
*commit
)
461 READ64(commit
->co_offset
);
462 READ32(commit
->co_count
);
468 nfsd4_decode_create(struct nfsd4_compoundargs
*argp
, struct nfsd4_create
*create
)
473 READ32(create
->cr_type
);
474 switch (create
->cr_type
) {
477 READ32(create
->cr_linklen
);
478 READ_BUF(create
->cr_linklen
);
479 SAVEMEM(create
->cr_linkname
, create
->cr_linklen
);
484 READ32(create
->cr_specdata1
);
485 READ32(create
->cr_specdata2
);
495 READ32(create
->cr_namelen
);
496 READ_BUF(create
->cr_namelen
);
497 SAVEMEM(create
->cr_name
, create
->cr_namelen
);
498 if ((status
= check_filename(create
->cr_name
, create
->cr_namelen
, nfserr_inval
)))
501 if ((status
= nfsd4_decode_fattr(argp
, create
->cr_bmval
, &create
->cr_iattr
, &create
->cr_acl
)))
508 nfsd4_decode_delegreturn(struct nfsd4_compoundargs
*argp
, struct nfsd4_delegreturn
*dr
)
512 READ_BUF(sizeof(stateid_t
));
513 READ32(dr
->dr_stateid
.si_generation
);
514 COPYMEM(&dr
->dr_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
520 nfsd4_decode_getattr(struct nfsd4_compoundargs
*argp
, struct nfsd4_getattr
*getattr
)
522 return nfsd4_decode_bitmap(argp
, getattr
->ga_bmval
);
526 nfsd4_decode_link(struct nfsd4_compoundargs
*argp
, struct nfsd4_link
*link
)
531 READ32(link
->li_namelen
);
532 READ_BUF(link
->li_namelen
);
533 SAVEMEM(link
->li_name
, link
->li_namelen
);
534 if ((status
= check_filename(link
->li_name
, link
->li_namelen
, nfserr_inval
)))
541 nfsd4_decode_lock(struct nfsd4_compoundargs
*argp
, struct nfsd4_lock
*lock
)
545 lock
->lk_replay_owner
= NULL
;
547 * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
550 READ32(lock
->lk_type
);
551 if ((lock
->lk_type
< NFS4_READ_LT
) || (lock
->lk_type
> NFS4_WRITEW_LT
))
553 READ32(lock
->lk_reclaim
);
554 READ64(lock
->lk_offset
);
555 READ64(lock
->lk_length
);
556 READ32(lock
->lk_is_new
);
558 if (lock
->lk_is_new
) {
560 READ32(lock
->lk_new_open_seqid
);
561 READ32(lock
->lk_new_open_stateid
.si_generation
);
563 COPYMEM(&lock
->lk_new_open_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
564 READ32(lock
->lk_new_lock_seqid
);
565 COPYMEM(&lock
->lk_new_clientid
, sizeof(clientid_t
));
566 READ32(lock
->lk_new_owner
.len
);
567 READ_BUF(lock
->lk_new_owner
.len
);
568 READMEM(lock
->lk_new_owner
.data
, lock
->lk_new_owner
.len
);
571 READ32(lock
->lk_old_lock_stateid
.si_generation
);
572 COPYMEM(&lock
->lk_old_lock_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
573 READ32(lock
->lk_old_lock_seqid
);
580 nfsd4_decode_lockt(struct nfsd4_compoundargs
*argp
, struct nfsd4_lockt
*lockt
)
585 READ32(lockt
->lt_type
);
586 if((lockt
->lt_type
< NFS4_READ_LT
) || (lockt
->lt_type
> NFS4_WRITEW_LT
))
588 READ64(lockt
->lt_offset
);
589 READ64(lockt
->lt_length
);
590 COPYMEM(&lockt
->lt_clientid
, 8);
591 READ32(lockt
->lt_owner
.len
);
592 READ_BUF(lockt
->lt_owner
.len
);
593 READMEM(lockt
->lt_owner
.data
, lockt
->lt_owner
.len
);
599 nfsd4_decode_locku(struct nfsd4_compoundargs
*argp
, struct nfsd4_locku
*locku
)
603 locku
->lu_stateowner
= NULL
;
604 READ_BUF(24 + sizeof(stateid_t
));
605 READ32(locku
->lu_type
);
606 if ((locku
->lu_type
< NFS4_READ_LT
) || (locku
->lu_type
> NFS4_WRITEW_LT
))
608 READ32(locku
->lu_seqid
);
609 READ32(locku
->lu_stateid
.si_generation
);
610 COPYMEM(&locku
->lu_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
611 READ64(locku
->lu_offset
);
612 READ64(locku
->lu_length
);
618 nfsd4_decode_lookup(struct nfsd4_compoundargs
*argp
, struct nfsd4_lookup
*lookup
)
623 READ32(lookup
->lo_len
);
624 READ_BUF(lookup
->lo_len
);
625 SAVEMEM(lookup
->lo_name
, lookup
->lo_len
);
626 if ((status
= check_filename(lookup
->lo_name
, lookup
->lo_len
, nfserr_noent
)))
633 nfsd4_decode_open(struct nfsd4_compoundargs
*argp
, struct nfsd4_open
*open
)
637 memset(open
->op_bmval
, 0, sizeof(open
->op_bmval
));
638 open
->op_iattr
.ia_valid
= 0;
639 open
->op_stateowner
= NULL
;
641 /* seqid, share_access, share_deny, clientid, ownerlen */
642 READ_BUF(16 + sizeof(clientid_t
));
643 READ32(open
->op_seqid
);
644 READ32(open
->op_share_access
);
645 READ32(open
->op_share_deny
);
646 COPYMEM(&open
->op_clientid
, sizeof(clientid_t
));
647 READ32(open
->op_owner
.len
);
649 /* owner, open_flag */
650 READ_BUF(open
->op_owner
.len
+ 4);
651 SAVEMEM(open
->op_owner
.data
, open
->op_owner
.len
);
652 READ32(open
->op_create
);
653 switch (open
->op_create
) {
654 case NFS4_OPEN_NOCREATE
:
656 case NFS4_OPEN_CREATE
:
658 READ32(open
->op_createmode
);
659 switch (open
->op_createmode
) {
660 case NFS4_CREATE_UNCHECKED
:
661 case NFS4_CREATE_GUARDED
:
662 if ((status
= nfsd4_decode_fattr(argp
, open
->op_bmval
, &open
->op_iattr
, &open
->op_acl
)))
665 case NFS4_CREATE_EXCLUSIVE
:
667 COPYMEM(open
->op_verf
.data
, 8);
679 READ32(open
->op_claim_type
);
680 switch (open
->op_claim_type
) {
681 case NFS4_OPEN_CLAIM_NULL
:
682 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
684 READ32(open
->op_fname
.len
);
685 READ_BUF(open
->op_fname
.len
);
686 SAVEMEM(open
->op_fname
.data
, open
->op_fname
.len
);
687 if ((status
= check_filename(open
->op_fname
.data
, open
->op_fname
.len
, nfserr_inval
)))
690 case NFS4_OPEN_CLAIM_PREVIOUS
:
692 READ32(open
->op_delegate_type
);
694 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
695 READ_BUF(sizeof(stateid_t
) + 4);
696 COPYMEM(&open
->op_delegate_stateid
, sizeof(stateid_t
));
697 READ32(open
->op_fname
.len
);
698 READ_BUF(open
->op_fname
.len
);
699 SAVEMEM(open
->op_fname
.data
, open
->op_fname
.len
);
700 if ((status
= check_filename(open
->op_fname
.data
, open
->op_fname
.len
, nfserr_inval
)))
711 nfsd4_decode_open_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_confirm
*open_conf
)
715 open_conf
->oc_stateowner
= NULL
;
716 READ_BUF(4 + sizeof(stateid_t
));
717 READ32(open_conf
->oc_req_stateid
.si_generation
);
718 COPYMEM(&open_conf
->oc_req_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
719 READ32(open_conf
->oc_seqid
);
725 nfsd4_decode_open_downgrade(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_downgrade
*open_down
)
729 open_down
->od_stateowner
= NULL
;
730 READ_BUF(12 + sizeof(stateid_t
));
731 READ32(open_down
->od_stateid
.si_generation
);
732 COPYMEM(&open_down
->od_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
733 READ32(open_down
->od_seqid
);
734 READ32(open_down
->od_share_access
);
735 READ32(open_down
->od_share_deny
);
741 nfsd4_decode_putfh(struct nfsd4_compoundargs
*argp
, struct nfsd4_putfh
*putfh
)
746 READ32(putfh
->pf_fhlen
);
747 if (putfh
->pf_fhlen
> NFS4_FHSIZE
)
749 READ_BUF(putfh
->pf_fhlen
);
750 SAVEMEM(putfh
->pf_fhval
, putfh
->pf_fhlen
);
756 nfsd4_decode_read(struct nfsd4_compoundargs
*argp
, struct nfsd4_read
*read
)
760 READ_BUF(sizeof(stateid_t
) + 12);
761 READ32(read
->rd_stateid
.si_generation
);
762 COPYMEM(&read
->rd_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
763 READ64(read
->rd_offset
);
764 READ32(read
->rd_length
);
770 nfsd4_decode_readdir(struct nfsd4_compoundargs
*argp
, struct nfsd4_readdir
*readdir
)
775 READ64(readdir
->rd_cookie
);
776 COPYMEM(readdir
->rd_verf
.data
, sizeof(readdir
->rd_verf
.data
));
777 READ32(readdir
->rd_dircount
); /* just in case you needed a useless field... */
778 READ32(readdir
->rd_maxcount
);
779 if ((status
= nfsd4_decode_bitmap(argp
, readdir
->rd_bmval
)))
786 nfsd4_decode_remove(struct nfsd4_compoundargs
*argp
, struct nfsd4_remove
*remove
)
791 READ32(remove
->rm_namelen
);
792 READ_BUF(remove
->rm_namelen
);
793 SAVEMEM(remove
->rm_name
, remove
->rm_namelen
);
794 if ((status
= check_filename(remove
->rm_name
, remove
->rm_namelen
, nfserr_noent
)))
801 nfsd4_decode_rename(struct nfsd4_compoundargs
*argp
, struct nfsd4_rename
*rename
)
806 READ32(rename
->rn_snamelen
);
807 READ_BUF(rename
->rn_snamelen
+ 4);
808 SAVEMEM(rename
->rn_sname
, rename
->rn_snamelen
);
809 READ32(rename
->rn_tnamelen
);
810 READ_BUF(rename
->rn_tnamelen
);
811 SAVEMEM(rename
->rn_tname
, rename
->rn_tnamelen
);
812 if ((status
= check_filename(rename
->rn_sname
, rename
->rn_snamelen
, nfserr_noent
)))
814 if ((status
= check_filename(rename
->rn_tname
, rename
->rn_tnamelen
, nfserr_inval
)))
821 nfsd4_decode_renew(struct nfsd4_compoundargs
*argp
, clientid_t
*clientid
)
825 READ_BUF(sizeof(clientid_t
));
826 COPYMEM(clientid
, sizeof(clientid_t
));
832 nfsd4_decode_secinfo(struct nfsd4_compoundargs
*argp
,
833 struct nfsd4_secinfo
*secinfo
)
838 READ32(secinfo
->si_namelen
);
839 READ_BUF(secinfo
->si_namelen
);
840 SAVEMEM(secinfo
->si_name
, secinfo
->si_namelen
);
841 status
= check_filename(secinfo
->si_name
, secinfo
->si_namelen
,
849 nfsd4_decode_setattr(struct nfsd4_compoundargs
*argp
, struct nfsd4_setattr
*setattr
)
853 READ_BUF(sizeof(stateid_t
));
854 READ32(setattr
->sa_stateid
.si_generation
);
855 COPYMEM(&setattr
->sa_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
856 if ((status
= nfsd4_decode_fattr(argp
, setattr
->sa_bmval
, &setattr
->sa_iattr
, &setattr
->sa_acl
)))
863 nfsd4_decode_setclientid(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid
*setclientid
)
868 COPYMEM(setclientid
->se_verf
.data
, 8);
869 READ32(setclientid
->se_namelen
);
871 READ_BUF(setclientid
->se_namelen
+ 8);
872 SAVEMEM(setclientid
->se_name
, setclientid
->se_namelen
);
873 READ32(setclientid
->se_callback_prog
);
874 READ32(setclientid
->se_callback_netid_len
);
876 READ_BUF(setclientid
->se_callback_netid_len
+ 4);
877 SAVEMEM(setclientid
->se_callback_netid_val
, setclientid
->se_callback_netid_len
);
878 READ32(setclientid
->se_callback_addr_len
);
880 READ_BUF(setclientid
->se_callback_addr_len
+ 4);
881 SAVEMEM(setclientid
->se_callback_addr_val
, setclientid
->se_callback_addr_len
);
882 READ32(setclientid
->se_callback_ident
);
888 nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid_confirm
*scd_c
)
892 READ_BUF(8 + sizeof(nfs4_verifier
));
893 COPYMEM(&scd_c
->sc_clientid
, 8);
894 COPYMEM(&scd_c
->sc_confirm
, sizeof(nfs4_verifier
));
899 /* Also used for NVERIFY */
901 nfsd4_decode_verify(struct nfsd4_compoundargs
*argp
, struct nfsd4_verify
*verify
)
904 struct nfsd4_compoundargs save
= {
907 .rqstp
= argp
->rqstp
,
910 struct iattr ve_iattr
; /* request */
911 struct nfs4_acl
*ve_acl
; /* request */
915 if ((status
= nfsd4_decode_bitmap(argp
, verify
->ve_bmval
)))
918 /* For convenience's sake, we compare raw xdr'd attributes in
919 * nfsd4_proc_verify; however we still decode here just to return
920 * correct error in case of bad xdr. */
922 status
= nfsd4_decode_fattr(ve_bmval
, &ve_iattr
, &ve_acl
);
923 if (status
== nfserr_inval
) {
924 status
= nfserrno(status
);
929 READ32(verify
->ve_attrlen
);
930 READ_BUF(verify
->ve_attrlen
);
931 SAVEMEM(verify
->ve_attrval
, verify
->ve_attrlen
);
937 nfsd4_decode_write(struct nfsd4_compoundargs
*argp
, struct nfsd4_write
*write
)
944 READ_BUF(sizeof(stateid_opaque_t
) + 20);
945 READ32(write
->wr_stateid
.si_generation
);
946 COPYMEM(&write
->wr_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
947 READ64(write
->wr_offset
);
948 READ32(write
->wr_stable_how
);
949 if (write
->wr_stable_how
> 2)
951 READ32(write
->wr_buflen
);
953 /* Sorry .. no magic macros for this.. *
954 * READ_BUF(write->wr_buflen);
955 * SAVEMEM(write->wr_buf, write->wr_buflen);
957 avail
= (char*)argp
->end
- (char*)argp
->p
;
958 if (avail
+ argp
->pagelen
< write
->wr_buflen
) {
959 dprintk("NFSD: xdr error (%s:%d)\n",
963 argp
->rqstp
->rq_vec
[0].iov_base
= p
;
964 argp
->rqstp
->rq_vec
[0].iov_len
= avail
;
966 len
= write
->wr_buflen
;
967 while (len
> argp
->rqstp
->rq_vec
[v
].iov_len
) {
968 len
-= argp
->rqstp
->rq_vec
[v
].iov_len
;
970 argp
->rqstp
->rq_vec
[v
].iov_base
= page_address(argp
->pagelist
[0]);
972 if (argp
->pagelen
>= PAGE_SIZE
) {
973 argp
->rqstp
->rq_vec
[v
].iov_len
= PAGE_SIZE
;
974 argp
->pagelen
-= PAGE_SIZE
;
976 argp
->rqstp
->rq_vec
[v
].iov_len
= argp
->pagelen
;
977 argp
->pagelen
-= len
;
980 argp
->end
= (__be32
*) (argp
->rqstp
->rq_vec
[v
].iov_base
+ argp
->rqstp
->rq_vec
[v
].iov_len
);
981 argp
->p
= (__be32
*) (argp
->rqstp
->rq_vec
[v
].iov_base
+ (XDR_QUADLEN(len
) << 2));
982 argp
->rqstp
->rq_vec
[v
].iov_len
= len
;
983 write
->wr_vlen
= v
+1;
989 nfsd4_decode_release_lockowner(struct nfsd4_compoundargs
*argp
, struct nfsd4_release_lockowner
*rlockowner
)
994 COPYMEM(&rlockowner
->rl_clientid
, sizeof(clientid_t
));
995 READ32(rlockowner
->rl_owner
.len
);
996 READ_BUF(rlockowner
->rl_owner
.len
);
997 READMEM(rlockowner
->rl_owner
.data
, rlockowner
->rl_owner
.len
);
1003 nfsd4_decode_compound(struct nfsd4_compoundargs
*argp
)
1006 struct nfsd4_op
*op
;
1010 * XXX: According to spec, we should check the tag
1011 * for UTF-8 compliance. I'm postponing this for
1012 * now because it seems that some clients do use
1016 READ32(argp
->taglen
);
1017 READ_BUF(argp
->taglen
+ 8);
1018 SAVEMEM(argp
->tag
, argp
->taglen
);
1019 READ32(argp
->minorversion
);
1020 READ32(argp
->opcnt
);
1022 if (argp
->taglen
> NFSD4_MAX_TAGLEN
)
1024 if (argp
->opcnt
> 100)
1027 if (argp
->opcnt
> ARRAY_SIZE(argp
->iops
)) {
1028 argp
->ops
= kmalloc(argp
->opcnt
* sizeof(*argp
->ops
), GFP_KERNEL
);
1030 argp
->ops
= argp
->iops
;
1031 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
1036 for (i
= 0; i
< argp
->opcnt
; i
++) {
1041 * We can't use READ_BUF() here because we need to handle
1042 * a missing opcode as an OP_WRITE + 1. So we need to check
1043 * to see if we're truly at the end of our buffer or if there
1044 * is another page we need to flip to.
1047 if (argp
->p
== argp
->end
) {
1048 if (argp
->pagelen
< 4) {
1049 /* There isn't an opcode still on the wire */
1050 op
->opnum
= OP_WRITE
+ 1;
1051 op
->status
= nfserr_bad_xdr
;
1057 * False alarm. We just hit a page boundary, but there
1058 * is still data available. Move pointer across page
1059 * boundary. *snip from READ_BUF*
1061 argp
->p
= page_address(argp
->pagelist
[0]);
1063 if (argp
->pagelen
< PAGE_SIZE
) {
1064 argp
->end
= p
+ (argp
->pagelen
>>2);
1067 argp
->end
= p
+ (PAGE_SIZE
>>2);
1068 argp
->pagelen
-= PAGE_SIZE
;
1071 op
->opnum
= ntohl(*argp
->p
++);
1073 switch (op
->opnum
) {
1074 case 2: /* Reserved operation */
1075 op
->opnum
= OP_ILLEGAL
;
1076 if (argp
->minorversion
== 0)
1077 op
->status
= nfserr_op_illegal
;
1079 op
->status
= nfserr_minor_vers_mismatch
;
1082 op
->status
= nfsd4_decode_access(argp
, &op
->u
.access
);
1085 op
->status
= nfsd4_decode_close(argp
, &op
->u
.close
);
1088 op
->status
= nfsd4_decode_commit(argp
, &op
->u
.commit
);
1091 op
->status
= nfsd4_decode_create(argp
, &op
->u
.create
);
1093 case OP_DELEGRETURN
:
1094 op
->status
= nfsd4_decode_delegreturn(argp
, &op
->u
.delegreturn
);
1097 op
->status
= nfsd4_decode_getattr(argp
, &op
->u
.getattr
);
1100 op
->status
= nfs_ok
;
1103 op
->status
= nfsd4_decode_link(argp
, &op
->u
.link
);
1106 op
->status
= nfsd4_decode_lock(argp
, &op
->u
.lock
);
1109 op
->status
= nfsd4_decode_lockt(argp
, &op
->u
.lockt
);
1112 op
->status
= nfsd4_decode_locku(argp
, &op
->u
.locku
);
1115 op
->status
= nfsd4_decode_lookup(argp
, &op
->u
.lookup
);
1118 op
->status
= nfs_ok
;
1121 op
->status
= nfsd4_decode_verify(argp
, &op
->u
.nverify
);
1124 op
->status
= nfsd4_decode_open(argp
, &op
->u
.open
);
1126 case OP_OPEN_CONFIRM
:
1127 op
->status
= nfsd4_decode_open_confirm(argp
, &op
->u
.open_confirm
);
1129 case OP_OPEN_DOWNGRADE
:
1130 op
->status
= nfsd4_decode_open_downgrade(argp
, &op
->u
.open_downgrade
);
1133 op
->status
= nfsd4_decode_putfh(argp
, &op
->u
.putfh
);
1136 op
->status
= nfs_ok
;
1139 op
->status
= nfsd4_decode_read(argp
, &op
->u
.read
);
1142 op
->status
= nfsd4_decode_readdir(argp
, &op
->u
.readdir
);
1145 op
->status
= nfs_ok
;
1148 op
->status
= nfsd4_decode_remove(argp
, &op
->u
.remove
);
1151 op
->status
= nfsd4_decode_rename(argp
, &op
->u
.rename
);
1154 op
->status
= nfs_ok
;
1157 op
->status
= nfsd4_decode_renew(argp
, &op
->u
.renew
);
1160 op
->status
= nfs_ok
;
1163 op
->status
= nfsd4_decode_secinfo(argp
, &op
->u
.secinfo
);
1166 op
->status
= nfsd4_decode_setattr(argp
, &op
->u
.setattr
);
1168 case OP_SETCLIENTID
:
1169 op
->status
= nfsd4_decode_setclientid(argp
, &op
->u
.setclientid
);
1171 case OP_SETCLIENTID_CONFIRM
:
1172 op
->status
= nfsd4_decode_setclientid_confirm(argp
, &op
->u
.setclientid_confirm
);
1175 op
->status
= nfsd4_decode_verify(argp
, &op
->u
.verify
);
1178 op
->status
= nfsd4_decode_write(argp
, &op
->u
.write
);
1180 case OP_RELEASE_LOCKOWNER
:
1181 op
->status
= nfsd4_decode_release_lockowner(argp
, &op
->u
.release_lockowner
);
1184 op
->opnum
= OP_ILLEGAL
;
1185 op
->status
= nfserr_op_illegal
;
1198 * END OF "GENERIC" DECODE ROUTINES.
1202 * START OF "GENERIC" ENCODE ROUTINES.
1203 * These may look a little ugly since they are imported from a "generic"
1204 * set of XDR encode/decode routines which are intended to be shared by
1205 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1207 * If the pain of reading these is too great, it should be a straightforward
1208 * task to translate them into Linux-specific versions which are more
1209 * consistent with the style used in NFSv2/v3...
1211 #define ENCODE_HEAD __be32 *p
1213 #define WRITE32(n) *p++ = htonl(n)
1214 #define WRITE64(n) do { \
1215 *p++ = htonl((u32)((n) >> 32)); \
1216 *p++ = htonl((u32)(n)); \
1218 #define WRITEMEM(ptr,nbytes) do { \
1219 *(p + XDR_QUADLEN(nbytes) -1) = 0; \
1220 memcpy(p, ptr, nbytes); \
1221 p += XDR_QUADLEN(nbytes); \
1223 #define WRITECINFO(c) do { \
1224 *p++ = htonl(c.atomic); \
1225 *p++ = htonl(c.before_ctime_sec); \
1226 *p++ = htonl(c.before_ctime_nsec); \
1227 *p++ = htonl(c.after_ctime_sec); \
1228 *p++ = htonl(c.after_ctime_nsec); \
1231 #define RESERVE_SPACE(nbytes) do { \
1233 BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
1235 #define ADJUST_ARGS() resp->p = p
1238 * Header routine to setup seqid operation replay cache
1240 #define ENCODE_SEQID_OP_HEAD \
1247 * Routine for encoding the result of a "seqid-mutating" NFSv4 operation. This
1248 * is where sequence id's are incremented, and the replay cache is filled.
1249 * Note that we increment sequence id's here, at the last moment, so we're sure
1250 * we know whether the error to be returned is a sequence id mutating error.
1253 #define ENCODE_SEQID_OP_TAIL(stateowner) do { \
1254 if (seqid_mutating_err(nfserr) && stateowner) { \
1255 stateowner->so_seqid++; \
1256 stateowner->so_replay.rp_status = nfserr; \
1257 stateowner->so_replay.rp_buflen = \
1258 (((char *)(resp)->p - (char *)save)); \
1259 memcpy(stateowner->so_replay.rp_buf, save, \
1260 stateowner->so_replay.rp_buflen); \
1263 /* Encode as an array of strings the string given with components
1266 static __be32
nfsd4_encode_components(char sep
, char *components
,
1267 __be32
**pp
, int *buflen
)
1271 int strlen
, count
=0;
1274 dprintk("nfsd4_encode_components(%s)\n", components
);
1275 if ((*buflen
-= 4) < 0)
1276 return nfserr_resource
;
1277 WRITE32(0); /* We will fill this in with @count later */
1278 end
= str
= components
;
1280 for (; *end
&& (*end
!= sep
); end
++)
1281 ; /* Point to end of component */
1284 if ((*buflen
-= ((XDR_QUADLEN(strlen
) << 2) + 4)) < 0)
1285 return nfserr_resource
;
1287 WRITEMEM(str
, strlen
);
1301 * encode a location element of a fs_locations structure
1303 static __be32
nfsd4_encode_fs_location4(struct nfsd4_fs_location
*location
,
1304 __be32
**pp
, int *buflen
)
1309 status
= nfsd4_encode_components(':', location
->hosts
, &p
, buflen
);
1312 status
= nfsd4_encode_components('/', location
->path
, &p
, buflen
);
1320 * Return the path to an export point in the pseudo filesystem namespace
1321 * Returned string is safe to use as long as the caller holds a reference
1324 static char *nfsd4_path(struct svc_rqst
*rqstp
, struct svc_export
*exp
, __be32
*stat
)
1326 struct svc_fh tmp_fh
;
1327 char *path
, *rootpath
;
1329 fh_init(&tmp_fh
, NFS4_FHSIZE
);
1330 *stat
= exp_pseudoroot(rqstp
, &tmp_fh
);
1333 rootpath
= tmp_fh
.fh_export
->ex_pathname
;
1335 path
= exp
->ex_pathname
;
1337 if (strncmp(path
, rootpath
, strlen(rootpath
))) {
1338 dprintk("nfsd: fs_locations failed;"
1339 "%s is not contained in %s\n", path
, rootpath
);
1340 *stat
= nfserr_notsupp
;
1344 return path
+ strlen(rootpath
);
1348 * encode a fs_locations structure
1350 static __be32
nfsd4_encode_fs_locations(struct svc_rqst
*rqstp
,
1351 struct svc_export
*exp
,
1352 __be32
**pp
, int *buflen
)
1357 struct nfsd4_fs_locations
*fslocs
= &exp
->ex_fslocs
;
1358 char *root
= nfsd4_path(rqstp
, exp
, &status
);
1362 status
= nfsd4_encode_components('/', root
, &p
, buflen
);
1365 if ((*buflen
-= 4) < 0)
1366 return nfserr_resource
;
1367 WRITE32(fslocs
->locations_count
);
1368 for (i
=0; i
<fslocs
->locations_count
; i
++) {
1369 status
= nfsd4_encode_fs_location4(&fslocs
->locations
[i
],
1378 static u32 nfs4_ftypes
[16] = {
1379 NF4BAD
, NF4FIFO
, NF4CHR
, NF4BAD
,
1380 NF4DIR
, NF4BAD
, NF4BLK
, NF4BAD
,
1381 NF4REG
, NF4BAD
, NF4LNK
, NF4BAD
,
1382 NF4SOCK
, NF4BAD
, NF4LNK
, NF4BAD
,
1386 nfsd4_encode_name(struct svc_rqst
*rqstp
, int whotype
, uid_t id
, int group
,
1387 __be32
**p
, int *buflen
)
1391 if (*buflen
< (XDR_QUADLEN(IDMAP_NAMESZ
) << 2) + 4)
1392 return nfserr_resource
;
1393 if (whotype
!= NFS4_ACL_WHO_NAMED
)
1394 status
= nfs4_acl_write_who(whotype
, (u8
*)(*p
+ 1));
1396 status
= nfsd_map_gid_to_name(rqstp
, id
, (u8
*)(*p
+ 1));
1398 status
= nfsd_map_uid_to_name(rqstp
, id
, (u8
*)(*p
+ 1));
1400 return nfserrno(status
);
1401 *p
= xdr_encode_opaque(*p
, NULL
, status
);
1402 *buflen
-= (XDR_QUADLEN(status
) << 2) + 4;
1403 BUG_ON(*buflen
< 0);
1407 static inline __be32
1408 nfsd4_encode_user(struct svc_rqst
*rqstp
, uid_t uid
, __be32
**p
, int *buflen
)
1410 return nfsd4_encode_name(rqstp
, NFS4_ACL_WHO_NAMED
, uid
, 0, p
, buflen
);
1413 static inline __be32
1414 nfsd4_encode_group(struct svc_rqst
*rqstp
, uid_t gid
, __be32
**p
, int *buflen
)
1416 return nfsd4_encode_name(rqstp
, NFS4_ACL_WHO_NAMED
, gid
, 1, p
, buflen
);
1419 static inline __be32
1420 nfsd4_encode_aclname(struct svc_rqst
*rqstp
, int whotype
, uid_t id
, int group
,
1421 __be32
**p
, int *buflen
)
1423 return nfsd4_encode_name(rqstp
, whotype
, id
, group
, p
, buflen
);
1426 #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
1427 FATTR4_WORD0_RDATTR_ERROR)
1428 #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
1430 static __be32
fattr_handle_absent_fs(u32
*bmval0
, u32
*bmval1
, u32
*rdattr_err
)
1432 /* As per referral draft: */
1433 if (*bmval0
& ~WORD0_ABSENT_FS_ATTRS
||
1434 *bmval1
& ~WORD1_ABSENT_FS_ATTRS
) {
1435 if (*bmval0
& FATTR4_WORD0_RDATTR_ERROR
||
1436 *bmval0
& FATTR4_WORD0_FS_LOCATIONS
)
1437 *rdattr_err
= NFSERR_MOVED
;
1439 return nfserr_moved
;
1441 *bmval0
&= WORD0_ABSENT_FS_ATTRS
;
1442 *bmval1
&= WORD1_ABSENT_FS_ATTRS
;
1447 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
1450 * @countp is the buffer size in _words_; upon successful return this becomes
1451 * replaced with the number of words written.
1454 nfsd4_encode_fattr(struct svc_fh
*fhp
, struct svc_export
*exp
,
1455 struct dentry
*dentry
, __be32
*buffer
, int *countp
, u32
*bmval
,
1456 struct svc_rqst
*rqstp
, int ignore_crossmnt
)
1458 u32 bmval0
= bmval
[0];
1459 u32 bmval1
= bmval
[1];
1461 struct svc_fh tempfh
;
1462 struct kstatfs statfs
;
1463 int buflen
= *countp
<< 2;
1472 struct nfs4_acl
*acl
= NULL
;
1474 BUG_ON(bmval1
& NFSD_WRITEONLY_ATTRS_WORD1
);
1475 BUG_ON(bmval0
& ~NFSD_SUPPORTED_ATTRS_WORD0
);
1476 BUG_ON(bmval1
& ~NFSD_SUPPORTED_ATTRS_WORD1
);
1478 if (exp
->ex_fslocs
.migrated
) {
1479 status
= fattr_handle_absent_fs(&bmval0
, &bmval1
, &rdattr_err
);
1484 err
= vfs_getattr(exp
->ex_path
.mnt
, dentry
, &stat
);
1487 if ((bmval0
& (FATTR4_WORD0_FILES_FREE
| FATTR4_WORD0_FILES_TOTAL
|
1488 FATTR4_WORD0_MAXNAME
)) ||
1489 (bmval1
& (FATTR4_WORD1_SPACE_AVAIL
| FATTR4_WORD1_SPACE_FREE
|
1490 FATTR4_WORD1_SPACE_TOTAL
))) {
1491 err
= vfs_statfs(dentry
, &statfs
);
1495 if ((bmval0
& (FATTR4_WORD0_FILEHANDLE
| FATTR4_WORD0_FSID
)) && !fhp
) {
1496 fh_init(&tempfh
, NFS4_FHSIZE
);
1497 status
= fh_compose(&tempfh
, exp
, dentry
, NULL
);
1502 if (bmval0
& (FATTR4_WORD0_ACL
| FATTR4_WORD0_ACLSUPPORT
1503 | FATTR4_WORD0_SUPPORTED_ATTRS
)) {
1504 err
= nfsd4_get_nfs4_acl(rqstp
, dentry
, &acl
);
1505 aclsupport
= (err
== 0);
1506 if (bmval0
& FATTR4_WORD0_ACL
) {
1507 if (err
== -EOPNOTSUPP
)
1508 bmval0
&= ~FATTR4_WORD0_ACL
;
1509 else if (err
== -EINVAL
) {
1510 status
= nfserr_attrnotsupp
;
1512 } else if (err
!= 0)
1516 if (bmval0
& FATTR4_WORD0_FS_LOCATIONS
) {
1517 if (exp
->ex_fslocs
.locations
== NULL
) {
1518 bmval0
&= ~FATTR4_WORD0_FS_LOCATIONS
;
1521 if ((buflen
-= 16) < 0)
1527 attrlenp
= p
++; /* to be backfilled later */
1529 if (bmval0
& FATTR4_WORD0_SUPPORTED_ATTRS
) {
1530 u32 word0
= NFSD_SUPPORTED_ATTRS_WORD0
;
1531 if ((buflen
-= 12) < 0)
1534 word0
&= ~FATTR4_WORD0_ACL
;
1535 if (!exp
->ex_fslocs
.locations
)
1536 word0
&= ~FATTR4_WORD0_FS_LOCATIONS
;
1539 WRITE32(NFSD_SUPPORTED_ATTRS_WORD1
);
1541 if (bmval0
& FATTR4_WORD0_TYPE
) {
1542 if ((buflen
-= 4) < 0)
1544 dummy
= nfs4_ftypes
[(stat
.mode
& S_IFMT
) >> 12];
1545 if (dummy
== NF4BAD
)
1546 goto out_serverfault
;
1549 if (bmval0
& FATTR4_WORD0_FH_EXPIRE_TYPE
) {
1550 if ((buflen
-= 4) < 0)
1552 if (exp
->ex_flags
& NFSEXP_NOSUBTREECHECK
)
1553 WRITE32(NFS4_FH_PERSISTENT
);
1555 WRITE32(NFS4_FH_PERSISTENT
|NFS4_FH_VOL_RENAME
);
1557 if (bmval0
& FATTR4_WORD0_CHANGE
) {
1559 * Note: This _must_ be consistent with the scheme for writing
1560 * change_info, so any changes made here must be reflected there
1561 * as well. (See xdr4.h:set_change_info() and the WRITECINFO()
1564 if ((buflen
-= 8) < 0)
1566 WRITE32(stat
.ctime
.tv_sec
);
1567 WRITE32(stat
.ctime
.tv_nsec
);
1569 if (bmval0
& FATTR4_WORD0_SIZE
) {
1570 if ((buflen
-= 8) < 0)
1574 if (bmval0
& FATTR4_WORD0_LINK_SUPPORT
) {
1575 if ((buflen
-= 4) < 0)
1579 if (bmval0
& FATTR4_WORD0_SYMLINK_SUPPORT
) {
1580 if ((buflen
-= 4) < 0)
1584 if (bmval0
& FATTR4_WORD0_NAMED_ATTR
) {
1585 if ((buflen
-= 4) < 0)
1589 if (bmval0
& FATTR4_WORD0_FSID
) {
1590 if ((buflen
-= 16) < 0)
1592 if (exp
->ex_fslocs
.migrated
) {
1593 WRITE64(NFS4_REFERRAL_FSID_MAJOR
);
1594 WRITE64(NFS4_REFERRAL_FSID_MINOR
);
1595 } else switch(fsid_source(fhp
)) {
1596 case FSIDSOURCE_FSID
:
1597 WRITE64((u64
)exp
->ex_fsid
);
1600 case FSIDSOURCE_DEV
:
1602 WRITE32(MAJOR(stat
.dev
));
1604 WRITE32(MINOR(stat
.dev
));
1606 case FSIDSOURCE_UUID
:
1607 WRITEMEM(exp
->ex_uuid
, 16);
1611 if (bmval0
& FATTR4_WORD0_UNIQUE_HANDLES
) {
1612 if ((buflen
-= 4) < 0)
1616 if (bmval0
& FATTR4_WORD0_LEASE_TIME
) {
1617 if ((buflen
-= 4) < 0)
1619 WRITE32(NFSD_LEASE_TIME
);
1621 if (bmval0
& FATTR4_WORD0_RDATTR_ERROR
) {
1622 if ((buflen
-= 4) < 0)
1624 WRITE32(rdattr_err
);
1626 if (bmval0
& FATTR4_WORD0_ACL
) {
1627 struct nfs4_ace
*ace
;
1630 if ((buflen
-= 4) < 0)
1636 if ((buflen
-= 4) < 0)
1638 WRITE32(acl
->naces
);
1640 for (ace
= acl
->aces
; ace
< acl
->aces
+ acl
->naces
; ace
++) {
1641 if ((buflen
-= 4*3) < 0)
1645 WRITE32(ace
->access_mask
& NFS4_ACE_MASK_ALL
);
1646 status
= nfsd4_encode_aclname(rqstp
, ace
->whotype
,
1647 ace
->who
, ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
,
1649 if (status
== nfserr_resource
)
1656 if (bmval0
& FATTR4_WORD0_ACLSUPPORT
) {
1657 if ((buflen
-= 4) < 0)
1659 WRITE32(aclsupport
?
1660 ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
: 0);
1662 if (bmval0
& FATTR4_WORD0_CANSETTIME
) {
1663 if ((buflen
-= 4) < 0)
1667 if (bmval0
& FATTR4_WORD0_CASE_INSENSITIVE
) {
1668 if ((buflen
-= 4) < 0)
1672 if (bmval0
& FATTR4_WORD0_CASE_PRESERVING
) {
1673 if ((buflen
-= 4) < 0)
1677 if (bmval0
& FATTR4_WORD0_CHOWN_RESTRICTED
) {
1678 if ((buflen
-= 4) < 0)
1682 if (bmval0
& FATTR4_WORD0_FILEHANDLE
) {
1683 buflen
-= (XDR_QUADLEN(fhp
->fh_handle
.fh_size
) << 2) + 4;
1686 WRITE32(fhp
->fh_handle
.fh_size
);
1687 WRITEMEM(&fhp
->fh_handle
.fh_base
, fhp
->fh_handle
.fh_size
);
1689 if (bmval0
& FATTR4_WORD0_FILEID
) {
1690 if ((buflen
-= 8) < 0)
1694 if (bmval0
& FATTR4_WORD0_FILES_AVAIL
) {
1695 if ((buflen
-= 8) < 0)
1697 WRITE64((u64
) statfs
.f_ffree
);
1699 if (bmval0
& FATTR4_WORD0_FILES_FREE
) {
1700 if ((buflen
-= 8) < 0)
1702 WRITE64((u64
) statfs
.f_ffree
);
1704 if (bmval0
& FATTR4_WORD0_FILES_TOTAL
) {
1705 if ((buflen
-= 8) < 0)
1707 WRITE64((u64
) statfs
.f_files
);
1709 if (bmval0
& FATTR4_WORD0_FS_LOCATIONS
) {
1710 status
= nfsd4_encode_fs_locations(rqstp
, exp
, &p
, &buflen
);
1711 if (status
== nfserr_resource
)
1716 if (bmval0
& FATTR4_WORD0_HOMOGENEOUS
) {
1717 if ((buflen
-= 4) < 0)
1721 if (bmval0
& FATTR4_WORD0_MAXFILESIZE
) {
1722 if ((buflen
-= 8) < 0)
1726 if (bmval0
& FATTR4_WORD0_MAXLINK
) {
1727 if ((buflen
-= 4) < 0)
1731 if (bmval0
& FATTR4_WORD0_MAXNAME
) {
1732 if ((buflen
-= 4) < 0)
1734 WRITE32(statfs
.f_namelen
);
1736 if (bmval0
& FATTR4_WORD0_MAXREAD
) {
1737 if ((buflen
-= 8) < 0)
1739 WRITE64((u64
) svc_max_payload(rqstp
));
1741 if (bmval0
& FATTR4_WORD0_MAXWRITE
) {
1742 if ((buflen
-= 8) < 0)
1744 WRITE64((u64
) svc_max_payload(rqstp
));
1746 if (bmval1
& FATTR4_WORD1_MODE
) {
1747 if ((buflen
-= 4) < 0)
1749 WRITE32(stat
.mode
& S_IALLUGO
);
1751 if (bmval1
& FATTR4_WORD1_NO_TRUNC
) {
1752 if ((buflen
-= 4) < 0)
1756 if (bmval1
& FATTR4_WORD1_NUMLINKS
) {
1757 if ((buflen
-= 4) < 0)
1759 WRITE32(stat
.nlink
);
1761 if (bmval1
& FATTR4_WORD1_OWNER
) {
1762 status
= nfsd4_encode_user(rqstp
, stat
.uid
, &p
, &buflen
);
1763 if (status
== nfserr_resource
)
1768 if (bmval1
& FATTR4_WORD1_OWNER_GROUP
) {
1769 status
= nfsd4_encode_group(rqstp
, stat
.gid
, &p
, &buflen
);
1770 if (status
== nfserr_resource
)
1775 if (bmval1
& FATTR4_WORD1_RAWDEV
) {
1776 if ((buflen
-= 8) < 0)
1778 WRITE32((u32
) MAJOR(stat
.rdev
));
1779 WRITE32((u32
) MINOR(stat
.rdev
));
1781 if (bmval1
& FATTR4_WORD1_SPACE_AVAIL
) {
1782 if ((buflen
-= 8) < 0)
1784 dummy64
= (u64
)statfs
.f_bavail
* (u64
)statfs
.f_bsize
;
1787 if (bmval1
& FATTR4_WORD1_SPACE_FREE
) {
1788 if ((buflen
-= 8) < 0)
1790 dummy64
= (u64
)statfs
.f_bfree
* (u64
)statfs
.f_bsize
;
1793 if (bmval1
& FATTR4_WORD1_SPACE_TOTAL
) {
1794 if ((buflen
-= 8) < 0)
1796 dummy64
= (u64
)statfs
.f_blocks
* (u64
)statfs
.f_bsize
;
1799 if (bmval1
& FATTR4_WORD1_SPACE_USED
) {
1800 if ((buflen
-= 8) < 0)
1802 dummy64
= (u64
)stat
.blocks
<< 9;
1805 if (bmval1
& FATTR4_WORD1_TIME_ACCESS
) {
1806 if ((buflen
-= 12) < 0)
1809 WRITE32(stat
.atime
.tv_sec
);
1810 WRITE32(stat
.atime
.tv_nsec
);
1812 if (bmval1
& FATTR4_WORD1_TIME_DELTA
) {
1813 if ((buflen
-= 12) < 0)
1819 if (bmval1
& FATTR4_WORD1_TIME_METADATA
) {
1820 if ((buflen
-= 12) < 0)
1823 WRITE32(stat
.ctime
.tv_sec
);
1824 WRITE32(stat
.ctime
.tv_nsec
);
1826 if (bmval1
& FATTR4_WORD1_TIME_MODIFY
) {
1827 if ((buflen
-= 12) < 0)
1830 WRITE32(stat
.mtime
.tv_sec
);
1831 WRITE32(stat
.mtime
.tv_nsec
);
1833 if (bmval1
& FATTR4_WORD1_MOUNTED_ON_FILEID
) {
1834 if ((buflen
-= 8) < 0)
1837 * Get parent's attributes if not ignoring crossmount
1838 * and this is the root of a cross-mounted filesystem.
1840 if (ignore_crossmnt
== 0 &&
1841 exp
->ex_path
.mnt
->mnt_root
->d_inode
== dentry
->d_inode
) {
1842 err
= vfs_getattr(exp
->ex_path
.mnt
->mnt_parent
,
1843 exp
->ex_path
.mnt
->mnt_mountpoint
, &stat
);
1849 *attrlenp
= htonl((char *)p
- (char *)attrlenp
- 4);
1850 *countp
= p
- buffer
;
1859 status
= nfserrno(err
);
1863 status
= nfserr_resource
;
1866 status
= nfserr_serverfault
;
1871 nfsd4_encode_dirent_fattr(struct nfsd4_readdir
*cd
,
1872 const char *name
, int namlen
, __be32
*p
, int *buflen
)
1874 struct svc_export
*exp
= cd
->rd_fhp
->fh_export
;
1875 struct dentry
*dentry
;
1877 int ignore_crossmnt
= 0;
1879 dentry
= lookup_one_len(name
, cd
->rd_fhp
->fh_dentry
, namlen
);
1881 return nfserrno(PTR_ERR(dentry
));
1885 * In the case of a mountpoint, the client may be asking for
1886 * attributes that are only properties of the underlying filesystem
1887 * as opposed to the cross-mounted file system. In such a case,
1888 * we will not follow the cross mount and will fill the attribtutes
1889 * directly from the mountpoint dentry.
1891 if (d_mountpoint(dentry
) &&
1892 (cd
->rd_bmval
[0] & ~FATTR4_WORD0_RDATTR_ERROR
) == 0 &&
1893 (cd
->rd_bmval
[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID
) == 0)
1894 ignore_crossmnt
= 1;
1895 else if (d_mountpoint(dentry
)) {
1899 * Why the heck aren't we just using nfsd_lookup??
1900 * Different "."/".." handling? Something else?
1901 * At least, add a comment here to explain....
1903 err
= nfsd_cross_mnt(cd
->rd_rqstp
, &dentry
, &exp
);
1905 nfserr
= nfserrno(err
);
1908 nfserr
= check_nfsd_access(exp
, cd
->rd_rqstp
);
1913 nfserr
= nfsd4_encode_fattr(NULL
, exp
, dentry
, p
, buflen
, cd
->rd_bmval
,
1914 cd
->rd_rqstp
, ignore_crossmnt
);
1922 nfsd4_encode_rdattr_error(__be32
*p
, int buflen
, __be32 nfserr
)
1929 *p
++ = htonl(FATTR4_WORD0_RDATTR_ERROR
); /* bmval0 */
1930 *p
++ = htonl(0); /* bmval1 */
1933 *p
++ = nfserr
; /* no htonl */
1934 *attrlenp
= htonl((char *)p
- (char *)attrlenp
- 4);
1939 nfsd4_encode_dirent(void *ccdv
, const char *name
, int namlen
,
1940 loff_t offset
, u64 ino
, unsigned int d_type
)
1942 struct readdir_cd
*ccd
= ccdv
;
1943 struct nfsd4_readdir
*cd
= container_of(ccd
, struct nfsd4_readdir
, common
);
1945 __be32
*p
= cd
->buffer
;
1946 __be32 nfserr
= nfserr_toosmall
;
1948 /* In nfsv4, "." and ".." never make it onto the wire.. */
1949 if (name
&& isdotent(name
, namlen
)) {
1950 cd
->common
.err
= nfs_ok
;
1955 xdr_encode_hyper(cd
->offset
, (u64
) offset
);
1957 buflen
= cd
->buflen
- 4 - XDR_QUADLEN(namlen
);
1961 *p
++ = xdr_one
; /* mark entry present */
1962 cd
->offset
= p
; /* remember pointer */
1963 p
= xdr_encode_hyper(p
, NFS_OFFSET_MAX
); /* offset of next entry */
1964 p
= xdr_encode_array(p
, name
, namlen
); /* name length & name */
1966 nfserr
= nfsd4_encode_dirent_fattr(cd
, name
, namlen
, p
, &buflen
);
1971 case nfserr_resource
:
1972 nfserr
= nfserr_toosmall
;
1978 * If the client requested the RDATTR_ERROR attribute,
1979 * we stuff the error code into this attribute
1980 * and continue. If this attribute was not requested,
1981 * then in accordance with the spec, we fail the
1982 * entire READDIR operation(!)
1984 if (!(cd
->rd_bmval
[0] & FATTR4_WORD0_RDATTR_ERROR
))
1986 p
= nfsd4_encode_rdattr_error(p
, buflen
, nfserr
);
1988 nfserr
= nfserr_toosmall
;
1992 cd
->buflen
-= (p
- cd
->buffer
);
1994 cd
->common
.err
= nfs_ok
;
1997 cd
->common
.err
= nfserr
;
2002 nfsd4_encode_access(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_access
*access
)
2008 WRITE32(access
->ac_supported
);
2009 WRITE32(access
->ac_resp_access
);
2015 nfsd4_encode_close(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_close
*close
)
2017 ENCODE_SEQID_OP_HEAD
;
2020 RESERVE_SPACE(sizeof(stateid_t
));
2021 WRITE32(close
->cl_stateid
.si_generation
);
2022 WRITEMEM(&close
->cl_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
2025 ENCODE_SEQID_OP_TAIL(close
->cl_stateowner
);
2030 nfsd4_encode_commit(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_commit
*commit
)
2036 WRITEMEM(commit
->co_verf
.data
, 8);
2042 nfsd4_encode_create(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_create
*create
)
2048 WRITECINFO(create
->cr_cinfo
);
2050 WRITE32(create
->cr_bmval
[0]);
2051 WRITE32(create
->cr_bmval
[1]);
2057 nfsd4_encode_getattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_getattr
*getattr
)
2059 struct svc_fh
*fhp
= getattr
->ga_fhp
;
2065 buflen
= resp
->end
- resp
->p
- (COMPOUND_ERR_SLACK_SPACE
>> 2);
2066 nfserr
= nfsd4_encode_fattr(fhp
, fhp
->fh_export
, fhp
->fh_dentry
,
2067 resp
->p
, &buflen
, getattr
->ga_bmval
,
2075 nfsd4_encode_getfh(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct svc_fh
*fhp
)
2081 len
= fhp
->fh_handle
.fh_size
;
2082 RESERVE_SPACE(len
+ 4);
2084 WRITEMEM(&fhp
->fh_handle
.fh_base
, len
);
2090 * Including all fields other than the name, a LOCK4denied structure requires
2091 * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
2094 nfsd4_encode_lock_denied(struct nfsd4_compoundres
*resp
, struct nfsd4_lock_denied
*ld
)
2098 RESERVE_SPACE(32 + XDR_LEN(ld
->ld_sop
? ld
->ld_sop
->so_owner
.len
: 0));
2099 WRITE64(ld
->ld_start
);
2100 WRITE64(ld
->ld_length
);
2101 WRITE32(ld
->ld_type
);
2103 WRITEMEM(&ld
->ld_clientid
, 8);
2104 WRITE32(ld
->ld_sop
->so_owner
.len
);
2105 WRITEMEM(ld
->ld_sop
->so_owner
.data
, ld
->ld_sop
->so_owner
.len
);
2106 kref_put(&ld
->ld_sop
->so_ref
, nfs4_free_stateowner
);
2107 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
2108 WRITE64((u64
)0); /* clientid */
2109 WRITE32(0); /* length of owner name */
2115 nfsd4_encode_lock(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lock
*lock
)
2117 ENCODE_SEQID_OP_HEAD
;
2120 RESERVE_SPACE(4 + sizeof(stateid_t
));
2121 WRITE32(lock
->lk_resp_stateid
.si_generation
);
2122 WRITEMEM(&lock
->lk_resp_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
2124 } else if (nfserr
== nfserr_denied
)
2125 nfsd4_encode_lock_denied(resp
, &lock
->lk_denied
);
2127 ENCODE_SEQID_OP_TAIL(lock
->lk_replay_owner
);
2131 nfsd4_encode_lockt(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lockt
*lockt
)
2133 if (nfserr
== nfserr_denied
)
2134 nfsd4_encode_lock_denied(resp
, &lockt
->lt_denied
);
2138 nfsd4_encode_locku(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_locku
*locku
)
2140 ENCODE_SEQID_OP_HEAD
;
2143 RESERVE_SPACE(sizeof(stateid_t
));
2144 WRITE32(locku
->lu_stateid
.si_generation
);
2145 WRITEMEM(&locku
->lu_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
2149 ENCODE_SEQID_OP_TAIL(locku
->lu_stateowner
);
2154 nfsd4_encode_link(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_link
*link
)
2160 WRITECINFO(link
->li_cinfo
);
2167 nfsd4_encode_open(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open
*open
)
2169 ENCODE_SEQID_OP_HEAD
;
2174 RESERVE_SPACE(36 + sizeof(stateid_t
));
2175 WRITE32(open
->op_stateid
.si_generation
);
2176 WRITEMEM(&open
->op_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
2177 WRITECINFO(open
->op_cinfo
);
2178 WRITE32(open
->op_rflags
);
2180 WRITE32(open
->op_bmval
[0]);
2181 WRITE32(open
->op_bmval
[1]);
2182 WRITE32(open
->op_delegate_type
);
2185 switch (open
->op_delegate_type
) {
2186 case NFS4_OPEN_DELEGATE_NONE
:
2188 case NFS4_OPEN_DELEGATE_READ
:
2189 RESERVE_SPACE(20 + sizeof(stateid_t
));
2190 WRITEMEM(&open
->op_delegate_stateid
, sizeof(stateid_t
));
2191 WRITE32(open
->op_recall
);
2194 * TODO: ACE's in delegations
2196 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
2199 WRITE32(0); /* XXX: is NULL principal ok? */
2202 case NFS4_OPEN_DELEGATE_WRITE
:
2203 RESERVE_SPACE(32 + sizeof(stateid_t
));
2204 WRITEMEM(&open
->op_delegate_stateid
, sizeof(stateid_t
));
2208 * TODO: space_limit's in delegations
2210 WRITE32(NFS4_LIMIT_SIZE
);
2215 * TODO: ACE's in delegations
2217 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
2220 WRITE32(0); /* XXX: is NULL principal ok? */
2226 /* XXX save filehandle here */
2228 ENCODE_SEQID_OP_TAIL(open
->op_stateowner
);
2232 nfsd4_encode_open_confirm(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_confirm
*oc
)
2234 ENCODE_SEQID_OP_HEAD
;
2237 RESERVE_SPACE(sizeof(stateid_t
));
2238 WRITE32(oc
->oc_resp_stateid
.si_generation
);
2239 WRITEMEM(&oc
->oc_resp_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
2243 ENCODE_SEQID_OP_TAIL(oc
->oc_stateowner
);
2247 nfsd4_encode_open_downgrade(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_downgrade
*od
)
2249 ENCODE_SEQID_OP_HEAD
;
2252 RESERVE_SPACE(sizeof(stateid_t
));
2253 WRITE32(od
->od_stateid
.si_generation
);
2254 WRITEMEM(&od
->od_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
2258 ENCODE_SEQID_OP_TAIL(od
->od_stateowner
);
2262 nfsd4_encode_read(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
2263 struct nfsd4_read
*read
)
2267 unsigned long maxcount
;
2273 if (resp
->xbuf
->page_len
)
2274 return nfserr_resource
;
2276 RESERVE_SPACE(8); /* eof flag and byte count */
2278 maxcount
= svc_max_payload(resp
->rqstp
);
2279 if (maxcount
> read
->rd_length
)
2280 maxcount
= read
->rd_length
;
2285 pn
= resp
->rqstp
->rq_resused
++;
2286 resp
->rqstp
->rq_vec
[v
].iov_base
=
2287 page_address(resp
->rqstp
->rq_respages
[pn
]);
2288 resp
->rqstp
->rq_vec
[v
].iov_len
=
2289 len
< PAGE_SIZE
? len
: PAGE_SIZE
;
2295 nfserr
= nfsd_read(read
->rd_rqstp
, read
->rd_fhp
, read
->rd_filp
,
2296 read
->rd_offset
, resp
->rqstp
->rq_vec
, read
->rd_vlen
,
2299 if (nfserr
== nfserr_symlink
)
2300 nfserr
= nfserr_inval
;
2303 eof
= (read
->rd_offset
+ maxcount
>=
2304 read
->rd_fhp
->fh_dentry
->d_inode
->i_size
);
2309 resp
->xbuf
->head
[0].iov_len
= (char*)p
2310 - (char*)resp
->xbuf
->head
[0].iov_base
;
2311 resp
->xbuf
->page_len
= maxcount
;
2313 /* Use rest of head for padding and remaining ops: */
2314 resp
->xbuf
->tail
[0].iov_base
= p
;
2315 resp
->xbuf
->tail
[0].iov_len
= 0;
2319 resp
->xbuf
->tail
[0].iov_base
+= maxcount
&3;
2320 resp
->xbuf
->tail
[0].iov_len
= 4 - (maxcount
&3);
2327 nfsd4_encode_readlink(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readlink
*readlink
)
2335 if (resp
->xbuf
->page_len
)
2336 return nfserr_resource
;
2338 page
= page_address(resp
->rqstp
->rq_respages
[resp
->rqstp
->rq_resused
++]);
2340 maxcount
= PAGE_SIZE
;
2344 * XXX: By default, the ->readlink() VFS op will truncate symlinks
2345 * if they would overflow the buffer. Is this kosher in NFSv4? If
2346 * not, one easy fix is: if ->readlink() precisely fills the buffer,
2347 * assume that truncation occurred, and return NFS4ERR_RESOURCE.
2349 nfserr
= nfsd_readlink(readlink
->rl_rqstp
, readlink
->rl_fhp
, page
, &maxcount
);
2350 if (nfserr
== nfserr_isdir
)
2351 return nfserr_inval
;
2357 resp
->xbuf
->head
[0].iov_len
= (char*)p
2358 - (char*)resp
->xbuf
->head
[0].iov_base
;
2359 resp
->xbuf
->page_len
= maxcount
;
2361 /* Use rest of head for padding and remaining ops: */
2362 resp
->xbuf
->tail
[0].iov_base
= p
;
2363 resp
->xbuf
->tail
[0].iov_len
= 0;
2367 resp
->xbuf
->tail
[0].iov_base
+= maxcount
&3;
2368 resp
->xbuf
->tail
[0].iov_len
= 4 - (maxcount
&3);
2375 nfsd4_encode_readdir(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readdir
*readdir
)
2379 __be32
*page
, *savep
, *tailbase
;
2384 if (resp
->xbuf
->page_len
)
2385 return nfserr_resource
;
2387 RESERVE_SPACE(8); /* verifier */
2390 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
2394 resp
->xbuf
->head
[0].iov_len
= ((char*)resp
->p
) - (char*)resp
->xbuf
->head
[0].iov_base
;
2397 maxcount
= PAGE_SIZE
;
2398 if (maxcount
> readdir
->rd_maxcount
)
2399 maxcount
= readdir
->rd_maxcount
;
2402 * Convert from bytes to words, account for the two words already
2403 * written, make sure to leave two words at the end for the next
2404 * pointer and eof field.
2406 maxcount
= (maxcount
>> 2) - 4;
2408 nfserr
= nfserr_toosmall
;
2412 page
= page_address(resp
->rqstp
->rq_respages
[resp
->rqstp
->rq_resused
++]);
2413 readdir
->common
.err
= 0;
2414 readdir
->buflen
= maxcount
;
2415 readdir
->buffer
= page
;
2416 readdir
->offset
= NULL
;
2418 offset
= readdir
->rd_cookie
;
2419 nfserr
= nfsd_readdir(readdir
->rd_rqstp
, readdir
->rd_fhp
,
2421 &readdir
->common
, nfsd4_encode_dirent
);
2422 if (nfserr
== nfs_ok
&&
2423 readdir
->common
.err
== nfserr_toosmall
&&
2424 readdir
->buffer
== page
)
2425 nfserr
= nfserr_toosmall
;
2426 if (nfserr
== nfserr_symlink
)
2427 nfserr
= nfserr_notdir
;
2431 if (readdir
->offset
)
2432 xdr_encode_hyper(readdir
->offset
, offset
);
2434 p
= readdir
->buffer
;
2435 *p
++ = 0; /* no more entries */
2436 *p
++ = htonl(readdir
->common
.err
== nfserr_eof
);
2437 resp
->xbuf
->page_len
= ((char*)p
) - (char*)page_address(
2438 resp
->rqstp
->rq_respages
[resp
->rqstp
->rq_resused
-1]);
2440 /* Use rest of head for padding and remaining ops: */
2441 resp
->xbuf
->tail
[0].iov_base
= tailbase
;
2442 resp
->xbuf
->tail
[0].iov_len
= 0;
2443 resp
->p
= resp
->xbuf
->tail
[0].iov_base
;
2444 resp
->end
= resp
->p
+ (PAGE_SIZE
- resp
->xbuf
->head
[0].iov_len
)/4;
2454 nfsd4_encode_remove(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_remove
*remove
)
2460 WRITECINFO(remove
->rm_cinfo
);
2466 nfsd4_encode_rename(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_rename
*rename
)
2472 WRITECINFO(rename
->rn_sinfo
);
2473 WRITECINFO(rename
->rn_tinfo
);
2479 nfsd4_encode_secinfo(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
2480 struct nfsd4_secinfo
*secinfo
)
2483 struct svc_export
*exp
= secinfo
->si_exp
;
2485 struct exp_flavor_info
*flavs
;
2486 struct exp_flavor_info def_flavs
[2];
2491 if (exp
->ex_nflavors
) {
2492 flavs
= exp
->ex_flavors
;
2493 nflavs
= exp
->ex_nflavors
;
2494 } else { /* Handling of some defaults in absence of real secinfo: */
2496 if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_UNIX
) {
2498 flavs
[0].pseudoflavor
= RPC_AUTH_UNIX
;
2499 flavs
[1].pseudoflavor
= RPC_AUTH_NULL
;
2500 } else if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_GSS
) {
2502 flavs
[0].pseudoflavor
2503 = svcauth_gss_flavor(exp
->ex_client
);
2506 flavs
[0].pseudoflavor
2507 = exp
->ex_client
->flavour
->flavour
;
2514 for (i
= 0; i
< nflavs
; i
++) {
2515 u32 flav
= flavs
[i
].pseudoflavor
;
2516 struct gss_api_mech
*gm
= gss_mech_get_by_pseudoflavor(flav
);
2520 WRITE32(RPC_AUTH_GSS
);
2522 RESERVE_SPACE(4 + gm
->gm_oid
.len
);
2523 WRITE32(gm
->gm_oid
.len
);
2524 WRITEMEM(gm
->gm_oid
.data
, gm
->gm_oid
.len
);
2527 WRITE32(0); /* qop */
2530 WRITE32(gss_pseudoflavor_to_service(gm
, flav
));
2545 * The SETATTR encode routine is special -- it always encodes a bitmap,
2546 * regardless of the error status.
2549 nfsd4_encode_setattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setattr
*setattr
)
2561 WRITE32(setattr
->sa_bmval
[0]);
2562 WRITE32(setattr
->sa_bmval
[1]);
2568 nfsd4_encode_setclientid(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setclientid
*scd
)
2573 RESERVE_SPACE(8 + sizeof(nfs4_verifier
));
2574 WRITEMEM(&scd
->se_clientid
, 8);
2575 WRITEMEM(&scd
->se_confirm
, sizeof(nfs4_verifier
));
2578 else if (nfserr
== nfserr_clid_inuse
) {
2587 nfsd4_encode_write(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_write
*write
)
2593 WRITE32(write
->wr_bytes_written
);
2594 WRITE32(write
->wr_how_written
);
2595 WRITEMEM(write
->wr_verifier
.data
, 8);
2601 nfsd4_encode_operation(struct nfsd4_compoundres
*resp
, struct nfsd4_op
*op
)
2608 statp
= p
++; /* to be backfilled at the end */
2611 switch (op
->opnum
) {
2613 nfsd4_encode_access(resp
, op
->status
, &op
->u
.access
);
2616 nfsd4_encode_close(resp
, op
->status
, &op
->u
.close
);
2619 nfsd4_encode_commit(resp
, op
->status
, &op
->u
.commit
);
2622 nfsd4_encode_create(resp
, op
->status
, &op
->u
.create
);
2624 case OP_DELEGRETURN
:
2627 op
->status
= nfsd4_encode_getattr(resp
, op
->status
, &op
->u
.getattr
);
2630 nfsd4_encode_getfh(resp
, op
->status
, op
->u
.getfh
);
2633 nfsd4_encode_link(resp
, op
->status
, &op
->u
.link
);
2636 nfsd4_encode_lock(resp
, op
->status
, &op
->u
.lock
);
2639 nfsd4_encode_lockt(resp
, op
->status
, &op
->u
.lockt
);
2642 nfsd4_encode_locku(resp
, op
->status
, &op
->u
.locku
);
2651 nfsd4_encode_open(resp
, op
->status
, &op
->u
.open
);
2653 case OP_OPEN_CONFIRM
:
2654 nfsd4_encode_open_confirm(resp
, op
->status
, &op
->u
.open_confirm
);
2656 case OP_OPEN_DOWNGRADE
:
2657 nfsd4_encode_open_downgrade(resp
, op
->status
, &op
->u
.open_downgrade
);
2664 op
->status
= nfsd4_encode_read(resp
, op
->status
, &op
->u
.read
);
2667 op
->status
= nfsd4_encode_readdir(resp
, op
->status
, &op
->u
.readdir
);
2670 op
->status
= nfsd4_encode_readlink(resp
, op
->status
, &op
->u
.readlink
);
2673 nfsd4_encode_remove(resp
, op
->status
, &op
->u
.remove
);
2676 nfsd4_encode_rename(resp
, op
->status
, &op
->u
.rename
);
2685 nfsd4_encode_secinfo(resp
, op
->status
, &op
->u
.secinfo
);
2688 nfsd4_encode_setattr(resp
, op
->status
, &op
->u
.setattr
);
2690 case OP_SETCLIENTID
:
2691 nfsd4_encode_setclientid(resp
, op
->status
, &op
->u
.setclientid
);
2693 case OP_SETCLIENTID_CONFIRM
:
2698 nfsd4_encode_write(resp
, op
->status
, &op
->u
.write
);
2700 case OP_RELEASE_LOCKOWNER
:
2707 * Note: We write the status directly, instead of using WRITE32(),
2708 * since it is already in network byte order.
2710 *statp
= op
->status
;
2714 * Encode the reply stored in the stateowner reply cache
2716 * XDR note: do not encode rp->rp_buflen: the buffer contains the
2717 * previously sent already encoded operation.
2719 * called with nfs4_lock_state() held
2722 nfsd4_encode_replay(struct nfsd4_compoundres
*resp
, struct nfsd4_op
*op
)
2725 struct nfs4_replay
*rp
= op
->replay
;
2731 *p
++ = rp
->rp_status
; /* already xdr'ed */
2734 RESERVE_SPACE(rp
->rp_buflen
);
2735 WRITEMEM(rp
->rp_buf
, rp
->rp_buflen
);
2740 * END OF "GENERIC" ENCODE ROUTINES.
2744 nfs4svc_encode_voidres(struct svc_rqst
*rqstp
, __be32
*p
, void *dummy
)
2746 return xdr_ressize_check(rqstp
, p
);
2749 void nfsd4_release_compoundargs(struct nfsd4_compoundargs
*args
)
2751 if (args
->ops
!= args
->iops
) {
2753 args
->ops
= args
->iops
;
2757 while (args
->to_free
) {
2758 struct tmpbuf
*tb
= args
->to_free
;
2759 args
->to_free
= tb
->next
;
2760 tb
->release(tb
->buf
);
2766 nfs4svc_decode_compoundargs(struct svc_rqst
*rqstp
, __be32
*p
, struct nfsd4_compoundargs
*args
)
2771 args
->end
= rqstp
->rq_arg
.head
[0].iov_base
+ rqstp
->rq_arg
.head
[0].iov_len
;
2772 args
->pagelist
= rqstp
->rq_arg
.pages
;
2773 args
->pagelen
= rqstp
->rq_arg
.page_len
;
2775 args
->to_free
= NULL
;
2776 args
->ops
= args
->iops
;
2777 args
->rqstp
= rqstp
;
2779 status
= nfsd4_decode_compound(args
);
2781 nfsd4_release_compoundargs(args
);
2787 nfs4svc_encode_compoundres(struct svc_rqst
*rqstp
, __be32
*p
, struct nfsd4_compoundres
*resp
)
2790 * All that remains is to write the tag and operation count...
2794 *p
++ = htonl(resp
->taglen
);
2795 memcpy(p
, resp
->tag
, resp
->taglen
);
2796 p
+= XDR_QUADLEN(resp
->taglen
);
2797 *p
++ = htonl(resp
->opcnt
);
2799 if (rqstp
->rq_res
.page_len
)
2800 iov
= &rqstp
->rq_res
.tail
[0];
2802 iov
= &rqstp
->rq_res
.head
[0];
2803 iov
->iov_len
= ((char*)resp
->p
) - (char*)iov
->iov_base
;
2804 BUG_ON(iov
->iov_len
> PAGE_SIZE
);