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.
36 #include <linux/file.h>
37 #include <linux/slab.h>
38 #include <linux/namei.h>
39 #include <linux/statfs.h>
40 #include <linux/utsname.h>
41 #include <linux/pagemap.h>
42 #include <linux/sunrpc/svcauth_gss.h>
43 #include <linux/sunrpc/addr.h>
44 #include <linux/xattr.h>
45 #include <uapi/linux/xattr.h>
55 #include "filecache.h"
59 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
60 #include <linux/security.h>
64 #define NFSDDBG_FACILITY NFSDDBG_XDR
66 const u32 nfsd_suppattrs
[3][3] = {
67 {NFSD4_SUPPORTED_ATTRS_WORD0
,
68 NFSD4_SUPPORTED_ATTRS_WORD1
,
69 NFSD4_SUPPORTED_ATTRS_WORD2
},
71 {NFSD4_1_SUPPORTED_ATTRS_WORD0
,
72 NFSD4_1_SUPPORTED_ATTRS_WORD1
,
73 NFSD4_1_SUPPORTED_ATTRS_WORD2
},
75 {NFSD4_1_SUPPORTED_ATTRS_WORD0
,
76 NFSD4_1_SUPPORTED_ATTRS_WORD1
,
77 NFSD4_2_SUPPORTED_ATTRS_WORD2
},
81 * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
82 * directory in order to indicate to the client that a filesystem boundary is present
83 * We use a fixed fsid for a referral
85 #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
86 #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
89 check_filename(char *str
, int len
)
95 if (len
> NFS4_MAXNAMLEN
)
96 return nfserr_nametoolong
;
97 if (isdotent(str
, len
))
98 return nfserr_badname
;
99 for (i
= 0; i
< len
; i
++)
101 return nfserr_badname
;
105 static int zero_clientid(clientid_t
*clid
)
107 return (clid
->cl_boot
== 0) && (clid
->cl_id
== 0);
111 * svcxdr_tmpalloc - allocate memory to be freed after compound processing
112 * @argp: NFSv4 compound argument structure
113 * @len: length of buffer to allocate
115 * Allocates a buffer of size @len to be freed when processing the compound
116 * operation described in @argp finishes.
119 svcxdr_tmpalloc(struct nfsd4_compoundargs
*argp
, u32 len
)
121 struct svcxdr_tmpbuf
*tb
;
123 tb
= kmalloc(sizeof(*tb
) + len
, GFP_KERNEL
);
126 tb
->next
= argp
->to_free
;
132 * For xdr strings that need to be passed to other kernel api's
133 * as null-terminated strings.
135 * Note null-terminating in place usually isn't safe since the
136 * buffer might end on a page boundary.
139 svcxdr_dupstr(struct nfsd4_compoundargs
*argp
, void *buf
, u32 len
)
141 char *p
= svcxdr_tmpalloc(argp
, len
+ 1);
151 * NFSv4 basic data type decoders
155 * This helper handles variable-length opaques which belong to protocol
156 * elements that this implementation does not support.
159 nfsd4_decode_ignored_string(struct nfsd4_compoundargs
*argp
, u32 maxlen
)
163 if (xdr_stream_decode_u32(argp
->xdr
, &len
) < 0)
164 return nfserr_bad_xdr
;
165 if (maxlen
&& len
> maxlen
)
166 return nfserr_bad_xdr
;
167 if (!xdr_inline_decode(argp
->xdr
, len
))
168 return nfserr_bad_xdr
;
174 nfsd4_decode_opaque(struct nfsd4_compoundargs
*argp
, struct xdr_netobj
*o
)
179 if (xdr_stream_decode_u32(argp
->xdr
, &len
) < 0)
180 return nfserr_bad_xdr
;
181 if (len
== 0 || len
> NFS4_OPAQUE_LIMIT
)
182 return nfserr_bad_xdr
;
183 p
= xdr_inline_decode(argp
->xdr
, len
);
185 return nfserr_bad_xdr
;
186 o
->data
= svcxdr_tmpalloc(argp
, len
);
188 return nfserr_jukebox
;
190 memcpy(o
->data
, p
, len
);
196 nfsd4_decode_component4(struct nfsd4_compoundargs
*argp
, char **namp
, u32
*lenp
)
200 if (xdr_stream_decode_u32(argp
->xdr
, lenp
) < 0)
201 return nfserr_bad_xdr
;
202 p
= xdr_inline_decode(argp
->xdr
, *lenp
);
204 return nfserr_bad_xdr
;
205 status
= check_filename((char *)p
, *lenp
);
208 *namp
= svcxdr_tmpalloc(argp
, *lenp
);
210 return nfserr_jukebox
;
211 memcpy(*namp
, p
, *lenp
);
217 nfsd4_decode_nfstime4(struct nfsd4_compoundargs
*argp
, struct timespec64
*tv
)
221 p
= xdr_inline_decode(argp
->xdr
, XDR_UNIT
* 3);
223 return nfserr_bad_xdr
;
224 p
= xdr_decode_hyper(p
, &tv
->tv_sec
);
225 tv
->tv_nsec
= be32_to_cpup(p
++);
226 if (tv
->tv_nsec
>= (u32
)1000000000)
232 nfsd4_decode_verifier4(struct nfsd4_compoundargs
*argp
, nfs4_verifier
*verf
)
236 p
= xdr_inline_decode(argp
->xdr
, NFS4_VERIFIER_SIZE
);
238 return nfserr_bad_xdr
;
239 memcpy(verf
->data
, p
, sizeof(verf
->data
));
244 * nfsd4_decode_bitmap4 - Decode an NFSv4 bitmap4
245 * @argp: NFSv4 compound argument structure
246 * @bmval: pointer to an array of u32's to decode into
247 * @bmlen: size of the @bmval array
249 * The server needs to return nfs_ok rather than nfserr_bad_xdr when
250 * encountering bitmaps containing bits it does not recognize. This
251 * includes bits in bitmap words past WORDn, where WORDn is the last
252 * bitmap WORD the implementation currently supports. Thus we are
253 * careful here to simply ignore bits in bitmap words that this
254 * implementation has yet to support explicitly.
257 * %nfs_ok: @bmval populated successfully
258 * %nfserr_bad_xdr: the encoded bitmap was invalid
261 nfsd4_decode_bitmap4(struct nfsd4_compoundargs
*argp
, u32
*bmval
, u32 bmlen
)
266 if (xdr_stream_decode_u32(argp
->xdr
, &count
) < 0)
267 return nfserr_bad_xdr
;
270 return nfserr_bad_xdr
;
271 p
= xdr_inline_decode(argp
->xdr
, count
<< 2);
273 return nfserr_bad_xdr
;
276 bmval
[i
++] = be32_to_cpup(p
++);
284 nfsd4_decode_nfsace4(struct nfsd4_compoundargs
*argp
, struct nfs4_ace
*ace
)
289 if (xdr_stream_decode_u32(argp
->xdr
, &ace
->type
) < 0)
290 return nfserr_bad_xdr
;
291 if (xdr_stream_decode_u32(argp
->xdr
, &ace
->flag
) < 0)
292 return nfserr_bad_xdr
;
293 if (xdr_stream_decode_u32(argp
->xdr
, &ace
->access_mask
) < 0)
294 return nfserr_bad_xdr
;
296 if (xdr_stream_decode_u32(argp
->xdr
, &length
) < 0)
297 return nfserr_bad_xdr
;
298 p
= xdr_inline_decode(argp
->xdr
, length
);
300 return nfserr_bad_xdr
;
301 ace
->whotype
= nfs4_acl_get_whotype((char *)p
, length
);
302 if (ace
->whotype
!= NFS4_ACL_WHO_NAMED
)
304 else if (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
)
305 status
= nfsd_map_name_to_gid(argp
->rqstp
,
306 (char *)p
, length
, &ace
->who_gid
);
308 status
= nfsd_map_name_to_uid(argp
->rqstp
,
309 (char *)p
, length
, &ace
->who_uid
);
314 /* A counted array of nfsace4's */
315 static noinline __be32
316 nfsd4_decode_acl(struct nfsd4_compoundargs
*argp
, struct nfs4_acl
**acl
)
318 struct nfs4_ace
*ace
;
322 if (xdr_stream_decode_u32(argp
->xdr
, &count
) < 0)
323 return nfserr_bad_xdr
;
325 if (count
> xdr_stream_remaining(argp
->xdr
) / 20)
327 * Even with 4-byte names there wouldn't be
328 * space for that many aces; something fishy is
333 *acl
= svcxdr_tmpalloc(argp
, nfs4_acl_bytes(count
));
335 return nfserr_jukebox
;
337 (*acl
)->naces
= count
;
338 for (ace
= (*acl
)->aces
; ace
< (*acl
)->aces
+ count
; ace
++) {
339 status
= nfsd4_decode_nfsace4(argp
, ace
);
347 static noinline __be32
348 nfsd4_decode_security_label(struct nfsd4_compoundargs
*argp
,
349 struct xdr_netobj
*label
)
354 if (xdr_stream_decode_u32(argp
->xdr
, &lfs
) < 0)
355 return nfserr_bad_xdr
;
356 if (xdr_stream_decode_u32(argp
->xdr
, &pi
) < 0)
357 return nfserr_bad_xdr
;
359 if (xdr_stream_decode_u32(argp
->xdr
, &length
) < 0)
360 return nfserr_bad_xdr
;
361 if (length
> NFS4_MAXLABELLEN
)
362 return nfserr_badlabel
;
363 p
= xdr_inline_decode(argp
->xdr
, length
);
365 return nfserr_bad_xdr
;
367 label
->data
= svcxdr_dupstr(argp
, p
, length
);
369 return nfserr_jukebox
;
375 nfsd4_decode_fattr4(struct nfsd4_compoundargs
*argp
, u32
*bmval
, u32 bmlen
,
376 struct iattr
*iattr
, struct nfs4_acl
**acl
,
377 struct xdr_netobj
*label
, int *umask
)
379 unsigned int starting_pos
;
384 status
= nfsd4_decode_bitmap4(argp
, bmval
, bmlen
);
386 return nfserr_bad_xdr
;
388 if (bmval
[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
389 || bmval
[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
390 || bmval
[2] & ~NFSD_WRITEABLE_ATTRS_WORD2
) {
391 if (nfsd_attrs_supported(argp
->minorversion
, bmval
))
393 return nfserr_attrnotsupp
;
396 if (xdr_stream_decode_u32(argp
->xdr
, &attrlist4_count
) < 0)
397 return nfserr_bad_xdr
;
398 starting_pos
= xdr_stream_pos(argp
->xdr
);
400 if (bmval
[0] & FATTR4_WORD0_SIZE
) {
403 if (xdr_stream_decode_u64(argp
->xdr
, &size
) < 0)
404 return nfserr_bad_xdr
;
405 iattr
->ia_size
= size
;
406 iattr
->ia_valid
|= ATTR_SIZE
;
408 if (bmval
[0] & FATTR4_WORD0_ACL
) {
409 status
= nfsd4_decode_acl(argp
, acl
);
414 if (bmval
[1] & FATTR4_WORD1_MODE
) {
417 if (xdr_stream_decode_u32(argp
->xdr
, &mode
) < 0)
418 return nfserr_bad_xdr
;
419 iattr
->ia_mode
= mode
;
420 iattr
->ia_mode
&= (S_IFMT
| S_IALLUGO
);
421 iattr
->ia_valid
|= ATTR_MODE
;
423 if (bmval
[1] & FATTR4_WORD1_OWNER
) {
426 if (xdr_stream_decode_u32(argp
->xdr
, &length
) < 0)
427 return nfserr_bad_xdr
;
428 p
= xdr_inline_decode(argp
->xdr
, length
);
430 return nfserr_bad_xdr
;
431 status
= nfsd_map_name_to_uid(argp
->rqstp
, (char *)p
, length
,
435 iattr
->ia_valid
|= ATTR_UID
;
437 if (bmval
[1] & FATTR4_WORD1_OWNER_GROUP
) {
440 if (xdr_stream_decode_u32(argp
->xdr
, &length
) < 0)
441 return nfserr_bad_xdr
;
442 p
= xdr_inline_decode(argp
->xdr
, length
);
444 return nfserr_bad_xdr
;
445 status
= nfsd_map_name_to_gid(argp
->rqstp
, (char *)p
, length
,
449 iattr
->ia_valid
|= ATTR_GID
;
451 if (bmval
[1] & FATTR4_WORD1_TIME_ACCESS_SET
) {
454 if (xdr_stream_decode_u32(argp
->xdr
, &set_it
) < 0)
455 return nfserr_bad_xdr
;
457 case NFS4_SET_TO_CLIENT_TIME
:
458 status
= nfsd4_decode_nfstime4(argp
, &iattr
->ia_atime
);
461 iattr
->ia_valid
|= (ATTR_ATIME
| ATTR_ATIME_SET
);
463 case NFS4_SET_TO_SERVER_TIME
:
464 iattr
->ia_valid
|= ATTR_ATIME
;
467 return nfserr_bad_xdr
;
470 if (bmval
[1] & FATTR4_WORD1_TIME_MODIFY_SET
) {
473 if (xdr_stream_decode_u32(argp
->xdr
, &set_it
) < 0)
474 return nfserr_bad_xdr
;
476 case NFS4_SET_TO_CLIENT_TIME
:
477 status
= nfsd4_decode_nfstime4(argp
, &iattr
->ia_mtime
);
480 iattr
->ia_valid
|= (ATTR_MTIME
| ATTR_MTIME_SET
);
482 case NFS4_SET_TO_SERVER_TIME
:
483 iattr
->ia_valid
|= ATTR_MTIME
;
486 return nfserr_bad_xdr
;
490 if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL
) &&
491 bmval
[2] & FATTR4_WORD2_SECURITY_LABEL
) {
492 status
= nfsd4_decode_security_label(argp
, label
);
496 if (bmval
[2] & FATTR4_WORD2_MODE_UMASK
) {
500 return nfserr_bad_xdr
;
501 if (xdr_stream_decode_u32(argp
->xdr
, &mode
) < 0)
502 return nfserr_bad_xdr
;
503 iattr
->ia_mode
= mode
& (S_IFMT
| S_IALLUGO
);
504 if (xdr_stream_decode_u32(argp
->xdr
, &mask
) < 0)
505 return nfserr_bad_xdr
;
506 *umask
= mask
& S_IRWXUGO
;
507 iattr
->ia_valid
|= ATTR_MODE
;
510 /* request sanity: did attrlist4 contain the expected number of words? */
511 if (attrlist4_count
!= xdr_stream_pos(argp
->xdr
) - starting_pos
)
512 return nfserr_bad_xdr
;
518 nfsd4_decode_stateid4(struct nfsd4_compoundargs
*argp
, stateid_t
*sid
)
522 p
= xdr_inline_decode(argp
->xdr
, NFS4_STATEID_SIZE
);
524 return nfserr_bad_xdr
;
525 sid
->si_generation
= be32_to_cpup(p
++);
526 memcpy(&sid
->si_opaque
, p
, sizeof(sid
->si_opaque
));
531 nfsd4_decode_clientid4(struct nfsd4_compoundargs
*argp
, clientid_t
*clientid
)
535 p
= xdr_inline_decode(argp
->xdr
, sizeof(__be64
));
537 return nfserr_bad_xdr
;
538 memcpy(clientid
, p
, sizeof(*clientid
));
543 nfsd4_decode_state_owner4(struct nfsd4_compoundargs
*argp
,
544 clientid_t
*clientid
, struct xdr_netobj
*owner
)
548 status
= nfsd4_decode_clientid4(argp
, clientid
);
551 return nfsd4_decode_opaque(argp
, owner
);
554 #ifdef CONFIG_NFSD_PNFS
556 nfsd4_decode_deviceid4(struct nfsd4_compoundargs
*argp
,
557 struct nfsd4_deviceid
*devid
)
561 p
= xdr_inline_decode(argp
->xdr
, NFS4_DEVICEID4_SIZE
);
563 return nfserr_bad_xdr
;
564 memcpy(devid
, p
, sizeof(*devid
));
569 nfsd4_decode_layoutupdate4(struct nfsd4_compoundargs
*argp
,
570 struct nfsd4_layoutcommit
*lcp
)
572 if (xdr_stream_decode_u32(argp
->xdr
, &lcp
->lc_layout_type
) < 0)
573 return nfserr_bad_xdr
;
574 if (lcp
->lc_layout_type
< LAYOUT_NFSV4_1_FILES
)
575 return nfserr_bad_xdr
;
576 if (lcp
->lc_layout_type
>= LAYOUT_TYPE_MAX
)
577 return nfserr_bad_xdr
;
579 if (xdr_stream_decode_u32(argp
->xdr
, &lcp
->lc_up_len
) < 0)
580 return nfserr_bad_xdr
;
581 if (lcp
->lc_up_len
> 0) {
582 lcp
->lc_up_layout
= xdr_inline_decode(argp
->xdr
, lcp
->lc_up_len
);
583 if (!lcp
->lc_up_layout
)
584 return nfserr_bad_xdr
;
591 nfsd4_decode_layoutreturn4(struct nfsd4_compoundargs
*argp
,
592 struct nfsd4_layoutreturn
*lrp
)
596 if (xdr_stream_decode_u32(argp
->xdr
, &lrp
->lr_return_type
) < 0)
597 return nfserr_bad_xdr
;
598 switch (lrp
->lr_return_type
) {
600 if (xdr_stream_decode_u64(argp
->xdr
, &lrp
->lr_seg
.offset
) < 0)
601 return nfserr_bad_xdr
;
602 if (xdr_stream_decode_u64(argp
->xdr
, &lrp
->lr_seg
.length
) < 0)
603 return nfserr_bad_xdr
;
604 status
= nfsd4_decode_stateid4(argp
, &lrp
->lr_sid
);
607 if (xdr_stream_decode_u32(argp
->xdr
, &lrp
->lrf_body_len
) < 0)
608 return nfserr_bad_xdr
;
609 if (lrp
->lrf_body_len
> 0) {
610 lrp
->lrf_body
= xdr_inline_decode(argp
->xdr
, lrp
->lrf_body_len
);
612 return nfserr_bad_xdr
;
617 lrp
->lr_seg
.offset
= 0;
618 lrp
->lr_seg
.length
= NFS4_MAX_UINT64
;
621 return nfserr_bad_xdr
;
627 #endif /* CONFIG_NFSD_PNFS */
630 nfsd4_decode_sessionid4(struct nfsd4_compoundargs
*argp
,
631 struct nfs4_sessionid
*sessionid
)
635 p
= xdr_inline_decode(argp
->xdr
, NFS4_MAX_SESSIONID_LEN
);
637 return nfserr_bad_xdr
;
638 memcpy(sessionid
->data
, p
, sizeof(sessionid
->data
));
642 /* Defined in Appendix A of RFC 5531 */
644 nfsd4_decode_authsys_parms(struct nfsd4_compoundargs
*argp
,
645 struct nfsd4_cb_sec
*cbs
)
647 u32 stamp
, gidcount
, uid
, gid
;
650 if (xdr_stream_decode_u32(argp
->xdr
, &stamp
) < 0)
651 return nfserr_bad_xdr
;
653 status
= nfsd4_decode_ignored_string(argp
, 255);
656 if (xdr_stream_decode_u32(argp
->xdr
, &uid
) < 0)
657 return nfserr_bad_xdr
;
658 if (xdr_stream_decode_u32(argp
->xdr
, &gid
) < 0)
659 return nfserr_bad_xdr
;
660 if (xdr_stream_decode_u32(argp
->xdr
, &gidcount
) < 0)
661 return nfserr_bad_xdr
;
663 return nfserr_bad_xdr
;
664 p
= xdr_inline_decode(argp
->xdr
, gidcount
<< 2);
666 return nfserr_bad_xdr
;
667 if (cbs
->flavor
== (u32
)(-1)) {
668 struct user_namespace
*userns
= nfsd_user_namespace(argp
->rqstp
);
670 kuid_t kuid
= make_kuid(userns
, uid
);
671 kgid_t kgid
= make_kgid(userns
, gid
);
672 if (uid_valid(kuid
) && gid_valid(kgid
)) {
675 cbs
->flavor
= RPC_AUTH_UNIX
;
677 dprintk("RPC_AUTH_UNIX with invalid uid or gid, ignoring!\n");
685 nfsd4_decode_gss_cb_handles4(struct nfsd4_compoundargs
*argp
,
686 struct nfsd4_cb_sec
*cbs
)
691 dprintk("RPC_AUTH_GSS callback secflavor not supported!\n");
693 if (xdr_stream_decode_u32(argp
->xdr
, &service
) < 0)
694 return nfserr_bad_xdr
;
695 if (service
< RPC_GSS_SVC_NONE
|| service
> RPC_GSS_SVC_PRIVACY
)
696 return nfserr_bad_xdr
;
697 /* gcbp_handle_from_server */
698 status
= nfsd4_decode_ignored_string(argp
, 0);
701 /* gcbp_handle_from_client */
702 status
= nfsd4_decode_ignored_string(argp
, 0);
709 /* a counted array of callback_sec_parms4 items */
711 nfsd4_decode_cb_sec(struct nfsd4_compoundargs
*argp
, struct nfsd4_cb_sec
*cbs
)
713 u32 i
, secflavor
, nr_secflavs
;
716 /* callback_sec_params4 */
717 if (xdr_stream_decode_u32(argp
->xdr
, &nr_secflavs
) < 0)
718 return nfserr_bad_xdr
;
720 cbs
->flavor
= (u32
)(-1);
722 /* Is this legal? Be generous, take it to mean AUTH_NONE: */
725 for (i
= 0; i
< nr_secflavs
; ++i
) {
726 if (xdr_stream_decode_u32(argp
->xdr
, &secflavor
) < 0)
727 return nfserr_bad_xdr
;
731 if (cbs
->flavor
== (u32
)(-1))
732 cbs
->flavor
= RPC_AUTH_NULL
;
735 status
= nfsd4_decode_authsys_parms(argp
, cbs
);
740 status
= nfsd4_decode_gss_cb_handles4(argp
, cbs
);
754 * NFSv4 operation argument decoders
758 nfsd4_decode_access(struct nfsd4_compoundargs
*argp
,
759 struct nfsd4_access
*access
)
761 if (xdr_stream_decode_u32(argp
->xdr
, &access
->ac_req_access
) < 0)
762 return nfserr_bad_xdr
;
767 nfsd4_decode_close(struct nfsd4_compoundargs
*argp
, struct nfsd4_close
*close
)
769 if (xdr_stream_decode_u32(argp
->xdr
, &close
->cl_seqid
) < 0)
770 return nfserr_bad_xdr
;
771 return nfsd4_decode_stateid4(argp
, &close
->cl_stateid
);
776 nfsd4_decode_commit(struct nfsd4_compoundargs
*argp
, struct nfsd4_commit
*commit
)
778 if (xdr_stream_decode_u64(argp
->xdr
, &commit
->co_offset
) < 0)
779 return nfserr_bad_xdr
;
780 if (xdr_stream_decode_u32(argp
->xdr
, &commit
->co_count
) < 0)
781 return nfserr_bad_xdr
;
786 nfsd4_decode_create(struct nfsd4_compoundargs
*argp
, struct nfsd4_create
*create
)
790 if (xdr_stream_decode_u32(argp
->xdr
, &create
->cr_type
) < 0)
791 return nfserr_bad_xdr
;
792 switch (create
->cr_type
) {
794 if (xdr_stream_decode_u32(argp
->xdr
, &create
->cr_datalen
) < 0)
795 return nfserr_bad_xdr
;
796 p
= xdr_inline_decode(argp
->xdr
, create
->cr_datalen
);
798 return nfserr_bad_xdr
;
799 create
->cr_data
= svcxdr_dupstr(argp
, p
, create
->cr_datalen
);
800 if (!create
->cr_data
)
801 return nfserr_jukebox
;
805 if (xdr_stream_decode_u32(argp
->xdr
, &create
->cr_specdata1
) < 0)
806 return nfserr_bad_xdr
;
807 if (xdr_stream_decode_u32(argp
->xdr
, &create
->cr_specdata2
) < 0)
808 return nfserr_bad_xdr
;
816 status
= nfsd4_decode_component4(argp
, &create
->cr_name
,
817 &create
->cr_namelen
);
820 status
= nfsd4_decode_fattr4(argp
, create
->cr_bmval
,
821 ARRAY_SIZE(create
->cr_bmval
),
822 &create
->cr_iattr
, &create
->cr_acl
,
823 &create
->cr_label
, &create
->cr_umask
);
831 nfsd4_decode_delegreturn(struct nfsd4_compoundargs
*argp
, struct nfsd4_delegreturn
*dr
)
833 return nfsd4_decode_stateid4(argp
, &dr
->dr_stateid
);
837 nfsd4_decode_getattr(struct nfsd4_compoundargs
*argp
, struct nfsd4_getattr
*getattr
)
839 return nfsd4_decode_bitmap4(argp
, getattr
->ga_bmval
,
840 ARRAY_SIZE(getattr
->ga_bmval
));
844 nfsd4_decode_link(struct nfsd4_compoundargs
*argp
, struct nfsd4_link
*link
)
846 return nfsd4_decode_component4(argp
, &link
->li_name
, &link
->li_namelen
);
850 nfsd4_decode_open_to_lock_owner4(struct nfsd4_compoundargs
*argp
,
851 struct nfsd4_lock
*lock
)
855 if (xdr_stream_decode_u32(argp
->xdr
, &lock
->lk_new_open_seqid
) < 0)
856 return nfserr_bad_xdr
;
857 status
= nfsd4_decode_stateid4(argp
, &lock
->lk_new_open_stateid
);
860 if (xdr_stream_decode_u32(argp
->xdr
, &lock
->lk_new_lock_seqid
) < 0)
861 return nfserr_bad_xdr
;
862 return nfsd4_decode_state_owner4(argp
, &lock
->lk_new_clientid
,
863 &lock
->lk_new_owner
);
867 nfsd4_decode_exist_lock_owner4(struct nfsd4_compoundargs
*argp
,
868 struct nfsd4_lock
*lock
)
872 status
= nfsd4_decode_stateid4(argp
, &lock
->lk_old_lock_stateid
);
875 if (xdr_stream_decode_u32(argp
->xdr
, &lock
->lk_old_lock_seqid
) < 0)
876 return nfserr_bad_xdr
;
882 nfsd4_decode_locker4(struct nfsd4_compoundargs
*argp
, struct nfsd4_lock
*lock
)
884 if (xdr_stream_decode_bool(argp
->xdr
, &lock
->lk_is_new
) < 0)
885 return nfserr_bad_xdr
;
887 return nfsd4_decode_open_to_lock_owner4(argp
, lock
);
888 return nfsd4_decode_exist_lock_owner4(argp
, lock
);
892 nfsd4_decode_lock(struct nfsd4_compoundargs
*argp
, struct nfsd4_lock
*lock
)
894 if (xdr_stream_decode_u32(argp
->xdr
, &lock
->lk_type
) < 0)
895 return nfserr_bad_xdr
;
896 if ((lock
->lk_type
< NFS4_READ_LT
) || (lock
->lk_type
> NFS4_WRITEW_LT
))
897 return nfserr_bad_xdr
;
898 if (xdr_stream_decode_bool(argp
->xdr
, &lock
->lk_reclaim
) < 0)
899 return nfserr_bad_xdr
;
900 if (xdr_stream_decode_u64(argp
->xdr
, &lock
->lk_offset
) < 0)
901 return nfserr_bad_xdr
;
902 if (xdr_stream_decode_u64(argp
->xdr
, &lock
->lk_length
) < 0)
903 return nfserr_bad_xdr
;
904 return nfsd4_decode_locker4(argp
, lock
);
908 nfsd4_decode_lockt(struct nfsd4_compoundargs
*argp
, struct nfsd4_lockt
*lockt
)
910 if (xdr_stream_decode_u32(argp
->xdr
, &lockt
->lt_type
) < 0)
911 return nfserr_bad_xdr
;
912 if ((lockt
->lt_type
< NFS4_READ_LT
) || (lockt
->lt_type
> NFS4_WRITEW_LT
))
913 return nfserr_bad_xdr
;
914 if (xdr_stream_decode_u64(argp
->xdr
, &lockt
->lt_offset
) < 0)
915 return nfserr_bad_xdr
;
916 if (xdr_stream_decode_u64(argp
->xdr
, &lockt
->lt_length
) < 0)
917 return nfserr_bad_xdr
;
918 return nfsd4_decode_state_owner4(argp
, &lockt
->lt_clientid
,
923 nfsd4_decode_locku(struct nfsd4_compoundargs
*argp
, struct nfsd4_locku
*locku
)
927 if (xdr_stream_decode_u32(argp
->xdr
, &locku
->lu_type
) < 0)
928 return nfserr_bad_xdr
;
929 if ((locku
->lu_type
< NFS4_READ_LT
) || (locku
->lu_type
> NFS4_WRITEW_LT
))
930 return nfserr_bad_xdr
;
931 if (xdr_stream_decode_u32(argp
->xdr
, &locku
->lu_seqid
) < 0)
932 return nfserr_bad_xdr
;
933 status
= nfsd4_decode_stateid4(argp
, &locku
->lu_stateid
);
936 if (xdr_stream_decode_u64(argp
->xdr
, &locku
->lu_offset
) < 0)
937 return nfserr_bad_xdr
;
938 if (xdr_stream_decode_u64(argp
->xdr
, &locku
->lu_length
) < 0)
939 return nfserr_bad_xdr
;
945 nfsd4_decode_lookup(struct nfsd4_compoundargs
*argp
, struct nfsd4_lookup
*lookup
)
947 return nfsd4_decode_component4(argp
, &lookup
->lo_name
, &lookup
->lo_len
);
951 nfsd4_decode_createhow4(struct nfsd4_compoundargs
*argp
, struct nfsd4_open
*open
)
955 if (xdr_stream_decode_u32(argp
->xdr
, &open
->op_createmode
) < 0)
956 return nfserr_bad_xdr
;
957 switch (open
->op_createmode
) {
958 case NFS4_CREATE_UNCHECKED
:
959 case NFS4_CREATE_GUARDED
:
960 status
= nfsd4_decode_fattr4(argp
, open
->op_bmval
,
961 ARRAY_SIZE(open
->op_bmval
),
962 &open
->op_iattr
, &open
->op_acl
,
963 &open
->op_label
, &open
->op_umask
);
967 case NFS4_CREATE_EXCLUSIVE
:
968 status
= nfsd4_decode_verifier4(argp
, &open
->op_verf
);
972 case NFS4_CREATE_EXCLUSIVE4_1
:
973 if (argp
->minorversion
< 1)
974 return nfserr_bad_xdr
;
975 status
= nfsd4_decode_verifier4(argp
, &open
->op_verf
);
978 status
= nfsd4_decode_fattr4(argp
, open
->op_bmval
,
979 ARRAY_SIZE(open
->op_bmval
),
980 &open
->op_iattr
, &open
->op_acl
,
981 &open
->op_label
, &open
->op_umask
);
986 return nfserr_bad_xdr
;
993 nfsd4_decode_openflag4(struct nfsd4_compoundargs
*argp
, struct nfsd4_open
*open
)
997 if (xdr_stream_decode_u32(argp
->xdr
, &open
->op_create
) < 0)
998 return nfserr_bad_xdr
;
999 switch (open
->op_create
) {
1000 case NFS4_OPEN_NOCREATE
:
1002 case NFS4_OPEN_CREATE
:
1003 status
= nfsd4_decode_createhow4(argp
, open
);
1008 return nfserr_bad_xdr
;
1014 static __be32
nfsd4_decode_share_access(struct nfsd4_compoundargs
*argp
, u32
*share_access
, u32
*deleg_want
, u32
*deleg_when
)
1018 if (xdr_stream_decode_u32(argp
->xdr
, &w
) < 0)
1019 return nfserr_bad_xdr
;
1020 *share_access
= w
& NFS4_SHARE_ACCESS_MASK
;
1021 *deleg_want
= w
& NFS4_SHARE_WANT_MASK
;
1023 *deleg_when
= w
& NFS4_SHARE_WHEN_MASK
;
1025 switch (w
& NFS4_SHARE_ACCESS_MASK
) {
1026 case NFS4_SHARE_ACCESS_READ
:
1027 case NFS4_SHARE_ACCESS_WRITE
:
1028 case NFS4_SHARE_ACCESS_BOTH
:
1031 return nfserr_bad_xdr
;
1033 w
&= ~NFS4_SHARE_ACCESS_MASK
;
1036 if (!argp
->minorversion
)
1037 return nfserr_bad_xdr
;
1038 switch (w
& NFS4_SHARE_WANT_MASK
) {
1039 case NFS4_SHARE_WANT_NO_PREFERENCE
:
1040 case NFS4_SHARE_WANT_READ_DELEG
:
1041 case NFS4_SHARE_WANT_WRITE_DELEG
:
1042 case NFS4_SHARE_WANT_ANY_DELEG
:
1043 case NFS4_SHARE_WANT_NO_DELEG
:
1044 case NFS4_SHARE_WANT_CANCEL
:
1047 return nfserr_bad_xdr
;
1049 w
&= ~NFS4_SHARE_WANT_MASK
;
1053 if (!deleg_when
) /* open_downgrade */
1054 return nfserr_inval
;
1056 case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL
:
1057 case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED
:
1058 case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL
|
1059 NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED
):
1062 return nfserr_bad_xdr
;
1065 static __be32
nfsd4_decode_share_deny(struct nfsd4_compoundargs
*argp
, u32
*x
)
1067 if (xdr_stream_decode_u32(argp
->xdr
, x
) < 0)
1068 return nfserr_bad_xdr
;
1069 /* Note: unlike access bits, deny bits may be zero. */
1070 if (*x
& ~NFS4_SHARE_DENY_BOTH
)
1071 return nfserr_bad_xdr
;
1077 nfsd4_decode_open_claim4(struct nfsd4_compoundargs
*argp
,
1078 struct nfsd4_open
*open
)
1082 if (xdr_stream_decode_u32(argp
->xdr
, &open
->op_claim_type
) < 0)
1083 return nfserr_bad_xdr
;
1084 switch (open
->op_claim_type
) {
1085 case NFS4_OPEN_CLAIM_NULL
:
1086 case NFS4_OPEN_CLAIM_DELEGATE_PREV
:
1087 status
= nfsd4_decode_component4(argp
, &open
->op_fname
,
1088 &open
->op_fnamelen
);
1092 case NFS4_OPEN_CLAIM_PREVIOUS
:
1093 if (xdr_stream_decode_u32(argp
->xdr
, &open
->op_delegate_type
) < 0)
1094 return nfserr_bad_xdr
;
1096 case NFS4_OPEN_CLAIM_DELEGATE_CUR
:
1097 status
= nfsd4_decode_stateid4(argp
, &open
->op_delegate_stateid
);
1100 status
= nfsd4_decode_component4(argp
, &open
->op_fname
,
1101 &open
->op_fnamelen
);
1105 case NFS4_OPEN_CLAIM_FH
:
1106 case NFS4_OPEN_CLAIM_DELEG_PREV_FH
:
1107 if (argp
->minorversion
< 1)
1108 return nfserr_bad_xdr
;
1111 case NFS4_OPEN_CLAIM_DELEG_CUR_FH
:
1112 if (argp
->minorversion
< 1)
1113 return nfserr_bad_xdr
;
1114 status
= nfsd4_decode_stateid4(argp
, &open
->op_delegate_stateid
);
1119 return nfserr_bad_xdr
;
1126 nfsd4_decode_open(struct nfsd4_compoundargs
*argp
, struct nfsd4_open
*open
)
1131 memset(open
->op_bmval
, 0, sizeof(open
->op_bmval
));
1132 open
->op_iattr
.ia_valid
= 0;
1133 open
->op_openowner
= NULL
;
1135 open
->op_xdr_error
= 0;
1136 if (xdr_stream_decode_u32(argp
->xdr
, &open
->op_seqid
) < 0)
1137 return nfserr_bad_xdr
;
1138 /* deleg_want is ignored */
1139 status
= nfsd4_decode_share_access(argp
, &open
->op_share_access
,
1140 &open
->op_deleg_want
, &dummy
);
1143 status
= nfsd4_decode_share_deny(argp
, &open
->op_share_deny
);
1146 status
= nfsd4_decode_state_owner4(argp
, &open
->op_clientid
,
1150 status
= nfsd4_decode_openflag4(argp
, open
);
1153 return nfsd4_decode_open_claim4(argp
, open
);
1157 nfsd4_decode_open_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_confirm
*open_conf
)
1161 if (argp
->minorversion
>= 1)
1162 return nfserr_notsupp
;
1164 status
= nfsd4_decode_stateid4(argp
, &open_conf
->oc_req_stateid
);
1167 if (xdr_stream_decode_u32(argp
->xdr
, &open_conf
->oc_seqid
) < 0)
1168 return nfserr_bad_xdr
;
1174 nfsd4_decode_open_downgrade(struct nfsd4_compoundargs
*argp
, struct nfsd4_open_downgrade
*open_down
)
1178 status
= nfsd4_decode_stateid4(argp
, &open_down
->od_stateid
);
1181 if (xdr_stream_decode_u32(argp
->xdr
, &open_down
->od_seqid
) < 0)
1182 return nfserr_bad_xdr
;
1183 /* deleg_want is ignored */
1184 status
= nfsd4_decode_share_access(argp
, &open_down
->od_share_access
,
1185 &open_down
->od_deleg_want
, NULL
);
1188 return nfsd4_decode_share_deny(argp
, &open_down
->od_share_deny
);
1192 nfsd4_decode_putfh(struct nfsd4_compoundargs
*argp
, struct nfsd4_putfh
*putfh
)
1196 if (xdr_stream_decode_u32(argp
->xdr
, &putfh
->pf_fhlen
) < 0)
1197 return nfserr_bad_xdr
;
1198 if (putfh
->pf_fhlen
> NFS4_FHSIZE
)
1199 return nfserr_bad_xdr
;
1200 p
= xdr_inline_decode(argp
->xdr
, putfh
->pf_fhlen
);
1202 return nfserr_bad_xdr
;
1203 putfh
->pf_fhval
= svcxdr_tmpalloc(argp
, putfh
->pf_fhlen
);
1204 if (!putfh
->pf_fhval
)
1205 return nfserr_jukebox
;
1206 memcpy(putfh
->pf_fhval
, p
, putfh
->pf_fhlen
);
1212 nfsd4_decode_putpubfh(struct nfsd4_compoundargs
*argp
, void *p
)
1214 if (argp
->minorversion
== 0)
1216 return nfserr_notsupp
;
1220 nfsd4_decode_read(struct nfsd4_compoundargs
*argp
, struct nfsd4_read
*read
)
1224 status
= nfsd4_decode_stateid4(argp
, &read
->rd_stateid
);
1227 if (xdr_stream_decode_u64(argp
->xdr
, &read
->rd_offset
) < 0)
1228 return nfserr_bad_xdr
;
1229 if (xdr_stream_decode_u32(argp
->xdr
, &read
->rd_length
) < 0)
1230 return nfserr_bad_xdr
;
1236 nfsd4_decode_readdir(struct nfsd4_compoundargs
*argp
, struct nfsd4_readdir
*readdir
)
1240 if (xdr_stream_decode_u64(argp
->xdr
, &readdir
->rd_cookie
) < 0)
1241 return nfserr_bad_xdr
;
1242 status
= nfsd4_decode_verifier4(argp
, &readdir
->rd_verf
);
1245 if (xdr_stream_decode_u32(argp
->xdr
, &readdir
->rd_dircount
) < 0)
1246 return nfserr_bad_xdr
;
1247 if (xdr_stream_decode_u32(argp
->xdr
, &readdir
->rd_maxcount
) < 0)
1248 return nfserr_bad_xdr
;
1249 if (xdr_stream_decode_uint32_array(argp
->xdr
, readdir
->rd_bmval
,
1250 ARRAY_SIZE(readdir
->rd_bmval
)) < 0)
1251 return nfserr_bad_xdr
;
1257 nfsd4_decode_remove(struct nfsd4_compoundargs
*argp
, struct nfsd4_remove
*remove
)
1259 return nfsd4_decode_component4(argp
, &remove
->rm_name
, &remove
->rm_namelen
);
1263 nfsd4_decode_rename(struct nfsd4_compoundargs
*argp
, struct nfsd4_rename
*rename
)
1267 status
= nfsd4_decode_component4(argp
, &rename
->rn_sname
, &rename
->rn_snamelen
);
1270 return nfsd4_decode_component4(argp
, &rename
->rn_tname
, &rename
->rn_tnamelen
);
1274 nfsd4_decode_renew(struct nfsd4_compoundargs
*argp
, clientid_t
*clientid
)
1276 return nfsd4_decode_clientid4(argp
, clientid
);
1280 nfsd4_decode_secinfo(struct nfsd4_compoundargs
*argp
,
1281 struct nfsd4_secinfo
*secinfo
)
1283 return nfsd4_decode_component4(argp
, &secinfo
->si_name
, &secinfo
->si_namelen
);
1287 nfsd4_decode_setattr(struct nfsd4_compoundargs
*argp
, struct nfsd4_setattr
*setattr
)
1291 status
= nfsd4_decode_stateid4(argp
, &setattr
->sa_stateid
);
1294 return nfsd4_decode_fattr4(argp
, setattr
->sa_bmval
,
1295 ARRAY_SIZE(setattr
->sa_bmval
),
1296 &setattr
->sa_iattr
, &setattr
->sa_acl
,
1297 &setattr
->sa_label
, NULL
);
1301 nfsd4_decode_setclientid(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid
*setclientid
)
1305 if (argp
->minorversion
>= 1)
1306 return nfserr_notsupp
;
1308 status
= nfsd4_decode_verifier4(argp
, &setclientid
->se_verf
);
1311 status
= nfsd4_decode_opaque(argp
, &setclientid
->se_name
);
1314 if (xdr_stream_decode_u32(argp
->xdr
, &setclientid
->se_callback_prog
) < 0)
1315 return nfserr_bad_xdr
;
1316 if (xdr_stream_decode_u32(argp
->xdr
, &setclientid
->se_callback_netid_len
) < 0)
1317 return nfserr_bad_xdr
;
1318 p
= xdr_inline_decode(argp
->xdr
, setclientid
->se_callback_netid_len
);
1320 return nfserr_bad_xdr
;
1321 setclientid
->se_callback_netid_val
= svcxdr_tmpalloc(argp
,
1322 setclientid
->se_callback_netid_len
);
1323 if (!setclientid
->se_callback_netid_val
)
1324 return nfserr_jukebox
;
1325 memcpy(setclientid
->se_callback_netid_val
, p
,
1326 setclientid
->se_callback_netid_len
);
1328 if (xdr_stream_decode_u32(argp
->xdr
, &setclientid
->se_callback_addr_len
) < 0)
1329 return nfserr_bad_xdr
;
1330 p
= xdr_inline_decode(argp
->xdr
, setclientid
->se_callback_addr_len
);
1332 return nfserr_bad_xdr
;
1333 setclientid
->se_callback_addr_val
= svcxdr_tmpalloc(argp
,
1334 setclientid
->se_callback_addr_len
);
1335 if (!setclientid
->se_callback_addr_val
)
1336 return nfserr_jukebox
;
1337 memcpy(setclientid
->se_callback_addr_val
, p
,
1338 setclientid
->se_callback_addr_len
);
1339 if (xdr_stream_decode_u32(argp
->xdr
, &setclientid
->se_callback_ident
) < 0)
1340 return nfserr_bad_xdr
;
1346 nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs
*argp
, struct nfsd4_setclientid_confirm
*scd_c
)
1350 if (argp
->minorversion
>= 1)
1351 return nfserr_notsupp
;
1353 status
= nfsd4_decode_clientid4(argp
, &scd_c
->sc_clientid
);
1356 return nfsd4_decode_verifier4(argp
, &scd_c
->sc_confirm
);
1359 /* Also used for NVERIFY */
1361 nfsd4_decode_verify(struct nfsd4_compoundargs
*argp
, struct nfsd4_verify
*verify
)
1365 status
= nfsd4_decode_bitmap4(argp
, verify
->ve_bmval
,
1366 ARRAY_SIZE(verify
->ve_bmval
));
1370 /* For convenience's sake, we compare raw xdr'd attributes in
1371 * nfsd4_proc_verify */
1373 if (xdr_stream_decode_u32(argp
->xdr
, &verify
->ve_attrlen
) < 0)
1374 return nfserr_bad_xdr
;
1375 p
= xdr_inline_decode(argp
->xdr
, verify
->ve_attrlen
);
1377 return nfserr_bad_xdr
;
1378 verify
->ve_attrval
= svcxdr_tmpalloc(argp
, verify
->ve_attrlen
);
1379 if (!verify
->ve_attrval
)
1380 return nfserr_jukebox
;
1381 memcpy(verify
->ve_attrval
, p
, verify
->ve_attrlen
);
1387 nfsd4_decode_write(struct nfsd4_compoundargs
*argp
, struct nfsd4_write
*write
)
1391 status
= nfsd4_decode_stateid4(argp
, &write
->wr_stateid
);
1394 if (xdr_stream_decode_u64(argp
->xdr
, &write
->wr_offset
) < 0)
1395 return nfserr_bad_xdr
;
1396 if (xdr_stream_decode_u32(argp
->xdr
, &write
->wr_stable_how
) < 0)
1397 return nfserr_bad_xdr
;
1398 if (write
->wr_stable_how
> NFS_FILE_SYNC
)
1399 return nfserr_bad_xdr
;
1400 if (xdr_stream_decode_u32(argp
->xdr
, &write
->wr_buflen
) < 0)
1401 return nfserr_bad_xdr
;
1402 if (!xdr_stream_subsegment(argp
->xdr
, &write
->wr_payload
, write
->wr_buflen
))
1403 return nfserr_bad_xdr
;
1409 nfsd4_decode_release_lockowner(struct nfsd4_compoundargs
*argp
, struct nfsd4_release_lockowner
*rlockowner
)
1413 if (argp
->minorversion
>= 1)
1414 return nfserr_notsupp
;
1416 status
= nfsd4_decode_state_owner4(argp
, &rlockowner
->rl_clientid
,
1417 &rlockowner
->rl_owner
);
1421 if (argp
->minorversion
&& !zero_clientid(&rlockowner
->rl_clientid
))
1422 return nfserr_inval
;
1427 static __be32
nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs
*argp
, struct nfsd4_backchannel_ctl
*bc
)
1429 if (xdr_stream_decode_u32(argp
->xdr
, &bc
->bc_cb_program
) < 0)
1430 return nfserr_bad_xdr
;
1431 return nfsd4_decode_cb_sec(argp
, &bc
->bc_cb_sec
);
1434 static __be32
nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs
*argp
, struct nfsd4_bind_conn_to_session
*bcts
)
1436 u32 use_conn_in_rdma_mode
;
1439 status
= nfsd4_decode_sessionid4(argp
, &bcts
->sessionid
);
1442 if (xdr_stream_decode_u32(argp
->xdr
, &bcts
->dir
) < 0)
1443 return nfserr_bad_xdr
;
1444 if (xdr_stream_decode_u32(argp
->xdr
, &use_conn_in_rdma_mode
) < 0)
1445 return nfserr_bad_xdr
;
1451 nfsd4_decode_state_protect_ops(struct nfsd4_compoundargs
*argp
,
1452 struct nfsd4_exchange_id
*exid
)
1456 status
= nfsd4_decode_bitmap4(argp
, exid
->spo_must_enforce
,
1457 ARRAY_SIZE(exid
->spo_must_enforce
));
1459 return nfserr_bad_xdr
;
1460 status
= nfsd4_decode_bitmap4(argp
, exid
->spo_must_allow
,
1461 ARRAY_SIZE(exid
->spo_must_allow
));
1463 return nfserr_bad_xdr
;
1469 * This implementation currently does not support SP4_SSV.
1470 * This decoder simply skips over these arguments.
1472 static noinline __be32
1473 nfsd4_decode_ssv_sp_parms(struct nfsd4_compoundargs
*argp
,
1474 struct nfsd4_exchange_id
*exid
)
1476 u32 count
, window
, num_gss_handles
;
1480 status
= nfsd4_decode_state_protect_ops(argp
, exid
);
1484 /* ssp_hash_algs<> */
1485 if (xdr_stream_decode_u32(argp
->xdr
, &count
) < 0)
1486 return nfserr_bad_xdr
;
1488 status
= nfsd4_decode_ignored_string(argp
, 0);
1493 /* ssp_encr_algs<> */
1494 if (xdr_stream_decode_u32(argp
->xdr
, &count
) < 0)
1495 return nfserr_bad_xdr
;
1497 status
= nfsd4_decode_ignored_string(argp
, 0);
1502 if (xdr_stream_decode_u32(argp
->xdr
, &window
) < 0)
1503 return nfserr_bad_xdr
;
1504 if (xdr_stream_decode_u32(argp
->xdr
, &num_gss_handles
) < 0)
1505 return nfserr_bad_xdr
;
1511 nfsd4_decode_state_protect4_a(struct nfsd4_compoundargs
*argp
,
1512 struct nfsd4_exchange_id
*exid
)
1516 if (xdr_stream_decode_u32(argp
->xdr
, &exid
->spa_how
) < 0)
1517 return nfserr_bad_xdr
;
1518 switch (exid
->spa_how
) {
1522 status
= nfsd4_decode_state_protect_ops(argp
, exid
);
1527 status
= nfsd4_decode_ssv_sp_parms(argp
, exid
);
1532 return nfserr_bad_xdr
;
1539 nfsd4_decode_nfs_impl_id4(struct nfsd4_compoundargs
*argp
,
1540 struct nfsd4_exchange_id
*exid
)
1545 if (xdr_stream_decode_u32(argp
->xdr
, &count
) < 0)
1546 return nfserr_bad_xdr
;
1551 /* Note that RFC 8881 places no length limit on
1552 * nii_domain, but this implementation permits no
1553 * more than NFS4_OPAQUE_LIMIT bytes */
1554 status
= nfsd4_decode_opaque(argp
, &exid
->nii_domain
);
1557 /* Note that RFC 8881 places no length limit on
1558 * nii_name, but this implementation permits no
1559 * more than NFS4_OPAQUE_LIMIT bytes */
1560 status
= nfsd4_decode_opaque(argp
, &exid
->nii_name
);
1563 status
= nfsd4_decode_nfstime4(argp
, &exid
->nii_time
);
1568 return nfserr_bad_xdr
;
1575 nfsd4_decode_exchange_id(struct nfsd4_compoundargs
*argp
,
1576 struct nfsd4_exchange_id
*exid
)
1580 status
= nfsd4_decode_verifier4(argp
, &exid
->verifier
);
1583 status
= nfsd4_decode_opaque(argp
, &exid
->clname
);
1586 if (xdr_stream_decode_u32(argp
->xdr
, &exid
->flags
) < 0)
1587 return nfserr_bad_xdr
;
1588 status
= nfsd4_decode_state_protect4_a(argp
, exid
);
1591 return nfsd4_decode_nfs_impl_id4(argp
, exid
);
1595 nfsd4_decode_channel_attrs4(struct nfsd4_compoundargs
*argp
,
1596 struct nfsd4_channel_attrs
*ca
)
1600 p
= xdr_inline_decode(argp
->xdr
, XDR_UNIT
* 7);
1602 return nfserr_bad_xdr
;
1604 /* headerpadsz is ignored */
1606 ca
->maxreq_sz
= be32_to_cpup(p
++);
1607 ca
->maxresp_sz
= be32_to_cpup(p
++);
1608 ca
->maxresp_cached
= be32_to_cpup(p
++);
1609 ca
->maxops
= be32_to_cpup(p
++);
1610 ca
->maxreqs
= be32_to_cpup(p
++);
1611 ca
->nr_rdma_attrs
= be32_to_cpup(p
);
1612 switch (ca
->nr_rdma_attrs
) {
1616 if (xdr_stream_decode_u32(argp
->xdr
, &ca
->rdma_attrs
) < 0)
1617 return nfserr_bad_xdr
;
1620 return nfserr_bad_xdr
;
1627 nfsd4_decode_create_session(struct nfsd4_compoundargs
*argp
,
1628 struct nfsd4_create_session
*sess
)
1632 status
= nfsd4_decode_clientid4(argp
, &sess
->clientid
);
1635 if (xdr_stream_decode_u32(argp
->xdr
, &sess
->seqid
) < 0)
1636 return nfserr_bad_xdr
;
1637 if (xdr_stream_decode_u32(argp
->xdr
, &sess
->flags
) < 0)
1638 return nfserr_bad_xdr
;
1639 status
= nfsd4_decode_channel_attrs4(argp
, &sess
->fore_channel
);
1642 status
= nfsd4_decode_channel_attrs4(argp
, &sess
->back_channel
);
1645 if (xdr_stream_decode_u32(argp
->xdr
, &sess
->callback_prog
) < 0)
1646 return nfserr_bad_xdr
;
1647 status
= nfsd4_decode_cb_sec(argp
, &sess
->cb_sec
);
1655 nfsd4_decode_destroy_session(struct nfsd4_compoundargs
*argp
,
1656 struct nfsd4_destroy_session
*destroy_session
)
1658 return nfsd4_decode_sessionid4(argp
, &destroy_session
->sessionid
);
1662 nfsd4_decode_free_stateid(struct nfsd4_compoundargs
*argp
,
1663 struct nfsd4_free_stateid
*free_stateid
)
1665 return nfsd4_decode_stateid4(argp
, &free_stateid
->fr_stateid
);
1668 #ifdef CONFIG_NFSD_PNFS
1670 nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs
*argp
,
1671 struct nfsd4_getdeviceinfo
*gdev
)
1675 status
= nfsd4_decode_deviceid4(argp
, &gdev
->gd_devid
);
1678 if (xdr_stream_decode_u32(argp
->xdr
, &gdev
->gd_layout_type
) < 0)
1679 return nfserr_bad_xdr
;
1680 if (xdr_stream_decode_u32(argp
->xdr
, &gdev
->gd_maxcount
) < 0)
1681 return nfserr_bad_xdr
;
1682 if (xdr_stream_decode_uint32_array(argp
->xdr
,
1683 &gdev
->gd_notify_types
, 1) < 0)
1684 return nfserr_bad_xdr
;
1690 nfsd4_decode_layoutcommit(struct nfsd4_compoundargs
*argp
,
1691 struct nfsd4_layoutcommit
*lcp
)
1695 if (xdr_stream_decode_u64(argp
->xdr
, &lcp
->lc_seg
.offset
) < 0)
1696 return nfserr_bad_xdr
;
1697 if (xdr_stream_decode_u64(argp
->xdr
, &lcp
->lc_seg
.length
) < 0)
1698 return nfserr_bad_xdr
;
1699 if (xdr_stream_decode_bool(argp
->xdr
, &lcp
->lc_reclaim
) < 0)
1700 return nfserr_bad_xdr
;
1701 status
= nfsd4_decode_stateid4(argp
, &lcp
->lc_sid
);
1704 if (xdr_stream_decode_u32(argp
->xdr
, &lcp
->lc_newoffset
) < 0)
1705 return nfserr_bad_xdr
;
1706 if (lcp
->lc_newoffset
) {
1707 if (xdr_stream_decode_u64(argp
->xdr
, &lcp
->lc_last_wr
) < 0)
1708 return nfserr_bad_xdr
;
1710 lcp
->lc_last_wr
= 0;
1711 p
= xdr_inline_decode(argp
->xdr
, XDR_UNIT
);
1713 return nfserr_bad_xdr
;
1714 if (xdr_item_is_present(p
)) {
1715 status
= nfsd4_decode_nfstime4(argp
, &lcp
->lc_mtime
);
1719 lcp
->lc_mtime
.tv_nsec
= UTIME_NOW
;
1721 return nfsd4_decode_layoutupdate4(argp
, lcp
);
1725 nfsd4_decode_layoutget(struct nfsd4_compoundargs
*argp
,
1726 struct nfsd4_layoutget
*lgp
)
1730 if (xdr_stream_decode_u32(argp
->xdr
, &lgp
->lg_signal
) < 0)
1731 return nfserr_bad_xdr
;
1732 if (xdr_stream_decode_u32(argp
->xdr
, &lgp
->lg_layout_type
) < 0)
1733 return nfserr_bad_xdr
;
1734 if (xdr_stream_decode_u32(argp
->xdr
, &lgp
->lg_seg
.iomode
) < 0)
1735 return nfserr_bad_xdr
;
1736 if (xdr_stream_decode_u64(argp
->xdr
, &lgp
->lg_seg
.offset
) < 0)
1737 return nfserr_bad_xdr
;
1738 if (xdr_stream_decode_u64(argp
->xdr
, &lgp
->lg_seg
.length
) < 0)
1739 return nfserr_bad_xdr
;
1740 if (xdr_stream_decode_u64(argp
->xdr
, &lgp
->lg_minlength
) < 0)
1741 return nfserr_bad_xdr
;
1742 status
= nfsd4_decode_stateid4(argp
, &lgp
->lg_sid
);
1745 if (xdr_stream_decode_u32(argp
->xdr
, &lgp
->lg_maxcount
) < 0)
1746 return nfserr_bad_xdr
;
1752 nfsd4_decode_layoutreturn(struct nfsd4_compoundargs
*argp
,
1753 struct nfsd4_layoutreturn
*lrp
)
1755 if (xdr_stream_decode_bool(argp
->xdr
, &lrp
->lr_reclaim
) < 0)
1756 return nfserr_bad_xdr
;
1757 if (xdr_stream_decode_u32(argp
->xdr
, &lrp
->lr_layout_type
) < 0)
1758 return nfserr_bad_xdr
;
1759 if (xdr_stream_decode_u32(argp
->xdr
, &lrp
->lr_seg
.iomode
) < 0)
1760 return nfserr_bad_xdr
;
1761 return nfsd4_decode_layoutreturn4(argp
, lrp
);
1763 #endif /* CONFIG_NFSD_PNFS */
1765 static __be32
nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs
*argp
,
1766 struct nfsd4_secinfo_no_name
*sin
)
1768 if (xdr_stream_decode_u32(argp
->xdr
, &sin
->sin_style
) < 0)
1769 return nfserr_bad_xdr
;
1774 nfsd4_decode_sequence(struct nfsd4_compoundargs
*argp
,
1775 struct nfsd4_sequence
*seq
)
1779 status
= nfsd4_decode_sessionid4(argp
, &seq
->sessionid
);
1782 p
= xdr_inline_decode(argp
->xdr
, XDR_UNIT
* 4);
1784 return nfserr_bad_xdr
;
1785 seq
->seqid
= be32_to_cpup(p
++);
1786 seq
->slotid
= be32_to_cpup(p
++);
1787 seq
->maxslots
= be32_to_cpup(p
++);
1788 seq
->cachethis
= be32_to_cpup(p
);
1794 nfsd4_decode_test_stateid(struct nfsd4_compoundargs
*argp
, struct nfsd4_test_stateid
*test_stateid
)
1796 struct nfsd4_test_stateid_id
*stateid
;
1800 if (xdr_stream_decode_u32(argp
->xdr
, &test_stateid
->ts_num_ids
) < 0)
1801 return nfserr_bad_xdr
;
1803 INIT_LIST_HEAD(&test_stateid
->ts_stateid_list
);
1804 for (i
= 0; i
< test_stateid
->ts_num_ids
; i
++) {
1805 stateid
= svcxdr_tmpalloc(argp
, sizeof(*stateid
));
1807 return nfserrno(-ENOMEM
); /* XXX: not jukebox? */
1808 INIT_LIST_HEAD(&stateid
->ts_id_list
);
1809 list_add_tail(&stateid
->ts_id_list
, &test_stateid
->ts_stateid_list
);
1810 status
= nfsd4_decode_stateid4(argp
, &stateid
->ts_id_stateid
);
1818 static __be32
nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs
*argp
,
1819 struct nfsd4_destroy_clientid
*dc
)
1821 return nfsd4_decode_clientid4(argp
, &dc
->clientid
);
1824 static __be32
nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs
*argp
,
1825 struct nfsd4_reclaim_complete
*rc
)
1827 if (xdr_stream_decode_bool(argp
->xdr
, &rc
->rca_one_fs
) < 0)
1828 return nfserr_bad_xdr
;
1833 nfsd4_decode_fallocate(struct nfsd4_compoundargs
*argp
,
1834 struct nfsd4_fallocate
*fallocate
)
1838 status
= nfsd4_decode_stateid4(argp
, &fallocate
->falloc_stateid
);
1841 if (xdr_stream_decode_u64(argp
->xdr
, &fallocate
->falloc_offset
) < 0)
1842 return nfserr_bad_xdr
;
1843 if (xdr_stream_decode_u64(argp
->xdr
, &fallocate
->falloc_length
) < 0)
1844 return nfserr_bad_xdr
;
1849 static __be32
nfsd4_decode_nl4_server(struct nfsd4_compoundargs
*argp
,
1850 struct nl4_server
*ns
)
1852 struct nfs42_netaddr
*naddr
;
1855 if (xdr_stream_decode_u32(argp
->xdr
, &ns
->nl4_type
) < 0)
1856 return nfserr_bad_xdr
;
1858 /* currently support for 1 inter-server source server */
1859 switch (ns
->nl4_type
) {
1861 naddr
= &ns
->u
.nl4_addr
;
1863 if (xdr_stream_decode_u32(argp
->xdr
, &naddr
->netid_len
) < 0)
1864 return nfserr_bad_xdr
;
1865 if (naddr
->netid_len
> RPCBIND_MAXNETIDLEN
)
1866 return nfserr_bad_xdr
;
1868 p
= xdr_inline_decode(argp
->xdr
, naddr
->netid_len
);
1870 return nfserr_bad_xdr
;
1871 memcpy(naddr
->netid
, p
, naddr
->netid_len
);
1873 if (xdr_stream_decode_u32(argp
->xdr
, &naddr
->addr_len
) < 0)
1874 return nfserr_bad_xdr
;
1875 if (naddr
->addr_len
> RPCBIND_MAXUADDRLEN
)
1876 return nfserr_bad_xdr
;
1878 p
= xdr_inline_decode(argp
->xdr
, naddr
->addr_len
);
1880 return nfserr_bad_xdr
;
1881 memcpy(naddr
->addr
, p
, naddr
->addr_len
);
1884 return nfserr_bad_xdr
;
1891 nfsd4_decode_copy(struct nfsd4_compoundargs
*argp
, struct nfsd4_copy
*copy
)
1893 struct nl4_server
*ns_dummy
;
1894 u32 consecutive
, i
, count
;
1897 status
= nfsd4_decode_stateid4(argp
, ©
->cp_src_stateid
);
1900 status
= nfsd4_decode_stateid4(argp
, ©
->cp_dst_stateid
);
1903 if (xdr_stream_decode_u64(argp
->xdr
, ©
->cp_src_pos
) < 0)
1904 return nfserr_bad_xdr
;
1905 if (xdr_stream_decode_u64(argp
->xdr
, ©
->cp_dst_pos
) < 0)
1906 return nfserr_bad_xdr
;
1907 if (xdr_stream_decode_u64(argp
->xdr
, ©
->cp_count
) < 0)
1908 return nfserr_bad_xdr
;
1909 /* ca_consecutive: we always do consecutive copies */
1910 if (xdr_stream_decode_u32(argp
->xdr
, &consecutive
) < 0)
1911 return nfserr_bad_xdr
;
1912 if (xdr_stream_decode_u32(argp
->xdr
, ©
->cp_synchronous
) < 0)
1913 return nfserr_bad_xdr
;
1915 if (xdr_stream_decode_u32(argp
->xdr
, &count
) < 0)
1916 return nfserr_bad_xdr
;
1917 copy
->cp_intra
= false;
1918 if (count
== 0) { /* intra-server copy */
1919 copy
->cp_intra
= true;
1923 /* decode all the supplied server addresses but use only the first */
1924 status
= nfsd4_decode_nl4_server(argp
, ©
->cp_src
);
1928 ns_dummy
= kmalloc(sizeof(struct nl4_server
), GFP_KERNEL
);
1929 if (ns_dummy
== NULL
)
1930 return nfserrno(-ENOMEM
); /* XXX: jukebox? */
1931 for (i
= 0; i
< count
- 1; i
++) {
1932 status
= nfsd4_decode_nl4_server(argp
, ns_dummy
);
1944 nfsd4_decode_copy_notify(struct nfsd4_compoundargs
*argp
,
1945 struct nfsd4_copy_notify
*cn
)
1949 status
= nfsd4_decode_stateid4(argp
, &cn
->cpn_src_stateid
);
1952 return nfsd4_decode_nl4_server(argp
, &cn
->cpn_dst
);
1956 nfsd4_decode_offload_status(struct nfsd4_compoundargs
*argp
,
1957 struct nfsd4_offload_status
*os
)
1959 return nfsd4_decode_stateid4(argp
, &os
->stateid
);
1963 nfsd4_decode_seek(struct nfsd4_compoundargs
*argp
, struct nfsd4_seek
*seek
)
1967 status
= nfsd4_decode_stateid4(argp
, &seek
->seek_stateid
);
1970 if (xdr_stream_decode_u64(argp
->xdr
, &seek
->seek_offset
) < 0)
1971 return nfserr_bad_xdr
;
1972 if (xdr_stream_decode_u32(argp
->xdr
, &seek
->seek_whence
) < 0)
1973 return nfserr_bad_xdr
;
1979 nfsd4_decode_clone(struct nfsd4_compoundargs
*argp
, struct nfsd4_clone
*clone
)
1983 status
= nfsd4_decode_stateid4(argp
, &clone
->cl_src_stateid
);
1986 status
= nfsd4_decode_stateid4(argp
, &clone
->cl_dst_stateid
);
1989 if (xdr_stream_decode_u64(argp
->xdr
, &clone
->cl_src_pos
) < 0)
1990 return nfserr_bad_xdr
;
1991 if (xdr_stream_decode_u64(argp
->xdr
, &clone
->cl_dst_pos
) < 0)
1992 return nfserr_bad_xdr
;
1993 if (xdr_stream_decode_u64(argp
->xdr
, &clone
->cl_count
) < 0)
1994 return nfserr_bad_xdr
;
2000 * XDR data that is more than PAGE_SIZE in size is normally part of a
2001 * read or write. However, the size of extended attributes is limited
2002 * by the maximum request size, and then further limited by the underlying
2003 * filesystem limits. This can exceed PAGE_SIZE (currently, XATTR_SIZE_MAX
2004 * is 64k). Since there is no kvec- or page-based interface to xattrs,
2005 * and we're not dealing with contiguous pages, we need to do some copying.
2009 * Decode data into buffer.
2012 nfsd4_vbuf_from_vector(struct nfsd4_compoundargs
*argp
, struct xdr_buf
*xdr
,
2013 char **bufp
, u32 buflen
)
2015 struct page
**pages
= xdr
->pages
;
2016 struct kvec
*head
= xdr
->head
;
2020 if (buflen
<= head
->iov_len
) {
2022 * We're in luck, the head has enough space. Just return
2023 * the head, no need for copying.
2025 *bufp
= head
->iov_base
;
2029 tmp
= svcxdr_tmpalloc(argp
, buflen
);
2031 return nfserr_jukebox
;
2034 memcpy(dp
, head
->iov_base
, head
->iov_len
);
2035 buflen
-= head
->iov_len
;
2036 dp
+= head
->iov_len
;
2038 while (buflen
> 0) {
2039 len
= min_t(u32
, buflen
, PAGE_SIZE
);
2040 memcpy(dp
, page_address(*pages
), len
);
2052 * Get a user extended attribute name from the XDR buffer.
2053 * It will not have the "user." prefix, so prepend it.
2054 * Lastly, check for nul characters in the name.
2057 nfsd4_decode_xattr_name(struct nfsd4_compoundargs
*argp
, char **namep
)
2059 char *name
, *sp
, *dp
;
2063 if (xdr_stream_decode_u32(argp
->xdr
, &namelen
) < 0)
2064 return nfserr_bad_xdr
;
2065 if (namelen
> (XATTR_NAME_MAX
- XATTR_USER_PREFIX_LEN
))
2066 return nfserr_nametoolong
;
2068 return nfserr_bad_xdr
;
2069 p
= xdr_inline_decode(argp
->xdr
, namelen
);
2071 return nfserr_bad_xdr
;
2072 name
= svcxdr_tmpalloc(argp
, namelen
+ XATTR_USER_PREFIX_LEN
+ 1);
2074 return nfserr_jukebox
;
2075 memcpy(name
, XATTR_USER_PREFIX
, XATTR_USER_PREFIX_LEN
);
2078 * Copy the extended attribute name over while checking for 0
2082 dp
= name
+ XATTR_USER_PREFIX_LEN
;
2087 return nfserr_bad_xdr
;
2098 * A GETXATTR op request comes without a length specifier. We just set the
2099 * maximum length for the reply based on XATTR_SIZE_MAX and the maximum
2100 * channel reply size. nfsd_getxattr will probe the length of the xattr,
2101 * check it against getxa_len, and allocate + return the value.
2104 nfsd4_decode_getxattr(struct nfsd4_compoundargs
*argp
,
2105 struct nfsd4_getxattr
*getxattr
)
2110 status
= nfsd4_decode_xattr_name(argp
, &getxattr
->getxa_name
);
2114 maxcount
= svc_max_payload(argp
->rqstp
);
2115 maxcount
= min_t(u32
, XATTR_SIZE_MAX
, maxcount
);
2117 getxattr
->getxa_len
= maxcount
;
2123 nfsd4_decode_setxattr(struct nfsd4_compoundargs
*argp
,
2124 struct nfsd4_setxattr
*setxattr
)
2126 u32 flags
, maxcount
, size
;
2129 if (xdr_stream_decode_u32(argp
->xdr
, &flags
) < 0)
2130 return nfserr_bad_xdr
;
2132 if (flags
> SETXATTR4_REPLACE
)
2133 return nfserr_inval
;
2134 setxattr
->setxa_flags
= flags
;
2136 status
= nfsd4_decode_xattr_name(argp
, &setxattr
->setxa_name
);
2140 maxcount
= svc_max_payload(argp
->rqstp
);
2141 maxcount
= min_t(u32
, XATTR_SIZE_MAX
, maxcount
);
2143 if (xdr_stream_decode_u32(argp
->xdr
, &size
) < 0)
2144 return nfserr_bad_xdr
;
2145 if (size
> maxcount
)
2146 return nfserr_xattr2big
;
2148 setxattr
->setxa_len
= size
;
2150 struct xdr_buf payload
;
2152 if (!xdr_stream_subsegment(argp
->xdr
, &payload
, size
))
2153 return nfserr_bad_xdr
;
2154 status
= nfsd4_vbuf_from_vector(argp
, &payload
,
2155 &setxattr
->setxa_buf
, size
);
2162 nfsd4_decode_listxattrs(struct nfsd4_compoundargs
*argp
,
2163 struct nfsd4_listxattrs
*listxattrs
)
2167 if (xdr_stream_decode_u64(argp
->xdr
, &listxattrs
->lsxa_cookie
) < 0)
2168 return nfserr_bad_xdr
;
2171 * If the cookie is too large to have even one user.x attribute
2172 * plus trailing '\0' left in a maximum size buffer, it's invalid.
2174 if (listxattrs
->lsxa_cookie
>=
2175 (XATTR_LIST_MAX
/ (XATTR_USER_PREFIX_LEN
+ 2)))
2176 return nfserr_badcookie
;
2178 if (xdr_stream_decode_u32(argp
->xdr
, &maxcount
) < 0)
2179 return nfserr_bad_xdr
;
2181 /* Always need at least 2 words (length and one character) */
2182 return nfserr_inval
;
2184 maxcount
= min(maxcount
, svc_max_payload(argp
->rqstp
));
2185 listxattrs
->lsxa_maxcount
= maxcount
;
2191 nfsd4_decode_removexattr(struct nfsd4_compoundargs
*argp
,
2192 struct nfsd4_removexattr
*removexattr
)
2194 return nfsd4_decode_xattr_name(argp
, &removexattr
->rmxa_name
);
2198 nfsd4_decode_noop(struct nfsd4_compoundargs
*argp
, void *p
)
2204 nfsd4_decode_notsupp(struct nfsd4_compoundargs
*argp
, void *p
)
2206 return nfserr_notsupp
;
2209 typedef __be32(*nfsd4_dec
)(struct nfsd4_compoundargs
*argp
, void *);
2211 static const nfsd4_dec nfsd4_dec_ops
[] = {
2212 [OP_ACCESS
] = (nfsd4_dec
)nfsd4_decode_access
,
2213 [OP_CLOSE
] = (nfsd4_dec
)nfsd4_decode_close
,
2214 [OP_COMMIT
] = (nfsd4_dec
)nfsd4_decode_commit
,
2215 [OP_CREATE
] = (nfsd4_dec
)nfsd4_decode_create
,
2216 [OP_DELEGPURGE
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2217 [OP_DELEGRETURN
] = (nfsd4_dec
)nfsd4_decode_delegreturn
,
2218 [OP_GETATTR
] = (nfsd4_dec
)nfsd4_decode_getattr
,
2219 [OP_GETFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
2220 [OP_LINK
] = (nfsd4_dec
)nfsd4_decode_link
,
2221 [OP_LOCK
] = (nfsd4_dec
)nfsd4_decode_lock
,
2222 [OP_LOCKT
] = (nfsd4_dec
)nfsd4_decode_lockt
,
2223 [OP_LOCKU
] = (nfsd4_dec
)nfsd4_decode_locku
,
2224 [OP_LOOKUP
] = (nfsd4_dec
)nfsd4_decode_lookup
,
2225 [OP_LOOKUPP
] = (nfsd4_dec
)nfsd4_decode_noop
,
2226 [OP_NVERIFY
] = (nfsd4_dec
)nfsd4_decode_verify
,
2227 [OP_OPEN
] = (nfsd4_dec
)nfsd4_decode_open
,
2228 [OP_OPENATTR
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2229 [OP_OPEN_CONFIRM
] = (nfsd4_dec
)nfsd4_decode_open_confirm
,
2230 [OP_OPEN_DOWNGRADE
] = (nfsd4_dec
)nfsd4_decode_open_downgrade
,
2231 [OP_PUTFH
] = (nfsd4_dec
)nfsd4_decode_putfh
,
2232 [OP_PUTPUBFH
] = (nfsd4_dec
)nfsd4_decode_putpubfh
,
2233 [OP_PUTROOTFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
2234 [OP_READ
] = (nfsd4_dec
)nfsd4_decode_read
,
2235 [OP_READDIR
] = (nfsd4_dec
)nfsd4_decode_readdir
,
2236 [OP_READLINK
] = (nfsd4_dec
)nfsd4_decode_noop
,
2237 [OP_REMOVE
] = (nfsd4_dec
)nfsd4_decode_remove
,
2238 [OP_RENAME
] = (nfsd4_dec
)nfsd4_decode_rename
,
2239 [OP_RENEW
] = (nfsd4_dec
)nfsd4_decode_renew
,
2240 [OP_RESTOREFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
2241 [OP_SAVEFH
] = (nfsd4_dec
)nfsd4_decode_noop
,
2242 [OP_SECINFO
] = (nfsd4_dec
)nfsd4_decode_secinfo
,
2243 [OP_SETATTR
] = (nfsd4_dec
)nfsd4_decode_setattr
,
2244 [OP_SETCLIENTID
] = (nfsd4_dec
)nfsd4_decode_setclientid
,
2245 [OP_SETCLIENTID_CONFIRM
] = (nfsd4_dec
)nfsd4_decode_setclientid_confirm
,
2246 [OP_VERIFY
] = (nfsd4_dec
)nfsd4_decode_verify
,
2247 [OP_WRITE
] = (nfsd4_dec
)nfsd4_decode_write
,
2248 [OP_RELEASE_LOCKOWNER
] = (nfsd4_dec
)nfsd4_decode_release_lockowner
,
2250 /* new operations for NFSv4.1 */
2251 [OP_BACKCHANNEL_CTL
] = (nfsd4_dec
)nfsd4_decode_backchannel_ctl
,
2252 [OP_BIND_CONN_TO_SESSION
]= (nfsd4_dec
)nfsd4_decode_bind_conn_to_session
,
2253 [OP_EXCHANGE_ID
] = (nfsd4_dec
)nfsd4_decode_exchange_id
,
2254 [OP_CREATE_SESSION
] = (nfsd4_dec
)nfsd4_decode_create_session
,
2255 [OP_DESTROY_SESSION
] = (nfsd4_dec
)nfsd4_decode_destroy_session
,
2256 [OP_FREE_STATEID
] = (nfsd4_dec
)nfsd4_decode_free_stateid
,
2257 [OP_GET_DIR_DELEGATION
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2258 #ifdef CONFIG_NFSD_PNFS
2259 [OP_GETDEVICEINFO
] = (nfsd4_dec
)nfsd4_decode_getdeviceinfo
,
2260 [OP_GETDEVICELIST
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2261 [OP_LAYOUTCOMMIT
] = (nfsd4_dec
)nfsd4_decode_layoutcommit
,
2262 [OP_LAYOUTGET
] = (nfsd4_dec
)nfsd4_decode_layoutget
,
2263 [OP_LAYOUTRETURN
] = (nfsd4_dec
)nfsd4_decode_layoutreturn
,
2265 [OP_GETDEVICEINFO
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2266 [OP_GETDEVICELIST
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2267 [OP_LAYOUTCOMMIT
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2268 [OP_LAYOUTGET
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2269 [OP_LAYOUTRETURN
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2271 [OP_SECINFO_NO_NAME
] = (nfsd4_dec
)nfsd4_decode_secinfo_no_name
,
2272 [OP_SEQUENCE
] = (nfsd4_dec
)nfsd4_decode_sequence
,
2273 [OP_SET_SSV
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2274 [OP_TEST_STATEID
] = (nfsd4_dec
)nfsd4_decode_test_stateid
,
2275 [OP_WANT_DELEGATION
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2276 [OP_DESTROY_CLIENTID
] = (nfsd4_dec
)nfsd4_decode_destroy_clientid
,
2277 [OP_RECLAIM_COMPLETE
] = (nfsd4_dec
)nfsd4_decode_reclaim_complete
,
2279 /* new operations for NFSv4.2 */
2280 [OP_ALLOCATE
] = (nfsd4_dec
)nfsd4_decode_fallocate
,
2281 [OP_COPY
] = (nfsd4_dec
)nfsd4_decode_copy
,
2282 [OP_COPY_NOTIFY
] = (nfsd4_dec
)nfsd4_decode_copy_notify
,
2283 [OP_DEALLOCATE
] = (nfsd4_dec
)nfsd4_decode_fallocate
,
2284 [OP_IO_ADVISE
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2285 [OP_LAYOUTERROR
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2286 [OP_LAYOUTSTATS
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2287 [OP_OFFLOAD_CANCEL
] = (nfsd4_dec
)nfsd4_decode_offload_status
,
2288 [OP_OFFLOAD_STATUS
] = (nfsd4_dec
)nfsd4_decode_offload_status
,
2289 [OP_READ_PLUS
] = (nfsd4_dec
)nfsd4_decode_read
,
2290 [OP_SEEK
] = (nfsd4_dec
)nfsd4_decode_seek
,
2291 [OP_WRITE_SAME
] = (nfsd4_dec
)nfsd4_decode_notsupp
,
2292 [OP_CLONE
] = (nfsd4_dec
)nfsd4_decode_clone
,
2293 /* RFC 8276 extended atributes operations */
2294 [OP_GETXATTR
] = (nfsd4_dec
)nfsd4_decode_getxattr
,
2295 [OP_SETXATTR
] = (nfsd4_dec
)nfsd4_decode_setxattr
,
2296 [OP_LISTXATTRS
] = (nfsd4_dec
)nfsd4_decode_listxattrs
,
2297 [OP_REMOVEXATTR
] = (nfsd4_dec
)nfsd4_decode_removexattr
,
2301 nfsd4_opnum_in_range(struct nfsd4_compoundargs
*argp
, struct nfsd4_op
*op
)
2303 if (op
->opnum
< FIRST_NFS4_OP
)
2305 else if (argp
->minorversion
== 0 && op
->opnum
> LAST_NFS40_OP
)
2307 else if (argp
->minorversion
== 1 && op
->opnum
> LAST_NFS41_OP
)
2309 else if (argp
->minorversion
== 2 && op
->opnum
> LAST_NFS42_OP
)
2315 nfsd4_decode_compound(struct nfsd4_compoundargs
*argp
)
2317 struct nfsd4_op
*op
;
2318 bool cachethis
= false;
2319 int auth_slack
= argp
->rqstp
->rq_auth_slack
;
2320 int max_reply
= auth_slack
+ 8; /* opcnt, status */
2326 if (xdr_stream_decode_u32(argp
->xdr
, &argp
->taglen
) < 0)
2328 max_reply
+= XDR_UNIT
;
2330 if (unlikely(argp
->taglen
)) {
2331 if (argp
->taglen
> NFSD4_MAX_TAGLEN
)
2333 p
= xdr_inline_decode(argp
->xdr
, argp
->taglen
);
2336 argp
->tag
= svcxdr_tmpalloc(argp
, argp
->taglen
);
2339 memcpy(argp
->tag
, p
, argp
->taglen
);
2340 max_reply
+= xdr_align_size(argp
->taglen
);
2343 if (xdr_stream_decode_u32(argp
->xdr
, &argp
->minorversion
) < 0)
2345 if (xdr_stream_decode_u32(argp
->xdr
, &argp
->opcnt
) < 0)
2349 * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS
2350 * here, so we return success at the xdr level so that
2351 * nfsd4_proc can handle this is an NFS-level error.
2353 if (argp
->opcnt
> NFSD_MAX_OPS_PER_COMPOUND
)
2356 if (argp
->opcnt
> ARRAY_SIZE(argp
->iops
)) {
2357 argp
->ops
= kzalloc(argp
->opcnt
* sizeof(*argp
->ops
), GFP_KERNEL
);
2359 argp
->ops
= argp
->iops
;
2360 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
2365 if (argp
->minorversion
> NFSD_SUPPORTED_MINOR_VERSION
)
2368 for (i
= 0; i
< argp
->opcnt
; i
++) {
2372 if (xdr_stream_decode_u32(argp
->xdr
, &op
->opnum
) < 0)
2374 if (nfsd4_opnum_in_range(argp
, op
)) {
2375 op
->status
= nfsd4_dec_ops
[op
->opnum
](argp
, &op
->u
);
2376 if (op
->status
!= nfs_ok
)
2377 trace_nfsd_compound_decode_err(argp
->rqstp
,
2382 op
->opnum
= OP_ILLEGAL
;
2383 op
->status
= nfserr_op_illegal
;
2385 op
->opdesc
= OPDESC(op
);
2387 * We'll try to cache the result in the DRC if any one
2388 * op in the compound wants to be cached:
2390 cachethis
|= nfsd4_cache_this_op(op
);
2392 if (op
->opnum
== OP_READ
|| op
->opnum
== OP_READ_PLUS
) {
2394 readbytes
+= nfsd4_max_reply(argp
->rqstp
, op
);
2396 max_reply
+= nfsd4_max_reply(argp
->rqstp
, op
);
2398 * OP_LOCK and OP_LOCKT may return a conflicting lock.
2399 * (Special case because it will just skip encoding this
2400 * if it runs out of xdr buffer space, and it is the only
2401 * operation that behaves this way.)
2403 if (op
->opnum
== OP_LOCK
|| op
->opnum
== OP_LOCKT
)
2404 max_reply
+= NFS4_OPAQUE_LIMIT
;
2411 /* Sessions make the DRC unnecessary: */
2412 if (argp
->minorversion
)
2414 svc_reserve(argp
->rqstp
, max_reply
+ readbytes
);
2415 argp
->rqstp
->rq_cachetype
= cachethis
? RC_REPLBUFF
: RC_NOCACHE
;
2417 if (readcount
> 1 || max_reply
> PAGE_SIZE
- auth_slack
)
2418 clear_bit(RQ_SPLICE_OK
, &argp
->rqstp
->rq_flags
);
2423 static __be32
*encode_change(__be32
*p
, struct kstat
*stat
, struct inode
*inode
,
2424 struct svc_export
*exp
)
2426 if (exp
->ex_flags
& NFSEXP_V4ROOT
) {
2427 *p
++ = cpu_to_be32(convert_to_wallclock(exp
->cd
->flush_time
));
2430 p
= xdr_encode_hyper(p
, nfsd4_change_attribute(stat
, inode
));
2435 * ctime (in NFSv4, time_metadata) is not writeable, and the client
2436 * doesn't really care what resolution could theoretically be stored by
2439 * The client cares how close together changes can be while still
2440 * guaranteeing ctime changes. For most filesystems (which have
2441 * timestamps with nanosecond fields) that is limited by the resolution
2442 * of the time returned from current_time() (which I'm assuming to be
2445 static __be32
*encode_time_delta(__be32
*p
, struct inode
*inode
)
2447 struct timespec64 ts
;
2450 ns
= max_t(u32
, NSEC_PER_SEC
/HZ
, inode
->i_sb
->s_time_gran
);
2451 ts
= ns_to_timespec64(ns
);
2453 p
= xdr_encode_hyper(p
, ts
.tv_sec
);
2454 *p
++ = cpu_to_be32(ts
.tv_nsec
);
2459 static __be32
*encode_cinfo(__be32
*p
, struct nfsd4_change_info
*c
)
2461 *p
++ = cpu_to_be32(c
->atomic
);
2462 p
= xdr_encode_hyper(p
, c
->before_change
);
2463 p
= xdr_encode_hyper(p
, c
->after_change
);
2467 /* Encode as an array of strings the string given with components
2468 * separated @sep, escaped with esc_enter and esc_exit.
2470 static __be32
nfsd4_encode_components_esc(struct xdr_stream
*xdr
, char sep
,
2471 char *components
, char esc_enter
,
2477 int strlen
, count
=0;
2478 char *str
, *end
, *next
;
2480 dprintk("nfsd4_encode_components(%s)\n", components
);
2482 pathlen_offset
= xdr
->buf
->len
;
2483 p
= xdr_reserve_space(xdr
, 4);
2485 return nfserr_resource
;
2486 p
++; /* We will fill this in with @count later */
2488 end
= str
= components
;
2490 bool found_esc
= false;
2492 /* try to parse as esc_start, ..., esc_end, sep */
2493 if (*str
== esc_enter
) {
2494 for (; *end
&& (*end
!= esc_exit
); end
++)
2495 /* find esc_exit or end of string */;
2497 if (*end
&& (!*next
|| *next
== sep
)) {
2504 for (; *end
&& (*end
!= sep
); end
++)
2505 /* find sep or end of string */;
2509 p
= xdr_reserve_space(xdr
, strlen
+ 4);
2511 return nfserr_resource
;
2512 p
= xdr_encode_opaque(p
, str
, strlen
);
2522 pathlen
= htonl(count
);
2523 write_bytes_to_xdr_buf(xdr
->buf
, pathlen_offset
, &pathlen
, 4);
2527 /* Encode as an array of strings the string given with components
2530 static __be32
nfsd4_encode_components(struct xdr_stream
*xdr
, char sep
,
2533 return nfsd4_encode_components_esc(xdr
, sep
, components
, 0, 0);
2537 * encode a location element of a fs_locations structure
2539 static __be32
nfsd4_encode_fs_location4(struct xdr_stream
*xdr
,
2540 struct nfsd4_fs_location
*location
)
2544 status
= nfsd4_encode_components_esc(xdr
, ':', location
->hosts
,
2548 status
= nfsd4_encode_components(xdr
, '/', location
->path
);
2555 * Encode a path in RFC3530 'pathname4' format
2557 static __be32
nfsd4_encode_path(struct xdr_stream
*xdr
,
2558 const struct path
*root
,
2559 const struct path
*path
)
2561 struct path cur
= *path
;
2563 struct dentry
**components
= NULL
;
2564 unsigned int ncomponents
= 0;
2565 __be32 err
= nfserr_jukebox
;
2567 dprintk("nfsd4_encode_components(");
2570 /* First walk the path up to the nfsd root, and store the
2571 * dentries/path components in an array.
2574 if (path_equal(&cur
, root
))
2576 if (cur
.dentry
== cur
.mnt
->mnt_root
) {
2577 if (follow_up(&cur
))
2581 if ((ncomponents
& 15) == 0) {
2582 struct dentry
**new;
2583 new = krealloc(components
,
2584 sizeof(*new) * (ncomponents
+ 16),
2590 components
[ncomponents
++] = cur
.dentry
;
2591 cur
.dentry
= dget_parent(cur
.dentry
);
2593 err
= nfserr_resource
;
2594 p
= xdr_reserve_space(xdr
, 4);
2597 *p
++ = cpu_to_be32(ncomponents
);
2599 while (ncomponents
) {
2600 struct dentry
*dentry
= components
[ncomponents
- 1];
2603 spin_lock(&dentry
->d_lock
);
2604 len
= dentry
->d_name
.len
;
2605 p
= xdr_reserve_space(xdr
, len
+ 4);
2607 spin_unlock(&dentry
->d_lock
);
2610 p
= xdr_encode_opaque(p
, dentry
->d_name
.name
, len
);
2611 dprintk("/%pd", dentry
);
2612 spin_unlock(&dentry
->d_lock
);
2621 dput(components
[--ncomponents
]);
2627 static __be32
nfsd4_encode_fsloc_fsroot(struct xdr_stream
*xdr
,
2628 struct svc_rqst
*rqstp
, const struct path
*path
)
2630 struct svc_export
*exp_ps
;
2633 exp_ps
= rqst_find_fsidzero_export(rqstp
);
2635 return nfserrno(PTR_ERR(exp_ps
));
2636 res
= nfsd4_encode_path(xdr
, &exp_ps
->ex_path
, path
);
2642 * encode a fs_locations structure
2644 static __be32
nfsd4_encode_fs_locations(struct xdr_stream
*xdr
,
2645 struct svc_rqst
*rqstp
, struct svc_export
*exp
)
2650 struct nfsd4_fs_locations
*fslocs
= &exp
->ex_fslocs
;
2652 status
= nfsd4_encode_fsloc_fsroot(xdr
, rqstp
, &exp
->ex_path
);
2655 p
= xdr_reserve_space(xdr
, 4);
2657 return nfserr_resource
;
2658 *p
++ = cpu_to_be32(fslocs
->locations_count
);
2659 for (i
=0; i
<fslocs
->locations_count
; i
++) {
2660 status
= nfsd4_encode_fs_location4(xdr
, &fslocs
->locations
[i
]);
2667 static u32
nfs4_file_type(umode_t mode
)
2669 switch (mode
& S_IFMT
) {
2670 case S_IFIFO
: return NF4FIFO
;
2671 case S_IFCHR
: return NF4CHR
;
2672 case S_IFDIR
: return NF4DIR
;
2673 case S_IFBLK
: return NF4BLK
;
2674 case S_IFLNK
: return NF4LNK
;
2675 case S_IFREG
: return NF4REG
;
2676 case S_IFSOCK
: return NF4SOCK
;
2677 default: return NF4BAD
;
2681 static inline __be32
2682 nfsd4_encode_aclname(struct xdr_stream
*xdr
, struct svc_rqst
*rqstp
,
2683 struct nfs4_ace
*ace
)
2685 if (ace
->whotype
!= NFS4_ACL_WHO_NAMED
)
2686 return nfs4_acl_write_who(xdr
, ace
->whotype
);
2687 else if (ace
->flag
& NFS4_ACE_IDENTIFIER_GROUP
)
2688 return nfsd4_encode_group(xdr
, rqstp
, ace
->who_gid
);
2690 return nfsd4_encode_user(xdr
, rqstp
, ace
->who_uid
);
2693 static inline __be32
2694 nfsd4_encode_layout_types(struct xdr_stream
*xdr
, u32 layout_types
)
2697 unsigned long i
= hweight_long(layout_types
);
2699 p
= xdr_reserve_space(xdr
, 4 + 4 * i
);
2701 return nfserr_resource
;
2703 *p
++ = cpu_to_be32(i
);
2705 for (i
= LAYOUT_NFSV4_1_FILES
; i
< LAYOUT_TYPE_MAX
; ++i
)
2706 if (layout_types
& (1 << i
))
2707 *p
++ = cpu_to_be32(i
);
2712 #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
2713 FATTR4_WORD0_RDATTR_ERROR)
2714 #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
2715 #define WORD2_ABSENT_FS_ATTRS 0
2717 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2718 static inline __be32
2719 nfsd4_encode_security_label(struct xdr_stream
*xdr
, struct svc_rqst
*rqstp
,
2720 void *context
, int len
)
2724 p
= xdr_reserve_space(xdr
, len
+ 4 + 4 + 4);
2726 return nfserr_resource
;
2729 * For now we use a 0 here to indicate the null translation; in
2730 * the future we may place a call to translation code here.
2732 *p
++ = cpu_to_be32(0); /* lfs */
2733 *p
++ = cpu_to_be32(0); /* pi */
2734 p
= xdr_encode_opaque(p
, context
, len
);
2738 static inline __be32
2739 nfsd4_encode_security_label(struct xdr_stream
*xdr
, struct svc_rqst
*rqstp
,
2740 void *context
, int len
)
2744 static __be32
fattr_handle_absent_fs(u32
*bmval0
, u32
*bmval1
, u32
*bmval2
, u32
*rdattr_err
)
2746 /* As per referral draft: */
2747 if (*bmval0
& ~WORD0_ABSENT_FS_ATTRS
||
2748 *bmval1
& ~WORD1_ABSENT_FS_ATTRS
) {
2749 if (*bmval0
& FATTR4_WORD0_RDATTR_ERROR
||
2750 *bmval0
& FATTR4_WORD0_FS_LOCATIONS
)
2751 *rdattr_err
= NFSERR_MOVED
;
2753 return nfserr_moved
;
2755 *bmval0
&= WORD0_ABSENT_FS_ATTRS
;
2756 *bmval1
&= WORD1_ABSENT_FS_ATTRS
;
2757 *bmval2
&= WORD2_ABSENT_FS_ATTRS
;
2762 static int get_parent_attributes(struct svc_export
*exp
, struct kstat
*stat
)
2764 struct path path
= exp
->ex_path
;
2768 while (follow_up(&path
)) {
2769 if (path
.dentry
!= path
.mnt
->mnt_root
)
2772 err
= vfs_getattr(&path
, stat
, STATX_BASIC_STATS
, AT_STATX_SYNC_AS_STAT
);
2778 nfsd4_encode_bitmap(struct xdr_stream
*xdr
, u32 bmval0
, u32 bmval1
, u32 bmval2
)
2783 p
= xdr_reserve_space(xdr
, 16);
2786 *p
++ = cpu_to_be32(3);
2787 *p
++ = cpu_to_be32(bmval0
);
2788 *p
++ = cpu_to_be32(bmval1
);
2789 *p
++ = cpu_to_be32(bmval2
);
2790 } else if (bmval1
) {
2791 p
= xdr_reserve_space(xdr
, 12);
2794 *p
++ = cpu_to_be32(2);
2795 *p
++ = cpu_to_be32(bmval0
);
2796 *p
++ = cpu_to_be32(bmval1
);
2798 p
= xdr_reserve_space(xdr
, 8);
2801 *p
++ = cpu_to_be32(1);
2802 *p
++ = cpu_to_be32(bmval0
);
2807 return nfserr_resource
;
2811 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
2815 nfsd4_encode_fattr(struct xdr_stream
*xdr
, struct svc_fh
*fhp
,
2816 struct svc_export
*exp
,
2817 struct dentry
*dentry
, u32
*bmval
,
2818 struct svc_rqst
*rqstp
, int ignore_crossmnt
)
2820 u32 bmval0
= bmval
[0];
2821 u32 bmval1
= bmval
[1];
2822 u32 bmval2
= bmval
[2];
2824 struct svc_fh
*tempfh
= NULL
;
2825 struct kstatfs statfs
;
2827 int starting_len
= xdr
->buf
->len
;
2835 struct nfs4_acl
*acl
= NULL
;
2836 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2837 void *context
= NULL
;
2840 bool contextsupport
= false;
2841 struct nfsd4_compoundres
*resp
= rqstp
->rq_resp
;
2842 u32 minorversion
= resp
->cstate
.minorversion
;
2843 struct path path
= {
2844 .mnt
= exp
->ex_path
.mnt
,
2847 struct nfsd_net
*nn
= net_generic(SVC_NET(rqstp
), nfsd_net_id
);
2849 BUG_ON(bmval1
& NFSD_WRITEONLY_ATTRS_WORD1
);
2850 BUG_ON(!nfsd_attrs_supported(minorversion
, bmval
));
2852 if (exp
->ex_fslocs
.migrated
) {
2853 status
= fattr_handle_absent_fs(&bmval0
, &bmval1
, &bmval2
, &rdattr_err
);
2858 err
= vfs_getattr(&path
, &stat
, STATX_BASIC_STATS
, AT_STATX_SYNC_AS_STAT
);
2861 if ((bmval0
& (FATTR4_WORD0_FILES_AVAIL
| FATTR4_WORD0_FILES_FREE
|
2862 FATTR4_WORD0_FILES_TOTAL
| FATTR4_WORD0_MAXNAME
)) ||
2863 (bmval1
& (FATTR4_WORD1_SPACE_AVAIL
| FATTR4_WORD1_SPACE_FREE
|
2864 FATTR4_WORD1_SPACE_TOTAL
))) {
2865 err
= vfs_statfs(&path
, &statfs
);
2869 if ((bmval0
& (FATTR4_WORD0_FILEHANDLE
| FATTR4_WORD0_FSID
)) && !fhp
) {
2870 tempfh
= kmalloc(sizeof(struct svc_fh
), GFP_KERNEL
);
2871 status
= nfserr_jukebox
;
2874 fh_init(tempfh
, NFS4_FHSIZE
);
2875 status
= fh_compose(tempfh
, exp
, dentry
, NULL
);
2880 if (bmval0
& FATTR4_WORD0_ACL
) {
2881 err
= nfsd4_get_nfs4_acl(rqstp
, dentry
, &acl
);
2882 if (err
== -EOPNOTSUPP
)
2883 bmval0
&= ~FATTR4_WORD0_ACL
;
2884 else if (err
== -EINVAL
) {
2885 status
= nfserr_attrnotsupp
;
2887 } else if (err
!= 0)
2891 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2892 if ((bmval2
& FATTR4_WORD2_SECURITY_LABEL
) ||
2893 bmval0
& FATTR4_WORD0_SUPPORTED_ATTRS
) {
2894 if (exp
->ex_flags
& NFSEXP_SECURITY_LABEL
)
2895 err
= security_inode_getsecctx(d_inode(dentry
),
2896 &context
, &contextlen
);
2899 contextsupport
= (err
== 0);
2900 if (bmval2
& FATTR4_WORD2_SECURITY_LABEL
) {
2901 if (err
== -EOPNOTSUPP
)
2902 bmval2
&= ~FATTR4_WORD2_SECURITY_LABEL
;
2907 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
2909 status
= nfsd4_encode_bitmap(xdr
, bmval0
, bmval1
, bmval2
);
2913 attrlen_offset
= xdr
->buf
->len
;
2914 p
= xdr_reserve_space(xdr
, 4);
2917 p
++; /* to be backfilled later */
2919 if (bmval0
& FATTR4_WORD0_SUPPORTED_ATTRS
) {
2922 memcpy(supp
, nfsd_suppattrs
[minorversion
], sizeof(supp
));
2924 if (!IS_POSIXACL(dentry
->d_inode
))
2925 supp
[0] &= ~FATTR4_WORD0_ACL
;
2926 if (!contextsupport
)
2927 supp
[2] &= ~FATTR4_WORD2_SECURITY_LABEL
;
2929 p
= xdr_reserve_space(xdr
, 12);
2932 *p
++ = cpu_to_be32(2);
2933 *p
++ = cpu_to_be32(supp
[0]);
2934 *p
++ = cpu_to_be32(supp
[1]);
2936 p
= xdr_reserve_space(xdr
, 16);
2939 *p
++ = cpu_to_be32(3);
2940 *p
++ = cpu_to_be32(supp
[0]);
2941 *p
++ = cpu_to_be32(supp
[1]);
2942 *p
++ = cpu_to_be32(supp
[2]);
2945 if (bmval0
& FATTR4_WORD0_TYPE
) {
2946 p
= xdr_reserve_space(xdr
, 4);
2949 dummy
= nfs4_file_type(stat
.mode
);
2950 if (dummy
== NF4BAD
) {
2951 status
= nfserr_serverfault
;
2954 *p
++ = cpu_to_be32(dummy
);
2956 if (bmval0
& FATTR4_WORD0_FH_EXPIRE_TYPE
) {
2957 p
= xdr_reserve_space(xdr
, 4);
2960 if (exp
->ex_flags
& NFSEXP_NOSUBTREECHECK
)
2961 *p
++ = cpu_to_be32(NFS4_FH_PERSISTENT
);
2963 *p
++ = cpu_to_be32(NFS4_FH_PERSISTENT
|
2964 NFS4_FH_VOL_RENAME
);
2966 if (bmval0
& FATTR4_WORD0_CHANGE
) {
2967 p
= xdr_reserve_space(xdr
, 8);
2970 p
= encode_change(p
, &stat
, d_inode(dentry
), exp
);
2972 if (bmval0
& FATTR4_WORD0_SIZE
) {
2973 p
= xdr_reserve_space(xdr
, 8);
2976 p
= xdr_encode_hyper(p
, stat
.size
);
2978 if (bmval0
& FATTR4_WORD0_LINK_SUPPORT
) {
2979 p
= xdr_reserve_space(xdr
, 4);
2982 *p
++ = cpu_to_be32(1);
2984 if (bmval0
& FATTR4_WORD0_SYMLINK_SUPPORT
) {
2985 p
= xdr_reserve_space(xdr
, 4);
2988 *p
++ = cpu_to_be32(1);
2990 if (bmval0
& FATTR4_WORD0_NAMED_ATTR
) {
2991 p
= xdr_reserve_space(xdr
, 4);
2994 *p
++ = cpu_to_be32(0);
2996 if (bmval0
& FATTR4_WORD0_FSID
) {
2997 p
= xdr_reserve_space(xdr
, 16);
3000 if (exp
->ex_fslocs
.migrated
) {
3001 p
= xdr_encode_hyper(p
, NFS4_REFERRAL_FSID_MAJOR
);
3002 p
= xdr_encode_hyper(p
, NFS4_REFERRAL_FSID_MINOR
);
3003 } else switch(fsid_source(fhp
)) {
3004 case FSIDSOURCE_FSID
:
3005 p
= xdr_encode_hyper(p
, (u64
)exp
->ex_fsid
);
3006 p
= xdr_encode_hyper(p
, (u64
)0);
3008 case FSIDSOURCE_DEV
:
3009 *p
++ = cpu_to_be32(0);
3010 *p
++ = cpu_to_be32(MAJOR(stat
.dev
));
3011 *p
++ = cpu_to_be32(0);
3012 *p
++ = cpu_to_be32(MINOR(stat
.dev
));
3014 case FSIDSOURCE_UUID
:
3015 p
= xdr_encode_opaque_fixed(p
, exp
->ex_uuid
,
3020 if (bmval0
& FATTR4_WORD0_UNIQUE_HANDLES
) {
3021 p
= xdr_reserve_space(xdr
, 4);
3024 *p
++ = cpu_to_be32(0);
3026 if (bmval0
& FATTR4_WORD0_LEASE_TIME
) {
3027 p
= xdr_reserve_space(xdr
, 4);
3030 *p
++ = cpu_to_be32(nn
->nfsd4_lease
);
3032 if (bmval0
& FATTR4_WORD0_RDATTR_ERROR
) {
3033 p
= xdr_reserve_space(xdr
, 4);
3036 *p
++ = cpu_to_be32(rdattr_err
);
3038 if (bmval0
& FATTR4_WORD0_ACL
) {
3039 struct nfs4_ace
*ace
;
3042 p
= xdr_reserve_space(xdr
, 4);
3046 *p
++ = cpu_to_be32(0);
3049 p
= xdr_reserve_space(xdr
, 4);
3052 *p
++ = cpu_to_be32(acl
->naces
);
3054 for (ace
= acl
->aces
; ace
< acl
->aces
+ acl
->naces
; ace
++) {
3055 p
= xdr_reserve_space(xdr
, 4*3);
3058 *p
++ = cpu_to_be32(ace
->type
);
3059 *p
++ = cpu_to_be32(ace
->flag
);
3060 *p
++ = cpu_to_be32(ace
->access_mask
&
3062 status
= nfsd4_encode_aclname(xdr
, rqstp
, ace
);
3068 if (bmval0
& FATTR4_WORD0_ACLSUPPORT
) {
3069 p
= xdr_reserve_space(xdr
, 4);
3072 *p
++ = cpu_to_be32(IS_POSIXACL(dentry
->d_inode
) ?
3073 ACL4_SUPPORT_ALLOW_ACL
|ACL4_SUPPORT_DENY_ACL
: 0);
3075 if (bmval0
& FATTR4_WORD0_CANSETTIME
) {
3076 p
= xdr_reserve_space(xdr
, 4);
3079 *p
++ = cpu_to_be32(1);
3081 if (bmval0
& FATTR4_WORD0_CASE_INSENSITIVE
) {
3082 p
= xdr_reserve_space(xdr
, 4);
3085 *p
++ = cpu_to_be32(0);
3087 if (bmval0
& FATTR4_WORD0_CASE_PRESERVING
) {
3088 p
= xdr_reserve_space(xdr
, 4);
3091 *p
++ = cpu_to_be32(1);
3093 if (bmval0
& FATTR4_WORD0_CHOWN_RESTRICTED
) {
3094 p
= xdr_reserve_space(xdr
, 4);
3097 *p
++ = cpu_to_be32(1);
3099 if (bmval0
& FATTR4_WORD0_FILEHANDLE
) {
3100 p
= xdr_reserve_space(xdr
, fhp
->fh_handle
.fh_size
+ 4);
3103 p
= xdr_encode_opaque(p
, &fhp
->fh_handle
.fh_base
,
3104 fhp
->fh_handle
.fh_size
);
3106 if (bmval0
& FATTR4_WORD0_FILEID
) {
3107 p
= xdr_reserve_space(xdr
, 8);
3110 p
= xdr_encode_hyper(p
, stat
.ino
);
3112 if (bmval0
& FATTR4_WORD0_FILES_AVAIL
) {
3113 p
= xdr_reserve_space(xdr
, 8);
3116 p
= xdr_encode_hyper(p
, (u64
) statfs
.f_ffree
);
3118 if (bmval0
& FATTR4_WORD0_FILES_FREE
) {
3119 p
= xdr_reserve_space(xdr
, 8);
3122 p
= xdr_encode_hyper(p
, (u64
) statfs
.f_ffree
);
3124 if (bmval0
& FATTR4_WORD0_FILES_TOTAL
) {
3125 p
= xdr_reserve_space(xdr
, 8);
3128 p
= xdr_encode_hyper(p
, (u64
) statfs
.f_files
);
3130 if (bmval0
& FATTR4_WORD0_FS_LOCATIONS
) {
3131 status
= nfsd4_encode_fs_locations(xdr
, rqstp
, exp
);
3135 if (bmval0
& FATTR4_WORD0_HOMOGENEOUS
) {
3136 p
= xdr_reserve_space(xdr
, 4);
3139 *p
++ = cpu_to_be32(1);
3141 if (bmval0
& FATTR4_WORD0_MAXFILESIZE
) {
3142 p
= xdr_reserve_space(xdr
, 8);
3145 p
= xdr_encode_hyper(p
, exp
->ex_path
.mnt
->mnt_sb
->s_maxbytes
);
3147 if (bmval0
& FATTR4_WORD0_MAXLINK
) {
3148 p
= xdr_reserve_space(xdr
, 4);
3151 *p
++ = cpu_to_be32(255);
3153 if (bmval0
& FATTR4_WORD0_MAXNAME
) {
3154 p
= xdr_reserve_space(xdr
, 4);
3157 *p
++ = cpu_to_be32(statfs
.f_namelen
);
3159 if (bmval0
& FATTR4_WORD0_MAXREAD
) {
3160 p
= xdr_reserve_space(xdr
, 8);
3163 p
= xdr_encode_hyper(p
, (u64
) svc_max_payload(rqstp
));
3165 if (bmval0
& FATTR4_WORD0_MAXWRITE
) {
3166 p
= xdr_reserve_space(xdr
, 8);
3169 p
= xdr_encode_hyper(p
, (u64
) svc_max_payload(rqstp
));
3171 if (bmval1
& FATTR4_WORD1_MODE
) {
3172 p
= xdr_reserve_space(xdr
, 4);
3175 *p
++ = cpu_to_be32(stat
.mode
& S_IALLUGO
);
3177 if (bmval1
& FATTR4_WORD1_NO_TRUNC
) {
3178 p
= xdr_reserve_space(xdr
, 4);
3181 *p
++ = cpu_to_be32(1);
3183 if (bmval1
& FATTR4_WORD1_NUMLINKS
) {
3184 p
= xdr_reserve_space(xdr
, 4);
3187 *p
++ = cpu_to_be32(stat
.nlink
);
3189 if (bmval1
& FATTR4_WORD1_OWNER
) {
3190 status
= nfsd4_encode_user(xdr
, rqstp
, stat
.uid
);
3194 if (bmval1
& FATTR4_WORD1_OWNER_GROUP
) {
3195 status
= nfsd4_encode_group(xdr
, rqstp
, stat
.gid
);
3199 if (bmval1
& FATTR4_WORD1_RAWDEV
) {
3200 p
= xdr_reserve_space(xdr
, 8);
3203 *p
++ = cpu_to_be32((u32
) MAJOR(stat
.rdev
));
3204 *p
++ = cpu_to_be32((u32
) MINOR(stat
.rdev
));
3206 if (bmval1
& FATTR4_WORD1_SPACE_AVAIL
) {
3207 p
= xdr_reserve_space(xdr
, 8);
3210 dummy64
= (u64
)statfs
.f_bavail
* (u64
)statfs
.f_bsize
;
3211 p
= xdr_encode_hyper(p
, dummy64
);
3213 if (bmval1
& FATTR4_WORD1_SPACE_FREE
) {
3214 p
= xdr_reserve_space(xdr
, 8);
3217 dummy64
= (u64
)statfs
.f_bfree
* (u64
)statfs
.f_bsize
;
3218 p
= xdr_encode_hyper(p
, dummy64
);
3220 if (bmval1
& FATTR4_WORD1_SPACE_TOTAL
) {
3221 p
= xdr_reserve_space(xdr
, 8);
3224 dummy64
= (u64
)statfs
.f_blocks
* (u64
)statfs
.f_bsize
;
3225 p
= xdr_encode_hyper(p
, dummy64
);
3227 if (bmval1
& FATTR4_WORD1_SPACE_USED
) {
3228 p
= xdr_reserve_space(xdr
, 8);
3231 dummy64
= (u64
)stat
.blocks
<< 9;
3232 p
= xdr_encode_hyper(p
, dummy64
);
3234 if (bmval1
& FATTR4_WORD1_TIME_ACCESS
) {
3235 p
= xdr_reserve_space(xdr
, 12);
3238 p
= xdr_encode_hyper(p
, (s64
)stat
.atime
.tv_sec
);
3239 *p
++ = cpu_to_be32(stat
.atime
.tv_nsec
);
3241 if (bmval1
& FATTR4_WORD1_TIME_DELTA
) {
3242 p
= xdr_reserve_space(xdr
, 12);
3245 p
= encode_time_delta(p
, d_inode(dentry
));
3247 if (bmval1
& FATTR4_WORD1_TIME_METADATA
) {
3248 p
= xdr_reserve_space(xdr
, 12);
3251 p
= xdr_encode_hyper(p
, (s64
)stat
.ctime
.tv_sec
);
3252 *p
++ = cpu_to_be32(stat
.ctime
.tv_nsec
);
3254 if (bmval1
& FATTR4_WORD1_TIME_MODIFY
) {
3255 p
= xdr_reserve_space(xdr
, 12);
3258 p
= xdr_encode_hyper(p
, (s64
)stat
.mtime
.tv_sec
);
3259 *p
++ = cpu_to_be32(stat
.mtime
.tv_nsec
);
3261 if (bmval1
& FATTR4_WORD1_MOUNTED_ON_FILEID
) {
3262 struct kstat parent_stat
;
3265 p
= xdr_reserve_space(xdr
, 8);
3269 * Get parent's attributes if not ignoring crossmount
3270 * and this is the root of a cross-mounted filesystem.
3272 if (ignore_crossmnt
== 0 &&
3273 dentry
== exp
->ex_path
.mnt
->mnt_root
) {
3274 err
= get_parent_attributes(exp
, &parent_stat
);
3277 ino
= parent_stat
.ino
;
3279 p
= xdr_encode_hyper(p
, ino
);
3281 #ifdef CONFIG_NFSD_PNFS
3282 if (bmval1
& FATTR4_WORD1_FS_LAYOUT_TYPES
) {
3283 status
= nfsd4_encode_layout_types(xdr
, exp
->ex_layout_types
);
3288 if (bmval2
& FATTR4_WORD2_LAYOUT_TYPES
) {
3289 status
= nfsd4_encode_layout_types(xdr
, exp
->ex_layout_types
);
3294 if (bmval2
& FATTR4_WORD2_LAYOUT_BLKSIZE
) {
3295 p
= xdr_reserve_space(xdr
, 4);
3298 *p
++ = cpu_to_be32(stat
.blksize
);
3300 #endif /* CONFIG_NFSD_PNFS */
3301 if (bmval2
& FATTR4_WORD2_SUPPATTR_EXCLCREAT
) {
3304 memcpy(supp
, nfsd_suppattrs
[minorversion
], sizeof(supp
));
3305 supp
[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0
;
3306 supp
[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1
;
3307 supp
[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2
;
3309 status
= nfsd4_encode_bitmap(xdr
, supp
[0], supp
[1], supp
[2]);
3314 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
3315 if (bmval2
& FATTR4_WORD2_SECURITY_LABEL
) {
3316 status
= nfsd4_encode_security_label(xdr
, rqstp
, context
,
3323 if (bmval2
& FATTR4_WORD2_XATTR_SUPPORT
) {
3324 p
= xdr_reserve_space(xdr
, 4);
3327 err
= xattr_supported_namespace(d_inode(dentry
),
3329 *p
++ = cpu_to_be32(err
== 0);
3332 attrlen
= htonl(xdr
->buf
->len
- attrlen_offset
- 4);
3333 write_bytes_to_xdr_buf(xdr
->buf
, attrlen_offset
, &attrlen
, 4);
3337 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
3339 security_release_secctx(context
, contextlen
);
3340 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
3347 xdr_truncate_encode(xdr
, starting_len
);
3350 status
= nfserrno(err
);
3353 status
= nfserr_resource
;
3357 static void svcxdr_init_encode_from_buffer(struct xdr_stream
*xdr
,
3358 struct xdr_buf
*buf
, __be32
*p
, int bytes
)
3360 xdr
->scratch
.iov_len
= 0;
3361 memset(buf
, 0, sizeof(struct xdr_buf
));
3362 buf
->head
[0].iov_base
= p
;
3363 buf
->head
[0].iov_len
= 0;
3366 xdr
->iov
= buf
->head
;
3368 xdr
->end
= (void *)p
+ bytes
;
3369 buf
->buflen
= bytes
;
3372 __be32
nfsd4_encode_fattr_to_buf(__be32
**p
, int words
,
3373 struct svc_fh
*fhp
, struct svc_export
*exp
,
3374 struct dentry
*dentry
, u32
*bmval
,
3375 struct svc_rqst
*rqstp
, int ignore_crossmnt
)
3377 struct xdr_buf dummy
;
3378 struct xdr_stream xdr
;
3381 svcxdr_init_encode_from_buffer(&xdr
, &dummy
, *p
, words
<< 2);
3382 ret
= nfsd4_encode_fattr(&xdr
, fhp
, exp
, dentry
, bmval
, rqstp
,
3388 static inline int attributes_need_mount(u32
*bmval
)
3390 if (bmval
[0] & ~(FATTR4_WORD0_RDATTR_ERROR
| FATTR4_WORD0_LEASE_TIME
))
3392 if (bmval
[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID
)
3398 nfsd4_encode_dirent_fattr(struct xdr_stream
*xdr
, struct nfsd4_readdir
*cd
,
3399 const char *name
, int namlen
)
3401 struct svc_export
*exp
= cd
->rd_fhp
->fh_export
;
3402 struct dentry
*dentry
;
3404 int ignore_crossmnt
= 0;
3406 dentry
= lookup_positive_unlocked(name
, cd
->rd_fhp
->fh_dentry
, namlen
);
3408 return nfserrno(PTR_ERR(dentry
));
3412 * In the case of a mountpoint, the client may be asking for
3413 * attributes that are only properties of the underlying filesystem
3414 * as opposed to the cross-mounted file system. In such a case,
3415 * we will not follow the cross mount and will fill the attribtutes
3416 * directly from the mountpoint dentry.
3418 if (nfsd_mountpoint(dentry
, exp
)) {
3421 if (!(exp
->ex_flags
& NFSEXP_V4ROOT
)
3422 && !attributes_need_mount(cd
->rd_bmval
)) {
3423 ignore_crossmnt
= 1;
3427 * Why the heck aren't we just using nfsd_lookup??
3428 * Different "."/".." handling? Something else?
3429 * At least, add a comment here to explain....
3431 err
= nfsd_cross_mnt(cd
->rd_rqstp
, &dentry
, &exp
);
3433 nfserr
= nfserrno(err
);
3436 nfserr
= check_nfsd_access(exp
, cd
->rd_rqstp
);
3442 nfserr
= nfsd4_encode_fattr(xdr
, NULL
, exp
, dentry
, cd
->rd_bmval
,
3443 cd
->rd_rqstp
, ignore_crossmnt
);
3451 nfsd4_encode_rdattr_error(struct xdr_stream
*xdr
, __be32 nfserr
)
3455 p
= xdr_reserve_space(xdr
, 20);
3459 *p
++ = htonl(FATTR4_WORD0_RDATTR_ERROR
); /* bmval0 */
3460 *p
++ = htonl(0); /* bmval1 */
3462 *p
++ = htonl(4); /* attribute length */
3463 *p
++ = nfserr
; /* no htonl */
3468 nfsd4_encode_dirent(void *ccdv
, const char *name
, int namlen
,
3469 loff_t offset
, u64 ino
, unsigned int d_type
)
3471 struct readdir_cd
*ccd
= ccdv
;
3472 struct nfsd4_readdir
*cd
= container_of(ccd
, struct nfsd4_readdir
, common
);
3473 struct xdr_stream
*xdr
= cd
->xdr
;
3474 int start_offset
= xdr
->buf
->len
;
3476 u32 name_and_cookie
;
3478 __be32 nfserr
= nfserr_toosmall
;
3482 /* In nfsv4, "." and ".." never make it onto the wire.. */
3483 if (name
&& isdotent(name
, namlen
)) {
3484 cd
->common
.err
= nfs_ok
;
3488 if (cd
->cookie_offset
) {
3489 wire_offset
= cpu_to_be64(offset
);
3490 write_bytes_to_xdr_buf(xdr
->buf
, cd
->cookie_offset
,
3494 p
= xdr_reserve_space(xdr
, 4);
3497 *p
++ = xdr_one
; /* mark entry present */
3498 cookie_offset
= xdr
->buf
->len
;
3499 p
= xdr_reserve_space(xdr
, 3*4 + namlen
);
3502 p
= xdr_encode_hyper(p
, NFS_OFFSET_MAX
); /* offset of next entry */
3503 p
= xdr_encode_array(p
, name
, namlen
); /* name length & name */
3505 nfserr
= nfsd4_encode_dirent_fattr(xdr
, cd
, name
, namlen
);
3509 case nfserr_resource
:
3510 nfserr
= nfserr_toosmall
;
3513 xdr_truncate_encode(xdr
, start_offset
);
3517 * If the client requested the RDATTR_ERROR attribute,
3518 * we stuff the error code into this attribute
3519 * and continue. If this attribute was not requested,
3520 * then in accordance with the spec, we fail the
3521 * entire READDIR operation(!)
3523 if (!(cd
->rd_bmval
[0] & FATTR4_WORD0_RDATTR_ERROR
))
3525 p
= nfsd4_encode_rdattr_error(xdr
, nfserr
);
3527 nfserr
= nfserr_toosmall
;
3531 nfserr
= nfserr_toosmall
;
3532 entry_bytes
= xdr
->buf
->len
- start_offset
;
3533 if (entry_bytes
> cd
->rd_maxcount
)
3535 cd
->rd_maxcount
-= entry_bytes
;
3537 * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so
3538 * let's always let through the first entry, at least:
3540 if (!cd
->rd_dircount
)
3542 name_and_cookie
= 4 + 4 * XDR_QUADLEN(namlen
) + 8;
3543 if (name_and_cookie
> cd
->rd_dircount
&& cd
->cookie_offset
)
3545 cd
->rd_dircount
-= min(cd
->rd_dircount
, name_and_cookie
);
3547 cd
->cookie_offset
= cookie_offset
;
3549 cd
->common
.err
= nfs_ok
;
3552 xdr_truncate_encode(xdr
, start_offset
);
3553 cd
->common
.err
= nfserr
;
3558 nfsd4_encode_stateid(struct xdr_stream
*xdr
, stateid_t
*sid
)
3562 p
= xdr_reserve_space(xdr
, sizeof(stateid_t
));
3564 return nfserr_resource
;
3565 *p
++ = cpu_to_be32(sid
->si_generation
);
3566 p
= xdr_encode_opaque_fixed(p
, &sid
->si_opaque
,
3567 sizeof(stateid_opaque_t
));
3572 nfsd4_encode_access(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_access
*access
)
3574 struct xdr_stream
*xdr
= &resp
->xdr
;
3577 p
= xdr_reserve_space(xdr
, 8);
3579 return nfserr_resource
;
3580 *p
++ = cpu_to_be32(access
->ac_supported
);
3581 *p
++ = cpu_to_be32(access
->ac_resp_access
);
3585 static __be32
nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_bind_conn_to_session
*bcts
)
3587 struct xdr_stream
*xdr
= &resp
->xdr
;
3590 p
= xdr_reserve_space(xdr
, NFS4_MAX_SESSIONID_LEN
+ 8);
3592 return nfserr_resource
;
3593 p
= xdr_encode_opaque_fixed(p
, bcts
->sessionid
.data
,
3594 NFS4_MAX_SESSIONID_LEN
);
3595 *p
++ = cpu_to_be32(bcts
->dir
);
3596 /* Upshifting from TCP to RDMA is not supported */
3597 *p
++ = cpu_to_be32(0);
3602 nfsd4_encode_close(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_close
*close
)
3604 struct xdr_stream
*xdr
= &resp
->xdr
;
3606 return nfsd4_encode_stateid(xdr
, &close
->cl_stateid
);
3611 nfsd4_encode_commit(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_commit
*commit
)
3613 struct xdr_stream
*xdr
= &resp
->xdr
;
3616 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
3618 return nfserr_resource
;
3619 p
= xdr_encode_opaque_fixed(p
, commit
->co_verf
.data
,
3620 NFS4_VERIFIER_SIZE
);
3625 nfsd4_encode_create(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_create
*create
)
3627 struct xdr_stream
*xdr
= &resp
->xdr
;
3630 p
= xdr_reserve_space(xdr
, 20);
3632 return nfserr_resource
;
3633 encode_cinfo(p
, &create
->cr_cinfo
);
3634 return nfsd4_encode_bitmap(xdr
, create
->cr_bmval
[0],
3635 create
->cr_bmval
[1], create
->cr_bmval
[2]);
3639 nfsd4_encode_getattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_getattr
*getattr
)
3641 struct svc_fh
*fhp
= getattr
->ga_fhp
;
3642 struct xdr_stream
*xdr
= &resp
->xdr
;
3644 return nfsd4_encode_fattr(xdr
, fhp
, fhp
->fh_export
, fhp
->fh_dentry
,
3645 getattr
->ga_bmval
, resp
->rqstp
, 0);
3649 nfsd4_encode_getfh(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct svc_fh
**fhpp
)
3651 struct xdr_stream
*xdr
= &resp
->xdr
;
3652 struct svc_fh
*fhp
= *fhpp
;
3656 len
= fhp
->fh_handle
.fh_size
;
3657 p
= xdr_reserve_space(xdr
, len
+ 4);
3659 return nfserr_resource
;
3660 p
= xdr_encode_opaque(p
, &fhp
->fh_handle
.fh_base
, len
);
3665 * Including all fields other than the name, a LOCK4denied structure requires
3666 * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
3669 nfsd4_encode_lock_denied(struct xdr_stream
*xdr
, struct nfsd4_lock_denied
*ld
)
3671 struct xdr_netobj
*conf
= &ld
->ld_owner
;
3675 p
= xdr_reserve_space(xdr
, 32 + XDR_LEN(conf
->len
));
3678 * Don't fail to return the result just because we can't
3679 * return the conflicting open:
3687 return nfserr_resource
;
3689 p
= xdr_encode_hyper(p
, ld
->ld_start
);
3690 p
= xdr_encode_hyper(p
, ld
->ld_length
);
3691 *p
++ = cpu_to_be32(ld
->ld_type
);
3693 p
= xdr_encode_opaque_fixed(p
, &ld
->ld_clientid
, 8);
3694 p
= xdr_encode_opaque(p
, conf
->data
, conf
->len
);
3696 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
3697 p
= xdr_encode_hyper(p
, (u64
)0); /* clientid */
3698 *p
++ = cpu_to_be32(0); /* length of owner name */
3700 return nfserr_denied
;
3704 nfsd4_encode_lock(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lock
*lock
)
3706 struct xdr_stream
*xdr
= &resp
->xdr
;
3709 nfserr
= nfsd4_encode_stateid(xdr
, &lock
->lk_resp_stateid
);
3710 else if (nfserr
== nfserr_denied
)
3711 nfserr
= nfsd4_encode_lock_denied(xdr
, &lock
->lk_denied
);
3717 nfsd4_encode_lockt(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_lockt
*lockt
)
3719 struct xdr_stream
*xdr
= &resp
->xdr
;
3721 if (nfserr
== nfserr_denied
)
3722 nfsd4_encode_lock_denied(xdr
, &lockt
->lt_denied
);
3727 nfsd4_encode_locku(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_locku
*locku
)
3729 struct xdr_stream
*xdr
= &resp
->xdr
;
3731 return nfsd4_encode_stateid(xdr
, &locku
->lu_stateid
);
3736 nfsd4_encode_link(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_link
*link
)
3738 struct xdr_stream
*xdr
= &resp
->xdr
;
3741 p
= xdr_reserve_space(xdr
, 20);
3743 return nfserr_resource
;
3744 p
= encode_cinfo(p
, &link
->li_cinfo
);
3750 nfsd4_encode_open(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open
*open
)
3752 struct xdr_stream
*xdr
= &resp
->xdr
;
3755 nfserr
= nfsd4_encode_stateid(xdr
, &open
->op_stateid
);
3758 p
= xdr_reserve_space(xdr
, 24);
3760 return nfserr_resource
;
3761 p
= encode_cinfo(p
, &open
->op_cinfo
);
3762 *p
++ = cpu_to_be32(open
->op_rflags
);
3764 nfserr
= nfsd4_encode_bitmap(xdr
, open
->op_bmval
[0], open
->op_bmval
[1],
3769 p
= xdr_reserve_space(xdr
, 4);
3771 return nfserr_resource
;
3773 *p
++ = cpu_to_be32(open
->op_delegate_type
);
3774 switch (open
->op_delegate_type
) {
3775 case NFS4_OPEN_DELEGATE_NONE
:
3777 case NFS4_OPEN_DELEGATE_READ
:
3778 nfserr
= nfsd4_encode_stateid(xdr
, &open
->op_delegate_stateid
);
3781 p
= xdr_reserve_space(xdr
, 20);
3783 return nfserr_resource
;
3784 *p
++ = cpu_to_be32(open
->op_recall
);
3787 * TODO: ACE's in delegations
3789 *p
++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
3790 *p
++ = cpu_to_be32(0);
3791 *p
++ = cpu_to_be32(0);
3792 *p
++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */
3794 case NFS4_OPEN_DELEGATE_WRITE
:
3795 nfserr
= nfsd4_encode_stateid(xdr
, &open
->op_delegate_stateid
);
3798 p
= xdr_reserve_space(xdr
, 32);
3800 return nfserr_resource
;
3801 *p
++ = cpu_to_be32(0);
3804 * TODO: space_limit's in delegations
3806 *p
++ = cpu_to_be32(NFS4_LIMIT_SIZE
);
3807 *p
++ = cpu_to_be32(~(u32
)0);
3808 *p
++ = cpu_to_be32(~(u32
)0);
3811 * TODO: ACE's in delegations
3813 *p
++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE
);
3814 *p
++ = cpu_to_be32(0);
3815 *p
++ = cpu_to_be32(0);
3816 *p
++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */
3818 case NFS4_OPEN_DELEGATE_NONE_EXT
: /* 4.1 */
3819 switch (open
->op_why_no_deleg
) {
3820 case WND4_CONTENTION
:
3822 p
= xdr_reserve_space(xdr
, 8);
3824 return nfserr_resource
;
3825 *p
++ = cpu_to_be32(open
->op_why_no_deleg
);
3826 /* deleg signaling not supported yet: */
3827 *p
++ = cpu_to_be32(0);
3830 p
= xdr_reserve_space(xdr
, 4);
3832 return nfserr_resource
;
3833 *p
++ = cpu_to_be32(open
->op_why_no_deleg
);
3839 /* XXX save filehandle here */
3844 nfsd4_encode_open_confirm(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_confirm
*oc
)
3846 struct xdr_stream
*xdr
= &resp
->xdr
;
3848 return nfsd4_encode_stateid(xdr
, &oc
->oc_resp_stateid
);
3852 nfsd4_encode_open_downgrade(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_open_downgrade
*od
)
3854 struct xdr_stream
*xdr
= &resp
->xdr
;
3856 return nfsd4_encode_stateid(xdr
, &od
->od_stateid
);
3859 static __be32
nfsd4_encode_splice_read(
3860 struct nfsd4_compoundres
*resp
,
3861 struct nfsd4_read
*read
,
3862 struct file
*file
, unsigned long maxcount
)
3864 struct xdr_stream
*xdr
= &resp
->xdr
;
3865 struct xdr_buf
*buf
= xdr
->buf
;
3866 int status
, space_left
;
3869 __be32
*p
= xdr
->p
- 2;
3871 /* Make sure there will be room for padding if needed */
3872 if (xdr
->end
- xdr
->p
< 1)
3873 return nfserr_resource
;
3875 nfserr
= nfsd_splice_read(read
->rd_rqstp
, read
->rd_fhp
,
3876 file
, read
->rd_offset
, &maxcount
, &eof
);
3877 read
->rd_length
= maxcount
;
3880 status
= svc_encode_result_payload(read
->rd_rqstp
,
3881 buf
->head
[0].iov_len
, maxcount
);
3883 nfserr
= nfserrno(status
);
3887 *(p
++) = htonl(eof
);
3888 *(p
++) = htonl(maxcount
);
3890 buf
->page_len
= maxcount
;
3891 buf
->len
+= maxcount
;
3892 xdr
->page_ptr
+= (buf
->page_base
+ maxcount
+ PAGE_SIZE
- 1)
3895 /* Use rest of head for padding and remaining ops: */
3896 buf
->tail
[0].iov_base
= xdr
->p
;
3897 buf
->tail
[0].iov_len
= 0;
3898 xdr
->iov
= buf
->tail
;
3900 int pad
= 4 - (maxcount
&3);
3904 buf
->tail
[0].iov_base
+= maxcount
&3;
3905 buf
->tail
[0].iov_len
= pad
;
3909 space_left
= min_t(int, (void *)xdr
->end
- (void *)xdr
->p
,
3910 buf
->buflen
- buf
->len
);
3911 buf
->buflen
= buf
->len
+ space_left
;
3912 xdr
->end
= (__be32
*)((void *)xdr
->end
+ space_left
);
3918 * nfsd_splice_actor may have already messed with the
3919 * page length; reset it so as not to confuse
3920 * xdr_truncate_encode in our caller.
3926 static __be32
nfsd4_encode_readv(struct nfsd4_compoundres
*resp
,
3927 struct nfsd4_read
*read
,
3928 struct file
*file
, unsigned long maxcount
)
3930 struct xdr_stream
*xdr
= &resp
->xdr
;
3932 int starting_len
= xdr
->buf
->len
- 8;
3937 read
->rd_vlen
= xdr_reserve_space_vec(xdr
, resp
->rqstp
->rq_vec
, maxcount
);
3938 if (read
->rd_vlen
< 0)
3939 return nfserr_resource
;
3941 nfserr
= nfsd_readv(resp
->rqstp
, read
->rd_fhp
, file
, read
->rd_offset
,
3942 resp
->rqstp
->rq_vec
, read
->rd_vlen
, &maxcount
,
3944 read
->rd_length
= maxcount
;
3947 if (svc_encode_result_payload(resp
->rqstp
, starting_len
+ 8, maxcount
))
3949 xdr_truncate_encode(xdr
, starting_len
+ 8 + xdr_align_size(maxcount
));
3952 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
, &tmp
, 4);
3953 tmp
= htonl(maxcount
);
3954 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
+ 4, &tmp
, 4);
3957 pad
= (maxcount
&3) ? 4 - (maxcount
&3) : 0;
3958 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
+ 8 + maxcount
,
3965 nfsd4_encode_read(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
3966 struct nfsd4_read
*read
)
3968 unsigned long maxcount
;
3969 struct xdr_stream
*xdr
= &resp
->xdr
;
3971 int starting_len
= xdr
->buf
->len
;
3976 file
= read
->rd_nf
->nf_file
;
3978 p
= xdr_reserve_space(xdr
, 8); /* eof flag and byte count */
3980 WARN_ON_ONCE(test_bit(RQ_SPLICE_OK
, &resp
->rqstp
->rq_flags
));
3981 return nfserr_resource
;
3983 if (resp
->xdr
.buf
->page_len
&&
3984 test_bit(RQ_SPLICE_OK
, &resp
->rqstp
->rq_flags
)) {
3986 return nfserr_resource
;
3988 xdr_commit_encode(xdr
);
3990 maxcount
= svc_max_payload(resp
->rqstp
);
3991 maxcount
= min_t(unsigned long, maxcount
,
3992 (xdr
->buf
->buflen
- xdr
->buf
->len
));
3993 maxcount
= min_t(unsigned long, maxcount
, read
->rd_length
);
3995 if (file
->f_op
->splice_read
&&
3996 test_bit(RQ_SPLICE_OK
, &resp
->rqstp
->rq_flags
))
3997 nfserr
= nfsd4_encode_splice_read(resp
, read
, file
, maxcount
);
3999 nfserr
= nfsd4_encode_readv(resp
, read
, file
, maxcount
);
4002 xdr_truncate_encode(xdr
, starting_len
);
4008 nfsd4_encode_readlink(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readlink
*readlink
)
4013 struct xdr_stream
*xdr
= &resp
->xdr
;
4014 int length_offset
= xdr
->buf
->len
;
4018 p
= xdr_reserve_space(xdr
, 4);
4020 return nfserr_resource
;
4021 maxcount
= PAGE_SIZE
;
4023 p
= xdr_reserve_space(xdr
, maxcount
);
4025 return nfserr_resource
;
4027 * XXX: By default, vfs_readlink() will truncate symlinks if they
4028 * would overflow the buffer. Is this kosher in NFSv4? If not, one
4029 * easy fix is: if vfs_readlink() precisely fills the buffer, assume
4030 * that truncation occurred, and return NFS4ERR_RESOURCE.
4032 nfserr
= nfsd_readlink(readlink
->rl_rqstp
, readlink
->rl_fhp
,
4033 (char *)p
, &maxcount
);
4034 if (nfserr
== nfserr_isdir
)
4035 nfserr
= nfserr_inval
;
4038 status
= svc_encode_result_payload(readlink
->rl_rqstp
, length_offset
,
4041 nfserr
= nfserrno(status
);
4045 wire_count
= htonl(maxcount
);
4046 write_bytes_to_xdr_buf(xdr
->buf
, length_offset
, &wire_count
, 4);
4047 xdr_truncate_encode(xdr
, length_offset
+ 4 + ALIGN(maxcount
, 4));
4049 write_bytes_to_xdr_buf(xdr
->buf
, length_offset
+ 4 + maxcount
,
4050 &zero
, 4 - (maxcount
&3));
4054 xdr_truncate_encode(xdr
, length_offset
);
4059 nfsd4_encode_readdir(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_readdir
*readdir
)
4065 struct xdr_stream
*xdr
= &resp
->xdr
;
4066 int starting_len
= xdr
->buf
->len
;
4069 p
= xdr_reserve_space(xdr
, NFS4_VERIFIER_SIZE
);
4071 return nfserr_resource
;
4073 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
4074 *p
++ = cpu_to_be32(0);
4075 *p
++ = cpu_to_be32(0);
4076 resp
->xdr
.buf
->head
[0].iov_len
= ((char *)resp
->xdr
.p
)
4077 - (char *)resp
->xdr
.buf
->head
[0].iov_base
;
4080 * Number of bytes left for directory entries allowing for the
4081 * final 8 bytes of the readdir and a following failed op:
4083 bytes_left
= xdr
->buf
->buflen
- xdr
->buf
->len
4084 - COMPOUND_ERR_SLACK_SPACE
- 8;
4085 if (bytes_left
< 0) {
4086 nfserr
= nfserr_resource
;
4089 maxcount
= svc_max_payload(resp
->rqstp
);
4090 maxcount
= min_t(u32
, readdir
->rd_maxcount
, maxcount
);
4092 * Note the rfc defines rd_maxcount as the size of the
4093 * READDIR4resok structure, which includes the verifier above
4094 * and the 8 bytes encoded at the end of this function:
4096 if (maxcount
< 16) {
4097 nfserr
= nfserr_toosmall
;
4100 maxcount
= min_t(int, maxcount
-16, bytes_left
);
4102 /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */
4103 if (!readdir
->rd_dircount
)
4104 readdir
->rd_dircount
= svc_max_payload(resp
->rqstp
);
4107 readdir
->rd_maxcount
= maxcount
;
4108 readdir
->common
.err
= 0;
4109 readdir
->cookie_offset
= 0;
4111 offset
= readdir
->rd_cookie
;
4112 nfserr
= nfsd_readdir(readdir
->rd_rqstp
, readdir
->rd_fhp
,
4114 &readdir
->common
, nfsd4_encode_dirent
);
4115 if (nfserr
== nfs_ok
&&
4116 readdir
->common
.err
== nfserr_toosmall
&&
4117 xdr
->buf
->len
== starting_len
+ 8) {
4118 /* nothing encoded; which limit did we hit?: */
4119 if (maxcount
- 16 < bytes_left
)
4120 /* It was the fault of rd_maxcount: */
4121 nfserr
= nfserr_toosmall
;
4123 /* We ran out of buffer space: */
4124 nfserr
= nfserr_resource
;
4129 if (readdir
->cookie_offset
) {
4130 wire_offset
= cpu_to_be64(offset
);
4131 write_bytes_to_xdr_buf(xdr
->buf
, readdir
->cookie_offset
,
4135 p
= xdr_reserve_space(xdr
, 8);
4140 *p
++ = 0; /* no more entries */
4141 *p
++ = htonl(readdir
->common
.err
== nfserr_eof
);
4145 xdr_truncate_encode(xdr
, starting_len
);
4150 nfsd4_encode_remove(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_remove
*remove
)
4152 struct xdr_stream
*xdr
= &resp
->xdr
;
4155 p
= xdr_reserve_space(xdr
, 20);
4157 return nfserr_resource
;
4158 p
= encode_cinfo(p
, &remove
->rm_cinfo
);
4163 nfsd4_encode_rename(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_rename
*rename
)
4165 struct xdr_stream
*xdr
= &resp
->xdr
;
4168 p
= xdr_reserve_space(xdr
, 40);
4170 return nfserr_resource
;
4171 p
= encode_cinfo(p
, &rename
->rn_sinfo
);
4172 p
= encode_cinfo(p
, &rename
->rn_tinfo
);
4177 nfsd4_do_encode_secinfo(struct xdr_stream
*xdr
, struct svc_export
*exp
)
4179 u32 i
, nflavs
, supported
;
4180 struct exp_flavor_info
*flavs
;
4181 struct exp_flavor_info def_flavs
[2];
4182 __be32
*p
, *flavorsp
;
4183 static bool report
= true;
4185 if (exp
->ex_nflavors
) {
4186 flavs
= exp
->ex_flavors
;
4187 nflavs
= exp
->ex_nflavors
;
4188 } else { /* Handling of some defaults in absence of real secinfo: */
4190 if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_UNIX
) {
4192 flavs
[0].pseudoflavor
= RPC_AUTH_UNIX
;
4193 flavs
[1].pseudoflavor
= RPC_AUTH_NULL
;
4194 } else if (exp
->ex_client
->flavour
->flavour
== RPC_AUTH_GSS
) {
4196 flavs
[0].pseudoflavor
4197 = svcauth_gss_flavor(exp
->ex_client
);
4200 flavs
[0].pseudoflavor
4201 = exp
->ex_client
->flavour
->flavour
;
4206 p
= xdr_reserve_space(xdr
, 4);
4208 return nfserr_resource
;
4209 flavorsp
= p
++; /* to be backfilled later */
4211 for (i
= 0; i
< nflavs
; i
++) {
4212 rpc_authflavor_t pf
= flavs
[i
].pseudoflavor
;
4213 struct rpcsec_gss_info info
;
4215 if (rpcauth_get_gssinfo(pf
, &info
) == 0) {
4217 p
= xdr_reserve_space(xdr
, 4 + 4 +
4218 XDR_LEN(info
.oid
.len
) + 4 + 4);
4220 return nfserr_resource
;
4221 *p
++ = cpu_to_be32(RPC_AUTH_GSS
);
4222 p
= xdr_encode_opaque(p
, info
.oid
.data
, info
.oid
.len
);
4223 *p
++ = cpu_to_be32(info
.qop
);
4224 *p
++ = cpu_to_be32(info
.service
);
4225 } else if (pf
< RPC_AUTH_MAXFLAVOR
) {
4227 p
= xdr_reserve_space(xdr
, 4);
4229 return nfserr_resource
;
4230 *p
++ = cpu_to_be32(pf
);
4233 pr_warn("NFS: SECINFO: security flavor %u "
4234 "is not supported\n", pf
);
4238 if (nflavs
!= supported
)
4240 *flavorsp
= htonl(supported
);
4245 nfsd4_encode_secinfo(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4246 struct nfsd4_secinfo
*secinfo
)
4248 struct xdr_stream
*xdr
= &resp
->xdr
;
4250 return nfsd4_do_encode_secinfo(xdr
, secinfo
->si_exp
);
4254 nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4255 struct nfsd4_secinfo_no_name
*secinfo
)
4257 struct xdr_stream
*xdr
= &resp
->xdr
;
4259 return nfsd4_do_encode_secinfo(xdr
, secinfo
->sin_exp
);
4263 * The SETATTR encode routine is special -- it always encodes a bitmap,
4264 * regardless of the error status.
4267 nfsd4_encode_setattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setattr
*setattr
)
4269 struct xdr_stream
*xdr
= &resp
->xdr
;
4272 p
= xdr_reserve_space(xdr
, 16);
4274 return nfserr_resource
;
4276 *p
++ = cpu_to_be32(3);
4277 *p
++ = cpu_to_be32(0);
4278 *p
++ = cpu_to_be32(0);
4279 *p
++ = cpu_to_be32(0);
4282 *p
++ = cpu_to_be32(3);
4283 *p
++ = cpu_to_be32(setattr
->sa_bmval
[0]);
4284 *p
++ = cpu_to_be32(setattr
->sa_bmval
[1]);
4285 *p
++ = cpu_to_be32(setattr
->sa_bmval
[2]);
4291 nfsd4_encode_setclientid(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_setclientid
*scd
)
4293 struct xdr_stream
*xdr
= &resp
->xdr
;
4297 p
= xdr_reserve_space(xdr
, 8 + NFS4_VERIFIER_SIZE
);
4299 return nfserr_resource
;
4300 p
= xdr_encode_opaque_fixed(p
, &scd
->se_clientid
, 8);
4301 p
= xdr_encode_opaque_fixed(p
, &scd
->se_confirm
,
4302 NFS4_VERIFIER_SIZE
);
4304 else if (nfserr
== nfserr_clid_inuse
) {
4305 p
= xdr_reserve_space(xdr
, 8);
4307 return nfserr_resource
;
4308 *p
++ = cpu_to_be32(0);
4309 *p
++ = cpu_to_be32(0);
4315 nfsd4_encode_write(struct nfsd4_compoundres
*resp
, __be32 nfserr
, struct nfsd4_write
*write
)
4317 struct xdr_stream
*xdr
= &resp
->xdr
;
4320 p
= xdr_reserve_space(xdr
, 16);
4322 return nfserr_resource
;
4323 *p
++ = cpu_to_be32(write
->wr_bytes_written
);
4324 *p
++ = cpu_to_be32(write
->wr_how_written
);
4325 p
= xdr_encode_opaque_fixed(p
, write
->wr_verifier
.data
,
4326 NFS4_VERIFIER_SIZE
);
4331 nfsd4_encode_exchange_id(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4332 struct nfsd4_exchange_id
*exid
)
4334 struct xdr_stream
*xdr
= &resp
->xdr
;
4339 int server_scope_sz
;
4340 uint64_t minor_id
= 0;
4341 struct nfsd_net
*nn
= net_generic(SVC_NET(resp
->rqstp
), nfsd_net_id
);
4343 major_id
= nn
->nfsd_name
;
4344 major_id_sz
= strlen(nn
->nfsd_name
);
4345 server_scope
= nn
->nfsd_name
;
4346 server_scope_sz
= strlen(nn
->nfsd_name
);
4348 p
= xdr_reserve_space(xdr
,
4349 8 /* eir_clientid */ +
4350 4 /* eir_sequenceid */ +
4354 return nfserr_resource
;
4356 p
= xdr_encode_opaque_fixed(p
, &exid
->clientid
, 8);
4357 *p
++ = cpu_to_be32(exid
->seqid
);
4358 *p
++ = cpu_to_be32(exid
->flags
);
4360 *p
++ = cpu_to_be32(exid
->spa_how
);
4362 switch (exid
->spa_how
) {
4366 /* spo_must_enforce bitmap: */
4367 nfserr
= nfsd4_encode_bitmap(xdr
,
4368 exid
->spo_must_enforce
[0],
4369 exid
->spo_must_enforce
[1],
4370 exid
->spo_must_enforce
[2]);
4373 /* spo_must_allow bitmap: */
4374 nfserr
= nfsd4_encode_bitmap(xdr
,
4375 exid
->spo_must_allow
[0],
4376 exid
->spo_must_allow
[1],
4377 exid
->spo_must_allow
[2]);
4385 p
= xdr_reserve_space(xdr
,
4386 8 /* so_minor_id */ +
4387 4 /* so_major_id.len */ +
4388 (XDR_QUADLEN(major_id_sz
) * 4) +
4389 4 /* eir_server_scope.len */ +
4390 (XDR_QUADLEN(server_scope_sz
) * 4) +
4391 4 /* eir_server_impl_id.count (0) */);
4393 return nfserr_resource
;
4395 /* The server_owner struct */
4396 p
= xdr_encode_hyper(p
, minor_id
); /* Minor id */
4398 p
= xdr_encode_opaque(p
, major_id
, major_id_sz
);
4401 p
= xdr_encode_opaque(p
, server_scope
, server_scope_sz
);
4403 /* Implementation id */
4404 *p
++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */
4409 nfsd4_encode_create_session(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4410 struct nfsd4_create_session
*sess
)
4412 struct xdr_stream
*xdr
= &resp
->xdr
;
4415 p
= xdr_reserve_space(xdr
, 24);
4417 return nfserr_resource
;
4418 p
= xdr_encode_opaque_fixed(p
, sess
->sessionid
.data
,
4419 NFS4_MAX_SESSIONID_LEN
);
4420 *p
++ = cpu_to_be32(sess
->seqid
);
4421 *p
++ = cpu_to_be32(sess
->flags
);
4423 p
= xdr_reserve_space(xdr
, 28);
4425 return nfserr_resource
;
4426 *p
++ = cpu_to_be32(0); /* headerpadsz */
4427 *p
++ = cpu_to_be32(sess
->fore_channel
.maxreq_sz
);
4428 *p
++ = cpu_to_be32(sess
->fore_channel
.maxresp_sz
);
4429 *p
++ = cpu_to_be32(sess
->fore_channel
.maxresp_cached
);
4430 *p
++ = cpu_to_be32(sess
->fore_channel
.maxops
);
4431 *p
++ = cpu_to_be32(sess
->fore_channel
.maxreqs
);
4432 *p
++ = cpu_to_be32(sess
->fore_channel
.nr_rdma_attrs
);
4434 if (sess
->fore_channel
.nr_rdma_attrs
) {
4435 p
= xdr_reserve_space(xdr
, 4);
4437 return nfserr_resource
;
4438 *p
++ = cpu_to_be32(sess
->fore_channel
.rdma_attrs
);
4441 p
= xdr_reserve_space(xdr
, 28);
4443 return nfserr_resource
;
4444 *p
++ = cpu_to_be32(0); /* headerpadsz */
4445 *p
++ = cpu_to_be32(sess
->back_channel
.maxreq_sz
);
4446 *p
++ = cpu_to_be32(sess
->back_channel
.maxresp_sz
);
4447 *p
++ = cpu_to_be32(sess
->back_channel
.maxresp_cached
);
4448 *p
++ = cpu_to_be32(sess
->back_channel
.maxops
);
4449 *p
++ = cpu_to_be32(sess
->back_channel
.maxreqs
);
4450 *p
++ = cpu_to_be32(sess
->back_channel
.nr_rdma_attrs
);
4452 if (sess
->back_channel
.nr_rdma_attrs
) {
4453 p
= xdr_reserve_space(xdr
, 4);
4455 return nfserr_resource
;
4456 *p
++ = cpu_to_be32(sess
->back_channel
.rdma_attrs
);
4462 nfsd4_encode_sequence(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4463 struct nfsd4_sequence
*seq
)
4465 struct xdr_stream
*xdr
= &resp
->xdr
;
4468 p
= xdr_reserve_space(xdr
, NFS4_MAX_SESSIONID_LEN
+ 20);
4470 return nfserr_resource
;
4471 p
= xdr_encode_opaque_fixed(p
, seq
->sessionid
.data
,
4472 NFS4_MAX_SESSIONID_LEN
);
4473 *p
++ = cpu_to_be32(seq
->seqid
);
4474 *p
++ = cpu_to_be32(seq
->slotid
);
4475 /* Note slotid's are numbered from zero: */
4476 *p
++ = cpu_to_be32(seq
->maxslots
- 1); /* sr_highest_slotid */
4477 *p
++ = cpu_to_be32(seq
->maxslots
- 1); /* sr_target_highest_slotid */
4478 *p
++ = cpu_to_be32(seq
->status_flags
);
4480 resp
->cstate
.data_offset
= xdr
->buf
->len
; /* DRC cache data pointer */
4485 nfsd4_encode_test_stateid(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4486 struct nfsd4_test_stateid
*test_stateid
)
4488 struct xdr_stream
*xdr
= &resp
->xdr
;
4489 struct nfsd4_test_stateid_id
*stateid
, *next
;
4492 p
= xdr_reserve_space(xdr
, 4 + (4 * test_stateid
->ts_num_ids
));
4494 return nfserr_resource
;
4495 *p
++ = htonl(test_stateid
->ts_num_ids
);
4497 list_for_each_entry_safe(stateid
, next
, &test_stateid
->ts_stateid_list
, ts_id_list
) {
4498 *p
++ = stateid
->ts_id_status
;
4504 #ifdef CONFIG_NFSD_PNFS
4506 nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4507 struct nfsd4_getdeviceinfo
*gdev
)
4509 struct xdr_stream
*xdr
= &resp
->xdr
;
4510 const struct nfsd4_layout_ops
*ops
;
4511 u32 starting_len
= xdr
->buf
->len
, needed_len
;
4514 p
= xdr_reserve_space(xdr
, 4);
4516 return nfserr_resource
;
4518 *p
++ = cpu_to_be32(gdev
->gd_layout_type
);
4520 /* If maxcount is 0 then just update notifications */
4521 if (gdev
->gd_maxcount
!= 0) {
4522 ops
= nfsd4_layout_ops
[gdev
->gd_layout_type
];
4523 nfserr
= ops
->encode_getdeviceinfo(xdr
, gdev
);
4526 * We don't bother to burden the layout drivers with
4527 * enforcing gd_maxcount, just tell the client to
4528 * come back with a bigger buffer if it's not enough.
4530 if (xdr
->buf
->len
+ 4 > gdev
->gd_maxcount
)
4536 if (gdev
->gd_notify_types
) {
4537 p
= xdr_reserve_space(xdr
, 4 + 4);
4539 return nfserr_resource
;
4540 *p
++ = cpu_to_be32(1); /* bitmap length */
4541 *p
++ = cpu_to_be32(gdev
->gd_notify_types
);
4543 p
= xdr_reserve_space(xdr
, 4);
4545 return nfserr_resource
;
4551 dprintk("%s: maxcount too small\n", __func__
);
4552 needed_len
= xdr
->buf
->len
+ 4 /* notifications */;
4553 xdr_truncate_encode(xdr
, starting_len
);
4554 p
= xdr_reserve_space(xdr
, 4);
4556 return nfserr_resource
;
4557 *p
++ = cpu_to_be32(needed_len
);
4558 return nfserr_toosmall
;
4562 nfsd4_encode_layoutget(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4563 struct nfsd4_layoutget
*lgp
)
4565 struct xdr_stream
*xdr
= &resp
->xdr
;
4566 const struct nfsd4_layout_ops
*ops
;
4569 p
= xdr_reserve_space(xdr
, 36 + sizeof(stateid_opaque_t
));
4571 return nfserr_resource
;
4573 *p
++ = cpu_to_be32(1); /* we always set return-on-close */
4574 *p
++ = cpu_to_be32(lgp
->lg_sid
.si_generation
);
4575 p
= xdr_encode_opaque_fixed(p
, &lgp
->lg_sid
.si_opaque
,
4576 sizeof(stateid_opaque_t
));
4578 *p
++ = cpu_to_be32(1); /* we always return a single layout */
4579 p
= xdr_encode_hyper(p
, lgp
->lg_seg
.offset
);
4580 p
= xdr_encode_hyper(p
, lgp
->lg_seg
.length
);
4581 *p
++ = cpu_to_be32(lgp
->lg_seg
.iomode
);
4582 *p
++ = cpu_to_be32(lgp
->lg_layout_type
);
4584 ops
= nfsd4_layout_ops
[lgp
->lg_layout_type
];
4585 return ops
->encode_layoutget(xdr
, lgp
);
4589 nfsd4_encode_layoutcommit(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4590 struct nfsd4_layoutcommit
*lcp
)
4592 struct xdr_stream
*xdr
= &resp
->xdr
;
4595 p
= xdr_reserve_space(xdr
, 4);
4597 return nfserr_resource
;
4598 *p
++ = cpu_to_be32(lcp
->lc_size_chg
);
4599 if (lcp
->lc_size_chg
) {
4600 p
= xdr_reserve_space(xdr
, 8);
4602 return nfserr_resource
;
4603 p
= xdr_encode_hyper(p
, lcp
->lc_newsize
);
4610 nfsd4_encode_layoutreturn(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4611 struct nfsd4_layoutreturn
*lrp
)
4613 struct xdr_stream
*xdr
= &resp
->xdr
;
4616 p
= xdr_reserve_space(xdr
, 4);
4618 return nfserr_resource
;
4619 *p
++ = cpu_to_be32(lrp
->lrs_present
);
4620 if (lrp
->lrs_present
)
4621 return nfsd4_encode_stateid(xdr
, &lrp
->lr_sid
);
4624 #endif /* CONFIG_NFSD_PNFS */
4627 nfsd42_encode_write_res(struct nfsd4_compoundres
*resp
,
4628 struct nfsd42_write_res
*write
, bool sync
)
4631 p
= xdr_reserve_space(&resp
->xdr
, 4);
4633 return nfserr_resource
;
4636 *p
++ = cpu_to_be32(0);
4639 *p
++ = cpu_to_be32(1);
4640 nfserr
= nfsd4_encode_stateid(&resp
->xdr
, &write
->cb_stateid
);
4644 p
= xdr_reserve_space(&resp
->xdr
, 8 + 4 + NFS4_VERIFIER_SIZE
);
4646 return nfserr_resource
;
4648 p
= xdr_encode_hyper(p
, write
->wr_bytes_written
);
4649 *p
++ = cpu_to_be32(write
->wr_stable_how
);
4650 p
= xdr_encode_opaque_fixed(p
, write
->wr_verifier
.data
,
4651 NFS4_VERIFIER_SIZE
);
4656 nfsd42_encode_nl4_server(struct nfsd4_compoundres
*resp
, struct nl4_server
*ns
)
4658 struct xdr_stream
*xdr
= &resp
->xdr
;
4659 struct nfs42_netaddr
*addr
;
4662 p
= xdr_reserve_space(xdr
, 4);
4663 *p
++ = cpu_to_be32(ns
->nl4_type
);
4665 switch (ns
->nl4_type
) {
4667 addr
= &ns
->u
.nl4_addr
;
4669 /* netid_len, netid, uaddr_len, uaddr (port included
4670 * in RPCBIND_MAXUADDRLEN)
4672 p
= xdr_reserve_space(xdr
,
4674 (XDR_QUADLEN(addr
->netid_len
) * 4) +
4676 (XDR_QUADLEN(addr
->addr_len
) * 4));
4678 return nfserr_resource
;
4680 *p
++ = cpu_to_be32(addr
->netid_len
);
4681 p
= xdr_encode_opaque_fixed(p
, addr
->netid
,
4683 *p
++ = cpu_to_be32(addr
->addr_len
);
4684 p
= xdr_encode_opaque_fixed(p
, addr
->addr
,
4688 WARN_ON_ONCE(ns
->nl4_type
!= NL4_NETADDR
);
4689 return nfserr_inval
;
4696 nfsd4_encode_copy(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4697 struct nfsd4_copy
*copy
)
4701 nfserr
= nfsd42_encode_write_res(resp
, ©
->cp_res
,
4702 !!copy
->cp_synchronous
);
4706 p
= xdr_reserve_space(&resp
->xdr
, 4 + 4);
4707 *p
++ = xdr_one
; /* cr_consecutive */
4708 *p
++ = cpu_to_be32(copy
->cp_synchronous
);
4713 nfsd4_encode_offload_status(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4714 struct nfsd4_offload_status
*os
)
4716 struct xdr_stream
*xdr
= &resp
->xdr
;
4719 p
= xdr_reserve_space(xdr
, 8 + 4);
4721 return nfserr_resource
;
4722 p
= xdr_encode_hyper(p
, os
->count
);
4723 *p
++ = cpu_to_be32(0);
4728 nfsd4_encode_read_plus_data(struct nfsd4_compoundres
*resp
,
4729 struct nfsd4_read
*read
,
4730 unsigned long *maxcount
, u32
*eof
,
4733 struct xdr_stream
*xdr
= &resp
->xdr
;
4734 struct file
*file
= read
->rd_nf
->nf_file
;
4735 int starting_len
= xdr
->buf
->len
;
4741 hole_pos
= pos
? *pos
: vfs_llseek(file
, read
->rd_offset
, SEEK_HOLE
);
4742 if (hole_pos
> read
->rd_offset
)
4743 *maxcount
= min_t(unsigned long, *maxcount
, hole_pos
- read
->rd_offset
);
4744 *maxcount
= min_t(unsigned long, *maxcount
, (xdr
->buf
->buflen
- xdr
->buf
->len
));
4746 /* Content type, offset, byte count */
4747 p
= xdr_reserve_space(xdr
, 4 + 8 + 4);
4749 return nfserr_resource
;
4751 read
->rd_vlen
= xdr_reserve_space_vec(xdr
, resp
->rqstp
->rq_vec
, *maxcount
);
4752 if (read
->rd_vlen
< 0)
4753 return nfserr_resource
;
4755 nfserr
= nfsd_readv(resp
->rqstp
, read
->rd_fhp
, file
, read
->rd_offset
,
4756 resp
->rqstp
->rq_vec
, read
->rd_vlen
, maxcount
, eof
);
4760 tmp
= htonl(NFS4_CONTENT_DATA
);
4761 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
, &tmp
, 4);
4762 tmp64
= cpu_to_be64(read
->rd_offset
);
4763 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
+ 4, &tmp64
, 8);
4764 tmp
= htonl(*maxcount
);
4765 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
+ 12, &tmp
, 4);
4770 nfsd4_encode_read_plus_hole(struct nfsd4_compoundres
*resp
,
4771 struct nfsd4_read
*read
,
4772 unsigned long *maxcount
, u32
*eof
)
4774 struct file
*file
= read
->rd_nf
->nf_file
;
4775 loff_t data_pos
= vfs_llseek(file
, read
->rd_offset
, SEEK_DATA
);
4776 loff_t f_size
= i_size_read(file_inode(file
));
4777 unsigned long count
;
4780 if (data_pos
== -ENXIO
)
4782 else if (data_pos
<= read
->rd_offset
|| (data_pos
< f_size
&& data_pos
% PAGE_SIZE
))
4783 return nfsd4_encode_read_plus_data(resp
, read
, maxcount
, eof
, &f_size
);
4784 count
= data_pos
- read
->rd_offset
;
4786 /* Content type, offset, byte count */
4787 p
= xdr_reserve_space(&resp
->xdr
, 4 + 8 + 8);
4789 return nfserr_resource
;
4791 *p
++ = htonl(NFS4_CONTENT_HOLE
);
4792 p
= xdr_encode_hyper(p
, read
->rd_offset
);
4793 p
= xdr_encode_hyper(p
, count
);
4795 *eof
= (read
->rd_offset
+ count
) >= f_size
;
4796 *maxcount
= min_t(unsigned long, count
, *maxcount
);
4801 nfsd4_encode_read_plus(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4802 struct nfsd4_read
*read
)
4804 unsigned long maxcount
, count
;
4805 struct xdr_stream
*xdr
= &resp
->xdr
;
4807 int starting_len
= xdr
->buf
->len
;
4808 int last_segment
= xdr
->buf
->len
;
4817 file
= read
->rd_nf
->nf_file
;
4819 /* eof flag, segment count */
4820 p
= xdr_reserve_space(xdr
, 4 + 4);
4822 return nfserr_resource
;
4823 xdr_commit_encode(xdr
);
4825 maxcount
= svc_max_payload(resp
->rqstp
);
4826 maxcount
= min_t(unsigned long, maxcount
,
4827 (xdr
->buf
->buflen
- xdr
->buf
->len
));
4828 maxcount
= min_t(unsigned long, maxcount
, read
->rd_length
);
4831 eof
= read
->rd_offset
>= i_size_read(file_inode(file
));
4835 pos
= vfs_llseek(file
, read
->rd_offset
, SEEK_HOLE
);
4836 is_data
= pos
> read
->rd_offset
;
4838 while (count
> 0 && !eof
) {
4841 nfserr
= nfsd4_encode_read_plus_data(resp
, read
, &maxcount
, &eof
,
4842 segments
== 0 ? &pos
: NULL
);
4844 nfserr
= nfsd4_encode_read_plus_hole(resp
, read
, &maxcount
, &eof
);
4848 read
->rd_offset
+= maxcount
;
4850 last_segment
= xdr
->buf
->len
;
4855 if (nfserr
&& segments
== 0)
4856 xdr_truncate_encode(xdr
, starting_len
);
4859 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
, &tmp
, 4);
4860 tmp
= htonl(segments
);
4861 write_bytes_to_xdr_buf(xdr
->buf
, starting_len
+ 4, &tmp
, 4);
4863 xdr_truncate_encode(xdr
, last_segment
);
4872 nfsd4_encode_copy_notify(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4873 struct nfsd4_copy_notify
*cn
)
4875 struct xdr_stream
*xdr
= &resp
->xdr
;
4882 p
= xdr_reserve_space(xdr
, 12);
4884 return nfserr_resource
;
4886 /* cnr_lease_time */
4887 p
= xdr_encode_hyper(p
, cn
->cpn_sec
);
4888 *p
++ = cpu_to_be32(cn
->cpn_nsec
);
4891 nfserr
= nfsd4_encode_stateid(xdr
, &cn
->cpn_cnr_stateid
);
4895 /* cnr_src.nl_nsvr */
4896 p
= xdr_reserve_space(xdr
, 4);
4898 return nfserr_resource
;
4900 *p
++ = cpu_to_be32(1);
4902 return nfsd42_encode_nl4_server(resp
, &cn
->cpn_src
);
4906 nfsd4_encode_seek(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4907 struct nfsd4_seek
*seek
)
4911 p
= xdr_reserve_space(&resp
->xdr
, 4 + 8);
4912 *p
++ = cpu_to_be32(seek
->seek_eof
);
4913 p
= xdr_encode_hyper(p
, seek
->seek_pos
);
4919 nfsd4_encode_noop(struct nfsd4_compoundres
*resp
, __be32 nfserr
, void *p
)
4925 * Encode kmalloc-ed buffer in to XDR stream.
4928 nfsd4_vbuf_to_stream(struct xdr_stream
*xdr
, char *buf
, u32 buflen
)
4933 cplen
= min_t(unsigned long, buflen
,
4934 ((void *)xdr
->end
- (void *)xdr
->p
));
4935 p
= xdr_reserve_space(xdr
, cplen
);
4937 return nfserr_resource
;
4939 memcpy(p
, buf
, cplen
);
4944 cplen
= min_t(u32
, buflen
, PAGE_SIZE
);
4945 p
= xdr_reserve_space(xdr
, cplen
);
4947 return nfserr_resource
;
4949 memcpy(p
, buf
, cplen
);
4951 if (cplen
< PAGE_SIZE
) {
4953 * We're done, with a length that wasn't page
4954 * aligned, so possibly not word aligned. Pad
4955 * any trailing bytes with 0.
4957 xdr_encode_opaque_fixed(p
, NULL
, cplen
);
4961 buflen
-= PAGE_SIZE
;
4969 nfsd4_encode_getxattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4970 struct nfsd4_getxattr
*getxattr
)
4972 struct xdr_stream
*xdr
= &resp
->xdr
;
4975 p
= xdr_reserve_space(xdr
, 4);
4977 return nfserr_resource
;
4979 *p
= cpu_to_be32(getxattr
->getxa_len
);
4981 if (getxattr
->getxa_len
== 0)
4984 err
= nfsd4_vbuf_to_stream(xdr
, getxattr
->getxa_buf
,
4985 getxattr
->getxa_len
);
4987 kvfree(getxattr
->getxa_buf
);
4993 nfsd4_encode_setxattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
4994 struct nfsd4_setxattr
*setxattr
)
4996 struct xdr_stream
*xdr
= &resp
->xdr
;
4999 p
= xdr_reserve_space(xdr
, 20);
5001 return nfserr_resource
;
5003 encode_cinfo(p
, &setxattr
->setxa_cinfo
);
5009 * See if there are cookie values that can be rejected outright.
5012 nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs
*listxattrs
,
5015 u64 cookie
= listxattrs
->lsxa_cookie
;
5018 * If the cookie is larger than the maximum number we can fit
5019 * in either the buffer we just got back from vfs_listxattr, or,
5020 * XDR-encoded, in the return buffer, it's invalid.
5022 if (cookie
> (listxattrs
->lsxa_len
) / (XATTR_USER_PREFIX_LEN
+ 2))
5023 return nfserr_badcookie
;
5025 if (cookie
> (listxattrs
->lsxa_maxcount
/
5026 (XDR_QUADLEN(XATTR_USER_PREFIX_LEN
+ 2) + 4)))
5027 return nfserr_badcookie
;
5029 *offsetp
= (u32
)cookie
;
5034 nfsd4_encode_listxattrs(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
5035 struct nfsd4_listxattrs
*listxattrs
)
5037 struct xdr_stream
*xdr
= &resp
->xdr
;
5038 u32 cookie_offset
, count_offset
, eof
;
5039 u32 left
, xdrleft
, slen
, count
;
5049 status
= nfsd4_listxattr_validate_cookie(listxattrs
, &offset
);
5054 * Reserve space for the cookie and the name array count. Record
5055 * the offsets to save them later.
5057 cookie_offset
= xdr
->buf
->len
;
5058 count_offset
= cookie_offset
+ 8;
5059 p
= xdr_reserve_space(xdr
, 12);
5061 status
= nfserr_resource
;
5066 left
= listxattrs
->lsxa_len
;
5067 sp
= listxattrs
->lsxa_buf
;
5070 xdrleft
= listxattrs
->lsxa_maxcount
;
5072 while (left
> 0 && xdrleft
> 0) {
5076 * Check if this is a "user." attribute, skip it if not.
5078 if (strncmp(sp
, XATTR_USER_PREFIX
, XATTR_USER_PREFIX_LEN
))
5081 slen
-= XATTR_USER_PREFIX_LEN
;
5082 xdrlen
= 4 + ((slen
+ 3) & ~3);
5083 if (xdrlen
> xdrleft
) {
5086 * Can't even fit the first attribute name.
5088 status
= nfserr_toosmall
;
5095 left
-= XATTR_USER_PREFIX_LEN
;
5096 sp
+= XATTR_USER_PREFIX_LEN
;
5097 if (nuser
++ < offset
)
5101 p
= xdr_reserve_space(xdr
, xdrlen
);
5103 status
= nfserr_resource
;
5107 xdr_encode_opaque(p
, sp
, slen
);
5117 * If there were user attributes to copy, but we didn't copy
5118 * any, the offset was too large (e.g. the cookie was invalid).
5120 if (nuser
> 0 && count
== 0) {
5121 status
= nfserr_badcookie
;
5126 p
= xdr_reserve_space(xdr
, 4);
5128 status
= nfserr_resource
;
5131 *p
= cpu_to_be32(eof
);
5133 cookie
= offset
+ count
;
5135 write_bytes_to_xdr_buf(xdr
->buf
, cookie_offset
, &cookie
, 8);
5136 tmp
= cpu_to_be32(count
);
5137 write_bytes_to_xdr_buf(xdr
->buf
, count_offset
, &tmp
, 4);
5139 if (listxattrs
->lsxa_len
)
5140 kvfree(listxattrs
->lsxa_buf
);
5145 nfsd4_encode_removexattr(struct nfsd4_compoundres
*resp
, __be32 nfserr
,
5146 struct nfsd4_removexattr
*removexattr
)
5148 struct xdr_stream
*xdr
= &resp
->xdr
;
5151 p
= xdr_reserve_space(xdr
, 20);
5153 return nfserr_resource
;
5155 p
= encode_cinfo(p
, &removexattr
->rmxa_cinfo
);
5159 typedef __be32(* nfsd4_enc
)(struct nfsd4_compoundres
*, __be32
, void *);
5162 * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
5163 * since we don't need to filter out obsolete ops as this is
5164 * done in the decoding phase.
5166 static const nfsd4_enc nfsd4_enc_ops
[] = {
5167 [OP_ACCESS
] = (nfsd4_enc
)nfsd4_encode_access
,
5168 [OP_CLOSE
] = (nfsd4_enc
)nfsd4_encode_close
,
5169 [OP_COMMIT
] = (nfsd4_enc
)nfsd4_encode_commit
,
5170 [OP_CREATE
] = (nfsd4_enc
)nfsd4_encode_create
,
5171 [OP_DELEGPURGE
] = (nfsd4_enc
)nfsd4_encode_noop
,
5172 [OP_DELEGRETURN
] = (nfsd4_enc
)nfsd4_encode_noop
,
5173 [OP_GETATTR
] = (nfsd4_enc
)nfsd4_encode_getattr
,
5174 [OP_GETFH
] = (nfsd4_enc
)nfsd4_encode_getfh
,
5175 [OP_LINK
] = (nfsd4_enc
)nfsd4_encode_link
,
5176 [OP_LOCK
] = (nfsd4_enc
)nfsd4_encode_lock
,
5177 [OP_LOCKT
] = (nfsd4_enc
)nfsd4_encode_lockt
,
5178 [OP_LOCKU
] = (nfsd4_enc
)nfsd4_encode_locku
,
5179 [OP_LOOKUP
] = (nfsd4_enc
)nfsd4_encode_noop
,
5180 [OP_LOOKUPP
] = (nfsd4_enc
)nfsd4_encode_noop
,
5181 [OP_NVERIFY
] = (nfsd4_enc
)nfsd4_encode_noop
,
5182 [OP_OPEN
] = (nfsd4_enc
)nfsd4_encode_open
,
5183 [OP_OPENATTR
] = (nfsd4_enc
)nfsd4_encode_noop
,
5184 [OP_OPEN_CONFIRM
] = (nfsd4_enc
)nfsd4_encode_open_confirm
,
5185 [OP_OPEN_DOWNGRADE
] = (nfsd4_enc
)nfsd4_encode_open_downgrade
,
5186 [OP_PUTFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
5187 [OP_PUTPUBFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
5188 [OP_PUTROOTFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
5189 [OP_READ
] = (nfsd4_enc
)nfsd4_encode_read
,
5190 [OP_READDIR
] = (nfsd4_enc
)nfsd4_encode_readdir
,
5191 [OP_READLINK
] = (nfsd4_enc
)nfsd4_encode_readlink
,
5192 [OP_REMOVE
] = (nfsd4_enc
)nfsd4_encode_remove
,
5193 [OP_RENAME
] = (nfsd4_enc
)nfsd4_encode_rename
,
5194 [OP_RENEW
] = (nfsd4_enc
)nfsd4_encode_noop
,
5195 [OP_RESTOREFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
5196 [OP_SAVEFH
] = (nfsd4_enc
)nfsd4_encode_noop
,
5197 [OP_SECINFO
] = (nfsd4_enc
)nfsd4_encode_secinfo
,
5198 [OP_SETATTR
] = (nfsd4_enc
)nfsd4_encode_setattr
,
5199 [OP_SETCLIENTID
] = (nfsd4_enc
)nfsd4_encode_setclientid
,
5200 [OP_SETCLIENTID_CONFIRM
] = (nfsd4_enc
)nfsd4_encode_noop
,
5201 [OP_VERIFY
] = (nfsd4_enc
)nfsd4_encode_noop
,
5202 [OP_WRITE
] = (nfsd4_enc
)nfsd4_encode_write
,
5203 [OP_RELEASE_LOCKOWNER
] = (nfsd4_enc
)nfsd4_encode_noop
,
5205 /* NFSv4.1 operations */
5206 [OP_BACKCHANNEL_CTL
] = (nfsd4_enc
)nfsd4_encode_noop
,
5207 [OP_BIND_CONN_TO_SESSION
] = (nfsd4_enc
)nfsd4_encode_bind_conn_to_session
,
5208 [OP_EXCHANGE_ID
] = (nfsd4_enc
)nfsd4_encode_exchange_id
,
5209 [OP_CREATE_SESSION
] = (nfsd4_enc
)nfsd4_encode_create_session
,
5210 [OP_DESTROY_SESSION
] = (nfsd4_enc
)nfsd4_encode_noop
,
5211 [OP_FREE_STATEID
] = (nfsd4_enc
)nfsd4_encode_noop
,
5212 [OP_GET_DIR_DELEGATION
] = (nfsd4_enc
)nfsd4_encode_noop
,
5213 #ifdef CONFIG_NFSD_PNFS
5214 [OP_GETDEVICEINFO
] = (nfsd4_enc
)nfsd4_encode_getdeviceinfo
,
5215 [OP_GETDEVICELIST
] = (nfsd4_enc
)nfsd4_encode_noop
,
5216 [OP_LAYOUTCOMMIT
] = (nfsd4_enc
)nfsd4_encode_layoutcommit
,
5217 [OP_LAYOUTGET
] = (nfsd4_enc
)nfsd4_encode_layoutget
,
5218 [OP_LAYOUTRETURN
] = (nfsd4_enc
)nfsd4_encode_layoutreturn
,
5220 [OP_GETDEVICEINFO
] = (nfsd4_enc
)nfsd4_encode_noop
,
5221 [OP_GETDEVICELIST
] = (nfsd4_enc
)nfsd4_encode_noop
,
5222 [OP_LAYOUTCOMMIT
] = (nfsd4_enc
)nfsd4_encode_noop
,
5223 [OP_LAYOUTGET
] = (nfsd4_enc
)nfsd4_encode_noop
,
5224 [OP_LAYOUTRETURN
] = (nfsd4_enc
)nfsd4_encode_noop
,
5226 [OP_SECINFO_NO_NAME
] = (nfsd4_enc
)nfsd4_encode_secinfo_no_name
,
5227 [OP_SEQUENCE
] = (nfsd4_enc
)nfsd4_encode_sequence
,
5228 [OP_SET_SSV
] = (nfsd4_enc
)nfsd4_encode_noop
,
5229 [OP_TEST_STATEID
] = (nfsd4_enc
)nfsd4_encode_test_stateid
,
5230 [OP_WANT_DELEGATION
] = (nfsd4_enc
)nfsd4_encode_noop
,
5231 [OP_DESTROY_CLIENTID
] = (nfsd4_enc
)nfsd4_encode_noop
,
5232 [OP_RECLAIM_COMPLETE
] = (nfsd4_enc
)nfsd4_encode_noop
,
5234 /* NFSv4.2 operations */
5235 [OP_ALLOCATE
] = (nfsd4_enc
)nfsd4_encode_noop
,
5236 [OP_COPY
] = (nfsd4_enc
)nfsd4_encode_copy
,
5237 [OP_COPY_NOTIFY
] = (nfsd4_enc
)nfsd4_encode_copy_notify
,
5238 [OP_DEALLOCATE
] = (nfsd4_enc
)nfsd4_encode_noop
,
5239 [OP_IO_ADVISE
] = (nfsd4_enc
)nfsd4_encode_noop
,
5240 [OP_LAYOUTERROR
] = (nfsd4_enc
)nfsd4_encode_noop
,
5241 [OP_LAYOUTSTATS
] = (nfsd4_enc
)nfsd4_encode_noop
,
5242 [OP_OFFLOAD_CANCEL
] = (nfsd4_enc
)nfsd4_encode_noop
,
5243 [OP_OFFLOAD_STATUS
] = (nfsd4_enc
)nfsd4_encode_offload_status
,
5244 [OP_READ_PLUS
] = (nfsd4_enc
)nfsd4_encode_read_plus
,
5245 [OP_SEEK
] = (nfsd4_enc
)nfsd4_encode_seek
,
5246 [OP_WRITE_SAME
] = (nfsd4_enc
)nfsd4_encode_noop
,
5247 [OP_CLONE
] = (nfsd4_enc
)nfsd4_encode_noop
,
5249 /* RFC 8276 extended atributes operations */
5250 [OP_GETXATTR
] = (nfsd4_enc
)nfsd4_encode_getxattr
,
5251 [OP_SETXATTR
] = (nfsd4_enc
)nfsd4_encode_setxattr
,
5252 [OP_LISTXATTRS
] = (nfsd4_enc
)nfsd4_encode_listxattrs
,
5253 [OP_REMOVEXATTR
] = (nfsd4_enc
)nfsd4_encode_removexattr
,
5257 * Calculate whether we still have space to encode repsize bytes.
5258 * There are two considerations:
5259 * - For NFS versions >=4.1, the size of the reply must stay within
5261 * - For all NFS versions, we must stay within limited preallocated
5264 * This is called before the operation is processed, so can only provide
5265 * an upper estimate. For some nonidempotent operations (such as
5266 * getattr), it's not necessarily a problem if that estimate is wrong,
5267 * as we can fail it after processing without significant side effects.
5269 __be32
nfsd4_check_resp_size(struct nfsd4_compoundres
*resp
, u32 respsize
)
5271 struct xdr_buf
*buf
= &resp
->rqstp
->rq_res
;
5272 struct nfsd4_slot
*slot
= resp
->cstate
.slot
;
5274 if (buf
->len
+ respsize
<= buf
->buflen
)
5276 if (!nfsd4_has_session(&resp
->cstate
))
5277 return nfserr_resource
;
5278 if (slot
->sl_flags
& NFSD4_SLOT_CACHETHIS
) {
5280 return nfserr_rep_too_big_to_cache
;
5282 return nfserr_rep_too_big
;
5286 nfsd4_encode_operation(struct nfsd4_compoundres
*resp
, struct nfsd4_op
*op
)
5288 struct xdr_stream
*xdr
= &resp
->xdr
;
5289 struct nfs4_stateowner
*so
= resp
->cstate
.replay_owner
;
5290 struct svc_rqst
*rqstp
= resp
->rqstp
;
5291 const struct nfsd4_operation
*opdesc
= op
->opdesc
;
5292 int post_err_offset
;
5296 p
= xdr_reserve_space(xdr
, 8);
5301 *p
++ = cpu_to_be32(op
->opnum
);
5302 post_err_offset
= xdr
->buf
->len
;
5304 if (op
->opnum
== OP_ILLEGAL
)
5306 if (op
->status
&& opdesc
&&
5307 !(opdesc
->op_flags
& OP_NONTRIVIAL_ERROR_ENCODE
))
5309 BUG_ON(op
->opnum
>= ARRAY_SIZE(nfsd4_enc_ops
) ||
5310 !nfsd4_enc_ops
[op
->opnum
]);
5311 encoder
= nfsd4_enc_ops
[op
->opnum
];
5312 op
->status
= encoder(resp
, op
->status
, &op
->u
);
5314 trace_nfsd_compound_encode_err(rqstp
, op
->opnum
, op
->status
);
5315 if (opdesc
&& opdesc
->op_release
)
5316 opdesc
->op_release(&op
->u
);
5317 xdr_commit_encode(xdr
);
5319 /* nfsd4_check_resp_size guarantees enough room for error status */
5321 int space_needed
= 0;
5322 if (!nfsd4_last_compound_op(rqstp
))
5323 space_needed
= COMPOUND_ERR_SLACK_SPACE
;
5324 op
->status
= nfsd4_check_resp_size(resp
, space_needed
);
5326 if (op
->status
== nfserr_resource
&& nfsd4_has_session(&resp
->cstate
)) {
5327 struct nfsd4_slot
*slot
= resp
->cstate
.slot
;
5329 if (slot
->sl_flags
& NFSD4_SLOT_CACHETHIS
)
5330 op
->status
= nfserr_rep_too_big_to_cache
;
5332 op
->status
= nfserr_rep_too_big
;
5334 if (op
->status
== nfserr_resource
||
5335 op
->status
== nfserr_rep_too_big
||
5336 op
->status
== nfserr_rep_too_big_to_cache
) {
5338 * The operation may have already been encoded or
5339 * partially encoded. No op returns anything additional
5340 * in the case of one of these three errors, so we can
5341 * just truncate back to after the status. But it's a
5342 * bug if we had to do this on a non-idempotent op:
5344 warn_on_nonidempotent_op(op
);
5345 xdr_truncate_encode(xdr
, post_err_offset
);
5348 int len
= xdr
->buf
->len
- post_err_offset
;
5350 so
->so_replay
.rp_status
= op
->status
;
5351 so
->so_replay
.rp_buflen
= len
;
5352 read_bytes_from_xdr_buf(xdr
->buf
, post_err_offset
,
5353 so
->so_replay
.rp_buf
, len
);
5356 /* Note that op->status is already in network byte order: */
5357 write_bytes_to_xdr_buf(xdr
->buf
, post_err_offset
- 4, &op
->status
, 4);
5361 * Encode the reply stored in the stateowner reply cache
5363 * XDR note: do not encode rp->rp_buflen: the buffer contains the
5364 * previously sent already encoded operation.
5367 nfsd4_encode_replay(struct xdr_stream
*xdr
, struct nfsd4_op
*op
)
5370 struct nfs4_replay
*rp
= op
->replay
;
5372 p
= xdr_reserve_space(xdr
, 8 + rp
->rp_buflen
);
5377 *p
++ = cpu_to_be32(op
->opnum
);
5378 *p
++ = rp
->rp_status
; /* already xdr'ed */
5380 p
= xdr_encode_opaque_fixed(p
, rp
->rp_buf
, rp
->rp_buflen
);
5383 void nfsd4_release_compoundargs(struct svc_rqst
*rqstp
)
5385 struct nfsd4_compoundargs
*args
= rqstp
->rq_argp
;
5387 if (args
->ops
!= args
->iops
) {
5389 args
->ops
= args
->iops
;
5391 while (args
->to_free
) {
5392 struct svcxdr_tmpbuf
*tb
= args
->to_free
;
5393 args
->to_free
= tb
->next
;
5399 nfs4svc_decode_compoundargs(struct svc_rqst
*rqstp
, __be32
*p
)
5401 struct nfsd4_compoundargs
*args
= rqstp
->rq_argp
;
5403 /* svcxdr_tmp_alloc */
5404 args
->to_free
= NULL
;
5406 args
->xdr
= &rqstp
->rq_arg_stream
;
5407 args
->ops
= args
->iops
;
5408 args
->rqstp
= rqstp
;
5410 return nfsd4_decode_compound(args
);
5414 nfs4svc_encode_compoundres(struct svc_rqst
*rqstp
, __be32
*p
)
5416 struct nfsd4_compoundres
*resp
= rqstp
->rq_resp
;
5417 struct xdr_buf
*buf
= resp
->xdr
.buf
;
5419 WARN_ON_ONCE(buf
->len
!= buf
->head
[0].iov_len
+ buf
->page_len
+
5420 buf
->tail
[0].iov_len
);
5422 *p
= resp
->cstate
.status
;
5424 rqstp
->rq_next_page
= resp
->xdr
.page_ptr
+ 1;
5427 *p
++ = htonl(resp
->taglen
);
5428 memcpy(p
, resp
->tag
, resp
->taglen
);
5429 p
+= XDR_QUADLEN(resp
->taglen
);
5430 *p
++ = htonl(resp
->opcnt
);
5432 nfsd4_sequence_done(resp
);