2 * Server-side XDR for NFSv4
4 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * Kendrick Smith <kmsmith@umich.edu>
8 * Andy Adamson <andros@umich.edu>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * TODO: Neil Brown made the following observation: We currently
36 * initially reserve NFSD_BUFSIZE space on the transmit queue and
37 * never release any of that until the request is complete.
38 * It would be good to calculate a new maximum response size while
39 * decoding the COMPOUND, and call svc_reserve with this number
40 * at the end of nfs4svc_decode_compoundargs.
43 #include <linux/slab.h>
44 #include <linux/namei.h>
45 #include <linux/statfs.h>
46 #include <linux/utsname.h>
47 #include <linux/pagemap.h>
48 #include <linux/sunrpc/svcauth_gss.h>
58 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
59 #include <linux/security.h>
63 #define NFSDDBG_FACILITY NFSDDBG_XDR
66 * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
67 * directory in order to indicate to the client that a filesystem boundary is present
68 * We use a fixed fsid for a referral
70 #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
71 #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
74 check_filename(char *str
, int len
)
80 if (isdotent(str
, len
))
81 return nfserr_badname
;
82 for (i
= 0; i
< len
; i
++)
84 return nfserr_badname
;
96 dprintk("NFSD: xdr error (%s:%d)\n", \
97 __FILE__, __LINE__); \
98 status = nfserr_bad_xdr; \
101 #define READ32(x) (x) = ntohl(*p++)
102 #define READ64(x) do { \
103 (x) = (u64)ntohl(*p++) << 32; \
104 (x) |= ntohl(*p++); \
106 #define READTIME(x) do { \
111 #define READMEM(x,nbytes) do { \
113 p += XDR_QUADLEN(nbytes); \
115 #define SAVEMEM(x,nbytes) do { \
116 if (!(x = (p==argp->tmp || p == argp->tmpp) ? \
117 savemem(argp, p, nbytes) : \
119 dprintk("NFSD: xdr error (%s:%d)\n", \
120 __FILE__, __LINE__); \
123 p += XDR_QUADLEN(nbytes); \
125 #define COPYMEM(x,nbytes) do { \
126 memcpy((x), p, nbytes); \
127 p += XDR_QUADLEN(nbytes); \
130 /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */
131 #define READ_BUF(nbytes) do { \
132 if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \
134 argp->p += XDR_QUADLEN(nbytes); \
135 } else if (!(p = read_buf(argp, nbytes))) { \
136 dprintk("NFSD: xdr error (%s:%d)\n", \
137 __FILE__, __LINE__); \
142 static void next_decode_page(struct nfsd4_compoundargs
*argp
)
144 argp
->p
= page_address(argp
->pagelist
[0]);
146 if (argp
->pagelen
< PAGE_SIZE
) {
147 argp
->end
= argp
->p
+ (argp
->pagelen
>>2);
150 argp
->end
= argp
->p
+ (PAGE_SIZE
>>2);
151 argp
->pagelen
-= PAGE_SIZE
;
155 static __be32
*read_buf(struct nfsd4_compoundargs
*argp
, u32 nbytes
)
157 /* We want more bytes than seem to be available.
158 * Maybe we need a new page, maybe we have just run out
160 unsigned int avail
= (char *)argp
->end
- (char *)argp
->p
;
162 if (avail
+ argp
->pagelen
< nbytes
)
164 if (avail
+ PAGE_SIZE
< nbytes
) /* need more than a page !! */
166 /* ok, we can do it with the current plus the next page */
167 if (nbytes
<= sizeof(argp
->tmp
))
171 p
= argp
->tmpp
= kmalloc(nbytes
, GFP_KERNEL
);
177 * The following memcpy is safe because read_buf is always
178 * called with nbytes > avail, and the two cases above both
179 * guarantee p points to at least nbytes bytes.
181 memcpy(p
, argp
->p
, avail
);
182 next_decode_page(argp
);
183 memcpy(((char*)p
)+avail
, argp
->p
, (nbytes
- avail
));
184 argp
->p
+= XDR_QUADLEN(nbytes
- avail
);
188 static int zero_clientid(clientid_t
*clid
)
190 return (clid
->cl_boot
== 0) && (clid
->cl_id
== 0);
194 * defer_free - mark an allocation as deferred freed
195 * @argp: NFSv4 compound argument structure to be freed with
196 * @release: release callback to free @p, typically kfree()
197 * @p: pointer to be freed
199 * Marks @p to be freed when processing the compound operation
200 * described in @argp finishes.
203 defer_free(struct nfsd4_compoundargs
*argp
,
204 void (*release
)(const void *), void *p
)
208 tb
= kmalloc(sizeof(*tb
), GFP_KERNEL
);
212 tb
->release
= release
;
213 tb
->next
= argp
->to_free
;
219 * savemem - duplicate a chunk of memory for later processing
220 * @argp: NFSv4 compound argument structure to be freed with
221 * @p: pointer to be duplicated
222 * @nbytes: length to be duplicated
224 * Returns a pointer to a copy of @nbytes bytes of memory at @p
225 * that are preserved until processing of the NFSv4 compound
226 * operation described by @argp finishes.
228 static char *savemem(struct nfsd4_compoundargs
*argp
, __be32
*p
, int nbytes
)
230 if (p
== argp
->tmp
) {
231 p
= kmemdup(argp
->tmp
, nbytes
, GFP_KERNEL
);
235 BUG_ON(p
!= argp
->tmpp
);
238 if (defer_free(argp
, kfree
, p
)) {
246 nfsd4_decode_bitmap(struct nfsd4_compoundargs
*argp
, u32
*bmval
)
260 READ_BUF(bmlen
<< 2);
272 nfsd4_decode_fattr(struct nfsd4_compoundargs
*argp
, u32
*bmval
,
273 struct iattr
*iattr
, struct nfs4_acl
**acl
,
274 struct xdr_netobj
*label
)
276 int expected_len
, len
= 0;
282 if ((status
= nfsd4_decode_bitmap(argp
, bmval
)))
286 READ32(expected_len
);
288 if (bmval
[0] & FATTR4_WORD0_SIZE
) {
291 READ64(iattr
->ia_size
);
292 iattr
->ia_valid
|= ATTR_SIZE
;
294 if (bmval
[0] & FATTR4_WORD0_ACL
) {
296 struct nfs4_ace
*ace
;
298 READ_BUF(4); len
+= 4;
301 if (nace
> NFS4_ACL_MAX
)
302 return nfserr_resource
;
304 *acl
= nfs4_acl_new(nace
);
306 return nfserr_jukebox
;
308 defer_free(argp
, kfree
, *acl
);
310 (*acl
)->naces
= nace
;
311 for (ace
= (*acl
)->aces
; ace
< (*acl
)->aces
+ nace
; ace
++) {
312 READ_BUF(16); len
+= 16;
315 READ32(ace
->access_mask
);
318 len
+= XDR_QUADLEN(dummy32
) << 2;
319 READMEM(buf
, dummy32
);
320 ace
->whotype
= nfs4_acl_get_whotype(buf
, dummy32
);
322 if (ace
->whotype
!= NFS4_ACL_WHO_NAMED
)
324 else if (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
)
325 status
= nfsd_map_name_to_gid(argp
->rqstp
,
326 buf
, dummy32
, &ace
->who_gid
);
328 status
= nfsd_map_name_to_uid(argp
->rqstp
,
329 buf
, dummy32
, &ace
->who_uid
);
335 if (bmval
[1] & FATTR4_WORD1_MODE
) {
338 READ32(iattr
->ia_mode
);
339 iattr
->ia_mode
&= (S_IFMT
| S_IALLUGO
);
340 iattr
->ia_valid
|= ATTR_MODE
;
342 if (bmval
[1] & FATTR4_WORD1_OWNER
) {
347 len
+= (XDR_QUADLEN(dummy32
) << 2);
348 READMEM(buf
, dummy32
);
349 if ((status
= nfsd_map_name_to_uid(argp
->rqstp
, buf
, dummy32
, &iattr
->ia_uid
)))
351 iattr
->ia_valid
|= ATTR_UID
;
353 if (bmval
[1] & FATTR4_WORD1_OWNER_GROUP
) {
358 len
+= (XDR_QUADLEN(dummy32
) << 2);
359 READMEM(buf
, dummy32
);
360 if ((status
= nfsd_map_name_to_gid(argp
->rqstp
, buf
, dummy32
, &iattr
->ia_gid
)))
362 iattr
->ia_valid
|= ATTR_GID
;
364 if (bmval
[1] & FATTR4_WORD1_TIME_ACCESS_SET
) {
369 case NFS4_SET_TO_CLIENT_TIME
:
370 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
371 all 32 bits of 'nseconds'. */
374 READ64(iattr
->ia_atime
.tv_sec
);
375 READ32(iattr
->ia_atime
.tv_nsec
);
376 if (iattr
->ia_atime
.tv_nsec
>= (u32
)1000000000)
378 iattr
->ia_valid
|= (ATTR_ATIME
| ATTR_ATIME_SET
);
380 case NFS4_SET_TO_SERVER_TIME
:
381 iattr
->ia_valid
|= ATTR_ATIME
;
387 if (bmval
[1] & FATTR4_WORD1_TIME_MODIFY_SET
) {
392 case NFS4_SET_TO_CLIENT_TIME
:
393 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
394 all 32 bits of 'nseconds'. */
397 READ64(iattr
->ia_mtime
.tv_sec
);
398 READ32(iattr
->ia_mtime
.tv_nsec
);
399 if (iattr
->ia_mtime
.tv_nsec
>= (u32
)1000000000)
401 iattr
->ia_valid
|= (ATTR_MTIME
| ATTR_MTIME_SET
);
403 case NFS4_SET_TO_SERVER_TIME
:
404 iattr
->ia_valid
|= ATTR_MTIME
;
412 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
413 if (bmval
[2] & FATTR4_WORD2_SECURITY_LABEL
) {
416 READ32(dummy32
); /* lfs: we don't use it */
419 READ32(dummy32
); /* pi: we don't use it either */
424 if (dummy32
> NFSD4_MAX_SEC_LABEL_LEN
)
425 return nfserr_badlabel
;
426 len
+= (XDR_QUADLEN(dummy32
) << 2);
427 READMEM(buf
, dummy32
);
428 label
->data
= kzalloc(dummy32
+ 1, GFP_KERNEL
);
430 return nfserr_jukebox
;
431 label
->len
= dummy32
;
432 defer_free(argp
, kfree
, label
->data
);
433 memcpy(label
->data
, buf
, dummy32
);
437 if (bmval
[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
438 || bmval
[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
439 || bmval
[2] & ~NFSD_WRITEABLE_ATTRS_WORD2
)
440 READ_BUF(expected_len
- len
);
441 else if (len
!= expected_len
)
448 nfsd4_decode_stateid(struct nfsd4_compoundargs
*argp
, stateid_t
*sid
)
452 READ_BUF(sizeof(stateid_t
));
453 READ32(sid
->si_generation
);
454 COPYMEM(&sid
->si_opaque
, sizeof(stateid_opaque_t
));
460 nfsd4_decode_access(struct nfsd4_compoundargs
*argp
, struct nfsd4_access
*access
)
465 READ32(access
->ac_req_access
);
470 static __be32
nfsd4_decode_cb_sec(struct nfsd4_compoundargs
*argp
, struct nfsd4_cb_sec
*cbs
)
478 /* callback_sec_params4 */
482 cbs
->flavor
= (u32
)(-1);
484 /* Is this legal? Be generous, take it to mean AUTH_NONE: */
486 for (i
= 0; i
< nr_secflavs
; ++i
) {
491 /* Nothing to read */
492 if (cbs
->flavor
== (u32
)(-1))
493 cbs
->flavor
= RPC_AUTH_NULL
;
503 SAVEMEM(machine_name
, dummy
);
514 if (cbs
->flavor
== (u32
)(-1)) {
515 kuid_t kuid
= make_kuid(&init_user_ns
, uid
);
516 kgid_t kgid
= make_kgid(&init_user_ns
, gid
);
517 if (uid_valid(kuid
) && gid_valid(kgid
)) {
520 cbs
->flavor
= RPC_AUTH_UNIX
;
522 dprintk("RPC_AUTH_UNIX with invalid"
523 "uid or gid ignoring!\n");
528 dprintk("RPC_AUTH_GSS callback secflavor "
533 /* gcbp_handle_from_server */
536 p
+= XDR_QUADLEN(dummy
);
537 /* gcbp_handle_from_client */
543 dprintk("Illegal callback secflavor\n");
550 static __be32
nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs
*argp
, struct nfsd4_backchannel_ctl
*bc
)
555 READ32(bc
->bc_cb_program
);
556 nfsd4_decode_cb_sec(argp
, &bc
->bc_cb_sec
);
561 static __be32
nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs
*argp
, struct nfsd4_bind_conn_to_session
*bcts
)
565 READ_BUF(NFS4_MAX_SESSIONID_LEN
+ 8);
566 COPYMEM(bcts
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
568 /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker
569 * could help us figure out we should be using it. */
574 nfsd4_decode_close(struct nfsd4_compoundargs
*argp
, struct nfsd4_close
*close
)
579 READ32(close
->cl_seqid
);
580 return nfsd4_decode_stateid(argp
, &close
->cl_stateid
);
587 nfsd4_decode_commit(struct nfsd4_compoundargs
*argp
, struct nfsd4_commit
*commit
)
592 READ64(commit
->co_offset
);
593 READ32(commit
->co_count
);
599 nfsd4_decode_create(struct nfsd4_compoundargs
*argp
, struct nfsd4_create
*create
)
604 READ32(create
->cr_type
);
605 switch (create
->cr_type
) {
608 READ32(create
->cr_linklen
);
609 READ_BUF(create
->cr_linklen
);
610 SAVEMEM(create
->cr_linkname
, create
->cr_linklen
);
615 READ32(create
->cr_specdata1
);
616 READ32(create
->cr_specdata2
);
626 READ32(create
->cr_namelen
);
627 READ_BUF(create
->cr_namelen
);
628 SAVEMEM(create
->cr_name
, create
->cr_namelen
);
629 if ((status
= check_filename(create
->cr_name
, create
->cr_namelen
)))
632 status
= nfsd4_decode_fattr(argp
, create
->cr_bmval
, &create
->cr_iattr
,
633 &create
->cr_acl
, &create
->cr_label
);
641 nfsd4_decode_delegreturn(struct nfsd4_compoundargs
*argp
, struct nfsd4_delegreturn
*dr
)
643 return nfsd4_decode_stateid(argp
, &dr
->dr_stateid
);
647 nfsd4_decode_getattr(struct nfsd4_compoundargs
*argp
, struct nfsd4_getattr
*getattr
)
649 return nfsd4_decode_bitmap(argp
, getattr
->ga_bmval
);
653 nfsd4_decode_link(struct nfsd4_compoundargs
*argp
, struct nfsd4_link
*link
)
658 READ32(link
->li_namelen
);
659 READ_BUF(link
->li_namelen
);
660 SAVEMEM(link
->li_name
, link
->li_namelen
);
661 if ((status
= check_filename(link
->li_name
, link
->li_namelen
)))
668 nfsd4_decode_lock(struct nfsd4_compoundargs
*argp
, struct nfsd4_lock
*lock
)
673 * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
676 READ32(lock
->lk_type
);
677 if ((lock
->lk_type
< NFS4_READ_LT
) || (lock
->lk_type
> NFS4_WRITEW_LT
))
679 READ32(lock
->lk_reclaim
);
680 READ64(lock
->lk_offset
);
681 READ64(lock
->lk_length
);
682 READ32(lock
->lk_is_new
);
684 if (lock
->lk_is_new
) {
686 READ32(lock
->lk_new_open_seqid
);
687 status
= nfsd4_decode_stateid(argp
, &lock
->lk_new_open_stateid
);
690 READ_BUF(8 + sizeof(clientid_t
));
691 READ32(lock
->lk_new_lock_seqid
);
692 COPYMEM(&lock
->lk_new_clientid
, sizeof(clientid_t
));
693 READ32(lock
->lk_new_owner
.len
);
694 READ_BUF(lock
->lk_new_owner
.len
);
695 READMEM(lock
->lk_new_owner
.data
, lock
->lk_new_owner
.len
);
697 status
= nfsd4_decode_stateid(argp
, &lock
->lk_old_lock_stateid
);
701 READ32(lock
->lk_old_lock_seqid
);
708 nfsd4_decode_lockt(struct nfsd4_compoundargs
*argp
, struct nfsd4_lockt
*lockt
)
713 READ32(lockt
->lt_type
);
714 if((lockt
->lt_type
< NFS4_READ_LT
) || (lockt
->lt_type
> NFS4_WRITEW_LT
))
716 READ64(lockt
->lt_offset
);
717 READ64(lockt
->lt_length
);
718 COPYMEM(&lockt
->lt_clientid
, 8);
719 READ32(lockt
->lt_owner
.len
);
720 READ_BUF(lockt
->lt_owner
.len
);
721 READMEM(lockt
->lt_owner
.data
, lockt
->lt_owner
.len
);
727 nfsd4_decode_locku(struct nfsd4_compoundargs
*argp
, struct nfsd4_locku
*locku
)
732 READ32(locku
->lu_type
);
733 if ((locku
->lu_type
< NFS4_READ_LT
) || (locku
->lu_type
> NFS4_WRITEW_LT
))
735 READ32(locku
->lu_seqid
);
736 status
= nfsd4_decode_stateid(argp
, &locku
->lu_stateid
);
740 READ64(locku
->lu_offset
);
741 READ64(locku
->lu_length
);
747 nfsd4_decode_lookup(struct nfsd4_compoundargs
*argp
, struct nfsd4_lookup
*lookup
)
752 READ32(lookup
->lo_len
);
753 READ_BUF(lookup
->lo_len
);
754 SAVEMEM(lookup
->lo_name
, lookup
->lo_len
);
755 if ((status
= check_filename(lookup
->lo_name
, lookup
->lo_len
)))
761 static __be32
nfsd4_decode_share_access(struct nfsd4_compoundargs
*argp
, u32
*share_access
, u32
*deleg_want
, u32
*deleg_when
)
768 *share_access
= w
& NFS4_SHARE_ACCESS_MASK
;
769 *deleg_want
= w
& NFS4_SHARE_WANT_MASK
;
771 *deleg_when
= w
& NFS4_SHARE_WHEN_MASK
;
773 switch (w
& NFS4_SHARE_ACCESS_MASK
) {
774 case NFS4_SHARE_ACCESS_READ
:
775 case NFS4_SHARE_ACCESS_WRITE
:
776 case NFS4_SHARE_ACCESS_BOTH
:
779 return nfserr_bad_xdr
;
781 w
&= ~NFS4_SHARE_ACCESS_MASK
;
784 if (!argp
->minorversion
)
785 return nfserr_bad_xdr
;
786 switch (w
& NFS4_SHARE_WANT_MASK
) {
787 case NFS4_SHARE_WANT_NO_PREFERENCE
:
788 case NFS4_SHARE_WANT_READ_DELEG
:
789 case NFS4_SHARE_WANT_WRITE_DELEG
:
790 case NFS4_SHARE_WANT_ANY_DELEG
:
791 case NFS4_SHARE_WANT_NO_DELEG
:
792 case NFS4_SHARE_WANT_CANCEL
:
795 return nfserr_bad_xdr
;
797 w
&= ~NFS4_SHARE_WANT_MASK
;
801 if (!deleg_when
) /* open_downgrade */
804 case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL
:
805 case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED
:
806 case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL
|
807 NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED
):
811 return nfserr_bad_xdr
;
814 static __be32
nfsd4_decode_share_deny(struct nfsd4_compoundargs
*argp
, u32
*x
)
820 /* Note: unlinke access bits, deny bits may be zero. */
821 if (*x
& ~NFS4_SHARE_DENY_BOTH
)
822 return nfserr_bad_xdr
;
825 return nfserr_bad_xdr
;
828 static __be32
nfsd4_decode_opaque(struct nfsd4_compoundargs
*argp
, struct xdr_netobj
*o
)
835 if (o
->len
== 0 || o
->len
> NFS4_OPAQUE_LIMIT
)
836 return nfserr_bad_xdr
;
839 SAVEMEM(o
->data
, o
->len
);
842 return nfserr_bad_xdr
;
846 nfsd4_decode_open(struct nfsd4_compoundargs
*argp
, struct nfsd4_open
*open
)
851 memset(open
->op_bmval
, 0, sizeof(open
->op_bmval
));
852 open
->op_iattr
.ia_valid
= 0;
853 open
->op_openowner
= NULL
;
855 open
->op_xdr_error
= 0;
856 /* seqid, share_access, share_deny, clientid, ownerlen */
858 READ32(open
->op_seqid
);
859 /* decode, yet ignore deleg_when until supported */
860 status
= nfsd4_decode_share_access(argp
, &open
->op_share_access
,
861 &open
->op_deleg_want
, &dummy
);
864 status
= nfsd4_decode_share_deny(argp
, &open
->op_share_deny
);
867 READ_BUF(sizeof(clientid_t
));
868 COPYMEM(&open
->op_clientid
, sizeof(clientid_t
));
869 status
= nfsd4_decode_opaque(argp
, &open
->op_owner
);
873 READ32(open
->op_create
);
874 switch (open
->op_create
) {
875 case NFS4_OPEN_NOCREATE
:
877 case NFS4_OPEN_CREATE
:
879 READ32(open
->op_createmode
);
880 switch (open
->op_createmode
) {
881 case NFS4_CREATE_UNCHECKED
:
882 case NFS4_CREATE_GUARDED
:
883 status
= nfsd4_decode_fattr(argp
, open
->op_bmval
,
884 &open
->op_iattr
, &open
->op_acl
, &open
->op_label
);
888 case NFS4_CREATE_EXCLUSIVE
:
889 READ_BUF(NFS4_VERIFIER_SIZE
);
890 COPYMEM(open
->op_verf
.data
, NFS4_VERIFIER_SIZE
);
892 case NFS4_CREATE_EXCLUSIVE4_1
:
893 if (argp
->minorversion
< 1)
895 READ_BUF(NFS4_VERIFIER_SIZE
);
896 COPYMEM(open
->op_verf
.data
, NFS4_VERIFIER_SIZE
);
897 status
= nfsd4_decode_fattr(argp
, open
->op_bmval
,
898 &open
->op_iattr
, &open
->op_acl
, &open
->op_label
);
912 READ32(open
->op_claim_type
);
913 switch (open
->op_claim_type
) {
914 case NFS4_OPEN_CLAIM_NULL
:
915 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
917 READ32(open
->op_fname
.len
);
918 READ_BUF(open
->op_fname
.len
);
919 SAVEMEM(open
->op_fname
.data
, open
->op_fname
.len
);
920 if ((status
= check_filename(open
->op_fname
.data
, open
->op_fname
.len
)))
923 case NFS4_OPEN_CLAIM_PREVIOUS
:
925 READ32(open
->op_delegate_type
);
927 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
928 status
= nfsd4_decode_stateid(argp
, &open
->op_delegate_stateid
);
932 READ32(open
->op_fname
.len
);
933 READ_BUF(open
->op_fname
.len
);
934 SAVEMEM(open
->op_fname
.data
, open
->op_fname
.len
);
935 if ((status
= check_filename(open
->op_fname
.data
, open
->op_fname
.len
)))
938 case NFS4_OPEN_CLAIM_FH
:
939 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
940 if (argp
->minorversion
< 1)
944 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
945 if (argp
->minorversion
< 1)
947 status
= nfsd4_decode_stateid(argp
, &open
->op_delegate_stateid
);
959 nfsd4_decode_open_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_confirm
*open_conf
)
963 if (argp
->minorversion
>= 1)
964 return nfserr_notsupp
;
966 status
= nfsd4_decode_stateid(argp
, &open_conf
->oc_req_stateid
);
970 READ32(open_conf
->oc_seqid
);
976 nfsd4_decode_open_downgrade(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_downgrade
*open_down
)
980 status
= nfsd4_decode_stateid(argp
, &open_down
->od_stateid
);
984 READ32(open_down
->od_seqid
);
985 status
= nfsd4_decode_share_access(argp
, &open_down
->od_share_access
,
986 &open_down
->od_deleg_want
, NULL
);
989 status
= nfsd4_decode_share_deny(argp
, &open_down
->od_share_deny
);
996 nfsd4_decode_putfh(struct nfsd4_compoundargs
*argp
, struct nfsd4_putfh
*putfh
)
1001 READ32(putfh
->pf_fhlen
);
1002 if (putfh
->pf_fhlen
> NFS4_FHSIZE
)
1004 READ_BUF(putfh
->pf_fhlen
);
1005 SAVEMEM(putfh
->pf_fhval
, putfh
->pf_fhlen
);
1011 nfsd4_decode_putpubfh(struct nfsd4_compoundargs
*argp
, void *p
)
1013 if (argp
->minorversion
== 0)
1015 return nfserr_notsupp
;
1019 nfsd4_decode_read(struct nfsd4_compoundargs
*argp
, struct nfsd4_read
*read
)
1023 status
= nfsd4_decode_stateid(argp
, &read
->rd_stateid
);
1027 READ64(read
->rd_offset
);
1028 READ32(read
->rd_length
);
1034 nfsd4_decode_readdir(struct nfsd4_compoundargs
*argp
, struct nfsd4_readdir
*readdir
)
1039 READ64(readdir
->rd_cookie
);
1040 COPYMEM(readdir
->rd_verf
.data
, sizeof(readdir
->rd_verf
.data
));
1041 READ32(readdir
->rd_dircount
); /* just in case you needed a useless field... */
1042 READ32(readdir
->rd_maxcount
);
1043 if ((status
= nfsd4_decode_bitmap(argp
, readdir
->rd_bmval
)))
1050 nfsd4_decode_remove(struct nfsd4_compoundargs
*argp
, struct nfsd4_remove
*remove
)
1055 READ32(remove
->rm_namelen
);
1056 READ_BUF(remove
->rm_namelen
);
1057 SAVEMEM(remove
->rm_name
, remove
->rm_namelen
);
1058 if ((status
= check_filename(remove
->rm_name
, remove
->rm_namelen
)))
1065 nfsd4_decode_rename(struct nfsd4_compoundargs
*argp
, struct nfsd4_rename
*rename
)
1070 READ32(rename
->rn_snamelen
);
1071 READ_BUF(rename
->rn_snamelen
+ 4);
1072 SAVEMEM(rename
->rn_sname
, rename
->rn_snamelen
);
1073 READ32(rename
->rn_tnamelen
);
1074 READ_BUF(rename
->rn_tnamelen
);
1075 SAVEMEM(rename
->rn_tname
, rename
->rn_tnamelen
);
1076 if ((status
= check_filename(rename
->rn_sname
, rename
->rn_snamelen
)))
1078 if ((status
= check_filename(rename
->rn_tname
, rename
->rn_tnamelen
)))
1085 nfsd4_decode_renew(struct nfsd4_compoundargs
*argp
, clientid_t
*clientid
)
1089 if (argp
->minorversion
>= 1)
1090 return nfserr_notsupp
;
1092 READ_BUF(sizeof(clientid_t
));
1093 COPYMEM(clientid
, sizeof(clientid_t
));
1099 nfsd4_decode_secinfo(struct nfsd4_compoundargs
*argp
,
1100 struct nfsd4_secinfo
*secinfo
)
1105 READ32(secinfo
->si_namelen
);
1106 READ_BUF(secinfo
->si_namelen
);
1107 SAVEMEM(secinfo
->si_name
, secinfo
->si_namelen
);
1108 status
= check_filename(secinfo
->si_name
, secinfo
->si_namelen
);
1115 nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs
*argp
,
1116 struct nfsd4_secinfo_no_name
*sin
)
1121 READ32(sin
->sin_style
);
1126 nfsd4_decode_setattr(struct nfsd4_compoundargs
*argp
, struct nfsd4_setattr
*setattr
)
1130 status
= nfsd4_decode_stateid(argp
, &setattr
->sa_stateid
);
1133 return nfsd4_decode_fattr(argp
, setattr
->sa_bmval
, &setattr
->sa_iattr
,
1134 &setattr
->sa_acl
, &setattr
->sa_label
);
1138 nfsd4_decode_setclientid(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid
*setclientid
)
1142 if (argp
->minorversion
>= 1)
1143 return nfserr_notsupp
;
1145 READ_BUF(NFS4_VERIFIER_SIZE
);
1146 COPYMEM(setclientid
->se_verf
.data
, NFS4_VERIFIER_SIZE
);
1148 status
= nfsd4_decode_opaque(argp
, &setclientid
->se_name
);
1150 return nfserr_bad_xdr
;
1152 READ32(setclientid
->se_callback_prog
);
1153 READ32(setclientid
->se_callback_netid_len
);
1155 READ_BUF(setclientid
->se_callback_netid_len
+ 4);
1156 SAVEMEM(setclientid
->se_callback_netid_val
, setclientid
->se_callback_netid_len
);
1157 READ32(setclientid
->se_callback_addr_len
);
1159 READ_BUF(setclientid
->se_callback_addr_len
+ 4);
1160 SAVEMEM(setclientid
->se_callback_addr_val
, setclientid
->se_callback_addr_len
);
1161 READ32(setclientid
->se_callback_ident
);
1167 nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid_confirm
*scd_c
)
1171 if (argp
->minorversion
>= 1)
1172 return nfserr_notsupp
;
1174 READ_BUF(8 + NFS4_VERIFIER_SIZE
);
1175 COPYMEM(&scd_c
->sc_clientid
, 8);
1176 COPYMEM(&scd_c
->sc_confirm
, NFS4_VERIFIER_SIZE
);
1181 /* Also used for NVERIFY */
1183 nfsd4_decode_verify(struct nfsd4_compoundargs
*argp
, struct nfsd4_verify
*verify
)
1187 if ((status
= nfsd4_decode_bitmap(argp
, verify
->ve_bmval
)))
1190 /* For convenience's sake, we compare raw xdr'd attributes in
1191 * nfsd4_proc_verify */
1194 READ32(verify
->ve_attrlen
);
1195 READ_BUF(verify
->ve_attrlen
);
1196 SAVEMEM(verify
->ve_attrval
, verify
->ve_attrlen
);
1202 nfsd4_decode_write(struct nfsd4_compoundargs
*argp
, struct nfsd4_write
*write
)
1208 status
= nfsd4_decode_stateid(argp
, &write
->wr_stateid
);
1212 READ64(write
->wr_offset
);
1213 READ32(write
->wr_stable_how
);
1214 if (write
->wr_stable_how
> 2)
1216 READ32(write
->wr_buflen
);
1218 /* Sorry .. no magic macros for this.. *
1219 * READ_BUF(write->wr_buflen);
1220 * SAVEMEM(write->wr_buf, write->wr_buflen);
1222 avail
= (char*)argp
->end
- (char*)argp
->p
;
1223 if (avail
+ argp
->pagelen
< write
->wr_buflen
) {
1224 dprintk("NFSD: xdr error (%s:%d)\n",
1225 __FILE__
, __LINE__
);
1228 write
->wr_head
.iov_base
= p
;
1229 write
->wr_head
.iov_len
= avail
;
1230 WARN_ON(avail
!= (XDR_QUADLEN(avail
) << 2));
1231 write
->wr_pagelist
= argp
->pagelist
;
1233 len
= XDR_QUADLEN(write
->wr_buflen
) << 2;
1239 pages
= len
>> PAGE_SHIFT
;
1240 argp
->pagelist
+= pages
;
1241 argp
->pagelen
-= pages
* PAGE_SIZE
;
1242 len
-= pages
* PAGE_SIZE
;
1244 argp
->p
= (__be32
*)page_address(argp
->pagelist
[0]);
1246 argp
->end
= argp
->p
+ XDR_QUADLEN(PAGE_SIZE
);
1248 argp
->p
+= XDR_QUADLEN(len
);
1254 nfsd4_decode_release_lockowner(struct nfsd4_compoundargs
*argp
, struct nfsd4_release_lockowner
*rlockowner
)
1258 if (argp
->minorversion
>= 1)
1259 return nfserr_notsupp
;
1262 COPYMEM(&rlockowner
->rl_clientid
, sizeof(clientid_t
));
1263 READ32(rlockowner
->rl_owner
.len
);
1264 READ_BUF(rlockowner
->rl_owner
.len
);
1265 READMEM(rlockowner
->rl_owner
.data
, rlockowner
->rl_owner
.len
);
1267 if (argp
->minorversion
&& !zero_clientid(&rlockowner
->rl_clientid
))
1268 return nfserr_inval
;
1273 nfsd4_decode_exchange_id(struct nfsd4_compoundargs
*argp
,
1274 struct nfsd4_exchange_id
*exid
)
1279 READ_BUF(NFS4_VERIFIER_SIZE
);
1280 COPYMEM(exid
->verifier
.data
, NFS4_VERIFIER_SIZE
);
1282 status
= nfsd4_decode_opaque(argp
, &exid
->clname
);
1284 return nfserr_bad_xdr
;
1287 READ32(exid
->flags
);
1289 /* Ignore state_protect4_a */
1291 READ32(exid
->spa_how
);
1292 switch (exid
->spa_how
) {
1296 /* spo_must_enforce */
1299 READ_BUF(dummy
* 4);
1302 /* spo_must_allow */
1305 READ_BUF(dummy
* 4);
1312 READ_BUF(dummy
* 4);
1317 READ_BUF(dummy
* 4);
1320 /* ssp_hash_algs<> */
1327 p
+= XDR_QUADLEN(dummy
);
1330 /* ssp_encr_algs<> */
1337 p
+= XDR_QUADLEN(dummy
);
1340 /* ssp_window and ssp_num_gss_handles */
1349 /* Ignore Implementation ID */
1350 READ_BUF(4); /* nfs_impl_id4 array length */
1361 p
+= XDR_QUADLEN(dummy
);
1367 p
+= XDR_QUADLEN(dummy
);
1377 nfsd4_decode_create_session(struct nfsd4_compoundargs
*argp
,
1378 struct nfsd4_create_session
*sess
)
1384 COPYMEM(&sess
->clientid
, 8);
1385 READ32(sess
->seqid
);
1386 READ32(sess
->flags
);
1388 /* Fore channel attrs */
1390 READ32(dummy
); /* headerpadsz is always 0 */
1391 READ32(sess
->fore_channel
.maxreq_sz
);
1392 READ32(sess
->fore_channel
.maxresp_sz
);
1393 READ32(sess
->fore_channel
.maxresp_cached
);
1394 READ32(sess
->fore_channel
.maxops
);
1395 READ32(sess
->fore_channel
.maxreqs
);
1396 READ32(sess
->fore_channel
.nr_rdma_attrs
);
1397 if (sess
->fore_channel
.nr_rdma_attrs
== 1) {
1399 READ32(sess
->fore_channel
.rdma_attrs
);
1400 } else if (sess
->fore_channel
.nr_rdma_attrs
> 1) {
1401 dprintk("Too many fore channel attr bitmaps!\n");
1405 /* Back channel attrs */
1407 READ32(dummy
); /* headerpadsz is always 0 */
1408 READ32(sess
->back_channel
.maxreq_sz
);
1409 READ32(sess
->back_channel
.maxresp_sz
);
1410 READ32(sess
->back_channel
.maxresp_cached
);
1411 READ32(sess
->back_channel
.maxops
);
1412 READ32(sess
->back_channel
.maxreqs
);
1413 READ32(sess
->back_channel
.nr_rdma_attrs
);
1414 if (sess
->back_channel
.nr_rdma_attrs
== 1) {
1416 READ32(sess
->back_channel
.rdma_attrs
);
1417 } else if (sess
->back_channel
.nr_rdma_attrs
> 1) {
1418 dprintk("Too many back channel attr bitmaps!\n");
1423 READ32(sess
->callback_prog
);
1424 nfsd4_decode_cb_sec(argp
, &sess
->cb_sec
);
1429 nfsd4_decode_destroy_session(struct nfsd4_compoundargs
*argp
,
1430 struct nfsd4_destroy_session
*destroy_session
)
1433 READ_BUF(NFS4_MAX_SESSIONID_LEN
);
1434 COPYMEM(destroy_session
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
1440 nfsd4_decode_free_stateid(struct nfsd4_compoundargs
*argp
,
1441 struct nfsd4_free_stateid
*free_stateid
)
1445 READ_BUF(sizeof(stateid_t
));
1446 READ32(free_stateid
->fr_stateid
.si_generation
);
1447 COPYMEM(&free_stateid
->fr_stateid
.si_opaque
, sizeof(stateid_opaque_t
));
1453 nfsd4_decode_sequence(struct nfsd4_compoundargs
*argp
,
1454 struct nfsd4_sequence
*seq
)
1458 READ_BUF(NFS4_MAX_SESSIONID_LEN
+ 16);
1459 COPYMEM(seq
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
1461 READ32(seq
->slotid
);
1462 READ32(seq
->maxslots
);
1463 READ32(seq
->cachethis
);
1469 nfsd4_decode_test_stateid(struct nfsd4_compoundargs
*argp
, struct nfsd4_test_stateid
*test_stateid
)
1473 struct nfsd4_test_stateid_id
*stateid
;
1476 test_stateid
->ts_num_ids
= ntohl(*p
++);
1478 INIT_LIST_HEAD(&test_stateid
->ts_stateid_list
);
1480 for (i
= 0; i
< test_stateid
->ts_num_ids
; i
++) {
1481 stateid
= kmalloc(sizeof(struct nfsd4_test_stateid_id
), GFP_KERNEL
);
1483 status
= nfserrno(-ENOMEM
);
1487 defer_free(argp
, kfree
, stateid
);
1488 INIT_LIST_HEAD(&stateid
->ts_id_list
);
1489 list_add_tail(&stateid
->ts_id_list
, &test_stateid
->ts_stateid_list
);
1491 status
= nfsd4_decode_stateid(argp
, &stateid
->ts_id_stateid
);
1500 dprintk("NFSD: xdr error (%s:%d)\n", __FILE__
, __LINE__
);
1501 status
= nfserr_bad_xdr
;
1505 static __be32
nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs
*argp
, struct nfsd4_destroy_clientid
*dc
)
1510 COPYMEM(&dc
->clientid
, 8);
1515 static __be32
nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs
*argp
, struct nfsd4_reclaim_complete
*rc
)
1520 READ32(rc
->rca_one_fs
);
1526 nfsd4_decode_noop(struct nfsd4_compoundargs
*argp
, void *p
)
1532 nfsd4_decode_notsupp(struct nfsd4_compoundargs
*argp
, void *p
)
1534 return nfserr_notsupp
;
1537 typedef __be32(*nfsd4_dec
)(struct nfsd4_compoundargs
*argp
, void *);
1539 static nfsd4_dec nfsd4_dec_ops
[] = {
1540 [OP_ACCESS
] = (nfsd4_dec
)nfsd4_decode_access
,
1541 [OP_CLOSE
] = (nfsd4_dec
)nfsd4_decode_close
,
1542 [OP_COMMIT
] = (nfsd4_dec
)nfsd4_decode_commit
,
1543 [OP_CREATE
] = (nfsd4_dec
)nfsd4_decode_create
,
1544 [OP_DELEGPURGE
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1545 [OP_DELEGRETURN
] = (nfsd4_dec
)nfsd4_decode_delegreturn
,
1546 [OP_GETATTR
] = (nfsd4_dec
)nfsd4_decode_getattr
,
1547 [OP_GETFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1548 [OP_LINK
] = (nfsd4_dec
)nfsd4_decode_link
,
1549 [OP_LOCK
] = (nfsd4_dec
)nfsd4_decode_lock
,
1550 [OP_LOCKT
] = (nfsd4_dec
)nfsd4_decode_lockt
,
1551 [OP_LOCKU
] = (nfsd4_dec
)nfsd4_decode_locku
,
1552 [OP_LOOKUP
] = (nfsd4_dec
)nfsd4_decode_lookup
,
1553 [OP_LOOKUPP
] = (nfsd4_dec
)nfsd4_decode_noop
,
1554 [OP_NVERIFY
] = (nfsd4_dec
)nfsd4_decode_verify
,
1555 [OP_OPEN
] = (nfsd4_dec
)nfsd4_decode_open
,
1556 [OP_OPENATTR
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1557 [OP_OPEN_CONFIRM
] = (nfsd4_dec
)nfsd4_decode_open_confirm
,
1558 [OP_OPEN_DOWNGRADE
] = (nfsd4_dec
)nfsd4_decode_open_downgrade
,
1559 [OP_PUTFH
] = (nfsd4_dec
)nfsd4_decode_putfh
,
1560 [OP_PUTPUBFH
] = (nfsd4_dec
)nfsd4_decode_putpubfh
,
1561 [OP_PUTROOTFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1562 [OP_READ
] = (nfsd4_dec
)nfsd4_decode_read
,
1563 [OP_READDIR
] = (nfsd4_dec
)nfsd4_decode_readdir
,
1564 [OP_READLINK
] = (nfsd4_dec
)nfsd4_decode_noop
,
1565 [OP_REMOVE
] = (nfsd4_dec
)nfsd4_decode_remove
,
1566 [OP_RENAME
] = (nfsd4_dec
)nfsd4_decode_rename
,
1567 [OP_RENEW
] = (nfsd4_dec
)nfsd4_decode_renew
,
1568 [OP_RESTOREFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1569 [OP_SAVEFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
1570 [OP_SECINFO
] = (nfsd4_dec
)nfsd4_decode_secinfo
,
1571 [OP_SETATTR
] = (nfsd4_dec
)nfsd4_decode_setattr
,
1572 [OP_SETCLIENTID
] = (nfsd4_dec
)nfsd4_decode_setclientid
,
1573 [OP_SETCLIENTID_CONFIRM
] = (nfsd4_dec
)nfsd4_decode_setclientid_confirm
,
1574 [OP_VERIFY
] = (nfsd4_dec
)nfsd4_decode_verify
,
1575 [OP_WRITE
] = (nfsd4_dec
)nfsd4_decode_write
,
1576 [OP_RELEASE_LOCKOWNER
] = (nfsd4_dec
)nfsd4_decode_release_lockowner
,
1578 /* new operations for NFSv4.1 */
1579 [OP_BACKCHANNEL_CTL
] = (nfsd4_dec
)nfsd4_decode_backchannel_ctl
,
1580 [OP_BIND_CONN_TO_SESSION
]= (nfsd4_dec
)nfsd4_decode_bind_conn_to_session
,
1581 [OP_EXCHANGE_ID
] = (nfsd4_dec
)nfsd4_decode_exchange_id
,
1582 [OP_CREATE_SESSION
] = (nfsd4_dec
)nfsd4_decode_create_session
,
1583 [OP_DESTROY_SESSION
] = (nfsd4_dec
)nfsd4_decode_destroy_session
,
1584 [OP_FREE_STATEID
] = (nfsd4_dec
)nfsd4_decode_free_stateid
,
1585 [OP_GET_DIR_DELEGATION
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1586 [OP_GETDEVICEINFO
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1587 [OP_GETDEVICELIST
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1588 [OP_LAYOUTCOMMIT
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1589 [OP_LAYOUTGET
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1590 [OP_LAYOUTRETURN
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1591 [OP_SECINFO_NO_NAME
] = (nfsd4_dec
)nfsd4_decode_secinfo_no_name
,
1592 [OP_SEQUENCE
] = (nfsd4_dec
)nfsd4_decode_sequence
,
1593 [OP_SET_SSV
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1594 [OP_TEST_STATEID
] = (nfsd4_dec
)nfsd4_decode_test_stateid
,
1595 [OP_WANT_DELEGATION
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
1596 [OP_DESTROY_CLIENTID
] = (nfsd4_dec
)nfsd4_decode_destroy_clientid
,
1597 [OP_RECLAIM_COMPLETE
] = (nfsd4_dec
)nfsd4_decode_reclaim_complete
,
1601 nfsd4_opnum_in_range(struct nfsd4_compoundargs
*argp
, struct nfsd4_op
*op
)
1603 if (op
->opnum
< FIRST_NFS4_OP
)
1605 else if (argp
->minorversion
== 0 && op
->opnum
> LAST_NFS40_OP
)
1607 else if (argp
->minorversion
== 1 && op
->opnum
> LAST_NFS41_OP
)
1609 else if (argp
->minorversion
== 2 && op
->opnum
> LAST_NFS42_OP
)
1615 * Return a rough estimate of the maximum possible reply size. Note the
1616 * estimate includes rpc headers so is meant to be passed to
1617 * svc_reserve, not svc_reserve_auth.
1619 * Also note the current compound encoding permits only one operation to
1620 * use pages beyond the first one, so the maximum possible length is the
1621 * maximum over these values, not the sum.
1623 static int nfsd4_max_reply(u32 opnum
)
1629 * Both of these ops take a single page for data and put
1630 * the head and tail in another page:
1632 return 2 * PAGE_SIZE
;
1641 nfsd4_decode_compound(struct nfsd4_compoundargs
*argp
)
1644 struct nfsd4_op
*op
;
1645 bool cachethis
= false;
1646 int max_reply
= PAGE_SIZE
;
1650 READ32(argp
->taglen
);
1651 READ_BUF(argp
->taglen
+ 8);
1652 SAVEMEM(argp
->tag
, argp
->taglen
);
1653 READ32(argp
->minorversion
);
1654 READ32(argp
->opcnt
);
1656 if (argp
->taglen
> NFSD4_MAX_TAGLEN
)
1658 if (argp
->opcnt
> 100)
1661 if (argp
->opcnt
> ARRAY_SIZE(argp
->iops
)) {
1662 argp
->ops
= kmalloc(argp
->opcnt
* sizeof(*argp
->ops
), GFP_KERNEL
);
1664 argp
->ops
= argp
->iops
;
1665 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
1670 if (argp
->minorversion
> NFSD_SUPPORTED_MINOR_VERSION
)
1673 for (i
= 0; i
< argp
->opcnt
; i
++) {
1680 if (nfsd4_opnum_in_range(argp
, op
))
1681 op
->status
= nfsd4_dec_ops
[op
->opnum
](argp
, &op
->u
);
1683 op
->opnum
= OP_ILLEGAL
;
1684 op
->status
= nfserr_op_illegal
;
1692 * We'll try to cache the result in the DRC if any one
1693 * op in the compound wants to be cached:
1695 cachethis
|= nfsd4_cache_this_op(op
);
1697 max_reply
= max(max_reply
, nfsd4_max_reply(op
->opnum
));
1699 /* Sessions make the DRC unnecessary: */
1700 if (argp
->minorversion
)
1702 if (max_reply
!= INT_MAX
)
1703 svc_reserve(argp
->rqstp
, max_reply
);
1704 argp
->rqstp
->rq_cachetype
= cachethis
? RC_REPLBUFF
: RC_NOCACHE
;
1709 #define WRITE32(n) *p++ = htonl(n)
1710 #define WRITE64(n) do { \
1711 *p++ = htonl((u32)((n) >> 32)); \
1712 *p++ = htonl((u32)(n)); \
1714 #define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \
1715 *(p + XDR_QUADLEN(nbytes) -1) = 0; \
1716 memcpy(p, ptr, nbytes); \
1717 p += XDR_QUADLEN(nbytes); \
1720 static void write32(__be32
**p
, u32 n
)
1725 static void write64(__be32
**p
, u64 n
)
1727 write32(p
, (n
>> 32));
1731 static void write_change(__be32
**p
, struct kstat
*stat
, struct inode
*inode
)
1733 if (IS_I_VERSION(inode
)) {
1734 write64(p
, inode
->i_version
);
1736 write32(p
, stat
->ctime
.tv_sec
);
1737 write32(p
, stat
->ctime
.tv_nsec
);
1741 static void write_cinfo(__be32
**p
, struct nfsd4_change_info
*c
)
1743 write32(p
, c
->atomic
);
1744 if (c
->change_supported
) {
1745 write64(p
, c
->before_change
);
1746 write64(p
, c
->after_change
);
1748 write32(p
, c
->before_ctime_sec
);
1749 write32(p
, c
->before_ctime_nsec
);
1750 write32(p
, c
->after_ctime_sec
);
1751 write32(p
, c
->after_ctime_nsec
);
1755 #define RESERVE_SPACE(nbytes) do { \
1757 BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
1759 #define ADJUST_ARGS() resp->p = p
1761 /* Encode as an array of strings the string given with components
1762 * separated @sep, escaped with esc_enter and esc_exit.
1764 static __be32
nfsd4_encode_components_esc(char sep
, char *components
,
1765 __be32
**pp
, int *buflen
,
1766 char esc_enter
, char esc_exit
)
1770 int strlen
, count
=0;
1771 char *str
, *end
, *next
;
1773 dprintk("nfsd4_encode_components(%s)\n", components
);
1774 if ((*buflen
-= 4) < 0)
1775 return nfserr_resource
;
1776 WRITE32(0); /* We will fill this in with @count later */
1777 end
= str
= components
;
1779 bool found_esc
= false;
1781 /* try to parse as esc_start, ..., esc_end, sep */
1782 if (*str
== esc_enter
) {
1783 for (; *end
&& (*end
!= esc_exit
); end
++)
1784 /* find esc_exit or end of string */;
1786 if (*end
&& (!*next
|| *next
== sep
)) {
1793 for (; *end
&& (*end
!= sep
); end
++)
1794 /* find sep or end of string */;
1798 if ((*buflen
-= ((XDR_QUADLEN(strlen
) << 2) + 4)) < 0)
1799 return nfserr_resource
;
1801 WRITEMEM(str
, strlen
);
1814 /* Encode as an array of strings the string given with components
1817 static __be32
nfsd4_encode_components(char sep
, char *components
,
1818 __be32
**pp
, int *buflen
)
1820 return nfsd4_encode_components_esc(sep
, components
, pp
, buflen
, 0, 0);
1824 * encode a location element of a fs_locations structure
1826 static __be32
nfsd4_encode_fs_location4(struct nfsd4_fs_location
*location
,
1827 __be32
**pp
, int *buflen
)
1832 status
= nfsd4_encode_components_esc(':', location
->hosts
, &p
, buflen
,
1836 status
= nfsd4_encode_components('/', location
->path
, &p
, buflen
);
1844 * Encode a path in RFC3530 'pathname4' format
1846 static __be32
nfsd4_encode_path(const struct path
*root
,
1847 const struct path
*path
, __be32
**pp
, int *buflen
)
1849 struct path cur
= *path
;
1851 struct dentry
**components
= NULL
;
1852 unsigned int ncomponents
= 0;
1853 __be32 err
= nfserr_jukebox
;
1855 dprintk("nfsd4_encode_components(");
1858 /* First walk the path up to the nfsd root, and store the
1859 * dentries/path components in an array.
1862 if (cur
.dentry
== root
->dentry
&& cur
.mnt
== root
->mnt
)
1864 if (cur
.dentry
== cur
.mnt
->mnt_root
) {
1865 if (follow_up(&cur
))
1869 if ((ncomponents
& 15) == 0) {
1870 struct dentry
**new;
1871 new = krealloc(components
,
1872 sizeof(*new) * (ncomponents
+ 16),
1878 components
[ncomponents
++] = cur
.dentry
;
1879 cur
.dentry
= dget_parent(cur
.dentry
);
1885 WRITE32(ncomponents
);
1887 while (ncomponents
) {
1888 struct dentry
*dentry
= components
[ncomponents
- 1];
1891 spin_lock(&dentry
->d_lock
);
1892 len
= dentry
->d_name
.len
;
1893 *buflen
-= 4 + (XDR_QUADLEN(len
) << 2);
1895 spin_unlock(&dentry
->d_lock
);
1899 WRITEMEM(dentry
->d_name
.name
, len
);
1900 dprintk("/%s", dentry
->d_name
.name
);
1901 spin_unlock(&dentry
->d_lock
);
1911 dput(components
[--ncomponents
]);
1917 static __be32
nfsd4_encode_fsloc_fsroot(struct svc_rqst
*rqstp
,
1918 const struct path
*path
, __be32
**pp
, int *buflen
)
1920 struct svc_export
*exp_ps
;
1923 exp_ps
= rqst_find_fsidzero_export(rqstp
);
1925 return nfserrno(PTR_ERR(exp_ps
));
1926 res
= nfsd4_encode_path(&exp_ps
->ex_path
, path
, pp
, buflen
);
1932 * encode a fs_locations structure
1934 static __be32
nfsd4_encode_fs_locations(struct svc_rqst
*rqstp
,
1935 struct svc_export
*exp
,
1936 __be32
**pp
, int *buflen
)
1941 struct nfsd4_fs_locations
*fslocs
= &exp
->ex_fslocs
;
1943 status
= nfsd4_encode_fsloc_fsroot(rqstp
, &exp
->ex_path
, &p
, buflen
);
1946 if ((*buflen
-= 4) < 0)
1947 return nfserr_resource
;
1948 WRITE32(fslocs
->locations_count
);
1949 for (i
=0; i
<fslocs
->locations_count
; i
++) {
1950 status
= nfsd4_encode_fs_location4(&fslocs
->locations
[i
],
1959 static u32
nfs4_file_type(umode_t mode
)
1961 switch (mode
& S_IFMT
) {
1962 case S_IFIFO
: return NF4FIFO
;
1963 case S_IFCHR
: return NF4CHR
;
1964 case S_IFDIR
: return NF4DIR
;
1965 case S_IFBLK
: return NF4BLK
;
1966 case S_IFLNK
: return NF4LNK
;
1967 case S_IFREG
: return NF4REG
;
1968 case S_IFSOCK
: return NF4SOCK
;
1969 default: return NF4BAD
;
1974 nfsd4_encode_name(struct svc_rqst
*rqstp
, int whotype
, kuid_t uid
, kgid_t gid
,
1975 __be32
**p
, int *buflen
)
1979 if (*buflen
< (XDR_QUADLEN(IDMAP_NAMESZ
) << 2) + 4)
1980 return nfserr_resource
;
1981 if (whotype
!= NFS4_ACL_WHO_NAMED
)
1982 status
= nfs4_acl_write_who(whotype
, (u8
*)(*p
+ 1));
1983 else if (gid_valid(gid
))
1984 status
= nfsd_map_gid_to_name(rqstp
, gid
, (u8
*)(*p
+ 1));
1986 status
= nfsd_map_uid_to_name(rqstp
, uid
, (u8
*)(*p
+ 1));
1988 return nfserrno(status
);
1989 *p
= xdr_encode_opaque(*p
, NULL
, status
);
1990 *buflen
-= (XDR_QUADLEN(status
) << 2) + 4;
1991 BUG_ON(*buflen
< 0);
1995 static inline __be32
1996 nfsd4_encode_user(struct svc_rqst
*rqstp
, kuid_t user
, __be32
**p
, int *buflen
)
1998 return nfsd4_encode_name(rqstp
, NFS4_ACL_WHO_NAMED
, user
, INVALID_GID
,
2002 static inline __be32
2003 nfsd4_encode_group(struct svc_rqst
*rqstp
, kgid_t group
, __be32
**p
, int *buflen
)
2005 return nfsd4_encode_name(rqstp
, NFS4_ACL_WHO_NAMED
, INVALID_UID
, group
,
2009 static inline __be32
2010 nfsd4_encode_aclname(struct svc_rqst
*rqstp
, struct nfs4_ace
*ace
,
2011 __be32
**p
, int *buflen
)
2013 kuid_t uid
= INVALID_UID
;
2014 kgid_t gid
= INVALID_GID
;
2016 if (ace
->whotype
== NFS4_ACL_WHO_NAMED
) {
2017 if (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
)
2022 return nfsd4_encode_name(rqstp
, ace
->whotype
, uid
, gid
, p
, buflen
);
2025 #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
2026 FATTR4_WORD0_RDATTR_ERROR)
2027 #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
2029 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2030 static inline __be32
2031 nfsd4_encode_security_label(struct svc_rqst
*rqstp
, void *context
, int len
, __be32
**pp
, int *buflen
)
2035 if (*buflen
< ((XDR_QUADLEN(len
) << 2) + 4 + 4 + 4))
2036 return nfserr_resource
;
2039 * For now we use a 0 here to indicate the null translation; in
2040 * the future we may place a call to translation code here.
2042 if ((*buflen
-= 8) < 0)
2043 return nfserr_resource
;
2045 WRITE32(0); /* lfs */
2046 WRITE32(0); /* pi */
2047 p
= xdr_encode_opaque(p
, context
, len
);
2048 *buflen
-= (XDR_QUADLEN(len
) << 2) + 4;
2054 static inline __be32
2055 nfsd4_encode_security_label(struct svc_rqst
*rqstp
, void *context
, int len
, __be32
**pp
, int *buflen
)
2059 static __be32
fattr_handle_absent_fs(u32
*bmval0
, u32
*bmval1
, u32
*rdattr_err
)
2061 /* As per referral draft: */
2062 if (*bmval0
& ~WORD0_ABSENT_FS_ATTRS
||
2063 *bmval1
& ~WORD1_ABSENT_FS_ATTRS
) {
2064 if (*bmval0
& FATTR4_WORD0_RDATTR_ERROR
||
2065 *bmval0
& FATTR4_WORD0_FS_LOCATIONS
)
2066 *rdattr_err
= NFSERR_MOVED
;
2068 return nfserr_moved
;
2070 *bmval0
&= WORD0_ABSENT_FS_ATTRS
;
2071 *bmval1
&= WORD1_ABSENT_FS_ATTRS
;
2076 static int get_parent_attributes(struct svc_export
*exp
, struct kstat
*stat
)
2078 struct path path
= exp
->ex_path
;
2082 while (follow_up(&path
)) {
2083 if (path
.dentry
!= path
.mnt
->mnt_root
)
2086 err
= vfs_getattr(&path
, stat
);
2092 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
2095 * countp is the buffer size in _words_
2098 nfsd4_encode_fattr(struct svc_fh
*fhp
, struct svc_export
*exp
,
2099 struct dentry
*dentry
, __be32
**buffer
, int count
, u32
*bmval
,
2100 struct svc_rqst
*rqstp
, int ignore_crossmnt
)
2102 u32 bmval0
= bmval
[0];
2103 u32 bmval1
= bmval
[1];
2104 u32 bmval2
= bmval
[2];
2106 struct svc_fh tempfh
;
2107 struct kstatfs statfs
;
2108 int buflen
= count
<< 2;
2113 __be32
*p
= *buffer
;
2117 struct nfs4_acl
*acl
= NULL
;
2118 void *context
= NULL
;
2120 bool contextsupport
= false;
2121 struct nfsd4_compoundres
*resp
= rqstp
->rq_resp
;
2122 u32 minorversion
= resp
->cstate
.minorversion
;
2123 struct path path
= {
2124 .mnt
= exp
->ex_path
.mnt
,
2127 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
2129 BUG_ON(bmval1
& NFSD_WRITEONLY_ATTRS_WORD1
);
2130 BUG_ON(bmval0
& ~nfsd_suppattrs0(minorversion
));
2131 BUG_ON(bmval1
& ~nfsd_suppattrs1(minorversion
));
2132 BUG_ON(bmval2
& ~nfsd_suppattrs2(minorversion
));
2134 if (exp
->ex_fslocs
.migrated
) {
2136 status
= fattr_handle_absent_fs(&bmval0
, &bmval1
, &rdattr_err
);
2141 err
= vfs_getattr(&path
, &stat
);
2144 if ((bmval0
& (FATTR4_WORD0_FILES_FREE
| FATTR4_WORD0_FILES_TOTAL
|
2145 FATTR4_WORD0_MAXNAME
)) ||
2146 (bmval1
& (FATTR4_WORD1_SPACE_AVAIL
| FATTR4_WORD1_SPACE_FREE
|
2147 FATTR4_WORD1_SPACE_TOTAL
))) {
2148 err
= vfs_statfs(&path
, &statfs
);
2152 if ((bmval0
& (FATTR4_WORD0_FILEHANDLE
| FATTR4_WORD0_FSID
)) && !fhp
) {
2153 fh_init(&tempfh
, NFS4_FHSIZE
);
2154 status
= fh_compose(&tempfh
, exp
, dentry
, NULL
);
2159 if (bmval0
& (FATTR4_WORD0_ACL
| FATTR4_WORD0_ACLSUPPORT
2160 | FATTR4_WORD0_SUPPORTED_ATTRS
)) {
2161 err
= nfsd4_get_nfs4_acl(rqstp
, dentry
, &acl
);
2162 aclsupport
= (err
== 0);
2163 if (bmval0
& FATTR4_WORD0_ACL
) {
2164 if (err
== -EOPNOTSUPP
)
2165 bmval0
&= ~FATTR4_WORD0_ACL
;
2166 else if (err
== -EINVAL
) {
2167 status
= nfserr_attrnotsupp
;
2169 } else if (err
!= 0)
2174 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2175 if ((bmval
[2] & FATTR4_WORD2_SECURITY_LABEL
) ||
2176 bmval
[0] & FATTR4_WORD0_SUPPORTED_ATTRS
) {
2177 err
= security_inode_getsecctx(dentry
->d_inode
,
2178 &context
, &contextlen
);
2179 contextsupport
= (err
== 0);
2180 if (bmval2
& FATTR4_WORD2_SECURITY_LABEL
) {
2181 if (err
== -EOPNOTSUPP
)
2182 bmval2
&= ~FATTR4_WORD2_SECURITY_LABEL
;
2187 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
2190 if ((buflen
-= 16) < 0)
2196 } else if (bmval1
) {
2197 if ((buflen
-= 12) < 0)
2203 if ((buflen
-= 8) < 0)
2208 attrlenp
= p
++; /* to be backfilled later */
2210 if (bmval0
& FATTR4_WORD0_SUPPORTED_ATTRS
) {
2211 u32 word0
= nfsd_suppattrs0(minorversion
);
2212 u32 word1
= nfsd_suppattrs1(minorversion
);
2213 u32 word2
= nfsd_suppattrs2(minorversion
);
2216 word0
&= ~FATTR4_WORD0_ACL
;
2217 if (!contextsupport
)
2218 word2
&= ~FATTR4_WORD2_SECURITY_LABEL
;
2220 if ((buflen
-= 12) < 0)
2226 if ((buflen
-= 16) < 0)
2234 if (bmval0
& FATTR4_WORD0_TYPE
) {
2235 if ((buflen
-= 4) < 0)
2237 dummy
= nfs4_file_type(stat
.mode
);
2238 if (dummy
== NF4BAD
)
2239 goto out_serverfault
;
2242 if (bmval0
& FATTR4_WORD0_FH_EXPIRE_TYPE
) {
2243 if ((buflen
-= 4) < 0)
2245 if (exp
->ex_flags
& NFSEXP_NOSUBTREECHECK
)
2246 WRITE32(NFS4_FH_PERSISTENT
);
2248 WRITE32(NFS4_FH_PERSISTENT
|NFS4_FH_VOL_RENAME
);
2250 if (bmval0
& FATTR4_WORD0_CHANGE
) {
2251 if ((buflen
-= 8) < 0)
2253 write_change(&p
, &stat
, dentry
->d_inode
);
2255 if (bmval0
& FATTR4_WORD0_SIZE
) {
2256 if ((buflen
-= 8) < 0)
2260 if (bmval0
& FATTR4_WORD0_LINK_SUPPORT
) {
2261 if ((buflen
-= 4) < 0)
2265 if (bmval0
& FATTR4_WORD0_SYMLINK_SUPPORT
) {
2266 if ((buflen
-= 4) < 0)
2270 if (bmval0
& FATTR4_WORD0_NAMED_ATTR
) {
2271 if ((buflen
-= 4) < 0)
2275 if (bmval0
& FATTR4_WORD0_FSID
) {
2276 if ((buflen
-= 16) < 0)
2278 if (exp
->ex_fslocs
.migrated
) {
2279 WRITE64(NFS4_REFERRAL_FSID_MAJOR
);
2280 WRITE64(NFS4_REFERRAL_FSID_MINOR
);
2281 } else switch(fsid_source(fhp
)) {
2282 case FSIDSOURCE_FSID
:
2283 WRITE64((u64
)exp
->ex_fsid
);
2286 case FSIDSOURCE_DEV
:
2288 WRITE32(MAJOR(stat
.dev
));
2290 WRITE32(MINOR(stat
.dev
));
2292 case FSIDSOURCE_UUID
:
2293 WRITEMEM(exp
->ex_uuid
, 16);
2297 if (bmval0
& FATTR4_WORD0_UNIQUE_HANDLES
) {
2298 if ((buflen
-= 4) < 0)
2302 if (bmval0
& FATTR4_WORD0_LEASE_TIME
) {
2303 if ((buflen
-= 4) < 0)
2305 WRITE32(nn
->nfsd4_lease
);
2307 if (bmval0
& FATTR4_WORD0_RDATTR_ERROR
) {
2308 if ((buflen
-= 4) < 0)
2310 WRITE32(rdattr_err
);
2312 if (bmval0
& FATTR4_WORD0_ACL
) {
2313 struct nfs4_ace
*ace
;
2316 if ((buflen
-= 4) < 0)
2322 if ((buflen
-= 4) < 0)
2324 WRITE32(acl
->naces
);
2326 for (ace
= acl
->aces
; ace
< acl
->aces
+ acl
->naces
; ace
++) {
2327 if ((buflen
-= 4*3) < 0)
2331 WRITE32(ace
->access_mask
& NFS4_ACE_MASK_ALL
);
2332 status
= nfsd4_encode_aclname(rqstp
, ace
, &p
, &buflen
);
2333 if (status
== nfserr_resource
)
2340 if (bmval0
& FATTR4_WORD0_ACLSUPPORT
) {
2341 if ((buflen
-= 4) < 0)
2343 WRITE32(aclsupport
?
2344 ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
: 0);
2346 if (bmval0
& FATTR4_WORD0_CANSETTIME
) {
2347 if ((buflen
-= 4) < 0)
2351 if (bmval0
& FATTR4_WORD0_CASE_INSENSITIVE
) {
2352 if ((buflen
-= 4) < 0)
2356 if (bmval0
& FATTR4_WORD0_CASE_PRESERVING
) {
2357 if ((buflen
-= 4) < 0)
2361 if (bmval0
& FATTR4_WORD0_CHOWN_RESTRICTED
) {
2362 if ((buflen
-= 4) < 0)
2366 if (bmval0
& FATTR4_WORD0_FILEHANDLE
) {
2367 buflen
-= (XDR_QUADLEN(fhp
->fh_handle
.fh_size
) << 2) + 4;
2370 WRITE32(fhp
->fh_handle
.fh_size
);
2371 WRITEMEM(&fhp
->fh_handle
.fh_base
, fhp
->fh_handle
.fh_size
);
2373 if (bmval0
& FATTR4_WORD0_FILEID
) {
2374 if ((buflen
-= 8) < 0)
2378 if (bmval0
& FATTR4_WORD0_FILES_AVAIL
) {
2379 if ((buflen
-= 8) < 0)
2381 WRITE64((u64
) statfs
.f_ffree
);
2383 if (bmval0
& FATTR4_WORD0_FILES_FREE
) {
2384 if ((buflen
-= 8) < 0)
2386 WRITE64((u64
) statfs
.f_ffree
);
2388 if (bmval0
& FATTR4_WORD0_FILES_TOTAL
) {
2389 if ((buflen
-= 8) < 0)
2391 WRITE64((u64
) statfs
.f_files
);
2393 if (bmval0
& FATTR4_WORD0_FS_LOCATIONS
) {
2394 status
= nfsd4_encode_fs_locations(rqstp
, exp
, &p
, &buflen
);
2395 if (status
== nfserr_resource
)
2400 if (bmval0
& FATTR4_WORD0_HOMOGENEOUS
) {
2401 if ((buflen
-= 4) < 0)
2405 if (bmval0
& FATTR4_WORD0_MAXFILESIZE
) {
2406 if ((buflen
-= 8) < 0)
2408 WRITE64(exp
->ex_path
.mnt
->mnt_sb
->s_maxbytes
);
2410 if (bmval0
& FATTR4_WORD0_MAXLINK
) {
2411 if ((buflen
-= 4) < 0)
2415 if (bmval0
& FATTR4_WORD0_MAXNAME
) {
2416 if ((buflen
-= 4) < 0)
2418 WRITE32(statfs
.f_namelen
);
2420 if (bmval0
& FATTR4_WORD0_MAXREAD
) {
2421 if ((buflen
-= 8) < 0)
2423 WRITE64((u64
) svc_max_payload(rqstp
));
2425 if (bmval0
& FATTR4_WORD0_MAXWRITE
) {
2426 if ((buflen
-= 8) < 0)
2428 WRITE64((u64
) svc_max_payload(rqstp
));
2430 if (bmval1
& FATTR4_WORD1_MODE
) {
2431 if ((buflen
-= 4) < 0)
2433 WRITE32(stat
.mode
& S_IALLUGO
);
2435 if (bmval1
& FATTR4_WORD1_NO_TRUNC
) {
2436 if ((buflen
-= 4) < 0)
2440 if (bmval1
& FATTR4_WORD1_NUMLINKS
) {
2441 if ((buflen
-= 4) < 0)
2443 WRITE32(stat
.nlink
);
2445 if (bmval1
& FATTR4_WORD1_OWNER
) {
2446 status
= nfsd4_encode_user(rqstp
, stat
.uid
, &p
, &buflen
);
2447 if (status
== nfserr_resource
)
2452 if (bmval1
& FATTR4_WORD1_OWNER_GROUP
) {
2453 status
= nfsd4_encode_group(rqstp
, stat
.gid
, &p
, &buflen
);
2454 if (status
== nfserr_resource
)
2459 if (bmval1
& FATTR4_WORD1_RAWDEV
) {
2460 if ((buflen
-= 8) < 0)
2462 WRITE32((u32
) MAJOR(stat
.rdev
));
2463 WRITE32((u32
) MINOR(stat
.rdev
));
2465 if (bmval1
& FATTR4_WORD1_SPACE_AVAIL
) {
2466 if ((buflen
-= 8) < 0)
2468 dummy64
= (u64
)statfs
.f_bavail
* (u64
)statfs
.f_bsize
;
2471 if (bmval1
& FATTR4_WORD1_SPACE_FREE
) {
2472 if ((buflen
-= 8) < 0)
2474 dummy64
= (u64
)statfs
.f_bfree
* (u64
)statfs
.f_bsize
;
2477 if (bmval1
& FATTR4_WORD1_SPACE_TOTAL
) {
2478 if ((buflen
-= 8) < 0)
2480 dummy64
= (u64
)statfs
.f_blocks
* (u64
)statfs
.f_bsize
;
2483 if (bmval1
& FATTR4_WORD1_SPACE_USED
) {
2484 if ((buflen
-= 8) < 0)
2486 dummy64
= (u64
)stat
.blocks
<< 9;
2489 if (bmval1
& FATTR4_WORD1_TIME_ACCESS
) {
2490 if ((buflen
-= 12) < 0)
2492 WRITE64((s64
)stat
.atime
.tv_sec
);
2493 WRITE32(stat
.atime
.tv_nsec
);
2495 if (bmval1
& FATTR4_WORD1_TIME_DELTA
) {
2496 if ((buflen
-= 12) < 0)
2502 if (bmval1
& FATTR4_WORD1_TIME_METADATA
) {
2503 if ((buflen
-= 12) < 0)
2505 WRITE64((s64
)stat
.ctime
.tv_sec
);
2506 WRITE32(stat
.ctime
.tv_nsec
);
2508 if (bmval1
& FATTR4_WORD1_TIME_MODIFY
) {
2509 if ((buflen
-= 12) < 0)
2511 WRITE64((s64
)stat
.mtime
.tv_sec
);
2512 WRITE32(stat
.mtime
.tv_nsec
);
2514 if (bmval1
& FATTR4_WORD1_MOUNTED_ON_FILEID
) {
2515 if ((buflen
-= 8) < 0)
2518 * Get parent's attributes if not ignoring crossmount
2519 * and this is the root of a cross-mounted filesystem.
2521 if (ignore_crossmnt
== 0 &&
2522 dentry
== exp
->ex_path
.mnt
->mnt_root
)
2523 get_parent_attributes(exp
, &stat
);
2526 if (bmval2
& FATTR4_WORD2_SECURITY_LABEL
) {
2527 status
= nfsd4_encode_security_label(rqstp
, context
,
2528 contextlen
, &p
, &buflen
);
2532 if (bmval2
& FATTR4_WORD2_SUPPATTR_EXCLCREAT
) {
2534 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0
);
2535 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1
);
2536 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2
);
2539 *attrlenp
= htonl((char *)p
- (char *)attrlenp
- 4);
2544 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2546 security_release_secctx(context
, contextlen
);
2547 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
2553 status
= nfserrno(err
);
2556 status
= nfserr_resource
;
2559 status
= nfserr_serverfault
;
2563 static inline int attributes_need_mount(u32
*bmval
)
2565 if (bmval
[0] & ~(FATTR4_WORD0_RDATTR_ERROR
| FATTR4_WORD0_LEASE_TIME
))
2567 if (bmval
[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID
)
2573 nfsd4_encode_dirent_fattr(struct nfsd4_readdir
*cd
,
2574 const char *name
, int namlen
, __be32
**p
, int buflen
)
2576 struct svc_export
*exp
= cd
->rd_fhp
->fh_export
;
2577 struct dentry
*dentry
;
2579 int ignore_crossmnt
= 0;
2581 dentry
= lookup_one_len(name
, cd
->rd_fhp
->fh_dentry
, namlen
);
2583 return nfserrno(PTR_ERR(dentry
));
2584 if (!dentry
->d_inode
) {
2586 * nfsd_buffered_readdir drops the i_mutex between
2587 * readdir and calling this callback, leaving a window
2588 * where this directory entry could have gone away.
2591 return nfserr_noent
;
2596 * In the case of a mountpoint, the client may be asking for
2597 * attributes that are only properties of the underlying filesystem
2598 * as opposed to the cross-mounted file system. In such a case,
2599 * we will not follow the cross mount and will fill the attribtutes
2600 * directly from the mountpoint dentry.
2602 if (nfsd_mountpoint(dentry
, exp
)) {
2605 if (!(exp
->ex_flags
& NFSEXP_V4ROOT
)
2606 && !attributes_need_mount(cd
->rd_bmval
)) {
2607 ignore_crossmnt
= 1;
2611 * Why the heck aren't we just using nfsd_lookup??
2612 * Different "."/".." handling? Something else?
2613 * At least, add a comment here to explain....
2615 err
= nfsd_cross_mnt(cd
->rd_rqstp
, &dentry
, &exp
);
2617 nfserr
= nfserrno(err
);
2620 nfserr
= check_nfsd_access(exp
, cd
->rd_rqstp
);
2626 nfserr
= nfsd4_encode_fattr(NULL
, exp
, dentry
, p
, buflen
, cd
->rd_bmval
,
2627 cd
->rd_rqstp
, ignore_crossmnt
);
2635 nfsd4_encode_rdattr_error(__be32
*p
, int buflen
, __be32 nfserr
)
2642 *p
++ = htonl(FATTR4_WORD0_RDATTR_ERROR
); /* bmval0 */
2643 *p
++ = htonl(0); /* bmval1 */
2646 *p
++ = nfserr
; /* no htonl */
2647 *attrlenp
= htonl((char *)p
- (char *)attrlenp
- 4);
2652 nfsd4_encode_dirent(void *ccdv
, const char *name
, int namlen
,
2653 loff_t offset
, u64 ino
, unsigned int d_type
)
2655 struct readdir_cd
*ccd
= ccdv
;
2656 struct nfsd4_readdir
*cd
= container_of(ccd
, struct nfsd4_readdir
, common
);
2658 __be32
*p
= cd
->buffer
;
2660 __be32 nfserr
= nfserr_toosmall
;
2662 /* In nfsv4, "." and ".." never make it onto the wire.. */
2663 if (name
&& isdotent(name
, namlen
)) {
2664 cd
->common
.err
= nfs_ok
;
2669 xdr_encode_hyper(cd
->offset
, (u64
) offset
);
2671 buflen
= cd
->buflen
- 4 - XDR_QUADLEN(namlen
);
2675 *p
++ = xdr_one
; /* mark entry present */
2677 p
= xdr_encode_hyper(p
, NFS_OFFSET_MAX
); /* offset of next entry */
2678 p
= xdr_encode_array(p
, name
, namlen
); /* name length & name */
2680 nfserr
= nfsd4_encode_dirent_fattr(cd
, name
, namlen
, &p
, buflen
);
2684 case nfserr_resource
:
2685 nfserr
= nfserr_toosmall
;
2691 * If the client requested the RDATTR_ERROR attribute,
2692 * we stuff the error code into this attribute
2693 * and continue. If this attribute was not requested,
2694 * then in accordance with the spec, we fail the
2695 * entire READDIR operation(!)
2697 if (!(cd
->rd_bmval
[0] & FATTR4_WORD0_RDATTR_ERROR
))
2699 p
= nfsd4_encode_rdattr_error(p
, buflen
, nfserr
);
2701 nfserr
= nfserr_toosmall
;
2705 cd
->buflen
-= (p
- cd
->buffer
);
2707 cd
->offset
= cookiep
;
2709 cd
->common
.err
= nfs_ok
;
2712 cd
->common
.err
= nfserr
;
2717 nfsd4_encode_stateid(struct nfsd4_compoundres
*resp
, stateid_t
*sid
)
2721 RESERVE_SPACE(sizeof(stateid_t
));
2722 WRITE32(sid
->si_generation
);
2723 WRITEMEM(&sid
->si_opaque
, sizeof(stateid_opaque_t
));
2728 nfsd4_encode_access(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_access
*access
)
2734 WRITE32(access
->ac_supported
);
2735 WRITE32(access
->ac_resp_access
);
2741 static __be32
nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_bind_conn_to_session
*bcts
)
2746 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN
+ 8);
2747 WRITEMEM(bcts
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
2749 /* Sorry, we do not yet support RDMA over 4.1: */
2757 nfsd4_encode_close(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_close
*close
)
2760 nfsd4_encode_stateid(resp
, &close
->cl_stateid
);
2767 nfsd4_encode_commit(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_commit
*commit
)
2772 RESERVE_SPACE(NFS4_VERIFIER_SIZE
);
2773 WRITEMEM(commit
->co_verf
.data
, NFS4_VERIFIER_SIZE
);
2780 nfsd4_encode_create(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_create
*create
)
2786 write_cinfo(&p
, &create
->cr_cinfo
);
2788 WRITE32(create
->cr_bmval
[0]);
2789 WRITE32(create
->cr_bmval
[1]);
2796 nfsd4_encode_getattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_getattr
*getattr
)
2798 struct svc_fh
*fhp
= getattr
->ga_fhp
;
2804 buflen
= resp
->end
- resp
->p
- (COMPOUND_ERR_SLACK_SPACE
>> 2);
2805 nfserr
= nfsd4_encode_fattr(fhp
, fhp
->fh_export
, fhp
->fh_dentry
,
2806 &resp
->p
, buflen
, getattr
->ga_bmval
,
2812 nfsd4_encode_getfh(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct svc_fh
**fhpp
)
2814 struct svc_fh
*fhp
= *fhpp
;
2819 len
= fhp
->fh_handle
.fh_size
;
2820 RESERVE_SPACE(len
+ 4);
2822 WRITEMEM(&fhp
->fh_handle
.fh_base
, len
);
2829 * Including all fields other than the name, a LOCK4denied structure requires
2830 * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
2833 nfsd4_encode_lock_denied(struct nfsd4_compoundres
*resp
, struct nfsd4_lock_denied
*ld
)
2835 struct xdr_netobj
*conf
= &ld
->ld_owner
;
2838 RESERVE_SPACE(32 + XDR_LEN(conf
->len
));
2839 WRITE64(ld
->ld_start
);
2840 WRITE64(ld
->ld_length
);
2841 WRITE32(ld
->ld_type
);
2843 WRITEMEM(&ld
->ld_clientid
, 8);
2845 WRITEMEM(conf
->data
, conf
->len
);
2847 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
2848 WRITE64((u64
)0); /* clientid */
2849 WRITE32(0); /* length of owner name */
2855 nfsd4_encode_lock(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lock
*lock
)
2858 nfsd4_encode_stateid(resp
, &lock
->lk_resp_stateid
);
2859 else if (nfserr
== nfserr_denied
)
2860 nfsd4_encode_lock_denied(resp
, &lock
->lk_denied
);
2866 nfsd4_encode_lockt(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lockt
*lockt
)
2868 if (nfserr
== nfserr_denied
)
2869 nfsd4_encode_lock_denied(resp
, &lockt
->lt_denied
);
2874 nfsd4_encode_locku(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_locku
*locku
)
2877 nfsd4_encode_stateid(resp
, &locku
->lu_stateid
);
2884 nfsd4_encode_link(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_link
*link
)
2890 write_cinfo(&p
, &link
->li_cinfo
);
2898 nfsd4_encode_open(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open
*open
)
2905 nfsd4_encode_stateid(resp
, &open
->op_stateid
);
2907 write_cinfo(&p
, &open
->op_cinfo
);
2908 WRITE32(open
->op_rflags
);
2910 WRITE32(open
->op_bmval
[0]);
2911 WRITE32(open
->op_bmval
[1]);
2912 WRITE32(open
->op_delegate_type
);
2915 switch (open
->op_delegate_type
) {
2916 case NFS4_OPEN_DELEGATE_NONE
:
2918 case NFS4_OPEN_DELEGATE_READ
:
2919 nfsd4_encode_stateid(resp
, &open
->op_delegate_stateid
);
2921 WRITE32(open
->op_recall
);
2924 * TODO: ACE's in delegations
2926 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
2929 WRITE32(0); /* XXX: is NULL principal ok? */
2932 case NFS4_OPEN_DELEGATE_WRITE
:
2933 nfsd4_encode_stateid(resp
, &open
->op_delegate_stateid
);
2938 * TODO: space_limit's in delegations
2940 WRITE32(NFS4_LIMIT_SIZE
);
2945 * TODO: ACE's in delegations
2947 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
2950 WRITE32(0); /* XXX: is NULL principal ok? */
2953 case NFS4_OPEN_DELEGATE_NONE_EXT
: /* 4.1 */
2954 switch (open
->op_why_no_deleg
) {
2955 case WND4_CONTENTION
:
2958 WRITE32(open
->op_why_no_deleg
);
2959 WRITE32(0); /* deleg signaling not supported yet */
2963 WRITE32(open
->op_why_no_deleg
);
2970 /* XXX save filehandle here */
2976 nfsd4_encode_open_confirm(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_confirm
*oc
)
2979 nfsd4_encode_stateid(resp
, &oc
->oc_resp_stateid
);
2985 nfsd4_encode_open_downgrade(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_downgrade
*od
)
2988 nfsd4_encode_stateid(resp
, &od
->od_stateid
);
2994 nfsd4_encode_read(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
2995 struct nfsd4_read
*read
)
3000 unsigned long maxcount
;
3006 if (resp
->xbuf
->page_len
)
3007 return nfserr_resource
;
3009 RESERVE_SPACE(8); /* eof flag and byte count */
3011 maxcount
= svc_max_payload(resp
->rqstp
);
3012 if (maxcount
> read
->rd_length
)
3013 maxcount
= read
->rd_length
;
3018 page
= *(resp
->rqstp
->rq_next_page
);
3019 if (!page
) { /* ran out of pages */
3023 resp
->rqstp
->rq_vec
[v
].iov_base
= page_address(page
);
3024 resp
->rqstp
->rq_vec
[v
].iov_len
=
3025 len
< PAGE_SIZE
? len
: PAGE_SIZE
;
3026 resp
->rqstp
->rq_next_page
++;
3032 nfserr
= nfsd_read_file(read
->rd_rqstp
, read
->rd_fhp
, read
->rd_filp
,
3033 read
->rd_offset
, resp
->rqstp
->rq_vec
, read
->rd_vlen
,
3038 eof
= (read
->rd_offset
+ maxcount
>=
3039 read
->rd_fhp
->fh_dentry
->d_inode
->i_size
);
3044 resp
->xbuf
->head
[0].iov_len
= (char*)p
3045 - (char*)resp
->xbuf
->head
[0].iov_base
;
3046 resp
->xbuf
->page_len
= maxcount
;
3048 /* Use rest of head for padding and remaining ops: */
3049 resp
->xbuf
->tail
[0].iov_base
= p
;
3050 resp
->xbuf
->tail
[0].iov_len
= 0;
3054 resp
->xbuf
->tail
[0].iov_base
+= maxcount
&3;
3055 resp
->xbuf
->tail
[0].iov_len
= 4 - (maxcount
&3);
3062 nfsd4_encode_readlink(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readlink
*readlink
)
3070 if (resp
->xbuf
->page_len
)
3071 return nfserr_resource
;
3072 if (!*resp
->rqstp
->rq_next_page
)
3073 return nfserr_resource
;
3075 page
= page_address(*(resp
->rqstp
->rq_next_page
++));
3077 maxcount
= PAGE_SIZE
;
3081 * XXX: By default, the ->readlink() VFS op will truncate symlinks
3082 * if they would overflow the buffer. Is this kosher in NFSv4? If
3083 * not, one easy fix is: if ->readlink() precisely fills the buffer,
3084 * assume that truncation occurred, and return NFS4ERR_RESOURCE.
3086 nfserr
= nfsd_readlink(readlink
->rl_rqstp
, readlink
->rl_fhp
, page
, &maxcount
);
3087 if (nfserr
== nfserr_isdir
)
3088 return nfserr_inval
;
3094 resp
->xbuf
->head
[0].iov_len
= (char*)p
3095 - (char*)resp
->xbuf
->head
[0].iov_base
;
3096 resp
->xbuf
->page_len
= maxcount
;
3098 /* Use rest of head for padding and remaining ops: */
3099 resp
->xbuf
->tail
[0].iov_base
= p
;
3100 resp
->xbuf
->tail
[0].iov_len
= 0;
3104 resp
->xbuf
->tail
[0].iov_base
+= maxcount
&3;
3105 resp
->xbuf
->tail
[0].iov_len
= 4 - (maxcount
&3);
3112 nfsd4_encode_readdir(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readdir
*readdir
)
3116 __be32
*page
, *savep
, *tailbase
;
3121 if (resp
->xbuf
->page_len
)
3122 return nfserr_resource
;
3123 if (!*resp
->rqstp
->rq_next_page
)
3124 return nfserr_resource
;
3126 RESERVE_SPACE(NFS4_VERIFIER_SIZE
);
3129 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
3133 resp
->xbuf
->head
[0].iov_len
= ((char*)resp
->p
) - (char*)resp
->xbuf
->head
[0].iov_base
;
3136 maxcount
= PAGE_SIZE
;
3137 if (maxcount
> readdir
->rd_maxcount
)
3138 maxcount
= readdir
->rd_maxcount
;
3141 * Convert from bytes to words, account for the two words already
3142 * written, make sure to leave two words at the end for the next
3143 * pointer and eof field.
3145 maxcount
= (maxcount
>> 2) - 4;
3147 nfserr
= nfserr_toosmall
;
3151 page
= page_address(*(resp
->rqstp
->rq_next_page
++));
3152 readdir
->common
.err
= 0;
3153 readdir
->buflen
= maxcount
;
3154 readdir
->buffer
= page
;
3155 readdir
->offset
= NULL
;
3157 offset
= readdir
->rd_cookie
;
3158 nfserr
= nfsd_readdir(readdir
->rd_rqstp
, readdir
->rd_fhp
,
3160 &readdir
->common
, nfsd4_encode_dirent
);
3161 if (nfserr
== nfs_ok
&&
3162 readdir
->common
.err
== nfserr_toosmall
&&
3163 readdir
->buffer
== page
)
3164 nfserr
= nfserr_toosmall
;
3168 if (readdir
->offset
)
3169 xdr_encode_hyper(readdir
->offset
, offset
);
3171 p
= readdir
->buffer
;
3172 *p
++ = 0; /* no more entries */
3173 *p
++ = htonl(readdir
->common
.err
== nfserr_eof
);
3174 resp
->xbuf
->page_len
= ((char*)p
) -
3175 (char*)page_address(*(resp
->rqstp
->rq_next_page
-1));
3177 /* Use rest of head for padding and remaining ops: */
3178 resp
->xbuf
->tail
[0].iov_base
= tailbase
;
3179 resp
->xbuf
->tail
[0].iov_len
= 0;
3180 resp
->p
= resp
->xbuf
->tail
[0].iov_base
;
3181 resp
->end
= resp
->p
+ (PAGE_SIZE
- resp
->xbuf
->head
[0].iov_len
)/4;
3191 nfsd4_encode_remove(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_remove
*remove
)
3197 write_cinfo(&p
, &remove
->rm_cinfo
);
3204 nfsd4_encode_rename(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_rename
*rename
)
3210 write_cinfo(&p
, &rename
->rn_sinfo
);
3211 write_cinfo(&p
, &rename
->rn_tinfo
);
3218 nfsd4_do_encode_secinfo(struct nfsd4_compoundres
*resp
,
3219 __be32 nfserr
, struct svc_export
*exp
)
3221 u32 i
, nflavs
, supported
;
3222 struct exp_flavor_info
*flavs
;
3223 struct exp_flavor_info def_flavs
[2];
3224 __be32
*p
, *flavorsp
;
3225 static bool report
= true;
3229 if (exp
->ex_nflavors
) {
3230 flavs
= exp
->ex_flavors
;
3231 nflavs
= exp
->ex_nflavors
;
3232 } else { /* Handling of some defaults in absence of real secinfo: */
3234 if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_UNIX
) {
3236 flavs
[0].pseudoflavor
= RPC_AUTH_UNIX
;
3237 flavs
[1].pseudoflavor
= RPC_AUTH_NULL
;
3238 } else if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_GSS
) {
3240 flavs
[0].pseudoflavor
3241 = svcauth_gss_flavor(exp
->ex_client
);
3244 flavs
[0].pseudoflavor
3245 = exp
->ex_client
->flavour
->flavour
;
3251 flavorsp
= p
++; /* to be backfilled later */
3254 for (i
= 0; i
< nflavs
; i
++) {
3255 rpc_authflavor_t pf
= flavs
[i
].pseudoflavor
;
3256 struct rpcsec_gss_info info
;
3258 if (rpcauth_get_gssinfo(pf
, &info
) == 0) {
3260 RESERVE_SPACE(4 + 4 + XDR_LEN(info
.oid
.len
) + 4 + 4);
3261 WRITE32(RPC_AUTH_GSS
);
3262 WRITE32(info
.oid
.len
);
3263 WRITEMEM(info
.oid
.data
, info
.oid
.len
);
3265 WRITE32(info
.service
);
3267 } else if (pf
< RPC_AUTH_MAXFLAVOR
) {
3274 pr_warn("NFS: SECINFO: security flavor %u "
3275 "is not supported\n", pf
);
3279 if (nflavs
!= supported
)
3281 *flavorsp
= htonl(supported
);
3290 nfsd4_encode_secinfo(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
3291 struct nfsd4_secinfo
*secinfo
)
3293 return nfsd4_do_encode_secinfo(resp
, nfserr
, secinfo
->si_exp
);
3297 nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
3298 struct nfsd4_secinfo_no_name
*secinfo
)
3300 return nfsd4_do_encode_secinfo(resp
, nfserr
, secinfo
->sin_exp
);
3304 * The SETATTR encode routine is special -- it always encodes a bitmap,
3305 * regardless of the error status.
3308 nfsd4_encode_setattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setattr
*setattr
)
3321 WRITE32(setattr
->sa_bmval
[0]);
3322 WRITE32(setattr
->sa_bmval
[1]);
3323 WRITE32(setattr
->sa_bmval
[2]);
3330 nfsd4_encode_setclientid(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setclientid
*scd
)
3335 RESERVE_SPACE(8 + NFS4_VERIFIER_SIZE
);
3336 WRITEMEM(&scd
->se_clientid
, 8);
3337 WRITEMEM(&scd
->se_confirm
, NFS4_VERIFIER_SIZE
);
3340 else if (nfserr
== nfserr_clid_inuse
) {
3350 nfsd4_encode_write(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_write
*write
)
3356 WRITE32(write
->wr_bytes_written
);
3357 WRITE32(write
->wr_how_written
);
3358 WRITEMEM(write
->wr_verifier
.data
, NFS4_VERIFIER_SIZE
);
3364 static const u32 nfs4_minimal_spo_must_enforce
[2] = {
3365 [1] = 1 << (OP_BIND_CONN_TO_SESSION
- 32) |
3366 1 << (OP_EXCHANGE_ID
- 32) |
3367 1 << (OP_CREATE_SESSION
- 32) |
3368 1 << (OP_DESTROY_SESSION
- 32) |
3369 1 << (OP_DESTROY_CLIENTID
- 32)
3373 nfsd4_encode_exchange_id(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
3374 struct nfsd4_exchange_id
*exid
)
3380 int server_scope_sz
;
3381 uint64_t minor_id
= 0;
3386 major_id
= utsname()->nodename
;
3387 major_id_sz
= strlen(major_id
);
3388 server_scope
= utsname()->nodename
;
3389 server_scope_sz
= strlen(server_scope
);
3392 8 /* eir_clientid */ +
3393 4 /* eir_sequenceid */ +
3397 WRITEMEM(&exid
->clientid
, 8);
3398 WRITE32(exid
->seqid
);
3399 WRITE32(exid
->flags
);
3401 WRITE32(exid
->spa_how
);
3404 switch (exid
->spa_how
) {
3408 /* spo_must_enforce, spo_must_allow */
3411 /* spo_must_enforce bitmap: */
3413 WRITE32(nfs4_minimal_spo_must_enforce
[0]);
3414 WRITE32(nfs4_minimal_spo_must_enforce
[1]);
3415 /* empty spo_must_allow bitmap: */
3425 8 /* so_minor_id */ +
3426 4 /* so_major_id.len */ +
3427 (XDR_QUADLEN(major_id_sz
) * 4) +
3428 4 /* eir_server_scope.len */ +
3429 (XDR_QUADLEN(server_scope_sz
) * 4) +
3430 4 /* eir_server_impl_id.count (0) */);
3432 /* The server_owner struct */
3433 WRITE64(minor_id
); /* Minor id */
3435 WRITE32(major_id_sz
);
3436 WRITEMEM(major_id
, major_id_sz
);
3439 WRITE32(server_scope_sz
);
3440 WRITEMEM(server_scope
, server_scope_sz
);
3442 /* Implementation id */
3443 WRITE32(0); /* zero length nfs_impl_id4 array */
3449 nfsd4_encode_create_session(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
3450 struct nfsd4_create_session
*sess
)
3458 WRITEMEM(sess
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
3459 WRITE32(sess
->seqid
);
3460 WRITE32(sess
->flags
);
3464 WRITE32(0); /* headerpadsz */
3465 WRITE32(sess
->fore_channel
.maxreq_sz
);
3466 WRITE32(sess
->fore_channel
.maxresp_sz
);
3467 WRITE32(sess
->fore_channel
.maxresp_cached
);
3468 WRITE32(sess
->fore_channel
.maxops
);
3469 WRITE32(sess
->fore_channel
.maxreqs
);
3470 WRITE32(sess
->fore_channel
.nr_rdma_attrs
);
3473 if (sess
->fore_channel
.nr_rdma_attrs
) {
3475 WRITE32(sess
->fore_channel
.rdma_attrs
);
3480 WRITE32(0); /* headerpadsz */
3481 WRITE32(sess
->back_channel
.maxreq_sz
);
3482 WRITE32(sess
->back_channel
.maxresp_sz
);
3483 WRITE32(sess
->back_channel
.maxresp_cached
);
3484 WRITE32(sess
->back_channel
.maxops
);
3485 WRITE32(sess
->back_channel
.maxreqs
);
3486 WRITE32(sess
->back_channel
.nr_rdma_attrs
);
3489 if (sess
->back_channel
.nr_rdma_attrs
) {
3491 WRITE32(sess
->back_channel
.rdma_attrs
);
3498 nfsd4_encode_sequence(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
3499 struct nfsd4_sequence
*seq
)
3506 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN
+ 20);
3507 WRITEMEM(seq
->sessionid
.data
, NFS4_MAX_SESSIONID_LEN
);
3508 WRITE32(seq
->seqid
);
3509 WRITE32(seq
->slotid
);
3510 /* Note slotid's are numbered from zero: */
3511 WRITE32(seq
->maxslots
- 1); /* sr_highest_slotid */
3512 WRITE32(seq
->maxslots
- 1); /* sr_target_highest_slotid */
3513 WRITE32(seq
->status_flags
);
3516 resp
->cstate
.datap
= p
; /* DRC cache data pointer */
3521 nfsd4_encode_test_stateid(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
3522 struct nfsd4_test_stateid
*test_stateid
)
3524 struct nfsd4_test_stateid_id
*stateid
, *next
;
3527 RESERVE_SPACE(4 + (4 * test_stateid
->ts_num_ids
));
3528 *p
++ = htonl(test_stateid
->ts_num_ids
);
3530 list_for_each_entry_safe(stateid
, next
, &test_stateid
->ts_stateid_list
, ts_id_list
) {
3531 *p
++ = stateid
->ts_id_status
;
3539 nfsd4_encode_noop(struct nfsd4_compoundres
*resp
, __be32 nfserr
, void *p
)
3544 typedef __be32(* nfsd4_enc
)(struct nfsd4_compoundres
*, __be32
, void *);
3547 * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
3548 * since we don't need to filter out obsolete ops as this is
3549 * done in the decoding phase.
3551 static nfsd4_enc nfsd4_enc_ops
[] = {
3552 [OP_ACCESS
] = (nfsd4_enc
)nfsd4_encode_access
,
3553 [OP_CLOSE
] = (nfsd4_enc
)nfsd4_encode_close
,
3554 [OP_COMMIT
] = (nfsd4_enc
)nfsd4_encode_commit
,
3555 [OP_CREATE
] = (nfsd4_enc
)nfsd4_encode_create
,
3556 [OP_DELEGPURGE
] = (nfsd4_enc
)nfsd4_encode_noop
,
3557 [OP_DELEGRETURN
] = (nfsd4_enc
)nfsd4_encode_noop
,
3558 [OP_GETATTR
] = (nfsd4_enc
)nfsd4_encode_getattr
,
3559 [OP_GETFH
] = (nfsd4_enc
)nfsd4_encode_getfh
,
3560 [OP_LINK
] = (nfsd4_enc
)nfsd4_encode_link
,
3561 [OP_LOCK
] = (nfsd4_enc
)nfsd4_encode_lock
,
3562 [OP_LOCKT
] = (nfsd4_enc
)nfsd4_encode_lockt
,
3563 [OP_LOCKU
] = (nfsd4_enc
)nfsd4_encode_locku
,
3564 [OP_LOOKUP
] = (nfsd4_enc
)nfsd4_encode_noop
,
3565 [OP_LOOKUPP
] = (nfsd4_enc
)nfsd4_encode_noop
,
3566 [OP_NVERIFY
] = (nfsd4_enc
)nfsd4_encode_noop
,
3567 [OP_OPEN
] = (nfsd4_enc
)nfsd4_encode_open
,
3568 [OP_OPENATTR
] = (nfsd4_enc
)nfsd4_encode_noop
,
3569 [OP_OPEN_CONFIRM
] = (nfsd4_enc
)nfsd4_encode_open_confirm
,
3570 [OP_OPEN_DOWNGRADE
] = (nfsd4_enc
)nfsd4_encode_open_downgrade
,
3571 [OP_PUTFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
3572 [OP_PUTPUBFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
3573 [OP_PUTROOTFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
3574 [OP_READ
] = (nfsd4_enc
)nfsd4_encode_read
,
3575 [OP_READDIR
] = (nfsd4_enc
)nfsd4_encode_readdir
,
3576 [OP_READLINK
] = (nfsd4_enc
)nfsd4_encode_readlink
,
3577 [OP_REMOVE
] = (nfsd4_enc
)nfsd4_encode_remove
,
3578 [OP_RENAME
] = (nfsd4_enc
)nfsd4_encode_rename
,
3579 [OP_RENEW
] = (nfsd4_enc
)nfsd4_encode_noop
,
3580 [OP_RESTOREFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
3581 [OP_SAVEFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
3582 [OP_SECINFO
] = (nfsd4_enc
)nfsd4_encode_secinfo
,
3583 [OP_SETATTR
] = (nfsd4_enc
)nfsd4_encode_setattr
,
3584 [OP_SETCLIENTID
] = (nfsd4_enc
)nfsd4_encode_setclientid
,
3585 [OP_SETCLIENTID_CONFIRM
] = (nfsd4_enc
)nfsd4_encode_noop
,
3586 [OP_VERIFY
] = (nfsd4_enc
)nfsd4_encode_noop
,
3587 [OP_WRITE
] = (nfsd4_enc
)nfsd4_encode_write
,
3588 [OP_RELEASE_LOCKOWNER
] = (nfsd4_enc
)nfsd4_encode_noop
,
3590 /* NFSv4.1 operations */
3591 [OP_BACKCHANNEL_CTL
] = (nfsd4_enc
)nfsd4_encode_noop
,
3592 [OP_BIND_CONN_TO_SESSION
] = (nfsd4_enc
)nfsd4_encode_bind_conn_to_session
,
3593 [OP_EXCHANGE_ID
] = (nfsd4_enc
)nfsd4_encode_exchange_id
,
3594 [OP_CREATE_SESSION
] = (nfsd4_enc
)nfsd4_encode_create_session
,
3595 [OP_DESTROY_SESSION
] = (nfsd4_enc
)nfsd4_encode_noop
,
3596 [OP_FREE_STATEID
] = (nfsd4_enc
)nfsd4_encode_noop
,
3597 [OP_GET_DIR_DELEGATION
] = (nfsd4_enc
)nfsd4_encode_noop
,
3598 [OP_GETDEVICEINFO
] = (nfsd4_enc
)nfsd4_encode_noop
,
3599 [OP_GETDEVICELIST
] = (nfsd4_enc
)nfsd4_encode_noop
,
3600 [OP_LAYOUTCOMMIT
] = (nfsd4_enc
)nfsd4_encode_noop
,
3601 [OP_LAYOUTGET
] = (nfsd4_enc
)nfsd4_encode_noop
,
3602 [OP_LAYOUTRETURN
] = (nfsd4_enc
)nfsd4_encode_noop
,
3603 [OP_SECINFO_NO_NAME
] = (nfsd4_enc
)nfsd4_encode_secinfo_no_name
,
3604 [OP_SEQUENCE
] = (nfsd4_enc
)nfsd4_encode_sequence
,
3605 [OP_SET_SSV
] = (nfsd4_enc
)nfsd4_encode_noop
,
3606 [OP_TEST_STATEID
] = (nfsd4_enc
)nfsd4_encode_test_stateid
,
3607 [OP_WANT_DELEGATION
] = (nfsd4_enc
)nfsd4_encode_noop
,
3608 [OP_DESTROY_CLIENTID
] = (nfsd4_enc
)nfsd4_encode_noop
,
3609 [OP_RECLAIM_COMPLETE
] = (nfsd4_enc
)nfsd4_encode_noop
,
3613 * Calculate the total amount of memory that the compound response has taken
3614 * after encoding the current operation with pad.
3616 * pad: if operation is non-idempotent, pad was calculate by op_rsize_bop()
3617 * which was specified at nfsd4_operation, else pad is zero.
3619 * Compare this length to the session se_fmaxresp_sz and se_fmaxresp_cached.
3621 * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
3622 * will be at least a page and will therefore hold the xdr_buf head.
3624 __be32
nfsd4_check_resp_size(struct nfsd4_compoundres
*resp
, u32 pad
)
3626 struct xdr_buf
*xb
= &resp
->rqstp
->rq_res
;
3627 struct nfsd4_session
*session
= NULL
;
3628 struct nfsd4_slot
*slot
= resp
->cstate
.slot
;
3629 u32 length
, tlen
= 0;
3631 if (!nfsd4_has_session(&resp
->cstate
))
3634 session
= resp
->cstate
.session
;
3635 if (session
== NULL
)
3638 if (xb
->page_len
== 0) {
3639 length
= (char *)resp
->p
- (char *)xb
->head
[0].iov_base
+ pad
;
3641 if (xb
->tail
[0].iov_base
&& xb
->tail
[0].iov_len
> 0)
3642 tlen
= (char *)resp
->p
- (char *)xb
->tail
[0].iov_base
;
3644 length
= xb
->head
[0].iov_len
+ xb
->page_len
+ tlen
+ pad
;
3646 dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__
,
3647 length
, xb
->page_len
, tlen
, pad
);
3649 if (length
> session
->se_fchannel
.maxresp_sz
)
3650 return nfserr_rep_too_big
;
3652 if ((slot
->sl_flags
& NFSD4_SLOT_CACHETHIS
) &&
3653 length
> session
->se_fchannel
.maxresp_cached
)
3654 return nfserr_rep_too_big_to_cache
;
3660 nfsd4_encode_operation(struct nfsd4_compoundres
*resp
, struct nfsd4_op
*op
)
3662 struct nfs4_stateowner
*so
= resp
->cstate
.replay_owner
;
3668 statp
= p
++; /* to be backfilled at the end */
3671 if (op
->opnum
== OP_ILLEGAL
)
3673 BUG_ON(op
->opnum
< 0 || op
->opnum
>= ARRAY_SIZE(nfsd4_enc_ops
) ||
3674 !nfsd4_enc_ops
[op
->opnum
]);
3675 op
->status
= nfsd4_enc_ops
[op
->opnum
](resp
, op
->status
, &op
->u
);
3676 /* nfsd4_check_drc_limit guarantees enough room for error status */
3678 op
->status
= nfsd4_check_resp_size(resp
, 0);
3680 so
->so_replay
.rp_status
= op
->status
;
3681 so
->so_replay
.rp_buflen
= (char *)resp
->p
- (char *)(statp
+1);
3682 memcpy(so
->so_replay
.rp_buf
, statp
+1, so
->so_replay
.rp_buflen
);
3686 * Note: We write the status directly, instead of using WRITE32(),
3687 * since it is already in network byte order.
3689 *statp
= op
->status
;
3693 * Encode the reply stored in the stateowner reply cache
3695 * XDR note: do not encode rp->rp_buflen: the buffer contains the
3696 * previously sent already encoded operation.
3698 * called with nfs4_lock_state() held
3701 nfsd4_encode_replay(struct nfsd4_compoundres
*resp
, struct nfsd4_op
*op
)
3704 struct nfs4_replay
*rp
= op
->replay
;
3710 *p
++ = rp
->rp_status
; /* already xdr'ed */
3713 RESERVE_SPACE(rp
->rp_buflen
);
3714 WRITEMEM(rp
->rp_buf
, rp
->rp_buflen
);
3719 nfs4svc_encode_voidres(struct svc_rqst
*rqstp
, __be32
*p
, void *dummy
)
3721 return xdr_ressize_check(rqstp
, p
);
3724 int nfsd4_release_compoundargs(void *rq
, __be32
*p
, void *resp
)
3726 struct svc_rqst
*rqstp
= rq
;
3727 struct nfsd4_compoundargs
*args
= rqstp
->rq_argp
;
3729 if (args
->ops
!= args
->iops
) {
3731 args
->ops
= args
->iops
;
3735 while (args
->to_free
) {
3736 struct tmpbuf
*tb
= args
->to_free
;
3737 args
->to_free
= tb
->next
;
3738 tb
->release(tb
->buf
);
3745 nfs4svc_decode_compoundargs(struct svc_rqst
*rqstp
, __be32
*p
, struct nfsd4_compoundargs
*args
)
3748 args
->end
= rqstp
->rq_arg
.head
[0].iov_base
+ rqstp
->rq_arg
.head
[0].iov_len
;
3749 args
->pagelist
= rqstp
->rq_arg
.pages
;
3750 args
->pagelen
= rqstp
->rq_arg
.page_len
;
3752 args
->to_free
= NULL
;
3753 args
->ops
= args
->iops
;
3754 args
->rqstp
= rqstp
;
3756 return !nfsd4_decode_compound(args
);
3760 nfs4svc_encode_compoundres(struct svc_rqst
*rqstp
, __be32
*p
, struct nfsd4_compoundres
*resp
)
3763 * All that remains is to write the tag and operation count...
3765 struct nfsd4_compound_state
*cs
= &resp
->cstate
;
3768 *p
++ = htonl(resp
->taglen
);
3769 memcpy(p
, resp
->tag
, resp
->taglen
);
3770 p
+= XDR_QUADLEN(resp
->taglen
);
3771 *p
++ = htonl(resp
->opcnt
);
3773 if (rqstp
->rq_res
.page_len
)
3774 iov
= &rqstp
->rq_res
.tail
[0];
3776 iov
= &rqstp
->rq_res
.head
[0];
3777 iov
->iov_len
= ((char*)resp
->p
) - (char*)iov
->iov_base
;
3778 BUG_ON(iov
->iov_len
> PAGE_SIZE
);
3779 if (nfsd4_has_session(cs
)) {
3780 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
3781 struct nfs4_client
*clp
= cs
->session
->se_client
;
3782 if (cs
->status
!= nfserr_replay_cache
) {
3783 nfsd4_store_cache_entry(resp
);
3784 cs
->slot
->sl_flags
&= ~NFSD4_SLOT_INUSE
;
3786 /* Renew the clientid on success and on replay */
3787 spin_lock(&nn
->client_lock
);
3788 nfsd4_put_session(cs
->session
);
3789 spin_unlock(&nn
->client_lock
);
3790 put_client_renew(clp
);