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_MODIFY_SET
) {
384 case NFS4_SET_TO_CLIENT_TIME
:
385 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
386 all 32 bits of 'nseconds'. */
392 READ32(iattr
->ia_mtime
.tv_sec
);
393 READ32(iattr
->ia_mtime
.tv_nsec
);
394 if (iattr
->ia_mtime
.tv_nsec
>= (u32
)1000000000)
396 iattr
->ia_valid
|= (ATTR_MTIME
| ATTR_MTIME_SET
);
398 case NFS4_SET_TO_SERVER_TIME
:
399 iattr
->ia_valid
|= ATTR_MTIME
;
405 if (len
!= expected_len
)
411 status
= nfserrno(host_err
);
416 nfsd4_decode_stateid(struct nfsd4_compoundargs
*argp
, stateid_t
*sid
)
420 READ_BUF(sizeof(stateid_t
));
421 READ32(sid
->si_generation
);
422 COPYMEM(&sid
->si_opaque
, sizeof(stateid_opaque_t
));
428 nfsd4_decode_access(struct nfsd4_compoundargs
*argp
, struct nfsd4_access
*access
)
433 READ32(access
->ac_req_access
);
439 nfsd4_decode_close(struct nfsd4_compoundargs
*argp
, struct nfsd4_close
*close
)
443 close
->cl_stateowner
= NULL
;
445 READ32(close
->cl_seqid
);
446 return nfsd4_decode_stateid(argp
, &close
->cl_stateid
);
453 nfsd4_decode_commit(struct nfsd4_compoundargs
*argp
, struct nfsd4_commit
*commit
)
458 READ64(commit
->co_offset
);
459 READ32(commit
->co_count
);
465 nfsd4_decode_create(struct nfsd4_compoundargs
*argp
, struct nfsd4_create
*create
)
470 READ32(create
->cr_type
);
471 switch (create
->cr_type
) {
474 READ32(create
->cr_linklen
);
475 READ_BUF(create
->cr_linklen
);
476 SAVEMEM(create
->cr_linkname
, create
->cr_linklen
);
481 READ32(create
->cr_specdata1
);
482 READ32(create
->cr_specdata2
);
492 READ32(create
->cr_namelen
);
493 READ_BUF(create
->cr_namelen
);
494 SAVEMEM(create
->cr_name
, create
->cr_namelen
);
495 if ((status
= check_filename(create
->cr_name
, create
->cr_namelen
, nfserr_inval
)))
498 if ((status
= nfsd4_decode_fattr(argp
, create
->cr_bmval
, &create
->cr_iattr
, &create
->cr_acl
)))
505 nfsd4_decode_delegreturn(struct nfsd4_compoundargs
*argp
, struct nfsd4_delegreturn
*dr
)
507 return nfsd4_decode_stateid(argp
, &dr
->dr_stateid
);
511 nfsd4_decode_getattr(struct nfsd4_compoundargs
*argp
, struct nfsd4_getattr
*getattr
)
513 return nfsd4_decode_bitmap(argp
, getattr
->ga_bmval
);
517 nfsd4_decode_link(struct nfsd4_compoundargs
*argp
, struct nfsd4_link
*link
)
522 READ32(link
->li_namelen
);
523 READ_BUF(link
->li_namelen
);
524 SAVEMEM(link
->li_name
, link
->li_namelen
);
525 if ((status
= check_filename(link
->li_name
, link
->li_namelen
, nfserr_inval
)))
532 nfsd4_decode_lock(struct nfsd4_compoundargs
*argp
, struct nfsd4_lock
*lock
)
536 lock
->lk_replay_owner
= NULL
;
538 * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
541 READ32(lock
->lk_type
);
542 if ((lock
->lk_type
< NFS4_READ_LT
) || (lock
->lk_type
> NFS4_WRITEW_LT
))
544 READ32(lock
->lk_reclaim
);
545 READ64(lock
->lk_offset
);
546 READ64(lock
->lk_length
);
547 READ32(lock
->lk_is_new
);
549 if (lock
->lk_is_new
) {
551 READ32(lock
->lk_new_open_seqid
);
552 status
= nfsd4_decode_stateid(argp
, &lock
->lk_new_open_stateid
);
555 READ_BUF(8 + sizeof(clientid_t
));
556 READ32(lock
->lk_new_lock_seqid
);
557 COPYMEM(&lock
->lk_new_clientid
, sizeof(clientid_t
));
558 READ32(lock
->lk_new_owner
.len
);
559 READ_BUF(lock
->lk_new_owner
.len
);
560 READMEM(lock
->lk_new_owner
.data
, lock
->lk_new_owner
.len
);
562 status
= nfsd4_decode_stateid(argp
, &lock
->lk_old_lock_stateid
);
566 READ32(lock
->lk_old_lock_seqid
);
573 nfsd4_decode_lockt(struct nfsd4_compoundargs
*argp
, struct nfsd4_lockt
*lockt
)
578 READ32(lockt
->lt_type
);
579 if((lockt
->lt_type
< NFS4_READ_LT
) || (lockt
->lt_type
> NFS4_WRITEW_LT
))
581 READ64(lockt
->lt_offset
);
582 READ64(lockt
->lt_length
);
583 COPYMEM(&lockt
->lt_clientid
, 8);
584 READ32(lockt
->lt_owner
.len
);
585 READ_BUF(lockt
->lt_owner
.len
);
586 READMEM(lockt
->lt_owner
.data
, lockt
->lt_owner
.len
);
592 nfsd4_decode_locku(struct nfsd4_compoundargs
*argp
, struct nfsd4_locku
*locku
)
596 locku
->lu_stateowner
= NULL
;
598 READ32(locku
->lu_type
);
599 if ((locku
->lu_type
< NFS4_READ_LT
) || (locku
->lu_type
> NFS4_WRITEW_LT
))
601 READ32(locku
->lu_seqid
);
602 status
= nfsd4_decode_stateid(argp
, &locku
->lu_stateid
);
606 READ64(locku
->lu_offset
);
607 READ64(locku
->lu_length
);
613 nfsd4_decode_lookup(struct nfsd4_compoundargs
*argp
, struct nfsd4_lookup
*lookup
)
618 READ32(lookup
->lo_len
);
619 READ_BUF(lookup
->lo_len
);
620 SAVEMEM(lookup
->lo_name
, lookup
->lo_len
);
621 if ((status
= check_filename(lookup
->lo_name
, lookup
->lo_len
, nfserr_noent
)))
628 nfsd4_decode_open(struct nfsd4_compoundargs
*argp
, struct nfsd4_open
*open
)
632 memset(open
->op_bmval
, 0, sizeof(open
->op_bmval
));
633 open
->op_iattr
.ia_valid
= 0;
634 open
->op_stateowner
= NULL
;
636 /* seqid, share_access, share_deny, clientid, ownerlen */
637 READ_BUF(16 + sizeof(clientid_t
));
638 READ32(open
->op_seqid
);
639 READ32(open
->op_share_access
);
640 READ32(open
->op_share_deny
);
641 COPYMEM(&open
->op_clientid
, sizeof(clientid_t
));
642 READ32(open
->op_owner
.len
);
644 /* owner, open_flag */
645 READ_BUF(open
->op_owner
.len
+ 4);
646 SAVEMEM(open
->op_owner
.data
, open
->op_owner
.len
);
647 READ32(open
->op_create
);
648 switch (open
->op_create
) {
649 case NFS4_OPEN_NOCREATE
:
651 case NFS4_OPEN_CREATE
:
653 READ32(open
->op_createmode
);
654 switch (open
->op_createmode
) {
655 case NFS4_CREATE_UNCHECKED
:
656 case NFS4_CREATE_GUARDED
:
657 if ((status
= nfsd4_decode_fattr(argp
, open
->op_bmval
, &open
->op_iattr
, &open
->op_acl
)))
660 case NFS4_CREATE_EXCLUSIVE
:
662 COPYMEM(open
->op_verf
.data
, 8);
674 READ32(open
->op_claim_type
);
675 switch (open
->op_claim_type
) {
676 case NFS4_OPEN_CLAIM_NULL
:
677 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
679 READ32(open
->op_fname
.len
);
680 READ_BUF(open
->op_fname
.len
);
681 SAVEMEM(open
->op_fname
.data
, open
->op_fname
.len
);
682 if ((status
= check_filename(open
->op_fname
.data
, open
->op_fname
.len
, nfserr_inval
)))
685 case NFS4_OPEN_CLAIM_PREVIOUS
:
687 READ32(open
->op_delegate_type
);
689 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
690 status
= nfsd4_decode_stateid(argp
, &open
->op_delegate_stateid
);
694 READ32(open
->op_fname
.len
);
695 READ_BUF(open
->op_fname
.len
);
696 SAVEMEM(open
->op_fname
.data
, open
->op_fname
.len
);
697 if ((status
= check_filename(open
->op_fname
.data
, open
->op_fname
.len
, nfserr_inval
)))
708 nfsd4_decode_open_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_confirm
*open_conf
)
712 open_conf
->oc_stateowner
= NULL
;
713 status
= nfsd4_decode_stateid(argp
, &open_conf
->oc_req_stateid
);
717 READ32(open_conf
->oc_seqid
);
723 nfsd4_decode_open_downgrade(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_downgrade
*open_down
)
727 open_down
->od_stateowner
= NULL
;
728 status
= nfsd4_decode_stateid(argp
, &open_down
->od_stateid
);
732 READ32(open_down
->od_seqid
);
733 READ32(open_down
->od_share_access
);
734 READ32(open_down
->od_share_deny
);
740 nfsd4_decode_putfh(struct nfsd4_compoundargs
*argp
, struct nfsd4_putfh
*putfh
)
745 READ32(putfh
->pf_fhlen
);
746 if (putfh
->pf_fhlen
> NFS4_FHSIZE
)
748 READ_BUF(putfh
->pf_fhlen
);
749 SAVEMEM(putfh
->pf_fhval
, putfh
->pf_fhlen
);
755 nfsd4_decode_read(struct nfsd4_compoundargs
*argp
, struct nfsd4_read
*read
)
759 status
= nfsd4_decode_stateid(argp
, &read
->rd_stateid
);
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 status
= nfsd4_decode_stateid(argp
, &setattr
->sa_stateid
);
856 return nfsd4_decode_fattr(argp
, setattr
->sa_bmval
,
857 &setattr
->sa_iattr
, &setattr
->sa_acl
);
861 nfsd4_decode_setclientid(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid
*setclientid
)
866 COPYMEM(setclientid
->se_verf
.data
, 8);
867 READ32(setclientid
->se_namelen
);
869 READ_BUF(setclientid
->se_namelen
+ 8);
870 SAVEMEM(setclientid
->se_name
, setclientid
->se_namelen
);
871 READ32(setclientid
->se_callback_prog
);
872 READ32(setclientid
->se_callback_netid_len
);
874 READ_BUF(setclientid
->se_callback_netid_len
+ 4);
875 SAVEMEM(setclientid
->se_callback_netid_val
, setclientid
->se_callback_netid_len
);
876 READ32(setclientid
->se_callback_addr_len
);
878 READ_BUF(setclientid
->se_callback_addr_len
+ 4);
879 SAVEMEM(setclientid
->se_callback_addr_val
, setclientid
->se_callback_addr_len
);
880 READ32(setclientid
->se_callback_ident
);
886 nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid_confirm
*scd_c
)
890 READ_BUF(8 + sizeof(nfs4_verifier
));
891 COPYMEM(&scd_c
->sc_clientid
, 8);
892 COPYMEM(&scd_c
->sc_confirm
, sizeof(nfs4_verifier
));
897 /* Also used for NVERIFY */
899 nfsd4_decode_verify(struct nfsd4_compoundargs
*argp
, struct nfsd4_verify
*verify
)
902 struct nfsd4_compoundargs save
= {
905 .rqstp
= argp
->rqstp
,
908 struct iattr ve_iattr
; /* request */
909 struct nfs4_acl
*ve_acl
; /* request */
913 if ((status
= nfsd4_decode_bitmap(argp
, verify
->ve_bmval
)))
916 /* For convenience's sake, we compare raw xdr'd attributes in
917 * nfsd4_proc_verify; however we still decode here just to return
918 * correct error in case of bad xdr. */
920 status
= nfsd4_decode_fattr(ve_bmval
, &ve_iattr
, &ve_acl
);
921 if (status
== nfserr_inval
) {
922 status
= nfserrno(status
);
927 READ32(verify
->ve_attrlen
);
928 READ_BUF(verify
->ve_attrlen
);
929 SAVEMEM(verify
->ve_attrval
, verify
->ve_attrlen
);
935 nfsd4_decode_write(struct nfsd4_compoundargs
*argp
, struct nfsd4_write
*write
)
942 status
= nfsd4_decode_stateid(argp
, &write
->wr_stateid
);
946 READ64(write
->wr_offset
);
947 READ32(write
->wr_stable_how
);
948 if (write
->wr_stable_how
> 2)
950 READ32(write
->wr_buflen
);
952 /* Sorry .. no magic macros for this.. *
953 * READ_BUF(write->wr_buflen);
954 * SAVEMEM(write->wr_buf, write->wr_buflen);
956 avail
= (char*)argp
->end
- (char*)argp
->p
;
957 if (avail
+ argp
->pagelen
< write
->wr_buflen
) {
958 dprintk("NFSD: xdr error (%s:%d)\n",
962 argp
->rqstp
->rq_vec
[0].iov_base
= p
;
963 argp
->rqstp
->rq_vec
[0].iov_len
= avail
;
965 len
= write
->wr_buflen
;
966 while (len
> argp
->rqstp
->rq_vec
[v
].iov_len
) {
967 len
-= argp
->rqstp
->rq_vec
[v
].iov_len
;
969 argp
->rqstp
->rq_vec
[v
].iov_base
= page_address(argp
->pagelist
[0]);
971 if (argp
->pagelen
>= PAGE_SIZE
) {
972 argp
->rqstp
->rq_vec
[v
].iov_len
= PAGE_SIZE
;
973 argp
->pagelen
-= PAGE_SIZE
;
975 argp
->rqstp
->rq_vec
[v
].iov_len
= argp
->pagelen
;
976 argp
->pagelen
-= len
;
979 argp
->end
= (__be32
*) (argp
->rqstp
->rq_vec
[v
].iov_base
+ argp
->rqstp
->rq_vec
[v
].iov_len
);
980 argp
->p
= (__be32
*) (argp
->rqstp
->rq_vec
[v
].iov_base
+ (XDR_QUADLEN(len
) << 2));
981 argp
->rqstp
->rq_vec
[v
].iov_len
= len
;
982 write
->wr_vlen
= v
+1;
988 nfsd4_decode_release_lockowner(struct nfsd4_compoundargs
*argp
, struct nfsd4_release_lockowner
*rlockowner
)
993 COPYMEM(&rlockowner
->rl_clientid
, sizeof(clientid_t
));
994 READ32(rlockowner
->rl_owner
.len
);
995 READ_BUF(rlockowner
->rl_owner
.len
);
996 READMEM(rlockowner
->rl_owner
.data
, rlockowner
->rl_owner
.len
);
1002 nfsd4_decode_noop(struct nfsd4_compoundargs
*argp
, void *p
)
1008 nfsd4_decode_notsupp(struct nfsd4_compoundargs
*argp
, void *p
)
1010 return nfserr_opnotsupp
;
1013 typedef __be32(*nfsd4_dec
)(struct nfsd4_compoundargs
*argp
, void *);
1015 static nfsd4_dec nfsd4_dec_ops
[] = {
1016 [OP_ACCESS
] = (nfsd4_dec
)nfsd4_decode_access
,
1017 [OP_CLOSE
] = (nfsd4_dec
)nfsd4_decode_close
,
1018 [OP_COMMIT
] = (nfsd4_dec
)nfsd4_decode_commit
,
1019 [OP_CREATE
] = (nfsd4_dec
)nfsd4_decode_create
,
1020 [OP_DELEGPURGE
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1021 [OP_DELEGRETURN
] = (nfsd4_dec
)nfsd4_decode_delegreturn
,
1022 [OP_GETATTR
] = (nfsd4_dec
)nfsd4_decode_getattr
,
1023 [OP_GETFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1024 [OP_LINK
] = (nfsd4_dec
)nfsd4_decode_link
,
1025 [OP_LOCK
] = (nfsd4_dec
)nfsd4_decode_lock
,
1026 [OP_LOCKT
] = (nfsd4_dec
)nfsd4_decode_lockt
,
1027 [OP_LOCKU
] = (nfsd4_dec
)nfsd4_decode_locku
,
1028 [OP_LOOKUP
] = (nfsd4_dec
)nfsd4_decode_lookup
,
1029 [OP_LOOKUPP
] = (nfsd4_dec
)nfsd4_decode_noop
,
1030 [OP_NVERIFY
] = (nfsd4_dec
)nfsd4_decode_verify
,
1031 [OP_OPEN
] = (nfsd4_dec
)nfsd4_decode_open
,
1032 [OP_OPENATTR
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1033 [OP_OPEN_CONFIRM
] = (nfsd4_dec
)nfsd4_decode_open_confirm
,
1034 [OP_OPEN_DOWNGRADE
] = (nfsd4_dec
)nfsd4_decode_open_downgrade
,
1035 [OP_PUTFH
] = (nfsd4_dec
)nfsd4_decode_putfh
,
1036 [OP_PUTPUBFH
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1037 [OP_PUTROOTFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1038 [OP_READ
] = (nfsd4_dec
)nfsd4_decode_read
,
1039 [OP_READDIR
] = (nfsd4_dec
)nfsd4_decode_readdir
,
1040 [OP_READLINK
] = (nfsd4_dec
)nfsd4_decode_noop
,
1041 [OP_REMOVE
] = (nfsd4_dec
)nfsd4_decode_remove
,
1042 [OP_RENAME
] = (nfsd4_dec
)nfsd4_decode_rename
,
1043 [OP_RENEW
] = (nfsd4_dec
)nfsd4_decode_renew
,
1044 [OP_RESTOREFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1045 [OP_SAVEFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1046 [OP_SECINFO
] = (nfsd4_dec
)nfsd4_decode_secinfo
,
1047 [OP_SETATTR
] = (nfsd4_dec
)nfsd4_decode_setattr
,
1048 [OP_SETCLIENTID
] = (nfsd4_dec
)nfsd4_decode_setclientid
,
1049 [OP_SETCLIENTID_CONFIRM
] = (nfsd4_dec
)nfsd4_decode_setclientid_confirm
,
1050 [OP_VERIFY
] = (nfsd4_dec
)nfsd4_decode_verify
,
1051 [OP_WRITE
] = (nfsd4_dec
)nfsd4_decode_write
,
1052 [OP_RELEASE_LOCKOWNER
] = (nfsd4_dec
)nfsd4_decode_release_lockowner
,
1055 struct nfsd4_minorversion_ops
{
1056 nfsd4_dec
*decoders
;
1060 static struct nfsd4_minorversion_ops nfsd4_minorversion
[] = {
1061 [0] = { nfsd4_dec_ops
, ARRAY_SIZE(nfsd4_dec_ops
) },
1065 nfsd4_decode_compound(struct nfsd4_compoundargs
*argp
)
1068 struct nfsd4_op
*op
;
1069 struct nfsd4_minorversion_ops
*ops
;
1073 * XXX: According to spec, we should check the tag
1074 * for UTF-8 compliance. I'm postponing this for
1075 * now because it seems that some clients do use
1079 READ32(argp
->taglen
);
1080 READ_BUF(argp
->taglen
+ 8);
1081 SAVEMEM(argp
->tag
, argp
->taglen
);
1082 READ32(argp
->minorversion
);
1083 READ32(argp
->opcnt
);
1085 if (argp
->taglen
> NFSD4_MAX_TAGLEN
)
1087 if (argp
->opcnt
> 100)
1090 if (argp
->opcnt
> ARRAY_SIZE(argp
->iops
)) {
1091 argp
->ops
= kmalloc(argp
->opcnt
* sizeof(*argp
->ops
), GFP_KERNEL
);
1093 argp
->ops
= argp
->iops
;
1094 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
1099 if (argp
->minorversion
>= ARRAY_SIZE(nfsd4_minorversion
))
1102 ops
= &nfsd4_minorversion
[argp
->minorversion
];
1103 for (i
= 0; i
< argp
->opcnt
; i
++) {
1108 * We can't use READ_BUF() here because we need to handle
1109 * a missing opcode as an OP_WRITE + 1. So we need to check
1110 * to see if we're truly at the end of our buffer or if there
1111 * is another page we need to flip to.
1114 if (argp
->p
== argp
->end
) {
1115 if (argp
->pagelen
< 4) {
1116 /* There isn't an opcode still on the wire */
1117 op
->opnum
= OP_WRITE
+ 1;
1118 op
->status
= nfserr_bad_xdr
;
1124 * False alarm. We just hit a page boundary, but there
1125 * is still data available. Move pointer across page
1126 * boundary. *snip from READ_BUF*
1128 argp
->p
= page_address(argp
->pagelist
[0]);
1130 if (argp
->pagelen
< PAGE_SIZE
) {
1131 argp
->end
= p
+ (argp
->pagelen
>>2);
1134 argp
->end
= p
+ (PAGE_SIZE
>>2);
1135 argp
->pagelen
-= PAGE_SIZE
;
1138 op
->opnum
= ntohl(*argp
->p
++);
1140 if (op
->opnum
>= OP_ACCESS
&& op
->opnum
< ops
->nops
)
1141 op
->status
= ops
->decoders
[op
->opnum
](argp
, &op
->u
);
1143 op
->opnum
= OP_ILLEGAL
;
1144 op
->status
= nfserr_op_illegal
;
1156 * END OF "GENERIC" DECODE ROUTINES.
1160 * START OF "GENERIC" ENCODE ROUTINES.
1161 * These may look a little ugly since they are imported from a "generic"
1162 * set of XDR encode/decode routines which are intended to be shared by
1163 * all of our NFSv4 implementations (OpenBSD, MacOS X...).
1165 * If the pain of reading these is too great, it should be a straightforward
1166 * task to translate them into Linux-specific versions which are more
1167 * consistent with the style used in NFSv2/v3...
1169 #define ENCODE_HEAD __be32 *p
1171 #define WRITE32(n) *p++ = htonl(n)
1172 #define WRITE64(n) do { \
1173 *p++ = htonl((u32)((n) >> 32)); \
1174 *p++ = htonl((u32)(n)); \
1176 #define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \
1177 *(p + XDR_QUADLEN(nbytes) -1) = 0; \
1178 memcpy(p, ptr, nbytes); \
1179 p += XDR_QUADLEN(nbytes); \
1181 #define WRITECINFO(c) do { \
1182 *p++ = htonl(c.atomic); \
1183 *p++ = htonl(c.before_ctime_sec); \
1184 *p++ = htonl(c.before_ctime_nsec); \
1185 *p++ = htonl(c.after_ctime_sec); \
1186 *p++ = htonl(c.after_ctime_nsec); \
1189 #define RESERVE_SPACE(nbytes) do { \
1191 BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
1193 #define ADJUST_ARGS() resp->p = p
1196 * Header routine to setup seqid operation replay cache
1198 #define ENCODE_SEQID_OP_HEAD \
1204 * Routine for encoding the result of a "seqid-mutating" NFSv4 operation. This
1205 * is where sequence id's are incremented, and the replay cache is filled.
1206 * Note that we increment sequence id's here, at the last moment, so we're sure
1207 * we know whether the error to be returned is a sequence id mutating error.
1210 #define ENCODE_SEQID_OP_TAIL(stateowner) do { \
1211 if (seqid_mutating_err(nfserr) && stateowner) { \
1212 stateowner->so_seqid++; \
1213 stateowner->so_replay.rp_status = nfserr; \
1214 stateowner->so_replay.rp_buflen = \
1215 (((char *)(resp)->p - (char *)save)); \
1216 memcpy(stateowner->so_replay.rp_buf, save, \
1217 stateowner->so_replay.rp_buflen); \
1220 /* Encode as an array of strings the string given with components
1223 static __be32
nfsd4_encode_components(char sep
, char *components
,
1224 __be32
**pp
, int *buflen
)
1228 int strlen
, count
=0;
1231 dprintk("nfsd4_encode_components(%s)\n", components
);
1232 if ((*buflen
-= 4) < 0)
1233 return nfserr_resource
;
1234 WRITE32(0); /* We will fill this in with @count later */
1235 end
= str
= components
;
1237 for (; *end
&& (*end
!= sep
); end
++)
1238 ; /* Point to end of component */
1241 if ((*buflen
-= ((XDR_QUADLEN(strlen
) << 2) + 4)) < 0)
1242 return nfserr_resource
;
1244 WRITEMEM(str
, strlen
);
1258 * encode a location element of a fs_locations structure
1260 static __be32
nfsd4_encode_fs_location4(struct nfsd4_fs_location
*location
,
1261 __be32
**pp
, int *buflen
)
1266 status
= nfsd4_encode_components(':', location
->hosts
, &p
, buflen
);
1269 status
= nfsd4_encode_components('/', location
->path
, &p
, buflen
);
1277 * Return the path to an export point in the pseudo filesystem namespace
1278 * Returned string is safe to use as long as the caller holds a reference
1281 static char *nfsd4_path(struct svc_rqst
*rqstp
, struct svc_export
*exp
, __be32
*stat
)
1283 struct svc_fh tmp_fh
;
1284 char *path
, *rootpath
;
1286 fh_init(&tmp_fh
, NFS4_FHSIZE
);
1287 *stat
= exp_pseudoroot(rqstp
, &tmp_fh
);
1290 rootpath
= tmp_fh
.fh_export
->ex_pathname
;
1292 path
= exp
->ex_pathname
;
1294 if (strncmp(path
, rootpath
, strlen(rootpath
))) {
1295 dprintk("nfsd: fs_locations failed;"
1296 "%s is not contained in %s\n", path
, rootpath
);
1297 *stat
= nfserr_notsupp
;
1301 return path
+ strlen(rootpath
);
1305 * encode a fs_locations structure
1307 static __be32
nfsd4_encode_fs_locations(struct svc_rqst
*rqstp
,
1308 struct svc_export
*exp
,
1309 __be32
**pp
, int *buflen
)
1314 struct nfsd4_fs_locations
*fslocs
= &exp
->ex_fslocs
;
1315 char *root
= nfsd4_path(rqstp
, exp
, &status
);
1319 status
= nfsd4_encode_components('/', root
, &p
, buflen
);
1322 if ((*buflen
-= 4) < 0)
1323 return nfserr_resource
;
1324 WRITE32(fslocs
->locations_count
);
1325 for (i
=0; i
<fslocs
->locations_count
; i
++) {
1326 status
= nfsd4_encode_fs_location4(&fslocs
->locations
[i
],
1335 static u32 nfs4_ftypes
[16] = {
1336 NF4BAD
, NF4FIFO
, NF4CHR
, NF4BAD
,
1337 NF4DIR
, NF4BAD
, NF4BLK
, NF4BAD
,
1338 NF4REG
, NF4BAD
, NF4LNK
, NF4BAD
,
1339 NF4SOCK
, NF4BAD
, NF4LNK
, NF4BAD
,
1343 nfsd4_encode_name(struct svc_rqst
*rqstp
, int whotype
, uid_t id
, int group
,
1344 __be32
**p
, int *buflen
)
1348 if (*buflen
< (XDR_QUADLEN(IDMAP_NAMESZ
) << 2) + 4)
1349 return nfserr_resource
;
1350 if (whotype
!= NFS4_ACL_WHO_NAMED
)
1351 status
= nfs4_acl_write_who(whotype
, (u8
*)(*p
+ 1));
1353 status
= nfsd_map_gid_to_name(rqstp
, id
, (u8
*)(*p
+ 1));
1355 status
= nfsd_map_uid_to_name(rqstp
, id
, (u8
*)(*p
+ 1));
1357 return nfserrno(status
);
1358 *p
= xdr_encode_opaque(*p
, NULL
, status
);
1359 *buflen
-= (XDR_QUADLEN(status
) << 2) + 4;
1360 BUG_ON(*buflen
< 0);
1364 static inline __be32
1365 nfsd4_encode_user(struct svc_rqst
*rqstp
, uid_t uid
, __be32
**p
, int *buflen
)
1367 return nfsd4_encode_name(rqstp
, NFS4_ACL_WHO_NAMED
, uid
, 0, p
, buflen
);
1370 static inline __be32
1371 nfsd4_encode_group(struct svc_rqst
*rqstp
, uid_t gid
, __be32
**p
, int *buflen
)
1373 return nfsd4_encode_name(rqstp
, NFS4_ACL_WHO_NAMED
, gid
, 1, p
, buflen
);
1376 static inline __be32
1377 nfsd4_encode_aclname(struct svc_rqst
*rqstp
, int whotype
, uid_t id
, int group
,
1378 __be32
**p
, int *buflen
)
1380 return nfsd4_encode_name(rqstp
, whotype
, id
, group
, p
, buflen
);
1383 #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
1384 FATTR4_WORD0_RDATTR_ERROR)
1385 #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
1387 static __be32
fattr_handle_absent_fs(u32
*bmval0
, u32
*bmval1
, u32
*rdattr_err
)
1389 /* As per referral draft: */
1390 if (*bmval0
& ~WORD0_ABSENT_FS_ATTRS
||
1391 *bmval1
& ~WORD1_ABSENT_FS_ATTRS
) {
1392 if (*bmval0
& FATTR4_WORD0_RDATTR_ERROR
||
1393 *bmval0
& FATTR4_WORD0_FS_LOCATIONS
)
1394 *rdattr_err
= NFSERR_MOVED
;
1396 return nfserr_moved
;
1398 *bmval0
&= WORD0_ABSENT_FS_ATTRS
;
1399 *bmval1
&= WORD1_ABSENT_FS_ATTRS
;
1404 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
1407 * @countp is the buffer size in _words_; upon successful return this becomes
1408 * replaced with the number of words written.
1411 nfsd4_encode_fattr(struct svc_fh
*fhp
, struct svc_export
*exp
,
1412 struct dentry
*dentry
, __be32
*buffer
, int *countp
, u32
*bmval
,
1413 struct svc_rqst
*rqstp
, int ignore_crossmnt
)
1415 u32 bmval0
= bmval
[0];
1416 u32 bmval1
= bmval
[1];
1418 struct svc_fh tempfh
;
1419 struct kstatfs statfs
;
1420 int buflen
= *countp
<< 2;
1429 struct nfs4_acl
*acl
= NULL
;
1431 BUG_ON(bmval1
& NFSD_WRITEONLY_ATTRS_WORD1
);
1432 BUG_ON(bmval0
& ~NFSD_SUPPORTED_ATTRS_WORD0
);
1433 BUG_ON(bmval1
& ~NFSD_SUPPORTED_ATTRS_WORD1
);
1435 if (exp
->ex_fslocs
.migrated
) {
1436 status
= fattr_handle_absent_fs(&bmval0
, &bmval1
, &rdattr_err
);
1441 err
= vfs_getattr(exp
->ex_path
.mnt
, dentry
, &stat
);
1444 if ((bmval0
& (FATTR4_WORD0_FILES_FREE
| FATTR4_WORD0_FILES_TOTAL
|
1445 FATTR4_WORD0_MAXNAME
)) ||
1446 (bmval1
& (FATTR4_WORD1_SPACE_AVAIL
| FATTR4_WORD1_SPACE_FREE
|
1447 FATTR4_WORD1_SPACE_TOTAL
))) {
1448 err
= vfs_statfs(dentry
, &statfs
);
1452 if ((bmval0
& (FATTR4_WORD0_FILEHANDLE
| FATTR4_WORD0_FSID
)) && !fhp
) {
1453 fh_init(&tempfh
, NFS4_FHSIZE
);
1454 status
= fh_compose(&tempfh
, exp
, dentry
, NULL
);
1459 if (bmval0
& (FATTR4_WORD0_ACL
| FATTR4_WORD0_ACLSUPPORT
1460 | FATTR4_WORD0_SUPPORTED_ATTRS
)) {
1461 err
= nfsd4_get_nfs4_acl(rqstp
, dentry
, &acl
);
1462 aclsupport
= (err
== 0);
1463 if (bmval0
& FATTR4_WORD0_ACL
) {
1464 if (err
== -EOPNOTSUPP
)
1465 bmval0
&= ~FATTR4_WORD0_ACL
;
1466 else if (err
== -EINVAL
) {
1467 status
= nfserr_attrnotsupp
;
1469 } else if (err
!= 0)
1473 if (bmval0
& FATTR4_WORD0_FS_LOCATIONS
) {
1474 if (exp
->ex_fslocs
.locations
== NULL
) {
1475 bmval0
&= ~FATTR4_WORD0_FS_LOCATIONS
;
1478 if ((buflen
-= 16) < 0)
1484 attrlenp
= p
++; /* to be backfilled later */
1486 if (bmval0
& FATTR4_WORD0_SUPPORTED_ATTRS
) {
1487 u32 word0
= NFSD_SUPPORTED_ATTRS_WORD0
;
1488 if ((buflen
-= 12) < 0)
1491 word0
&= ~FATTR4_WORD0_ACL
;
1492 if (!exp
->ex_fslocs
.locations
)
1493 word0
&= ~FATTR4_WORD0_FS_LOCATIONS
;
1496 WRITE32(NFSD_SUPPORTED_ATTRS_WORD1
);
1498 if (bmval0
& FATTR4_WORD0_TYPE
) {
1499 if ((buflen
-= 4) < 0)
1501 dummy
= nfs4_ftypes
[(stat
.mode
& S_IFMT
) >> 12];
1502 if (dummy
== NF4BAD
)
1503 goto out_serverfault
;
1506 if (bmval0
& FATTR4_WORD0_FH_EXPIRE_TYPE
) {
1507 if ((buflen
-= 4) < 0)
1509 if (exp
->ex_flags
& NFSEXP_NOSUBTREECHECK
)
1510 WRITE32(NFS4_FH_PERSISTENT
);
1512 WRITE32(NFS4_FH_PERSISTENT
|NFS4_FH_VOL_RENAME
);
1514 if (bmval0
& FATTR4_WORD0_CHANGE
) {
1516 * Note: This _must_ be consistent with the scheme for writing
1517 * change_info, so any changes made here must be reflected there
1518 * as well. (See xdr4.h:set_change_info() and the WRITECINFO()
1521 if ((buflen
-= 8) < 0)
1523 WRITE32(stat
.ctime
.tv_sec
);
1524 WRITE32(stat
.ctime
.tv_nsec
);
1526 if (bmval0
& FATTR4_WORD0_SIZE
) {
1527 if ((buflen
-= 8) < 0)
1531 if (bmval0
& FATTR4_WORD0_LINK_SUPPORT
) {
1532 if ((buflen
-= 4) < 0)
1536 if (bmval0
& FATTR4_WORD0_SYMLINK_SUPPORT
) {
1537 if ((buflen
-= 4) < 0)
1541 if (bmval0
& FATTR4_WORD0_NAMED_ATTR
) {
1542 if ((buflen
-= 4) < 0)
1546 if (bmval0
& FATTR4_WORD0_FSID
) {
1547 if ((buflen
-= 16) < 0)
1549 if (exp
->ex_fslocs
.migrated
) {
1550 WRITE64(NFS4_REFERRAL_FSID_MAJOR
);
1551 WRITE64(NFS4_REFERRAL_FSID_MINOR
);
1552 } else switch(fsid_source(fhp
)) {
1553 case FSIDSOURCE_FSID
:
1554 WRITE64((u64
)exp
->ex_fsid
);
1557 case FSIDSOURCE_DEV
:
1559 WRITE32(MAJOR(stat
.dev
));
1561 WRITE32(MINOR(stat
.dev
));
1563 case FSIDSOURCE_UUID
:
1564 WRITEMEM(exp
->ex_uuid
, 16);
1568 if (bmval0
& FATTR4_WORD0_UNIQUE_HANDLES
) {
1569 if ((buflen
-= 4) < 0)
1573 if (bmval0
& FATTR4_WORD0_LEASE_TIME
) {
1574 if ((buflen
-= 4) < 0)
1576 WRITE32(NFSD_LEASE_TIME
);
1578 if (bmval0
& FATTR4_WORD0_RDATTR_ERROR
) {
1579 if ((buflen
-= 4) < 0)
1581 WRITE32(rdattr_err
);
1583 if (bmval0
& FATTR4_WORD0_ACL
) {
1584 struct nfs4_ace
*ace
;
1587 if ((buflen
-= 4) < 0)
1593 if ((buflen
-= 4) < 0)
1595 WRITE32(acl
->naces
);
1597 for (ace
= acl
->aces
; ace
< acl
->aces
+ acl
->naces
; ace
++) {
1598 if ((buflen
-= 4*3) < 0)
1602 WRITE32(ace
->access_mask
& NFS4_ACE_MASK_ALL
);
1603 status
= nfsd4_encode_aclname(rqstp
, ace
->whotype
,
1604 ace
->who
, ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
,
1606 if (status
== nfserr_resource
)
1613 if (bmval0
& FATTR4_WORD0_ACLSUPPORT
) {
1614 if ((buflen
-= 4) < 0)
1616 WRITE32(aclsupport
?
1617 ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
: 0);
1619 if (bmval0
& FATTR4_WORD0_CANSETTIME
) {
1620 if ((buflen
-= 4) < 0)
1624 if (bmval0
& FATTR4_WORD0_CASE_INSENSITIVE
) {
1625 if ((buflen
-= 4) < 0)
1629 if (bmval0
& FATTR4_WORD0_CASE_PRESERVING
) {
1630 if ((buflen
-= 4) < 0)
1634 if (bmval0
& FATTR4_WORD0_CHOWN_RESTRICTED
) {
1635 if ((buflen
-= 4) < 0)
1639 if (bmval0
& FATTR4_WORD0_FILEHANDLE
) {
1640 buflen
-= (XDR_QUADLEN(fhp
->fh_handle
.fh_size
) << 2) + 4;
1643 WRITE32(fhp
->fh_handle
.fh_size
);
1644 WRITEMEM(&fhp
->fh_handle
.fh_base
, fhp
->fh_handle
.fh_size
);
1646 if (bmval0
& FATTR4_WORD0_FILEID
) {
1647 if ((buflen
-= 8) < 0)
1651 if (bmval0
& FATTR4_WORD0_FILES_AVAIL
) {
1652 if ((buflen
-= 8) < 0)
1654 WRITE64((u64
) statfs
.f_ffree
);
1656 if (bmval0
& FATTR4_WORD0_FILES_FREE
) {
1657 if ((buflen
-= 8) < 0)
1659 WRITE64((u64
) statfs
.f_ffree
);
1661 if (bmval0
& FATTR4_WORD0_FILES_TOTAL
) {
1662 if ((buflen
-= 8) < 0)
1664 WRITE64((u64
) statfs
.f_files
);
1666 if (bmval0
& FATTR4_WORD0_FS_LOCATIONS
) {
1667 status
= nfsd4_encode_fs_locations(rqstp
, exp
, &p
, &buflen
);
1668 if (status
== nfserr_resource
)
1673 if (bmval0
& FATTR4_WORD0_HOMOGENEOUS
) {
1674 if ((buflen
-= 4) < 0)
1678 if (bmval0
& FATTR4_WORD0_MAXFILESIZE
) {
1679 if ((buflen
-= 8) < 0)
1683 if (bmval0
& FATTR4_WORD0_MAXLINK
) {
1684 if ((buflen
-= 4) < 0)
1688 if (bmval0
& FATTR4_WORD0_MAXNAME
) {
1689 if ((buflen
-= 4) < 0)
1691 WRITE32(statfs
.f_namelen
);
1693 if (bmval0
& FATTR4_WORD0_MAXREAD
) {
1694 if ((buflen
-= 8) < 0)
1696 WRITE64((u64
) svc_max_payload(rqstp
));
1698 if (bmval0
& FATTR4_WORD0_MAXWRITE
) {
1699 if ((buflen
-= 8) < 0)
1701 WRITE64((u64
) svc_max_payload(rqstp
));
1703 if (bmval1
& FATTR4_WORD1_MODE
) {
1704 if ((buflen
-= 4) < 0)
1706 WRITE32(stat
.mode
& S_IALLUGO
);
1708 if (bmval1
& FATTR4_WORD1_NO_TRUNC
) {
1709 if ((buflen
-= 4) < 0)
1713 if (bmval1
& FATTR4_WORD1_NUMLINKS
) {
1714 if ((buflen
-= 4) < 0)
1716 WRITE32(stat
.nlink
);
1718 if (bmval1
& FATTR4_WORD1_OWNER
) {
1719 status
= nfsd4_encode_user(rqstp
, stat
.uid
, &p
, &buflen
);
1720 if (status
== nfserr_resource
)
1725 if (bmval1
& FATTR4_WORD1_OWNER_GROUP
) {
1726 status
= nfsd4_encode_group(rqstp
, stat
.gid
, &p
, &buflen
);
1727 if (status
== nfserr_resource
)
1732 if (bmval1
& FATTR4_WORD1_RAWDEV
) {
1733 if ((buflen
-= 8) < 0)
1735 WRITE32((u32
) MAJOR(stat
.rdev
));
1736 WRITE32((u32
) MINOR(stat
.rdev
));
1738 if (bmval1
& FATTR4_WORD1_SPACE_AVAIL
) {
1739 if ((buflen
-= 8) < 0)
1741 dummy64
= (u64
)statfs
.f_bavail
* (u64
)statfs
.f_bsize
;
1744 if (bmval1
& FATTR4_WORD1_SPACE_FREE
) {
1745 if ((buflen
-= 8) < 0)
1747 dummy64
= (u64
)statfs
.f_bfree
* (u64
)statfs
.f_bsize
;
1750 if (bmval1
& FATTR4_WORD1_SPACE_TOTAL
) {
1751 if ((buflen
-= 8) < 0)
1753 dummy64
= (u64
)statfs
.f_blocks
* (u64
)statfs
.f_bsize
;
1756 if (bmval1
& FATTR4_WORD1_SPACE_USED
) {
1757 if ((buflen
-= 8) < 0)
1759 dummy64
= (u64
)stat
.blocks
<< 9;
1762 if (bmval1
& FATTR4_WORD1_TIME_ACCESS
) {
1763 if ((buflen
-= 12) < 0)
1766 WRITE32(stat
.atime
.tv_sec
);
1767 WRITE32(stat
.atime
.tv_nsec
);
1769 if (bmval1
& FATTR4_WORD1_TIME_DELTA
) {
1770 if ((buflen
-= 12) < 0)
1776 if (bmval1
& FATTR4_WORD1_TIME_METADATA
) {
1777 if ((buflen
-= 12) < 0)
1780 WRITE32(stat
.ctime
.tv_sec
);
1781 WRITE32(stat
.ctime
.tv_nsec
);
1783 if (bmval1
& FATTR4_WORD1_TIME_MODIFY
) {
1784 if ((buflen
-= 12) < 0)
1787 WRITE32(stat
.mtime
.tv_sec
);
1788 WRITE32(stat
.mtime
.tv_nsec
);
1790 if (bmval1
& FATTR4_WORD1_MOUNTED_ON_FILEID
) {
1791 if ((buflen
-= 8) < 0)
1794 * Get parent's attributes if not ignoring crossmount
1795 * and this is the root of a cross-mounted filesystem.
1797 if (ignore_crossmnt
== 0 &&
1798 exp
->ex_path
.mnt
->mnt_root
->d_inode
== dentry
->d_inode
) {
1799 err
= vfs_getattr(exp
->ex_path
.mnt
->mnt_parent
,
1800 exp
->ex_path
.mnt
->mnt_mountpoint
, &stat
);
1806 *attrlenp
= htonl((char *)p
- (char *)attrlenp
- 4);
1807 *countp
= p
- buffer
;
1816 status
= nfserrno(err
);
1820 status
= nfserr_resource
;
1823 status
= nfserr_serverfault
;
1827 static inline int attributes_need_mount(u32
*bmval
)
1829 if (bmval
[0] & ~(FATTR4_WORD0_RDATTR_ERROR
| FATTR4_WORD0_LEASE_TIME
))
1831 if (bmval
[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID
)
1837 nfsd4_encode_dirent_fattr(struct nfsd4_readdir
*cd
,
1838 const char *name
, int namlen
, __be32
*p
, int *buflen
)
1840 struct svc_export
*exp
= cd
->rd_fhp
->fh_export
;
1841 struct dentry
*dentry
;
1843 int ignore_crossmnt
= 0;
1845 dentry
= lookup_one_len(name
, cd
->rd_fhp
->fh_dentry
, namlen
);
1847 return nfserrno(PTR_ERR(dentry
));
1851 * In the case of a mountpoint, the client may be asking for
1852 * attributes that are only properties of the underlying filesystem
1853 * as opposed to the cross-mounted file system. In such a case,
1854 * we will not follow the cross mount and will fill the attribtutes
1855 * directly from the mountpoint dentry.
1857 if (d_mountpoint(dentry
) && !attributes_need_mount(cd
->rd_bmval
))
1858 ignore_crossmnt
= 1;
1859 else if (d_mountpoint(dentry
)) {
1863 * Why the heck aren't we just using nfsd_lookup??
1864 * Different "."/".." handling? Something else?
1865 * At least, add a comment here to explain....
1867 err
= nfsd_cross_mnt(cd
->rd_rqstp
, &dentry
, &exp
);
1869 nfserr
= nfserrno(err
);
1872 nfserr
= check_nfsd_access(exp
, cd
->rd_rqstp
);
1877 nfserr
= nfsd4_encode_fattr(NULL
, exp
, dentry
, p
, buflen
, cd
->rd_bmval
,
1878 cd
->rd_rqstp
, ignore_crossmnt
);
1886 nfsd4_encode_rdattr_error(__be32
*p
, int buflen
, __be32 nfserr
)
1893 *p
++ = htonl(FATTR4_WORD0_RDATTR_ERROR
); /* bmval0 */
1894 *p
++ = htonl(0); /* bmval1 */
1897 *p
++ = nfserr
; /* no htonl */
1898 *attrlenp
= htonl((char *)p
- (char *)attrlenp
- 4);
1903 nfsd4_encode_dirent(void *ccdv
, const char *name
, int namlen
,
1904 loff_t offset
, u64 ino
, unsigned int d_type
)
1906 struct readdir_cd
*ccd
= ccdv
;
1907 struct nfsd4_readdir
*cd
= container_of(ccd
, struct nfsd4_readdir
, common
);
1909 __be32
*p
= cd
->buffer
;
1910 __be32 nfserr
= nfserr_toosmall
;
1912 /* In nfsv4, "." and ".." never make it onto the wire.. */
1913 if (name
&& isdotent(name
, namlen
)) {
1914 cd
->common
.err
= nfs_ok
;
1919 xdr_encode_hyper(cd
->offset
, (u64
) offset
);
1921 buflen
= cd
->buflen
- 4 - XDR_QUADLEN(namlen
);
1925 *p
++ = xdr_one
; /* mark entry present */
1926 cd
->offset
= p
; /* remember pointer */
1927 p
= xdr_encode_hyper(p
, NFS_OFFSET_MAX
); /* offset of next entry */
1928 p
= xdr_encode_array(p
, name
, namlen
); /* name length & name */
1930 nfserr
= nfsd4_encode_dirent_fattr(cd
, name
, namlen
, p
, &buflen
);
1935 case nfserr_resource
:
1936 nfserr
= nfserr_toosmall
;
1942 * If the client requested the RDATTR_ERROR attribute,
1943 * we stuff the error code into this attribute
1944 * and continue. If this attribute was not requested,
1945 * then in accordance with the spec, we fail the
1946 * entire READDIR operation(!)
1948 if (!(cd
->rd_bmval
[0] & FATTR4_WORD0_RDATTR_ERROR
))
1950 p
= nfsd4_encode_rdattr_error(p
, buflen
, nfserr
);
1952 nfserr
= nfserr_toosmall
;
1956 cd
->buflen
-= (p
- cd
->buffer
);
1958 cd
->common
.err
= nfs_ok
;
1961 cd
->common
.err
= nfserr
;
1966 nfsd4_encode_stateid(struct nfsd4_compoundres
*resp
, stateid_t
*sid
)
1970 RESERVE_SPACE(sizeof(stateid_t
));
1971 WRITE32(sid
->si_generation
);
1972 WRITEMEM(&sid
->si_opaque
, sizeof(stateid_opaque_t
));
1977 nfsd4_encode_access(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_access
*access
)
1983 WRITE32(access
->ac_supported
);
1984 WRITE32(access
->ac_resp_access
);
1991 nfsd4_encode_close(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_close
*close
)
1993 ENCODE_SEQID_OP_HEAD
;
1996 nfsd4_encode_stateid(resp
, &close
->cl_stateid
);
1998 ENCODE_SEQID_OP_TAIL(close
->cl_stateowner
);
2004 nfsd4_encode_commit(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_commit
*commit
)
2010 WRITEMEM(commit
->co_verf
.data
, 8);
2017 nfsd4_encode_create(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_create
*create
)
2023 WRITECINFO(create
->cr_cinfo
);
2025 WRITE32(create
->cr_bmval
[0]);
2026 WRITE32(create
->cr_bmval
[1]);
2033 nfsd4_encode_getattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_getattr
*getattr
)
2035 struct svc_fh
*fhp
= getattr
->ga_fhp
;
2041 buflen
= resp
->end
- resp
->p
- (COMPOUND_ERR_SLACK_SPACE
>> 2);
2042 nfserr
= nfsd4_encode_fattr(fhp
, fhp
->fh_export
, fhp
->fh_dentry
,
2043 resp
->p
, &buflen
, getattr
->ga_bmval
,
2051 nfsd4_encode_getfh(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct svc_fh
**fhpp
)
2053 struct svc_fh
*fhp
= *fhpp
;
2058 len
= fhp
->fh_handle
.fh_size
;
2059 RESERVE_SPACE(len
+ 4);
2061 WRITEMEM(&fhp
->fh_handle
.fh_base
, len
);
2068 * Including all fields other than the name, a LOCK4denied structure requires
2069 * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
2072 nfsd4_encode_lock_denied(struct nfsd4_compoundres
*resp
, struct nfsd4_lock_denied
*ld
)
2076 RESERVE_SPACE(32 + XDR_LEN(ld
->ld_sop
? ld
->ld_sop
->so_owner
.len
: 0));
2077 WRITE64(ld
->ld_start
);
2078 WRITE64(ld
->ld_length
);
2079 WRITE32(ld
->ld_type
);
2081 WRITEMEM(&ld
->ld_clientid
, 8);
2082 WRITE32(ld
->ld_sop
->so_owner
.len
);
2083 WRITEMEM(ld
->ld_sop
->so_owner
.data
, ld
->ld_sop
->so_owner
.len
);
2084 kref_put(&ld
->ld_sop
->so_ref
, nfs4_free_stateowner
);
2085 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
2086 WRITE64((u64
)0); /* clientid */
2087 WRITE32(0); /* length of owner name */
2093 nfsd4_encode_lock(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lock
*lock
)
2095 ENCODE_SEQID_OP_HEAD
;
2098 nfsd4_encode_stateid(resp
, &lock
->lk_resp_stateid
);
2099 else if (nfserr
== nfserr_denied
)
2100 nfsd4_encode_lock_denied(resp
, &lock
->lk_denied
);
2102 ENCODE_SEQID_OP_TAIL(lock
->lk_replay_owner
);
2107 nfsd4_encode_lockt(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lockt
*lockt
)
2109 if (nfserr
== nfserr_denied
)
2110 nfsd4_encode_lock_denied(resp
, &lockt
->lt_denied
);
2115 nfsd4_encode_locku(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_locku
*locku
)
2117 ENCODE_SEQID_OP_HEAD
;
2120 nfsd4_encode_stateid(resp
, &locku
->lu_stateid
);
2122 ENCODE_SEQID_OP_TAIL(locku
->lu_stateowner
);
2128 nfsd4_encode_link(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_link
*link
)
2134 WRITECINFO(link
->li_cinfo
);
2142 nfsd4_encode_open(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open
*open
)
2145 ENCODE_SEQID_OP_HEAD
;
2150 nfsd4_encode_stateid(resp
, &open
->op_stateid
);
2152 WRITECINFO(open
->op_cinfo
);
2153 WRITE32(open
->op_rflags
);
2155 WRITE32(open
->op_bmval
[0]);
2156 WRITE32(open
->op_bmval
[1]);
2157 WRITE32(open
->op_delegate_type
);
2160 switch (open
->op_delegate_type
) {
2161 case NFS4_OPEN_DELEGATE_NONE
:
2163 case NFS4_OPEN_DELEGATE_READ
:
2164 nfsd4_encode_stateid(resp
, &open
->op_delegate_stateid
);
2166 WRITE32(open
->op_recall
);
2169 * TODO: ACE's in delegations
2171 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
2174 WRITE32(0); /* XXX: is NULL principal ok? */
2177 case NFS4_OPEN_DELEGATE_WRITE
:
2178 nfsd4_encode_stateid(resp
, &open
->op_delegate_stateid
);
2183 * TODO: space_limit's in delegations
2185 WRITE32(NFS4_LIMIT_SIZE
);
2190 * TODO: ACE's in delegations
2192 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
2195 WRITE32(0); /* XXX: is NULL principal ok? */
2201 /* XXX save filehandle here */
2203 ENCODE_SEQID_OP_TAIL(open
->op_stateowner
);
2208 nfsd4_encode_open_confirm(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_confirm
*oc
)
2210 ENCODE_SEQID_OP_HEAD
;
2213 nfsd4_encode_stateid(resp
, &oc
->oc_resp_stateid
);
2215 ENCODE_SEQID_OP_TAIL(oc
->oc_stateowner
);
2220 nfsd4_encode_open_downgrade(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_downgrade
*od
)
2222 ENCODE_SEQID_OP_HEAD
;
2225 nfsd4_encode_stateid(resp
, &od
->od_stateid
);
2227 ENCODE_SEQID_OP_TAIL(od
->od_stateowner
);
2232 nfsd4_encode_read(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
2233 struct nfsd4_read
*read
)
2237 unsigned long maxcount
;
2243 if (resp
->xbuf
->page_len
)
2244 return nfserr_resource
;
2246 RESERVE_SPACE(8); /* eof flag and byte count */
2248 maxcount
= svc_max_payload(resp
->rqstp
);
2249 if (maxcount
> read
->rd_length
)
2250 maxcount
= read
->rd_length
;
2255 pn
= resp
->rqstp
->rq_resused
++;
2256 resp
->rqstp
->rq_vec
[v
].iov_base
=
2257 page_address(resp
->rqstp
->rq_respages
[pn
]);
2258 resp
->rqstp
->rq_vec
[v
].iov_len
=
2259 len
< PAGE_SIZE
? len
: PAGE_SIZE
;
2265 nfserr
= nfsd_read(read
->rd_rqstp
, read
->rd_fhp
, read
->rd_filp
,
2266 read
->rd_offset
, resp
->rqstp
->rq_vec
, read
->rd_vlen
,
2269 if (nfserr
== nfserr_symlink
)
2270 nfserr
= nfserr_inval
;
2273 eof
= (read
->rd_offset
+ maxcount
>=
2274 read
->rd_fhp
->fh_dentry
->d_inode
->i_size
);
2279 resp
->xbuf
->head
[0].iov_len
= (char*)p
2280 - (char*)resp
->xbuf
->head
[0].iov_base
;
2281 resp
->xbuf
->page_len
= maxcount
;
2283 /* Use rest of head for padding and remaining ops: */
2284 resp
->xbuf
->tail
[0].iov_base
= p
;
2285 resp
->xbuf
->tail
[0].iov_len
= 0;
2289 resp
->xbuf
->tail
[0].iov_base
+= maxcount
&3;
2290 resp
->xbuf
->tail
[0].iov_len
= 4 - (maxcount
&3);
2297 nfsd4_encode_readlink(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readlink
*readlink
)
2305 if (resp
->xbuf
->page_len
)
2306 return nfserr_resource
;
2308 page
= page_address(resp
->rqstp
->rq_respages
[resp
->rqstp
->rq_resused
++]);
2310 maxcount
= PAGE_SIZE
;
2314 * XXX: By default, the ->readlink() VFS op will truncate symlinks
2315 * if they would overflow the buffer. Is this kosher in NFSv4? If
2316 * not, one easy fix is: if ->readlink() precisely fills the buffer,
2317 * assume that truncation occurred, and return NFS4ERR_RESOURCE.
2319 nfserr
= nfsd_readlink(readlink
->rl_rqstp
, readlink
->rl_fhp
, page
, &maxcount
);
2320 if (nfserr
== nfserr_isdir
)
2321 return nfserr_inval
;
2327 resp
->xbuf
->head
[0].iov_len
= (char*)p
2328 - (char*)resp
->xbuf
->head
[0].iov_base
;
2329 resp
->xbuf
->page_len
= maxcount
;
2331 /* Use rest of head for padding and remaining ops: */
2332 resp
->xbuf
->tail
[0].iov_base
= p
;
2333 resp
->xbuf
->tail
[0].iov_len
= 0;
2337 resp
->xbuf
->tail
[0].iov_base
+= maxcount
&3;
2338 resp
->xbuf
->tail
[0].iov_len
= 4 - (maxcount
&3);
2345 nfsd4_encode_readdir(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readdir
*readdir
)
2349 __be32
*page
, *savep
, *tailbase
;
2354 if (resp
->xbuf
->page_len
)
2355 return nfserr_resource
;
2357 RESERVE_SPACE(8); /* verifier */
2360 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
2364 resp
->xbuf
->head
[0].iov_len
= ((char*)resp
->p
) - (char*)resp
->xbuf
->head
[0].iov_base
;
2367 maxcount
= PAGE_SIZE
;
2368 if (maxcount
> readdir
->rd_maxcount
)
2369 maxcount
= readdir
->rd_maxcount
;
2372 * Convert from bytes to words, account for the two words already
2373 * written, make sure to leave two words at the end for the next
2374 * pointer and eof field.
2376 maxcount
= (maxcount
>> 2) - 4;
2378 nfserr
= nfserr_toosmall
;
2382 page
= page_address(resp
->rqstp
->rq_respages
[resp
->rqstp
->rq_resused
++]);
2383 readdir
->common
.err
= 0;
2384 readdir
->buflen
= maxcount
;
2385 readdir
->buffer
= page
;
2386 readdir
->offset
= NULL
;
2388 offset
= readdir
->rd_cookie
;
2389 nfserr
= nfsd_readdir(readdir
->rd_rqstp
, readdir
->rd_fhp
,
2391 &readdir
->common
, nfsd4_encode_dirent
);
2392 if (nfserr
== nfs_ok
&&
2393 readdir
->common
.err
== nfserr_toosmall
&&
2394 readdir
->buffer
== page
)
2395 nfserr
= nfserr_toosmall
;
2396 if (nfserr
== nfserr_symlink
)
2397 nfserr
= nfserr_notdir
;
2401 if (readdir
->offset
)
2402 xdr_encode_hyper(readdir
->offset
, offset
);
2404 p
= readdir
->buffer
;
2405 *p
++ = 0; /* no more entries */
2406 *p
++ = htonl(readdir
->common
.err
== nfserr_eof
);
2407 resp
->xbuf
->page_len
= ((char*)p
) - (char*)page_address(
2408 resp
->rqstp
->rq_respages
[resp
->rqstp
->rq_resused
-1]);
2410 /* Use rest of head for padding and remaining ops: */
2411 resp
->xbuf
->tail
[0].iov_base
= tailbase
;
2412 resp
->xbuf
->tail
[0].iov_len
= 0;
2413 resp
->p
= resp
->xbuf
->tail
[0].iov_base
;
2414 resp
->end
= resp
->p
+ (PAGE_SIZE
- resp
->xbuf
->head
[0].iov_len
)/4;
2424 nfsd4_encode_remove(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_remove
*remove
)
2430 WRITECINFO(remove
->rm_cinfo
);
2437 nfsd4_encode_rename(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_rename
*rename
)
2443 WRITECINFO(rename
->rn_sinfo
);
2444 WRITECINFO(rename
->rn_tinfo
);
2451 nfsd4_encode_secinfo(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
2452 struct nfsd4_secinfo
*secinfo
)
2455 struct svc_export
*exp
= secinfo
->si_exp
;
2457 struct exp_flavor_info
*flavs
;
2458 struct exp_flavor_info def_flavs
[2];
2463 if (exp
->ex_nflavors
) {
2464 flavs
= exp
->ex_flavors
;
2465 nflavs
= exp
->ex_nflavors
;
2466 } else { /* Handling of some defaults in absence of real secinfo: */
2468 if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_UNIX
) {
2470 flavs
[0].pseudoflavor
= RPC_AUTH_UNIX
;
2471 flavs
[1].pseudoflavor
= RPC_AUTH_NULL
;
2472 } else if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_GSS
) {
2474 flavs
[0].pseudoflavor
2475 = svcauth_gss_flavor(exp
->ex_client
);
2478 flavs
[0].pseudoflavor
2479 = exp
->ex_client
->flavour
->flavour
;
2486 for (i
= 0; i
< nflavs
; i
++) {
2487 u32 flav
= flavs
[i
].pseudoflavor
;
2488 struct gss_api_mech
*gm
= gss_mech_get_by_pseudoflavor(flav
);
2492 WRITE32(RPC_AUTH_GSS
);
2494 RESERVE_SPACE(4 + gm
->gm_oid
.len
);
2495 WRITE32(gm
->gm_oid
.len
);
2496 WRITEMEM(gm
->gm_oid
.data
, gm
->gm_oid
.len
);
2499 WRITE32(0); /* qop */
2502 WRITE32(gss_pseudoflavor_to_service(gm
, flav
));
2518 * The SETATTR encode routine is special -- it always encodes a bitmap,
2519 * regardless of the error status.
2522 nfsd4_encode_setattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setattr
*setattr
)
2534 WRITE32(setattr
->sa_bmval
[0]);
2535 WRITE32(setattr
->sa_bmval
[1]);
2542 nfsd4_encode_setclientid(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setclientid
*scd
)
2547 RESERVE_SPACE(8 + sizeof(nfs4_verifier
));
2548 WRITEMEM(&scd
->se_clientid
, 8);
2549 WRITEMEM(&scd
->se_confirm
, sizeof(nfs4_verifier
));
2552 else if (nfserr
== nfserr_clid_inuse
) {
2562 nfsd4_encode_write(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_write
*write
)
2568 WRITE32(write
->wr_bytes_written
);
2569 WRITE32(write
->wr_how_written
);
2570 WRITEMEM(write
->wr_verifier
.data
, 8);
2577 nfsd4_encode_noop(struct nfsd4_compoundres
*resp
, __be32 nfserr
, void *p
)
2582 typedef __be32(* nfsd4_enc
)(struct nfsd4_compoundres
*, __be32
, void *);
2584 static nfsd4_enc nfsd4_enc_ops
[] = {
2585 [OP_ACCESS
] = (nfsd4_enc
)nfsd4_encode_access
,
2586 [OP_CLOSE
] = (nfsd4_enc
)nfsd4_encode_close
,
2587 [OP_COMMIT
] = (nfsd4_enc
)nfsd4_encode_commit
,
2588 [OP_CREATE
] = (nfsd4_enc
)nfsd4_encode_create
,
2589 [OP_DELEGPURGE
] = (nfsd4_enc
)nfsd4_encode_noop
,
2590 [OP_DELEGRETURN
] = (nfsd4_enc
)nfsd4_encode_noop
,
2591 [OP_GETATTR
] = (nfsd4_enc
)nfsd4_encode_getattr
,
2592 [OP_GETFH
] = (nfsd4_enc
)nfsd4_encode_getfh
,
2593 [OP_LINK
] = (nfsd4_enc
)nfsd4_encode_link
,
2594 [OP_LOCK
] = (nfsd4_enc
)nfsd4_encode_lock
,
2595 [OP_LOCKT
] = (nfsd4_enc
)nfsd4_encode_lockt
,
2596 [OP_LOCKU
] = (nfsd4_enc
)nfsd4_encode_locku
,
2597 [OP_LOOKUP
] = (nfsd4_enc
)nfsd4_encode_noop
,
2598 [OP_LOOKUPP
] = (nfsd4_enc
)nfsd4_encode_noop
,
2599 [OP_NVERIFY
] = (nfsd4_enc
)nfsd4_encode_noop
,
2600 [OP_OPEN
] = (nfsd4_enc
)nfsd4_encode_open
,
2601 [OP_OPEN_CONFIRM
] = (nfsd4_enc
)nfsd4_encode_open_confirm
,
2602 [OP_OPEN_DOWNGRADE
] = (nfsd4_enc
)nfsd4_encode_open_downgrade
,
2603 [OP_PUTFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
2604 [OP_PUTPUBFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
2605 [OP_PUTROOTFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
2606 [OP_READ
] = (nfsd4_enc
)nfsd4_encode_read
,
2607 [OP_READDIR
] = (nfsd4_enc
)nfsd4_encode_readdir
,
2608 [OP_READLINK
] = (nfsd4_enc
)nfsd4_encode_readlink
,
2609 [OP_REMOVE
] = (nfsd4_enc
)nfsd4_encode_remove
,
2610 [OP_RENAME
] = (nfsd4_enc
)nfsd4_encode_rename
,
2611 [OP_RENEW
] = (nfsd4_enc
)nfsd4_encode_noop
,
2612 [OP_RESTOREFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
2613 [OP_SAVEFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
2614 [OP_SECINFO
] = (nfsd4_enc
)nfsd4_encode_secinfo
,
2615 [OP_SETATTR
] = (nfsd4_enc
)nfsd4_encode_setattr
,
2616 [OP_SETCLIENTID
] = (nfsd4_enc
)nfsd4_encode_setclientid
,
2617 [OP_SETCLIENTID_CONFIRM
] = (nfsd4_enc
)nfsd4_encode_noop
,
2618 [OP_VERIFY
] = (nfsd4_enc
)nfsd4_encode_noop
,
2619 [OP_WRITE
] = (nfsd4_enc
)nfsd4_encode_write
,
2620 [OP_RELEASE_LOCKOWNER
] = (nfsd4_enc
)nfsd4_encode_noop
,
2624 nfsd4_encode_operation(struct nfsd4_compoundres
*resp
, struct nfsd4_op
*op
)
2631 statp
= p
++; /* to be backfilled at the end */
2634 if (op
->opnum
== OP_ILLEGAL
)
2636 BUG_ON(op
->opnum
< 0 || op
->opnum
>= ARRAY_SIZE(nfsd4_enc_ops
) ||
2637 !nfsd4_enc_ops
[op
->opnum
]);
2638 op
->status
= nfsd4_enc_ops
[op
->opnum
](resp
, op
->status
, &op
->u
);
2641 * Note: We write the status directly, instead of using WRITE32(),
2642 * since it is already in network byte order.
2644 *statp
= op
->status
;
2648 * Encode the reply stored in the stateowner reply cache
2650 * XDR note: do not encode rp->rp_buflen: the buffer contains the
2651 * previously sent already encoded operation.
2653 * called with nfs4_lock_state() held
2656 nfsd4_encode_replay(struct nfsd4_compoundres
*resp
, struct nfsd4_op
*op
)
2659 struct nfs4_replay
*rp
= op
->replay
;
2665 *p
++ = rp
->rp_status
; /* already xdr'ed */
2668 RESERVE_SPACE(rp
->rp_buflen
);
2669 WRITEMEM(rp
->rp_buf
, rp
->rp_buflen
);
2674 * END OF "GENERIC" ENCODE ROUTINES.
2678 nfs4svc_encode_voidres(struct svc_rqst
*rqstp
, __be32
*p
, void *dummy
)
2680 return xdr_ressize_check(rqstp
, p
);
2683 void nfsd4_release_compoundargs(struct nfsd4_compoundargs
*args
)
2685 if (args
->ops
!= args
->iops
) {
2687 args
->ops
= args
->iops
;
2691 while (args
->to_free
) {
2692 struct tmpbuf
*tb
= args
->to_free
;
2693 args
->to_free
= tb
->next
;
2694 tb
->release(tb
->buf
);
2700 nfs4svc_decode_compoundargs(struct svc_rqst
*rqstp
, __be32
*p
, struct nfsd4_compoundargs
*args
)
2705 args
->end
= rqstp
->rq_arg
.head
[0].iov_base
+ rqstp
->rq_arg
.head
[0].iov_len
;
2706 args
->pagelist
= rqstp
->rq_arg
.pages
;
2707 args
->pagelen
= rqstp
->rq_arg
.page_len
;
2709 args
->to_free
= NULL
;
2710 args
->ops
= args
->iops
;
2711 args
->rqstp
= rqstp
;
2713 status
= nfsd4_decode_compound(args
);
2715 nfsd4_release_compoundargs(args
);
2721 nfs4svc_encode_compoundres(struct svc_rqst
*rqstp
, __be32
*p
, struct nfsd4_compoundres
*resp
)
2724 * All that remains is to write the tag and operation count...
2728 *p
++ = htonl(resp
->taglen
);
2729 memcpy(p
, resp
->tag
, resp
->taglen
);
2730 p
+= XDR_QUADLEN(resp
->taglen
);
2731 *p
++ = htonl(resp
->opcnt
);
2733 if (rqstp
->rq_res
.page_len
)
2734 iov
= &rqstp
->rq_res
.tail
[0];
2736 iov
= &rqstp
->rq_res
.head
[0];
2737 iov
->iov_len
= ((char*)resp
->p
) - (char*)iov
->iov_base
;
2738 BUG_ON(iov
->iov_len
> PAGE_SIZE
);