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>
52 #include "filecache.h"
54 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
55 #include <linux/security.h>
59 #define NFSDDBG_FACILITY NFSDDBG_XDR
61 const u32 nfsd_suppattrs[3][3] = {
62 {NFSD4_SUPPORTED_ATTRS_WORD0,
63 NFSD4_SUPPORTED_ATTRS_WORD1,
64 NFSD4_SUPPORTED_ATTRS_WORD2},
66 {NFSD4_1_SUPPORTED_ATTRS_WORD0,
67 NFSD4_1_SUPPORTED_ATTRS_WORD1,
68 NFSD4_1_SUPPORTED_ATTRS_WORD2},
70 {NFSD4_1_SUPPORTED_ATTRS_WORD0,
71 NFSD4_1_SUPPORTED_ATTRS_WORD1,
72 NFSD4_2_SUPPORTED_ATTRS_WORD2},
76 * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
77 * directory in order to indicate to the client that a filesystem boundary is present
78 * We use a fixed fsid for a referral
80 #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
81 #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
84 check_filename(char *str, int len)
90 if (isdotent(str, len))
91 return nfserr_badname;
92 for (i = 0; i < len; i++)
94 return nfserr_badname;
101 #define DECODE_TAIL \
106 dprintk("NFSD: xdr error (%s:%d)\n", \
107 __FILE__, __LINE__); \
108 status = nfserr_bad_xdr; \
111 #define READMEM(x,nbytes) do { \
113 p += XDR_QUADLEN(nbytes); \
115 #define SAVEMEM(x,nbytes) do { \
116 if (!(x = (p==argp->tmp || p == argp->tmpp) ? \
117 savemem(argp, p, nbytes) : \
119 dprintk("NFSD: xdr error (%s:%d)\n", \
120 __FILE__, __LINE__); \
123 p += XDR_QUADLEN(nbytes); \
125 #define COPYMEM(x,nbytes) do { \
126 memcpy((x), p, nbytes); \
127 p += XDR_QUADLEN(nbytes); \
130 /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */
131 #define READ_BUF(nbytes) do { \
132 if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \
134 argp->p += XDR_QUADLEN(nbytes); \
135 } else if (!(p = read_buf(argp, nbytes))) { \
136 dprintk("NFSD: xdr error (%s:%d)\n", \
137 __FILE__, __LINE__); \
142 static void next_decode_page(struct nfsd4_compoundargs *argp)
144 argp->p = page_address(argp->pagelist[0]);
146 if (argp->pagelen < PAGE_SIZE) {
147 argp->end = argp->p + XDR_QUADLEN(argp->pagelen);
150 argp->end = argp->p + (PAGE_SIZE>>2);
151 argp->pagelen -= PAGE_SIZE;
155 static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
157 /* We want more bytes than seem to be available.
158 * Maybe we need a new page, maybe we have just run out
160 unsigned int avail = (char *)argp->end - (char *)argp->p;
163 if (argp->pagelen == 0) {
164 struct kvec *vec = &argp->rqstp->rq_arg.tail[0];
168 avail = vec->iov_len;
169 argp->p = vec->iov_base;
170 argp->end = vec->iov_base + avail;
177 argp->p += XDR_QUADLEN(nbytes);
181 if (avail + argp->pagelen < nbytes)
183 if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */
185 /* ok, we can do it with the current plus the next page */
186 if (nbytes <= sizeof(argp->tmp))
190 p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL);
196 * The following memcpy is safe because read_buf is always
197 * called with nbytes > avail, and the two cases above both
198 * guarantee p points to at least nbytes bytes.
200 memcpy(p, argp->p, avail);
201 next_decode_page(argp);
202 memcpy(((char*)p)+avail, argp->p, (nbytes - avail));
203 argp->p += XDR_QUADLEN(nbytes - avail);
207 static int zero_clientid(clientid_t *clid)
209 return (clid->cl_boot == 0) && (clid->cl_id == 0);
213 * svcxdr_tmpalloc - allocate memory to be freed after compound processing
214 * @argp: NFSv4 compound argument structure
215 * @p: pointer to be freed (with kfree())
217 * Marks @p to be freed when processing the compound operation
218 * described in @argp finishes.
221 svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, u32 len)
223 struct svcxdr_tmpbuf *tb;
225 tb = kmalloc(sizeof(*tb) + len, GFP_KERNEL);
228 tb->next = argp->to_free;
234 * For xdr strings that need to be passed to other kernel api's
235 * as null-terminated strings.
237 * Note null-terminating in place usually isn't safe since the
238 * buffer might end on a page boundary.
241 svcxdr_dupstr(struct nfsd4_compoundargs *argp, void *buf, u32 len)
243 char *p = svcxdr_tmpalloc(argp, len + 1);
253 * savemem - duplicate a chunk of memory for later processing
254 * @argp: NFSv4 compound argument structure to be freed with
255 * @p: pointer to be duplicated
256 * @nbytes: length to be duplicated
258 * Returns a pointer to a copy of @nbytes bytes of memory at @p
259 * that are preserved until processing of the NFSv4 compound
260 * operation described by @argp finishes.
262 static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
266 ret = svcxdr_tmpalloc(argp, nbytes);
269 memcpy(ret, p, nbytes);
274 nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec64 *tv)
279 p = xdr_decode_hyper(p, &tv->tv_sec);
280 tv->tv_nsec = be32_to_cpup(p++);
281 if (tv->tv_nsec >= (u32)1000000000)
288 nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
298 bmlen = be32_to_cpup(p++);
302 READ_BUF(bmlen << 2);
304 bmval[0] = be32_to_cpup(p++);
306 bmval[1] = be32_to_cpup(p++);
308 bmval[2] = be32_to_cpup(p++);
314 nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
315 struct iattr *iattr, struct nfs4_acl **acl,
316 struct xdr_netobj *label, int *umask)
318 int expected_len, len = 0;
324 if ((status = nfsd4_decode_bitmap(argp, bmval)))
327 if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
328 || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
329 || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) {
330 if (nfsd_attrs_supported(argp->minorversion, bmval))
332 return nfserr_attrnotsupp;
336 expected_len = be32_to_cpup(p++);
338 if (bmval[0] & FATTR4_WORD0_SIZE) {
341 p = xdr_decode_hyper(p, &iattr->ia_size);
342 iattr->ia_valid |= ATTR_SIZE;
344 if (bmval[0] & FATTR4_WORD0_ACL) {
346 struct nfs4_ace *ace;
348 READ_BUF(4); len += 4;
349 nace = be32_to_cpup(p++);
351 if (nace > NFS4_ACL_MAX)
354 *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(nace));
356 return nfserr_jukebox;
358 (*acl)->naces = nace;
359 for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) {
360 READ_BUF(16); len += 16;
361 ace->type = be32_to_cpup(p++);
362 ace->flag = be32_to_cpup(p++);
363 ace->access_mask = be32_to_cpup(p++);
364 dummy32 = be32_to_cpup(p++);
366 len += XDR_QUADLEN(dummy32) << 2;
367 READMEM(buf, dummy32);
368 ace->whotype = nfs4_acl_get_whotype(buf, dummy32);
370 if (ace->whotype != NFS4_ACL_WHO_NAMED)
372 else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
373 status = nfsd_map_name_to_gid(argp->rqstp,
374 buf, dummy32, &ace->who_gid);
376 status = nfsd_map_name_to_uid(argp->rqstp,
377 buf, dummy32, &ace->who_uid);
383 if (bmval[1] & FATTR4_WORD1_MODE) {
386 iattr->ia_mode = be32_to_cpup(p++);
387 iattr->ia_mode &= (S_IFMT | S_IALLUGO);
388 iattr->ia_valid |= ATTR_MODE;
390 if (bmval[1] & FATTR4_WORD1_OWNER) {
393 dummy32 = be32_to_cpup(p++);
395 len += (XDR_QUADLEN(dummy32) << 2);
396 READMEM(buf, dummy32);
397 if ((status = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid)))
399 iattr->ia_valid |= ATTR_UID;
401 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) {
404 dummy32 = be32_to_cpup(p++);
406 len += (XDR_QUADLEN(dummy32) << 2);
407 READMEM(buf, dummy32);
408 if ((status = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid)))
410 iattr->ia_valid |= ATTR_GID;
412 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
415 dummy32 = be32_to_cpup(p++);
417 case NFS4_SET_TO_CLIENT_TIME:
419 status = nfsd4_decode_time(argp, &iattr->ia_atime);
422 iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
424 case NFS4_SET_TO_SERVER_TIME:
425 iattr->ia_valid |= ATTR_ATIME;
431 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
434 dummy32 = be32_to_cpup(p++);
436 case NFS4_SET_TO_CLIENT_TIME:
438 status = nfsd4_decode_time(argp, &iattr->ia_mtime);
441 iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
443 case NFS4_SET_TO_SERVER_TIME:
444 iattr->ia_valid |= ATTR_MTIME;
452 if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) &&
453 bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
456 dummy32 = be32_to_cpup(p++); /* lfs: we don't use it */
459 dummy32 = be32_to_cpup(p++); /* pi: we don't use it either */
462 dummy32 = be32_to_cpup(p++);
464 if (dummy32 > NFS4_MAXLABELLEN)
465 return nfserr_badlabel;
466 len += (XDR_QUADLEN(dummy32) << 2);
467 READMEM(buf, dummy32);
468 label->len = dummy32;
469 label->data = svcxdr_dupstr(argp, buf, dummy32);
471 return nfserr_jukebox;
473 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
478 dummy32 = be32_to_cpup(p++);
479 iattr->ia_mode = dummy32 & (S_IFMT | S_IALLUGO);
480 dummy32 = be32_to_cpup(p++);
481 *umask = dummy32 & S_IRWXUGO;
482 iattr->ia_valid |= ATTR_MODE;
484 if (len != expected_len)
491 nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid)
495 READ_BUF(sizeof(stateid_t));
496 sid->si_generation = be32_to_cpup(p++);
497 COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
503 nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access)
508 access->ac_req_access = be32_to_cpup(p++);
513 static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs)
516 struct user_namespace *userns = nfsd_user_namespace(argp->rqstp);
522 /* callback_sec_params4 */
524 nr_secflavs = be32_to_cpup(p++);
526 cbs->flavor = (u32)(-1);
528 /* Is this legal? Be generous, take it to mean AUTH_NONE: */
530 for (i = 0; i < nr_secflavs; ++i) {
532 dummy = be32_to_cpup(p++);
535 /* Nothing to read */
536 if (cbs->flavor == (u32)(-1))
537 cbs->flavor = RPC_AUTH_NULL;
542 dummy = be32_to_cpup(p++);
545 dummy = be32_to_cpup(p++);
547 SAVEMEM(machine_name, dummy);
551 uid = be32_to_cpup(p++);
552 gid = be32_to_cpup(p++);
556 dummy = be32_to_cpup(p++);
558 if (cbs->flavor == (u32)(-1)) {
559 kuid_t kuid = make_kuid(userns, uid);
560 kgid_t kgid = make_kgid(userns, gid);
561 if (uid_valid(kuid) && gid_valid(kgid)) {
564 cbs->flavor = RPC_AUTH_UNIX;
566 dprintk("RPC_AUTH_UNIX with invalid"
567 "uid or gid ignoring!\n");
572 dprintk("RPC_AUTH_GSS callback secflavor "
576 dummy = be32_to_cpup(p++);
577 /* gcbp_handle_from_server */
578 dummy = be32_to_cpup(p++);
580 p += XDR_QUADLEN(dummy);
581 /* gcbp_handle_from_client */
583 dummy = be32_to_cpup(p++);
587 dprintk("Illegal callback secflavor\n");
594 static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc)
599 bc->bc_cb_program = be32_to_cpup(p++);
600 nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec);
605 static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts)
609 READ_BUF(NFS4_MAX_SESSIONID_LEN + 8);
610 COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
611 bcts->dir = be32_to_cpup(p++);
612 /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker
613 * could help us figure out we should be using it. */
618 nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close)
623 close->cl_seqid = be32_to_cpup(p++);
624 return nfsd4_decode_stateid(argp, &close->cl_stateid);
631 nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit)
636 p = xdr_decode_hyper(p, &commit->co_offset);
637 commit->co_count = be32_to_cpup(p++);
643 nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create)
648 create->cr_type = be32_to_cpup(p++);
649 switch (create->cr_type) {
652 create->cr_datalen = be32_to_cpup(p++);
653 READ_BUF(create->cr_datalen);
654 create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen);
655 if (!create->cr_data)
656 return nfserr_jukebox;
661 create->cr_specdata1 = be32_to_cpup(p++);
662 create->cr_specdata2 = be32_to_cpup(p++);
672 create->cr_namelen = be32_to_cpup(p++);
673 READ_BUF(create->cr_namelen);
674 SAVEMEM(create->cr_name, create->cr_namelen);
675 if ((status = check_filename(create->cr_name, create->cr_namelen)))
678 status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
679 &create->cr_acl, &create->cr_label,
688 nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr)
690 return nfsd4_decode_stateid(argp, &dr->dr_stateid);
694 nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr)
696 return nfsd4_decode_bitmap(argp, getattr->ga_bmval);
700 nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link)
705 link->li_namelen = be32_to_cpup(p++);
706 READ_BUF(link->li_namelen);
707 SAVEMEM(link->li_name, link->li_namelen);
708 if ((status = check_filename(link->li_name, link->li_namelen)))
715 nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
720 * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
723 lock->lk_type = be32_to_cpup(p++);
724 if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT))
726 lock->lk_reclaim = be32_to_cpup(p++);
727 p = xdr_decode_hyper(p, &lock->lk_offset);
728 p = xdr_decode_hyper(p, &lock->lk_length);
729 lock->lk_is_new = be32_to_cpup(p++);
731 if (lock->lk_is_new) {
733 lock->lk_new_open_seqid = be32_to_cpup(p++);
734 status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid);
737 READ_BUF(8 + sizeof(clientid_t));
738 lock->lk_new_lock_seqid = be32_to_cpup(p++);
739 COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t));
740 lock->lk_new_owner.len = be32_to_cpup(p++);
741 READ_BUF(lock->lk_new_owner.len);
742 READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len);
744 status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid);
748 lock->lk_old_lock_seqid = be32_to_cpup(p++);
755 nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt)
760 lockt->lt_type = be32_to_cpup(p++);
761 if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT))
763 p = xdr_decode_hyper(p, &lockt->lt_offset);
764 p = xdr_decode_hyper(p, &lockt->lt_length);
765 COPYMEM(&lockt->lt_clientid, 8);
766 lockt->lt_owner.len = be32_to_cpup(p++);
767 READ_BUF(lockt->lt_owner.len);
768 READMEM(lockt->lt_owner.data, lockt->lt_owner.len);
774 nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku)
779 locku->lu_type = be32_to_cpup(p++);
780 if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
782 locku->lu_seqid = be32_to_cpup(p++);
783 status = nfsd4_decode_stateid(argp, &locku->lu_stateid);
787 p = xdr_decode_hyper(p, &locku->lu_offset);
788 p = xdr_decode_hyper(p, &locku->lu_length);
794 nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup)
799 lookup->lo_len = be32_to_cpup(p++);
800 READ_BUF(lookup->lo_len);
801 SAVEMEM(lookup->lo_name, lookup->lo_len);
802 if ((status = check_filename(lookup->lo_name, lookup->lo_len)))
808 static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *share_access, u32 *deleg_want, u32 *deleg_when)
814 w = be32_to_cpup(p++);
815 *share_access = w & NFS4_SHARE_ACCESS_MASK;
816 *deleg_want = w & NFS4_SHARE_WANT_MASK;
818 *deleg_when = w & NFS4_SHARE_WHEN_MASK;
820 switch (w & NFS4_SHARE_ACCESS_MASK) {
821 case NFS4_SHARE_ACCESS_READ:
822 case NFS4_SHARE_ACCESS_WRITE:
823 case NFS4_SHARE_ACCESS_BOTH:
826 return nfserr_bad_xdr;
828 w &= ~NFS4_SHARE_ACCESS_MASK;
831 if (!argp->minorversion)
832 return nfserr_bad_xdr;
833 switch (w & NFS4_SHARE_WANT_MASK) {
834 case NFS4_SHARE_WANT_NO_PREFERENCE:
835 case NFS4_SHARE_WANT_READ_DELEG:
836 case NFS4_SHARE_WANT_WRITE_DELEG:
837 case NFS4_SHARE_WANT_ANY_DELEG:
838 case NFS4_SHARE_WANT_NO_DELEG:
839 case NFS4_SHARE_WANT_CANCEL:
842 return nfserr_bad_xdr;
844 w &= ~NFS4_SHARE_WANT_MASK;
848 if (!deleg_when) /* open_downgrade */
851 case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL:
852 case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED:
853 case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL |
854 NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED):
858 return nfserr_bad_xdr;
861 static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x)
866 *x = be32_to_cpup(p++);
867 /* Note: unlinke access bits, deny bits may be zero. */
868 if (*x & ~NFS4_SHARE_DENY_BOTH)
869 return nfserr_bad_xdr;
872 return nfserr_bad_xdr;
875 static __be32 nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o)
880 o->len = be32_to_cpup(p++);
882 if (o->len == 0 || o->len > NFS4_OPAQUE_LIMIT)
883 return nfserr_bad_xdr;
886 SAVEMEM(o->data, o->len);
889 return nfserr_bad_xdr;
893 nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
898 memset(open->op_bmval, 0, sizeof(open->op_bmval));
899 open->op_iattr.ia_valid = 0;
900 open->op_openowner = NULL;
902 open->op_xdr_error = 0;
903 /* seqid, share_access, share_deny, clientid, ownerlen */
905 open->op_seqid = be32_to_cpup(p++);
906 /* decode, yet ignore deleg_when until supported */
907 status = nfsd4_decode_share_access(argp, &open->op_share_access,
908 &open->op_deleg_want, &dummy);
911 status = nfsd4_decode_share_deny(argp, &open->op_share_deny);
914 READ_BUF(sizeof(clientid_t));
915 COPYMEM(&open->op_clientid, sizeof(clientid_t));
916 status = nfsd4_decode_opaque(argp, &open->op_owner);
920 open->op_create = be32_to_cpup(p++);
921 switch (open->op_create) {
922 case NFS4_OPEN_NOCREATE:
924 case NFS4_OPEN_CREATE:
926 open->op_createmode = be32_to_cpup(p++);
927 switch (open->op_createmode) {
928 case NFS4_CREATE_UNCHECKED:
929 case NFS4_CREATE_GUARDED:
930 status = nfsd4_decode_fattr(argp, open->op_bmval,
931 &open->op_iattr, &open->op_acl, &open->op_label,
936 case NFS4_CREATE_EXCLUSIVE:
937 READ_BUF(NFS4_VERIFIER_SIZE);
938 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
940 case NFS4_CREATE_EXCLUSIVE4_1:
941 if (argp->minorversion < 1)
943 READ_BUF(NFS4_VERIFIER_SIZE);
944 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
945 status = nfsd4_decode_fattr(argp, open->op_bmval,
946 &open->op_iattr, &open->op_acl, &open->op_label,
961 open->op_claim_type = be32_to_cpup(p++);
962 switch (open->op_claim_type) {
963 case NFS4_OPEN_CLAIM_NULL:
964 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
966 open->op_fname.len = be32_to_cpup(p++);
967 READ_BUF(open->op_fname.len);
968 SAVEMEM(open->op_fname.data, open->op_fname.len);
969 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
972 case NFS4_OPEN_CLAIM_PREVIOUS:
974 open->op_delegate_type = be32_to_cpup(p++);
976 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
977 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
981 open->op_fname.len = be32_to_cpup(p++);
982 READ_BUF(open->op_fname.len);
983 SAVEMEM(open->op_fname.data, open->op_fname.len);
984 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
987 case NFS4_OPEN_CLAIM_FH:
988 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
989 if (argp->minorversion < 1)
993 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
994 if (argp->minorversion < 1)
996 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
1008 nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf)
1012 if (argp->minorversion >= 1)
1013 return nfserr_notsupp;
1015 status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
1019 open_conf->oc_seqid = be32_to_cpup(p++);
1025 nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down)
1029 status = nfsd4_decode_stateid(argp, &open_down->od_stateid);
1033 open_down->od_seqid = be32_to_cpup(p++);
1034 status = nfsd4_decode_share_access(argp, &open_down->od_share_access,
1035 &open_down->od_deleg_want, NULL);
1038 status = nfsd4_decode_share_deny(argp, &open_down->od_share_deny);
1045 nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh)
1050 putfh->pf_fhlen = be32_to_cpup(p++);
1051 if (putfh->pf_fhlen > NFS4_FHSIZE)
1053 READ_BUF(putfh->pf_fhlen);
1054 SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen);
1060 nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p)
1062 if (argp->minorversion == 0)
1064 return nfserr_notsupp;
1068 nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
1072 status = nfsd4_decode_stateid(argp, &read->rd_stateid);
1076 p = xdr_decode_hyper(p, &read->rd_offset);
1077 read->rd_length = be32_to_cpup(p++);
1083 nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir)
1088 p = xdr_decode_hyper(p, &readdir->rd_cookie);
1089 COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data));
1090 readdir->rd_dircount = be32_to_cpup(p++);
1091 readdir->rd_maxcount = be32_to_cpup(p++);
1092 if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval)))
1099 nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove)
1104 remove->rm_namelen = be32_to_cpup(p++);
1105 READ_BUF(remove->rm_namelen);
1106 SAVEMEM(remove->rm_name, remove->rm_namelen);
1107 if ((status = check_filename(remove->rm_name, remove->rm_namelen)))
1114 nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename)
1119 rename->rn_snamelen = be32_to_cpup(p++);
1120 READ_BUF(rename->rn_snamelen);
1121 SAVEMEM(rename->rn_sname, rename->rn_snamelen);
1123 rename->rn_tnamelen = be32_to_cpup(p++);
1124 READ_BUF(rename->rn_tnamelen);
1125 SAVEMEM(rename->rn_tname, rename->rn_tnamelen);
1126 if ((status = check_filename(rename->rn_sname, rename->rn_snamelen)))
1128 if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen)))
1135 nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid)
1139 if (argp->minorversion >= 1)
1140 return nfserr_notsupp;
1142 READ_BUF(sizeof(clientid_t));
1143 COPYMEM(clientid, sizeof(clientid_t));
1149 nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
1150 struct nfsd4_secinfo *secinfo)
1155 secinfo->si_namelen = be32_to_cpup(p++);
1156 READ_BUF(secinfo->si_namelen);
1157 SAVEMEM(secinfo->si_name, secinfo->si_namelen);
1158 status = check_filename(secinfo->si_name, secinfo->si_namelen);
1165 nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp,
1166 struct nfsd4_secinfo_no_name *sin)
1171 sin->sin_style = be32_to_cpup(p++);
1176 nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr)
1180 status = nfsd4_decode_stateid(argp, &setattr->sa_stateid);
1183 return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr,
1184 &setattr->sa_acl, &setattr->sa_label, NULL);
1188 nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid)
1192 if (argp->minorversion >= 1)
1193 return nfserr_notsupp;
1195 READ_BUF(NFS4_VERIFIER_SIZE);
1196 COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE);
1198 status = nfsd4_decode_opaque(argp, &setclientid->se_name);
1200 return nfserr_bad_xdr;
1202 setclientid->se_callback_prog = be32_to_cpup(p++);
1203 setclientid->se_callback_netid_len = be32_to_cpup(p++);
1204 READ_BUF(setclientid->se_callback_netid_len);
1205 SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len);
1207 setclientid->se_callback_addr_len = be32_to_cpup(p++);
1209 READ_BUF(setclientid->se_callback_addr_len);
1210 SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len);
1212 setclientid->se_callback_ident = be32_to_cpup(p++);
1218 nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c)
1222 if (argp->minorversion >= 1)
1223 return nfserr_notsupp;
1225 READ_BUF(8 + NFS4_VERIFIER_SIZE);
1226 COPYMEM(&scd_c->sc_clientid, 8);
1227 COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE);
1232 /* Also used for NVERIFY */
1234 nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify)
1238 if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval)))
1241 /* For convenience's sake, we compare raw xdr'd attributes in
1242 * nfsd4_proc_verify */
1245 verify->ve_attrlen = be32_to_cpup(p++);
1246 READ_BUF(verify->ve_attrlen);
1247 SAVEMEM(verify->ve_attrval, verify->ve_attrlen);
1253 nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
1259 status = nfsd4_decode_stateid(argp, &write->wr_stateid);
1263 p = xdr_decode_hyper(p, &write->wr_offset);
1264 write->wr_stable_how = be32_to_cpup(p++);
1265 if (write->wr_stable_how > NFS_FILE_SYNC)
1267 write->wr_buflen = be32_to_cpup(p++);
1269 /* Sorry .. no magic macros for this.. *
1270 * READ_BUF(write->wr_buflen);
1271 * SAVEMEM(write->wr_buf, write->wr_buflen);
1273 avail = (char*)argp->end - (char*)argp->p;
1274 if (avail + argp->pagelen < write->wr_buflen) {
1275 dprintk("NFSD: xdr error (%s:%d)\n",
1276 __FILE__, __LINE__);
1279 write->wr_head.iov_base = p;
1280 write->wr_head.iov_len = avail;
1281 write->wr_pagelist = argp->pagelist;
1283 len = XDR_QUADLEN(write->wr_buflen) << 2;
1289 pages = len >> PAGE_SHIFT;
1290 argp->pagelist += pages;
1291 argp->pagelen -= pages * PAGE_SIZE;
1292 len -= pages * PAGE_SIZE;
1294 next_decode_page(argp);
1296 argp->p += XDR_QUADLEN(len);
1302 nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner)
1306 if (argp->minorversion >= 1)
1307 return nfserr_notsupp;
1310 COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t));
1311 rlockowner->rl_owner.len = be32_to_cpup(p++);
1312 READ_BUF(rlockowner->rl_owner.len);
1313 READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len);
1315 if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid))
1316 return nfserr_inval;
1321 nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
1322 struct nfsd4_exchange_id *exid)
1327 READ_BUF(NFS4_VERIFIER_SIZE);
1328 COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE);
1330 status = nfsd4_decode_opaque(argp, &exid->clname);
1332 return nfserr_bad_xdr;
1335 exid->flags = be32_to_cpup(p++);
1337 /* Ignore state_protect4_a */
1339 exid->spa_how = be32_to_cpup(p++);
1340 switch (exid->spa_how) {
1344 /* spo_must_enforce */
1345 status = nfsd4_decode_bitmap(argp,
1346 exid->spo_must_enforce);
1349 /* spo_must_allow */
1350 status = nfsd4_decode_bitmap(argp, exid->spo_must_allow);
1357 dummy = be32_to_cpup(p++);
1358 READ_BUF(dummy * 4);
1362 dummy = be32_to_cpup(p++);
1363 READ_BUF(dummy * 4);
1366 /* ssp_hash_algs<> */
1368 tmp = be32_to_cpup(p++);
1371 dummy = be32_to_cpup(p++);
1373 p += XDR_QUADLEN(dummy);
1376 /* ssp_encr_algs<> */
1378 tmp = be32_to_cpup(p++);
1381 dummy = be32_to_cpup(p++);
1383 p += XDR_QUADLEN(dummy);
1386 /* ignore ssp_window and ssp_num_gss_handles: */
1393 READ_BUF(4); /* nfs_impl_id4 array length */
1394 dummy = be32_to_cpup(p++);
1400 status = nfsd4_decode_opaque(argp, &exid->nii_domain);
1405 status = nfsd4_decode_opaque(argp, &exid->nii_name);
1410 status = nfsd4_decode_time(argp, &exid->nii_time);
1418 nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
1419 struct nfsd4_create_session *sess)
1425 COPYMEM(&sess->clientid, 8);
1426 sess->seqid = be32_to_cpup(p++);
1427 sess->flags = be32_to_cpup(p++);
1429 /* Fore channel attrs */
1431 dummy = be32_to_cpup(p++); /* headerpadsz is always 0 */
1432 sess->fore_channel.maxreq_sz = be32_to_cpup(p++);
1433 sess->fore_channel.maxresp_sz = be32_to_cpup(p++);
1434 sess->fore_channel.maxresp_cached = be32_to_cpup(p++);
1435 sess->fore_channel.maxops = be32_to_cpup(p++);
1436 sess->fore_channel.maxreqs = be32_to_cpup(p++);
1437 sess->fore_channel.nr_rdma_attrs = be32_to_cpup(p++);
1438 if (sess->fore_channel.nr_rdma_attrs == 1) {
1440 sess->fore_channel.rdma_attrs = be32_to_cpup(p++);
1441 } else if (sess->fore_channel.nr_rdma_attrs > 1) {
1442 dprintk("Too many fore channel attr bitmaps!\n");
1446 /* Back channel attrs */
1448 dummy = be32_to_cpup(p++); /* headerpadsz is always 0 */
1449 sess->back_channel.maxreq_sz = be32_to_cpup(p++);
1450 sess->back_channel.maxresp_sz = be32_to_cpup(p++);
1451 sess->back_channel.maxresp_cached = be32_to_cpup(p++);
1452 sess->back_channel.maxops = be32_to_cpup(p++);
1453 sess->back_channel.maxreqs = be32_to_cpup(p++);
1454 sess->back_channel.nr_rdma_attrs = be32_to_cpup(p++);
1455 if (sess->back_channel.nr_rdma_attrs == 1) {
1457 sess->back_channel.rdma_attrs = be32_to_cpup(p++);
1458 } else if (sess->back_channel.nr_rdma_attrs > 1) {
1459 dprintk("Too many back channel attr bitmaps!\n");
1464 sess->callback_prog = be32_to_cpup(p++);
1465 nfsd4_decode_cb_sec(argp, &sess->cb_sec);
1470 nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp,
1471 struct nfsd4_destroy_session *destroy_session)
1474 READ_BUF(NFS4_MAX_SESSIONID_LEN);
1475 COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1481 nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp,
1482 struct nfsd4_free_stateid *free_stateid)
1486 READ_BUF(sizeof(stateid_t));
1487 free_stateid->fr_stateid.si_generation = be32_to_cpup(p++);
1488 COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t));
1494 nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
1495 struct nfsd4_sequence *seq)
1499 READ_BUF(NFS4_MAX_SESSIONID_LEN + 16);
1500 COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1501 seq->seqid = be32_to_cpup(p++);
1502 seq->slotid = be32_to_cpup(p++);
1503 seq->maxslots = be32_to_cpup(p++);
1504 seq->cachethis = be32_to_cpup(p++);
1510 nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid)
1514 struct nfsd4_test_stateid_id *stateid;
1517 test_stateid->ts_num_ids = ntohl(*p++);
1519 INIT_LIST_HEAD(&test_stateid->ts_stateid_list);
1521 for (i = 0; i < test_stateid->ts_num_ids; i++) {
1522 stateid = svcxdr_tmpalloc(argp, sizeof(*stateid));
1524 status = nfserrno(-ENOMEM);
1528 INIT_LIST_HEAD(&stateid->ts_id_list);
1529 list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list);
1531 status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid);
1540 dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__);
1541 status = nfserr_bad_xdr;
1545 static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc)
1550 COPYMEM(&dc->clientid, 8);
1555 static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc)
1560 rc->rca_one_fs = be32_to_cpup(p++);
1565 #ifdef CONFIG_NFSD_PNFS
1567 nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp,
1568 struct nfsd4_getdeviceinfo *gdev)
1573 READ_BUF(sizeof(struct nfsd4_deviceid) + 3 * 4);
1574 COPYMEM(&gdev->gd_devid, sizeof(struct nfsd4_deviceid));
1575 gdev->gd_layout_type = be32_to_cpup(p++);
1576 gdev->gd_maxcount = be32_to_cpup(p++);
1577 num = be32_to_cpup(p++);
1582 gdev->gd_notify_types = be32_to_cpup(p++);
1583 for (i = 1; i < num; i++) {
1584 if (be32_to_cpup(p++)) {
1585 status = nfserr_inval;
1594 nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp,
1595 struct nfsd4_layoutget *lgp)
1600 lgp->lg_signal = be32_to_cpup(p++);
1601 lgp->lg_layout_type = be32_to_cpup(p++);
1602 lgp->lg_seg.iomode = be32_to_cpup(p++);
1603 p = xdr_decode_hyper(p, &lgp->lg_seg.offset);
1604 p = xdr_decode_hyper(p, &lgp->lg_seg.length);
1605 p = xdr_decode_hyper(p, &lgp->lg_minlength);
1607 status = nfsd4_decode_stateid(argp, &lgp->lg_sid);
1612 lgp->lg_maxcount = be32_to_cpup(p++);
1618 nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp,
1619 struct nfsd4_layoutcommit *lcp)
1625 p = xdr_decode_hyper(p, &lcp->lc_seg.offset);
1626 p = xdr_decode_hyper(p, &lcp->lc_seg.length);
1627 lcp->lc_reclaim = be32_to_cpup(p++);
1629 status = nfsd4_decode_stateid(argp, &lcp->lc_sid);
1634 lcp->lc_newoffset = be32_to_cpup(p++);
1635 if (lcp->lc_newoffset) {
1637 p = xdr_decode_hyper(p, &lcp->lc_last_wr);
1639 lcp->lc_last_wr = 0;
1641 timechange = be32_to_cpup(p++);
1643 status = nfsd4_decode_time(argp, &lcp->lc_mtime);
1647 lcp->lc_mtime.tv_nsec = UTIME_NOW;
1650 lcp->lc_layout_type = be32_to_cpup(p++);
1653 * Save the layout update in XDR format and let the layout driver deal
1656 lcp->lc_up_len = be32_to_cpup(p++);
1657 if (lcp->lc_up_len > 0) {
1658 READ_BUF(lcp->lc_up_len);
1659 READMEM(lcp->lc_up_layout, lcp->lc_up_len);
1666 nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp,
1667 struct nfsd4_layoutreturn *lrp)
1672 lrp->lr_reclaim = be32_to_cpup(p++);
1673 lrp->lr_layout_type = be32_to_cpup(p++);
1674 lrp->lr_seg.iomode = be32_to_cpup(p++);
1675 lrp->lr_return_type = be32_to_cpup(p++);
1676 if (lrp->lr_return_type == RETURN_FILE) {
1678 p = xdr_decode_hyper(p, &lrp->lr_seg.offset);
1679 p = xdr_decode_hyper(p, &lrp->lr_seg.length);
1681 status = nfsd4_decode_stateid(argp, &lrp->lr_sid);
1686 lrp->lrf_body_len = be32_to_cpup(p++);
1687 if (lrp->lrf_body_len > 0) {
1688 READ_BUF(lrp->lrf_body_len);
1689 READMEM(lrp->lrf_body, lrp->lrf_body_len);
1692 lrp->lr_seg.offset = 0;
1693 lrp->lr_seg.length = NFS4_MAX_UINT64;
1698 #endif /* CONFIG_NFSD_PNFS */
1701 nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp,
1702 struct nfsd4_fallocate *fallocate)
1706 status = nfsd4_decode_stateid(argp, &fallocate->falloc_stateid);
1711 p = xdr_decode_hyper(p, &fallocate->falloc_offset);
1712 xdr_decode_hyper(p, &fallocate->falloc_length);
1718 nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone)
1722 status = nfsd4_decode_stateid(argp, &clone->cl_src_stateid);
1725 status = nfsd4_decode_stateid(argp, &clone->cl_dst_stateid);
1729 READ_BUF(8 + 8 + 8);
1730 p = xdr_decode_hyper(p, &clone->cl_src_pos);
1731 p = xdr_decode_hyper(p, &clone->cl_dst_pos);
1732 p = xdr_decode_hyper(p, &clone->cl_count);
1737 nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy)
1742 status = nfsd4_decode_stateid(argp, ©->cp_src_stateid);
1745 status = nfsd4_decode_stateid(argp, ©->cp_dst_stateid);
1749 READ_BUF(8 + 8 + 8 + 4 + 4 + 4);
1750 p = xdr_decode_hyper(p, ©->cp_src_pos);
1751 p = xdr_decode_hyper(p, ©->cp_dst_pos);
1752 p = xdr_decode_hyper(p, ©->cp_count);
1753 p++; /* ca_consecutive: we always do consecutive copies */
1754 copy->cp_synchronous = be32_to_cpup(p++);
1755 tmp = be32_to_cpup(p); /* Source server list not supported */
1761 nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp,
1762 struct nfsd4_offload_status *os)
1764 return nfsd4_decode_stateid(argp, &os->stateid);
1768 nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek)
1772 status = nfsd4_decode_stateid(argp, &seek->seek_stateid);
1777 p = xdr_decode_hyper(p, &seek->seek_offset);
1778 seek->seek_whence = be32_to_cpup(p);
1784 nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p)
1790 nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
1792 return nfserr_notsupp;
1795 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
1797 static const nfsd4_dec nfsd4_dec_ops[] = {
1798 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
1799 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
1800 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
1801 [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
1802 [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
1803 [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
1804 [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
1805 [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
1806 [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
1807 [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
1808 [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
1809 [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
1810 [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
1811 [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
1812 [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1813 [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
1814 [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
1815 [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm,
1816 [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
1817 [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
1818 [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh,
1819 [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
1820 [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
1821 [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
1822 [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
1823 [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
1824 [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
1825 [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew,
1826 [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
1827 [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
1828 [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
1829 [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
1830 [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid,
1831 [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm,
1832 [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1833 [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
1834 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
1836 /* new operations for NFSv4.1 */
1837 [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl,
1838 [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session,
1839 [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id,
1840 [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session,
1841 [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session,
1842 [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid,
1843 [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
1844 #ifdef CONFIG_NFSD_PNFS
1845 [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_getdeviceinfo,
1846 [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
1847 [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_layoutcommit,
1848 [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_layoutget,
1849 [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_layoutreturn,
1851 [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp,
1852 [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
1853 [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp,
1854 [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp,
1855 [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp,
1857 [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name,
1858 [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence,
1859 [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp,
1860 [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid,
1861 [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
1862 [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid,
1863 [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete,
1865 /* new operations for NFSv4.2 */
1866 [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate,
1867 [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy,
1868 [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_notsupp,
1869 [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate,
1870 [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp,
1871 [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp,
1872 [OP_LAYOUTSTATS] = (nfsd4_dec)nfsd4_decode_notsupp,
1873 [OP_OFFLOAD_CANCEL] = (nfsd4_dec)nfsd4_decode_offload_status,
1874 [OP_OFFLOAD_STATUS] = (nfsd4_dec)nfsd4_decode_offload_status,
1875 [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_notsupp,
1876 [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek,
1877 [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp,
1878 [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone,
1882 nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op)
1884 if (op->opnum < FIRST_NFS4_OP)
1886 else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP)
1888 else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP)
1890 else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP)
1896 nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
1899 struct nfsd4_op *op;
1900 bool cachethis = false;
1901 int auth_slack= argp->rqstp->rq_auth_slack;
1902 int max_reply = auth_slack + 8; /* opcnt, status */
1908 argp->taglen = be32_to_cpup(p++);
1909 READ_BUF(argp->taglen);
1910 SAVEMEM(argp->tag, argp->taglen);
1912 argp->minorversion = be32_to_cpup(p++);
1913 argp->opcnt = be32_to_cpup(p++);
1914 max_reply += 4 + (XDR_QUADLEN(argp->taglen) << 2);
1916 if (argp->taglen > NFSD4_MAX_TAGLEN)
1919 * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS
1920 * here, so we return success at the xdr level so that
1921 * nfsd4_proc can handle this is an NFS-level error.
1923 if (argp->opcnt > NFSD_MAX_OPS_PER_COMPOUND)
1926 if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
1927 argp->ops = kzalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL);
1929 argp->ops = argp->iops;
1930 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
1935 if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION)
1938 for (i = 0; i < argp->opcnt; i++) {
1943 op->opnum = be32_to_cpup(p++);
1945 if (nfsd4_opnum_in_range(argp, op))
1946 op->status = nfsd4_dec_ops[op->opnum](argp, &op->u);
1948 op->opnum = OP_ILLEGAL;
1949 op->status = nfserr_op_illegal;
1951 op->opdesc = OPDESC(op);
1953 * We'll try to cache the result in the DRC if any one
1954 * op in the compound wants to be cached:
1956 cachethis |= nfsd4_cache_this_op(op);
1958 if (op->opnum == OP_READ) {
1960 readbytes += nfsd4_max_reply(argp->rqstp, op);
1962 max_reply += nfsd4_max_reply(argp->rqstp, op);
1964 * OP_LOCK and OP_LOCKT may return a conflicting lock.
1965 * (Special case because it will just skip encoding this
1966 * if it runs out of xdr buffer space, and it is the only
1967 * operation that behaves this way.)
1969 if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT)
1970 max_reply += NFS4_OPAQUE_LIMIT;
1977 /* Sessions make the DRC unnecessary: */
1978 if (argp->minorversion)
1980 svc_reserve(argp->rqstp, max_reply + readbytes);
1981 argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE;
1983 if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack)
1984 clear_bit(RQ_SPLICE_OK, &argp->rqstp->rq_flags);
1989 static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode,
1990 struct svc_export *exp)
1992 if (exp->ex_flags & NFSEXP_V4ROOT) {
1993 *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time));
1995 } else if (IS_I_VERSION(inode)) {
1996 p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode));
1998 *p++ = cpu_to_be32(stat->ctime.tv_sec);
1999 *p++ = cpu_to_be32(stat->ctime.tv_nsec);
2005 * ctime (in NFSv4, time_metadata) is not writeable, and the client
2006 * doesn't really care what resolution could theoretically be stored by
2009 * The client cares how close together changes can be while still
2010 * guaranteeing ctime changes. For most filesystems (which have
2011 * timestamps with nanosecond fields) that is limited by the resolution
2012 * of the time returned from current_time() (which I'm assuming to be
2015 static __be32 *encode_time_delta(__be32 *p, struct inode *inode)
2020 ns = max_t(u32, NSEC_PER_SEC/HZ, inode->i_sb->s_time_gran);
2021 ts = ns_to_timespec(ns);
2023 p = xdr_encode_hyper(p, ts.tv_sec);
2024 *p++ = cpu_to_be32(ts.tv_nsec);
2029 static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c)
2031 *p++ = cpu_to_be32(c->atomic);
2032 if (c->change_supported) {
2033 p = xdr_encode_hyper(p, c->before_change);
2034 p = xdr_encode_hyper(p, c->after_change);
2036 *p++ = cpu_to_be32(c->before_ctime_sec);
2037 *p++ = cpu_to_be32(c->before_ctime_nsec);
2038 *p++ = cpu_to_be32(c->after_ctime_sec);
2039 *p++ = cpu_to_be32(c->after_ctime_nsec);
2044 /* Encode as an array of strings the string given with components
2045 * separated @sep, escaped with esc_enter and esc_exit.
2047 static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep,
2048 char *components, char esc_enter,
2054 int strlen, count=0;
2055 char *str, *end, *next;
2057 dprintk("nfsd4_encode_components(%s)\n", components);
2059 pathlen_offset = xdr->buf->len;
2060 p = xdr_reserve_space(xdr, 4);
2062 return nfserr_resource;
2063 p++; /* We will fill this in with @count later */
2065 end = str = components;
2067 bool found_esc = false;
2069 /* try to parse as esc_start, ..., esc_end, sep */
2070 if (*str == esc_enter) {
2071 for (; *end && (*end != esc_exit); end++)
2072 /* find esc_exit or end of string */;
2074 if (*end && (!*next || *next == sep)) {
2081 for (; *end && (*end != sep); end++)
2082 /* find sep or end of string */;
2086 p = xdr_reserve_space(xdr, strlen + 4);
2088 return nfserr_resource;
2089 p = xdr_encode_opaque(p, str, strlen);
2099 pathlen = htonl(count);
2100 write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4);
2104 /* Encode as an array of strings the string given with components
2107 static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep,
2110 return nfsd4_encode_components_esc(xdr, sep, components, 0, 0);
2114 * encode a location element of a fs_locations structure
2116 static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr,
2117 struct nfsd4_fs_location *location)
2121 status = nfsd4_encode_components_esc(xdr, ':', location->hosts,
2125 status = nfsd4_encode_components(xdr, '/', location->path);
2132 * Encode a path in RFC3530 'pathname4' format
2134 static __be32 nfsd4_encode_path(struct xdr_stream *xdr,
2135 const struct path *root,
2136 const struct path *path)
2138 struct path cur = *path;
2140 struct dentry **components = NULL;
2141 unsigned int ncomponents = 0;
2142 __be32 err = nfserr_jukebox;
2144 dprintk("nfsd4_encode_components(");
2147 /* First walk the path up to the nfsd root, and store the
2148 * dentries/path components in an array.
2151 if (path_equal(&cur, root))
2153 if (cur.dentry == cur.mnt->mnt_root) {
2154 if (follow_up(&cur))
2158 if ((ncomponents & 15) == 0) {
2159 struct dentry **new;
2160 new = krealloc(components,
2161 sizeof(*new) * (ncomponents + 16),
2167 components[ncomponents++] = cur.dentry;
2168 cur.dentry = dget_parent(cur.dentry);
2170 err = nfserr_resource;
2171 p = xdr_reserve_space(xdr, 4);
2174 *p++ = cpu_to_be32(ncomponents);
2176 while (ncomponents) {
2177 struct dentry *dentry = components[ncomponents - 1];
2180 spin_lock(&dentry->d_lock);
2181 len = dentry->d_name.len;
2182 p = xdr_reserve_space(xdr, len + 4);
2184 spin_unlock(&dentry->d_lock);
2187 p = xdr_encode_opaque(p, dentry->d_name.name, len);
2188 dprintk("/%pd", dentry);
2189 spin_unlock(&dentry->d_lock);
2198 dput(components[--ncomponents]);
2204 static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr,
2205 struct svc_rqst *rqstp, const struct path *path)
2207 struct svc_export *exp_ps;
2210 exp_ps = rqst_find_fsidzero_export(rqstp);
2212 return nfserrno(PTR_ERR(exp_ps));
2213 res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path);
2219 * encode a fs_locations structure
2221 static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr,
2222 struct svc_rqst *rqstp, struct svc_export *exp)
2227 struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
2229 status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path);
2232 p = xdr_reserve_space(xdr, 4);
2234 return nfserr_resource;
2235 *p++ = cpu_to_be32(fslocs->locations_count);
2236 for (i=0; i<fslocs->locations_count; i++) {
2237 status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]);
2244 static u32 nfs4_file_type(umode_t mode)
2246 switch (mode & S_IFMT) {
2247 case S_IFIFO: return NF4FIFO;
2248 case S_IFCHR: return NF4CHR;
2249 case S_IFDIR: return NF4DIR;
2250 case S_IFBLK: return NF4BLK;
2251 case S_IFLNK: return NF4LNK;
2252 case S_IFREG: return NF4REG;
2253 case S_IFSOCK: return NF4SOCK;
2254 default: return NF4BAD;
2258 static inline __be32
2259 nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp,
2260 struct nfs4_ace *ace)
2262 if (ace->whotype != NFS4_ACL_WHO_NAMED)
2263 return nfs4_acl_write_who(xdr, ace->whotype);
2264 else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
2265 return nfsd4_encode_group(xdr, rqstp, ace->who_gid);
2267 return nfsd4_encode_user(xdr, rqstp, ace->who_uid);
2270 static inline __be32
2271 nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types)
2274 unsigned long i = hweight_long(layout_types);
2276 p = xdr_reserve_space(xdr, 4 + 4 * i);
2278 return nfserr_resource;
2280 *p++ = cpu_to_be32(i);
2282 for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i)
2283 if (layout_types & (1 << i))
2284 *p++ = cpu_to_be32(i);
2289 #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
2290 FATTR4_WORD0_RDATTR_ERROR)
2291 #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
2292 #define WORD2_ABSENT_FS_ATTRS 0
2294 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2295 static inline __be32
2296 nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,
2297 void *context, int len)
2301 p = xdr_reserve_space(xdr, len + 4 + 4 + 4);
2303 return nfserr_resource;
2306 * For now we use a 0 here to indicate the null translation; in
2307 * the future we may place a call to translation code here.
2309 *p++ = cpu_to_be32(0); /* lfs */
2310 *p++ = cpu_to_be32(0); /* pi */
2311 p = xdr_encode_opaque(p, context, len);
2315 static inline __be32
2316 nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp,
2317 void *context, int len)
2321 static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *bmval2, u32 *rdattr_err)
2323 /* As per referral draft: */
2324 if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
2325 *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
2326 if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
2327 *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
2328 *rdattr_err = NFSERR_MOVED;
2330 return nfserr_moved;
2332 *bmval0 &= WORD0_ABSENT_FS_ATTRS;
2333 *bmval1 &= WORD1_ABSENT_FS_ATTRS;
2334 *bmval2 &= WORD2_ABSENT_FS_ATTRS;
2339 static int get_parent_attributes(struct svc_export *exp, struct kstat *stat)
2341 struct path path = exp->ex_path;
2345 while (follow_up(&path)) {
2346 if (path.dentry != path.mnt->mnt_root)
2349 err = vfs_getattr(&path, stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
2355 nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2)
2360 p = xdr_reserve_space(xdr, 16);
2363 *p++ = cpu_to_be32(3);
2364 *p++ = cpu_to_be32(bmval0);
2365 *p++ = cpu_to_be32(bmval1);
2366 *p++ = cpu_to_be32(bmval2);
2367 } else if (bmval1) {
2368 p = xdr_reserve_space(xdr, 12);
2371 *p++ = cpu_to_be32(2);
2372 *p++ = cpu_to_be32(bmval0);
2373 *p++ = cpu_to_be32(bmval1);
2375 p = xdr_reserve_space(xdr, 8);
2378 *p++ = cpu_to_be32(1);
2379 *p++ = cpu_to_be32(bmval0);
2384 return nfserr_resource;
2388 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
2392 nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp,
2393 struct svc_export *exp,
2394 struct dentry *dentry, u32 *bmval,
2395 struct svc_rqst *rqstp, int ignore_crossmnt)
2397 u32 bmval0 = bmval[0];
2398 u32 bmval1 = bmval[1];
2399 u32 bmval2 = bmval[2];
2401 struct svc_fh *tempfh = NULL;
2402 struct kstatfs statfs;
2404 int starting_len = xdr->buf->len;
2412 struct nfs4_acl *acl = NULL;
2413 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2414 void *context = NULL;
2417 bool contextsupport = false;
2418 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2419 u32 minorversion = resp->cstate.minorversion;
2420 struct path path = {
2421 .mnt = exp->ex_path.mnt,
2424 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
2426 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
2427 BUG_ON(!nfsd_attrs_supported(minorversion, bmval));
2429 if (exp->ex_fslocs.migrated) {
2430 status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err);
2435 err = vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
2438 if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
2439 FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) ||
2440 (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
2441 FATTR4_WORD1_SPACE_TOTAL))) {
2442 err = vfs_statfs(&path, &statfs);
2446 if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
2447 tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
2448 status = nfserr_jukebox;
2451 fh_init(tempfh, NFS4_FHSIZE);
2452 status = fh_compose(tempfh, exp, dentry, NULL);
2457 if (bmval0 & FATTR4_WORD0_ACL) {
2458 err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
2459 if (err == -EOPNOTSUPP)
2460 bmval0 &= ~FATTR4_WORD0_ACL;
2461 else if (err == -EINVAL) {
2462 status = nfserr_attrnotsupp;
2464 } else if (err != 0)
2468 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2469 if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) ||
2470 bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
2471 if (exp->ex_flags & NFSEXP_SECURITY_LABEL)
2472 err = security_inode_getsecctx(d_inode(dentry),
2473 &context, &contextlen);
2476 contextsupport = (err == 0);
2477 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
2478 if (err == -EOPNOTSUPP)
2479 bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL;
2484 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
2486 status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2);
2490 attrlen_offset = xdr->buf->len;
2491 p = xdr_reserve_space(xdr, 4);
2494 p++; /* to be backfilled later */
2496 if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
2499 memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp));
2501 if (!IS_POSIXACL(dentry->d_inode))
2502 supp[0] &= ~FATTR4_WORD0_ACL;
2503 if (!contextsupport)
2504 supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
2506 p = xdr_reserve_space(xdr, 12);
2509 *p++ = cpu_to_be32(2);
2510 *p++ = cpu_to_be32(supp[0]);
2511 *p++ = cpu_to_be32(supp[1]);
2513 p = xdr_reserve_space(xdr, 16);
2516 *p++ = cpu_to_be32(3);
2517 *p++ = cpu_to_be32(supp[0]);
2518 *p++ = cpu_to_be32(supp[1]);
2519 *p++ = cpu_to_be32(supp[2]);
2522 if (bmval0 & FATTR4_WORD0_TYPE) {
2523 p = xdr_reserve_space(xdr, 4);
2526 dummy = nfs4_file_type(stat.mode);
2527 if (dummy == NF4BAD) {
2528 status = nfserr_serverfault;
2531 *p++ = cpu_to_be32(dummy);
2533 if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
2534 p = xdr_reserve_space(xdr, 4);
2537 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
2538 *p++ = cpu_to_be32(NFS4_FH_PERSISTENT);
2540 *p++ = cpu_to_be32(NFS4_FH_PERSISTENT|
2541 NFS4_FH_VOL_RENAME);
2543 if (bmval0 & FATTR4_WORD0_CHANGE) {
2544 p = xdr_reserve_space(xdr, 8);
2547 p = encode_change(p, &stat, d_inode(dentry), exp);
2549 if (bmval0 & FATTR4_WORD0_SIZE) {
2550 p = xdr_reserve_space(xdr, 8);
2553 p = xdr_encode_hyper(p, stat.size);
2555 if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
2556 p = xdr_reserve_space(xdr, 4);
2559 *p++ = cpu_to_be32(1);
2561 if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
2562 p = xdr_reserve_space(xdr, 4);
2565 *p++ = cpu_to_be32(1);
2567 if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
2568 p = xdr_reserve_space(xdr, 4);
2571 *p++ = cpu_to_be32(0);
2573 if (bmval0 & FATTR4_WORD0_FSID) {
2574 p = xdr_reserve_space(xdr, 16);
2577 if (exp->ex_fslocs.migrated) {
2578 p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR);
2579 p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR);
2580 } else switch(fsid_source(fhp)) {
2581 case FSIDSOURCE_FSID:
2582 p = xdr_encode_hyper(p, (u64)exp->ex_fsid);
2583 p = xdr_encode_hyper(p, (u64)0);
2585 case FSIDSOURCE_DEV:
2586 *p++ = cpu_to_be32(0);
2587 *p++ = cpu_to_be32(MAJOR(stat.dev));
2588 *p++ = cpu_to_be32(0);
2589 *p++ = cpu_to_be32(MINOR(stat.dev));
2591 case FSIDSOURCE_UUID:
2592 p = xdr_encode_opaque_fixed(p, exp->ex_uuid,
2597 if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
2598 p = xdr_reserve_space(xdr, 4);
2601 *p++ = cpu_to_be32(0);
2603 if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
2604 p = xdr_reserve_space(xdr, 4);
2607 *p++ = cpu_to_be32(nn->nfsd4_lease);
2609 if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
2610 p = xdr_reserve_space(xdr, 4);
2613 *p++ = cpu_to_be32(rdattr_err);
2615 if (bmval0 & FATTR4_WORD0_ACL) {
2616 struct nfs4_ace *ace;
2619 p = xdr_reserve_space(xdr, 4);
2623 *p++ = cpu_to_be32(0);
2626 p = xdr_reserve_space(xdr, 4);
2629 *p++ = cpu_to_be32(acl->naces);
2631 for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
2632 p = xdr_reserve_space(xdr, 4*3);
2635 *p++ = cpu_to_be32(ace->type);
2636 *p++ = cpu_to_be32(ace->flag);
2637 *p++ = cpu_to_be32(ace->access_mask &
2639 status = nfsd4_encode_aclname(xdr, rqstp, ace);
2645 if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
2646 p = xdr_reserve_space(xdr, 4);
2649 *p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ?
2650 ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
2652 if (bmval0 & FATTR4_WORD0_CANSETTIME) {
2653 p = xdr_reserve_space(xdr, 4);
2656 *p++ = cpu_to_be32(1);
2658 if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
2659 p = xdr_reserve_space(xdr, 4);
2662 *p++ = cpu_to_be32(0);
2664 if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
2665 p = xdr_reserve_space(xdr, 4);
2668 *p++ = cpu_to_be32(1);
2670 if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
2671 p = xdr_reserve_space(xdr, 4);
2674 *p++ = cpu_to_be32(1);
2676 if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
2677 p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4);
2680 p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base,
2681 fhp->fh_handle.fh_size);
2683 if (bmval0 & FATTR4_WORD0_FILEID) {
2684 p = xdr_reserve_space(xdr, 8);
2687 p = xdr_encode_hyper(p, stat.ino);
2689 if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
2690 p = xdr_reserve_space(xdr, 8);
2693 p = xdr_encode_hyper(p, (u64) statfs.f_ffree);
2695 if (bmval0 & FATTR4_WORD0_FILES_FREE) {
2696 p = xdr_reserve_space(xdr, 8);
2699 p = xdr_encode_hyper(p, (u64) statfs.f_ffree);
2701 if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
2702 p = xdr_reserve_space(xdr, 8);
2705 p = xdr_encode_hyper(p, (u64) statfs.f_files);
2707 if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
2708 status = nfsd4_encode_fs_locations(xdr, rqstp, exp);
2712 if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
2713 p = xdr_reserve_space(xdr, 4);
2716 *p++ = cpu_to_be32(1);
2718 if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
2719 p = xdr_reserve_space(xdr, 8);
2722 p = xdr_encode_hyper(p, exp->ex_path.mnt->mnt_sb->s_maxbytes);
2724 if (bmval0 & FATTR4_WORD0_MAXLINK) {
2725 p = xdr_reserve_space(xdr, 4);
2728 *p++ = cpu_to_be32(255);
2730 if (bmval0 & FATTR4_WORD0_MAXNAME) {
2731 p = xdr_reserve_space(xdr, 4);
2734 *p++ = cpu_to_be32(statfs.f_namelen);
2736 if (bmval0 & FATTR4_WORD0_MAXREAD) {
2737 p = xdr_reserve_space(xdr, 8);
2740 p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp));
2742 if (bmval0 & FATTR4_WORD0_MAXWRITE) {
2743 p = xdr_reserve_space(xdr, 8);
2746 p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp));
2748 if (bmval1 & FATTR4_WORD1_MODE) {
2749 p = xdr_reserve_space(xdr, 4);
2752 *p++ = cpu_to_be32(stat.mode & S_IALLUGO);
2754 if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
2755 p = xdr_reserve_space(xdr, 4);
2758 *p++ = cpu_to_be32(1);
2760 if (bmval1 & FATTR4_WORD1_NUMLINKS) {
2761 p = xdr_reserve_space(xdr, 4);
2764 *p++ = cpu_to_be32(stat.nlink);
2766 if (bmval1 & FATTR4_WORD1_OWNER) {
2767 status = nfsd4_encode_user(xdr, rqstp, stat.uid);
2771 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
2772 status = nfsd4_encode_group(xdr, rqstp, stat.gid);
2776 if (bmval1 & FATTR4_WORD1_RAWDEV) {
2777 p = xdr_reserve_space(xdr, 8);
2780 *p++ = cpu_to_be32((u32) MAJOR(stat.rdev));
2781 *p++ = cpu_to_be32((u32) MINOR(stat.rdev));
2783 if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
2784 p = xdr_reserve_space(xdr, 8);
2787 dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
2788 p = xdr_encode_hyper(p, dummy64);
2790 if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
2791 p = xdr_reserve_space(xdr, 8);
2794 dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
2795 p = xdr_encode_hyper(p, dummy64);
2797 if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
2798 p = xdr_reserve_space(xdr, 8);
2801 dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
2802 p = xdr_encode_hyper(p, dummy64);
2804 if (bmval1 & FATTR4_WORD1_SPACE_USED) {
2805 p = xdr_reserve_space(xdr, 8);
2808 dummy64 = (u64)stat.blocks << 9;
2809 p = xdr_encode_hyper(p, dummy64);
2811 if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
2812 p = xdr_reserve_space(xdr, 12);
2815 p = xdr_encode_hyper(p, (s64)stat.atime.tv_sec);
2816 *p++ = cpu_to_be32(stat.atime.tv_nsec);
2818 if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
2819 p = xdr_reserve_space(xdr, 12);
2822 p = encode_time_delta(p, d_inode(dentry));
2824 if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
2825 p = xdr_reserve_space(xdr, 12);
2828 p = xdr_encode_hyper(p, (s64)stat.ctime.tv_sec);
2829 *p++ = cpu_to_be32(stat.ctime.tv_nsec);
2831 if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
2832 p = xdr_reserve_space(xdr, 12);
2835 p = xdr_encode_hyper(p, (s64)stat.mtime.tv_sec);
2836 *p++ = cpu_to_be32(stat.mtime.tv_nsec);
2838 if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
2839 struct kstat parent_stat;
2842 p = xdr_reserve_space(xdr, 8);
2846 * Get parent's attributes if not ignoring crossmount
2847 * and this is the root of a cross-mounted filesystem.
2849 if (ignore_crossmnt == 0 &&
2850 dentry == exp->ex_path.mnt->mnt_root) {
2851 err = get_parent_attributes(exp, &parent_stat);
2854 ino = parent_stat.ino;
2856 p = xdr_encode_hyper(p, ino);
2858 #ifdef CONFIG_NFSD_PNFS
2859 if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) {
2860 status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types);
2865 if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) {
2866 status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types);
2871 if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) {
2872 p = xdr_reserve_space(xdr, 4);
2875 *p++ = cpu_to_be32(stat.blksize);
2877 #endif /* CONFIG_NFSD_PNFS */
2878 if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
2881 memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp));
2882 supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0;
2883 supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1;
2884 supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2;
2886 status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]);
2891 if (bmval2 & FATTR4_WORD2_CHANGE_ATTR_TYPE) {
2892 p = xdr_reserve_space(xdr, 4);
2895 if (IS_I_VERSION(d_inode(dentry)))
2896 *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR);
2898 *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA);
2901 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2902 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) {
2903 status = nfsd4_encode_security_label(xdr, rqstp, context,
2910 attrlen = htonl(xdr->buf->len - attrlen_offset - 4);
2911 write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4);
2915 #ifdef CONFIG_NFSD_V4_SECURITY_LABEL
2917 security_release_secctx(context, contextlen);
2918 #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */
2925 xdr_truncate_encode(xdr, starting_len);
2928 status = nfserrno(err);
2931 status = nfserr_resource;
2935 static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr,
2936 struct xdr_buf *buf, __be32 *p, int bytes)
2938 xdr->scratch.iov_len = 0;
2939 memset(buf, 0, sizeof(struct xdr_buf));
2940 buf->head[0].iov_base = p;
2941 buf->head[0].iov_len = 0;
2944 xdr->iov = buf->head;
2946 xdr->end = (void *)p + bytes;
2947 buf->buflen = bytes;
2950 __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words,
2951 struct svc_fh *fhp, struct svc_export *exp,
2952 struct dentry *dentry, u32 *bmval,
2953 struct svc_rqst *rqstp, int ignore_crossmnt)
2955 struct xdr_buf dummy;
2956 struct xdr_stream xdr;
2959 svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2);
2960 ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp,
2966 static inline int attributes_need_mount(u32 *bmval)
2968 if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
2970 if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
2976 nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd,
2977 const char *name, int namlen)
2979 struct svc_export *exp = cd->rd_fhp->fh_export;
2980 struct dentry *dentry;
2982 int ignore_crossmnt = 0;
2984 dentry = lookup_one_len_unlocked(name, cd->rd_fhp->fh_dentry, namlen);
2986 return nfserrno(PTR_ERR(dentry));
2987 if (d_really_is_negative(dentry)) {
2989 * we're not holding the i_mutex here, so there's
2990 * a window where this directory entry could have gone
2994 return nfserr_noent;
2999 * In the case of a mountpoint, the client may be asking for
3000 * attributes that are only properties of the underlying filesystem
3001 * as opposed to the cross-mounted file system. In such a case,
3002 * we will not follow the cross mount and will fill the attribtutes
3003 * directly from the mountpoint dentry.
3005 if (nfsd_mountpoint(dentry, exp)) {
3008 if (!(exp->ex_flags & NFSEXP_V4ROOT)
3009 && !attributes_need_mount(cd->rd_bmval)) {
3010 ignore_crossmnt = 1;
3014 * Why the heck aren't we just using nfsd_lookup??
3015 * Different "."/".." handling? Something else?
3016 * At least, add a comment here to explain....
3018 err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
3020 nfserr = nfserrno(err);
3023 nfserr = check_nfsd_access(exp, cd->rd_rqstp);
3029 nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval,
3030 cd->rd_rqstp, ignore_crossmnt);
3038 nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr)
3042 p = xdr_reserve_space(xdr, 20);
3046 *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */
3047 *p++ = htonl(0); /* bmval1 */
3049 *p++ = htonl(4); /* attribute length */
3050 *p++ = nfserr; /* no htonl */
3055 nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
3056 loff_t offset, u64 ino, unsigned int d_type)
3058 struct readdir_cd *ccd = ccdv;
3059 struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
3060 struct xdr_stream *xdr = cd->xdr;
3061 int start_offset = xdr->buf->len;
3063 u32 name_and_cookie;
3065 __be32 nfserr = nfserr_toosmall;
3069 /* In nfsv4, "." and ".." never make it onto the wire.. */
3070 if (name && isdotent(name, namlen)) {
3071 cd->common.err = nfs_ok;
3075 if (cd->cookie_offset) {
3076 wire_offset = cpu_to_be64(offset);
3077 write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset,
3081 p = xdr_reserve_space(xdr, 4);
3084 *p++ = xdr_one; /* mark entry present */
3085 cookie_offset = xdr->buf->len;
3086 p = xdr_reserve_space(xdr, 3*4 + namlen);
3089 p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */
3090 p = xdr_encode_array(p, name, namlen); /* name length & name */
3092 nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen);
3096 case nfserr_resource:
3097 nfserr = nfserr_toosmall;
3100 xdr_truncate_encode(xdr, start_offset);
3104 * If the client requested the RDATTR_ERROR attribute,
3105 * we stuff the error code into this attribute
3106 * and continue. If this attribute was not requested,
3107 * then in accordance with the spec, we fail the
3108 * entire READDIR operation(!)
3110 if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
3112 p = nfsd4_encode_rdattr_error(xdr, nfserr);
3114 nfserr = nfserr_toosmall;
3118 nfserr = nfserr_toosmall;
3119 entry_bytes = xdr->buf->len - start_offset;
3120 if (entry_bytes > cd->rd_maxcount)
3122 cd->rd_maxcount -= entry_bytes;
3124 * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so
3125 * let's always let through the first entry, at least:
3127 if (!cd->rd_dircount)
3129 name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8;
3130 if (name_and_cookie > cd->rd_dircount && cd->cookie_offset)
3132 cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie);
3134 cd->cookie_offset = cookie_offset;
3136 cd->common.err = nfs_ok;
3139 xdr_truncate_encode(xdr, start_offset);
3140 cd->common.err = nfserr;
3145 nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid)
3149 p = xdr_reserve_space(xdr, sizeof(stateid_t));
3151 return nfserr_resource;
3152 *p++ = cpu_to_be32(sid->si_generation);
3153 p = xdr_encode_opaque_fixed(p, &sid->si_opaque,
3154 sizeof(stateid_opaque_t));
3159 nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
3161 struct xdr_stream *xdr = &resp->xdr;
3164 p = xdr_reserve_space(xdr, 8);
3166 return nfserr_resource;
3167 *p++ = cpu_to_be32(access->ac_supported);
3168 *p++ = cpu_to_be32(access->ac_resp_access);
3172 static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts)
3174 struct xdr_stream *xdr = &resp->xdr;
3177 p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 8);
3179 return nfserr_resource;
3180 p = xdr_encode_opaque_fixed(p, bcts->sessionid.data,
3181 NFS4_MAX_SESSIONID_LEN);
3182 *p++ = cpu_to_be32(bcts->dir);
3183 /* Upshifting from TCP to RDMA is not supported */
3184 *p++ = cpu_to_be32(0);
3189 nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close)
3191 struct xdr_stream *xdr = &resp->xdr;
3193 return nfsd4_encode_stateid(xdr, &close->cl_stateid);
3198 nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit)
3200 struct xdr_stream *xdr = &resp->xdr;
3203 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
3205 return nfserr_resource;
3206 p = xdr_encode_opaque_fixed(p, commit->co_verf.data,
3207 NFS4_VERIFIER_SIZE);
3212 nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create)
3214 struct xdr_stream *xdr = &resp->xdr;
3217 p = xdr_reserve_space(xdr, 20);
3219 return nfserr_resource;
3220 encode_cinfo(p, &create->cr_cinfo);
3221 nfserr = nfsd4_encode_bitmap(xdr, create->cr_bmval[0],
3222 create->cr_bmval[1], create->cr_bmval[2]);
3227 nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr)
3229 struct svc_fh *fhp = getattr->ga_fhp;
3230 struct xdr_stream *xdr = &resp->xdr;
3232 return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry,
3233 getattr->ga_bmval, resp->rqstp, 0);
3237 nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp)
3239 struct xdr_stream *xdr = &resp->xdr;
3240 struct svc_fh *fhp = *fhpp;
3244 len = fhp->fh_handle.fh_size;
3245 p = xdr_reserve_space(xdr, len + 4);
3247 return nfserr_resource;
3248 p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len);
3253 * Including all fields other than the name, a LOCK4denied structure requires
3254 * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
3257 nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld)
3259 struct xdr_netobj *conf = &ld->ld_owner;
3263 p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len));
3266 * Don't fail to return the result just because we can't
3267 * return the conflicting open:
3275 return nfserr_resource;
3277 p = xdr_encode_hyper(p, ld->ld_start);
3278 p = xdr_encode_hyper(p, ld->ld_length);
3279 *p++ = cpu_to_be32(ld->ld_type);
3281 p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8);
3282 p = xdr_encode_opaque(p, conf->data, conf->len);
3284 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
3285 p = xdr_encode_hyper(p, (u64)0); /* clientid */
3286 *p++ = cpu_to_be32(0); /* length of owner name */
3288 return nfserr_denied;
3292 nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock)
3294 struct xdr_stream *xdr = &resp->xdr;
3297 nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid);
3298 else if (nfserr == nfserr_denied)
3299 nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied);
3305 nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt)
3307 struct xdr_stream *xdr = &resp->xdr;
3309 if (nfserr == nfserr_denied)
3310 nfsd4_encode_lock_denied(xdr, &lockt->lt_denied);
3315 nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku)
3317 struct xdr_stream *xdr = &resp->xdr;
3319 return nfsd4_encode_stateid(xdr, &locku->lu_stateid);
3324 nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link)
3326 struct xdr_stream *xdr = &resp->xdr;
3329 p = xdr_reserve_space(xdr, 20);
3331 return nfserr_resource;
3332 p = encode_cinfo(p, &link->li_cinfo);
3338 nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
3340 struct xdr_stream *xdr = &resp->xdr;
3343 nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid);
3346 p = xdr_reserve_space(xdr, 24);
3348 return nfserr_resource;
3349 p = encode_cinfo(p, &open->op_cinfo);
3350 *p++ = cpu_to_be32(open->op_rflags);
3352 nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1],
3357 p = xdr_reserve_space(xdr, 4);
3359 return nfserr_resource;
3361 *p++ = cpu_to_be32(open->op_delegate_type);
3362 switch (open->op_delegate_type) {
3363 case NFS4_OPEN_DELEGATE_NONE:
3365 case NFS4_OPEN_DELEGATE_READ:
3366 nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid);
3369 p = xdr_reserve_space(xdr, 20);
3371 return nfserr_resource;
3372 *p++ = cpu_to_be32(open->op_recall);
3375 * TODO: ACE's in delegations
3377 *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
3378 *p++ = cpu_to_be32(0);
3379 *p++ = cpu_to_be32(0);
3380 *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */
3382 case NFS4_OPEN_DELEGATE_WRITE:
3383 nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid);
3386 p = xdr_reserve_space(xdr, 32);
3388 return nfserr_resource;
3389 *p++ = cpu_to_be32(0);
3392 * TODO: space_limit's in delegations
3394 *p++ = cpu_to_be32(NFS4_LIMIT_SIZE);
3395 *p++ = cpu_to_be32(~(u32)0);
3396 *p++ = cpu_to_be32(~(u32)0);
3399 * TODO: ACE's in delegations
3401 *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
3402 *p++ = cpu_to_be32(0);
3403 *p++ = cpu_to_be32(0);
3404 *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */
3406 case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */
3407 switch (open->op_why_no_deleg) {
3408 case WND4_CONTENTION:
3410 p = xdr_reserve_space(xdr, 8);
3412 return nfserr_resource;
3413 *p++ = cpu_to_be32(open->op_why_no_deleg);
3414 /* deleg signaling not supported yet: */
3415 *p++ = cpu_to_be32(0);
3418 p = xdr_reserve_space(xdr, 4);
3420 return nfserr_resource;
3421 *p++ = cpu_to_be32(open->op_why_no_deleg);
3427 /* XXX save filehandle here */
3432 nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
3434 struct xdr_stream *xdr = &resp->xdr;
3436 return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid);
3440 nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
3442 struct xdr_stream *xdr = &resp->xdr;
3444 return nfsd4_encode_stateid(xdr, &od->od_stateid);
3447 static __be32 nfsd4_encode_splice_read(
3448 struct nfsd4_compoundres *resp,
3449 struct nfsd4_read *read,
3450 struct file *file, unsigned long maxcount)
3452 struct xdr_stream *xdr = &resp->xdr;
3453 struct xdr_buf *buf = xdr->buf;
3458 __be32 *p = xdr->p - 2;
3460 /* Make sure there will be room for padding if needed */
3461 if (xdr->end - xdr->p < 1)
3462 return nfserr_resource;
3465 nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp,
3466 file, read->rd_offset, &maxcount);
3467 read->rd_length = maxcount;
3470 * nfsd_splice_actor may have already messed with the
3471 * page length; reset it so as not to confuse
3472 * xdr_truncate_encode:
3478 eof = nfsd_eof_on_read(len, maxcount, read->rd_offset,
3479 d_inode(read->rd_fhp->fh_dentry)->i_size);
3481 *(p++) = htonl(eof);
3482 *(p++) = htonl(maxcount);
3484 buf->page_len = maxcount;
3485 buf->len += maxcount;
3486 xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1)
3489 /* Use rest of head for padding and remaining ops: */
3490 buf->tail[0].iov_base = xdr->p;
3491 buf->tail[0].iov_len = 0;
3492 xdr->iov = buf->tail;
3494 int pad = 4 - (maxcount&3);
3498 buf->tail[0].iov_base += maxcount&3;
3499 buf->tail[0].iov_len = pad;
3503 space_left = min_t(int, (void *)xdr->end - (void *)xdr->p,
3504 buf->buflen - buf->len);
3505 buf->buflen = buf->len + space_left;
3506 xdr->end = (__be32 *)((void *)xdr->end + space_left);
3511 static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp,
3512 struct nfsd4_read *read,
3513 struct file *file, unsigned long maxcount)
3515 struct xdr_stream *xdr = &resp->xdr;
3518 int starting_len = xdr->buf->len - 8;
3530 thislen = min_t(long, len, ((void *)xdr->end - (void *)xdr->p));
3531 p = xdr_reserve_space(xdr, (thislen+3)&~3);
3533 resp->rqstp->rq_vec[v].iov_base = p;
3534 resp->rqstp->rq_vec[v].iov_len = thislen;
3539 thislen = min_t(long, len, PAGE_SIZE);
3540 p = xdr_reserve_space(xdr, (thislen+3)&~3);
3542 resp->rqstp->rq_vec[v].iov_base = p;
3543 resp->rqstp->rq_vec[v].iov_len = thislen;
3550 nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset,
3551 resp->rqstp->rq_vec, read->rd_vlen, &maxcount);
3552 read->rd_length = maxcount;
3555 xdr_truncate_encode(xdr, starting_len + 8 + ((maxcount+3)&~3));
3557 eof = nfsd_eof_on_read(len, maxcount, read->rd_offset,
3558 d_inode(read->rd_fhp->fh_dentry)->i_size);
3561 write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4);
3562 tmp = htonl(maxcount);
3563 write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4);
3565 pad = (maxcount&3) ? 4 - (maxcount&3) : 0;
3566 write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount,
3573 nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
3574 struct nfsd4_read *read)
3576 unsigned long maxcount;
3577 struct xdr_stream *xdr = &resp->xdr;
3579 int starting_len = xdr->buf->len;
3584 file = read->rd_nf->nf_file;
3586 p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */
3588 WARN_ON_ONCE(test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags));
3589 return nfserr_resource;
3591 if (resp->xdr.buf->page_len &&
3592 test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) {
3594 return nfserr_resource;
3596 xdr_commit_encode(xdr);
3598 maxcount = svc_max_payload(resp->rqstp);
3599 maxcount = min_t(unsigned long, maxcount,
3600 (xdr->buf->buflen - xdr->buf->len));
3601 maxcount = min_t(unsigned long, maxcount, read->rd_length);
3603 if (file->f_op->splice_read &&
3604 test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags))
3605 nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount);
3607 nfserr = nfsd4_encode_readv(resp, read, file, maxcount);
3610 xdr_truncate_encode(xdr, starting_len);
3616 nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink)
3621 struct xdr_stream *xdr = &resp->xdr;
3622 int length_offset = xdr->buf->len;
3625 p = xdr_reserve_space(xdr, 4);
3627 return nfserr_resource;
3628 maxcount = PAGE_SIZE;
3630 p = xdr_reserve_space(xdr, maxcount);
3632 return nfserr_resource;
3634 * XXX: By default, vfs_readlink() will truncate symlinks if they
3635 * would overflow the buffer. Is this kosher in NFSv4? If not, one
3636 * easy fix is: if vfs_readlink() precisely fills the buffer, assume
3637 * that truncation occurred, and return NFS4ERR_RESOURCE.
3639 nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp,
3640 (char *)p, &maxcount);
3641 if (nfserr == nfserr_isdir)
3642 nfserr = nfserr_inval;
3644 xdr_truncate_encode(xdr, length_offset);
3648 wire_count = htonl(maxcount);
3649 write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4);
3650 xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4));
3652 write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount,
3653 &zero, 4 - (maxcount&3));
3658 nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir)
3664 struct xdr_stream *xdr = &resp->xdr;
3665 int starting_len = xdr->buf->len;
3668 p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE);
3670 return nfserr_resource;
3672 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
3673 *p++ = cpu_to_be32(0);
3674 *p++ = cpu_to_be32(0);
3675 resp->xdr.buf->head[0].iov_len = ((char *)resp->xdr.p)
3676 - (char *)resp->xdr.buf->head[0].iov_base;
3679 * Number of bytes left for directory entries allowing for the
3680 * final 8 bytes of the readdir and a following failed op:
3682 bytes_left = xdr->buf->buflen - xdr->buf->len
3683 - COMPOUND_ERR_SLACK_SPACE - 8;
3684 if (bytes_left < 0) {
3685 nfserr = nfserr_resource;
3688 maxcount = svc_max_payload(resp->rqstp);
3689 maxcount = min_t(u32, readdir->rd_maxcount, maxcount);
3691 * Note the rfc defines rd_maxcount as the size of the
3692 * READDIR4resok structure, which includes the verifier above
3693 * and the 8 bytes encoded at the end of this function:
3695 if (maxcount < 16) {
3696 nfserr = nfserr_toosmall;
3699 maxcount = min_t(int, maxcount-16, bytes_left);
3701 /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */
3702 if (!readdir->rd_dircount)
3703 readdir->rd_dircount = svc_max_payload(resp->rqstp);
3706 readdir->rd_maxcount = maxcount;
3707 readdir->common.err = 0;
3708 readdir->cookie_offset = 0;
3710 offset = readdir->rd_cookie;
3711 nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp,
3713 &readdir->common, nfsd4_encode_dirent);
3714 if (nfserr == nfs_ok &&
3715 readdir->common.err == nfserr_toosmall &&
3716 xdr->buf->len == starting_len + 8) {
3717 /* nothing encoded; which limit did we hit?: */
3718 if (maxcount - 16 < bytes_left)
3719 /* It was the fault of rd_maxcount: */
3720 nfserr = nfserr_toosmall;
3722 /* We ran out of buffer space: */
3723 nfserr = nfserr_resource;
3728 if (readdir->cookie_offset) {
3729 wire_offset = cpu_to_be64(offset);
3730 write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset,
3734 p = xdr_reserve_space(xdr, 8);
3739 *p++ = 0; /* no more entries */
3740 *p++ = htonl(readdir->common.err == nfserr_eof);
3744 xdr_truncate_encode(xdr, starting_len);
3749 nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove)
3751 struct xdr_stream *xdr = &resp->xdr;
3754 p = xdr_reserve_space(xdr, 20);
3756 return nfserr_resource;
3757 p = encode_cinfo(p, &remove->rm_cinfo);
3762 nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename)
3764 struct xdr_stream *xdr = &resp->xdr;
3767 p = xdr_reserve_space(xdr, 40);
3769 return nfserr_resource;
3770 p = encode_cinfo(p, &rename->rn_sinfo);
3771 p = encode_cinfo(p, &rename->rn_tinfo);
3776 nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp)
3778 u32 i, nflavs, supported;
3779 struct exp_flavor_info *flavs;
3780 struct exp_flavor_info def_flavs[2];
3781 __be32 *p, *flavorsp;
3782 static bool report = true;
3784 if (exp->ex_nflavors) {
3785 flavs = exp->ex_flavors;
3786 nflavs = exp->ex_nflavors;
3787 } else { /* Handling of some defaults in absence of real secinfo: */
3789 if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
3791 flavs[0].pseudoflavor = RPC_AUTH_UNIX;
3792 flavs[1].pseudoflavor = RPC_AUTH_NULL;
3793 } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
3795 flavs[0].pseudoflavor
3796 = svcauth_gss_flavor(exp->ex_client);
3799 flavs[0].pseudoflavor
3800 = exp->ex_client->flavour->flavour;
3805 p = xdr_reserve_space(xdr, 4);
3807 return nfserr_resource;
3808 flavorsp = p++; /* to be backfilled later */
3810 for (i = 0; i < nflavs; i++) {
3811 rpc_authflavor_t pf = flavs[i].pseudoflavor;
3812 struct rpcsec_gss_info info;
3814 if (rpcauth_get_gssinfo(pf, &info) == 0) {
3816 p = xdr_reserve_space(xdr, 4 + 4 +
3817 XDR_LEN(info.oid.len) + 4 + 4);
3819 return nfserr_resource;
3820 *p++ = cpu_to_be32(RPC_AUTH_GSS);
3821 p = xdr_encode_opaque(p, info.oid.data, info.oid.len);
3822 *p++ = cpu_to_be32(info.qop);
3823 *p++ = cpu_to_be32(info.service);
3824 } else if (pf < RPC_AUTH_MAXFLAVOR) {
3826 p = xdr_reserve_space(xdr, 4);
3828 return nfserr_resource;
3829 *p++ = cpu_to_be32(pf);
3832 pr_warn("NFS: SECINFO: security flavor %u "
3833 "is not supported\n", pf);
3837 if (nflavs != supported)
3839 *flavorsp = htonl(supported);
3844 nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
3845 struct nfsd4_secinfo *secinfo)
3847 struct xdr_stream *xdr = &resp->xdr;
3849 return nfsd4_do_encode_secinfo(xdr, secinfo->si_exp);
3853 nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr,
3854 struct nfsd4_secinfo_no_name *secinfo)
3856 struct xdr_stream *xdr = &resp->xdr;
3858 return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp);
3862 * The SETATTR encode routine is special -- it always encodes a bitmap,
3863 * regardless of the error status.
3866 nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr)
3868 struct xdr_stream *xdr = &resp->xdr;
3871 p = xdr_reserve_space(xdr, 16);
3873 return nfserr_resource;
3875 *p++ = cpu_to_be32(3);
3876 *p++ = cpu_to_be32(0);
3877 *p++ = cpu_to_be32(0);
3878 *p++ = cpu_to_be32(0);
3881 *p++ = cpu_to_be32(3);
3882 *p++ = cpu_to_be32(setattr->sa_bmval[0]);
3883 *p++ = cpu_to_be32(setattr->sa_bmval[1]);
3884 *p++ = cpu_to_be32(setattr->sa_bmval[2]);
3890 nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd)
3892 struct xdr_stream *xdr = &resp->xdr;
3896 p = xdr_reserve_space(xdr, 8 + NFS4_VERIFIER_SIZE);
3898 return nfserr_resource;
3899 p = xdr_encode_opaque_fixed(p, &scd->se_clientid, 8);
3900 p = xdr_encode_opaque_fixed(p, &scd->se_confirm,
3901 NFS4_VERIFIER_SIZE);
3903 else if (nfserr == nfserr_clid_inuse) {
3904 p = xdr_reserve_space(xdr, 8);
3906 return nfserr_resource;
3907 *p++ = cpu_to_be32(0);
3908 *p++ = cpu_to_be32(0);
3914 nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write)
3916 struct xdr_stream *xdr = &resp->xdr;
3919 p = xdr_reserve_space(xdr, 16);
3921 return nfserr_resource;
3922 *p++ = cpu_to_be32(write->wr_bytes_written);
3923 *p++ = cpu_to_be32(write->wr_how_written);
3924 p = xdr_encode_opaque_fixed(p, write->wr_verifier.data,
3925 NFS4_VERIFIER_SIZE);
3930 nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
3931 struct nfsd4_exchange_id *exid)
3933 struct xdr_stream *xdr = &resp->xdr;
3938 int server_scope_sz;
3939 uint64_t minor_id = 0;
3941 major_id = utsname()->nodename;
3942 major_id_sz = strlen(major_id);
3943 server_scope = utsname()->nodename;
3944 server_scope_sz = strlen(server_scope);
3946 p = xdr_reserve_space(xdr,
3947 8 /* eir_clientid */ +
3948 4 /* eir_sequenceid */ +
3952 return nfserr_resource;
3954 p = xdr_encode_opaque_fixed(p, &exid->clientid, 8);
3955 *p++ = cpu_to_be32(exid->seqid);
3956 *p++ = cpu_to_be32(exid->flags);
3958 *p++ = cpu_to_be32(exid->spa_how);
3960 switch (exid->spa_how) {
3964 /* spo_must_enforce bitmap: */
3965 nfserr = nfsd4_encode_bitmap(xdr,
3966 exid->spo_must_enforce[0],
3967 exid->spo_must_enforce[1],
3968 exid->spo_must_enforce[2]);
3971 /* spo_must_allow bitmap: */
3972 nfserr = nfsd4_encode_bitmap(xdr,
3973 exid->spo_must_allow[0],
3974 exid->spo_must_allow[1],
3975 exid->spo_must_allow[2]);
3983 p = xdr_reserve_space(xdr,
3984 8 /* so_minor_id */ +
3985 4 /* so_major_id.len */ +
3986 (XDR_QUADLEN(major_id_sz) * 4) +
3987 4 /* eir_server_scope.len */ +
3988 (XDR_QUADLEN(server_scope_sz) * 4) +
3989 4 /* eir_server_impl_id.count (0) */);
3991 return nfserr_resource;
3993 /* The server_owner struct */
3994 p = xdr_encode_hyper(p, minor_id); /* Minor id */
3996 p = xdr_encode_opaque(p, major_id, major_id_sz);
3999 p = xdr_encode_opaque(p, server_scope, server_scope_sz);
4001 /* Implementation id */
4002 *p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */
4007 nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,
4008 struct nfsd4_create_session *sess)
4010 struct xdr_stream *xdr = &resp->xdr;
4013 p = xdr_reserve_space(xdr, 24);
4015 return nfserr_resource;
4016 p = xdr_encode_opaque_fixed(p, sess->sessionid.data,
4017 NFS4_MAX_SESSIONID_LEN);
4018 *p++ = cpu_to_be32(sess->seqid);
4019 *p++ = cpu_to_be32(sess->flags);
4021 p = xdr_reserve_space(xdr, 28);
4023 return nfserr_resource;
4024 *p++ = cpu_to_be32(0); /* headerpadsz */
4025 *p++ = cpu_to_be32(sess->fore_channel.maxreq_sz);
4026 *p++ = cpu_to_be32(sess->fore_channel.maxresp_sz);
4027 *p++ = cpu_to_be32(sess->fore_channel.maxresp_cached);
4028 *p++ = cpu_to_be32(sess->fore_channel.maxops);
4029 *p++ = cpu_to_be32(sess->fore_channel.maxreqs);
4030 *p++ = cpu_to_be32(sess->fore_channel.nr_rdma_attrs);
4032 if (sess->fore_channel.nr_rdma_attrs) {
4033 p = xdr_reserve_space(xdr, 4);
4035 return nfserr_resource;
4036 *p++ = cpu_to_be32(sess->fore_channel.rdma_attrs);
4039 p = xdr_reserve_space(xdr, 28);
4041 return nfserr_resource;
4042 *p++ = cpu_to_be32(0); /* headerpadsz */
4043 *p++ = cpu_to_be32(sess->back_channel.maxreq_sz);
4044 *p++ = cpu_to_be32(sess->back_channel.maxresp_sz);
4045 *p++ = cpu_to_be32(sess->back_channel.maxresp_cached);
4046 *p++ = cpu_to_be32(sess->back_channel.maxops);
4047 *p++ = cpu_to_be32(sess->back_channel.maxreqs);
4048 *p++ = cpu_to_be32(sess->back_channel.nr_rdma_attrs);
4050 if (sess->back_channel.nr_rdma_attrs) {
4051 p = xdr_reserve_space(xdr, 4);
4053 return nfserr_resource;
4054 *p++ = cpu_to_be32(sess->back_channel.rdma_attrs);
4060 nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
4061 struct nfsd4_sequence *seq)
4063 struct xdr_stream *xdr = &resp->xdr;
4066 p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20);
4068 return nfserr_resource;
4069 p = xdr_encode_opaque_fixed(p, seq->sessionid.data,
4070 NFS4_MAX_SESSIONID_LEN);
4071 *p++ = cpu_to_be32(seq->seqid);
4072 *p++ = cpu_to_be32(seq->slotid);
4073 /* Note slotid's are numbered from zero: */
4074 *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */
4075 *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */
4076 *p++ = cpu_to_be32(seq->status_flags);
4078 resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */
4083 nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
4084 struct nfsd4_test_stateid *test_stateid)
4086 struct xdr_stream *xdr = &resp->xdr;
4087 struct nfsd4_test_stateid_id *stateid, *next;
4090 p = xdr_reserve_space(xdr, 4 + (4 * test_stateid->ts_num_ids));
4092 return nfserr_resource;
4093 *p++ = htonl(test_stateid->ts_num_ids);
4095 list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
4096 *p++ = stateid->ts_id_status;
4102 #ifdef CONFIG_NFSD_PNFS
4104 nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
4105 struct nfsd4_getdeviceinfo *gdev)
4107 struct xdr_stream *xdr = &resp->xdr;
4108 const struct nfsd4_layout_ops *ops;
4109 u32 starting_len = xdr->buf->len, needed_len;
4112 p = xdr_reserve_space(xdr, 4);
4114 return nfserr_resource;
4116 *p++ = cpu_to_be32(gdev->gd_layout_type);
4118 /* If maxcount is 0 then just update notifications */
4119 if (gdev->gd_maxcount != 0) {
4120 ops = nfsd4_layout_ops[gdev->gd_layout_type];
4121 nfserr = ops->encode_getdeviceinfo(xdr, gdev);
4124 * We don't bother to burden the layout drivers with
4125 * enforcing gd_maxcount, just tell the client to
4126 * come back with a bigger buffer if it's not enough.
4128 if (xdr->buf->len + 4 > gdev->gd_maxcount)
4134 if (gdev->gd_notify_types) {
4135 p = xdr_reserve_space(xdr, 4 + 4);
4137 return nfserr_resource;
4138 *p++ = cpu_to_be32(1); /* bitmap length */
4139 *p++ = cpu_to_be32(gdev->gd_notify_types);
4141 p = xdr_reserve_space(xdr, 4);
4143 return nfserr_resource;
4149 dprintk("%s: maxcount too small\n", __func__);
4150 needed_len = xdr->buf->len + 4 /* notifications */;
4151 xdr_truncate_encode(xdr, starting_len);
4152 p = xdr_reserve_space(xdr, 4);
4154 return nfserr_resource;
4155 *p++ = cpu_to_be32(needed_len);
4156 return nfserr_toosmall;
4160 nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr,
4161 struct nfsd4_layoutget *lgp)
4163 struct xdr_stream *xdr = &resp->xdr;
4164 const struct nfsd4_layout_ops *ops;
4167 p = xdr_reserve_space(xdr, 36 + sizeof(stateid_opaque_t));
4169 return nfserr_resource;
4171 *p++ = cpu_to_be32(1); /* we always set return-on-close */
4172 *p++ = cpu_to_be32(lgp->lg_sid.si_generation);
4173 p = xdr_encode_opaque_fixed(p, &lgp->lg_sid.si_opaque,
4174 sizeof(stateid_opaque_t));
4176 *p++ = cpu_to_be32(1); /* we always return a single layout */
4177 p = xdr_encode_hyper(p, lgp->lg_seg.offset);
4178 p = xdr_encode_hyper(p, lgp->lg_seg.length);
4179 *p++ = cpu_to_be32(lgp->lg_seg.iomode);
4180 *p++ = cpu_to_be32(lgp->lg_layout_type);
4182 ops = nfsd4_layout_ops[lgp->lg_layout_type];
4183 return ops->encode_layoutget(xdr, lgp);
4187 nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr,
4188 struct nfsd4_layoutcommit *lcp)
4190 struct xdr_stream *xdr = &resp->xdr;
4193 p = xdr_reserve_space(xdr, 4);
4195 return nfserr_resource;
4196 *p++ = cpu_to_be32(lcp->lc_size_chg);
4197 if (lcp->lc_size_chg) {
4198 p = xdr_reserve_space(xdr, 8);
4200 return nfserr_resource;
4201 p = xdr_encode_hyper(p, lcp->lc_newsize);
4208 nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr,
4209 struct nfsd4_layoutreturn *lrp)
4211 struct xdr_stream *xdr = &resp->xdr;
4214 p = xdr_reserve_space(xdr, 4);
4216 return nfserr_resource;
4217 *p++ = cpu_to_be32(lrp->lrs_present);
4218 if (lrp->lrs_present)
4219 return nfsd4_encode_stateid(xdr, &lrp->lr_sid);
4222 #endif /* CONFIG_NFSD_PNFS */
4225 nfsd42_encode_write_res(struct nfsd4_compoundres *resp,
4226 struct nfsd42_write_res *write, bool sync)
4229 p = xdr_reserve_space(&resp->xdr, 4);
4231 return nfserr_resource;
4234 *p++ = cpu_to_be32(0);
4237 *p++ = cpu_to_be32(1);
4238 nfserr = nfsd4_encode_stateid(&resp->xdr, &write->cb_stateid);
4242 p = xdr_reserve_space(&resp->xdr, 8 + 4 + NFS4_VERIFIER_SIZE);
4244 return nfserr_resource;
4246 p = xdr_encode_hyper(p, write->wr_bytes_written);
4247 *p++ = cpu_to_be32(write->wr_stable_how);
4248 p = xdr_encode_opaque_fixed(p, write->wr_verifier.data,
4249 NFS4_VERIFIER_SIZE);
4254 nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr,
4255 struct nfsd4_copy *copy)
4259 nfserr = nfsd42_encode_write_res(resp, ©->cp_res,
4260 copy->cp_synchronous);
4264 p = xdr_reserve_space(&resp->xdr, 4 + 4);
4265 *p++ = xdr_one; /* cr_consecutive */
4266 *p++ = cpu_to_be32(copy->cp_synchronous);
4271 nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr,
4272 struct nfsd4_offload_status *os)
4274 struct xdr_stream *xdr = &resp->xdr;
4277 p = xdr_reserve_space(xdr, 8 + 4);
4279 return nfserr_resource;
4280 p = xdr_encode_hyper(p, os->count);
4281 *p++ = cpu_to_be32(0);
4287 nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr,
4288 struct nfsd4_seek *seek)
4292 p = xdr_reserve_space(&resp->xdr, 4 + 8);
4293 *p++ = cpu_to_be32(seek->seek_eof);
4294 p = xdr_encode_hyper(p, seek->seek_pos);
4300 nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p)
4305 typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *);
4308 * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
4309 * since we don't need to filter out obsolete ops as this is
4310 * done in the decoding phase.
4312 static const nfsd4_enc nfsd4_enc_ops[] = {
4313 [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access,
4314 [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close,
4315 [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit,
4316 [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create,
4317 [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop,
4318 [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop,
4319 [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr,
4320 [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh,
4321 [OP_LINK] = (nfsd4_enc)nfsd4_encode_link,
4322 [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock,
4323 [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt,
4324 [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku,
4325 [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop,
4326 [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop,
4327 [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop,
4328 [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open,
4329 [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop,
4330 [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm,
4331 [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade,
4332 [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop,
4333 [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop,
4334 [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop,
4335 [OP_READ] = (nfsd4_enc)nfsd4_encode_read,
4336 [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir,
4337 [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink,
4338 [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove,
4339 [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename,
4340 [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop,
4341 [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop,
4342 [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop,
4343 [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo,
4344 [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr,
4345 [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid,
4346 [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop,
4347 [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop,
4348 [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write,
4349 [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop,
4351 /* NFSv4.1 operations */
4352 [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop,
4353 [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session,
4354 [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id,
4355 [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session,
4356 [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_noop,
4357 [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop,
4358 [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
4359 #ifdef CONFIG_NFSD_PNFS
4360 [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_getdeviceinfo,
4361 [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
4362 [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_layoutcommit,
4363 [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_layoutget,
4364 [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_layoutreturn,
4366 [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop,
4367 [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
4368 [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop,
4369 [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop,
4370 [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop,
4372 [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name,
4373 [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence,
4374 [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop,
4375 [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid,
4376 [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
4377 [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop,
4378 [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop,
4380 /* NFSv4.2 operations */
4381 [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop,
4382 [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy,
4383 [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_noop,
4384 [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop,
4385 [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop,
4386 [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop,
4387 [OP_LAYOUTSTATS] = (nfsd4_enc)nfsd4_encode_noop,
4388 [OP_OFFLOAD_CANCEL] = (nfsd4_enc)nfsd4_encode_noop,
4389 [OP_OFFLOAD_STATUS] = (nfsd4_enc)nfsd4_encode_offload_status,
4390 [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_noop,
4391 [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek,
4392 [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop,
4393 [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop,
4397 * Calculate whether we still have space to encode repsize bytes.
4398 * There are two considerations:
4399 * - For NFS versions >=4.1, the size of the reply must stay within
4401 * - For all NFS versions, we must stay within limited preallocated
4404 * This is called before the operation is processed, so can only provide
4405 * an upper estimate. For some nonidempotent operations (such as
4406 * getattr), it's not necessarily a problem if that estimate is wrong,
4407 * as we can fail it after processing without significant side effects.
4409 __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize)
4411 struct xdr_buf *buf = &resp->rqstp->rq_res;
4412 struct nfsd4_slot *slot = resp->cstate.slot;
4414 if (buf->len + respsize <= buf->buflen)
4416 if (!nfsd4_has_session(&resp->cstate))
4417 return nfserr_resource;
4418 if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) {
4420 return nfserr_rep_too_big_to_cache;
4422 return nfserr_rep_too_big;
4426 nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
4428 struct xdr_stream *xdr = &resp->xdr;
4429 struct nfs4_stateowner *so = resp->cstate.replay_owner;
4430 struct svc_rqst *rqstp = resp->rqstp;
4431 const struct nfsd4_operation *opdesc = op->opdesc;
4432 int post_err_offset;
4436 p = xdr_reserve_space(xdr, 8);
4441 *p++ = cpu_to_be32(op->opnum);
4442 post_err_offset = xdr->buf->len;
4444 if (op->opnum == OP_ILLEGAL)
4446 if (op->status && opdesc &&
4447 !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE))
4449 BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) ||
4450 !nfsd4_enc_ops[op->opnum]);
4451 encoder = nfsd4_enc_ops[op->opnum];
4452 op->status = encoder(resp, op->status, &op->u);
4453 if (opdesc && opdesc->op_release)
4454 opdesc->op_release(&op->u);
4455 xdr_commit_encode(xdr);
4457 /* nfsd4_check_resp_size guarantees enough room for error status */
4459 int space_needed = 0;
4460 if (!nfsd4_last_compound_op(rqstp))
4461 space_needed = COMPOUND_ERR_SLACK_SPACE;
4462 op->status = nfsd4_check_resp_size(resp, space_needed);
4464 if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) {
4465 struct nfsd4_slot *slot = resp->cstate.slot;
4467 if (slot->sl_flags & NFSD4_SLOT_CACHETHIS)
4468 op->status = nfserr_rep_too_big_to_cache;
4470 op->status = nfserr_rep_too_big;
4472 if (op->status == nfserr_resource ||
4473 op->status == nfserr_rep_too_big ||
4474 op->status == nfserr_rep_too_big_to_cache) {
4476 * The operation may have already been encoded or
4477 * partially encoded. No op returns anything additional
4478 * in the case of one of these three errors, so we can
4479 * just truncate back to after the status. But it's a
4480 * bug if we had to do this on a non-idempotent op:
4482 warn_on_nonidempotent_op(op);
4483 xdr_truncate_encode(xdr, post_err_offset);
4486 int len = xdr->buf->len - post_err_offset;
4488 so->so_replay.rp_status = op->status;
4489 so->so_replay.rp_buflen = len;
4490 read_bytes_from_xdr_buf(xdr->buf, post_err_offset,
4491 so->so_replay.rp_buf, len);
4494 /* Note that op->status is already in network byte order: */
4495 write_bytes_to_xdr_buf(xdr->buf, post_err_offset - 4, &op->status, 4);
4499 * Encode the reply stored in the stateowner reply cache
4501 * XDR note: do not encode rp->rp_buflen: the buffer contains the
4502 * previously sent already encoded operation.
4505 nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
4508 struct nfs4_replay *rp = op->replay;
4512 p = xdr_reserve_space(xdr, 8 + rp->rp_buflen);
4517 *p++ = cpu_to_be32(op->opnum);
4518 *p++ = rp->rp_status; /* already xdr'ed */
4520 p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen);
4524 nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p)
4526 return xdr_ressize_check(rqstp, p);
4529 void nfsd4_release_compoundargs(struct svc_rqst *rqstp)
4531 struct nfsd4_compoundargs *args = rqstp->rq_argp;
4533 if (args->ops != args->iops) {
4535 args->ops = args->iops;
4539 while (args->to_free) {
4540 struct svcxdr_tmpbuf *tb = args->to_free;
4541 args->to_free = tb->next;
4547 nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p)
4549 struct nfsd4_compoundargs *args = rqstp->rq_argp;
4551 if (rqstp->rq_arg.head[0].iov_len % 4) {
4552 /* client is nuts */
4553 dprintk("%s: compound not properly padded! (peeraddr=%pISc xid=0x%x)",
4554 __func__, svc_addr(rqstp), be32_to_cpu(rqstp->rq_xid));
4558 args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len;
4559 args->pagelist = rqstp->rq_arg.pages;
4560 args->pagelen = rqstp->rq_arg.page_len;
4563 args->to_free = NULL;
4564 args->ops = args->iops;
4565 args->rqstp = rqstp;
4567 return !nfsd4_decode_compound(args);
4571 nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p)
4574 * All that remains is to write the tag and operation count...
4576 struct nfsd4_compoundres *resp = rqstp->rq_resp;
4577 struct xdr_buf *buf = resp->xdr.buf;
4579 WARN_ON_ONCE(buf->len != buf->head[0].iov_len + buf->page_len +
4580 buf->tail[0].iov_len);
4582 rqstp->rq_next_page = resp->xdr.page_ptr + 1;
4585 *p++ = htonl(resp->taglen);
4586 memcpy(p, resp->tag, resp->taglen);
4587 p += XDR_QUADLEN(resp->taglen);
4588 *p++ = htonl(resp->opcnt);
4590 nfsd4_sequence_done(resp);