2 * Server-side XDR for NFSv4
4 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * Kendrick Smith <kmsmith@umich.edu>
8 * Andy Adamson <andros@umich.edu>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * TODO: Neil Brown made the following observation: We currently
36 * initially reserve NFSD_BUFSIZE space on the transmit queue and
37 * never release any of that until the request is complete.
38 * It would be good to calculate a new maximum response size while
39 * decoding the COMPOUND, and call svc_reserve with this number
40 * at the end of nfs4svc_decode_compoundargs.
43 #include <linux/slab.h>
44 #include <linux/namei.h>
45 #include <linux/statfs.h>
46 #include <linux/utsname.h>
47 #include <linux/pagemap.h>
48 #include <linux/sunrpc/svcauth_gss.h>
58 #define NFSDDBG_FACILITY NFSDDBG_XDR
61 * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
62 * directory in order to indicate to the client that a filesystem boundary is present
63 * We use a fixed fsid for a referral
65 #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
66 #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
69 check_filename(char *str, int len)
75 if (isdotent(str, len))
76 return nfserr_badname;
77 for (i = 0; i < len; i++)
79 return nfserr_badname;
91 dprintk("NFSD: xdr error (%s:%d)\n", \
92 __FILE__, __LINE__); \
93 status = nfserr_bad_xdr; \
96 #define READ32(x) (x) = ntohl(*p++)
97 #define READ64(x) do { \
98 (x) = (u64)ntohl(*p++) << 32; \
101 #define READTIME(x) do { \
106 #define READMEM(x,nbytes) do { \
108 p += XDR_QUADLEN(nbytes); \
110 #define SAVEMEM(x,nbytes) do { \
111 if (!(x = (p==argp->tmp || p == argp->tmpp) ? \
112 savemem(argp, p, nbytes) : \
114 dprintk("NFSD: xdr error (%s:%d)\n", \
115 __FILE__, __LINE__); \
118 p += XDR_QUADLEN(nbytes); \
120 #define COPYMEM(x,nbytes) do { \
121 memcpy((x), p, nbytes); \
122 p += XDR_QUADLEN(nbytes); \
125 /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */
126 #define READ_BUF(nbytes) do { \
127 if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \
129 argp->p += XDR_QUADLEN(nbytes); \
130 } else if (!(p = read_buf(argp, nbytes))) { \
131 dprintk("NFSD: xdr error (%s:%d)\n", \
132 __FILE__, __LINE__); \
137 static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
139 /* We want more bytes than seem to be available.
140 * Maybe we need a new page, maybe we have just run out
142 unsigned int avail = (char *)argp->end - (char *)argp->p;
144 if (avail + argp->pagelen < nbytes)
146 if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */
148 /* ok, we can do it with the current plus the next page */
149 if (nbytes <= sizeof(argp->tmp))
153 p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL);
159 * The following memcpy is safe because read_buf is always
160 * called with nbytes > avail, and the two cases above both
161 * guarantee p points to at least nbytes bytes.
163 memcpy(p, argp->p, avail);
164 /* step to next page */
166 argp->p = page_address(argp->pagelist[0]);
167 if (argp->pagelen < PAGE_SIZE) {
168 argp->end = argp->p + (argp->pagelen>>2);
171 argp->end = argp->p + (PAGE_SIZE>>2);
172 argp->pagelen -= PAGE_SIZE;
174 memcpy(((char*)p)+avail, argp->p, (nbytes - avail));
175 argp->p += XDR_QUADLEN(nbytes - avail);
179 static int zero_clientid(clientid_t *clid)
181 return (clid->cl_boot == 0) && (clid->cl_id == 0);
185 defer_free(struct nfsd4_compoundargs *argp,
186 void (*release)(const void *), void *p)
190 tb = kmalloc(sizeof(*tb), GFP_KERNEL);
194 tb->release = release;
195 tb->next = argp->to_free;
200 static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
202 if (p == argp->tmp) {
203 p = kmemdup(argp->tmp, nbytes, GFP_KERNEL);
207 BUG_ON(p != argp->tmpp);
210 if (defer_free(argp, kfree, p)) {
218 nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
232 READ_BUF(bmlen << 2);
244 nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
245 struct iattr *iattr, struct nfs4_acl **acl)
247 int expected_len, len = 0;
254 if ((status = nfsd4_decode_bitmap(argp, bmval)))
258 READ32(expected_len);
260 if (bmval[0] & FATTR4_WORD0_SIZE) {
263 READ64(iattr->ia_size);
264 iattr->ia_valid |= ATTR_SIZE;
266 if (bmval[0] & FATTR4_WORD0_ACL) {
268 struct nfs4_ace *ace;
270 READ_BUF(4); len += 4;
273 if (nace > NFS4_ACL_MAX)
274 return nfserr_resource;
276 *acl = nfs4_acl_new(nace);
281 defer_free(argp, kfree, *acl);
283 (*acl)->naces = nace;
284 for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) {
285 READ_BUF(16); len += 16;
288 READ32(ace->access_mask);
291 len += XDR_QUADLEN(dummy32) << 2;
292 READMEM(buf, dummy32);
293 ace->whotype = nfs4_acl_get_whotype(buf, dummy32);
295 if (ace->whotype != NFS4_ACL_WHO_NAMED)
297 else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
298 status = nfsd_map_name_to_gid(argp->rqstp,
299 buf, dummy32, &ace->who_gid);
301 status = nfsd_map_name_to_uid(argp->rqstp,
302 buf, dummy32, &ace->who_uid);
308 if (bmval[1] & FATTR4_WORD1_MODE) {
311 READ32(iattr->ia_mode);
312 iattr->ia_mode &= (S_IFMT | S_IALLUGO);
313 iattr->ia_valid |= ATTR_MODE;
315 if (bmval[1] & FATTR4_WORD1_OWNER) {
320 len += (XDR_QUADLEN(dummy32) << 2);
321 READMEM(buf, dummy32);
322 if ((status = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid)))
324 iattr->ia_valid |= ATTR_UID;
326 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) {
331 len += (XDR_QUADLEN(dummy32) << 2);
332 READMEM(buf, dummy32);
333 if ((status = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid)))
335 iattr->ia_valid |= ATTR_GID;
337 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
342 case NFS4_SET_TO_CLIENT_TIME:
343 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
344 all 32 bits of 'nseconds'. */
347 READ64(iattr->ia_atime.tv_sec);
348 READ32(iattr->ia_atime.tv_nsec);
349 if (iattr->ia_atime.tv_nsec >= (u32)1000000000)
351 iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
353 case NFS4_SET_TO_SERVER_TIME:
354 iattr->ia_valid |= ATTR_ATIME;
360 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
365 case NFS4_SET_TO_CLIENT_TIME:
366 /* We require the high 32 bits of 'seconds' to be 0, and we ignore
367 all 32 bits of 'nseconds'. */
370 READ64(iattr->ia_mtime.tv_sec);
371 READ32(iattr->ia_mtime.tv_nsec);
372 if (iattr->ia_mtime.tv_nsec >= (u32)1000000000)
374 iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
376 case NFS4_SET_TO_SERVER_TIME:
377 iattr->ia_valid |= ATTR_MTIME;
383 if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
384 || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
385 || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2)
386 READ_BUF(expected_len - len);
387 else if (len != expected_len)
393 status = nfserrno(host_err);
398 nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid)
402 READ_BUF(sizeof(stateid_t));
403 READ32(sid->si_generation);
404 COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
410 nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access)
415 READ32(access->ac_req_access);
420 static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs)
428 /* callback_sec_params4 */
431 cbs->flavor = (u32)(-1);
432 for (i = 0; i < nr_secflavs; ++i) {
437 /* Nothing to read */
438 if (cbs->flavor == (u32)(-1))
439 cbs->flavor = RPC_AUTH_NULL;
449 SAVEMEM(machine_name, dummy);
460 if (cbs->flavor == (u32)(-1)) {
461 kuid_t kuid = make_kuid(&init_user_ns, uid);
462 kgid_t kgid = make_kgid(&init_user_ns, gid);
463 if (uid_valid(kuid) && gid_valid(kgid)) {
466 cbs->flavor = RPC_AUTH_UNIX;
468 dprintk("RPC_AUTH_UNIX with invalid"
469 "uid or gid ignoring!\n");
474 dprintk("RPC_AUTH_GSS callback secflavor "
479 /* gcbp_handle_from_server */
482 p += XDR_QUADLEN(dummy);
483 /* gcbp_handle_from_client */
489 dprintk("Illegal callback secflavor\n");
496 static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc)
501 READ32(bc->bc_cb_program);
502 nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec);
507 static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts)
511 READ_BUF(NFS4_MAX_SESSIONID_LEN + 8);
512 COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
514 /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker
515 * could help us figure out we should be using it. */
520 nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close)
525 READ32(close->cl_seqid);
526 return nfsd4_decode_stateid(argp, &close->cl_stateid);
533 nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit)
538 READ64(commit->co_offset);
539 READ32(commit->co_count);
545 nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create)
550 READ32(create->cr_type);
551 switch (create->cr_type) {
554 READ32(create->cr_linklen);
555 READ_BUF(create->cr_linklen);
557 * The VFS will want a null-terminated string, and
558 * null-terminating in place isn't safe since this might
559 * end on a page boundary:
561 create->cr_linkname =
562 kmalloc(create->cr_linklen + 1, GFP_KERNEL);
563 if (!create->cr_linkname)
564 return nfserr_jukebox;
565 memcpy(create->cr_linkname, p, create->cr_linklen);
566 create->cr_linkname[create->cr_linklen] = '\0';
567 defer_free(argp, kfree, create->cr_linkname);
572 READ32(create->cr_specdata1);
573 READ32(create->cr_specdata2);
583 READ32(create->cr_namelen);
584 READ_BUF(create->cr_namelen);
585 SAVEMEM(create->cr_name, create->cr_namelen);
586 if ((status = check_filename(create->cr_name, create->cr_namelen)))
589 status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
598 nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr)
600 return nfsd4_decode_stateid(argp, &dr->dr_stateid);
604 nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr)
606 return nfsd4_decode_bitmap(argp, getattr->ga_bmval);
610 nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link)
615 READ32(link->li_namelen);
616 READ_BUF(link->li_namelen);
617 SAVEMEM(link->li_name, link->li_namelen);
618 if ((status = check_filename(link->li_name, link->li_namelen)))
625 nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
630 * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
633 READ32(lock->lk_type);
634 if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT))
636 READ32(lock->lk_reclaim);
637 READ64(lock->lk_offset);
638 READ64(lock->lk_length);
639 READ32(lock->lk_is_new);
641 if (lock->lk_is_new) {
643 READ32(lock->lk_new_open_seqid);
644 status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid);
647 READ_BUF(8 + sizeof(clientid_t));
648 READ32(lock->lk_new_lock_seqid);
649 COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t));
650 READ32(lock->lk_new_owner.len);
651 READ_BUF(lock->lk_new_owner.len);
652 READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len);
654 status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid);
658 READ32(lock->lk_old_lock_seqid);
665 nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt)
670 READ32(lockt->lt_type);
671 if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT))
673 READ64(lockt->lt_offset);
674 READ64(lockt->lt_length);
675 COPYMEM(&lockt->lt_clientid, 8);
676 READ32(lockt->lt_owner.len);
677 READ_BUF(lockt->lt_owner.len);
678 READMEM(lockt->lt_owner.data, lockt->lt_owner.len);
684 nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku)
689 READ32(locku->lu_type);
690 if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
692 READ32(locku->lu_seqid);
693 status = nfsd4_decode_stateid(argp, &locku->lu_stateid);
697 READ64(locku->lu_offset);
698 READ64(locku->lu_length);
704 nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup)
709 READ32(lookup->lo_len);
710 READ_BUF(lookup->lo_len);
711 SAVEMEM(lookup->lo_name, lookup->lo_len);
712 if ((status = check_filename(lookup->lo_name, lookup->lo_len)))
718 static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *share_access, u32 *deleg_want, u32 *deleg_when)
725 *share_access = w & NFS4_SHARE_ACCESS_MASK;
726 *deleg_want = w & NFS4_SHARE_WANT_MASK;
728 *deleg_when = w & NFS4_SHARE_WHEN_MASK;
730 switch (w & NFS4_SHARE_ACCESS_MASK) {
731 case NFS4_SHARE_ACCESS_READ:
732 case NFS4_SHARE_ACCESS_WRITE:
733 case NFS4_SHARE_ACCESS_BOTH:
736 return nfserr_bad_xdr;
738 w &= ~NFS4_SHARE_ACCESS_MASK;
741 if (!argp->minorversion)
742 return nfserr_bad_xdr;
743 switch (w & NFS4_SHARE_WANT_MASK) {
744 case NFS4_SHARE_WANT_NO_PREFERENCE:
745 case NFS4_SHARE_WANT_READ_DELEG:
746 case NFS4_SHARE_WANT_WRITE_DELEG:
747 case NFS4_SHARE_WANT_ANY_DELEG:
748 case NFS4_SHARE_WANT_NO_DELEG:
749 case NFS4_SHARE_WANT_CANCEL:
752 return nfserr_bad_xdr;
754 w &= ~NFS4_SHARE_WANT_MASK;
758 if (!deleg_when) /* open_downgrade */
761 case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL:
762 case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED:
763 case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL |
764 NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED):
768 return nfserr_bad_xdr;
771 static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x)
777 /* Note: unlinke access bits, deny bits may be zero. */
778 if (*x & ~NFS4_SHARE_DENY_BOTH)
779 return nfserr_bad_xdr;
782 return nfserr_bad_xdr;
785 static __be32 nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o)
792 if (o->len == 0 || o->len > NFS4_OPAQUE_LIMIT)
793 return nfserr_bad_xdr;
796 SAVEMEM(o->data, o->len);
799 return nfserr_bad_xdr;
803 nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
808 memset(open->op_bmval, 0, sizeof(open->op_bmval));
809 open->op_iattr.ia_valid = 0;
810 open->op_openowner = NULL;
812 open->op_xdr_error = 0;
813 /* seqid, share_access, share_deny, clientid, ownerlen */
815 READ32(open->op_seqid);
816 /* decode, yet ignore deleg_when until supported */
817 status = nfsd4_decode_share_access(argp, &open->op_share_access,
818 &open->op_deleg_want, &dummy);
821 status = nfsd4_decode_share_deny(argp, &open->op_share_deny);
824 READ_BUF(sizeof(clientid_t));
825 COPYMEM(&open->op_clientid, sizeof(clientid_t));
826 status = nfsd4_decode_opaque(argp, &open->op_owner);
830 READ32(open->op_create);
831 switch (open->op_create) {
832 case NFS4_OPEN_NOCREATE:
834 case NFS4_OPEN_CREATE:
836 READ32(open->op_createmode);
837 switch (open->op_createmode) {
838 case NFS4_CREATE_UNCHECKED:
839 case NFS4_CREATE_GUARDED:
840 status = nfsd4_decode_fattr(argp, open->op_bmval,
841 &open->op_iattr, &open->op_acl);
845 case NFS4_CREATE_EXCLUSIVE:
846 READ_BUF(NFS4_VERIFIER_SIZE);
847 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
849 case NFS4_CREATE_EXCLUSIVE4_1:
850 if (argp->minorversion < 1)
852 READ_BUF(NFS4_VERIFIER_SIZE);
853 COPYMEM(open->op_verf.data, NFS4_VERIFIER_SIZE);
854 status = nfsd4_decode_fattr(argp, open->op_bmval,
855 &open->op_iattr, &open->op_acl);
869 READ32(open->op_claim_type);
870 switch (open->op_claim_type) {
871 case NFS4_OPEN_CLAIM_NULL:
872 case NFS4_OPEN_CLAIM_DELEGATE_PREV:
874 READ32(open->op_fname.len);
875 READ_BUF(open->op_fname.len);
876 SAVEMEM(open->op_fname.data, open->op_fname.len);
877 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
880 case NFS4_OPEN_CLAIM_PREVIOUS:
882 READ32(open->op_delegate_type);
884 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
885 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
889 READ32(open->op_fname.len);
890 READ_BUF(open->op_fname.len);
891 SAVEMEM(open->op_fname.data, open->op_fname.len);
892 if ((status = check_filename(open->op_fname.data, open->op_fname.len)))
895 case NFS4_OPEN_CLAIM_FH:
896 case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
897 if (argp->minorversion < 1)
901 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
902 if (argp->minorversion < 1)
904 status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
916 nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf)
920 status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
924 READ32(open_conf->oc_seqid);
930 nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down)
934 status = nfsd4_decode_stateid(argp, &open_down->od_stateid);
938 READ32(open_down->od_seqid);
939 status = nfsd4_decode_share_access(argp, &open_down->od_share_access,
940 &open_down->od_deleg_want, NULL);
943 status = nfsd4_decode_share_deny(argp, &open_down->od_share_deny);
950 nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh)
955 READ32(putfh->pf_fhlen);
956 if (putfh->pf_fhlen > NFS4_FHSIZE)
958 READ_BUF(putfh->pf_fhlen);
959 SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen);
965 nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
969 status = nfsd4_decode_stateid(argp, &read->rd_stateid);
973 READ64(read->rd_offset);
974 READ32(read->rd_length);
980 nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir)
985 READ64(readdir->rd_cookie);
986 COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data));
987 READ32(readdir->rd_dircount); /* just in case you needed a useless field... */
988 READ32(readdir->rd_maxcount);
989 if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval)))
996 nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove)
1001 READ32(remove->rm_namelen);
1002 READ_BUF(remove->rm_namelen);
1003 SAVEMEM(remove->rm_name, remove->rm_namelen);
1004 if ((status = check_filename(remove->rm_name, remove->rm_namelen)))
1011 nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename)
1016 READ32(rename->rn_snamelen);
1017 READ_BUF(rename->rn_snamelen + 4);
1018 SAVEMEM(rename->rn_sname, rename->rn_snamelen);
1019 READ32(rename->rn_tnamelen);
1020 READ_BUF(rename->rn_tnamelen);
1021 SAVEMEM(rename->rn_tname, rename->rn_tnamelen);
1022 if ((status = check_filename(rename->rn_sname, rename->rn_snamelen)))
1024 if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen)))
1031 nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid)
1035 READ_BUF(sizeof(clientid_t));
1036 COPYMEM(clientid, sizeof(clientid_t));
1042 nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
1043 struct nfsd4_secinfo *secinfo)
1048 READ32(secinfo->si_namelen);
1049 READ_BUF(secinfo->si_namelen);
1050 SAVEMEM(secinfo->si_name, secinfo->si_namelen);
1051 status = check_filename(secinfo->si_name, secinfo->si_namelen);
1058 nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp,
1059 struct nfsd4_secinfo_no_name *sin)
1064 READ32(sin->sin_style);
1069 nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr)
1073 status = nfsd4_decode_stateid(argp, &setattr->sa_stateid);
1076 return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr,
1081 nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid)
1085 READ_BUF(NFS4_VERIFIER_SIZE);
1086 COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE);
1088 status = nfsd4_decode_opaque(argp, &setclientid->se_name);
1090 return nfserr_bad_xdr;
1092 READ32(setclientid->se_callback_prog);
1093 READ32(setclientid->se_callback_netid_len);
1095 READ_BUF(setclientid->se_callback_netid_len + 4);
1096 SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len);
1097 READ32(setclientid->se_callback_addr_len);
1099 READ_BUF(setclientid->se_callback_addr_len + 4);
1100 SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len);
1101 READ32(setclientid->se_callback_ident);
1107 nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c)
1111 READ_BUF(8 + NFS4_VERIFIER_SIZE);
1112 COPYMEM(&scd_c->sc_clientid, 8);
1113 COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE);
1118 /* Also used for NVERIFY */
1120 nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify)
1124 if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval)))
1127 /* For convenience's sake, we compare raw xdr'd attributes in
1128 * nfsd4_proc_verify */
1131 READ32(verify->ve_attrlen);
1132 READ_BUF(verify->ve_attrlen);
1133 SAVEMEM(verify->ve_attrval, verify->ve_attrlen);
1139 nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
1145 status = nfsd4_decode_stateid(argp, &write->wr_stateid);
1149 READ64(write->wr_offset);
1150 READ32(write->wr_stable_how);
1151 if (write->wr_stable_how > 2)
1153 READ32(write->wr_buflen);
1155 /* Sorry .. no magic macros for this.. *
1156 * READ_BUF(write->wr_buflen);
1157 * SAVEMEM(write->wr_buf, write->wr_buflen);
1159 avail = (char*)argp->end - (char*)argp->p;
1160 if (avail + argp->pagelen < write->wr_buflen) {
1161 dprintk("NFSD: xdr error (%s:%d)\n",
1162 __FILE__, __LINE__);
1165 write->wr_head.iov_base = p;
1166 write->wr_head.iov_len = avail;
1167 WARN_ON(avail != (XDR_QUADLEN(avail) << 2));
1168 write->wr_pagelist = argp->pagelist;
1170 len = XDR_QUADLEN(write->wr_buflen) << 2;
1176 pages = len >> PAGE_SHIFT;
1177 argp->pagelist += pages;
1178 argp->pagelen -= pages * PAGE_SIZE;
1179 len -= pages * PAGE_SIZE;
1181 argp->p = (__be32 *)page_address(argp->pagelist[0]);
1182 argp->end = argp->p + XDR_QUADLEN(PAGE_SIZE);
1184 argp->p += XDR_QUADLEN(len);
1190 nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner)
1195 COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t));
1196 READ32(rlockowner->rl_owner.len);
1197 READ_BUF(rlockowner->rl_owner.len);
1198 READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len);
1200 if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid))
1201 return nfserr_inval;
1206 nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
1207 struct nfsd4_exchange_id *exid)
1212 READ_BUF(NFS4_VERIFIER_SIZE);
1213 COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE);
1215 status = nfsd4_decode_opaque(argp, &exid->clname);
1217 return nfserr_bad_xdr;
1220 READ32(exid->flags);
1222 /* Ignore state_protect4_a */
1224 READ32(exid->spa_how);
1225 switch (exid->spa_how) {
1229 /* spo_must_enforce */
1232 READ_BUF(dummy * 4);
1235 /* spo_must_allow */
1238 READ_BUF(dummy * 4);
1245 READ_BUF(dummy * 4);
1250 READ_BUF(dummy * 4);
1253 /* ssp_hash_algs<> */
1260 p += XDR_QUADLEN(dummy);
1263 /* ssp_encr_algs<> */
1270 p += XDR_QUADLEN(dummy);
1273 /* ssp_window and ssp_num_gss_handles */
1282 /* Ignore Implementation ID */
1283 READ_BUF(4); /* nfs_impl_id4 array length */
1294 p += XDR_QUADLEN(dummy);
1300 p += XDR_QUADLEN(dummy);
1310 nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
1311 struct nfsd4_create_session *sess)
1317 COPYMEM(&sess->clientid, 8);
1318 READ32(sess->seqid);
1319 READ32(sess->flags);
1321 /* Fore channel attrs */
1323 READ32(dummy); /* headerpadsz is always 0 */
1324 READ32(sess->fore_channel.maxreq_sz);
1325 READ32(sess->fore_channel.maxresp_sz);
1326 READ32(sess->fore_channel.maxresp_cached);
1327 READ32(sess->fore_channel.maxops);
1328 READ32(sess->fore_channel.maxreqs);
1329 READ32(sess->fore_channel.nr_rdma_attrs);
1330 if (sess->fore_channel.nr_rdma_attrs == 1) {
1332 READ32(sess->fore_channel.rdma_attrs);
1333 } else if (sess->fore_channel.nr_rdma_attrs > 1) {
1334 dprintk("Too many fore channel attr bitmaps!\n");
1338 /* Back channel attrs */
1340 READ32(dummy); /* headerpadsz is always 0 */
1341 READ32(sess->back_channel.maxreq_sz);
1342 READ32(sess->back_channel.maxresp_sz);
1343 READ32(sess->back_channel.maxresp_cached);
1344 READ32(sess->back_channel.maxops);
1345 READ32(sess->back_channel.maxreqs);
1346 READ32(sess->back_channel.nr_rdma_attrs);
1347 if (sess->back_channel.nr_rdma_attrs == 1) {
1349 READ32(sess->back_channel.rdma_attrs);
1350 } else if (sess->back_channel.nr_rdma_attrs > 1) {
1351 dprintk("Too many back channel attr bitmaps!\n");
1356 READ32(sess->callback_prog);
1357 nfsd4_decode_cb_sec(argp, &sess->cb_sec);
1362 nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp,
1363 struct nfsd4_destroy_session *destroy_session)
1366 READ_BUF(NFS4_MAX_SESSIONID_LEN);
1367 COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1373 nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp,
1374 struct nfsd4_free_stateid *free_stateid)
1378 READ_BUF(sizeof(stateid_t));
1379 READ32(free_stateid->fr_stateid.si_generation);
1380 COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t));
1386 nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
1387 struct nfsd4_sequence *seq)
1391 READ_BUF(NFS4_MAX_SESSIONID_LEN + 16);
1392 COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
1394 READ32(seq->slotid);
1395 READ32(seq->maxslots);
1396 READ32(seq->cachethis);
1402 nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid)
1406 struct nfsd4_test_stateid_id *stateid;
1409 test_stateid->ts_num_ids = ntohl(*p++);
1411 INIT_LIST_HEAD(&test_stateid->ts_stateid_list);
1413 for (i = 0; i < test_stateid->ts_num_ids; i++) {
1414 stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL);
1416 status = nfserrno(-ENOMEM);
1420 defer_free(argp, kfree, stateid);
1421 INIT_LIST_HEAD(&stateid->ts_id_list);
1422 list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list);
1424 status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid);
1433 dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__);
1434 status = nfserr_bad_xdr;
1438 static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc)
1443 COPYMEM(&dc->clientid, 8);
1448 static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc)
1453 READ32(rc->rca_one_fs);
1459 nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p)
1465 nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
1467 return nfserr_notsupp;
1470 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
1472 static nfsd4_dec nfsd4_dec_ops[] = {
1473 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
1474 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
1475 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
1476 [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
1477 [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
1478 [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
1479 [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
1480 [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
1481 [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
1482 [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
1483 [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
1484 [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
1485 [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
1486 [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
1487 [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1488 [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
1489 [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
1490 [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm,
1491 [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
1492 [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
1493 [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_noop,
1494 [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
1495 [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
1496 [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
1497 [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
1498 [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
1499 [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
1500 [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew,
1501 [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
1502 [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
1503 [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
1504 [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
1505 [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid,
1506 [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm,
1507 [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1508 [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
1509 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
1512 static nfsd4_dec nfsd41_dec_ops[] = {
1513 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
1514 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
1515 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
1516 [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
1517 [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
1518 [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
1519 [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
1520 [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
1521 [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
1522 [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
1523 [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
1524 [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
1525 [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
1526 [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
1527 [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1528 [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
1529 [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
1530 [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_notsupp,
1531 [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
1532 [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
1533 [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_notsupp,
1534 [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
1535 [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
1536 [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
1537 [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
1538 [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
1539 [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
1540 [OP_RENEW] = (nfsd4_dec)nfsd4_decode_notsupp,
1541 [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
1542 [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
1543 [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
1544 [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
1545 [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_notsupp,
1546 [OP_SETCLIENTID_CONFIRM]= (nfsd4_dec)nfsd4_decode_notsupp,
1547 [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
1548 [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
1549 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_notsupp,
1551 /* new operations for NFSv4.1 */
1552 [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl,
1553 [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session,
1554 [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id,
1555 [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session,
1556 [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session,
1557 [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid,
1558 [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
1559 [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp,
1560 [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
1561 [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp,
1562 [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp,
1563 [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp,
1564 [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name,
1565 [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence,
1566 [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp,
1567 [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid,
1568 [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
1569 [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid,
1570 [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete,
1573 struct nfsd4_minorversion_ops {
1574 nfsd4_dec *decoders;
1578 static struct nfsd4_minorversion_ops nfsd4_minorversion[] = {
1579 [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) },
1580 [1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
1584 nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
1587 struct nfsd4_op *op;
1588 struct nfsd4_minorversion_ops *ops;
1589 bool cachethis = false;
1593 READ32(argp->taglen);
1594 READ_BUF(argp->taglen + 8);
1595 SAVEMEM(argp->tag, argp->taglen);
1596 READ32(argp->minorversion);
1597 READ32(argp->opcnt);
1599 if (argp->taglen > NFSD4_MAX_TAGLEN)
1601 if (argp->opcnt > 100)
1604 if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
1605 argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL);
1607 argp->ops = argp->iops;
1608 dprintk("nfsd: couldn't allocate room for COMPOUND\n");
1613 if (argp->minorversion >= ARRAY_SIZE(nfsd4_minorversion))
1616 ops = &nfsd4_minorversion[argp->minorversion];
1617 for (i = 0; i < argp->opcnt; i++) {
1624 if (op->opnum >= FIRST_NFS4_OP && op->opnum <= LAST_NFS4_OP)
1625 op->status = ops->decoders[op->opnum](argp, &op->u);
1627 op->opnum = OP_ILLEGAL;
1628 op->status = nfserr_op_illegal;
1636 * We'll try to cache the result in the DRC if any one
1637 * op in the compound wants to be cached:
1639 cachethis |= nfsd4_cache_this_op(op);
1641 /* Sessions make the DRC unnecessary: */
1642 if (argp->minorversion)
1644 argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE;
1649 #define WRITE32(n) *p++ = htonl(n)
1650 #define WRITE64(n) do { \
1651 *p++ = htonl((u32)((n) >> 32)); \
1652 *p++ = htonl((u32)(n)); \
1654 #define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \
1655 *(p + XDR_QUADLEN(nbytes) -1) = 0; \
1656 memcpy(p, ptr, nbytes); \
1657 p += XDR_QUADLEN(nbytes); \
1660 static void write32(__be32 **p, u32 n)
1665 static void write64(__be32 **p, u64 n)
1667 write32(p, (n >> 32));
1671 static void write_change(__be32 **p, struct kstat *stat, struct inode *inode)
1673 if (IS_I_VERSION(inode)) {
1674 write64(p, inode->i_version);
1676 write32(p, stat->ctime.tv_sec);
1677 write32(p, stat->ctime.tv_nsec);
1681 static void write_cinfo(__be32 **p, struct nfsd4_change_info *c)
1683 write32(p, c->atomic);
1684 if (c->change_supported) {
1685 write64(p, c->before_change);
1686 write64(p, c->after_change);
1688 write32(p, c->before_ctime_sec);
1689 write32(p, c->before_ctime_nsec);
1690 write32(p, c->after_ctime_sec);
1691 write32(p, c->after_ctime_nsec);
1695 #define RESERVE_SPACE(nbytes) do { \
1697 BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
1699 #define ADJUST_ARGS() resp->p = p
1701 /* Encode as an array of strings the string given with components
1702 * separated @sep, escaped with esc_enter and esc_exit.
1704 static __be32 nfsd4_encode_components_esc(char sep, char *components,
1705 __be32 **pp, int *buflen,
1706 char esc_enter, char esc_exit)
1710 int strlen, count=0;
1711 char *str, *end, *next;
1713 dprintk("nfsd4_encode_components(%s)\n", components);
1714 if ((*buflen -= 4) < 0)
1715 return nfserr_resource;
1716 WRITE32(0); /* We will fill this in with @count later */
1717 end = str = components;
1719 bool found_esc = false;
1721 /* try to parse as esc_start, ..., esc_end, sep */
1722 if (*str == esc_enter) {
1723 for (; *end && (*end != esc_exit); end++)
1724 /* find esc_exit or end of string */;
1726 if (*end && (!*next || *next == sep)) {
1733 for (; *end && (*end != sep); end++)
1734 /* find sep or end of string */;
1738 if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
1739 return nfserr_resource;
1741 WRITEMEM(str, strlen);
1757 /* Encode as an array of strings the string given with components
1760 static __be32 nfsd4_encode_components(char sep, char *components,
1761 __be32 **pp, int *buflen)
1763 return nfsd4_encode_components_esc(sep, components, pp, buflen, 0, 0);
1767 * encode a location element of a fs_locations structure
1769 static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
1770 __be32 **pp, int *buflen)
1775 status = nfsd4_encode_components_esc(':', location->hosts, &p, buflen,
1779 status = nfsd4_encode_components('/', location->path, &p, buflen);
1787 * Encode a path in RFC3530 'pathname4' format
1789 static __be32 nfsd4_encode_path(const struct path *root,
1790 const struct path *path, __be32 **pp, int *buflen)
1794 .dentry = path->dentry,
1797 struct dentry **components = NULL;
1798 unsigned int ncomponents = 0;
1799 __be32 err = nfserr_jukebox;
1801 dprintk("nfsd4_encode_components(");
1804 /* First walk the path up to the nfsd root, and store the
1805 * dentries/path components in an array.
1808 if (cur.dentry == root->dentry && cur.mnt == root->mnt)
1810 if (cur.dentry == cur.mnt->mnt_root) {
1811 if (follow_up(&cur))
1815 if ((ncomponents & 15) == 0) {
1816 struct dentry **new;
1817 new = krealloc(components,
1818 sizeof(*new) * (ncomponents + 16),
1824 components[ncomponents++] = cur.dentry;
1825 cur.dentry = dget_parent(cur.dentry);
1831 WRITE32(ncomponents);
1833 while (ncomponents) {
1834 struct dentry *dentry = components[ncomponents - 1];
1835 unsigned int len = dentry->d_name.len;
1837 *buflen -= 4 + (XDR_QUADLEN(len) << 2);
1841 WRITEMEM(dentry->d_name.name, len);
1842 dprintk("/%s", dentry->d_name.name);
1852 dput(components[--ncomponents]);
1858 static __be32 nfsd4_encode_fsloc_fsroot(struct svc_rqst *rqstp,
1859 const struct path *path, __be32 **pp, int *buflen)
1861 struct svc_export *exp_ps;
1864 exp_ps = rqst_find_fsidzero_export(rqstp);
1866 return nfserrno(PTR_ERR(exp_ps));
1867 res = nfsd4_encode_path(&exp_ps->ex_path, path, pp, buflen);
1873 * encode a fs_locations structure
1875 static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp,
1876 struct svc_export *exp,
1877 __be32 **pp, int *buflen)
1882 struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
1884 status = nfsd4_encode_fsloc_fsroot(rqstp, &exp->ex_path, &p, buflen);
1887 if ((*buflen -= 4) < 0)
1888 return nfserr_resource;
1889 WRITE32(fslocs->locations_count);
1890 for (i=0; i<fslocs->locations_count; i++) {
1891 status = nfsd4_encode_fs_location4(&fslocs->locations[i],
1900 static u32 nfs4_file_type(umode_t mode)
1902 switch (mode & S_IFMT) {
1903 case S_IFIFO: return NF4FIFO;
1904 case S_IFCHR: return NF4CHR;
1905 case S_IFDIR: return NF4DIR;
1906 case S_IFBLK: return NF4BLK;
1907 case S_IFLNK: return NF4LNK;
1908 case S_IFREG: return NF4REG;
1909 case S_IFSOCK: return NF4SOCK;
1910 default: return NF4BAD;
1915 nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, kuid_t uid, kgid_t gid,
1916 __be32 **p, int *buflen)
1920 if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4)
1921 return nfserr_resource;
1922 if (whotype != NFS4_ACL_WHO_NAMED)
1923 status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1));
1924 else if (gid_valid(gid))
1925 status = nfsd_map_gid_to_name(rqstp, gid, (u8 *)(*p + 1));
1927 status = nfsd_map_uid_to_name(rqstp, uid, (u8 *)(*p + 1));
1929 return nfserrno(status);
1930 *p = xdr_encode_opaque(*p, NULL, status);
1931 *buflen -= (XDR_QUADLEN(status) << 2) + 4;
1932 BUG_ON(*buflen < 0);
1936 static inline __be32
1937 nfsd4_encode_user(struct svc_rqst *rqstp, kuid_t user, __be32 **p, int *buflen)
1939 return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, user, INVALID_GID,
1943 static inline __be32
1944 nfsd4_encode_group(struct svc_rqst *rqstp, kgid_t group, __be32 **p, int *buflen)
1946 return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, INVALID_UID, group,
1950 static inline __be32
1951 nfsd4_encode_aclname(struct svc_rqst *rqstp, struct nfs4_ace *ace,
1952 __be32 **p, int *buflen)
1954 kuid_t uid = INVALID_UID;
1955 kgid_t gid = INVALID_GID;
1957 if (ace->whotype == NFS4_ACL_WHO_NAMED) {
1958 if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
1963 return nfsd4_encode_name(rqstp, ace->whotype, uid, gid, p, buflen);
1966 #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
1967 FATTR4_WORD0_RDATTR_ERROR)
1968 #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
1970 static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
1972 /* As per referral draft: */
1973 if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
1974 *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
1975 if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
1976 *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
1977 *rdattr_err = NFSERR_MOVED;
1979 return nfserr_moved;
1981 *bmval0 &= WORD0_ABSENT_FS_ATTRS;
1982 *bmval1 &= WORD1_ABSENT_FS_ATTRS;
1987 static int get_parent_attributes(struct svc_export *exp, struct kstat *stat)
1989 struct path path = exp->ex_path;
1993 while (follow_up(&path)) {
1994 if (path.dentry != path.mnt->mnt_root)
1997 err = vfs_getattr(&path, stat);
2003 * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
2006 * countp is the buffer size in _words_
2009 nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
2010 struct dentry *dentry, __be32 **buffer, int count, u32 *bmval,
2011 struct svc_rqst *rqstp, int ignore_crossmnt)
2013 u32 bmval0 = bmval[0];
2014 u32 bmval1 = bmval[1];
2015 u32 bmval2 = bmval[2];
2017 struct svc_fh tempfh;
2018 struct kstatfs statfs;
2019 int buflen = count << 2;
2024 __be32 *p = *buffer;
2028 struct nfs4_acl *acl = NULL;
2029 struct nfsd4_compoundres *resp = rqstp->rq_resp;
2030 u32 minorversion = resp->cstate.minorversion;
2031 struct path path = {
2032 .mnt = exp->ex_path.mnt,
2035 struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
2037 BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
2038 BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
2039 BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
2040 BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion));
2042 if (exp->ex_fslocs.migrated) {
2044 status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err);
2049 err = vfs_getattr(&path, &stat);
2052 if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE |
2053 FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) ||
2054 (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
2055 FATTR4_WORD1_SPACE_TOTAL))) {
2056 err = vfs_statfs(&path, &statfs);
2060 if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
2061 fh_init(&tempfh, NFS4_FHSIZE);
2062 status = fh_compose(&tempfh, exp, dentry, NULL);
2067 if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT
2068 | FATTR4_WORD0_SUPPORTED_ATTRS)) {
2069 err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
2070 aclsupport = (err == 0);
2071 if (bmval0 & FATTR4_WORD0_ACL) {
2072 if (err == -EOPNOTSUPP)
2073 bmval0 &= ~FATTR4_WORD0_ACL;
2074 else if (err == -EINVAL) {
2075 status = nfserr_attrnotsupp;
2077 } else if (err != 0)
2083 if ((buflen -= 16) < 0)
2089 } else if (bmval1) {
2090 if ((buflen -= 12) < 0)
2096 if ((buflen -= 8) < 0)
2101 attrlenp = p++; /* to be backfilled later */
2103 if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
2104 u32 word0 = nfsd_suppattrs0(minorversion);
2105 u32 word1 = nfsd_suppattrs1(minorversion);
2106 u32 word2 = nfsd_suppattrs2(minorversion);
2109 word0 &= ~FATTR4_WORD0_ACL;
2111 if ((buflen -= 12) < 0)
2117 if ((buflen -= 16) < 0)
2125 if (bmval0 & FATTR4_WORD0_TYPE) {
2126 if ((buflen -= 4) < 0)
2128 dummy = nfs4_file_type(stat.mode);
2129 if (dummy == NF4BAD)
2130 goto out_serverfault;
2133 if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
2134 if ((buflen -= 4) < 0)
2136 if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
2137 WRITE32(NFS4_FH_PERSISTENT);
2139 WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME);
2141 if (bmval0 & FATTR4_WORD0_CHANGE) {
2142 if ((buflen -= 8) < 0)
2144 write_change(&p, &stat, dentry->d_inode);
2146 if (bmval0 & FATTR4_WORD0_SIZE) {
2147 if ((buflen -= 8) < 0)
2151 if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
2152 if ((buflen -= 4) < 0)
2156 if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
2157 if ((buflen -= 4) < 0)
2161 if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
2162 if ((buflen -= 4) < 0)
2166 if (bmval0 & FATTR4_WORD0_FSID) {
2167 if ((buflen -= 16) < 0)
2169 if (exp->ex_fslocs.migrated) {
2170 WRITE64(NFS4_REFERRAL_FSID_MAJOR);
2171 WRITE64(NFS4_REFERRAL_FSID_MINOR);
2172 } else switch(fsid_source(fhp)) {
2173 case FSIDSOURCE_FSID:
2174 WRITE64((u64)exp->ex_fsid);
2177 case FSIDSOURCE_DEV:
2179 WRITE32(MAJOR(stat.dev));
2181 WRITE32(MINOR(stat.dev));
2183 case FSIDSOURCE_UUID:
2184 WRITEMEM(exp->ex_uuid, 16);
2188 if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
2189 if ((buflen -= 4) < 0)
2193 if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
2194 if ((buflen -= 4) < 0)
2196 WRITE32(nn->nfsd4_lease);
2198 if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
2199 if ((buflen -= 4) < 0)
2201 WRITE32(rdattr_err);
2203 if (bmval0 & FATTR4_WORD0_ACL) {
2204 struct nfs4_ace *ace;
2207 if ((buflen -= 4) < 0)
2213 if ((buflen -= 4) < 0)
2215 WRITE32(acl->naces);
2217 for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
2218 if ((buflen -= 4*3) < 0)
2222 WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL);
2223 status = nfsd4_encode_aclname(rqstp, ace, &p, &buflen);
2224 if (status == nfserr_resource)
2231 if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
2232 if ((buflen -= 4) < 0)
2234 WRITE32(aclsupport ?
2235 ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
2237 if (bmval0 & FATTR4_WORD0_CANSETTIME) {
2238 if ((buflen -= 4) < 0)
2242 if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
2243 if ((buflen -= 4) < 0)
2247 if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
2248 if ((buflen -= 4) < 0)
2252 if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
2253 if ((buflen -= 4) < 0)
2257 if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
2258 buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4;
2261 WRITE32(fhp->fh_handle.fh_size);
2262 WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size);
2264 if (bmval0 & FATTR4_WORD0_FILEID) {
2265 if ((buflen -= 8) < 0)
2269 if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
2270 if ((buflen -= 8) < 0)
2272 WRITE64((u64) statfs.f_ffree);
2274 if (bmval0 & FATTR4_WORD0_FILES_FREE) {
2275 if ((buflen -= 8) < 0)
2277 WRITE64((u64) statfs.f_ffree);
2279 if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
2280 if ((buflen -= 8) < 0)
2282 WRITE64((u64) statfs.f_files);
2284 if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
2285 status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen);
2286 if (status == nfserr_resource)
2291 if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
2292 if ((buflen -= 4) < 0)
2296 if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
2297 if ((buflen -= 8) < 0)
2301 if (bmval0 & FATTR4_WORD0_MAXLINK) {
2302 if ((buflen -= 4) < 0)
2306 if (bmval0 & FATTR4_WORD0_MAXNAME) {
2307 if ((buflen -= 4) < 0)
2309 WRITE32(statfs.f_namelen);
2311 if (bmval0 & FATTR4_WORD0_MAXREAD) {
2312 if ((buflen -= 8) < 0)
2314 WRITE64((u64) svc_max_payload(rqstp));
2316 if (bmval0 & FATTR4_WORD0_MAXWRITE) {
2317 if ((buflen -= 8) < 0)
2319 WRITE64((u64) svc_max_payload(rqstp));
2321 if (bmval1 & FATTR4_WORD1_MODE) {
2322 if ((buflen -= 4) < 0)
2324 WRITE32(stat.mode & S_IALLUGO);
2326 if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
2327 if ((buflen -= 4) < 0)
2331 if (bmval1 & FATTR4_WORD1_NUMLINKS) {
2332 if ((buflen -= 4) < 0)
2334 WRITE32(stat.nlink);
2336 if (bmval1 & FATTR4_WORD1_OWNER) {
2337 status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
2338 if (status == nfserr_resource)
2343 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
2344 status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
2345 if (status == nfserr_resource)
2350 if (bmval1 & FATTR4_WORD1_RAWDEV) {
2351 if ((buflen -= 8) < 0)
2353 WRITE32((u32) MAJOR(stat.rdev));
2354 WRITE32((u32) MINOR(stat.rdev));
2356 if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
2357 if ((buflen -= 8) < 0)
2359 dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
2362 if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
2363 if ((buflen -= 8) < 0)
2365 dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
2368 if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
2369 if ((buflen -= 8) < 0)
2371 dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
2374 if (bmval1 & FATTR4_WORD1_SPACE_USED) {
2375 if ((buflen -= 8) < 0)
2377 dummy64 = (u64)stat.blocks << 9;
2380 if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
2381 if ((buflen -= 12) < 0)
2383 WRITE64((s64)stat.atime.tv_sec);
2384 WRITE32(stat.atime.tv_nsec);
2386 if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
2387 if ((buflen -= 12) < 0)
2393 if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
2394 if ((buflen -= 12) < 0)
2396 WRITE64((s64)stat.ctime.tv_sec);
2397 WRITE32(stat.ctime.tv_nsec);
2399 if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
2400 if ((buflen -= 12) < 0)
2402 WRITE64((s64)stat.mtime.tv_sec);
2403 WRITE32(stat.mtime.tv_nsec);
2405 if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
2406 if ((buflen -= 8) < 0)
2409 * Get parent's attributes if not ignoring crossmount
2410 * and this is the root of a cross-mounted filesystem.
2412 if (ignore_crossmnt == 0 &&
2413 dentry == exp->ex_path.mnt->mnt_root)
2414 get_parent_attributes(exp, &stat);
2417 if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
2418 if ((buflen -= 16) < 0)
2421 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0);
2422 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1);
2423 WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2);
2426 *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
2436 status = nfserrno(err);
2439 status = nfserr_resource;
2442 status = nfserr_serverfault;
2446 static inline int attributes_need_mount(u32 *bmval)
2448 if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
2450 if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
2456 nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
2457 const char *name, int namlen, __be32 **p, int buflen)
2459 struct svc_export *exp = cd->rd_fhp->fh_export;
2460 struct dentry *dentry;
2462 int ignore_crossmnt = 0;
2464 dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
2466 return nfserrno(PTR_ERR(dentry));
2467 if (!dentry->d_inode) {
2469 * nfsd_buffered_readdir drops the i_mutex between
2470 * readdir and calling this callback, leaving a window
2471 * where this directory entry could have gone away.
2474 return nfserr_noent;
2479 * In the case of a mountpoint, the client may be asking for
2480 * attributes that are only properties of the underlying filesystem
2481 * as opposed to the cross-mounted file system. In such a case,
2482 * we will not follow the cross mount and will fill the attribtutes
2483 * directly from the mountpoint dentry.
2485 if (nfsd_mountpoint(dentry, exp)) {
2488 if (!(exp->ex_flags & NFSEXP_V4ROOT)
2489 && !attributes_need_mount(cd->rd_bmval)) {
2490 ignore_crossmnt = 1;
2494 * Why the heck aren't we just using nfsd_lookup??
2495 * Different "."/".." handling? Something else?
2496 * At least, add a comment here to explain....
2498 err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
2500 nfserr = nfserrno(err);
2503 nfserr = check_nfsd_access(exp, cd->rd_rqstp);
2509 nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
2510 cd->rd_rqstp, ignore_crossmnt);
2518 nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr)
2525 *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */
2526 *p++ = htonl(0); /* bmval1 */
2529 *p++ = nfserr; /* no htonl */
2530 *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
2535 nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
2536 loff_t offset, u64 ino, unsigned int d_type)
2538 struct readdir_cd *ccd = ccdv;
2539 struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
2541 __be32 *p = cd->buffer;
2543 __be32 nfserr = nfserr_toosmall;
2545 /* In nfsv4, "." and ".." never make it onto the wire.. */
2546 if (name && isdotent(name, namlen)) {
2547 cd->common.err = nfs_ok;
2552 xdr_encode_hyper(cd->offset, (u64) offset);
2554 buflen = cd->buflen - 4 - XDR_QUADLEN(namlen);
2558 *p++ = xdr_one; /* mark entry present */
2560 p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */
2561 p = xdr_encode_array(p, name, namlen); /* name length & name */
2563 nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, &p, buflen);
2567 case nfserr_resource:
2568 nfserr = nfserr_toosmall;
2574 * If the client requested the RDATTR_ERROR attribute,
2575 * we stuff the error code into this attribute
2576 * and continue. If this attribute was not requested,
2577 * then in accordance with the spec, we fail the
2578 * entire READDIR operation(!)
2580 if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
2582 p = nfsd4_encode_rdattr_error(p, buflen, nfserr);
2584 nfserr = nfserr_toosmall;
2588 cd->buflen -= (p - cd->buffer);
2590 cd->offset = cookiep;
2592 cd->common.err = nfs_ok;
2595 cd->common.err = nfserr;
2600 nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)
2604 RESERVE_SPACE(sizeof(stateid_t));
2605 WRITE32(sid->si_generation);
2606 WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
2611 nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
2617 WRITE32(access->ac_supported);
2618 WRITE32(access->ac_resp_access);
2624 static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts)
2629 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 8);
2630 WRITEMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
2632 /* Sorry, we do not yet support RDMA over 4.1: */
2640 nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close)
2643 nfsd4_encode_stateid(resp, &close->cl_stateid);
2650 nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit)
2655 RESERVE_SPACE(NFS4_VERIFIER_SIZE);
2656 WRITEMEM(commit->co_verf.data, NFS4_VERIFIER_SIZE);
2663 nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create)
2669 write_cinfo(&p, &create->cr_cinfo);
2671 WRITE32(create->cr_bmval[0]);
2672 WRITE32(create->cr_bmval[1]);
2679 nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr)
2681 struct svc_fh *fhp = getattr->ga_fhp;
2687 buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
2688 nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
2689 &resp->p, buflen, getattr->ga_bmval,
2695 nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp)
2697 struct svc_fh *fhp = *fhpp;
2702 len = fhp->fh_handle.fh_size;
2703 RESERVE_SPACE(len + 4);
2705 WRITEMEM(&fhp->fh_handle.fh_base, len);
2712 * Including all fields other than the name, a LOCK4denied structure requires
2713 * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
2716 nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld)
2718 struct xdr_netobj *conf = &ld->ld_owner;
2721 RESERVE_SPACE(32 + XDR_LEN(conf->len));
2722 WRITE64(ld->ld_start);
2723 WRITE64(ld->ld_length);
2724 WRITE32(ld->ld_type);
2726 WRITEMEM(&ld->ld_clientid, 8);
2728 WRITEMEM(conf->data, conf->len);
2730 } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
2731 WRITE64((u64)0); /* clientid */
2732 WRITE32(0); /* length of owner name */
2738 nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock)
2741 nfsd4_encode_stateid(resp, &lock->lk_resp_stateid);
2742 else if (nfserr == nfserr_denied)
2743 nfsd4_encode_lock_denied(resp, &lock->lk_denied);
2749 nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt)
2751 if (nfserr == nfserr_denied)
2752 nfsd4_encode_lock_denied(resp, &lockt->lt_denied);
2757 nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku)
2760 nfsd4_encode_stateid(resp, &locku->lu_stateid);
2767 nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link)
2773 write_cinfo(&p, &link->li_cinfo);
2781 nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
2788 nfsd4_encode_stateid(resp, &open->op_stateid);
2790 write_cinfo(&p, &open->op_cinfo);
2791 WRITE32(open->op_rflags);
2793 WRITE32(open->op_bmval[0]);
2794 WRITE32(open->op_bmval[1]);
2795 WRITE32(open->op_delegate_type);
2798 switch (open->op_delegate_type) {
2799 case NFS4_OPEN_DELEGATE_NONE:
2801 case NFS4_OPEN_DELEGATE_READ:
2802 nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
2804 WRITE32(open->op_recall);
2807 * TODO: ACE's in delegations
2809 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
2812 WRITE32(0); /* XXX: is NULL principal ok? */
2815 case NFS4_OPEN_DELEGATE_WRITE:
2816 nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
2821 * TODO: space_limit's in delegations
2823 WRITE32(NFS4_LIMIT_SIZE);
2828 * TODO: ACE's in delegations
2830 WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
2833 WRITE32(0); /* XXX: is NULL principal ok? */
2836 case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */
2837 switch (open->op_why_no_deleg) {
2838 case WND4_CONTENTION:
2841 WRITE32(open->op_why_no_deleg);
2842 WRITE32(0); /* deleg signaling not supported yet */
2846 WRITE32(open->op_why_no_deleg);
2853 /* XXX save filehandle here */
2859 nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
2862 nfsd4_encode_stateid(resp, &oc->oc_resp_stateid);
2868 nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
2871 nfsd4_encode_stateid(resp, &od->od_stateid);
2877 nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
2878 struct nfsd4_read *read)
2883 unsigned long maxcount;
2889 if (resp->xbuf->page_len)
2890 return nfserr_resource;
2892 RESERVE_SPACE(8); /* eof flag and byte count */
2894 maxcount = svc_max_payload(resp->rqstp);
2895 if (maxcount > read->rd_length)
2896 maxcount = read->rd_length;
2901 page = *(resp->rqstp->rq_next_page);
2902 if (!page) { /* ran out of pages */
2906 resp->rqstp->rq_vec[v].iov_base = page_address(page);
2907 resp->rqstp->rq_vec[v].iov_len =
2908 len < PAGE_SIZE ? len : PAGE_SIZE;
2909 resp->rqstp->rq_next_page++;
2915 nfserr = nfsd_read_file(read->rd_rqstp, read->rd_fhp, read->rd_filp,
2916 read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
2921 eof = (read->rd_offset + maxcount >=
2922 read->rd_fhp->fh_dentry->d_inode->i_size);
2927 resp->xbuf->head[0].iov_len = (char*)p
2928 - (char*)resp->xbuf->head[0].iov_base;
2929 resp->xbuf->page_len = maxcount;
2931 /* Use rest of head for padding and remaining ops: */
2932 resp->xbuf->tail[0].iov_base = p;
2933 resp->xbuf->tail[0].iov_len = 0;
2937 resp->xbuf->tail[0].iov_base += maxcount&3;
2938 resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
2945 nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink)
2953 if (resp->xbuf->page_len)
2954 return nfserr_resource;
2955 if (!*resp->rqstp->rq_next_page)
2956 return nfserr_resource;
2958 page = page_address(*(resp->rqstp->rq_next_page++));
2960 maxcount = PAGE_SIZE;
2964 * XXX: By default, the ->readlink() VFS op will truncate symlinks
2965 * if they would overflow the buffer. Is this kosher in NFSv4? If
2966 * not, one easy fix is: if ->readlink() precisely fills the buffer,
2967 * assume that truncation occurred, and return NFS4ERR_RESOURCE.
2969 nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);
2970 if (nfserr == nfserr_isdir)
2971 return nfserr_inval;
2977 resp->xbuf->head[0].iov_len = (char*)p
2978 - (char*)resp->xbuf->head[0].iov_base;
2979 resp->xbuf->page_len = maxcount;
2981 /* Use rest of head for padding and remaining ops: */
2982 resp->xbuf->tail[0].iov_base = p;
2983 resp->xbuf->tail[0].iov_len = 0;
2987 resp->xbuf->tail[0].iov_base += maxcount&3;
2988 resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
2995 nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir)
2999 __be32 *page, *savep, *tailbase;
3004 if (resp->xbuf->page_len)
3005 return nfserr_resource;
3006 if (!*resp->rqstp->rq_next_page)
3007 return nfserr_resource;
3009 RESERVE_SPACE(NFS4_VERIFIER_SIZE);
3012 /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
3016 resp->xbuf->head[0].iov_len = ((char*)resp->p) - (char*)resp->xbuf->head[0].iov_base;
3019 maxcount = PAGE_SIZE;
3020 if (maxcount > readdir->rd_maxcount)
3021 maxcount = readdir->rd_maxcount;
3024 * Convert from bytes to words, account for the two words already
3025 * written, make sure to leave two words at the end for the next
3026 * pointer and eof field.
3028 maxcount = (maxcount >> 2) - 4;
3030 nfserr = nfserr_toosmall;
3034 page = page_address(*(resp->rqstp->rq_next_page++));
3035 readdir->common.err = 0;
3036 readdir->buflen = maxcount;
3037 readdir->buffer = page;
3038 readdir->offset = NULL;
3040 offset = readdir->rd_cookie;
3041 nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp,
3043 &readdir->common, nfsd4_encode_dirent);
3044 if (nfserr == nfs_ok &&
3045 readdir->common.err == nfserr_toosmall &&
3046 readdir->buffer == page)
3047 nfserr = nfserr_toosmall;
3051 if (readdir->offset)
3052 xdr_encode_hyper(readdir->offset, offset);
3054 p = readdir->buffer;
3055 *p++ = 0; /* no more entries */
3056 *p++ = htonl(readdir->common.err == nfserr_eof);
3057 resp->xbuf->page_len = ((char*)p) -
3058 (char*)page_address(*(resp->rqstp->rq_next_page-1));
3060 /* Use rest of head for padding and remaining ops: */
3061 resp->xbuf->tail[0].iov_base = tailbase;
3062 resp->xbuf->tail[0].iov_len = 0;
3063 resp->p = resp->xbuf->tail[0].iov_base;
3064 resp->end = resp->p + (PAGE_SIZE - resp->xbuf->head[0].iov_len)/4;
3074 nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove)
3080 write_cinfo(&p, &remove->rm_cinfo);
3087 nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename)
3093 write_cinfo(&p, &rename->rn_sinfo);
3094 write_cinfo(&p, &rename->rn_tinfo);
3101 nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp,
3102 __be32 nfserr, struct svc_export *exp)
3104 u32 i, nflavs, supported;
3105 struct exp_flavor_info *flavs;
3106 struct exp_flavor_info def_flavs[2];
3107 __be32 *p, *flavorsp;
3108 static bool report = true;
3112 if (exp->ex_nflavors) {
3113 flavs = exp->ex_flavors;
3114 nflavs = exp->ex_nflavors;
3115 } else { /* Handling of some defaults in absence of real secinfo: */
3117 if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
3119 flavs[0].pseudoflavor = RPC_AUTH_UNIX;
3120 flavs[1].pseudoflavor = RPC_AUTH_NULL;
3121 } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
3123 flavs[0].pseudoflavor
3124 = svcauth_gss_flavor(exp->ex_client);
3127 flavs[0].pseudoflavor
3128 = exp->ex_client->flavour->flavour;
3134 flavorsp = p++; /* to be backfilled later */
3137 for (i = 0; i < nflavs; i++) {
3138 rpc_authflavor_t pf = flavs[i].pseudoflavor;
3139 struct rpcsec_gss_info info;
3141 if (rpcauth_get_gssinfo(pf, &info) == 0) {
3143 RESERVE_SPACE(4 + 4 + info.oid.len + 4 + 4);
3144 WRITE32(RPC_AUTH_GSS);
3145 WRITE32(info.oid.len);
3146 WRITEMEM(info.oid.data, info.oid.len);
3148 WRITE32(info.service);
3150 } else if (pf < RPC_AUTH_MAXFLAVOR) {
3157 pr_warn("NFS: SECINFO: security flavor %u "
3158 "is not supported\n", pf);
3162 if (nflavs != supported)
3164 *flavorsp = htonl(supported);
3173 nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
3174 struct nfsd4_secinfo *secinfo)
3176 return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->si_exp);
3180 nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr,
3181 struct nfsd4_secinfo_no_name *secinfo)
3183 return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->sin_exp);
3187 * The SETATTR encode routine is special -- it always encodes a bitmap,
3188 * regardless of the error status.
3191 nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr)
3203 WRITE32(setattr->sa_bmval[0]);
3204 WRITE32(setattr->sa_bmval[1]);
3211 nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd)
3216 RESERVE_SPACE(8 + NFS4_VERIFIER_SIZE);
3217 WRITEMEM(&scd->se_clientid, 8);
3218 WRITEMEM(&scd->se_confirm, NFS4_VERIFIER_SIZE);
3221 else if (nfserr == nfserr_clid_inuse) {
3231 nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write)
3237 WRITE32(write->wr_bytes_written);
3238 WRITE32(write->wr_how_written);
3239 WRITEMEM(write->wr_verifier.data, NFS4_VERIFIER_SIZE);
3246 nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
3247 struct nfsd4_exchange_id *exid)
3253 int server_scope_sz;
3254 uint64_t minor_id = 0;
3259 major_id = utsname()->nodename;
3260 major_id_sz = strlen(major_id);
3261 server_scope = utsname()->nodename;
3262 server_scope_sz = strlen(server_scope);
3265 8 /* eir_clientid */ +
3266 4 /* eir_sequenceid */ +
3268 4 /* spr_how (SP4_NONE) */ +
3269 8 /* so_minor_id */ +
3270 4 /* so_major_id.len */ +
3271 (XDR_QUADLEN(major_id_sz) * 4) +
3272 4 /* eir_server_scope.len */ +
3273 (XDR_QUADLEN(server_scope_sz) * 4) +
3274 4 /* eir_server_impl_id.count (0) */);
3276 WRITEMEM(&exid->clientid, 8);
3277 WRITE32(exid->seqid);
3278 WRITE32(exid->flags);
3280 /* state_protect4_r. Currently only support SP4_NONE */
3281 BUG_ON(exid->spa_how != SP4_NONE);
3282 WRITE32(exid->spa_how);
3284 /* The server_owner struct */
3285 WRITE64(minor_id); /* Minor id */
3287 WRITE32(major_id_sz);
3288 WRITEMEM(major_id, major_id_sz);
3291 WRITE32(server_scope_sz);
3292 WRITEMEM(server_scope, server_scope_sz);
3294 /* Implementation id */
3295 WRITE32(0); /* zero length nfs_impl_id4 array */
3301 nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,
3302 struct nfsd4_create_session *sess)
3310 WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN);
3311 WRITE32(sess->seqid);
3312 WRITE32(sess->flags);
3316 WRITE32(0); /* headerpadsz */
3317 WRITE32(sess->fore_channel.maxreq_sz);
3318 WRITE32(sess->fore_channel.maxresp_sz);
3319 WRITE32(sess->fore_channel.maxresp_cached);
3320 WRITE32(sess->fore_channel.maxops);
3321 WRITE32(sess->fore_channel.maxreqs);
3322 WRITE32(sess->fore_channel.nr_rdma_attrs);
3325 if (sess->fore_channel.nr_rdma_attrs) {
3327 WRITE32(sess->fore_channel.rdma_attrs);
3332 WRITE32(0); /* headerpadsz */
3333 WRITE32(sess->back_channel.maxreq_sz);
3334 WRITE32(sess->back_channel.maxresp_sz);
3335 WRITE32(sess->back_channel.maxresp_cached);
3336 WRITE32(sess->back_channel.maxops);
3337 WRITE32(sess->back_channel.maxreqs);
3338 WRITE32(sess->back_channel.nr_rdma_attrs);
3341 if (sess->back_channel.nr_rdma_attrs) {
3343 WRITE32(sess->back_channel.rdma_attrs);
3350 nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, __be32 nfserr,
3351 struct nfsd4_destroy_session *destroy_session)
3357 nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
3358 struct nfsd4_free_stateid *free_stateid)
3372 nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
3373 struct nfsd4_sequence *seq)
3380 RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20);
3381 WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
3382 WRITE32(seq->seqid);
3383 WRITE32(seq->slotid);
3384 /* Note slotid's are numbered from zero: */
3385 WRITE32(seq->maxslots - 1); /* sr_highest_slotid */
3386 WRITE32(seq->maxslots - 1); /* sr_target_highest_slotid */
3387 WRITE32(seq->status_flags);
3390 resp->cstate.datap = p; /* DRC cache data pointer */
3395 nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
3396 struct nfsd4_test_stateid *test_stateid)
3398 struct nfsd4_test_stateid_id *stateid, *next;
3404 RESERVE_SPACE(4 + (4 * test_stateid->ts_num_ids));
3405 *p++ = htonl(test_stateid->ts_num_ids);
3407 list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
3408 *p++ = stateid->ts_id_status;
3416 nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p)
3421 typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *);
3424 * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
3425 * since we don't need to filter out obsolete ops as this is
3426 * done in the decoding phase.
3428 static nfsd4_enc nfsd4_enc_ops[] = {
3429 [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access,
3430 [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close,
3431 [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit,
3432 [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create,
3433 [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop,
3434 [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop,
3435 [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr,
3436 [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh,
3437 [OP_LINK] = (nfsd4_enc)nfsd4_encode_link,
3438 [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock,
3439 [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt,
3440 [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku,
3441 [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop,
3442 [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop,
3443 [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop,
3444 [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open,
3445 [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop,
3446 [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm,
3447 [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade,
3448 [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop,
3449 [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop,
3450 [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop,
3451 [OP_READ] = (nfsd4_enc)nfsd4_encode_read,
3452 [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir,
3453 [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink,
3454 [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove,
3455 [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename,
3456 [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop,
3457 [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop,
3458 [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop,
3459 [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo,
3460 [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr,
3461 [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid,
3462 [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop,
3463 [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop,
3464 [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write,
3465 [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop,
3467 /* NFSv4.1 operations */
3468 [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop,
3469 [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session,
3470 [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id,
3471 [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session,
3472 [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session,
3473 [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_free_stateid,
3474 [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
3475 [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop,
3476 [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
3477 [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop,
3478 [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop,
3479 [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop,
3480 [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name,
3481 [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence,
3482 [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop,
3483 [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid,
3484 [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
3485 [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop,
3486 [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop,
3490 * Calculate the total amount of memory that the compound response has taken
3491 * after encoding the current operation with pad.
3493 * pad: if operation is non-idempotent, pad was calculate by op_rsize_bop()
3494 * which was specified at nfsd4_operation, else pad is zero.
3496 * Compare this length to the session se_fmaxresp_sz and se_fmaxresp_cached.
3498 * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
3499 * will be at least a page and will therefore hold the xdr_buf head.
3501 __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)
3503 struct xdr_buf *xb = &resp->rqstp->rq_res;
3504 struct nfsd4_session *session = NULL;
3505 struct nfsd4_slot *slot = resp->cstate.slot;
3506 u32 length, tlen = 0;
3508 if (!nfsd4_has_session(&resp->cstate))
3511 session = resp->cstate.session;
3512 if (session == NULL)
3515 if (xb->page_len == 0) {
3516 length = (char *)resp->p - (char *)xb->head[0].iov_base + pad;
3518 if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0)
3519 tlen = (char *)resp->p - (char *)xb->tail[0].iov_base;
3521 length = xb->head[0].iov_len + xb->page_len + tlen + pad;
3523 dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__,
3524 length, xb->page_len, tlen, pad);
3526 if (length > session->se_fchannel.maxresp_sz)
3527 return nfserr_rep_too_big;
3529 if ((slot->sl_flags & NFSD4_SLOT_CACHETHIS) &&
3530 length > session->se_fchannel.maxresp_cached)
3531 return nfserr_rep_too_big_to_cache;
3537 nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
3539 struct nfs4_stateowner *so = resp->cstate.replay_owner;
3545 statp = p++; /* to be backfilled at the end */
3548 if (op->opnum == OP_ILLEGAL)
3550 BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) ||
3551 !nfsd4_enc_ops[op->opnum]);
3552 op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u);
3553 /* nfsd4_check_drc_limit guarantees enough room for error status */
3555 op->status = nfsd4_check_resp_size(resp, 0);
3557 so->so_replay.rp_status = op->status;
3558 so->so_replay.rp_buflen = (char *)resp->p - (char *)(statp+1);
3559 memcpy(so->so_replay.rp_buf, statp+1, so->so_replay.rp_buflen);
3563 * Note: We write the status directly, instead of using WRITE32(),
3564 * since it is already in network byte order.
3566 *statp = op->status;
3570 * Encode the reply stored in the stateowner reply cache
3572 * XDR note: do not encode rp->rp_buflen: the buffer contains the
3573 * previously sent already encoded operation.
3575 * called with nfs4_lock_state() held
3578 nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
3581 struct nfs4_replay *rp = op->replay;
3587 *p++ = rp->rp_status; /* already xdr'ed */
3590 RESERVE_SPACE(rp->rp_buflen);
3591 WRITEMEM(rp->rp_buf, rp->rp_buflen);
3596 nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
3598 return xdr_ressize_check(rqstp, p);
3601 int nfsd4_release_compoundargs(void *rq, __be32 *p, void *resp)
3603 struct svc_rqst *rqstp = rq;
3604 struct nfsd4_compoundargs *args = rqstp->rq_argp;
3606 if (args->ops != args->iops) {
3608 args->ops = args->iops;
3612 while (args->to_free) {
3613 struct tmpbuf *tb = args->to_free;
3614 args->to_free = tb->next;
3615 tb->release(tb->buf);
3622 nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundargs *args)
3625 args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len;
3626 args->pagelist = rqstp->rq_arg.pages;
3627 args->pagelen = rqstp->rq_arg.page_len;
3629 args->to_free = NULL;
3630 args->ops = args->iops;
3631 args->rqstp = rqstp;
3633 return !nfsd4_decode_compound(args);
3637 nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundres *resp)
3640 * All that remains is to write the tag and operation count...
3642 struct nfsd4_compound_state *cs = &resp->cstate;
3645 *p++ = htonl(resp->taglen);
3646 memcpy(p, resp->tag, resp->taglen);
3647 p += XDR_QUADLEN(resp->taglen);
3648 *p++ = htonl(resp->opcnt);
3650 if (rqstp->rq_res.page_len)
3651 iov = &rqstp->rq_res.tail[0];
3653 iov = &rqstp->rq_res.head[0];
3654 iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
3655 BUG_ON(iov->iov_len > PAGE_SIZE);
3656 if (nfsd4_has_session(cs)) {
3657 if (cs->status != nfserr_replay_cache) {
3658 nfsd4_store_cache_entry(resp);
3659 cs->slot->sl_flags &= ~NFSD4_SLOT_INUSE;
3661 /* Renew the clientid on success and on replay */
3662 put_client_renew(cs->session->se_client);
3663 nfsd4_put_session(cs->session);