11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * fs/nfs/nfs4xdr.c
31da177e4SLinus Torvalds *
41da177e4SLinus Torvalds * Client-side XDR for NFSv4.
51da177e4SLinus Torvalds *
61da177e4SLinus Torvalds * Copyright (c) 2002 The Regents of the University of Michigan.
71da177e4SLinus Torvalds * All rights reserved.
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds * Kendrick Smith <kmsmith@umich.edu>
101da177e4SLinus Torvalds * Andy Adamson <andros@umich.edu>
111da177e4SLinus Torvalds *
121da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or without
131da177e4SLinus Torvalds * modification, are permitted provided that the following conditions
141da177e4SLinus Torvalds * are met:
151da177e4SLinus Torvalds *
161da177e4SLinus Torvalds * 1. Redistributions of source code must retain the above copyright
171da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer.
181da177e4SLinus Torvalds * 2. Redistributions in binary form must reproduce the above copyright
191da177e4SLinus Torvalds * notice, this list of conditions and the following disclaimer in the
201da177e4SLinus Torvalds * documentation and/or other materials provided with the distribution.
211da177e4SLinus Torvalds * 3. Neither the name of the University nor the names of its
221da177e4SLinus Torvalds * contributors may be used to endorse or promote products derived
231da177e4SLinus Torvalds * from this software without specific prior written permission.
241da177e4SLinus Torvalds *
251da177e4SLinus Torvalds * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
261da177e4SLinus Torvalds * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
271da177e4SLinus Torvalds * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
281da177e4SLinus Torvalds * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
291da177e4SLinus Torvalds * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
301da177e4SLinus Torvalds * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
311da177e4SLinus Torvalds * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
321da177e4SLinus Torvalds * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
331da177e4SLinus Torvalds * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
341da177e4SLinus Torvalds * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
351da177e4SLinus Torvalds * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
361da177e4SLinus Torvalds */
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds #include <linux/param.h>
391da177e4SLinus Torvalds #include <linux/time.h>
401da177e4SLinus Torvalds #include <linux/mm.h>
411da177e4SLinus Torvalds #include <linux/errno.h>
421da177e4SLinus Torvalds #include <linux/string.h>
431da177e4SLinus Torvalds #include <linux/in.h>
441da177e4SLinus Torvalds #include <linux/pagemap.h>
451da177e4SLinus Torvalds #include <linux/proc_fs.h>
461da177e4SLinus Torvalds #include <linux/kdev_t.h>
47db8ac8baSWeston Andros Adamson #include <linux/module.h>
48db8ac8baSWeston Andros Adamson #include <linux/utsname.h>
491da177e4SLinus Torvalds #include <linux/sunrpc/clnt.h>
502449ea2eSAlexandros Batsakis #include <linux/sunrpc/msg_prot.h>
515a5ea0d4SBryan Schumaker #include <linux/sunrpc/gss_api.h>
521da177e4SLinus Torvalds #include <linux/nfs.h>
531da177e4SLinus Torvalds #include <linux/nfs4.h>
541da177e4SLinus Torvalds #include <linux/nfs_fs.h>
55f092075dSChuck Lever
564ce79717STrond Myklebust #include "nfs4_fs.h"
57f23f6584SChuck Lever #include "nfs4trace.h"
584882ef72SAlexandros Batsakis #include "internal.h"
5940c64c26SAnna Schumaker #include "nfs4idmap.h"
6076e697baSTrond Myklebust #include "nfs4session.h"
61b1f69b75SAndy Adamson #include "pnfs.h"
62f092075dSChuck Lever #include "netns.h"
631da177e4SLinus Torvalds
641da177e4SLinus Torvalds #define NFSDBG_FACILITY NFSDBG_XDR
651da177e4SLinus Torvalds
661da177e4SLinus Torvalds /* Mapping from NFS error code to "errno" error code. */
671da177e4SLinus Torvalds #define errno_NFSERR_IO EIO
681da177e4SLinus Torvalds
6956f487f8SFred Isaman struct compound_hdr;
700a8ea437SDavid Howells static int nfs4_stat_to_errno(int);
7156f487f8SFred Isaman static void encode_layoutget(struct xdr_stream *xdr,
7256f487f8SFred Isaman const struct nfs4_layoutget_args *args,
7356f487f8SFred Isaman struct compound_hdr *hdr);
7456f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
7556f487f8SFred Isaman struct nfs4_layoutget_res *res);
761da177e4SLinus Torvalds
771da177e4SLinus Torvalds /* NFSv4 COMPOUND tags are only wanted for debugging purposes */
781da177e4SLinus Torvalds #ifdef DEBUG
791da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 20
801da177e4SLinus Torvalds #else
811da177e4SLinus Torvalds #define NFS4_MAXTAGLEN 0
821da177e4SLinus Torvalds #endif
831da177e4SLinus Torvalds
841da177e4SLinus Torvalds /* lock,open owner id:
859f958ab8STrond Myklebust * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
861da177e4SLinus Torvalds */
879ed5af26STrond Myklebust #define pagepad_maxsz (1)
8895b72eb0STrond Myklebust #define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
89d035c36cSTrond Myklebust #define lock_owner_id_maxsz (1 + 1 + 4)
909104a55dSTrond Myklebust #define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
911da177e4SLinus Torvalds #define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
921da177e4SLinus Torvalds #define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
931da177e4SLinus Torvalds #define op_encode_hdr_maxsz (1)
941da177e4SLinus Torvalds #define op_decode_hdr_maxsz (2)
959104a55dSTrond Myklebust #define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
969104a55dSTrond Myklebust #define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
979104a55dSTrond Myklebust #define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
989104a55dSTrond Myklebust #define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
991da177e4SLinus Torvalds #define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
1001da177e4SLinus Torvalds (NFS4_FHSIZE >> 2))
1011da177e4SLinus Torvalds #define decode_putfh_maxsz (op_decode_hdr_maxsz)
1021da177e4SLinus Torvalds #define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
1031da177e4SLinus Torvalds #define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
1041da177e4SLinus Torvalds #define encode_getfh_maxsz (op_encode_hdr_maxsz)
1051da177e4SLinus Torvalds #define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
1061da177e4SLinus Torvalds ((3+NFS4_FHSIZE) >> 2))
107e5012d1fSAndy Adamson #define nfs4_fattr_bitmap_maxsz 4
10896928206SJ. Bruce Fields #define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
10936b3743fSTrond Myklebust #define nfstime4_maxsz (3)
1101da177e4SLinus Torvalds #define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
1111da177e4SLinus Torvalds #define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
112bd625ba8STrond Myklebust #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
113bd625ba8STrond Myklebust #define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
114aa9c2669SDavid Quigley #ifdef CONFIG_NFS_V4_SECURITY_LABEL
115aa9c2669SDavid Quigley /* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
116aa9c2669SDavid Quigley #define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
117aa9c2669SDavid Quigley #else
118aa9c2669SDavid Quigley #define nfs4_label_maxsz 0
119aa9c2669SDavid Quigley #endif
12088034c3dSAndy Adamson /* We support only one layout type per file system */
12188034c3dSAndy Adamson #define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
12296928206SJ. Bruce Fields /* This is based on getfattr, which uses the most attributes: */
12396928206SJ. Bruce Fields #define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
12436b3743fSTrond Myklebust 3*nfstime4_maxsz + \
12536b3743fSTrond Myklebust nfs4_owner_maxsz + \
126aa9c2669SDavid Quigley nfs4_group_maxsz + nfs4_label_maxsz + \
127aa9c2669SDavid Quigley decode_mdsthreshold_maxsz))
12896928206SJ. Bruce Fields #define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
12996928206SJ. Bruce Fields nfs4_fattr_value_maxsz)
13096928206SJ. Bruce Fields #define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
1319104a55dSTrond Myklebust #define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
1329104a55dSTrond Myklebust 1 + 2 + 1 + \
1339104a55dSTrond Myklebust nfs4_owner_maxsz + \
1349104a55dSTrond Myklebust nfs4_group_maxsz + \
135aa9c2669SDavid Quigley nfs4_label_maxsz + \
13636b3743fSTrond Myklebust 1 + nfstime4_maxsz + \
13736b3743fSTrond Myklebust 1 + nfstime4_maxsz)
1381da177e4SLinus Torvalds #define encode_savefh_maxsz (op_encode_hdr_maxsz)
1391da177e4SLinus Torvalds #define decode_savefh_maxsz (op_decode_hdr_maxsz)
14056ae19f3STrond Myklebust #define encode_restorefh_maxsz (op_encode_hdr_maxsz)
14156ae19f3STrond Myklebust #define decode_restorefh_maxsz (op_decode_hdr_maxsz)
1422f42b5d0SFred Isaman #define encode_fsinfo_maxsz (encode_getattr_maxsz)
143dae100c2SFred Isaman /* The 5 accounts for the PNFS attributes, and assumes that at most three
144dae100c2SFred Isaman * layout types will be returned.
145dae100c2SFred Isaman */
146dae100c2SFred Isaman #define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
14757a789a1STrond Myklebust nfs4_fattr_bitmap_maxsz + 1 + \
14857a789a1STrond Myklebust 1 /* lease time */ + \
14957a789a1STrond Myklebust 2 /* max filesize */ + \
15057a789a1STrond Myklebust 2 /* max read */ + \
15157a789a1STrond Myklebust 2 /* max write */ + \
15257a789a1STrond Myklebust nfstime4_maxsz /* time delta */ + \
15357a789a1STrond Myklebust 5 /* fs layout types */ + \
15457a789a1STrond Myklebust 1 /* layout blksize */ + \
15557a789a1STrond Myklebust 1 /* clone blksize */ + \
1567f08a335STrond Myklebust 1 /* change attr type */ + \
15757a789a1STrond Myklebust 1 /* xattr support */)
1581da177e4SLinus Torvalds #define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
1591da177e4SLinus Torvalds #define decode_renew_maxsz (op_decode_hdr_maxsz)
1601da177e4SLinus Torvalds #define encode_setclientid_maxsz \
1611da177e4SLinus Torvalds (op_encode_hdr_maxsz + \
162cc38bac3SChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
163b8fb2f59SJeff Layton /* client name */ \
164b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
165cc38bac3SChuck Lever 1 /* sc_prog */ + \
1666dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1676dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
168cc38bac3SChuck Lever 1) /* sc_cb_ident */
1691da177e4SLinus Torvalds #define decode_setclientid_maxsz \
1701da177e4SLinus Torvalds (op_decode_hdr_maxsz + \
1716dd3436bSChuck Lever 2 /* clientid */ + \
1726dd3436bSChuck Lever XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
1736dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
1746dd3436bSChuck Lever 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
1751da177e4SLinus Torvalds #define encode_setclientid_confirm_maxsz \
1761da177e4SLinus Torvalds (op_encode_hdr_maxsz + \
1771da177e4SLinus Torvalds 3 + (NFS4_VERIFIER_SIZE >> 2))
1781da177e4SLinus Torvalds #define decode_setclientid_confirm_maxsz \
1791da177e4SLinus Torvalds (op_decode_hdr_maxsz)
180e6889620STrond Myklebust #define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
181e6889620STrond Myklebust #define decode_lookup_maxsz (op_decode_hdr_maxsz)
1825b5faaf6SJeff Layton #define encode_lookupp_maxsz (op_encode_hdr_maxsz)
1835b5faaf6SJeff Layton #define decode_lookupp_maxsz (op_decode_hdr_maxsz)
1842cebf828STrond Myklebust #define encode_share_access_maxsz \
1852cebf828STrond Myklebust (2)
1864882ef72SAlexandros Batsakis #define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
1872cebf828STrond Myklebust #define encode_opentype_maxsz (1 + encode_createmode_maxsz)
1882cebf828STrond Myklebust #define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
1892cebf828STrond Myklebust #define encode_open_maxsz (op_encode_hdr_maxsz + \
1902cebf828STrond Myklebust 2 + encode_share_access_maxsz + 2 + \
1912cebf828STrond Myklebust open_owner_id_maxsz + \
1922cebf828STrond Myklebust encode_opentype_maxsz + \
1932cebf828STrond Myklebust encode_claim_null_maxsz)
1945a1f6d9eSTrond Myklebust #define decode_space_limit_maxsz (3)
1952cebf828STrond Myklebust #define decode_ace_maxsz (3 + nfs4_owner_maxsz)
1969104a55dSTrond Myklebust #define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
1975a1f6d9eSTrond Myklebust decode_space_limit_maxsz + \
1982cebf828STrond Myklebust decode_ace_maxsz)
1992cebf828STrond Myklebust #define decode_change_info_maxsz (5)
2002cebf828STrond Myklebust #define decode_open_maxsz (op_decode_hdr_maxsz + \
2019104a55dSTrond Myklebust decode_stateid_maxsz + \
2022cebf828STrond Myklebust decode_change_info_maxsz + 1 + \
2032cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz + \
2042cebf828STrond Myklebust decode_delegation_maxsz)
2059104a55dSTrond Myklebust #define encode_open_confirm_maxsz \
2069104a55dSTrond Myklebust (op_encode_hdr_maxsz + \
2079104a55dSTrond Myklebust encode_stateid_maxsz + 1)
2089104a55dSTrond Myklebust #define decode_open_confirm_maxsz \
2099104a55dSTrond Myklebust (op_decode_hdr_maxsz + \
2109104a55dSTrond Myklebust decode_stateid_maxsz)
2119104a55dSTrond Myklebust #define encode_open_downgrade_maxsz \
2129104a55dSTrond Myklebust (op_encode_hdr_maxsz + \
2139104a55dSTrond Myklebust encode_stateid_maxsz + 1 + \
2149104a55dSTrond Myklebust encode_share_access_maxsz)
2159104a55dSTrond Myklebust #define decode_open_downgrade_maxsz \
2169104a55dSTrond Myklebust (op_decode_hdr_maxsz + \
2179104a55dSTrond Myklebust decode_stateid_maxsz)
2189104a55dSTrond Myklebust #define encode_close_maxsz (op_encode_hdr_maxsz + \
2199104a55dSTrond Myklebust 1 + encode_stateid_maxsz)
2209104a55dSTrond Myklebust #define decode_close_maxsz (op_decode_hdr_maxsz + \
2219104a55dSTrond Myklebust decode_stateid_maxsz)
2229104a55dSTrond Myklebust #define encode_setattr_maxsz (op_encode_hdr_maxsz + \
2239104a55dSTrond Myklebust encode_stateid_maxsz + \
2249104a55dSTrond Myklebust encode_attrs_maxsz)
2259104a55dSTrond Myklebust #define decode_setattr_maxsz (op_decode_hdr_maxsz + \
2269104a55dSTrond Myklebust nfs4_fattr_bitmap_maxsz)
2279104a55dSTrond Myklebust #define encode_read_maxsz (op_encode_hdr_maxsz + \
2289104a55dSTrond Myklebust encode_stateid_maxsz + 3)
2299ed5af26STrond Myklebust #define decode_read_maxsz (op_decode_hdr_maxsz + 2 + pagepad_maxsz)
2309104a55dSTrond Myklebust #define encode_readdir_maxsz (op_encode_hdr_maxsz + \
231aa9c2669SDavid Quigley 2 + encode_verifier_maxsz + 5 + \
232aa9c2669SDavid Quigley nfs4_label_maxsz)
2339104a55dSTrond Myklebust #define decode_readdir_maxsz (op_decode_hdr_maxsz + \
2349ed5af26STrond Myklebust decode_verifier_maxsz + pagepad_maxsz)
2359104a55dSTrond Myklebust #define encode_readlink_maxsz (op_encode_hdr_maxsz)
2369ed5af26STrond Myklebust #define decode_readlink_maxsz (op_decode_hdr_maxsz + 1 + pagepad_maxsz)
2379104a55dSTrond Myklebust #define encode_write_maxsz (op_encode_hdr_maxsz + \
2389104a55dSTrond Myklebust encode_stateid_maxsz + 4)
2399104a55dSTrond Myklebust #define decode_write_maxsz (op_decode_hdr_maxsz + \
2409104a55dSTrond Myklebust 2 + decode_verifier_maxsz)
2419104a55dSTrond Myklebust #define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
2429104a55dSTrond Myklebust #define decode_commit_maxsz (op_decode_hdr_maxsz + \
2439104a55dSTrond Myklebust decode_verifier_maxsz)
2441da177e4SLinus Torvalds #define encode_remove_maxsz (op_encode_hdr_maxsz + \
2451da177e4SLinus Torvalds nfs4_name_maxsz)
2466ce18391SBenny Halevy #define decode_remove_maxsz (op_decode_hdr_maxsz + \
2476ce18391SBenny Halevy decode_change_info_maxsz)
2481da177e4SLinus Torvalds #define encode_rename_maxsz (op_encode_hdr_maxsz + \
2491da177e4SLinus Torvalds 2 * nfs4_name_maxsz)
2506ce18391SBenny Halevy #define decode_rename_maxsz (op_decode_hdr_maxsz + \
2516ce18391SBenny Halevy decode_change_info_maxsz + \
2526ce18391SBenny Halevy decode_change_info_maxsz)
2531da177e4SLinus Torvalds #define encode_link_maxsz (op_encode_hdr_maxsz + \
2541da177e4SLinus Torvalds nfs4_name_maxsz)
2556ce18391SBenny Halevy #define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
256daccbdedSTrond Myklebust #define encode_lockowner_maxsz (7)
2579104a55dSTrond Myklebust #define encode_lock_maxsz (op_encode_hdr_maxsz + \
2589104a55dSTrond Myklebust 7 + \
259daccbdedSTrond Myklebust 1 + encode_stateid_maxsz + 1 + \
260daccbdedSTrond Myklebust encode_lockowner_maxsz)
2619104a55dSTrond Myklebust #define decode_lock_denied_maxsz \
2629104a55dSTrond Myklebust (8 + decode_lockowner_maxsz)
2639104a55dSTrond Myklebust #define decode_lock_maxsz (op_decode_hdr_maxsz + \
2649104a55dSTrond Myklebust decode_lock_denied_maxsz)
265daccbdedSTrond Myklebust #define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
266daccbdedSTrond Myklebust encode_lockowner_maxsz)
2679104a55dSTrond Myklebust #define decode_lockt_maxsz (op_decode_hdr_maxsz + \
2689104a55dSTrond Myklebust decode_lock_denied_maxsz)
2699104a55dSTrond Myklebust #define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
2709104a55dSTrond Myklebust encode_stateid_maxsz + \
2719104a55dSTrond Myklebust 4)
2729104a55dSTrond Myklebust #define decode_locku_maxsz (op_decode_hdr_maxsz + \
2739104a55dSTrond Myklebust decode_stateid_maxsz)
274d3c7b7ccSTrond Myklebust #define encode_release_lockowner_maxsz \
275d3c7b7ccSTrond Myklebust (op_encode_hdr_maxsz + \
276d3c7b7ccSTrond Myklebust encode_lockowner_maxsz)
277d3c7b7ccSTrond Myklebust #define decode_release_lockowner_maxsz \
278d3c7b7ccSTrond Myklebust (op_decode_hdr_maxsz)
2799104a55dSTrond Myklebust #define encode_access_maxsz (op_encode_hdr_maxsz + 1)
2809104a55dSTrond Myklebust #define decode_access_maxsz (op_decode_hdr_maxsz + 2)
2811da177e4SLinus Torvalds #define encode_symlink_maxsz (op_encode_hdr_maxsz + \
2821da177e4SLinus Torvalds 1 + nfs4_name_maxsz + \
28394a6d753SChuck Lever 1 + \
28496928206SJ. Bruce Fields nfs4_fattr_maxsz)
2851da177e4SLinus Torvalds #define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
2861da177e4SLinus Torvalds #define encode_create_maxsz (op_encode_hdr_maxsz + \
2879104a55dSTrond Myklebust 1 + 2 + nfs4_name_maxsz + \
2889104a55dSTrond Myklebust encode_attrs_maxsz)
2892cebf828STrond Myklebust #define decode_create_maxsz (op_decode_hdr_maxsz + \
2902cebf828STrond Myklebust decode_change_info_maxsz + \
2912cebf828STrond Myklebust nfs4_fattr_bitmap_maxsz)
2929104a55dSTrond Myklebust #define encode_statfs_maxsz (encode_getattr_maxsz)
2939104a55dSTrond Myklebust #define decode_statfs_maxsz (decode_getattr_maxsz)
2941da177e4SLinus Torvalds #define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
2951da177e4SLinus Torvalds #define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
2969104a55dSTrond Myklebust #define encode_getacl_maxsz (encode_getattr_maxsz)
2979104a55dSTrond Myklebust #define decode_getacl_maxsz (op_decode_hdr_maxsz + \
2989ed5af26STrond Myklebust nfs4_fattr_bitmap_maxsz + 1 + pagepad_maxsz)
2999104a55dSTrond Myklebust #define encode_setacl_maxsz (op_encode_hdr_maxsz + \
3009104a55dSTrond Myklebust encode_stateid_maxsz + 3)
3019104a55dSTrond Myklebust #define decode_setacl_maxsz (decode_setattr_maxsz)
302e6889620STrond Myklebust #define encode_fs_locations_maxsz \
303e6889620STrond Myklebust (encode_getattr_maxsz)
304e6889620STrond Myklebust #define decode_fs_locations_maxsz \
3059ed5af26STrond Myklebust (pagepad_maxsz)
3065a5ea0d4SBryan Schumaker #define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
3071650add2SBryan Schumaker #define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
3089b7b9fccSAndy Adamson
3099b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
310fc931582SAndy Adamson #define NFS4_MAX_MACHINE_NAME_LEN (64)
311d751f748SJim Rees #define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
312d751f748SJim Rees sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
313fc931582SAndy Adamson
31499fe60d0SBenny Halevy #define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
31599fe60d0SBenny Halevy encode_verifier_maxsz + \
31699fe60d0SBenny Halevy 1 /* co_ownerid.len */ + \
317b8fb2f59SJeff Layton /* eia_clientowner */ \
318b8fb2f59SJeff Layton 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
31999fe60d0SBenny Halevy 1 /* flags */ + \
32099fe60d0SBenny Halevy 1 /* spa_how */ + \
3212031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \
3222031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \
3232031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \
324db8ac8baSWeston Andros Adamson 1 /* implementation id array of size 1 */ + \
325db8ac8baSWeston Andros Adamson 1 /* nii_domain */ + \
326db8ac8baSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
327db8ac8baSWeston Andros Adamson 1 /* nii_name */ + \
328d751f748SJim Rees XDR_QUADLEN(IMPL_NAME_LIMIT) + \
329db8ac8baSWeston Andros Adamson 3 /* nii_date */)
33099fe60d0SBenny Halevy #define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
33199fe60d0SBenny Halevy 2 /* eir_clientid */ + \
33299fe60d0SBenny Halevy 1 /* eir_sequenceid */ + \
33399fe60d0SBenny Halevy 1 /* eir_flags */ + \
33499fe60d0SBenny Halevy 1 /* spr_how */ + \
3352031cd1aSWeston Andros Adamson /* max is SP4_MACH_CRED (for now) */ + \
3362031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \
3372031cd1aSWeston Andros Adamson 1 + NFS4_OP_MAP_NUM_WORDS + \
33899fe60d0SBenny Halevy 2 /* eir_server_owner.so_minor_id */ + \
33999fe60d0SBenny Halevy /* eir_server_owner.so_major_id<> */ \
34099fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
34199fe60d0SBenny Halevy /* eir_server_scope<> */ \
34299fe60d0SBenny Halevy XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
34399fe60d0SBenny Halevy 1 /* eir_server_impl_id array length */ + \
3447d2ed9acSWeston Andros Adamson 1 /* nii_domain */ + \
3457d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3467d2ed9acSWeston Andros Adamson 1 /* nii_name */ + \
3477d2ed9acSWeston Andros Adamson XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
3487d2ed9acSWeston Andros Adamson 3 /* nii_date */)
349fc931582SAndy Adamson #define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
350fc931582SAndy Adamson #define decode_channel_attrs_maxsz (6 + \
351fc931582SAndy Adamson 1 /* ca_rdma_ird.len */ + \
352fc931582SAndy Adamson 1 /* ca_rdma_ird */)
353fc931582SAndy Adamson #define encode_create_session_maxsz (op_encode_hdr_maxsz + \
354fc931582SAndy Adamson 2 /* csa_clientid */ + \
355fc931582SAndy Adamson 1 /* csa_sequence */ + \
356fc931582SAndy Adamson 1 /* csa_flags */ + \
357fc931582SAndy Adamson encode_channel_attrs_maxsz + \
358fc931582SAndy Adamson encode_channel_attrs_maxsz + \
359fc931582SAndy Adamson 1 /* csa_cb_program */ + \
360fc931582SAndy Adamson 1 /* csa_sec_parms.len (1) */ + \
361fc931582SAndy Adamson 1 /* cb_secflavor (AUTH_SYS) */ + \
362fc931582SAndy Adamson 1 /* stamp */ + \
363fc931582SAndy Adamson 1 /* machinename.len */ + \
364fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
365fc931582SAndy Adamson 1 /* uid */ + \
366fc931582SAndy Adamson 1 /* gid */ + \
367fc931582SAndy Adamson 1 /* gids.len (0) */)
368fc931582SAndy Adamson #define decode_create_session_maxsz (op_decode_hdr_maxsz + \
369fc931582SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
370fc931582SAndy Adamson 1 /* csr_sequence */ + \
371fc931582SAndy Adamson 1 /* csr_flags */ + \
372fc931582SAndy Adamson decode_channel_attrs_maxsz + \
373fc931582SAndy Adamson decode_channel_attrs_maxsz)
3747c44f1aeSWeston Andros Adamson #define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
3757c44f1aeSWeston Andros Adamson /* bctsa_sessid */ \
3767c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3777c44f1aeSWeston Andros Adamson 1 /* bctsa_dir */ + \
3787c44f1aeSWeston Andros Adamson 1 /* bctsa_use_conn_in_rdma_mode */)
3797c44f1aeSWeston Andros Adamson #define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
3807c44f1aeSWeston Andros Adamson /* bctsr_sessid */ \
3817c44f1aeSWeston Andros Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
3827c44f1aeSWeston Andros Adamson 1 /* bctsr_dir */ + \
3837c44f1aeSWeston Andros Adamson 1 /* bctsr_use_conn_in_rdma_mode */)
3840f3e66c6SAndy Adamson #define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
3850f3e66c6SAndy Adamson #define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
38666245539STrond Myklebust #define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
38766245539STrond Myklebust #define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
388fc01cea9SAndy Adamson #define encode_sequence_maxsz (op_encode_hdr_maxsz + \
389fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
390fc01cea9SAndy Adamson #define decode_sequence_maxsz (op_decode_hdr_maxsz + \
391fc01cea9SAndy Adamson XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
39218019753SRicardo Labiaga #define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
39318019753SRicardo Labiaga #define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
39484c9dee3SChristoph Hellwig #define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
39584c9dee3SChristoph Hellwig XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
39684c9dee3SChristoph Hellwig 1 /* layout type */ + \
39784c9dee3SChristoph Hellwig 1 /* maxcount */ + \
39884c9dee3SChristoph Hellwig 1 /* bitmap size */ + \
39984c9dee3SChristoph Hellwig 1 /* notification bitmap length */ + \
40084c9dee3SChristoph Hellwig 1 /* notification bitmap, word 0 */)
401b1f69b75SAndy Adamson #define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
402b1f69b75SAndy Adamson 1 /* layout type */ + \
403b1f69b75SAndy Adamson 1 /* opaque devaddr4 length */ + \
404b1f69b75SAndy Adamson /* devaddr4 payload is read into page */ \
405b1f69b75SAndy Adamson 1 /* notification bitmap length */ + \
40602ef04e4SChuck Lever 1 /* notification bitmap, word 0 */ + \
4079ed5af26STrond Myklebust pagepad_maxsz /* possible XDR padding */)
408b1f69b75SAndy Adamson #define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
409b1f69b75SAndy Adamson encode_stateid_maxsz)
410b1f69b75SAndy Adamson #define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
411b1f69b75SAndy Adamson decode_stateid_maxsz + \
4129ed5af26STrond Myklebust XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE) + \
4139ed5af26STrond Myklebust pagepad_maxsz)
414863a3c6cSAndy Adamson #define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
415863a3c6cSAndy Adamson 2 /* offset */ + \
416863a3c6cSAndy Adamson 2 /* length */ + \
417863a3c6cSAndy Adamson 1 /* reclaim */ + \
418863a3c6cSAndy Adamson encode_stateid_maxsz + \
419863a3c6cSAndy Adamson 1 /* new offset (true) */ + \
420863a3c6cSAndy Adamson 2 /* last byte written */ + \
421863a3c6cSAndy Adamson 1 /* nt_timechanged (false) */ + \
422863a3c6cSAndy Adamson 1 /* layoutupdate4 layout type */ + \
4235f919c9fSChristoph Hellwig 1 /* layoutupdate4 opaqueue len */)
4245f919c9fSChristoph Hellwig /* the actual content of layoutupdate4 should
4255f919c9fSChristoph Hellwig be allocated by drivers and spliced in
4265f919c9fSChristoph Hellwig using xdr_write_pages */
427863a3c6cSAndy Adamson #define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
428cbe82603SBenny Halevy #define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
429cbe82603SBenny Halevy encode_stateid_maxsz + \
4306669cb8bSTrond Myklebust 1 + \
4316669cb8bSTrond Myklebust XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
432cbe82603SBenny Halevy #define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
433cbe82603SBenny Halevy 1 + decode_stateid_maxsz)
434fca78d6dSBryan Schumaker #define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
435fca78d6dSBryan Schumaker #define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
4367d974794SBryan Schumaker #define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
4377d974794SBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE))
4387d974794SBryan Schumaker #define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
4399aeda35fSBryan Schumaker #define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
4409aeda35fSBryan Schumaker XDR_QUADLEN(NFS4_STATEID_SIZE))
4419f79fb48SAndy Adamson #define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
4429b7b9fccSAndy Adamson #else /* CONFIG_NFS_V4_1 */
4439b7b9fccSAndy Adamson #define encode_sequence_maxsz 0
4449b7b9fccSAndy Adamson #define decode_sequence_maxsz 0
445cf805165STrond Myklebust #define encode_layoutreturn_maxsz 0
446cf805165STrond Myklebust #define decode_layoutreturn_maxsz 0
44756f487f8SFred Isaman #define encode_layoutget_maxsz 0
44856f487f8SFred Isaman #define decode_layoutget_maxsz 0
4499b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
4509b7b9fccSAndy Adamson
4511da177e4SLinus Torvalds #define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
4521da177e4SLinus Torvalds #define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
4531da177e4SLinus Torvalds #define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
4549b7b9fccSAndy Adamson encode_sequence_maxsz + \
4551da177e4SLinus Torvalds encode_putfh_maxsz + \
4569104a55dSTrond Myklebust encode_read_maxsz)
4571da177e4SLinus Torvalds #define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
4589b7b9fccSAndy Adamson decode_sequence_maxsz + \
4591da177e4SLinus Torvalds decode_putfh_maxsz + \
4609104a55dSTrond Myklebust decode_read_maxsz)
4611da177e4SLinus Torvalds #define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
4629b7b9fccSAndy Adamson encode_sequence_maxsz + \
4631da177e4SLinus Torvalds encode_putfh_maxsz + \
4649104a55dSTrond Myklebust encode_readlink_maxsz)
4651da177e4SLinus Torvalds #define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
4669b7b9fccSAndy Adamson decode_sequence_maxsz + \
4671da177e4SLinus Torvalds decode_putfh_maxsz + \
4689104a55dSTrond Myklebust decode_readlink_maxsz)
4691da177e4SLinus Torvalds #define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
4709b7b9fccSAndy Adamson encode_sequence_maxsz + \
4711da177e4SLinus Torvalds encode_putfh_maxsz + \
4729104a55dSTrond Myklebust encode_readdir_maxsz)
4731da177e4SLinus Torvalds #define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
4749b7b9fccSAndy Adamson decode_sequence_maxsz + \
4751da177e4SLinus Torvalds decode_putfh_maxsz + \
4769104a55dSTrond Myklebust decode_readdir_maxsz)
4771da177e4SLinus Torvalds #define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
4789b7b9fccSAndy Adamson encode_sequence_maxsz + \
4791da177e4SLinus Torvalds encode_putfh_maxsz + \
4809104a55dSTrond Myklebust encode_write_maxsz + \
4814f9838c7STrond Myklebust encode_getattr_maxsz)
4821da177e4SLinus Torvalds #define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
4839b7b9fccSAndy Adamson decode_sequence_maxsz + \
4841da177e4SLinus Torvalds decode_putfh_maxsz + \
4859104a55dSTrond Myklebust decode_write_maxsz + \
4864f9838c7STrond Myklebust decode_getattr_maxsz)
4871da177e4SLinus Torvalds #define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
4889b7b9fccSAndy Adamson encode_sequence_maxsz + \
4891da177e4SLinus Torvalds encode_putfh_maxsz + \
4908582715eSTrond Myklebust encode_commit_maxsz)
4911da177e4SLinus Torvalds #define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
4929b7b9fccSAndy Adamson decode_sequence_maxsz + \
4931da177e4SLinus Torvalds decode_putfh_maxsz + \
4948582715eSTrond Myklebust decode_commit_maxsz)
4951da177e4SLinus Torvalds #define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
4969b7b9fccSAndy Adamson encode_sequence_maxsz + \
4971da177e4SLinus Torvalds encode_putfh_maxsz + \
4982cebf828STrond Myklebust encode_open_maxsz + \
4996168f62cSWeston Andros Adamson encode_access_maxsz + \
5002cebf828STrond Myklebust encode_getfh_maxsz + \
50156f487f8SFred Isaman encode_getattr_maxsz + \
50256f487f8SFred Isaman encode_layoutget_maxsz)
5031da177e4SLinus Torvalds #define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
5049b7b9fccSAndy Adamson decode_sequence_maxsz + \
5051da177e4SLinus Torvalds decode_putfh_maxsz + \
5062cebf828STrond Myklebust decode_open_maxsz + \
5076168f62cSWeston Andros Adamson decode_access_maxsz + \
5082cebf828STrond Myklebust decode_getfh_maxsz + \
50956f487f8SFred Isaman decode_getattr_maxsz + \
51056f487f8SFred Isaman decode_layoutget_maxsz)
5111da177e4SLinus Torvalds #define NFS4_enc_open_confirm_sz \
5121da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \
5131da177e4SLinus Torvalds encode_putfh_maxsz + \
5149104a55dSTrond Myklebust encode_open_confirm_maxsz)
5159104a55dSTrond Myklebust #define NFS4_dec_open_confirm_sz \
5169104a55dSTrond Myklebust (compound_decode_hdr_maxsz + \
5171da177e4SLinus Torvalds decode_putfh_maxsz + \
5189104a55dSTrond Myklebust decode_open_confirm_maxsz)
5191da177e4SLinus Torvalds #define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
5209b7b9fccSAndy Adamson encode_sequence_maxsz + \
5211da177e4SLinus Torvalds encode_putfh_maxsz + \
5222cebf828STrond Myklebust encode_open_maxsz + \
5236168f62cSWeston Andros Adamson encode_access_maxsz + \
52456f487f8SFred Isaman encode_getattr_maxsz + \
52556f487f8SFred Isaman encode_layoutget_maxsz)
5261da177e4SLinus Torvalds #define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
5279b7b9fccSAndy Adamson decode_sequence_maxsz + \
5281da177e4SLinus Torvalds decode_putfh_maxsz + \
5292cebf828STrond Myklebust decode_open_maxsz + \
5306168f62cSWeston Andros Adamson decode_access_maxsz + \
53156f487f8SFred Isaman decode_getattr_maxsz + \
53256f487f8SFred Isaman decode_layoutget_maxsz)
5331da177e4SLinus Torvalds #define NFS4_enc_open_downgrade_sz \
5341da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \
5359b7b9fccSAndy Adamson encode_sequence_maxsz + \
5361da177e4SLinus Torvalds encode_putfh_maxsz + \
537b6808145STrond Myklebust encode_layoutreturn_maxsz + \
5383947b74dSTrond Myklebust encode_open_downgrade_maxsz)
5391da177e4SLinus Torvalds #define NFS4_dec_open_downgrade_sz \
5401da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \
5419b7b9fccSAndy Adamson decode_sequence_maxsz + \
5421da177e4SLinus Torvalds decode_putfh_maxsz + \
543b6808145STrond Myklebust decode_layoutreturn_maxsz + \
5443947b74dSTrond Myklebust decode_open_downgrade_maxsz)
5451da177e4SLinus Torvalds #define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
5469b7b9fccSAndy Adamson encode_sequence_maxsz + \
5471da177e4SLinus Torvalds encode_putfh_maxsz + \
548cf805165STrond Myklebust encode_layoutreturn_maxsz + \
5499104a55dSTrond Myklebust encode_close_maxsz + \
550516a6af6STrond Myklebust encode_getattr_maxsz)
5511da177e4SLinus Torvalds #define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
5529b7b9fccSAndy Adamson decode_sequence_maxsz + \
5531da177e4SLinus Torvalds decode_putfh_maxsz + \
554cf805165STrond Myklebust decode_layoutreturn_maxsz + \
5559104a55dSTrond Myklebust decode_close_maxsz + \
556516a6af6STrond Myklebust decode_getattr_maxsz)
5571da177e4SLinus Torvalds #define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
5589b7b9fccSAndy Adamson encode_sequence_maxsz + \
5591da177e4SLinus Torvalds encode_putfh_maxsz + \
5609104a55dSTrond Myklebust encode_setattr_maxsz + \
5611da177e4SLinus Torvalds encode_getattr_maxsz)
5621da177e4SLinus Torvalds #define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
5639b7b9fccSAndy Adamson decode_sequence_maxsz + \
5641da177e4SLinus Torvalds decode_putfh_maxsz + \
5659104a55dSTrond Myklebust decode_setattr_maxsz + \
5669104a55dSTrond Myklebust decode_getattr_maxsz)
5671da177e4SLinus Torvalds #define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
5689b7b9fccSAndy Adamson encode_sequence_maxsz + \
5691da177e4SLinus Torvalds encode_putfh_maxsz + \
5701da177e4SLinus Torvalds encode_fsinfo_maxsz)
5711da177e4SLinus Torvalds #define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
5729b7b9fccSAndy Adamson decode_sequence_maxsz + \
5731da177e4SLinus Torvalds decode_putfh_maxsz + \
5741da177e4SLinus Torvalds decode_fsinfo_maxsz)
5751da177e4SLinus Torvalds #define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
5761da177e4SLinus Torvalds encode_renew_maxsz)
5771da177e4SLinus Torvalds #define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
5781da177e4SLinus Torvalds decode_renew_maxsz)
5791da177e4SLinus Torvalds #define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
5801da177e4SLinus Torvalds encode_setclientid_maxsz)
5811da177e4SLinus Torvalds #define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
5821da177e4SLinus Torvalds decode_setclientid_maxsz)
5831da177e4SLinus Torvalds #define NFS4_enc_setclientid_confirm_sz \
5841da177e4SLinus Torvalds (compound_encode_hdr_maxsz + \
58583ca7f5aSChuck Lever encode_setclientid_confirm_maxsz)
5861da177e4SLinus Torvalds #define NFS4_dec_setclientid_confirm_sz \
5871da177e4SLinus Torvalds (compound_decode_hdr_maxsz + \
58883ca7f5aSChuck Lever decode_setclientid_confirm_maxsz)
5891da177e4SLinus Torvalds #define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
5909b7b9fccSAndy Adamson encode_sequence_maxsz + \
5911da177e4SLinus Torvalds encode_putfh_maxsz + \
5929104a55dSTrond Myklebust encode_lock_maxsz)
5931da177e4SLinus Torvalds #define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
5949b7b9fccSAndy Adamson decode_sequence_maxsz + \
5951da177e4SLinus Torvalds decode_putfh_maxsz + \
5969104a55dSTrond Myklebust decode_lock_maxsz)
5971da177e4SLinus Torvalds #define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
5989b7b9fccSAndy Adamson encode_sequence_maxsz + \
5991da177e4SLinus Torvalds encode_putfh_maxsz + \
6009104a55dSTrond Myklebust encode_lockt_maxsz)
6019104a55dSTrond Myklebust #define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
6029b7b9fccSAndy Adamson decode_sequence_maxsz + \
6039104a55dSTrond Myklebust decode_putfh_maxsz + \
6049104a55dSTrond Myklebust decode_lockt_maxsz)
6051da177e4SLinus Torvalds #define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
6069b7b9fccSAndy Adamson encode_sequence_maxsz + \
6071da177e4SLinus Torvalds encode_putfh_maxsz + \
6089104a55dSTrond Myklebust encode_locku_maxsz)
6091da177e4SLinus Torvalds #define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
6109b7b9fccSAndy Adamson decode_sequence_maxsz + \
6111da177e4SLinus Torvalds decode_putfh_maxsz + \
6129104a55dSTrond Myklebust decode_locku_maxsz)
613d3c7b7ccSTrond Myklebust #define NFS4_enc_release_lockowner_sz \
614d3c7b7ccSTrond Myklebust (compound_encode_hdr_maxsz + \
615d3c7b7ccSTrond Myklebust encode_lockowner_maxsz)
616d3c7b7ccSTrond Myklebust #define NFS4_dec_release_lockowner_sz \
617d3c7b7ccSTrond Myklebust (compound_decode_hdr_maxsz + \
618d3c7b7ccSTrond Myklebust decode_lockowner_maxsz)
6191da177e4SLinus Torvalds #define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
6209b7b9fccSAndy Adamson encode_sequence_maxsz + \
6211da177e4SLinus Torvalds encode_putfh_maxsz + \
62276b32999STrond Myklebust encode_access_maxsz + \
62376b32999STrond Myklebust encode_getattr_maxsz)
6241da177e4SLinus Torvalds #define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
6259b7b9fccSAndy Adamson decode_sequence_maxsz + \
6261da177e4SLinus Torvalds decode_putfh_maxsz + \
62776b32999STrond Myklebust decode_access_maxsz + \
62876b32999STrond Myklebust decode_getattr_maxsz)
6291da177e4SLinus Torvalds #define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
6309b7b9fccSAndy Adamson encode_sequence_maxsz + \
6311da177e4SLinus Torvalds encode_putfh_maxsz + \
63244c99933SChuck Lever encode_getattr_maxsz + \
63344c99933SChuck Lever encode_renew_maxsz)
6341da177e4SLinus Torvalds #define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
6359b7b9fccSAndy Adamson decode_sequence_maxsz + \
6361da177e4SLinus Torvalds decode_putfh_maxsz + \
63744c99933SChuck Lever decode_getattr_maxsz + \
63844c99933SChuck Lever decode_renew_maxsz)
6391da177e4SLinus Torvalds #define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
6409b7b9fccSAndy Adamson encode_sequence_maxsz + \
6411da177e4SLinus Torvalds encode_putfh_maxsz + \
6421da177e4SLinus Torvalds encode_lookup_maxsz + \
6431da177e4SLinus Torvalds encode_getattr_maxsz + \
6441da177e4SLinus Torvalds encode_getfh_maxsz)
6451da177e4SLinus Torvalds #define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
6469b7b9fccSAndy Adamson decode_sequence_maxsz + \
6471da177e4SLinus Torvalds decode_putfh_maxsz + \
648e6889620STrond Myklebust decode_lookup_maxsz + \
6491da177e4SLinus Torvalds decode_getattr_maxsz + \
6501da177e4SLinus Torvalds decode_getfh_maxsz)
6515b5faaf6SJeff Layton #define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
6525b5faaf6SJeff Layton encode_sequence_maxsz + \
6535b5faaf6SJeff Layton encode_putfh_maxsz + \
6545b5faaf6SJeff Layton encode_lookupp_maxsz + \
6555b5faaf6SJeff Layton encode_getattr_maxsz + \
6565b5faaf6SJeff Layton encode_getfh_maxsz)
6575b5faaf6SJeff Layton #define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
6585b5faaf6SJeff Layton decode_sequence_maxsz + \
6595b5faaf6SJeff Layton decode_putfh_maxsz + \
6605b5faaf6SJeff Layton decode_lookupp_maxsz + \
6615b5faaf6SJeff Layton decode_getattr_maxsz + \
6625b5faaf6SJeff Layton decode_getfh_maxsz)
6631da177e4SLinus Torvalds #define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
6649b7b9fccSAndy Adamson encode_sequence_maxsz + \
6651da177e4SLinus Torvalds encode_putrootfh_maxsz + \
6661da177e4SLinus Torvalds encode_getattr_maxsz + \
6671da177e4SLinus Torvalds encode_getfh_maxsz)
6681da177e4SLinus Torvalds #define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
6699b7b9fccSAndy Adamson decode_sequence_maxsz + \
6701da177e4SLinus Torvalds decode_putrootfh_maxsz + \
6711da177e4SLinus Torvalds decode_getattr_maxsz + \
6721da177e4SLinus Torvalds decode_getfh_maxsz)
6731da177e4SLinus Torvalds #define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
6749b7b9fccSAndy Adamson encode_sequence_maxsz + \
6751da177e4SLinus Torvalds encode_putfh_maxsz + \
676778d2817STrond Myklebust encode_remove_maxsz)
6771da177e4SLinus Torvalds #define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
6789b7b9fccSAndy Adamson decode_sequence_maxsz + \
6791da177e4SLinus Torvalds decode_putfh_maxsz + \
680778d2817STrond Myklebust decode_remove_maxsz)
6811da177e4SLinus Torvalds #define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
6829b7b9fccSAndy Adamson encode_sequence_maxsz + \
6831da177e4SLinus Torvalds encode_putfh_maxsz + \
6841da177e4SLinus Torvalds encode_savefh_maxsz + \
6851da177e4SLinus Torvalds encode_putfh_maxsz + \
686778d2817STrond Myklebust encode_rename_maxsz)
6871da177e4SLinus Torvalds #define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
6889b7b9fccSAndy Adamson decode_sequence_maxsz + \
6891da177e4SLinus Torvalds decode_putfh_maxsz + \
6901da177e4SLinus Torvalds decode_savefh_maxsz + \
6911da177e4SLinus Torvalds decode_putfh_maxsz + \
692778d2817STrond Myklebust decode_rename_maxsz)
6931da177e4SLinus Torvalds #define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
6949b7b9fccSAndy Adamson encode_sequence_maxsz + \
6951da177e4SLinus Torvalds encode_putfh_maxsz + \
6961da177e4SLinus Torvalds encode_savefh_maxsz + \
6971da177e4SLinus Torvalds encode_putfh_maxsz + \
69891ba2eeeSTrond Myklebust encode_link_maxsz + \
69991ba2eeeSTrond Myklebust encode_restorefh_maxsz + \
700a9f6991bSTrond Myklebust encode_getattr_maxsz)
7011da177e4SLinus Torvalds #define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
7029b7b9fccSAndy Adamson decode_sequence_maxsz + \
7031da177e4SLinus Torvalds decode_putfh_maxsz + \
7041da177e4SLinus Torvalds decode_savefh_maxsz + \
7051da177e4SLinus Torvalds decode_putfh_maxsz + \
70691ba2eeeSTrond Myklebust decode_link_maxsz + \
70791ba2eeeSTrond Myklebust decode_restorefh_maxsz + \
70891ba2eeeSTrond Myklebust decode_getattr_maxsz)
7091da177e4SLinus Torvalds #define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
7109b7b9fccSAndy Adamson encode_sequence_maxsz + \
7111da177e4SLinus Torvalds encode_putfh_maxsz + \
7121da177e4SLinus Torvalds encode_symlink_maxsz + \
7131da177e4SLinus Torvalds encode_getattr_maxsz + \
7141da177e4SLinus Torvalds encode_getfh_maxsz)
7151da177e4SLinus Torvalds #define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
7169b7b9fccSAndy Adamson decode_sequence_maxsz + \
7171da177e4SLinus Torvalds decode_putfh_maxsz + \
7181da177e4SLinus Torvalds decode_symlink_maxsz + \
7191da177e4SLinus Torvalds decode_getattr_maxsz + \
7201da177e4SLinus Torvalds decode_getfh_maxsz)
7211da177e4SLinus Torvalds #define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
7229b7b9fccSAndy Adamson encode_sequence_maxsz + \
7231da177e4SLinus Torvalds encode_putfh_maxsz + \
7241da177e4SLinus Torvalds encode_create_maxsz + \
72556ae19f3STrond Myklebust encode_getfh_maxsz + \
72656ae19f3STrond Myklebust encode_getattr_maxsz)
7271da177e4SLinus Torvalds #define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
7289b7b9fccSAndy Adamson decode_sequence_maxsz + \
7291da177e4SLinus Torvalds decode_putfh_maxsz + \
7301da177e4SLinus Torvalds decode_create_maxsz + \
73156ae19f3STrond Myklebust decode_getfh_maxsz + \
73256ae19f3STrond Myklebust decode_getattr_maxsz)
7331da177e4SLinus Torvalds #define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
7349b7b9fccSAndy Adamson encode_sequence_maxsz + \
7351da177e4SLinus Torvalds encode_putfh_maxsz + \
7361da177e4SLinus Torvalds encode_getattr_maxsz)
7371da177e4SLinus Torvalds #define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
7389b7b9fccSAndy Adamson decode_sequence_maxsz + \
7391da177e4SLinus Torvalds decode_putfh_maxsz + \
7401da177e4SLinus Torvalds decode_getattr_maxsz)
7411da177e4SLinus Torvalds #define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
7429b7b9fccSAndy Adamson encode_sequence_maxsz + \
7431da177e4SLinus Torvalds encode_putfh_maxsz + \
7449104a55dSTrond Myklebust encode_statfs_maxsz)
7451da177e4SLinus Torvalds #define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
7469b7b9fccSAndy Adamson decode_sequence_maxsz + \
7471da177e4SLinus Torvalds decode_putfh_maxsz + \
7489104a55dSTrond Myklebust decode_statfs_maxsz)
7491da177e4SLinus Torvalds #define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
7509b7b9fccSAndy Adamson encode_sequence_maxsz + \
751ab91f264STrond Myklebust encode_putfh_maxsz + \
7521da177e4SLinus Torvalds encode_getattr_maxsz)
7531da177e4SLinus Torvalds #define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
7549b7b9fccSAndy Adamson decode_sequence_maxsz + \
755ab91f264STrond Myklebust decode_putfh_maxsz + \
7561da177e4SLinus Torvalds decode_getattr_maxsz)
7571da177e4SLinus Torvalds #define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
7589b7b9fccSAndy Adamson encode_sequence_maxsz + \
7591da177e4SLinus Torvalds encode_putfh_maxsz + \
760586f1c39STrond Myklebust encode_layoutreturn_maxsz + \
761fa178f29STrond Myklebust encode_delegreturn_maxsz + \
762fa178f29STrond Myklebust encode_getattr_maxsz)
7631da177e4SLinus Torvalds #define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
7649b7b9fccSAndy Adamson decode_sequence_maxsz + \
765d8434d4cSTrond Myklebust decode_putfh_maxsz + \
766586f1c39STrond Myklebust decode_layoutreturn_maxsz + \
767fa178f29STrond Myklebust decode_delegreturn_maxsz + \
768fa178f29STrond Myklebust decode_getattr_maxsz)
769029d105eSJ. Bruce Fields #define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
7709b7b9fccSAndy Adamson encode_sequence_maxsz + \
771029d105eSJ. Bruce Fields encode_putfh_maxsz + \
7729104a55dSTrond Myklebust encode_getacl_maxsz)
773029d105eSJ. Bruce Fields #define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
7749b7b9fccSAndy Adamson decode_sequence_maxsz + \
775029d105eSJ. Bruce Fields decode_putfh_maxsz + \
7769104a55dSTrond Myklebust decode_getacl_maxsz)
77723ec6965SJ. Bruce Fields #define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
7789b7b9fccSAndy Adamson encode_sequence_maxsz + \
77923ec6965SJ. Bruce Fields encode_putfh_maxsz + \
7809104a55dSTrond Myklebust encode_setacl_maxsz)
78123ec6965SJ. Bruce Fields #define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
7829b7b9fccSAndy Adamson decode_sequence_maxsz + \
78323ec6965SJ. Bruce Fields decode_putfh_maxsz + \
7849104a55dSTrond Myklebust decode_setacl_maxsz)
785683b57b4STrond Myklebust #define NFS4_enc_fs_locations_sz \
786683b57b4STrond Myklebust (compound_encode_hdr_maxsz + \
7879b7b9fccSAndy Adamson encode_sequence_maxsz + \
788683b57b4STrond Myklebust encode_putfh_maxsz + \
789e6889620STrond Myklebust encode_lookup_maxsz + \
790b03d735bSChuck Lever encode_fs_locations_maxsz + \
791b03d735bSChuck Lever encode_renew_maxsz)
792683b57b4STrond Myklebust #define NFS4_dec_fs_locations_sz \
793683b57b4STrond Myklebust (compound_decode_hdr_maxsz + \
7949b7b9fccSAndy Adamson decode_sequence_maxsz + \
795683b57b4STrond Myklebust decode_putfh_maxsz + \
796e6889620STrond Myklebust decode_lookup_maxsz + \
797b03d735bSChuck Lever decode_fs_locations_maxsz + \
798b03d735bSChuck Lever decode_renew_maxsz)
7995a5ea0d4SBryan Schumaker #define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
8005a5ea0d4SBryan Schumaker encode_sequence_maxsz + \
8015a5ea0d4SBryan Schumaker encode_putfh_maxsz + \
8025a5ea0d4SBryan Schumaker encode_secinfo_maxsz)
8035a5ea0d4SBryan Schumaker #define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
8045a5ea0d4SBryan Schumaker decode_sequence_maxsz + \
8055a5ea0d4SBryan Schumaker decode_putfh_maxsz + \
8065a5ea0d4SBryan Schumaker decode_secinfo_maxsz)
80744c99933SChuck Lever #define NFS4_enc_fsid_present_sz \
80844c99933SChuck Lever (compound_encode_hdr_maxsz + \
80944c99933SChuck Lever encode_sequence_maxsz + \
81044c99933SChuck Lever encode_putfh_maxsz + \
81144c99933SChuck Lever encode_getfh_maxsz + \
81244c99933SChuck Lever encode_renew_maxsz)
81344c99933SChuck Lever #define NFS4_dec_fsid_present_sz \
81444c99933SChuck Lever (compound_decode_hdr_maxsz + \
81544c99933SChuck Lever decode_sequence_maxsz + \
81644c99933SChuck Lever decode_putfh_maxsz + \
81744c99933SChuck Lever decode_getfh_maxsz + \
81844c99933SChuck Lever decode_renew_maxsz)
81999fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
8207c44f1aeSWeston Andros Adamson #define NFS4_enc_bind_conn_to_session_sz \
8217c44f1aeSWeston Andros Adamson (compound_encode_hdr_maxsz + \
8227c44f1aeSWeston Andros Adamson encode_bind_conn_to_session_maxsz)
8237c44f1aeSWeston Andros Adamson #define NFS4_dec_bind_conn_to_session_sz \
8247c44f1aeSWeston Andros Adamson (compound_decode_hdr_maxsz + \
8257c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz)
82699fe60d0SBenny Halevy #define NFS4_enc_exchange_id_sz \
82799fe60d0SBenny Halevy (compound_encode_hdr_maxsz + \
82899fe60d0SBenny Halevy encode_exchange_id_maxsz)
82999fe60d0SBenny Halevy #define NFS4_dec_exchange_id_sz \
83099fe60d0SBenny Halevy (compound_decode_hdr_maxsz + \
83199fe60d0SBenny Halevy decode_exchange_id_maxsz)
832fc931582SAndy Adamson #define NFS4_enc_create_session_sz \
833fc931582SAndy Adamson (compound_encode_hdr_maxsz + \
834fc931582SAndy Adamson encode_create_session_maxsz)
835fc931582SAndy Adamson #define NFS4_dec_create_session_sz \
836fc931582SAndy Adamson (compound_decode_hdr_maxsz + \
837fc931582SAndy Adamson decode_create_session_maxsz)
8380f3e66c6SAndy Adamson #define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
8390f3e66c6SAndy Adamson encode_destroy_session_maxsz)
8400f3e66c6SAndy Adamson #define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
8410f3e66c6SAndy Adamson decode_destroy_session_maxsz)
84266245539STrond Myklebust #define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
84366245539STrond Myklebust encode_destroy_clientid_maxsz)
84466245539STrond Myklebust #define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
84566245539STrond Myklebust decode_destroy_clientid_maxsz)
846fc01cea9SAndy Adamson #define NFS4_enc_sequence_sz \
847fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \
848fc01cea9SAndy Adamson encode_sequence_maxsz)
849fc01cea9SAndy Adamson #define NFS4_dec_sequence_sz \
850fc01cea9SAndy Adamson (compound_decode_hdr_maxsz + \
851fc01cea9SAndy Adamson decode_sequence_maxsz)
8520efb01b2SDonald Buczek #endif
8532050f0ccSAndy Adamson #define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
8542050f0ccSAndy Adamson encode_sequence_maxsz + \
8552050f0ccSAndy Adamson encode_putrootfh_maxsz + \
8562050f0ccSAndy Adamson encode_fsinfo_maxsz)
8572050f0ccSAndy Adamson #define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
8582050f0ccSAndy Adamson decode_sequence_maxsz + \
8592050f0ccSAndy Adamson decode_putrootfh_maxsz + \
8602050f0ccSAndy Adamson decode_fsinfo_maxsz)
8610efb01b2SDonald Buczek #if defined(CONFIG_NFS_V4_1)
86218019753SRicardo Labiaga #define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
86318019753SRicardo Labiaga encode_sequence_maxsz + \
86418019753SRicardo Labiaga encode_reclaim_complete_maxsz)
86518019753SRicardo Labiaga #define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
86618019753SRicardo Labiaga decode_sequence_maxsz + \
86718019753SRicardo Labiaga decode_reclaim_complete_maxsz)
868b1f69b75SAndy Adamson #define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
869b1f69b75SAndy Adamson encode_sequence_maxsz +\
870b1f69b75SAndy Adamson encode_getdeviceinfo_maxsz)
871b1f69b75SAndy Adamson #define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
872b1f69b75SAndy Adamson decode_sequence_maxsz + \
873b1f69b75SAndy Adamson decode_getdeviceinfo_maxsz)
874b1f69b75SAndy Adamson #define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
875b1f69b75SAndy Adamson encode_sequence_maxsz + \
876b1f69b75SAndy Adamson encode_putfh_maxsz + \
877b1f69b75SAndy Adamson encode_layoutget_maxsz)
878b1f69b75SAndy Adamson #define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
879b1f69b75SAndy Adamson decode_sequence_maxsz + \
880b1f69b75SAndy Adamson decode_putfh_maxsz + \
881b1f69b75SAndy Adamson decode_layoutget_maxsz)
882863a3c6cSAndy Adamson #define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
883863a3c6cSAndy Adamson encode_sequence_maxsz +\
884863a3c6cSAndy Adamson encode_putfh_maxsz + \
885863a3c6cSAndy Adamson encode_layoutcommit_maxsz + \
886863a3c6cSAndy Adamson encode_getattr_maxsz)
887863a3c6cSAndy Adamson #define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
888863a3c6cSAndy Adamson decode_sequence_maxsz + \
889863a3c6cSAndy Adamson decode_putfh_maxsz + \
890863a3c6cSAndy Adamson decode_layoutcommit_maxsz + \
891863a3c6cSAndy Adamson decode_getattr_maxsz)
892cbe82603SBenny Halevy #define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
893cbe82603SBenny Halevy encode_sequence_maxsz + \
894cbe82603SBenny Halevy encode_putfh_maxsz + \
895cbe82603SBenny Halevy encode_layoutreturn_maxsz)
896cbe82603SBenny Halevy #define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
897cbe82603SBenny Halevy decode_sequence_maxsz + \
898cbe82603SBenny Halevy decode_putfh_maxsz + \
899cbe82603SBenny Halevy decode_layoutreturn_maxsz)
900fca78d6dSBryan Schumaker #define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
901fca78d6dSBryan Schumaker encode_sequence_maxsz + \
902fca78d6dSBryan Schumaker encode_putrootfh_maxsz +\
903fca78d6dSBryan Schumaker encode_secinfo_no_name_maxsz)
904fca78d6dSBryan Schumaker #define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
905fca78d6dSBryan Schumaker decode_sequence_maxsz + \
906fca78d6dSBryan Schumaker decode_putrootfh_maxsz + \
907fca78d6dSBryan Schumaker decode_secinfo_no_name_maxsz)
9087d974794SBryan Schumaker #define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
9097d974794SBryan Schumaker encode_sequence_maxsz + \
9107d974794SBryan Schumaker encode_test_stateid_maxsz)
9117d974794SBryan Schumaker #define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
9127d974794SBryan Schumaker decode_sequence_maxsz + \
9137d974794SBryan Schumaker decode_test_stateid_maxsz)
9149aeda35fSBryan Schumaker #define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
9159aeda35fSBryan Schumaker encode_sequence_maxsz + \
9169aeda35fSBryan Schumaker encode_free_stateid_maxsz)
9179aeda35fSBryan Schumaker #define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
9189aeda35fSBryan Schumaker decode_sequence_maxsz + \
9199aeda35fSBryan Schumaker decode_free_stateid_maxsz)
9202449ea2eSAlexandros Batsakis
9212449ea2eSAlexandros Batsakis const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
9222449ea2eSAlexandros Batsakis compound_encode_hdr_maxsz +
9232449ea2eSAlexandros Batsakis encode_sequence_maxsz +
9242449ea2eSAlexandros Batsakis encode_putfh_maxsz +
9252449ea2eSAlexandros Batsakis encode_getattr_maxsz) *
9262449ea2eSAlexandros Batsakis XDR_UNIT);
9272449ea2eSAlexandros Batsakis
9282449ea2eSAlexandros Batsakis const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
9292449ea2eSAlexandros Batsakis compound_decode_hdr_maxsz +
9302449ea2eSAlexandros Batsakis decode_sequence_maxsz +
9312449ea2eSAlexandros Batsakis decode_putfh_maxsz) *
9322449ea2eSAlexandros Batsakis XDR_UNIT);
933f1c097beSAndy Adamson
934f1c097beSAndy Adamson const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
935f1c097beSAndy Adamson compound_decode_hdr_maxsz +
936f1c097beSAndy Adamson decode_sequence_maxsz) *
937f1c097beSAndy Adamson XDR_UNIT);
938f1c097beSAndy Adamson EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
93999fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
9401da177e4SLinus Torvalds
941bca79478STrond Myklebust static const umode_t nfs_type2fmt[] = {
942bca79478STrond Myklebust [NF4BAD] = 0,
943bca79478STrond Myklebust [NF4REG] = S_IFREG,
944bca79478STrond Myklebust [NF4DIR] = S_IFDIR,
945bca79478STrond Myklebust [NF4BLK] = S_IFBLK,
946bca79478STrond Myklebust [NF4CHR] = S_IFCHR,
947bca79478STrond Myklebust [NF4LNK] = S_IFLNK,
948bca79478STrond Myklebust [NF4SOCK] = S_IFSOCK,
949bca79478STrond Myklebust [NF4FIFO] = S_IFIFO,
950bca79478STrond Myklebust [NF4ATTRDIR] = 0,
951bca79478STrond Myklebust [NF4NAMEDATTR] = 0,
9521da177e4SLinus Torvalds };
9531da177e4SLinus Torvalds
9541da177e4SLinus Torvalds struct compound_hdr {
9551da177e4SLinus Torvalds int32_t status;
9561da177e4SLinus Torvalds uint32_t nops;
957d017931cSAndy Adamson __be32 * nops_p;
9581da177e4SLinus Torvalds uint32_t taglen;
9591da177e4SLinus Torvalds char * tag;
9600c4e8c18SBenny Halevy uint32_t replen; /* expected reply words */
96166cc0429SBenny Halevy u32 minorversion;
9621da177e4SLinus Torvalds };
9631da177e4SLinus Torvalds
reserve_space(struct xdr_stream * xdr,size_t nbytes)96413c65ce9SBenny Halevy static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
96513c65ce9SBenny Halevy {
96613c65ce9SBenny Halevy __be32 *p = xdr_reserve_space(xdr, nbytes);
96713c65ce9SBenny Halevy BUG_ON(!p);
96813c65ce9SBenny Halevy return p;
96913c65ce9SBenny Halevy }
9701da177e4SLinus Torvalds
encode_opaque_fixed(struct xdr_stream * xdr,const void * buf,size_t len)971cb17e556STrond Myklebust static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
972cb17e556STrond Myklebust {
973ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
974cb17e556STrond Myklebust }
975cb17e556STrond Myklebust
encode_string(struct xdr_stream * xdr,unsigned int len,const char * str)9761da177e4SLinus Torvalds static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
9771da177e4SLinus Torvalds {
978ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
9791da177e4SLinus Torvalds }
9801da177e4SLinus Torvalds
encode_uint32(struct xdr_stream * xdr,u32 n)9814ade9821STrond Myklebust static void encode_uint32(struct xdr_stream *xdr, u32 n)
9824ade9821STrond Myklebust {
983ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
9844ade9821STrond Myklebust }
9854ade9821STrond Myklebust
encode_uint64(struct xdr_stream * xdr,u64 n)986ff2eb681STrond Myklebust static void encode_uint64(struct xdr_stream *xdr, u64 n)
987ff2eb681STrond Myklebust {
988ab6e9aafSTrond Myklebust WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
989ff2eb681STrond Myklebust }
990ff2eb681STrond Myklebust
xdr_encode_bitmap4(struct xdr_stream * xdr,const __u32 * bitmap,size_t len)99137c88763STrond Myklebust static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
99237c88763STrond Myklebust const __u32 *bitmap, size_t len)
99337c88763STrond Myklebust {
99437c88763STrond Myklebust ssize_t ret;
99537c88763STrond Myklebust
99637c88763STrond Myklebust /* Trim empty words */
99737c88763STrond Myklebust while (len > 0 && bitmap[len-1] == 0)
99837c88763STrond Myklebust len--;
99937c88763STrond Myklebust ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
100037c88763STrond Myklebust if (WARN_ON_ONCE(ret < 0))
100137c88763STrond Myklebust return ret;
100237c88763STrond Myklebust return len;
100337c88763STrond Myklebust }
100437c88763STrond Myklebust
mask_bitmap4(const __u32 * bitmap,const __u32 * mask,__u32 * res,size_t len)100537c88763STrond Myklebust static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
100637c88763STrond Myklebust __u32 *res, size_t len)
100737c88763STrond Myklebust {
100837c88763STrond Myklebust size_t i;
100937c88763STrond Myklebust __u32 tmp;
101037c88763STrond Myklebust
101137c88763STrond Myklebust while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
101237c88763STrond Myklebust len--;
101337c88763STrond Myklebust for (i = len; i-- > 0;) {
101437c88763STrond Myklebust tmp = bitmap[i] & mask[i];
101537c88763STrond Myklebust res[i] = tmp;
101637c88763STrond Myklebust }
101737c88763STrond Myklebust return len;
101837c88763STrond Myklebust }
101937c88763STrond Myklebust
encode_nfs4_seqid(struct xdr_stream * xdr,const struct nfs_seqid * seqid)10204ade9821STrond Myklebust static void encode_nfs4_seqid(struct xdr_stream *xdr,
10214ade9821STrond Myklebust const struct nfs_seqid *seqid)
10224ade9821STrond Myklebust {
1023a6796419STrond Myklebust if (seqid != NULL)
10244ade9821STrond Myklebust encode_uint32(xdr, seqid->sequence->counter);
1025a6796419STrond Myklebust else
1026a6796419STrond Myklebust encode_uint32(xdr, 0);
10274ade9821STrond Myklebust }
10284ade9821STrond Myklebust
encode_compound_hdr(struct xdr_stream * xdr,struct rpc_rqst * req,struct compound_hdr * hdr)10290c4e8c18SBenny Halevy static void encode_compound_hdr(struct xdr_stream *xdr,
10300c4e8c18SBenny Halevy struct rpc_rqst *req,
10310c4e8c18SBenny Halevy struct compound_hdr *hdr)
10321da177e4SLinus Torvalds {
10338687b63aSAl Viro __be32 *p;
10340c4e8c18SBenny Halevy
10350c4e8c18SBenny Halevy /* initialize running count of expected bytes in reply.
10360c4e8c18SBenny Halevy * NOTE: the replied tag SHOULD be the same is the one sent,
10370c4e8c18SBenny Halevy * but this is not required as a MUST for the server to do so. */
1038cf500bacSChuck Lever hdr->replen = 3 + hdr->taglen;
10391da177e4SLinus Torvalds
10407fc38846STrond Myklebust WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
10416fdfb0bcSTrond Myklebust encode_string(xdr, hdr->taglen, hdr->tag);
10426fdfb0bcSTrond Myklebust p = reserve_space(xdr, 8);
1043e75bc1c8SBenny Halevy *p++ = cpu_to_be32(hdr->minorversion);
1044d017931cSAndy Adamson hdr->nops_p = p;
104534558513SBenny Halevy *p = cpu_to_be32(hdr->nops);
1046d017931cSAndy Adamson }
1047d017931cSAndy Adamson
encode_op_hdr(struct xdr_stream * xdr,enum nfs_opnum4 op,uint32_t replen,struct compound_hdr * hdr)1048ab19b481STrond Myklebust static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1049ab19b481STrond Myklebust uint32_t replen,
1050ab19b481STrond Myklebust struct compound_hdr *hdr)
1051ab19b481STrond Myklebust {
1052ab19b481STrond Myklebust encode_uint32(xdr, op);
1053ab19b481STrond Myklebust hdr->nops++;
1054ab19b481STrond Myklebust hdr->replen += replen;
1055ab19b481STrond Myklebust }
1056ab19b481STrond Myklebust
encode_nops(struct compound_hdr * hdr)1057d017931cSAndy Adamson static void encode_nops(struct compound_hdr *hdr)
1058d017931cSAndy Adamson {
10597fc38846STrond Myklebust WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
1060d017931cSAndy Adamson *hdr->nops_p = htonl(hdr->nops);
10611da177e4SLinus Torvalds }
10621da177e4SLinus Torvalds
encode_nfs4_stateid(struct xdr_stream * xdr,const nfs4_stateid * stateid)1063ea9d23f5STrond Myklebust static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1064ea9d23f5STrond Myklebust {
10652d2f24adSTrond Myklebust encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
1066ea9d23f5STrond Myklebust }
1067ea9d23f5STrond Myklebust
encode_nfs4_verifier(struct xdr_stream * xdr,const nfs4_verifier * verf)10681da177e4SLinus Torvalds static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
10691da177e4SLinus Torvalds {
1070cb17e556STrond Myklebust encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
10711da177e4SLinus Torvalds }
10721da177e4SLinus Torvalds
107336b3743fSTrond Myklebust static __be32 *
xdr_encode_nfstime4(__be32 * p,const struct timespec64 * t)1074e7d4b05cSTrond Myklebust xdr_encode_nfstime4(__be32 *p, const struct timespec64 *t)
107536b3743fSTrond Myklebust {
1076a3167dacSArnd Bergmann p = xdr_encode_hyper(p, t->tv_sec);
107736b3743fSTrond Myklebust *p++ = cpu_to_be32(t->tv_nsec);
107836b3743fSTrond Myklebust return p;
107936b3743fSTrond Myklebust }
108036b3743fSTrond Myklebust
encode_attrs(struct xdr_stream * xdr,const struct iattr * iap,const struct nfs4_label * label,const umode_t * umask,const struct nfs_server * server,const uint32_t attrmask[])1081aa9c2669SDavid Quigley static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1082aa9c2669SDavid Quigley const struct nfs4_label *label,
108328cf22d0STrond Myklebust const umode_t *umask,
10845334c5bdSKinglong Mee const struct nfs_server *server,
108528cf22d0STrond Myklebust const uint32_t attrmask[])
10861da177e4SLinus Torvalds {
10871da177e4SLinus Torvalds char owner_name[IDMAP_NAMESZ];
10881da177e4SLinus Torvalds char owner_group[IDMAP_NAMESZ];
10891da177e4SLinus Torvalds int owner_namelen = 0;
10901da177e4SLinus Torvalds int owner_grouplen = 0;
10918687b63aSAl Viro __be32 *p;
1092d7067b2dSTrond Myklebust uint32_t len = 0;
1093d7067b2dSTrond Myklebust uint32_t bmval[3] = { 0 };
10941da177e4SLinus Torvalds
10951da177e4SLinus Torvalds /*
10961da177e4SLinus Torvalds * We reserve enough space to write the entire attribute buffer at once.
10971da177e4SLinus Torvalds */
109828cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
1099d7067b2dSTrond Myklebust bmval[0] |= FATTR4_WORD0_SIZE;
11001da177e4SLinus Torvalds len += 8;
1101d7067b2dSTrond Myklebust }
1102d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MODE) {
110328cf22d0STrond Myklebust if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
1104dff25ddbSAndreas Gruenbacher bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1105dff25ddbSAndreas Gruenbacher len += 8;
110628cf22d0STrond Myklebust } else if (attrmask[1] & FATTR4_WORD1_MODE) {
1107d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_MODE;
11081da177e4SLinus Torvalds len += 4;
1109d7067b2dSTrond Myklebust }
1110dff25ddbSAndreas Gruenbacher }
111128cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
1112e4fd72a1STrond Myklebust owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
11131da177e4SLinus Torvalds if (owner_namelen < 0) {
1114fe82a183SChuck Lever dprintk("nfs: couldn't resolve uid %d to string\n",
1115e5782076SEric W. Biederman from_kuid(&init_user_ns, iap->ia_uid));
11161da177e4SLinus Torvalds /* XXX */
11171da177e4SLinus Torvalds strcpy(owner_name, "nobody");
11181da177e4SLinus Torvalds owner_namelen = sizeof("nobody") - 1;
11191da177e4SLinus Torvalds /* goto out; */
11201da177e4SLinus Torvalds }
1121d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER;
11221da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
11231da177e4SLinus Torvalds }
112428cf22d0STrond Myklebust if ((iap->ia_valid & ATTR_GID) &&
112528cf22d0STrond Myklebust (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
1126e4fd72a1STrond Myklebust owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
11271da177e4SLinus Torvalds if (owner_grouplen < 0) {
1128fe82a183SChuck Lever dprintk("nfs: couldn't resolve gid %d to string\n",
1129e5782076SEric W. Biederman from_kgid(&init_user_ns, iap->ia_gid));
11301da177e4SLinus Torvalds strcpy(owner_group, "nobody");
11311da177e4SLinus Torvalds owner_grouplen = sizeof("nobody") - 1;
11321da177e4SLinus Torvalds /* goto out; */
11331da177e4SLinus Torvalds }
1134d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
11351da177e4SLinus Torvalds len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
11361da177e4SLinus Torvalds }
113728cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1138d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_ATIME_SET) {
1139d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
114036b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2);
1141d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_ATIME) {
1142d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
11431da177e4SLinus Torvalds len += 4;
1144d7067b2dSTrond Myklebust }
114528cf22d0STrond Myklebust }
114628cf22d0STrond Myklebust if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1147d7067b2dSTrond Myklebust if (iap->ia_valid & ATTR_MTIME_SET) {
1148d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
114936b3743fSTrond Myklebust len += 4 + (nfstime4_maxsz << 2);
1150d7067b2dSTrond Myklebust } else if (iap->ia_valid & ATTR_MTIME) {
1151d7067b2dSTrond Myklebust bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
11521da177e4SLinus Torvalds len += 4;
1153d7067b2dSTrond Myklebust }
11545334c5bdSKinglong Mee }
11555334c5bdSKinglong Mee
115628cf22d0STrond Myklebust if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1157b4a2cf76STrond Myklebust len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1158d7067b2dSTrond Myklebust bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1159d7067b2dSTrond Myklebust }
1160d7067b2dSTrond Myklebust
116140a3426cSTrond Myklebust xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
116240a3426cSTrond Myklebust xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
11631da177e4SLinus Torvalds
1164d7067b2dSTrond Myklebust if (bmval[0] & FATTR4_WORD0_SIZE)
1165b95be5a9SBenny Halevy p = xdr_encode_hyper(p, iap->ia_size);
1166d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_MODE)
1167e75bc1c8SBenny Halevy *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1168d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER)
1169811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_name, owner_namelen);
1170d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1171811652bdSBenny Halevy p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1172d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
11731da177e4SLinus Torvalds if (iap->ia_valid & ATTR_ATIME_SET) {
1174e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1175e7d4b05cSTrond Myklebust p = xdr_encode_nfstime4(p, &iap->ia_atime);
1176d7067b2dSTrond Myklebust } else
1177e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11781da177e4SLinus Torvalds }
1179d7067b2dSTrond Myklebust if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
11801da177e4SLinus Torvalds if (iap->ia_valid & ATTR_MTIME_SET) {
1181e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1182e7d4b05cSTrond Myklebust p = xdr_encode_nfstime4(p, &iap->ia_mtime);
1183d7067b2dSTrond Myklebust } else
1184e75bc1c8SBenny Halevy *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
11851da177e4SLinus Torvalds }
1186e2751463SJia-Ju Bai if (label && (bmval[2] & FATTR4_WORD2_SECURITY_LABEL)) {
1187aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->lfs);
1188aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->pi);
1189aa9c2669SDavid Quigley *p++ = cpu_to_be32(label->len);
1190aa9c2669SDavid Quigley p = xdr_encode_opaque_fixed(p, label->label, label->len);
1191aa9c2669SDavid Quigley }
1192dff25ddbSAndreas Gruenbacher if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1193dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1194dff25ddbSAndreas Gruenbacher *p++ = cpu_to_be32(*umask);
1195dff25ddbSAndreas Gruenbacher }
11961da177e4SLinus Torvalds
11971da177e4SLinus Torvalds /* out: */
11981da177e4SLinus Torvalds }
11991da177e4SLinus Torvalds
encode_access(struct xdr_stream * xdr,u32 access,struct compound_hdr * hdr)1200cf8cdbe5SAndy Adamson static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
12011da177e4SLinus Torvalds {
1202475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1203475d4ba0STrond Myklebust encode_uint32(xdr, access);
12041da177e4SLinus Torvalds }
12051da177e4SLinus Torvalds
encode_close(struct xdr_stream * xdr,const struct nfs_closeargs * arg,struct compound_hdr * hdr)1206cf8cdbe5SAndy Adamson static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
12071da177e4SLinus Torvalds {
1208ab19b481STrond Myklebust encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
12094ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid);
1210566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid);
12111da177e4SLinus Torvalds }
12121da177e4SLinus Torvalds
encode_commit(struct xdr_stream * xdr,const struct nfs_commitargs * args,struct compound_hdr * hdr)12130b7c0153SFred Isaman static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
12141da177e4SLinus Torvalds {
12158687b63aSAl Viro __be32 *p;
12161da177e4SLinus Torvalds
1217475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1218475d4ba0STrond Myklebust p = reserve_space(xdr, 12);
1219b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset);
122034558513SBenny Halevy *p = cpu_to_be32(args->count);
12211da177e4SLinus Torvalds }
12221da177e4SLinus Torvalds
encode_create(struct xdr_stream * xdr,const struct nfs4_create_arg * create,struct compound_hdr * hdr)1223cf8cdbe5SAndy Adamson static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
12241da177e4SLinus Torvalds {
12258687b63aSAl Viro __be32 *p;
12261da177e4SLinus Torvalds
1227475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1228475d4ba0STrond Myklebust encode_uint32(xdr, create->ftype);
12291da177e4SLinus Torvalds
12301da177e4SLinus Torvalds switch (create->ftype) {
12311da177e4SLinus Torvalds case NF4LNK:
123213c65ce9SBenny Halevy p = reserve_space(xdr, 4);
123334558513SBenny Halevy *p = cpu_to_be32(create->u.symlink.len);
12342fcc213aSChuck Lever xdr_write_pages(xdr, create->u.symlink.pages, 0,
12352fcc213aSChuck Lever create->u.symlink.len);
12362fcc213aSChuck Lever xdr->buf->flags |= XDRBUF_WRITE;
12371da177e4SLinus Torvalds break;
12381da177e4SLinus Torvalds
12391da177e4SLinus Torvalds case NF4BLK: case NF4CHR:
124013c65ce9SBenny Halevy p = reserve_space(xdr, 8);
1241e75bc1c8SBenny Halevy *p++ = cpu_to_be32(create->u.device.specdata1);
124234558513SBenny Halevy *p = cpu_to_be32(create->u.device.specdata2);
12431da177e4SLinus Torvalds break;
12441da177e4SLinus Torvalds
12451da177e4SLinus Torvalds default:
12461da177e4SLinus Torvalds break;
12471da177e4SLinus Torvalds }
12481da177e4SLinus Torvalds
1249811652bdSBenny Halevy encode_string(xdr, create->name->len, create->name->name);
125028cf22d0STrond Myklebust encode_attrs(xdr, create->attrs, create->label, &create->umask,
125128cf22d0STrond Myklebust create->server, create->server->attr_bitmask);
12521da177e4SLinus Torvalds }
12531da177e4SLinus Torvalds
encode_getattr(struct xdr_stream * xdr,const __u32 * bitmap,const __u32 * mask,size_t len,struct compound_hdr * hdr)125437c88763STrond Myklebust static void encode_getattr(struct xdr_stream *xdr,
125537c88763STrond Myklebust const __u32 *bitmap, const __u32 *mask, size_t len,
1256dae100c2SFred Isaman struct compound_hdr *hdr)
1257dae100c2SFred Isaman {
125837c88763STrond Myklebust __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
1259dae100c2SFred Isaman
1260ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
126137c88763STrond Myklebust if (mask) {
126237c88763STrond Myklebust if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
126337c88763STrond Myklebust len = ARRAY_SIZE(masked_bitmap);
126437c88763STrond Myklebust len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
126537c88763STrond Myklebust bitmap = masked_bitmap;
1266dae100c2SFred Isaman }
126737c88763STrond Myklebust xdr_encode_bitmap4(xdr, bitmap, len);
1268dae100c2SFred Isaman }
1269dae100c2SFred Isaman
encode_getfattr(struct xdr_stream * xdr,const u32 * bitmask,struct compound_hdr * hdr)1270cf8cdbe5SAndy Adamson static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12711da177e4SLinus Torvalds {
127237c88763STrond Myklebust encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
127337c88763STrond Myklebust ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
12741da177e4SLinus Torvalds }
12751da177e4SLinus Torvalds
encode_getfattr_open(struct xdr_stream * xdr,const u32 * bitmask,const u32 * open_bitmap,struct compound_hdr * hdr)127688034c3dSAndy Adamson static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
12771549210fSTrond Myklebust const u32 *open_bitmap,
127888034c3dSAndy Adamson struct compound_hdr *hdr)
127988034c3dSAndy Adamson {
128037c88763STrond Myklebust encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
128188034c3dSAndy Adamson }
128288034c3dSAndy Adamson
encode_fsinfo(struct xdr_stream * xdr,const u32 * bitmask,struct compound_hdr * hdr)1283cf8cdbe5SAndy Adamson static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
12841da177e4SLinus Torvalds {
128537c88763STrond Myklebust encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
128637c88763STrond Myklebust ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
12871da177e4SLinus Torvalds }
12881da177e4SLinus Torvalds
encode_fs_locations(struct xdr_stream * xdr,const u32 * bitmask,struct compound_hdr * hdr)1289cf8cdbe5SAndy Adamson static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
1290830b8e33SManoj Naik {
129137c88763STrond Myklebust encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
129237c88763STrond Myklebust ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
1293830b8e33SManoj Naik }
1294830b8e33SManoj Naik
encode_getfh(struct xdr_stream * xdr,struct compound_hdr * hdr)1295cf8cdbe5SAndy Adamson static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
12961da177e4SLinus Torvalds {
1297ab19b481STrond Myklebust encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
12981da177e4SLinus Torvalds }
12991da177e4SLinus Torvalds
encode_link(struct xdr_stream * xdr,const struct qstr * name,struct compound_hdr * hdr)1300cf8cdbe5SAndy Adamson static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13011da177e4SLinus Torvalds {
1302ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
13036fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name);
13041da177e4SLinus Torvalds }
13051da177e4SLinus Torvalds
nfs4_lock_type(struct file_lock * fl,int block)1306911d1aafSTrond Myklebust static inline int nfs4_lock_type(struct file_lock *fl, int block)
1307911d1aafSTrond Myklebust {
1308f44106e2SJeff Layton if (fl->fl_type == F_RDLCK)
1309911d1aafSTrond Myklebust return block ? NFS4_READW_LT : NFS4_READ_LT;
1310911d1aafSTrond Myklebust return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1311911d1aafSTrond Myklebust }
1312911d1aafSTrond Myklebust
nfs4_lock_length(struct file_lock * fl)1313911d1aafSTrond Myklebust static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1314911d1aafSTrond Myklebust {
1315911d1aafSTrond Myklebust if (fl->fl_end == OFFSET_MAX)
1316911d1aafSTrond Myklebust return ~(uint64_t)0;
1317911d1aafSTrond Myklebust return fl->fl_end - fl->fl_start + 1;
1318911d1aafSTrond Myklebust }
1319911d1aafSTrond Myklebust
encode_lockowner(struct xdr_stream * xdr,const struct nfs_lowner * lowner)1320daccbdedSTrond Myklebust static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1321daccbdedSTrond Myklebust {
1322daccbdedSTrond Myklebust __be32 *p;
1323daccbdedSTrond Myklebust
1324d035c36cSTrond Myklebust p = reserve_space(xdr, 32);
1325daccbdedSTrond Myklebust p = xdr_encode_hyper(p, lowner->clientid);
1326d035c36cSTrond Myklebust *p++ = cpu_to_be32(20);
1327daccbdedSTrond Myklebust p = xdr_encode_opaque_fixed(p, "lock id:", 8);
1328d035c36cSTrond Myklebust *p++ = cpu_to_be32(lowner->s_dev);
1329daccbdedSTrond Myklebust xdr_encode_hyper(p, lowner->id);
1330daccbdedSTrond Myklebust }
1331daccbdedSTrond Myklebust
13321da177e4SLinus Torvalds /*
13331da177e4SLinus Torvalds * opcode,type,reclaim,offset,length,new_lock_owner = 32
13341da177e4SLinus Torvalds * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
13351da177e4SLinus Torvalds */
encode_lock(struct xdr_stream * xdr,const struct nfs_lock_args * args,struct compound_hdr * hdr)1336cf8cdbe5SAndy Adamson static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
13371da177e4SLinus Torvalds {
13388687b63aSAl Viro __be32 *p;
13391da177e4SLinus Torvalds
1340475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1341475d4ba0STrond Myklebust p = reserve_space(xdr, 28);
1342e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1343e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->reclaim);
1344b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start);
1345b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
134634558513SBenny Halevy *p = cpu_to_be32(args->new_lock_owner);
1347911d1aafSTrond Myklebust if (args->new_lock_owner){
13484ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->open_seqid);
1349425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->open_stateid);
13504ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid);
1351daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner);
13521da177e4SLinus Torvalds }
13531da177e4SLinus Torvalds else {
1354425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->lock_stateid);
13554ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->lock_seqid);
13561da177e4SLinus Torvalds }
13571da177e4SLinus Torvalds }
13581da177e4SLinus Torvalds
encode_lockt(struct xdr_stream * xdr,const struct nfs_lockt_args * args,struct compound_hdr * hdr)1359cf8cdbe5SAndy Adamson static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
13601da177e4SLinus Torvalds {
13618687b63aSAl Viro __be32 *p;
13621da177e4SLinus Torvalds
1363475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1364475d4ba0STrond Myklebust p = reserve_space(xdr, 20);
1365e75bc1c8SBenny Halevy *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
1366b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start);
1367b95be5a9SBenny Halevy p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
1368daccbdedSTrond Myklebust encode_lockowner(xdr, &args->lock_owner);
13691da177e4SLinus Torvalds }
13701da177e4SLinus Torvalds
encode_locku(struct xdr_stream * xdr,const struct nfs_locku_args * args,struct compound_hdr * hdr)1371cf8cdbe5SAndy Adamson static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
13721da177e4SLinus Torvalds {
13738687b63aSAl Viro __be32 *p;
13741da177e4SLinus Torvalds
1375475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1376475d4ba0STrond Myklebust encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
13774ade9821STrond Myklebust encode_nfs4_seqid(xdr, args->seqid);
1378425c1d4eSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid);
1379ea9d23f5STrond Myklebust p = reserve_space(xdr, 16);
1380b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->fl->fl_start);
138134558513SBenny Halevy xdr_encode_hyper(p, nfs4_lock_length(args->fl));
13821da177e4SLinus Torvalds }
13831da177e4SLinus Torvalds
encode_release_lockowner(struct xdr_stream * xdr,const struct nfs_lowner * lowner,struct compound_hdr * hdr)1384d3c7b7ccSTrond Myklebust static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1385d3c7b7ccSTrond Myklebust {
1386ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
1387d3c7b7ccSTrond Myklebust encode_lockowner(xdr, lowner);
1388d3c7b7ccSTrond Myklebust }
1389d3c7b7ccSTrond Myklebust
encode_lookup(struct xdr_stream * xdr,const struct qstr * name,struct compound_hdr * hdr)1390cf8cdbe5SAndy Adamson static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
13911da177e4SLinus Torvalds {
1392ab19b481STrond Myklebust encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
13936fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name);
13941da177e4SLinus Torvalds }
13951da177e4SLinus Torvalds
encode_lookupp(struct xdr_stream * xdr,struct compound_hdr * hdr)13965b5faaf6SJeff Layton static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
13975b5faaf6SJeff Layton {
13985b5faaf6SJeff Layton encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
13995b5faaf6SJeff Layton }
14005b5faaf6SJeff Layton
encode_share_access(struct xdr_stream * xdr,u32 share_access)14016ae37339STrond Myklebust static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
14021da177e4SLinus Torvalds {
14038687b63aSAl Viro __be32 *p;
14041da177e4SLinus Torvalds
140513c65ce9SBenny Halevy p = reserve_space(xdr, 8);
14066ae37339STrond Myklebust *p++ = cpu_to_be32(share_access);
140734558513SBenny Halevy *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
14081da177e4SLinus Torvalds }
14091da177e4SLinus Torvalds
encode_openhdr(struct xdr_stream * xdr,const struct nfs_openargs * arg)14101da177e4SLinus Torvalds static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14111da177e4SLinus Torvalds {
14128687b63aSAl Viro __be32 *p;
14131da177e4SLinus Torvalds /*
14141da177e4SLinus Torvalds * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
14151da177e4SLinus Torvalds * owner 4 = 32
14161da177e4SLinus Torvalds */
14174ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid);
14186ae37339STrond Myklebust encode_share_access(xdr, arg->share_access);
141995b72eb0STrond Myklebust p = reserve_space(xdr, 36);
1420b95be5a9SBenny Halevy p = xdr_encode_hyper(p, arg->clientid);
142195b72eb0STrond Myklebust *p++ = cpu_to_be32(24);
142293f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, "open id:", 8);
1423d035c36cSTrond Myklebust *p++ = cpu_to_be32(arg->server->s_dev);
142495b72eb0STrond Myklebust *p++ = cpu_to_be32(arg->id.uniquifier);
142595b72eb0STrond Myklebust xdr_encode_hyper(p, arg->id.create_time);
14261da177e4SLinus Torvalds }
14271da177e4SLinus Torvalds
encode_createmode(struct xdr_stream * xdr,const struct nfs_openargs * arg)14281da177e4SLinus Torvalds static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14291da177e4SLinus Torvalds {
14308687b63aSAl Viro __be32 *p;
14311da177e4SLinus Torvalds
143213c65ce9SBenny Halevy p = reserve_space(xdr, 4);
1433549b19ccSTrond Myklebust switch(arg->createmode) {
1434549b19ccSTrond Myklebust case NFS4_CREATE_UNCHECKED:
143534558513SBenny Halevy *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
143628cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
143728cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask);
14381da177e4SLinus Torvalds break;
1439549b19ccSTrond Myklebust case NFS4_CREATE_GUARDED:
14404882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_GUARDED);
144128cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
144228cf22d0STrond Myklebust arg->server, arg->server->attr_bitmask);
1443549b19ccSTrond Myklebust break;
1444549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE:
1445549b19ccSTrond Myklebust *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1446549b19ccSTrond Myklebust encode_nfs4_verifier(xdr, &arg->u.verifier);
1447549b19ccSTrond Myklebust break;
1448549b19ccSTrond Myklebust case NFS4_CREATE_EXCLUSIVE4_1:
14494882ef72SAlexandros Batsakis *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
14504882ef72SAlexandros Batsakis encode_nfs4_verifier(xdr, &arg->u.verifier);
145128cf22d0STrond Myklebust encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
145228cf22d0STrond Myklebust arg->server, arg->server->exclcreat_bitmask);
14534882ef72SAlexandros Batsakis }
14544882ef72SAlexandros Batsakis }
14551da177e4SLinus Torvalds
encode_opentype(struct xdr_stream * xdr,const struct nfs_openargs * arg)14561da177e4SLinus Torvalds static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
14571da177e4SLinus Torvalds {
14588687b63aSAl Viro __be32 *p;
14591da177e4SLinus Torvalds
146013c65ce9SBenny Halevy p = reserve_space(xdr, 4);
14611da177e4SLinus Torvalds switch (arg->open_flags & O_CREAT) {
14621da177e4SLinus Torvalds case 0:
146334558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
14641da177e4SLinus Torvalds break;
14651da177e4SLinus Torvalds default:
146634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CREATE);
14671da177e4SLinus Torvalds encode_createmode(xdr, arg);
14681da177e4SLinus Torvalds }
14691da177e4SLinus Torvalds }
14701da177e4SLinus Torvalds
encode_delegation_type(struct xdr_stream * xdr,fmode_t delegation_type)1471bd7bf9d5STrond Myklebust static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
14721da177e4SLinus Torvalds {
14738687b63aSAl Viro __be32 *p;
14741da177e4SLinus Torvalds
147513c65ce9SBenny Halevy p = reserve_space(xdr, 4);
14761da177e4SLinus Torvalds switch (delegation_type) {
14771da177e4SLinus Torvalds case 0:
147834558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
14791da177e4SLinus Torvalds break;
14801da177e4SLinus Torvalds case FMODE_READ:
148134558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
14821da177e4SLinus Torvalds break;
14831da177e4SLinus Torvalds case FMODE_WRITE|FMODE_READ:
148434558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
14851da177e4SLinus Torvalds break;
14861da177e4SLinus Torvalds default:
14871da177e4SLinus Torvalds BUG();
14881da177e4SLinus Torvalds }
14891da177e4SLinus Torvalds }
14901da177e4SLinus Torvalds
encode_claim_null(struct xdr_stream * xdr,const struct qstr * name)14911da177e4SLinus Torvalds static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
14921da177e4SLinus Torvalds {
14938687b63aSAl Viro __be32 *p;
14941da177e4SLinus Torvalds
149513c65ce9SBenny Halevy p = reserve_space(xdr, 4);
149634558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
14971da177e4SLinus Torvalds encode_string(xdr, name->len, name->name);
14981da177e4SLinus Torvalds }
14991da177e4SLinus Torvalds
encode_claim_previous(struct xdr_stream * xdr,fmode_t type)1500bd7bf9d5STrond Myklebust static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
15011da177e4SLinus Torvalds {
15028687b63aSAl Viro __be32 *p;
15031da177e4SLinus Torvalds
150413c65ce9SBenny Halevy p = reserve_space(xdr, 4);
150534558513SBenny Halevy *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
15061da177e4SLinus Torvalds encode_delegation_type(xdr, type);
15071da177e4SLinus Torvalds }
15081da177e4SLinus Torvalds
encode_claim_delegate_cur(struct xdr_stream * xdr,const struct qstr * name,const nfs4_stateid * stateid)15091da177e4SLinus Torvalds static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
15101da177e4SLinus Torvalds {
15118687b63aSAl Viro __be32 *p;
15121da177e4SLinus Torvalds
1513ea9d23f5STrond Myklebust p = reserve_space(xdr, 4);
1514ea9d23f5STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1515ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid);
15161da177e4SLinus Torvalds encode_string(xdr, name->len, name->name);
15171da177e4SLinus Torvalds }
15181da177e4SLinus Torvalds
encode_claim_fh(struct xdr_stream * xdr)1519d9fc6619STrond Myklebust static inline void encode_claim_fh(struct xdr_stream *xdr)
1520d9fc6619STrond Myklebust {
1521d9fc6619STrond Myklebust __be32 *p;
1522d9fc6619STrond Myklebust
1523d9fc6619STrond Myklebust p = reserve_space(xdr, 4);
1524d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1525d9fc6619STrond Myklebust }
1526d9fc6619STrond Myklebust
encode_claim_delegate_cur_fh(struct xdr_stream * xdr,const nfs4_stateid * stateid)1527d9fc6619STrond Myklebust static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1528d9fc6619STrond Myklebust {
1529d9fc6619STrond Myklebust __be32 *p;
1530d9fc6619STrond Myklebust
1531d9fc6619STrond Myklebust p = reserve_space(xdr, 4);
1532d9fc6619STrond Myklebust *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1533d9fc6619STrond Myklebust encode_nfs4_stateid(xdr, stateid);
1534d9fc6619STrond Myklebust }
1535d9fc6619STrond Myklebust
encode_open(struct xdr_stream * xdr,const struct nfs_openargs * arg,struct compound_hdr * hdr)1536cf8cdbe5SAndy Adamson static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
15371da177e4SLinus Torvalds {
1538ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
15391da177e4SLinus Torvalds encode_openhdr(xdr, arg);
15401da177e4SLinus Torvalds encode_opentype(xdr, arg);
15411da177e4SLinus Torvalds switch (arg->claim) {
15421da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_NULL:
15431da177e4SLinus Torvalds encode_claim_null(xdr, arg->name);
15441da177e4SLinus Torvalds break;
15451da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_PREVIOUS:
15461da177e4SLinus Torvalds encode_claim_previous(xdr, arg->u.delegation_type);
15471da177e4SLinus Torvalds break;
15481da177e4SLinus Torvalds case NFS4_OPEN_CLAIM_DELEGATE_CUR:
15491da177e4SLinus Torvalds encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
15501da177e4SLinus Torvalds break;
1551d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_FH:
1552d9fc6619STrond Myklebust encode_claim_fh(xdr);
1553d9fc6619STrond Myklebust break;
1554d9fc6619STrond Myklebust case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1555d9fc6619STrond Myklebust encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1556d9fc6619STrond Myklebust break;
15571da177e4SLinus Torvalds default:
15581da177e4SLinus Torvalds BUG();
15591da177e4SLinus Torvalds }
15601da177e4SLinus Torvalds }
15611da177e4SLinus Torvalds
encode_open_confirm(struct xdr_stream * xdr,const struct nfs_open_confirmargs * arg,struct compound_hdr * hdr)1562cf8cdbe5SAndy Adamson static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
15631da177e4SLinus Torvalds {
1564ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
1565ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, arg->stateid);
15664ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid);
15671da177e4SLinus Torvalds }
15681da177e4SLinus Torvalds
encode_open_downgrade(struct xdr_stream * xdr,const struct nfs_closeargs * arg,struct compound_hdr * hdr)1569cf8cdbe5SAndy Adamson static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
15701da177e4SLinus Torvalds {
1571ab19b481STrond Myklebust encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
1572566fcec6STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid);
15734ade9821STrond Myklebust encode_nfs4_seqid(xdr, arg->seqid);
15746ae37339STrond Myklebust encode_share_access(xdr, arg->share_access);
15751da177e4SLinus Torvalds }
15761da177e4SLinus Torvalds
1577cf8cdbe5SAndy Adamson static void
encode_putfh(struct xdr_stream * xdr,const struct nfs_fh * fh,struct compound_hdr * hdr)1578d017931cSAndy Adamson encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
15791da177e4SLinus Torvalds {
1580ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
15816fdfb0bcSTrond Myklebust encode_string(xdr, fh->size, fh->data);
15821da177e4SLinus Torvalds }
15831da177e4SLinus Torvalds
encode_putrootfh(struct xdr_stream * xdr,struct compound_hdr * hdr)1584cf8cdbe5SAndy Adamson static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
15851da177e4SLinus Torvalds {
1586ab19b481STrond Myklebust encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
15871da177e4SLinus Torvalds }
15881da177e4SLinus Torvalds
encode_read(struct xdr_stream * xdr,const struct nfs_pgio_args * args,struct compound_hdr * hdr)15893c6b899cSAnna Schumaker static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
15903c6b899cSAnna Schumaker struct compound_hdr *hdr)
15911da177e4SLinus Torvalds {
15928687b63aSAl Viro __be32 *p;
15931da177e4SLinus Torvalds
1594ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
15959b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid);
15961da177e4SLinus Torvalds
159713c65ce9SBenny Halevy p = reserve_space(xdr, 12);
1598b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset);
159934558513SBenny Halevy *p = cpu_to_be32(args->count);
16001da177e4SLinus Torvalds }
16011da177e4SLinus Torvalds
encode_readdir(struct xdr_stream * xdr,const struct nfs4_readdir_arg * readdir,struct rpc_rqst * req,struct compound_hdr * hdr)1602cf8cdbe5SAndy Adamson static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
16031da177e4SLinus Torvalds {
1604aa9c2669SDavid Quigley uint32_t attrs[3] = {
160528331a46STrond Myklebust FATTR4_WORD0_RDATTR_ERROR,
160628331a46STrond Myklebust FATTR4_WORD1_MOUNTED_ON_FILEID,
160728331a46STrond Myklebust };
1608c49c6894STrond Myklebust uint32_t dircount = readdir->count;
1609c49c6894STrond Myklebust uint32_t maxcount = readdir->count;
1610cd93710eSChuck Lever __be32 *p, verf[2];
1611d204c5d2STrond Myklebust uint32_t attrlen = 0;
1612d204c5d2STrond Myklebust unsigned int i;
16131da177e4SLinus Torvalds
161482f2e547SBryan Schumaker if (readdir->plus) {
161582f2e547SBryan Schumaker attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
161628331a46STrond Myklebust FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
161782f2e547SBryan Schumaker attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
161882f2e547SBryan Schumaker FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
161982f2e547SBryan Schumaker FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
162082f2e547SBryan Schumaker FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
1621d204c5d2STrond Myklebust attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
162282f2e547SBryan Schumaker }
162328331a46STrond Myklebust /* Use mounted_on_fileid only if the server supports it */
162428331a46STrond Myklebust if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
162528331a46STrond Myklebust attrs[0] |= FATTR4_WORD0_FILEID;
1626d204c5d2STrond Myklebust for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1627d204c5d2STrond Myklebust attrs[i] &= readdir->bitmask[i];
1628d204c5d2STrond Myklebust if (attrs[i] != 0)
1629d204c5d2STrond Myklebust attrlen = i+1;
1630d204c5d2STrond Myklebust }
16316f7a35bdSTrond Myklebust
1632475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
1633ff2eb681STrond Myklebust encode_uint64(xdr, readdir->cookie);
1634cd93710eSChuck Lever encode_nfs4_verifier(xdr, &readdir->verifier);
1635d204c5d2STrond Myklebust p = reserve_space(xdr, 12 + (attrlen << 2));
16366f7a35bdSTrond Myklebust *p++ = cpu_to_be32(dircount);
1637c49c6894STrond Myklebust *p++ = cpu_to_be32(maxcount);
1638d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrlen);
1639d204c5d2STrond Myklebust for (i = 0; i < attrlen; i++)
1640d204c5d2STrond Myklebust *p++ = cpu_to_be32(attrs[i]);
1641cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf));
1642aa9c2669SDavid Quigley
1643aa9c2669SDavid Quigley dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
164444109241SFred Isaman __func__,
1645eadf4598STrond Myklebust (unsigned long long)readdir->cookie,
1646cd93710eSChuck Lever verf[0], verf[1],
1647eadf4598STrond Myklebust attrs[0] & readdir->bitmask[0],
1648aa9c2669SDavid Quigley attrs[1] & readdir->bitmask[1],
1649aa9c2669SDavid Quigley attrs[2] & readdir->bitmask[2]);
16501da177e4SLinus Torvalds }
16511da177e4SLinus Torvalds
encode_readlink(struct xdr_stream * xdr,const struct nfs4_readlink * readlink,struct rpc_rqst * req,struct compound_hdr * hdr)1652cf8cdbe5SAndy Adamson static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
16531da177e4SLinus Torvalds {
1654ab19b481STrond Myklebust encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
16551da177e4SLinus Torvalds }
16561da177e4SLinus Torvalds
encode_remove(struct xdr_stream * xdr,const struct qstr * name,struct compound_hdr * hdr)1657cf8cdbe5SAndy Adamson static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
16581da177e4SLinus Torvalds {
1659ab19b481STrond Myklebust encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
16606fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name);
16611da177e4SLinus Torvalds }
16621da177e4SLinus Torvalds
encode_rename(struct xdr_stream * xdr,const struct qstr * oldname,const struct qstr * newname,struct compound_hdr * hdr)1663cf8cdbe5SAndy Adamson static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
16641da177e4SLinus Torvalds {
1665ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
1666811652bdSBenny Halevy encode_string(xdr, oldname->len, oldname->name);
1667811652bdSBenny Halevy encode_string(xdr, newname->len, newname->name);
16681da177e4SLinus Torvalds }
16691da177e4SLinus Torvalds
encode_renew(struct xdr_stream * xdr,clientid4 clid,struct compound_hdr * hdr)1670bb4dae5eSChuck Lever static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1671bb4dae5eSChuck Lever struct compound_hdr *hdr)
16721da177e4SLinus Torvalds {
1673475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
1674ff2eb681STrond Myklebust encode_uint64(xdr, clid);
16751da177e4SLinus Torvalds }
16761da177e4SLinus Torvalds
1677cf8cdbe5SAndy Adamson static void
encode_restorefh(struct xdr_stream * xdr,struct compound_hdr * hdr)1678d017931cSAndy Adamson encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
167956ae19f3STrond Myklebust {
1680ab19b481STrond Myklebust encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
168156ae19f3STrond Myklebust }
168256ae19f3STrond Myklebust
nfs4_acltype_to_bitmap(enum nfs4_acl_type type,__u32 bitmap[2])1683db145db0STrond Myklebust static void nfs4_acltype_to_bitmap(enum nfs4_acl_type type, __u32 bitmap[2])
1684db145db0STrond Myklebust {
1685db145db0STrond Myklebust switch (type) {
1686db145db0STrond Myklebust default:
1687db145db0STrond Myklebust bitmap[0] = FATTR4_WORD0_ACL;
1688db145db0STrond Myklebust bitmap[1] = 0;
1689db145db0STrond Myklebust break;
1690db145db0STrond Myklebust case NFS4ACL_DACL:
1691db145db0STrond Myklebust bitmap[0] = 0;
1692db145db0STrond Myklebust bitmap[1] = FATTR4_WORD1_DACL;
1693db145db0STrond Myklebust break;
1694db145db0STrond Myklebust case NFS4ACL_SACL:
1695db145db0STrond Myklebust bitmap[0] = 0;
1696db145db0STrond Myklebust bitmap[1] = FATTR4_WORD1_SACL;
1697db145db0STrond Myklebust }
1698db145db0STrond Myklebust }
1699db145db0STrond Myklebust
encode_setacl(struct xdr_stream * xdr,const struct nfs_setaclargs * arg,struct compound_hdr * hdr)1700db145db0STrond Myklebust static void encode_setacl(struct xdr_stream *xdr,
1701db145db0STrond Myklebust const struct nfs_setaclargs *arg,
1702fcc85819SChristoph Hellwig struct compound_hdr *hdr)
170323ec6965SJ. Bruce Fields {
1704db145db0STrond Myklebust __u32 bitmap[2];
1705db145db0STrond Myklebust
1706db145db0STrond Myklebust nfs4_acltype_to_bitmap(arg->acl_type, bitmap);
170723ec6965SJ. Bruce Fields
1708ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
1709ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &zero_stateid);
1710db145db0STrond Myklebust xdr_encode_bitmap4(xdr, bitmap, ARRAY_SIZE(bitmap));
1711db145db0STrond Myklebust encode_uint32(xdr, arg->acl_len);
17128fbcf237SAndreas Gruenbacher xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
171323ec6965SJ. Bruce Fields }
171423ec6965SJ. Bruce Fields
1715cf8cdbe5SAndy Adamson static void
encode_savefh(struct xdr_stream * xdr,struct compound_hdr * hdr)1716d017931cSAndy Adamson encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
17171da177e4SLinus Torvalds {
1718ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
17191da177e4SLinus Torvalds }
17201da177e4SLinus Torvalds
encode_setattr(struct xdr_stream * xdr,const struct nfs_setattrargs * arg,const struct nfs_server * server,struct compound_hdr * hdr)1721cf8cdbe5SAndy Adamson static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
17221da177e4SLinus Torvalds {
1723ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
1724ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &arg->stateid);
172528cf22d0STrond Myklebust encode_attrs(xdr, arg->iap, arg->label, NULL, server,
172628cf22d0STrond Myklebust server->attr_bitmask);
17271da177e4SLinus Torvalds }
17281da177e4SLinus Torvalds
encode_setclientid(struct xdr_stream * xdr,const struct nfs4_setclientid * setclientid,struct compound_hdr * hdr)1729cf8cdbe5SAndy Adamson static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
17301da177e4SLinus Torvalds {
17318687b63aSAl Viro __be32 *p;
17321da177e4SLinus Torvalds
173370019514STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
1734cd93710eSChuck Lever encode_nfs4_verifier(xdr, setclientid->sc_verifier);
17351da177e4SLinus Torvalds
17363a6bb738SJeff Layton encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
17373a6bb738SJeff Layton setclientid->sc_clnt->cl_owner_id);
173813c65ce9SBenny Halevy p = reserve_space(xdr, 4);
173934558513SBenny Halevy *p = cpu_to_be32(setclientid->sc_prog);
17401da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
17411da177e4SLinus Torvalds encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
174213c65ce9SBenny Halevy p = reserve_space(xdr, 4);
17433a6bb738SJeff Layton *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
17441da177e4SLinus Torvalds }
17451da177e4SLinus Torvalds
encode_setclientid_confirm(struct xdr_stream * xdr,const struct nfs4_setclientid_res * arg,struct compound_hdr * hdr)1746bb8b27e5STrond Myklebust static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
17471da177e4SLinus Torvalds {
1748475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1749475d4ba0STrond Myklebust decode_setclientid_confirm_maxsz, hdr);
1750ff2eb681STrond Myklebust encode_uint64(xdr, arg->clientid);
1751cd93710eSChuck Lever encode_nfs4_verifier(xdr, &arg->confirm);
17521da177e4SLinus Torvalds }
17531da177e4SLinus Torvalds
encode_write(struct xdr_stream * xdr,const struct nfs_pgio_args * args,struct compound_hdr * hdr)17543c6b899cSAnna Schumaker static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
17553c6b899cSAnna Schumaker struct compound_hdr *hdr)
17561da177e4SLinus Torvalds {
17578687b63aSAl Viro __be32 *p;
17581da177e4SLinus Torvalds
1759ab19b481STrond Myklebust encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
17609b206149STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid);
17611da177e4SLinus Torvalds
176213c65ce9SBenny Halevy p = reserve_space(xdr, 16);
1763b95be5a9SBenny Halevy p = xdr_encode_hyper(p, args->offset);
1764e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->stable);
176534558513SBenny Halevy *p = cpu_to_be32(args->count);
17661da177e4SLinus Torvalds
17671da177e4SLinus Torvalds xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
17681da177e4SLinus Torvalds }
17691da177e4SLinus Torvalds
encode_delegreturn(struct xdr_stream * xdr,const nfs4_stateid * stateid,struct compound_hdr * hdr)1770cf8cdbe5SAndy Adamson static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
17711da177e4SLinus Torvalds {
1772ab19b481STrond Myklebust encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
1773ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, stateid);
17741da177e4SLinus Torvalds }
17759b7b9fccSAndy Adamson
encode_secinfo(struct xdr_stream * xdr,const struct qstr * name,struct compound_hdr * hdr)17765a5ea0d4SBryan Schumaker static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
17775a5ea0d4SBryan Schumaker {
1778ab19b481STrond Myklebust encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
17796fdfb0bcSTrond Myklebust encode_string(xdr, name->len, name->name);
17805a5ea0d4SBryan Schumaker }
17815a5ea0d4SBryan Schumaker
178299fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
17839b7b9fccSAndy Adamson /* NFSv4.1 operations */
encode_bind_conn_to_session(struct xdr_stream * xdr,const struct nfs41_bind_conn_to_session_args * args,struct compound_hdr * hdr)17847c44f1aeSWeston Andros Adamson static void encode_bind_conn_to_session(struct xdr_stream *xdr,
1785fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args,
17867c44f1aeSWeston Andros Adamson struct compound_hdr *hdr)
17877c44f1aeSWeston Andros Adamson {
17887c44f1aeSWeston Andros Adamson __be32 *p;
17897c44f1aeSWeston Andros Adamson
17907c44f1aeSWeston Andros Adamson encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
17917c44f1aeSWeston Andros Adamson decode_bind_conn_to_session_maxsz, hdr);
179271a097c6STrond Myklebust encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
17937c44f1aeSWeston Andros Adamson p = xdr_reserve_space(xdr, 8);
179471a097c6STrond Myklebust *p++ = cpu_to_be32(args->dir);
179571a097c6STrond Myklebust *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
17967c44f1aeSWeston Andros Adamson }
17977c44f1aeSWeston Andros Adamson
encode_op_map(struct xdr_stream * xdr,const struct nfs4_op_map * op_map)1798fcc85819SChristoph Hellwig static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
17992031cd1aSWeston Andros Adamson {
18002031cd1aSWeston Andros Adamson unsigned int i;
18012031cd1aSWeston Andros Adamson encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
18022031cd1aSWeston Andros Adamson for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
18032031cd1aSWeston Andros Adamson encode_uint32(xdr, op_map->u.words[i]);
18042031cd1aSWeston Andros Adamson }
18052031cd1aSWeston Andros Adamson
encode_exchange_id(struct xdr_stream * xdr,const struct nfs41_exchange_id_args * args,struct compound_hdr * hdr)180699fe60d0SBenny Halevy static void encode_exchange_id(struct xdr_stream *xdr,
1807fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args,
180899fe60d0SBenny Halevy struct compound_hdr *hdr)
180999fe60d0SBenny Halevy {
181099fe60d0SBenny Halevy __be32 *p;
1811d751f748SJim Rees char impl_name[IMPL_NAME_LIMIT];
1812db8ac8baSWeston Andros Adamson int len = 0;
181399fe60d0SBenny Halevy
181470019514STrond Myklebust encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
1815fd40559cSTrond Myklebust encode_nfs4_verifier(xdr, &args->verifier);
181699fe60d0SBenny Halevy
18173a6bb738SJeff Layton encode_string(xdr, strlen(args->client->cl_owner_id),
18183a6bb738SJeff Layton args->client->cl_owner_id);
181999fe60d0SBenny Halevy
18202031cd1aSWeston Andros Adamson encode_uint32(xdr, args->flags);
18212031cd1aSWeston Andros Adamson encode_uint32(xdr, args->state_protect.how);
18222031cd1aSWeston Andros Adamson
18232031cd1aSWeston Andros Adamson switch (args->state_protect.how) {
18242031cd1aSWeston Andros Adamson case SP4_NONE:
18252031cd1aSWeston Andros Adamson break;
18262031cd1aSWeston Andros Adamson case SP4_MACH_CRED:
18272031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.enforce);
18282031cd1aSWeston Andros Adamson encode_op_map(xdr, &args->state_protect.allow);
18292031cd1aSWeston Andros Adamson break;
18302031cd1aSWeston Andros Adamson default:
18312031cd1aSWeston Andros Adamson WARN_ON_ONCE(1);
18322031cd1aSWeston Andros Adamson break;
18332031cd1aSWeston Andros Adamson }
1834db8ac8baSWeston Andros Adamson
1835db8ac8baSWeston Andros Adamson if (send_implementation_id &&
1836db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1837db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
1838d751f748SJim Rees <= sizeof(impl_name) + 1)
1839db8ac8baSWeston Andros Adamson len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1840db8ac8baSWeston Andros Adamson utsname()->sysname, utsname()->release,
1841db8ac8baSWeston Andros Adamson utsname()->version, utsname()->machine);
1842db8ac8baSWeston Andros Adamson
1843db8ac8baSWeston Andros Adamson if (len > 0) {
18442031cd1aSWeston Andros Adamson encode_uint32(xdr, 1); /* implementation id array length=1 */
1845db8ac8baSWeston Andros Adamson
1846db8ac8baSWeston Andros Adamson encode_string(xdr,
1847db8ac8baSWeston Andros Adamson sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1848db8ac8baSWeston Andros Adamson CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1849db8ac8baSWeston Andros Adamson encode_string(xdr, len, impl_name);
1850db8ac8baSWeston Andros Adamson /* just send zeros for nii_date - the date is in nii_name */
1851db8ac8baSWeston Andros Adamson p = reserve_space(xdr, 12);
1852db8ac8baSWeston Andros Adamson p = xdr_encode_hyper(p, 0);
1853db8ac8baSWeston Andros Adamson *p = cpu_to_be32(0);
1854db8ac8baSWeston Andros Adamson } else
18552031cd1aSWeston Andros Adamson encode_uint32(xdr, 0); /* implementation id array length=0 */
185699fe60d0SBenny Halevy }
1857fc931582SAndy Adamson
encode_create_session(struct xdr_stream * xdr,const struct nfs41_create_session_args * args,struct compound_hdr * hdr)1858fc931582SAndy Adamson static void encode_create_session(struct xdr_stream *xdr,
1859fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args,
1860fc931582SAndy Adamson struct compound_hdr *hdr)
1861fc931582SAndy Adamson {
1862fc931582SAndy Adamson __be32 *p;
1863fc931582SAndy Adamson struct nfs_client *clp = args->client;
186489f0ff38STrond Myklebust struct rpc_clnt *clnt = clp->cl_rpcclient;
1865f092075dSChuck Lever struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
18668e0d46e1SMike Sager u32 max_resp_sz_cached;
18678e0d46e1SMike Sager
18688e0d46e1SMike Sager /*
18698e0d46e1SMike Sager * Assumes OPEN is the biggest non-idempotent compound.
18708e0d46e1SMike Sager * 2 is the verifier.
18718e0d46e1SMike Sager */
187235c036efSJ. Bruce Fields max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
187335c036efSJ. Bruce Fields * XDR_UNIT + RPC_MAX_AUTH_SIZE;
1874fc931582SAndy Adamson
1875475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
187689f0ff38STrond Myklebust p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
187779969dd1STrond Myklebust p = xdr_encode_hyper(p, args->clientid);
187879969dd1STrond Myklebust *p++ = cpu_to_be32(args->seqid); /*Sequence id */
1879e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->flags); /*flags */
1880fc931582SAndy Adamson
1881fc931582SAndy Adamson /* Fore Channel */
1882c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */
1883e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1884e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
18858e0d46e1SMike Sager *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
1886e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1887e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1888e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1889fc931582SAndy Adamson
1890fc931582SAndy Adamson /* Back Channel */
1891c9c30dd5SBenny Halevy *p++ = cpu_to_be32(0); /* header padding size */
1892e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1893e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1894e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1895e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1896e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1897e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
1898fc931582SAndy Adamson
1899e75bc1c8SBenny Halevy *p++ = cpu_to_be32(args->cb_program); /* cb_program */
1900e75bc1c8SBenny Halevy *p++ = cpu_to_be32(1);
1901e75bc1c8SBenny Halevy *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
1902fc931582SAndy Adamson
1903fc931582SAndy Adamson /* authsys_parms rfc1831 */
19042f86e091SDeepa Dinamani *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
190589f0ff38STrond Myklebust p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
1906e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* UID */
1907e75bc1c8SBenny Halevy *p++ = cpu_to_be32(0); /* GID */
190834558513SBenny Halevy *p = cpu_to_be32(0); /* No more gids */
1909fc931582SAndy Adamson }
19100f3e66c6SAndy Adamson
encode_destroy_session(struct xdr_stream * xdr,const struct nfs4_session * session,struct compound_hdr * hdr)19110f3e66c6SAndy Adamson static void encode_destroy_session(struct xdr_stream *xdr,
1912fcc85819SChristoph Hellwig const struct nfs4_session *session,
19130f3e66c6SAndy Adamson struct compound_hdr *hdr)
19140f3e66c6SAndy Adamson {
1915475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1916475d4ba0STrond Myklebust encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
19170f3e66c6SAndy Adamson }
191818019753SRicardo Labiaga
encode_destroy_clientid(struct xdr_stream * xdr,uint64_t clientid,struct compound_hdr * hdr)191966245539STrond Myklebust static void encode_destroy_clientid(struct xdr_stream *xdr,
192066245539STrond Myklebust uint64_t clientid,
192166245539STrond Myklebust struct compound_hdr *hdr)
192266245539STrond Myklebust {
192366245539STrond Myklebust encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
192466245539STrond Myklebust encode_uint64(xdr, clientid);
192566245539STrond Myklebust }
192666245539STrond Myklebust
encode_reclaim_complete(struct xdr_stream * xdr,const struct nfs41_reclaim_complete_args * args,struct compound_hdr * hdr)192718019753SRicardo Labiaga static void encode_reclaim_complete(struct xdr_stream *xdr,
1928fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args,
192918019753SRicardo Labiaga struct compound_hdr *hdr)
193018019753SRicardo Labiaga {
1931475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1932475d4ba0STrond Myklebust encode_uint32(xdr, args->one_fs);
193318019753SRicardo Labiaga }
193499fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
193599fe60d0SBenny Halevy
encode_sequence(struct xdr_stream * xdr,const struct nfs4_sequence_args * args,struct compound_hdr * hdr)19369b7b9fccSAndy Adamson static void encode_sequence(struct xdr_stream *xdr,
19379b7b9fccSAndy Adamson const struct nfs4_sequence_args *args,
19389b7b9fccSAndy Adamson struct compound_hdr *hdr)
19399b7b9fccSAndy Adamson {
19409b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
19412b2fa717STrond Myklebust struct nfs4_session *session;
1942fc01cea9SAndy Adamson struct nfs4_slot_table *tp;
19432b2fa717STrond Myklebust struct nfs4_slot *slot = args->sa_slot;
1944fc01cea9SAndy Adamson __be32 *p;
19459b7b9fccSAndy Adamson
19462b2fa717STrond Myklebust tp = slot->table;
19472b2fa717STrond Myklebust session = tp->session;
19483bd2384aSChuck Lever if (!session)
19493bd2384aSChuck Lever return;
1950fc01cea9SAndy Adamson
1951475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
1952fc01cea9SAndy Adamson
1953fc01cea9SAndy Adamson /*
1954fc01cea9SAndy Adamson * Sessionid + seqid + slotid + max slotid + cache_this
1955fc01cea9SAndy Adamson */
1956fc01cea9SAndy Adamson dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1957fc01cea9SAndy Adamson "max_slotid=%d cache_this=%d\n",
1958fc01cea9SAndy Adamson __func__,
1959fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[0],
1960fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[1],
1961fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[2],
1962fc01cea9SAndy Adamson ((u32 *)session->sess_id.data)[3],
19632b2fa717STrond Myklebust slot->seq_nr, slot->slot_nr,
1964fc01cea9SAndy Adamson tp->highest_used_slotid, args->sa_cache_this);
1965475d4ba0STrond Myklebust p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
196693f0cf25SBenny Halevy p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
1967e75bc1c8SBenny Halevy *p++ = cpu_to_be32(slot->seq_nr);
19682b2fa717STrond Myklebust *p++ = cpu_to_be32(slot->slot_nr);
1969e75bc1c8SBenny Halevy *p++ = cpu_to_be32(tp->highest_used_slotid);
197034558513SBenny Halevy *p = cpu_to_be32(args->sa_cache_this);
19719b7b9fccSAndy Adamson #endif /* CONFIG_NFS_V4_1 */
19729b7b9fccSAndy Adamson }
19739b7b9fccSAndy Adamson
1974b1f69b75SAndy Adamson #ifdef CONFIG_NFS_V4_1
1975b1f69b75SAndy Adamson static void
encode_getdeviceinfo(struct xdr_stream * xdr,const struct nfs4_getdeviceinfo_args * args,struct compound_hdr * hdr)1976b1f69b75SAndy Adamson encode_getdeviceinfo(struct xdr_stream *xdr,
1977b1f69b75SAndy Adamson const struct nfs4_getdeviceinfo_args *args,
1978b1f69b75SAndy Adamson struct compound_hdr *hdr)
1979b1f69b75SAndy Adamson {
1980b1f69b75SAndy Adamson __be32 *p;
1981b1f69b75SAndy Adamson
1982475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
198384c9dee3SChristoph Hellwig p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
1984b1f69b75SAndy Adamson p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1985b1f69b75SAndy Adamson NFS4_DEVICEID4_SIZE);
1986b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->pdev->layout_type);
1987f1c097beSAndy Adamson *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
198884c9dee3SChristoph Hellwig
198984c9dee3SChristoph Hellwig p = reserve_space(xdr, 4 + 4);
199084c9dee3SChristoph Hellwig *p++ = cpu_to_be32(1); /* bitmap length */
19914e590803STrond Myklebust *p++ = cpu_to_be32(args->notify_types);
1992b1f69b75SAndy Adamson }
1993b1f69b75SAndy Adamson
1994b1f69b75SAndy Adamson static void
encode_layoutget(struct xdr_stream * xdr,const struct nfs4_layoutget_args * args,struct compound_hdr * hdr)1995b1f69b75SAndy Adamson encode_layoutget(struct xdr_stream *xdr,
1996b1f69b75SAndy Adamson const struct nfs4_layoutget_args *args,
1997b1f69b75SAndy Adamson struct compound_hdr *hdr)
1998b1f69b75SAndy Adamson {
1999b1f69b75SAndy Adamson __be32 *p;
2000b1f69b75SAndy Adamson
2001475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
2002475d4ba0STrond Myklebust p = reserve_space(xdr, 36);
2003b1f69b75SAndy Adamson *p++ = cpu_to_be32(0); /* Signal layout available */
2004b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->type);
2005b1f69b75SAndy Adamson *p++ = cpu_to_be32(args->range.iomode);
2006b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.offset);
2007b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->range.length);
2008b1f69b75SAndy Adamson p = xdr_encode_hyper(p, args->minlength);
2009ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid);
2010475d4ba0STrond Myklebust encode_uint32(xdr, args->maxcount);
2011b1f69b75SAndy Adamson
2012b1f69b75SAndy Adamson dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
2013b1f69b75SAndy Adamson __func__,
2014b1f69b75SAndy Adamson args->type,
2015b1f69b75SAndy Adamson args->range.iomode,
2016b1f69b75SAndy Adamson (unsigned long)args->range.offset,
2017b1f69b75SAndy Adamson (unsigned long)args->range.length,
2018b1f69b75SAndy Adamson args->maxcount);
2019b1f69b75SAndy Adamson }
2020863a3c6cSAndy Adamson
2021863a3c6cSAndy Adamson static int
encode_layoutcommit(struct xdr_stream * xdr,struct inode * inode,const struct nfs4_layoutcommit_args * args,struct compound_hdr * hdr)2022863a3c6cSAndy Adamson encode_layoutcommit(struct xdr_stream *xdr,
2023ac7db726SBenny Halevy struct inode *inode,
2024fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args,
2025863a3c6cSAndy Adamson struct compound_hdr *hdr)
2026863a3c6cSAndy Adamson {
2027863a3c6cSAndy Adamson __be32 *p;
2028863a3c6cSAndy Adamson
2029863a3c6cSAndy Adamson dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2030863a3c6cSAndy Adamson NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2031863a3c6cSAndy Adamson
2032475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2033475d4ba0STrond Myklebust p = reserve_space(xdr, 20);
2034863a3c6cSAndy Adamson /* Only whole file layouts */
2035863a3c6cSAndy Adamson p = xdr_encode_hyper(p, 0); /* offset */
20363557c6c3SPeng Tao p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
2037ea9d23f5STrond Myklebust *p = cpu_to_be32(0); /* reclaim */
2038ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid);
20392e18d4d8STrond Myklebust if (args->lastbytewritten != U64_MAX) {
2040ea9d23f5STrond Myklebust p = reserve_space(xdr, 20);
2041863a3c6cSAndy Adamson *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2042863a3c6cSAndy Adamson p = xdr_encode_hyper(p, args->lastbytewritten);
20432e18d4d8STrond Myklebust } else {
20442e18d4d8STrond Myklebust p = reserve_space(xdr, 12);
20452e18d4d8STrond Myklebust *p++ = cpu_to_be32(0); /* newoffset = FALSE */
20462e18d4d8STrond Myklebust }
2047863a3c6cSAndy Adamson *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2048863a3c6cSAndy Adamson *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
2049ac7db726SBenny Halevy
20505f919c9fSChristoph Hellwig encode_uint32(xdr, args->layoutupdate_len);
205173504740STrond Myklebust if (args->layoutupdate_pages)
20525f919c9fSChristoph Hellwig xdr_write_pages(xdr, args->layoutupdate_pages, 0,
20535f919c9fSChristoph Hellwig args->layoutupdate_len);
2054863a3c6cSAndy Adamson
2055863a3c6cSAndy Adamson return 0;
2056863a3c6cSAndy Adamson }
2057cbe82603SBenny Halevy
2058cbe82603SBenny Halevy static void
encode_layoutreturn(struct xdr_stream * xdr,const struct nfs4_layoutreturn_args * args,struct compound_hdr * hdr)2059cbe82603SBenny Halevy encode_layoutreturn(struct xdr_stream *xdr,
2060cbe82603SBenny Halevy const struct nfs4_layoutreturn_args *args,
2061cbe82603SBenny Halevy struct compound_hdr *hdr)
2062cbe82603SBenny Halevy {
2063cbe82603SBenny Halevy __be32 *p;
2064cbe82603SBenny Halevy
2065475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2066475d4ba0STrond Myklebust p = reserve_space(xdr, 16);
2067cbe82603SBenny Halevy *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2068cbe82603SBenny Halevy *p++ = cpu_to_be32(args->layout_type);
206915eb67c1SPeng Tao *p++ = cpu_to_be32(args->range.iomode);
2070cbe82603SBenny Halevy *p = cpu_to_be32(RETURN_FILE);
2071ea9d23f5STrond Myklebust p = reserve_space(xdr, 16);
207215eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.offset);
207315eb67c1SPeng Tao p = xdr_encode_hyper(p, args->range.length);
2074cbe82603SBenny Halevy spin_lock(&args->inode->i_lock);
2075ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, &args->stateid);
2076cbe82603SBenny Halevy spin_unlock(&args->inode->i_lock);
20774d796d75STrond Myklebust if (args->ld_private->ops && args->ld_private->ops->encode)
20784d796d75STrond Myklebust args->ld_private->ops->encode(xdr, args, args->ld_private);
207994e5c571STrond Myklebust else
2080475d4ba0STrond Myklebust encode_uint32(xdr, 0);
2081cbe82603SBenny Halevy }
2082fca78d6dSBryan Schumaker
2083fca78d6dSBryan Schumaker static int
encode_secinfo_no_name(struct xdr_stream * xdr,const struct nfs41_secinfo_no_name_args * args,struct compound_hdr * hdr)2084fca78d6dSBryan Schumaker encode_secinfo_no_name(struct xdr_stream *xdr,
2085fca78d6dSBryan Schumaker const struct nfs41_secinfo_no_name_args *args,
2086fca78d6dSBryan Schumaker struct compound_hdr *hdr)
2087fca78d6dSBryan Schumaker {
2088475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2089475d4ba0STrond Myklebust encode_uint32(xdr, args->style);
2090fca78d6dSBryan Schumaker return 0;
2091fca78d6dSBryan Schumaker }
20927d974794SBryan Schumaker
encode_test_stateid(struct xdr_stream * xdr,const struct nfs41_test_stateid_args * args,struct compound_hdr * hdr)20937d974794SBryan Schumaker static void encode_test_stateid(struct xdr_stream *xdr,
2094fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args,
20957d974794SBryan Schumaker struct compound_hdr *hdr)
20967d974794SBryan Schumaker {
2097475d4ba0STrond Myklebust encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2098475d4ba0STrond Myklebust encode_uint32(xdr, 1);
2099ea9d23f5STrond Myklebust encode_nfs4_stateid(xdr, args->stateid);
21007d974794SBryan Schumaker }
21019aeda35fSBryan Schumaker
encode_free_stateid(struct xdr_stream * xdr,const struct nfs41_free_stateid_args * args,struct compound_hdr * hdr)21029aeda35fSBryan Schumaker static void encode_free_stateid(struct xdr_stream *xdr,
2103fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args,
21049aeda35fSBryan Schumaker struct compound_hdr *hdr)
21059aeda35fSBryan Schumaker {
2106ab19b481STrond Myklebust encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
21077c1d5faeSTrond Myklebust encode_nfs4_stateid(xdr, &args->stateid);
21089aeda35fSBryan Schumaker }
2109cf805165STrond Myklebust #else
2110cf805165STrond Myklebust static inline void
encode_layoutreturn(struct xdr_stream * xdr,const struct nfs4_layoutreturn_args * args,struct compound_hdr * hdr)2111cf805165STrond Myklebust encode_layoutreturn(struct xdr_stream *xdr,
2112cf805165STrond Myklebust const struct nfs4_layoutreturn_args *args,
2113cf805165STrond Myklebust struct compound_hdr *hdr)
2114cf805165STrond Myklebust {
2115cf805165STrond Myklebust }
211656f487f8SFred Isaman
211756f487f8SFred Isaman static void
encode_layoutget(struct xdr_stream * xdr,const struct nfs4_layoutget_args * args,struct compound_hdr * hdr)211856f487f8SFred Isaman encode_layoutget(struct xdr_stream *xdr,
211956f487f8SFred Isaman const struct nfs4_layoutget_args *args,
212056f487f8SFred Isaman struct compound_hdr *hdr)
212156f487f8SFred Isaman {
212256f487f8SFred Isaman }
2123b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
2124b1f69b75SAndy Adamson
21251da177e4SLinus Torvalds /*
21261da177e4SLinus Torvalds * END OF "GENERIC" ENCODE ROUTINES.
21271da177e4SLinus Torvalds */
21281da177e4SLinus Torvalds
nfs4_xdr_minorversion(const struct nfs4_sequence_args * args)212966cc0429SBenny Halevy static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
213066cc0429SBenny Halevy {
213166cc0429SBenny Halevy #if defined(CONFIG_NFS_V4_1)
21323bd2384aSChuck Lever struct nfs4_session *session = args->sa_slot->table->session;
21333bd2384aSChuck Lever if (session)
21343bd2384aSChuck Lever return session->clp->cl_mvops->minor_version;
213566cc0429SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
213666cc0429SBenny Halevy return 0;
213766cc0429SBenny Halevy }
213866cc0429SBenny Halevy
21391da177e4SLinus Torvalds /*
21401da177e4SLinus Torvalds * Encode an ACCESS request
21411da177e4SLinus Torvalds */
nfs4_xdr_enc_access(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)21429f06c719SChuck Lever static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2143fcc85819SChristoph Hellwig const void *data)
21441da177e4SLinus Torvalds {
2145fcc85819SChristoph Hellwig const struct nfs4_accessargs *args = data;
21461da177e4SLinus Torvalds struct compound_hdr hdr = {
214766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
21481da177e4SLinus Torvalds };
21491da177e4SLinus Torvalds
21509f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
21519f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
21529f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
21539f06c719SChuck Lever encode_access(xdr, args->access, &hdr);
21548bcbe7d9STrond Myklebust if (args->bitmask)
21559f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2156d017931cSAndy Adamson encode_nops(&hdr);
21571da177e4SLinus Torvalds }
21581da177e4SLinus Torvalds
21591da177e4SLinus Torvalds /*
21601da177e4SLinus Torvalds * Encode LOOKUP request
21611da177e4SLinus Torvalds */
nfs4_xdr_enc_lookup(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)21629f06c719SChuck Lever static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2163fcc85819SChristoph Hellwig const void *data)
21641da177e4SLinus Torvalds {
2165fcc85819SChristoph Hellwig const struct nfs4_lookup_arg *args = data;
21661da177e4SLinus Torvalds struct compound_hdr hdr = {
216766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
21681da177e4SLinus Torvalds };
21691da177e4SLinus Torvalds
21709f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
21719f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
21729f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr);
21739f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr);
21749f06c719SChuck Lever encode_getfh(xdr, &hdr);
21759f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2176d017931cSAndy Adamson encode_nops(&hdr);
21771da177e4SLinus Torvalds }
21781da177e4SLinus Torvalds
21791da177e4SLinus Torvalds /*
21805b5faaf6SJeff Layton * Encode LOOKUPP request
21815b5faaf6SJeff Layton */
nfs4_xdr_enc_lookupp(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)21825b5faaf6SJeff Layton static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
21835b5faaf6SJeff Layton const void *data)
21845b5faaf6SJeff Layton {
21855b5faaf6SJeff Layton const struct nfs4_lookupp_arg *args = data;
21865b5faaf6SJeff Layton struct compound_hdr hdr = {
21875b5faaf6SJeff Layton .minorversion = nfs4_xdr_minorversion(&args->seq_args),
21885b5faaf6SJeff Layton };
21895b5faaf6SJeff Layton
21905b5faaf6SJeff Layton encode_compound_hdr(xdr, req, &hdr);
21915b5faaf6SJeff Layton encode_sequence(xdr, &args->seq_args, &hdr);
21925b5faaf6SJeff Layton encode_putfh(xdr, args->fh, &hdr);
21935b5faaf6SJeff Layton encode_lookupp(xdr, &hdr);
21945b5faaf6SJeff Layton encode_getfh(xdr, &hdr);
21955b5faaf6SJeff Layton encode_getfattr(xdr, args->bitmask, &hdr);
21965b5faaf6SJeff Layton encode_nops(&hdr);
21975b5faaf6SJeff Layton }
21985b5faaf6SJeff Layton
21995b5faaf6SJeff Layton /*
22001da177e4SLinus Torvalds * Encode LOOKUP_ROOT request
22011da177e4SLinus Torvalds */
nfs4_xdr_enc_lookup_root(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)22029f06c719SChuck Lever static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
22039f06c719SChuck Lever struct xdr_stream *xdr,
2204fcc85819SChristoph Hellwig const void *data)
22051da177e4SLinus Torvalds {
2206fcc85819SChristoph Hellwig const struct nfs4_lookup_root_arg *args = data;
22071da177e4SLinus Torvalds struct compound_hdr hdr = {
220866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
22091da177e4SLinus Torvalds };
22101da177e4SLinus Torvalds
22119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
22129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
22139f06c719SChuck Lever encode_putrootfh(xdr, &hdr);
22149f06c719SChuck Lever encode_getfh(xdr, &hdr);
22159f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2216d017931cSAndy Adamson encode_nops(&hdr);
22171da177e4SLinus Torvalds }
22181da177e4SLinus Torvalds
22191da177e4SLinus Torvalds /*
22201da177e4SLinus Torvalds * Encode REMOVE request
22211da177e4SLinus Torvalds */
nfs4_xdr_enc_remove(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)22229f06c719SChuck Lever static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2223fcc85819SChristoph Hellwig const void *data)
22241da177e4SLinus Torvalds {
2225fcc85819SChristoph Hellwig const struct nfs_removeargs *args = data;
22261da177e4SLinus Torvalds struct compound_hdr hdr = {
222766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
22281da177e4SLinus Torvalds };
22291da177e4SLinus Torvalds
22309f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
22319f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
22329f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
22339f06c719SChuck Lever encode_remove(xdr, &args->name, &hdr);
2234d017931cSAndy Adamson encode_nops(&hdr);
22351da177e4SLinus Torvalds }
22361da177e4SLinus Torvalds
22371da177e4SLinus Torvalds /*
22381da177e4SLinus Torvalds * Encode RENAME request
22391da177e4SLinus Torvalds */
nfs4_xdr_enc_rename(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)22409f06c719SChuck Lever static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2241fcc85819SChristoph Hellwig const void *data)
22421da177e4SLinus Torvalds {
2243fcc85819SChristoph Hellwig const struct nfs_renameargs *args = data;
22441da177e4SLinus Torvalds struct compound_hdr hdr = {
224566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
22461da177e4SLinus Torvalds };
22471da177e4SLinus Torvalds
22489f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
22499f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
22509f06c719SChuck Lever encode_putfh(xdr, args->old_dir, &hdr);
22519f06c719SChuck Lever encode_savefh(xdr, &hdr);
22529f06c719SChuck Lever encode_putfh(xdr, args->new_dir, &hdr);
22539f06c719SChuck Lever encode_rename(xdr, args->old_name, args->new_name, &hdr);
2254d017931cSAndy Adamson encode_nops(&hdr);
22551da177e4SLinus Torvalds }
22561da177e4SLinus Torvalds
22571da177e4SLinus Torvalds /*
22581da177e4SLinus Torvalds * Encode LINK request
22591da177e4SLinus Torvalds */
nfs4_xdr_enc_link(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)22609f06c719SChuck Lever static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2261fcc85819SChristoph Hellwig const void *data)
22621da177e4SLinus Torvalds {
2263fcc85819SChristoph Hellwig const struct nfs4_link_arg *args = data;
22641da177e4SLinus Torvalds struct compound_hdr hdr = {
226566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
22661da177e4SLinus Torvalds };
22671da177e4SLinus Torvalds
22689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
22699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
22709f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
22719f06c719SChuck Lever encode_savefh(xdr, &hdr);
22729f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr);
22739f06c719SChuck Lever encode_link(xdr, args->name, &hdr);
22749f06c719SChuck Lever encode_restorefh(xdr, &hdr);
22759f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2276d017931cSAndy Adamson encode_nops(&hdr);
22771da177e4SLinus Torvalds }
22781da177e4SLinus Torvalds
22791da177e4SLinus Torvalds /*
22801da177e4SLinus Torvalds * Encode CREATE request
22811da177e4SLinus Torvalds */
nfs4_xdr_enc_create(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)22829f06c719SChuck Lever static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2283fcc85819SChristoph Hellwig const void *data)
22841da177e4SLinus Torvalds {
2285fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data;
22861da177e4SLinus Torvalds struct compound_hdr hdr = {
228766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
22881da177e4SLinus Torvalds };
22891da177e4SLinus Torvalds
22909f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
22919f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
22929f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr);
22939f06c719SChuck Lever encode_create(xdr, args, &hdr);
22949f06c719SChuck Lever encode_getfh(xdr, &hdr);
22959f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2296d017931cSAndy Adamson encode_nops(&hdr);
22971da177e4SLinus Torvalds }
22981da177e4SLinus Torvalds
22991da177e4SLinus Torvalds /*
23001da177e4SLinus Torvalds * Encode SYMLINK request
23011da177e4SLinus Torvalds */
nfs4_xdr_enc_symlink(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)23029f06c719SChuck Lever static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2303fcc85819SChristoph Hellwig const void *data)
23041da177e4SLinus Torvalds {
2305fcc85819SChristoph Hellwig const struct nfs4_create_arg *args = data;
2306fcc85819SChristoph Hellwig
23079f06c719SChuck Lever nfs4_xdr_enc_create(req, xdr, args);
23081da177e4SLinus Torvalds }
23091da177e4SLinus Torvalds
23101da177e4SLinus Torvalds /*
23111da177e4SLinus Torvalds * Encode GETATTR request
23121da177e4SLinus Torvalds */
nfs4_xdr_enc_getattr(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)23139f06c719SChuck Lever static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2314fcc85819SChristoph Hellwig const void *data)
23151da177e4SLinus Torvalds {
2316fcc85819SChristoph Hellwig const struct nfs4_getattr_arg *args = data;
23171da177e4SLinus Torvalds struct compound_hdr hdr = {
231866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
23191da177e4SLinus Torvalds };
23201da177e4SLinus Torvalds
23219f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
23229f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
23239f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
23249f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2325d017931cSAndy Adamson encode_nops(&hdr);
23261da177e4SLinus Torvalds }
23271da177e4SLinus Torvalds
23281da177e4SLinus Torvalds /*
23291da177e4SLinus Torvalds * Encode a CLOSE request
23301da177e4SLinus Torvalds */
nfs4_xdr_enc_close(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)23319f06c719SChuck Lever static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2332fcc85819SChristoph Hellwig const void *data)
23331da177e4SLinus Torvalds {
2334fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data;
23351da177e4SLinus Torvalds struct compound_hdr hdr = {
233666cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
23371da177e4SLinus Torvalds };
23381da177e4SLinus Torvalds
23399f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
23409f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
23419f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
2342cf805165STrond Myklebust if (args->lr_args)
2343cf805165STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr);
23443ecefc92STrond Myklebust if (args->bitmask != NULL)
23459f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2346d8d84983STrond Myklebust encode_close(xdr, args, &hdr);
2347d017931cSAndy Adamson encode_nops(&hdr);
23481da177e4SLinus Torvalds }
23491da177e4SLinus Torvalds
23501da177e4SLinus Torvalds /*
23511da177e4SLinus Torvalds * Encode an OPEN request
23521da177e4SLinus Torvalds */
nfs4_xdr_enc_open(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)23539f06c719SChuck Lever static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2354fcc85819SChristoph Hellwig const void *data)
23551da177e4SLinus Torvalds {
2356fcc85819SChristoph Hellwig const struct nfs_openargs *args = data;
23571da177e4SLinus Torvalds struct compound_hdr hdr = {
235866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
23591da177e4SLinus Torvalds };
23601da177e4SLinus Torvalds
23619f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
23629f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
23639f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
23649f06c719SChuck Lever encode_open(xdr, args, &hdr);
23659f06c719SChuck Lever encode_getfh(xdr, &hdr);
2366ae2bb032SWeston Andros Adamson if (args->access)
23676168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr);
23681549210fSTrond Myklebust encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
236956f487f8SFred Isaman if (args->lg_args) {
237056f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr);
2371cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2372cf500bacSChuck Lever args->lg_args->layout.pglen,
23739ed5af26STrond Myklebust hdr.replen - pagepad_maxsz);
237456f487f8SFred Isaman }
2375d017931cSAndy Adamson encode_nops(&hdr);
23761da177e4SLinus Torvalds }
23771da177e4SLinus Torvalds
23781da177e4SLinus Torvalds /*
23791da177e4SLinus Torvalds * Encode an OPEN_CONFIRM request
23801da177e4SLinus Torvalds */
nfs4_xdr_enc_open_confirm(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)23819f06c719SChuck Lever static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
23829f06c719SChuck Lever struct xdr_stream *xdr,
2383fcc85819SChristoph Hellwig const void *data)
23841da177e4SLinus Torvalds {
2385fcc85819SChristoph Hellwig const struct nfs_open_confirmargs *args = data;
23861da177e4SLinus Torvalds struct compound_hdr hdr = {
2387d017931cSAndy Adamson .nops = 0,
23881da177e4SLinus Torvalds };
23891da177e4SLinus Torvalds
23909f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
23919f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
23929f06c719SChuck Lever encode_open_confirm(xdr, args, &hdr);
2393d017931cSAndy Adamson encode_nops(&hdr);
23941da177e4SLinus Torvalds }
23951da177e4SLinus Torvalds
23961da177e4SLinus Torvalds /*
23971da177e4SLinus Torvalds * Encode an OPEN request with no attributes.
23981da177e4SLinus Torvalds */
nfs4_xdr_enc_open_noattr(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)23999f06c719SChuck Lever static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
24009f06c719SChuck Lever struct xdr_stream *xdr,
2401fcc85819SChristoph Hellwig const void *data)
24021da177e4SLinus Torvalds {
2403fcc85819SChristoph Hellwig const struct nfs_openargs *args = data;
24041da177e4SLinus Torvalds struct compound_hdr hdr = {
240566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
24061da177e4SLinus Torvalds };
24071da177e4SLinus Torvalds
24089f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
24099f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
24109f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
24119f06c719SChuck Lever encode_open(xdr, args, &hdr);
2412ae2bb032SWeston Andros Adamson if (args->access)
24136168f62cSWeston Andros Adamson encode_access(xdr, args->access, &hdr);
2414e23008ecSAndy Adamson encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
241556f487f8SFred Isaman if (args->lg_args) {
241656f487f8SFred Isaman encode_layoutget(xdr, args->lg_args, &hdr);
2417cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->lg_args->layout.pages, 0,
2418cf500bacSChuck Lever args->lg_args->layout.pglen,
24199ed5af26STrond Myklebust hdr.replen - pagepad_maxsz);
242056f487f8SFred Isaman }
2421d017931cSAndy Adamson encode_nops(&hdr);
24221da177e4SLinus Torvalds }
24231da177e4SLinus Torvalds
24241da177e4SLinus Torvalds /*
24251da177e4SLinus Torvalds * Encode an OPEN_DOWNGRADE request
24261da177e4SLinus Torvalds */
nfs4_xdr_enc_open_downgrade(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)24279f06c719SChuck Lever static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
24289f06c719SChuck Lever struct xdr_stream *xdr,
2429fcc85819SChristoph Hellwig const void *data)
24301da177e4SLinus Torvalds {
2431fcc85819SChristoph Hellwig const struct nfs_closeargs *args = data;
24321da177e4SLinus Torvalds struct compound_hdr hdr = {
243366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
24341da177e4SLinus Torvalds };
24351da177e4SLinus Torvalds
24369f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
24379f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
24389f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
2439b6808145STrond Myklebust if (args->lr_args)
2440b6808145STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr);
24419f06c719SChuck Lever encode_open_downgrade(xdr, args, &hdr);
2442d017931cSAndy Adamson encode_nops(&hdr);
24431da177e4SLinus Torvalds }
24441da177e4SLinus Torvalds
24451da177e4SLinus Torvalds /*
24461da177e4SLinus Torvalds * Encode a LOCK request
24471da177e4SLinus Torvalds */
nfs4_xdr_enc_lock(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)24489f06c719SChuck Lever static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2449fcc85819SChristoph Hellwig const void *data)
24501da177e4SLinus Torvalds {
2451fcc85819SChristoph Hellwig const struct nfs_lock_args *args = data;
24521da177e4SLinus Torvalds struct compound_hdr hdr = {
245366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
24541da177e4SLinus Torvalds };
24551da177e4SLinus Torvalds
24569f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
24579f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
24589f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
24599f06c719SChuck Lever encode_lock(xdr, args, &hdr);
2460d017931cSAndy Adamson encode_nops(&hdr);
24611da177e4SLinus Torvalds }
24621da177e4SLinus Torvalds
24631da177e4SLinus Torvalds /*
24641da177e4SLinus Torvalds * Encode a LOCKT request
24651da177e4SLinus Torvalds */
nfs4_xdr_enc_lockt(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)24669f06c719SChuck Lever static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2467fcc85819SChristoph Hellwig const void *data)
24681da177e4SLinus Torvalds {
2469fcc85819SChristoph Hellwig const struct nfs_lockt_args *args = data;
24701da177e4SLinus Torvalds struct compound_hdr hdr = {
247166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
24721da177e4SLinus Torvalds };
24731da177e4SLinus Torvalds
24749f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
24759f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
24769f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
24779f06c719SChuck Lever encode_lockt(xdr, args, &hdr);
2478d017931cSAndy Adamson encode_nops(&hdr);
24791da177e4SLinus Torvalds }
24801da177e4SLinus Torvalds
24811da177e4SLinus Torvalds /*
24821da177e4SLinus Torvalds * Encode a LOCKU request
24831da177e4SLinus Torvalds */
nfs4_xdr_enc_locku(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)24849f06c719SChuck Lever static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2485fcc85819SChristoph Hellwig const void *data)
24861da177e4SLinus Torvalds {
2487fcc85819SChristoph Hellwig const struct nfs_locku_args *args = data;
24881da177e4SLinus Torvalds struct compound_hdr hdr = {
248966cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
24901da177e4SLinus Torvalds };
24911da177e4SLinus Torvalds
24929f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
24939f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
24949f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
24959f06c719SChuck Lever encode_locku(xdr, args, &hdr);
2496d017931cSAndy Adamson encode_nops(&hdr);
24971da177e4SLinus Torvalds }
24981da177e4SLinus Torvalds
nfs4_xdr_enc_release_lockowner(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)24999f06c719SChuck Lever static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
25009f06c719SChuck Lever struct xdr_stream *xdr,
2501fcc85819SChristoph Hellwig const void *data)
2502d3c7b7ccSTrond Myklebust {
2503fcc85819SChristoph Hellwig const struct nfs_release_lockowner_args *args = data;
2504d3c7b7ccSTrond Myklebust struct compound_hdr hdr = {
2505d3c7b7ccSTrond Myklebust .minorversion = 0,
2506d3c7b7ccSTrond Myklebust };
2507d3c7b7ccSTrond Myklebust
25089f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
25099f06c719SChuck Lever encode_release_lockowner(xdr, &args->lock_owner, &hdr);
2510d3c7b7ccSTrond Myklebust encode_nops(&hdr);
2511d3c7b7ccSTrond Myklebust }
2512d3c7b7ccSTrond Myklebust
25131da177e4SLinus Torvalds /*
25141da177e4SLinus Torvalds * Encode a READLINK request
25151da177e4SLinus Torvalds */
nfs4_xdr_enc_readlink(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)25169f06c719SChuck Lever static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2517fcc85819SChristoph Hellwig const void *data)
25181da177e4SLinus Torvalds {
2519fcc85819SChristoph Hellwig const struct nfs4_readlink *args = data;
25201da177e4SLinus Torvalds struct compound_hdr hdr = {
252166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
25221da177e4SLinus Torvalds };
25231da177e4SLinus Torvalds
25249f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
25259f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
25269f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
25279f06c719SChuck Lever encode_readlink(xdr, args, req, &hdr);
2528e3a535e1STrond Myklebust
2529cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pages, args->pgbase,
25309ed5af26STrond Myklebust args->pglen, hdr.replen - pagepad_maxsz);
2531d017931cSAndy Adamson encode_nops(&hdr);
25321da177e4SLinus Torvalds }
25331da177e4SLinus Torvalds
25341da177e4SLinus Torvalds /*
25351da177e4SLinus Torvalds * Encode a READDIR request
25361da177e4SLinus Torvalds */
nfs4_xdr_enc_readdir(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)25379f06c719SChuck Lever static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2538fcc85819SChristoph Hellwig const void *data)
25391da177e4SLinus Torvalds {
2540fcc85819SChristoph Hellwig const struct nfs4_readdir_arg *args = data;
25411da177e4SLinus Torvalds struct compound_hdr hdr = {
254266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
25431da177e4SLinus Torvalds };
25441da177e4SLinus Torvalds
25459f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
25469f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
25479f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
25489f06c719SChuck Lever encode_readdir(xdr, args, req, &hdr);
2549d6ac02dfSTrond Myklebust
2550cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pages, args->pgbase,
25519ed5af26STrond Myklebust args->count, hdr.replen - pagepad_maxsz);
2552d017931cSAndy Adamson encode_nops(&hdr);
25531da177e4SLinus Torvalds }
25541da177e4SLinus Torvalds
25551da177e4SLinus Torvalds /*
25561da177e4SLinus Torvalds * Encode a READ request
25571da177e4SLinus Torvalds */
nfs4_xdr_enc_read(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)25589f06c719SChuck Lever static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
2559fcc85819SChristoph Hellwig const void *data)
25601da177e4SLinus Torvalds {
2561fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data;
25621da177e4SLinus Torvalds struct compound_hdr hdr = {
256366cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
25641da177e4SLinus Torvalds };
25651da177e4SLinus Torvalds
25669f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
25679f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
25689f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
25699f06c719SChuck Lever encode_read(xdr, args, &hdr);
25701da177e4SLinus Torvalds
2571cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pages, args->pgbase,
25729ed5af26STrond Myklebust args->count, hdr.replen - pagepad_maxsz);
25734f22ccc3S\"Talpey, Thomas\ req->rq_rcv_buf.flags |= XDRBUF_READ;
2574d017931cSAndy Adamson encode_nops(&hdr);
25751da177e4SLinus Torvalds }
25761da177e4SLinus Torvalds
25771da177e4SLinus Torvalds /*
25781da177e4SLinus Torvalds * Encode an SETATTR request
25791da177e4SLinus Torvalds */
nfs4_xdr_enc_setattr(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)25809f06c719SChuck Lever static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2581fcc85819SChristoph Hellwig const void *data)
25821da177e4SLinus Torvalds {
2583fcc85819SChristoph Hellwig const struct nfs_setattrargs *args = data;
25841da177e4SLinus Torvalds struct compound_hdr hdr = {
258566cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
25861da177e4SLinus Torvalds };
25871da177e4SLinus Torvalds
25889f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
25899f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
25909f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
25919f06c719SChuck Lever encode_setattr(xdr, args, args->server, &hdr);
25929f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2593d017931cSAndy Adamson encode_nops(&hdr);
25941da177e4SLinus Torvalds }
25951da177e4SLinus Torvalds
25961da177e4SLinus Torvalds /*
2597029d105eSJ. Bruce Fields * Encode a GETACL request
2598029d105eSJ. Bruce Fields */
nfs4_xdr_enc_getacl(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)25999f06c719SChuck Lever static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2600fcc85819SChristoph Hellwig const void *data)
2601029d105eSJ. Bruce Fields {
2602fcc85819SChristoph Hellwig const struct nfs_getaclargs *args = data;
2603029d105eSJ. Bruce Fields struct compound_hdr hdr = {
260466cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2605029d105eSJ. Bruce Fields };
2606db145db0STrond Myklebust __u32 nfs4_acl_bitmap[2];
260728f56694SBenny Halevy uint32_t replen;
2608029d105eSJ. Bruce Fields
2609db145db0STrond Myklebust nfs4_acltype_to_bitmap(args->acl_type, nfs4_acl_bitmap);
2610db145db0STrond Myklebust
26119f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
26129f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
26139f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
26146682c14bSJ. Bruce Fields replen = hdr.replen + op_decode_hdr_maxsz;
261537c88763STrond Myklebust encode_getattr(xdr, nfs4_acl_bitmap, NULL,
261637c88763STrond Myklebust ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
2617cf8cdbe5SAndy Adamson
2618cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->acl_pages, 0,
26199ed5af26STrond Myklebust args->acl_len, replen);
2620d017931cSAndy Adamson encode_nops(&hdr);
2621029d105eSJ. Bruce Fields }
2622029d105eSJ. Bruce Fields
2623029d105eSJ. Bruce Fields /*
26241da177e4SLinus Torvalds * Encode a WRITE request
26251da177e4SLinus Torvalds */
nfs4_xdr_enc_write(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)26269f06c719SChuck Lever static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
2627fcc85819SChristoph Hellwig const void *data)
26281da177e4SLinus Torvalds {
2629fcc85819SChristoph Hellwig const struct nfs_pgio_args *args = data;
26301da177e4SLinus Torvalds struct compound_hdr hdr = {
263166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
26321da177e4SLinus Torvalds };
26331da177e4SLinus Torvalds
26349f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
26359f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
26369f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
26379f06c719SChuck Lever encode_write(xdr, args, &hdr);
26384f22ccc3S\"Talpey, Thomas\ req->rq_snd_buf.flags |= XDRBUF_WRITE;
26397ffd1064SFred Isaman if (args->bitmask)
26409f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2641d017931cSAndy Adamson encode_nops(&hdr);
26421da177e4SLinus Torvalds }
26431da177e4SLinus Torvalds
26441da177e4SLinus Torvalds /*
26451da177e4SLinus Torvalds * a COMMIT request
26461da177e4SLinus Torvalds */
nfs4_xdr_enc_commit(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)26479f06c719SChuck Lever static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
2648fcc85819SChristoph Hellwig const void *data)
26491da177e4SLinus Torvalds {
2650fcc85819SChristoph Hellwig const struct nfs_commitargs *args = data;
26511da177e4SLinus Torvalds struct compound_hdr hdr = {
265266cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
26531da177e4SLinus Torvalds };
26541da177e4SLinus Torvalds
26559f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
26569f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
26579f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
26589f06c719SChuck Lever encode_commit(xdr, args, &hdr);
2659d017931cSAndy Adamson encode_nops(&hdr);
26601da177e4SLinus Torvalds }
26611da177e4SLinus Torvalds
26621da177e4SLinus Torvalds /*
26631da177e4SLinus Torvalds * FSINFO request
26641da177e4SLinus Torvalds */
nfs4_xdr_enc_fsinfo(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)26659f06c719SChuck Lever static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2666fcc85819SChristoph Hellwig const void *data)
26671da177e4SLinus Torvalds {
2668fcc85819SChristoph Hellwig const struct nfs4_fsinfo_arg *args = data;
26691da177e4SLinus Torvalds struct compound_hdr hdr = {
267066cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
26711da177e4SLinus Torvalds };
26721da177e4SLinus Torvalds
26739f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
26749f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
26759f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
26769f06c719SChuck Lever encode_fsinfo(xdr, args->bitmask, &hdr);
2677d017931cSAndy Adamson encode_nops(&hdr);
26781da177e4SLinus Torvalds }
26791da177e4SLinus Torvalds
26801da177e4SLinus Torvalds /*
26811da177e4SLinus Torvalds * a PATHCONF request
26821da177e4SLinus Torvalds */
nfs4_xdr_enc_pathconf(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)26839f06c719SChuck Lever static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2684fcc85819SChristoph Hellwig const void *data)
26851da177e4SLinus Torvalds {
2686fcc85819SChristoph Hellwig const struct nfs4_pathconf_arg *args = data;
26871da177e4SLinus Torvalds struct compound_hdr hdr = {
268866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
26891da177e4SLinus Torvalds };
26901da177e4SLinus Torvalds
26919f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
26929f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
26939f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
269437c88763STrond Myklebust encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
269537c88763STrond Myklebust ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
2696d017931cSAndy Adamson encode_nops(&hdr);
26971da177e4SLinus Torvalds }
26981da177e4SLinus Torvalds
26991da177e4SLinus Torvalds /*
27001da177e4SLinus Torvalds * a STATFS request
27011da177e4SLinus Torvalds */
nfs4_xdr_enc_statfs(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)27029f06c719SChuck Lever static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2703fcc85819SChristoph Hellwig const void *data)
27041da177e4SLinus Torvalds {
2705fcc85819SChristoph Hellwig const struct nfs4_statfs_arg *args = data;
27061da177e4SLinus Torvalds struct compound_hdr hdr = {
270766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
27081da177e4SLinus Torvalds };
27091da177e4SLinus Torvalds
27109f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
27119f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
27129f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
271337c88763STrond Myklebust encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
271437c88763STrond Myklebust ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
2715d017931cSAndy Adamson encode_nops(&hdr);
27161da177e4SLinus Torvalds }
27171da177e4SLinus Torvalds
27181da177e4SLinus Torvalds /*
27191da177e4SLinus Torvalds * GETATTR_BITMAP request
27201da177e4SLinus Torvalds */
nfs4_xdr_enc_server_caps(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)27219f06c719SChuck Lever static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
27229f06c719SChuck Lever struct xdr_stream *xdr,
2723fcc85819SChristoph Hellwig const void *data)
27241da177e4SLinus Torvalds {
2725fcc85819SChristoph Hellwig const struct nfs4_server_caps_arg *args = data;
27268c61282fSKinglong Mee const u32 *bitmask = args->bitmask;
27271da177e4SLinus Torvalds struct compound_hdr hdr = {
272866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
27291da177e4SLinus Torvalds };
27301da177e4SLinus Torvalds
27319f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
27329f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
27339f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr);
273437c88763STrond Myklebust encode_getattr(xdr, bitmask, NULL, 3, &hdr);
2735d017931cSAndy Adamson encode_nops(&hdr);
27361da177e4SLinus Torvalds }
27371da177e4SLinus Torvalds
27381da177e4SLinus Torvalds /*
27391da177e4SLinus Torvalds * a RENEW request
27401da177e4SLinus Torvalds */
nfs4_xdr_enc_renew(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)27419f06c719SChuck Lever static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2742fcc85819SChristoph Hellwig const void *data)
2743fcc85819SChristoph Hellwig
27441da177e4SLinus Torvalds {
2745fcc85819SChristoph Hellwig const struct nfs_client *clp = data;
27461da177e4SLinus Torvalds struct compound_hdr hdr = {
2747d017931cSAndy Adamson .nops = 0,
27481da177e4SLinus Torvalds };
27491da177e4SLinus Torvalds
27509f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
2751bb4dae5eSChuck Lever encode_renew(xdr, clp->cl_clientid, &hdr);
2752d017931cSAndy Adamson encode_nops(&hdr);
27531da177e4SLinus Torvalds }
27541da177e4SLinus Torvalds
27551da177e4SLinus Torvalds /*
27561da177e4SLinus Torvalds * a SETCLIENTID request
27571da177e4SLinus Torvalds */
nfs4_xdr_enc_setclientid(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)27589f06c719SChuck Lever static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
27599f06c719SChuck Lever struct xdr_stream *xdr,
2760fcc85819SChristoph Hellwig const void *data)
27611da177e4SLinus Torvalds {
2762fcc85819SChristoph Hellwig const struct nfs4_setclientid *sc = data;
27631da177e4SLinus Torvalds struct compound_hdr hdr = {
2764d017931cSAndy Adamson .nops = 0,
27651da177e4SLinus Torvalds };
27661da177e4SLinus Torvalds
27679f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
27689f06c719SChuck Lever encode_setclientid(xdr, sc, &hdr);
2769d017931cSAndy Adamson encode_nops(&hdr);
27701da177e4SLinus Torvalds }
27711da177e4SLinus Torvalds
27721da177e4SLinus Torvalds /*
27731da177e4SLinus Torvalds * a SETCLIENTID_CONFIRM request
27741da177e4SLinus Torvalds */
nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)27759f06c719SChuck Lever static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
27769f06c719SChuck Lever struct xdr_stream *xdr,
2777fcc85819SChristoph Hellwig const void *data)
27781da177e4SLinus Torvalds {
2779fcc85819SChristoph Hellwig const struct nfs4_setclientid_res *arg = data;
27801da177e4SLinus Torvalds struct compound_hdr hdr = {
2781d017931cSAndy Adamson .nops = 0,
27821da177e4SLinus Torvalds };
27831da177e4SLinus Torvalds
27849f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
27859f06c719SChuck Lever encode_setclientid_confirm(xdr, arg, &hdr);
2786d017931cSAndy Adamson encode_nops(&hdr);
27871da177e4SLinus Torvalds }
27881da177e4SLinus Torvalds
27891da177e4SLinus Torvalds /*
27901da177e4SLinus Torvalds * DELEGRETURN request
27911da177e4SLinus Torvalds */
nfs4_xdr_enc_delegreturn(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)27929f06c719SChuck Lever static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
27939f06c719SChuck Lever struct xdr_stream *xdr,
2794fcc85819SChristoph Hellwig const void *data)
27951da177e4SLinus Torvalds {
2796fcc85819SChristoph Hellwig const struct nfs4_delegreturnargs *args = data;
27971da177e4SLinus Torvalds struct compound_hdr hdr = {
279866cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
27991da177e4SLinus Torvalds };
28001da177e4SLinus Torvalds
28019f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
28029f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
28039f06c719SChuck Lever encode_putfh(xdr, args->fhandle, &hdr);
2804586f1c39STrond Myklebust if (args->lr_args)
2805586f1c39STrond Myklebust encode_layoutreturn(xdr, args->lr_args, &hdr);
28068ac2b422STrond Myklebust if (args->bitmask)
28079f06c719SChuck Lever encode_getfattr(xdr, args->bitmask, &hdr);
2808e144cbccSTrond Myklebust encode_delegreturn(xdr, args->stateid, &hdr);
2809d017931cSAndy Adamson encode_nops(&hdr);
28101da177e4SLinus Torvalds }
28111da177e4SLinus Torvalds
28121da177e4SLinus Torvalds /*
2813683b57b4STrond Myklebust * Encode FS_LOCATIONS request
2814683b57b4STrond Myklebust */
nfs4_xdr_enc_fs_locations(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)28159f06c719SChuck Lever static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
28169f06c719SChuck Lever struct xdr_stream *xdr,
2817fcc85819SChristoph Hellwig const void *data)
2818683b57b4STrond Myklebust {
2819fcc85819SChristoph Hellwig const struct nfs4_fs_locations_arg *args = data;
2820683b57b4STrond Myklebust struct compound_hdr hdr = {
282166cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2822683b57b4STrond Myklebust };
282328f56694SBenny Halevy uint32_t replen;
2824683b57b4STrond Myklebust
28259f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
28269f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
2827b03d735bSChuck Lever if (args->migration) {
2828b03d735bSChuck Lever encode_putfh(xdr, args->fh, &hdr);
2829b03d735bSChuck Lever replen = hdr.replen;
2830b03d735bSChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr);
2831b03d735bSChuck Lever if (args->renew)
2832b03d735bSChuck Lever encode_renew(xdr, args->clientid, &hdr);
2833b03d735bSChuck Lever } else {
28349f06c719SChuck Lever encode_putfh(xdr, args->dir_fh, &hdr);
28359f06c719SChuck Lever encode_lookup(xdr, args->name, &hdr);
2836b03d735bSChuck Lever replen = hdr.replen;
28379f06c719SChuck Lever encode_fs_locations(xdr, args->bitmask, &hdr);
2838b03d735bSChuck Lever }
2839cf8cdbe5SAndy Adamson
2840cf500bacSChuck Lever rpc_prepare_reply_pages(req, (struct page **)&args->page, 0,
28419ed5af26STrond Myklebust PAGE_SIZE, replen);
2842d017931cSAndy Adamson encode_nops(&hdr);
2843683b57b4STrond Myklebust }
2844683b57b4STrond Myklebust
28455a5ea0d4SBryan Schumaker /*
28465a5ea0d4SBryan Schumaker * Encode SECINFO request
28475a5ea0d4SBryan Schumaker */
nfs4_xdr_enc_secinfo(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)28485a5ea0d4SBryan Schumaker static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
28495a5ea0d4SBryan Schumaker struct xdr_stream *xdr,
2850fcc85819SChristoph Hellwig const void *data)
28515a5ea0d4SBryan Schumaker {
2852fcc85819SChristoph Hellwig const struct nfs4_secinfo_arg *args = data;
28535a5ea0d4SBryan Schumaker struct compound_hdr hdr = {
28545a5ea0d4SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args),
28555a5ea0d4SBryan Schumaker };
28565a5ea0d4SBryan Schumaker
28575a5ea0d4SBryan Schumaker encode_compound_hdr(xdr, req, &hdr);
28585a5ea0d4SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr);
28595a5ea0d4SBryan Schumaker encode_putfh(xdr, args->dir_fh, &hdr);
28605a5ea0d4SBryan Schumaker encode_secinfo(xdr, args->name, &hdr);
28615a5ea0d4SBryan Schumaker encode_nops(&hdr);
28625a5ea0d4SBryan Schumaker }
28635a5ea0d4SBryan Schumaker
286444c99933SChuck Lever /*
286544c99933SChuck Lever * Encode FSID_PRESENT request
286644c99933SChuck Lever */
nfs4_xdr_enc_fsid_present(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)286744c99933SChuck Lever static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
286844c99933SChuck Lever struct xdr_stream *xdr,
2869fcc85819SChristoph Hellwig const void *data)
287044c99933SChuck Lever {
2871fcc85819SChristoph Hellwig const struct nfs4_fsid_present_arg *args = data;
287244c99933SChuck Lever struct compound_hdr hdr = {
287344c99933SChuck Lever .minorversion = nfs4_xdr_minorversion(&args->seq_args),
287444c99933SChuck Lever };
287544c99933SChuck Lever
287644c99933SChuck Lever encode_compound_hdr(xdr, req, &hdr);
287744c99933SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
287844c99933SChuck Lever encode_putfh(xdr, args->fh, &hdr);
287944c99933SChuck Lever encode_getfh(xdr, &hdr);
288044c99933SChuck Lever if (args->renew)
288144c99933SChuck Lever encode_renew(xdr, args->clientid, &hdr);
288244c99933SChuck Lever encode_nops(&hdr);
288344c99933SChuck Lever }
288444c99933SChuck Lever
288599fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
288699fe60d0SBenny Halevy /*
28877c44f1aeSWeston Andros Adamson * BIND_CONN_TO_SESSION request
28887c44f1aeSWeston Andros Adamson */
nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)28897c44f1aeSWeston Andros Adamson static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
28907c44f1aeSWeston Andros Adamson struct xdr_stream *xdr,
2891fcc85819SChristoph Hellwig const void *data)
28927c44f1aeSWeston Andros Adamson {
2893fcc85819SChristoph Hellwig const struct nfs41_bind_conn_to_session_args *args = data;
28947c44f1aeSWeston Andros Adamson struct compound_hdr hdr = {
289571a097c6STrond Myklebust .minorversion = args->client->cl_mvops->minor_version,
28967c44f1aeSWeston Andros Adamson };
28977c44f1aeSWeston Andros Adamson
28987c44f1aeSWeston Andros Adamson encode_compound_hdr(xdr, req, &hdr);
289971a097c6STrond Myklebust encode_bind_conn_to_session(xdr, args, &hdr);
29007c44f1aeSWeston Andros Adamson encode_nops(&hdr);
29017c44f1aeSWeston Andros Adamson }
29027c44f1aeSWeston Andros Adamson
29037c44f1aeSWeston Andros Adamson /*
290499fe60d0SBenny Halevy * EXCHANGE_ID request
290599fe60d0SBenny Halevy */
nfs4_xdr_enc_exchange_id(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)29069f06c719SChuck Lever static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
29079f06c719SChuck Lever struct xdr_stream *xdr,
2908fcc85819SChristoph Hellwig const void *data)
290999fe60d0SBenny Halevy {
2910fcc85819SChristoph Hellwig const struct nfs41_exchange_id_args *args = data;
291199fe60d0SBenny Halevy struct compound_hdr hdr = {
2912a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version,
291399fe60d0SBenny Halevy };
291499fe60d0SBenny Halevy
29159f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
29169f06c719SChuck Lever encode_exchange_id(xdr, args, &hdr);
291799fe60d0SBenny Halevy encode_nops(&hdr);
291899fe60d0SBenny Halevy }
29192050f0ccSAndy Adamson
29202050f0ccSAndy Adamson /*
2921fc931582SAndy Adamson * a CREATE_SESSION request
2922fc931582SAndy Adamson */
nfs4_xdr_enc_create_session(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)29239f06c719SChuck Lever static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
29249f06c719SChuck Lever struct xdr_stream *xdr,
2925fcc85819SChristoph Hellwig const void *data)
2926fc931582SAndy Adamson {
2927fcc85819SChristoph Hellwig const struct nfs41_create_session_args *args = data;
2928fc931582SAndy Adamson struct compound_hdr hdr = {
2929a4432345STrond Myklebust .minorversion = args->client->cl_mvops->minor_version,
2930fc931582SAndy Adamson };
2931fc931582SAndy Adamson
29329f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
29339f06c719SChuck Lever encode_create_session(xdr, args, &hdr);
2934fc931582SAndy Adamson encode_nops(&hdr);
2935fc931582SAndy Adamson }
2936fc931582SAndy Adamson
2937fc931582SAndy Adamson /*
29380f3e66c6SAndy Adamson * a DESTROY_SESSION request
29390f3e66c6SAndy Adamson */
nfs4_xdr_enc_destroy_session(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)29409f06c719SChuck Lever static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
29419f06c719SChuck Lever struct xdr_stream *xdr,
2942fcc85819SChristoph Hellwig const void *data)
29430f3e66c6SAndy Adamson {
2944fcc85819SChristoph Hellwig const struct nfs4_session *session = data;
29450f3e66c6SAndy Adamson struct compound_hdr hdr = {
2946a4432345STrond Myklebust .minorversion = session->clp->cl_mvops->minor_version,
29470f3e66c6SAndy Adamson };
29480f3e66c6SAndy Adamson
29499f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
29509f06c719SChuck Lever encode_destroy_session(xdr, session, &hdr);
29510f3e66c6SAndy Adamson encode_nops(&hdr);
29520f3e66c6SAndy Adamson }
29530f3e66c6SAndy Adamson
29540f3e66c6SAndy Adamson /*
295566245539STrond Myklebust * a DESTROY_CLIENTID request
295666245539STrond Myklebust */
nfs4_xdr_enc_destroy_clientid(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)295766245539STrond Myklebust static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
295866245539STrond Myklebust struct xdr_stream *xdr,
2959fcc85819SChristoph Hellwig const void *data)
296066245539STrond Myklebust {
2961fcc85819SChristoph Hellwig const struct nfs_client *clp = data;
296266245539STrond Myklebust struct compound_hdr hdr = {
296366245539STrond Myklebust .minorversion = clp->cl_mvops->minor_version,
296466245539STrond Myklebust };
296566245539STrond Myklebust
296666245539STrond Myklebust encode_compound_hdr(xdr, req, &hdr);
296766245539STrond Myklebust encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
296866245539STrond Myklebust encode_nops(&hdr);
296966245539STrond Myklebust }
297066245539STrond Myklebust
297166245539STrond Myklebust /*
2972fc01cea9SAndy Adamson * a SEQUENCE request
2973fc01cea9SAndy Adamson */
nfs4_xdr_enc_sequence(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)29749f06c719SChuck Lever static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2975fcc85819SChristoph Hellwig const void *data)
2976fc01cea9SAndy Adamson {
2977fcc85819SChristoph Hellwig const struct nfs4_sequence_args *args = data;
2978fc01cea9SAndy Adamson struct compound_hdr hdr = {
2979fc01cea9SAndy Adamson .minorversion = nfs4_xdr_minorversion(args),
2980fc01cea9SAndy Adamson };
2981fc01cea9SAndy Adamson
29829f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
29839f06c719SChuck Lever encode_sequence(xdr, args, &hdr);
2984fc01cea9SAndy Adamson encode_nops(&hdr);
2985fc01cea9SAndy Adamson }
2986fc01cea9SAndy Adamson
29870efb01b2SDonald Buczek #endif
29880efb01b2SDonald Buczek
2989fc01cea9SAndy Adamson /*
29902050f0ccSAndy Adamson * a GET_LEASE_TIME request
29912050f0ccSAndy Adamson */
nfs4_xdr_enc_get_lease_time(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)29929f06c719SChuck Lever static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
29939f06c719SChuck Lever struct xdr_stream *xdr,
2994fcc85819SChristoph Hellwig const void *data)
29952050f0ccSAndy Adamson {
2996fcc85819SChristoph Hellwig const struct nfs4_get_lease_time_args *args = data;
29972050f0ccSAndy Adamson struct compound_hdr hdr = {
29982050f0ccSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
29992050f0ccSAndy Adamson };
3000dae100c2SFred Isaman const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
30012050f0ccSAndy Adamson
30029f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
30039f06c719SChuck Lever encode_sequence(xdr, &args->la_seq_args, &hdr);
30049f06c719SChuck Lever encode_putrootfh(xdr, &hdr);
30059f06c719SChuck Lever encode_fsinfo(xdr, lease_bitmap, &hdr);
30062050f0ccSAndy Adamson encode_nops(&hdr);
30072050f0ccSAndy Adamson }
300818019753SRicardo Labiaga
30090efb01b2SDonald Buczek #ifdef CONFIG_NFS_V4_1
30100efb01b2SDonald Buczek
301118019753SRicardo Labiaga /*
301218019753SRicardo Labiaga * a RECLAIM_COMPLETE request
301318019753SRicardo Labiaga */
nfs4_xdr_enc_reclaim_complete(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)30149f06c719SChuck Lever static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
30159f06c719SChuck Lever struct xdr_stream *xdr,
3016fcc85819SChristoph Hellwig const void *data)
301718019753SRicardo Labiaga {
3018fcc85819SChristoph Hellwig const struct nfs41_reclaim_complete_args *args = data;
301918019753SRicardo Labiaga struct compound_hdr hdr = {
302018019753SRicardo Labiaga .minorversion = nfs4_xdr_minorversion(&args->seq_args)
302118019753SRicardo Labiaga };
302218019753SRicardo Labiaga
30239f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
30249f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
30259f06c719SChuck Lever encode_reclaim_complete(xdr, args, &hdr);
302618019753SRicardo Labiaga encode_nops(&hdr);
302718019753SRicardo Labiaga }
302818019753SRicardo Labiaga
3029b1f69b75SAndy Adamson /*
3030b1f69b75SAndy Adamson * Encode GETDEVICEINFO request
3031b1f69b75SAndy Adamson */
nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)30329f06c719SChuck Lever static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
30339f06c719SChuck Lever struct xdr_stream *xdr,
3034fcc85819SChristoph Hellwig const void *data)
3035b1f69b75SAndy Adamson {
3036fcc85819SChristoph Hellwig const struct nfs4_getdeviceinfo_args *args = data;
3037b1f69b75SAndy Adamson struct compound_hdr hdr = {
3038b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3039b1f69b75SAndy Adamson };
3040046e5ccbSTrond Myklebust uint32_t replen;
3041b1f69b75SAndy Adamson
30429f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
30439f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
3044046e5ccbSTrond Myklebust
30459ed5af26STrond Myklebust replen = hdr.replen + op_decode_hdr_maxsz + 2;
3046046e5ccbSTrond Myklebust
30479f06c719SChuck Lever encode_getdeviceinfo(xdr, args, &hdr);
3048b1f69b75SAndy Adamson
3049046e5ccbSTrond Myklebust /* set up reply kvec. device_addr4 opaque data is read into the
3050046e5ccbSTrond Myklebust * pages */
3051cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->pdev->pages, args->pdev->pgbase,
30529ed5af26STrond Myklebust args->pdev->pglen, replen);
3053b1f69b75SAndy Adamson encode_nops(&hdr);
3054b1f69b75SAndy Adamson }
3055b1f69b75SAndy Adamson
3056b1f69b75SAndy Adamson /*
3057b1f69b75SAndy Adamson * Encode LAYOUTGET request
3058b1f69b75SAndy Adamson */
nfs4_xdr_enc_layoutget(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)30599f06c719SChuck Lever static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
30609f06c719SChuck Lever struct xdr_stream *xdr,
3061fcc85819SChristoph Hellwig const void *data)
3062b1f69b75SAndy Adamson {
3063fcc85819SChristoph Hellwig const struct nfs4_layoutget_args *args = data;
3064b1f69b75SAndy Adamson struct compound_hdr hdr = {
3065b1f69b75SAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3066b1f69b75SAndy Adamson };
3067b1f69b75SAndy Adamson
30689f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
30699f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
30709f06c719SChuck Lever encode_putfh(xdr, NFS_FH(args->inode), &hdr);
30719f06c719SChuck Lever encode_layoutget(xdr, args, &hdr);
307235124a09SWeston Andros Adamson
3073cf500bacSChuck Lever rpc_prepare_reply_pages(req, args->layout.pages, 0,
30749ed5af26STrond Myklebust args->layout.pglen, hdr.replen - pagepad_maxsz);
3075b1f69b75SAndy Adamson encode_nops(&hdr);
3076b1f69b75SAndy Adamson }
3077863a3c6cSAndy Adamson
3078863a3c6cSAndy Adamson /*
3079863a3c6cSAndy Adamson * Encode LAYOUTCOMMIT request
3080863a3c6cSAndy Adamson */
nfs4_xdr_enc_layoutcommit(struct rpc_rqst * req,struct xdr_stream * xdr,const void * priv)3081cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3082863a3c6cSAndy Adamson struct xdr_stream *xdr,
3083fcc85819SChristoph Hellwig const void *priv)
3084863a3c6cSAndy Adamson {
3085fcc85819SChristoph Hellwig const struct nfs4_layoutcommit_args *args = priv;
3086ac7db726SBenny Halevy struct nfs4_layoutcommit_data *data =
3087ac7db726SBenny Halevy container_of(args, struct nfs4_layoutcommit_data, args);
3088863a3c6cSAndy Adamson struct compound_hdr hdr = {
3089863a3c6cSAndy Adamson .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3090863a3c6cSAndy Adamson };
3091863a3c6cSAndy Adamson
3092863a3c6cSAndy Adamson encode_compound_hdr(xdr, req, &hdr);
3093863a3c6cSAndy Adamson encode_sequence(xdr, &args->seq_args, &hdr);
3094863a3c6cSAndy Adamson encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3095ac7db726SBenny Halevy encode_layoutcommit(xdr, data->args.inode, args, &hdr);
3096863a3c6cSAndy Adamson encode_getfattr(xdr, args->bitmask, &hdr);
3097863a3c6cSAndy Adamson encode_nops(&hdr);
3098cbe82603SBenny Halevy }
3099cbe82603SBenny Halevy
3100cbe82603SBenny Halevy /*
3101cbe82603SBenny Halevy * Encode LAYOUTRETURN request
3102cbe82603SBenny Halevy */
nfs4_xdr_enc_layoutreturn(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)3103cbe82603SBenny Halevy static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3104cbe82603SBenny Halevy struct xdr_stream *xdr,
3105fcc85819SChristoph Hellwig const void *data)
3106cbe82603SBenny Halevy {
3107fcc85819SChristoph Hellwig const struct nfs4_layoutreturn_args *args = data;
3108cbe82603SBenny Halevy struct compound_hdr hdr = {
3109cbe82603SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3110cbe82603SBenny Halevy };
3111cbe82603SBenny Halevy
3112cbe82603SBenny Halevy encode_compound_hdr(xdr, req, &hdr);
3113cbe82603SBenny Halevy encode_sequence(xdr, &args->seq_args, &hdr);
3114cbe82603SBenny Halevy encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3115cbe82603SBenny Halevy encode_layoutreturn(xdr, args, &hdr);
3116cbe82603SBenny Halevy encode_nops(&hdr);
3117863a3c6cSAndy Adamson }
3118fca78d6dSBryan Schumaker
3119fca78d6dSBryan Schumaker /*
3120fca78d6dSBryan Schumaker * Encode SECINFO_NO_NAME request
3121fca78d6dSBryan Schumaker */
nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)3122fcc85819SChristoph Hellwig static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
3123fca78d6dSBryan Schumaker struct xdr_stream *xdr,
3124fcc85819SChristoph Hellwig const void *data)
3125fca78d6dSBryan Schumaker {
3126fcc85819SChristoph Hellwig const struct nfs41_secinfo_no_name_args *args = data;
3127fca78d6dSBryan Schumaker struct compound_hdr hdr = {
3128fca78d6dSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3129fca78d6dSBryan Schumaker };
3130fca78d6dSBryan Schumaker
3131fca78d6dSBryan Schumaker encode_compound_hdr(xdr, req, &hdr);
3132fca78d6dSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr);
3133fca78d6dSBryan Schumaker encode_putrootfh(xdr, &hdr);
3134fca78d6dSBryan Schumaker encode_secinfo_no_name(xdr, args, &hdr);
3135fca78d6dSBryan Schumaker encode_nops(&hdr);
3136fca78d6dSBryan Schumaker }
31377d974794SBryan Schumaker
31387d974794SBryan Schumaker /*
31397d974794SBryan Schumaker * Encode TEST_STATEID request
31407d974794SBryan Schumaker */
nfs4_xdr_enc_test_stateid(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)31417d974794SBryan Schumaker static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
31427d974794SBryan Schumaker struct xdr_stream *xdr,
3143fcc85819SChristoph Hellwig const void *data)
31447d974794SBryan Schumaker {
3145fcc85819SChristoph Hellwig const struct nfs41_test_stateid_args *args = data;
31467d974794SBryan Schumaker struct compound_hdr hdr = {
31477d974794SBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args),
31487d974794SBryan Schumaker };
31497d974794SBryan Schumaker
31507d974794SBryan Schumaker encode_compound_hdr(xdr, req, &hdr);
31517d974794SBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr);
31527d974794SBryan Schumaker encode_test_stateid(xdr, args, &hdr);
31537d974794SBryan Schumaker encode_nops(&hdr);
31547d974794SBryan Schumaker }
31559aeda35fSBryan Schumaker
31569aeda35fSBryan Schumaker /*
31579aeda35fSBryan Schumaker * Encode FREE_STATEID request
31589aeda35fSBryan Schumaker */
nfs4_xdr_enc_free_stateid(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)31599aeda35fSBryan Schumaker static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
31609aeda35fSBryan Schumaker struct xdr_stream *xdr,
3161fcc85819SChristoph Hellwig const void *data)
31629aeda35fSBryan Schumaker {
3163fcc85819SChristoph Hellwig const struct nfs41_free_stateid_args *args = data;
31649aeda35fSBryan Schumaker struct compound_hdr hdr = {
31659aeda35fSBryan Schumaker .minorversion = nfs4_xdr_minorversion(&args->seq_args),
31669aeda35fSBryan Schumaker };
31679aeda35fSBryan Schumaker
31689aeda35fSBryan Schumaker encode_compound_hdr(xdr, req, &hdr);
31699aeda35fSBryan Schumaker encode_sequence(xdr, &args->seq_args, &hdr);
31709aeda35fSBryan Schumaker encode_free_stateid(xdr, args, &hdr);
31719aeda35fSBryan Schumaker encode_nops(&hdr);
31729aeda35fSBryan Schumaker }
317399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
317499fe60d0SBenny Halevy
decode_opaque_inline(struct xdr_stream * xdr,unsigned int * len,char ** string)3175683b57b4STrond Myklebust static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
31761da177e4SLinus Torvalds {
31776da59ce2STrond Myklebust ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
31786da59ce2STrond Myklebust NFS4_OPAQUE_LIMIT);
3179eb72f484SChuck Lever if (unlikely(ret < 0))
3180c0eae66eSBenny Halevy return -EIO;
31816da59ce2STrond Myklebust *len = ret;
31826da59ce2STrond Myklebust return 0;
31836da59ce2STrond Myklebust }
31841da177e4SLinus Torvalds
decode_compound_hdr(struct xdr_stream * xdr,struct compound_hdr * hdr)31851da177e4SLinus Torvalds static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
31861da177e4SLinus Torvalds {
31876659db4cSTrond Myklebust ssize_t ret;
31886659db4cSTrond Myklebust void *ptr;
31896659db4cSTrond Myklebust u32 tmp;
31901da177e4SLinus Torvalds
31916659db4cSTrond Myklebust if (xdr_stream_decode_u32(xdr, &tmp) < 0)
3192eb72f484SChuck Lever return -EIO;
31936659db4cSTrond Myklebust hdr->status = tmp;
31941da177e4SLinus Torvalds
31956659db4cSTrond Myklebust ret = xdr_stream_decode_opaque_inline(xdr, &ptr, NFS4_OPAQUE_LIMIT);
31966659db4cSTrond Myklebust if (ret < 0)
3197eb72f484SChuck Lever return -EIO;
31986659db4cSTrond Myklebust hdr->taglen = ret;
31996659db4cSTrond Myklebust hdr->tag = ptr;
32006659db4cSTrond Myklebust
32016659db4cSTrond Myklebust if (xdr_stream_decode_u32(xdr, &tmp) < 0)
32026659db4cSTrond Myklebust return -EIO;
32036659db4cSTrond Myklebust hdr->nops = tmp;
3204aadf6152SBenny Halevy if (unlikely(hdr->nops < 1))
3205aadf6152SBenny Halevy return nfs4_stat_to_errno(hdr->status);
32061da177e4SLinus Torvalds return 0;
32071da177e4SLinus Torvalds }
32081da177e4SLinus Torvalds
__decode_op_hdr(struct xdr_stream * xdr,enum nfs_opnum4 expected,int * nfs_retval)3209c7848f69STrond Myklebust static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3210c7848f69STrond Myklebust int *nfs_retval)
32111da177e4SLinus Torvalds {
32128687b63aSAl Viro __be32 *p;
32131da177e4SLinus Torvalds uint32_t opnum;
32141da177e4SLinus Torvalds int32_t nfserr;
32151da177e4SLinus Torvalds
3216c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3217c0eae66eSBenny Halevy if (unlikely(!p))
3218c0eae66eSBenny Halevy goto out_overflow;
32196f723f77SBenny Halevy opnum = be32_to_cpup(p++);
3220c7848f69STrond Myklebust if (unlikely(opnum != expected))
3221c7848f69STrond Myklebust goto out_bad_operation;
3222f23f6584SChuck Lever if (unlikely(*p != cpu_to_be32(NFS_OK)))
3223f23f6584SChuck Lever goto out_status;
3224c7848f69STrond Myklebust *nfs_retval = 0;
3225f23f6584SChuck Lever return true;
3226f23f6584SChuck Lever out_status:
3227f23f6584SChuck Lever nfserr = be32_to_cpup(p);
322862a92ba9SChuck Lever trace_nfs4_xdr_status(xdr, opnum, nfserr);
3229c7848f69STrond Myklebust *nfs_retval = nfs4_stat_to_errno(nfserr);
3230c7848f69STrond Myklebust return true;
3231c7848f69STrond Myklebust out_bad_operation:
3232da934ae0STrond Myklebust trace_nfs4_xdr_bad_operation(xdr, opnum, expected);
3233c7848f69STrond Myklebust *nfs_retval = -EREMOTEIO;
3234c7848f69STrond Myklebust return false;
3235c0eae66eSBenny Halevy out_overflow:
3236c7848f69STrond Myklebust *nfs_retval = -EIO;
3237c7848f69STrond Myklebust return false;
3238c7848f69STrond Myklebust }
3239c7848f69STrond Myklebust
decode_op_hdr(struct xdr_stream * xdr,enum nfs_opnum4 expected)3240c7848f69STrond Myklebust static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3241c7848f69STrond Myklebust {
3242c7848f69STrond Myklebust int retval;
3243c7848f69STrond Myklebust
3244c7848f69STrond Myklebust __decode_op_hdr(xdr, expected, &retval);
3245c7848f69STrond Myklebust return retval;
32461da177e4SLinus Torvalds }
32471da177e4SLinus Torvalds
32481da177e4SLinus Torvalds /* Dummy routine */
decode_ace(struct xdr_stream * xdr,void * ace)32491bbe60ffSTrond Myklebust static int decode_ace(struct xdr_stream *xdr, void *ace)
32501da177e4SLinus Torvalds {
32518687b63aSAl Viro __be32 *p;
3252683b57b4STrond Myklebust unsigned int strlen;
32531da177e4SLinus Torvalds char *str;
32541da177e4SLinus Torvalds
3255c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12);
3256eb72f484SChuck Lever if (unlikely(!p))
3257c0eae66eSBenny Halevy return -EIO;
3258eb72f484SChuck Lever return decode_opaque_inline(xdr, &strlen, &str);
32591da177e4SLinus Torvalds }
32601da177e4SLinus Torvalds
326137c88763STrond Myklebust static ssize_t
decode_bitmap4(struct xdr_stream * xdr,uint32_t * bitmap,size_t sz)326237c88763STrond Myklebust decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
32631da177e4SLinus Torvalds {
326437c88763STrond Myklebust ssize_t ret;
32651da177e4SLinus Torvalds
326637c88763STrond Myklebust ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
326737c88763STrond Myklebust if (likely(ret >= 0))
326837c88763STrond Myklebust return ret;
3269eb72f484SChuck Lever if (ret != -EMSGSIZE)
3270c0eae66eSBenny Halevy return -EIO;
3271eb72f484SChuck Lever return sz;
32721da177e4SLinus Torvalds }
32731da177e4SLinus Torvalds
decode_attr_bitmap(struct xdr_stream * xdr,uint32_t * bitmap)327437c88763STrond Myklebust static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
327537c88763STrond Myklebust {
327637c88763STrond Myklebust ssize_t ret;
327737c88763STrond Myklebust ret = decode_bitmap4(xdr, bitmap, 3);
327837c88763STrond Myklebust return ret < 0 ? ret : 0;
327937c88763STrond Myklebust }
328037c88763STrond Myklebust
decode_attr_length(struct xdr_stream * xdr,uint32_t * attrlen,unsigned int * savep)3281256e48bbSTrond Myklebust static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
32821da177e4SLinus Torvalds {
32838687b63aSAl Viro __be32 *p;
32841da177e4SLinus Torvalds
3285c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3286c0eae66eSBenny Halevy if (unlikely(!p))
3287eb72f484SChuck Lever return -EIO;
3288cccddf4fSBenny Halevy *attrlen = be32_to_cpup(p);
3289256e48bbSTrond Myklebust *savep = xdr_stream_pos(xdr);
32901da177e4SLinus Torvalds return 0;
32911da177e4SLinus Torvalds }
32921da177e4SLinus Torvalds
decode_attr_supported(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * bitmask)32931da177e4SLinus Torvalds static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
32941da177e4SLinus Torvalds {
32951da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
32963388bff5SRoman Borisov int ret;
32973388bff5SRoman Borisov ret = decode_attr_bitmap(xdr, bitmask);
32983388bff5SRoman Borisov if (unlikely(ret < 0))
32993388bff5SRoman Borisov return ret;
33001da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
33011da177e4SLinus Torvalds } else
3302dae100c2SFred Isaman bitmask[0] = bitmask[1] = bitmask[2] = 0;
3303dae100c2SFred Isaman dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3304dae100c2SFred Isaman bitmask[0], bitmask[1], bitmask[2]);
33051da177e4SLinus Torvalds return 0;
33061da177e4SLinus Torvalds }
33071da177e4SLinus Torvalds
decode_attr_type(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * type)33081da177e4SLinus Torvalds static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
33091da177e4SLinus Torvalds {
33108687b63aSAl Viro __be32 *p;
3311409924e4STrond Myklebust int ret = 0;
33121da177e4SLinus Torvalds
33131da177e4SLinus Torvalds *type = 0;
33141da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
33151da177e4SLinus Torvalds return -EIO;
33161da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
3317c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3318c0eae66eSBenny Halevy if (unlikely(!p))
3319eb72f484SChuck Lever return -EIO;
3320cccddf4fSBenny Halevy *type = be32_to_cpup(p);
33211da177e4SLinus Torvalds if (*type < NF4REG || *type > NF4NAMEDATTR) {
33223110ff80SHarvey Harrison dprintk("%s: bad type %d\n", __func__, *type);
33231da177e4SLinus Torvalds return -EIO;
33241da177e4SLinus Torvalds }
33251da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_TYPE;
3326409924e4STrond Myklebust ret = NFS_ATTR_FATTR_TYPE;
33271da177e4SLinus Torvalds }
3328bca79478STrond Myklebust dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
3329409924e4STrond Myklebust return ret;
33301da177e4SLinus Torvalds }
33311da177e4SLinus Torvalds
decode_attr_fh_expire_type(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * type)3332264e6351SChuck Lever static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3333264e6351SChuck Lever uint32_t *bitmap, uint32_t *type)
3334264e6351SChuck Lever {
3335264e6351SChuck Lever __be32 *p;
3336264e6351SChuck Lever
3337264e6351SChuck Lever *type = 0;
3338264e6351SChuck Lever if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3339264e6351SChuck Lever return -EIO;
3340264e6351SChuck Lever if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3341264e6351SChuck Lever p = xdr_inline_decode(xdr, 4);
3342264e6351SChuck Lever if (unlikely(!p))
3343eb72f484SChuck Lever return -EIO;
3344264e6351SChuck Lever *type = be32_to_cpup(p);
3345264e6351SChuck Lever bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3346264e6351SChuck Lever }
3347264e6351SChuck Lever dprintk("%s: expire type=0x%x\n", __func__, *type);
3348264e6351SChuck Lever return 0;
3349264e6351SChuck Lever }
3350264e6351SChuck Lever
decode_attr_change(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * change)33511da177e4SLinus Torvalds static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
33521da177e4SLinus Torvalds {
33538687b63aSAl Viro __be32 *p;
3354409924e4STrond Myklebust int ret = 0;
33551da177e4SLinus Torvalds
33561da177e4SLinus Torvalds *change = 0;
33571da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
33581da177e4SLinus Torvalds return -EIO;
33591da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
3360c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3361c0eae66eSBenny Halevy if (unlikely(!p))
3362eb72f484SChuck Lever return -EIO;
3363cccddf4fSBenny Halevy xdr_decode_hyper(p, change);
33641da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_CHANGE;
3365409924e4STrond Myklebust ret = NFS_ATTR_FATTR_CHANGE;
33661da177e4SLinus Torvalds }
33673110ff80SHarvey Harrison dprintk("%s: change attribute=%Lu\n", __func__,
33681da177e4SLinus Torvalds (unsigned long long)*change);
3369409924e4STrond Myklebust return ret;
33701da177e4SLinus Torvalds }
33711da177e4SLinus Torvalds
decode_attr_size(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * size)33721da177e4SLinus Torvalds static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
33731da177e4SLinus Torvalds {
33748687b63aSAl Viro __be32 *p;
3375409924e4STrond Myklebust int ret = 0;
33761da177e4SLinus Torvalds
33771da177e4SLinus Torvalds *size = 0;
33781da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
33791da177e4SLinus Torvalds return -EIO;
33801da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
3381c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3382c0eae66eSBenny Halevy if (unlikely(!p))
3383eb72f484SChuck Lever return -EIO;
3384cccddf4fSBenny Halevy xdr_decode_hyper(p, size);
33851da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SIZE;
3386409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SIZE;
33871da177e4SLinus Torvalds }
33883110ff80SHarvey Harrison dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
3389409924e4STrond Myklebust return ret;
33901da177e4SLinus Torvalds }
33911da177e4SLinus Torvalds
decode_attr_link_support(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)33921da177e4SLinus Torvalds static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
33931da177e4SLinus Torvalds {
33948687b63aSAl Viro __be32 *p;
33951da177e4SLinus Torvalds
33961da177e4SLinus Torvalds *res = 0;
33971da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
33981da177e4SLinus Torvalds return -EIO;
33991da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
3400c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3401c0eae66eSBenny Halevy if (unlikely(!p))
3402eb72f484SChuck Lever return -EIO;
3403cccddf4fSBenny Halevy *res = be32_to_cpup(p);
34041da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
34051da177e4SLinus Torvalds }
34063110ff80SHarvey Harrison dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
34071da177e4SLinus Torvalds return 0;
34081da177e4SLinus Torvalds }
34091da177e4SLinus Torvalds
decode_attr_symlink_support(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)34101da177e4SLinus Torvalds static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34111da177e4SLinus Torvalds {
34128687b63aSAl Viro __be32 *p;
34131da177e4SLinus Torvalds
34141da177e4SLinus Torvalds *res = 0;
34151da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
34161da177e4SLinus Torvalds return -EIO;
34171da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
3418c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3419c0eae66eSBenny Halevy if (unlikely(!p))
3420eb72f484SChuck Lever return -EIO;
3421cccddf4fSBenny Halevy *res = be32_to_cpup(p);
34221da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
34231da177e4SLinus Torvalds }
34243110ff80SHarvey Harrison dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
34251da177e4SLinus Torvalds return 0;
34261da177e4SLinus Torvalds }
34271da177e4SLinus Torvalds
decode_attr_fsid(struct xdr_stream * xdr,uint32_t * bitmap,struct nfs_fsid * fsid)34288b4bdcf8STrond Myklebust static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
34291da177e4SLinus Torvalds {
34308687b63aSAl Viro __be32 *p;
3431409924e4STrond Myklebust int ret = 0;
34321da177e4SLinus Torvalds
34331da177e4SLinus Torvalds fsid->major = 0;
34341da177e4SLinus Torvalds fsid->minor = 0;
34351da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
34361da177e4SLinus Torvalds return -EIO;
34371da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
3438c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 16);
3439c0eae66eSBenny Halevy if (unlikely(!p))
3440eb72f484SChuck Lever return -EIO;
34413ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &fsid->major);
3442cccddf4fSBenny Halevy xdr_decode_hyper(p, &fsid->minor);
34431da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FSID;
3444409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FSID;
34451da177e4SLinus Torvalds }
34463110ff80SHarvey Harrison dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
34471da177e4SLinus Torvalds (unsigned long long)fsid->major,
34481da177e4SLinus Torvalds (unsigned long long)fsid->minor);
3449409924e4STrond Myklebust return ret;
34501da177e4SLinus Torvalds }
34511da177e4SLinus Torvalds
decode_attr_lease_time(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)34521da177e4SLinus Torvalds static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
34531da177e4SLinus Torvalds {
34548687b63aSAl Viro __be32 *p;
34551da177e4SLinus Torvalds
34561da177e4SLinus Torvalds *res = 60;
34571da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
34581da177e4SLinus Torvalds return -EIO;
34591da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
3460c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3461c0eae66eSBenny Halevy if (unlikely(!p))
3462eb72f484SChuck Lever return -EIO;
3463cccddf4fSBenny Halevy *res = be32_to_cpup(p);
34641da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
34651da177e4SLinus Torvalds }
34662eaf426dSDonald Buczek dprintk("%s: lease time=%u\n", __func__, (unsigned int)*res);
34671da177e4SLinus Torvalds return 0;
34681da177e4SLinus Torvalds }
34691da177e4SLinus Torvalds
decode_attr_error(struct xdr_stream * xdr,uint32_t * bitmap,int32_t * res)3470ee7b75fcSTrond Myklebust static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
3471ae42c70aSBryan Schumaker {
3472ae42c70aSBryan Schumaker __be32 *p;
3473ae42c70aSBryan Schumaker
3474ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3475ae42c70aSBryan Schumaker return -EIO;
3476ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3477ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4);
3478ae42c70aSBryan Schumaker if (unlikely(!p))
3479eb72f484SChuck Lever return -EIO;
3480ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
3481ee7b75fcSTrond Myklebust *res = -be32_to_cpup(p);
3482ae42c70aSBryan Schumaker }
3483ae42c70aSBryan Schumaker return 0;
3484ae42c70aSBryan Schumaker }
3485ae42c70aSBryan Schumaker
decode_attr_exclcreat_supported(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * bitmask)34868c61282fSKinglong Mee static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
34878c61282fSKinglong Mee uint32_t *bitmap, uint32_t *bitmask)
34888c61282fSKinglong Mee {
34898c61282fSKinglong Mee if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
34908c61282fSKinglong Mee int ret;
34918c61282fSKinglong Mee ret = decode_attr_bitmap(xdr, bitmask);
34928c61282fSKinglong Mee if (unlikely(ret < 0))
34938c61282fSKinglong Mee return ret;
34948c61282fSKinglong Mee bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
34958c61282fSKinglong Mee } else
34968c61282fSKinglong Mee bitmask[0] = bitmask[1] = bitmask[2] = 0;
34978c61282fSKinglong Mee dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
34988c61282fSKinglong Mee bitmask[0], bitmask[1], bitmask[2]);
34998c61282fSKinglong Mee return 0;
35008c61282fSKinglong Mee }
35018c61282fSKinglong Mee
decode_attr_filehandle(struct xdr_stream * xdr,uint32_t * bitmap,struct nfs_fh * fh)3502ae42c70aSBryan Schumaker static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3503ae42c70aSBryan Schumaker {
3504ae42c70aSBryan Schumaker __be32 *p;
350586bbd742SFrank Sorenson u32 len;
3506ae42c70aSBryan Schumaker
35077ad07353STrond Myklebust if (fh != NULL)
3508ae42c70aSBryan Schumaker memset(fh, 0, sizeof(*fh));
3509ae42c70aSBryan Schumaker
3510ae42c70aSBryan Schumaker if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3511ae42c70aSBryan Schumaker return -EIO;
3512ae42c70aSBryan Schumaker if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3513ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, 4);
3514ae42c70aSBryan Schumaker if (unlikely(!p))
3515eb72f484SChuck Lever return -EIO;
3516ae42c70aSBryan Schumaker len = be32_to_cpup(p);
3517eb3d58c6STrond Myklebust if (len > NFS4_FHSIZE || len == 0) {
3518eb3d58c6STrond Myklebust trace_nfs4_xdr_bad_filehandle(xdr, OP_READDIR,
3519eb3d58c6STrond Myklebust NFS4ERR_BADHANDLE);
3520eb3d58c6STrond Myklebust return -EREMOTEIO;
3521eb3d58c6STrond Myklebust }
3522ae42c70aSBryan Schumaker p = xdr_inline_decode(xdr, len);
3523ae42c70aSBryan Schumaker if (unlikely(!p))
3524eb72f484SChuck Lever return -EIO;
35257ad07353STrond Myklebust if (fh != NULL) {
3526ae42c70aSBryan Schumaker memcpy(fh->data, p, len);
35277ad07353STrond Myklebust fh->size = len;
35287ad07353STrond Myklebust }
3529ae42c70aSBryan Schumaker bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3530ae42c70aSBryan Schumaker }
3531ae42c70aSBryan Schumaker return 0;
3532ae42c70aSBryan Schumaker }
3533ae42c70aSBryan Schumaker
decode_attr_aclsupport(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)35341da177e4SLinus Torvalds static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
35351da177e4SLinus Torvalds {
35368687b63aSAl Viro __be32 *p;
35371da177e4SLinus Torvalds
3538a1800acaSMalahal Naineni *res = 0;
35391da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
35401da177e4SLinus Torvalds return -EIO;
35411da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
3542c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3543c0eae66eSBenny Halevy if (unlikely(!p))
3544eb72f484SChuck Lever return -EIO;
3545cccddf4fSBenny Halevy *res = be32_to_cpup(p);
35461da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
35471da177e4SLinus Torvalds }
35483110ff80SHarvey Harrison dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
35491da177e4SLinus Torvalds return 0;
35501da177e4SLinus Torvalds }
35511da177e4SLinus Torvalds
decode_attr_case_insensitive(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)35521ab5be4aSTrond Myklebust static int decode_attr_case_insensitive(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
35531ab5be4aSTrond Myklebust {
35541ab5be4aSTrond Myklebust __be32 *p;
35551ab5be4aSTrond Myklebust
35561ab5be4aSTrond Myklebust *res = 0;
35571ab5be4aSTrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_CASE_INSENSITIVE - 1U)))
35581ab5be4aSTrond Myklebust return -EIO;
35591ab5be4aSTrond Myklebust if (likely(bitmap[0] & FATTR4_WORD0_CASE_INSENSITIVE)) {
35601ab5be4aSTrond Myklebust p = xdr_inline_decode(xdr, 4);
35611ab5be4aSTrond Myklebust if (unlikely(!p))
35621ab5be4aSTrond Myklebust return -EIO;
35631ab5be4aSTrond Myklebust *res = be32_to_cpup(p);
35641ab5be4aSTrond Myklebust bitmap[0] &= ~FATTR4_WORD0_CASE_INSENSITIVE;
35651ab5be4aSTrond Myklebust }
35661ab5be4aSTrond Myklebust dprintk("%s: case_insensitive=%s\n", __func__, *res == 0 ? "false" : "true");
35671ab5be4aSTrond Myklebust return 0;
35681ab5be4aSTrond Myklebust }
35691ab5be4aSTrond Myklebust
decode_attr_case_preserving(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)35701ab5be4aSTrond Myklebust static int decode_attr_case_preserving(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
35711ab5be4aSTrond Myklebust {
35721ab5be4aSTrond Myklebust __be32 *p;
35731ab5be4aSTrond Myklebust
35741ab5be4aSTrond Myklebust *res = 0;
35751ab5be4aSTrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_CASE_PRESERVING - 1U)))
35761ab5be4aSTrond Myklebust return -EIO;
35771ab5be4aSTrond Myklebust if (likely(bitmap[0] & FATTR4_WORD0_CASE_PRESERVING)) {
35781ab5be4aSTrond Myklebust p = xdr_inline_decode(xdr, 4);
35791ab5be4aSTrond Myklebust if (unlikely(!p))
35801ab5be4aSTrond Myklebust return -EIO;
35811ab5be4aSTrond Myklebust *res = be32_to_cpup(p);
35821ab5be4aSTrond Myklebust bitmap[0] &= ~FATTR4_WORD0_CASE_PRESERVING;
35831ab5be4aSTrond Myklebust }
35841ab5be4aSTrond Myklebust dprintk("%s: case_preserving=%s\n", __func__, *res == 0 ? "false" : "true");
35851ab5be4aSTrond Myklebust return 0;
35861ab5be4aSTrond Myklebust }
35871ab5be4aSTrond Myklebust
decode_attr_fileid(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * fileid)35881da177e4SLinus Torvalds static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
35891da177e4SLinus Torvalds {
35908687b63aSAl Viro __be32 *p;
3591409924e4STrond Myklebust int ret = 0;
35921da177e4SLinus Torvalds
35931da177e4SLinus Torvalds *fileid = 0;
35941da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
35951da177e4SLinus Torvalds return -EIO;
35961da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
3597c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3598c0eae66eSBenny Halevy if (unlikely(!p))
3599eb72f484SChuck Lever return -EIO;
3600cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid);
36011da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILEID;
3602409924e4STrond Myklebust ret = NFS_ATTR_FATTR_FILEID;
36031da177e4SLinus Torvalds }
36043110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3605409924e4STrond Myklebust return ret;
36061da177e4SLinus Torvalds }
36071da177e4SLinus Torvalds
decode_attr_mounted_on_fileid(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * fileid)360899baf625SManoj Naik static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
360999baf625SManoj Naik {
36108687b63aSAl Viro __be32 *p;
3611409924e4STrond Myklebust int ret = 0;
361299baf625SManoj Naik
361399baf625SManoj Naik *fileid = 0;
361499baf625SManoj Naik if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
361599baf625SManoj Naik return -EIO;
361699baf625SManoj Naik if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
3617c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3618c0eae66eSBenny Halevy if (unlikely(!p))
3619eb72f484SChuck Lever return -EIO;
3620cccddf4fSBenny Halevy xdr_decode_hyper(p, fileid);
362199baf625SManoj Naik bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
362228331a46STrond Myklebust ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
362399baf625SManoj Naik }
36243110ff80SHarvey Harrison dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
3625409924e4STrond Myklebust return ret;
362699baf625SManoj Naik }
362799baf625SManoj Naik
decode_attr_files_avail(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res)36281da177e4SLinus Torvalds static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36291da177e4SLinus Torvalds {
36308687b63aSAl Viro __be32 *p;
36311da177e4SLinus Torvalds int status = 0;
36321da177e4SLinus Torvalds
36331da177e4SLinus Torvalds *res = 0;
36341da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
36351da177e4SLinus Torvalds return -EIO;
36361da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
3637c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3638c0eae66eSBenny Halevy if (unlikely(!p))
3639eb72f484SChuck Lever return -EIO;
3640cccddf4fSBenny Halevy xdr_decode_hyper(p, res);
36411da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
36421da177e4SLinus Torvalds }
36433110ff80SHarvey Harrison dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
36441da177e4SLinus Torvalds return status;
36451da177e4SLinus Torvalds }
36461da177e4SLinus Torvalds
decode_attr_files_free(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res)36471da177e4SLinus Torvalds static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36481da177e4SLinus Torvalds {
36498687b63aSAl Viro __be32 *p;
36501da177e4SLinus Torvalds int status = 0;
36511da177e4SLinus Torvalds
36521da177e4SLinus Torvalds *res = 0;
36531da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
36541da177e4SLinus Torvalds return -EIO;
36551da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
3656c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3657c0eae66eSBenny Halevy if (unlikely(!p))
3658eb72f484SChuck Lever return -EIO;
3659cccddf4fSBenny Halevy xdr_decode_hyper(p, res);
36601da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
36611da177e4SLinus Torvalds }
36623110ff80SHarvey Harrison dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
36631da177e4SLinus Torvalds return status;
36641da177e4SLinus Torvalds }
36651da177e4SLinus Torvalds
decode_attr_files_total(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res)36661da177e4SLinus Torvalds static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
36671da177e4SLinus Torvalds {
36688687b63aSAl Viro __be32 *p;
36691da177e4SLinus Torvalds int status = 0;
36701da177e4SLinus Torvalds
36711da177e4SLinus Torvalds *res = 0;
36721da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
36731da177e4SLinus Torvalds return -EIO;
36741da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
3675c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3676c0eae66eSBenny Halevy if (unlikely(!p))
3677eb72f484SChuck Lever return -EIO;
3678cccddf4fSBenny Halevy xdr_decode_hyper(p, res);
36791da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
36801da177e4SLinus Torvalds }
36813110ff80SHarvey Harrison dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
36821da177e4SLinus Torvalds return status;
36831da177e4SLinus Torvalds }
36841da177e4SLinus Torvalds
decode_pathname(struct xdr_stream * xdr,struct nfs4_pathname * path)36857aaa0b3bSManoj Naik static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
36867aaa0b3bSManoj Naik {
3687464ad6b1SChuck Lever u32 n;
36888687b63aSAl Viro __be32 *p;
36897aaa0b3bSManoj Naik int status = 0;
36907aaa0b3bSManoj Naik
3691c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3692c0eae66eSBenny Halevy if (unlikely(!p))
3693eb72f484SChuck Lever return -EIO;
3694cccddf4fSBenny Halevy n = be32_to_cpup(p);
369533a43f28SAndy Adamson if (n == 0)
369633a43f28SAndy Adamson goto root_path;
369702a2976cSChuck Lever dprintk("pathname4: ");
3698809b426cSTrond Myklebust if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3699809b426cSTrond Myklebust dprintk("cannot parse %d components in path\n", n);
3700809b426cSTrond Myklebust goto out_eio;
3701809b426cSTrond Myklebust }
3702809b426cSTrond Myklebust for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
37037aaa0b3bSManoj Naik struct nfs4_string *component = &path->components[path->ncomponents];
37047aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &component->len, &component->data);
37057aaa0b3bSManoj Naik if (unlikely(status != 0))
37067aaa0b3bSManoj Naik goto out_eio;
370795a13f7bSTrond Myklebust ifdebug (XDR)
370802a2976cSChuck Lever pr_cont("%s%.*s ",
370902a2976cSChuck Lever (path->ncomponents != n ? "/ " : ""),
371002a2976cSChuck Lever component->len, component->data);
37117aaa0b3bSManoj Naik }
37127aaa0b3bSManoj Naik out:
37137aaa0b3bSManoj Naik return status;
371433a43f28SAndy Adamson root_path:
371533a43f28SAndy Adamson /* a root pathname is sent as a zero component4 */
371633a43f28SAndy Adamson path->ncomponents = 1;
371733a43f28SAndy Adamson path->components[0].len=0;
371833a43f28SAndy Adamson path->components[0].data=NULL;
371902a2976cSChuck Lever dprintk("pathname4: /\n");
372033a43f28SAndy Adamson goto out;
37217aaa0b3bSManoj Naik out_eio:
37227aaa0b3bSManoj Naik dprintk(" status %d", status);
37237aaa0b3bSManoj Naik status = -EIO;
37247aaa0b3bSManoj Naik goto out;
37257aaa0b3bSManoj Naik }
37267aaa0b3bSManoj Naik
decode_attr_fs_locations(struct xdr_stream * xdr,uint32_t * bitmap,struct nfs4_fs_locations * res)37277aaa0b3bSManoj Naik static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
3728683b57b4STrond Myklebust {
3729683b57b4STrond Myklebust int n;
37308687b63aSAl Viro __be32 *p;
3731683b57b4STrond Myklebust int status = -EIO;
3732683b57b4STrond Myklebust
3733683b57b4STrond Myklebust if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3734683b57b4STrond Myklebust goto out;
3735683b57b4STrond Myklebust status = 0;
3736683b57b4STrond Myklebust if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3737683b57b4STrond Myklebust goto out;
3738f54423a1SKinglong Mee bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
37398b7e3f49STrond Myklebust status = -EIO;
37408b7e3f49STrond Myklebust /* Ignore borken servers that return unrequested attrs */
37418b7e3f49STrond Myklebust if (unlikely(res == NULL))
37428b7e3f49STrond Myklebust goto out;
374302a2976cSChuck Lever dprintk("%s: fsroot:\n", __func__);
37447aaa0b3bSManoj Naik status = decode_pathname(xdr, &res->fs_path);
3745683b57b4STrond Myklebust if (unlikely(status != 0))
3746683b57b4STrond Myklebust goto out;
3747c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3748c0eae66eSBenny Halevy if (unlikely(!p))
3749eb72f484SChuck Lever goto out_eio;
3750cccddf4fSBenny Halevy n = be32_to_cpup(p);
3751809b426cSTrond Myklebust for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
3752464ad6b1SChuck Lever u32 m;
3753809b426cSTrond Myklebust struct nfs4_fs_location *loc;
3754683b57b4STrond Myklebust
3755809b426cSTrond Myklebust if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3756809b426cSTrond Myklebust break;
3757809b426cSTrond Myklebust loc = &res->locations[res->nlocations];
3758c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3759c0eae66eSBenny Halevy if (unlikely(!p))
3760eb72f484SChuck Lever goto out_eio;
3761cccddf4fSBenny Halevy m = be32_to_cpup(p);
37627aaa0b3bSManoj Naik
376302a2976cSChuck Lever dprintk("%s: servers:\n", __func__);
3764809b426cSTrond Myklebust for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3765809b426cSTrond Myklebust struct nfs4_string *server;
3766809b426cSTrond Myklebust
3767809b426cSTrond Myklebust if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
3768464ad6b1SChuck Lever unsigned int i;
3769464ad6b1SChuck Lever dprintk("%s: using first %u of %u servers "
3770464ad6b1SChuck Lever "returned for location %u\n",
37713110ff80SHarvey Harrison __func__,
3772464ad6b1SChuck Lever NFS4_FS_LOCATION_MAXSERVERS,
3773464ad6b1SChuck Lever m, res->nlocations);
37747aaa0b3bSManoj Naik for (i = loc->nservers; i < m; i++) {
37752e42c3e2STrond Myklebust unsigned int len;
37767aaa0b3bSManoj Naik char *data;
37777aaa0b3bSManoj Naik status = decode_opaque_inline(xdr, &len, &data);
3778683b57b4STrond Myklebust if (unlikely(status != 0))
3779683b57b4STrond Myklebust goto out_eio;
37807aaa0b3bSManoj Naik }
3781809b426cSTrond Myklebust break;
37827aaa0b3bSManoj Naik }
3783809b426cSTrond Myklebust server = &loc->servers[loc->nservers];
3784809b426cSTrond Myklebust status = decode_opaque_inline(xdr, &server->len, &server->data);
3785809b426cSTrond Myklebust if (unlikely(status != 0))
3786809b426cSTrond Myklebust goto out_eio;
3787809b426cSTrond Myklebust dprintk("%s ", server->data);
37887aaa0b3bSManoj Naik }
37897aaa0b3bSManoj Naik status = decode_pathname(xdr, &loc->rootpath);
37907aaa0b3bSManoj Naik if (unlikely(status != 0))
37917aaa0b3bSManoj Naik goto out_eio;
3792683b57b4STrond Myklebust }
3793409924e4STrond Myklebust if (res->nlocations != 0)
379481934ddbSChuck Lever status = NFS_ATTR_FATTR_V4_LOCATIONS;
3795683b57b4STrond Myklebust out:
37963110ff80SHarvey Harrison dprintk("%s: fs_locations done, error = %d\n", __func__, status);
3797683b57b4STrond Myklebust return status;
3798683b57b4STrond Myklebust out_eio:
3799683b57b4STrond Myklebust status = -EIO;
3800683b57b4STrond Myklebust goto out;
3801683b57b4STrond Myklebust }
3802683b57b4STrond Myklebust
decode_attr_maxfilesize(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res)38031da177e4SLinus Torvalds static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
38041da177e4SLinus Torvalds {
38058687b63aSAl Viro __be32 *p;
38061da177e4SLinus Torvalds int status = 0;
38071da177e4SLinus Torvalds
38081da177e4SLinus Torvalds *res = 0;
38091da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
38101da177e4SLinus Torvalds return -EIO;
38111da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
3812c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3813c0eae66eSBenny Halevy if (unlikely(!p))
3814eb72f484SChuck Lever return -EIO;
3815cccddf4fSBenny Halevy xdr_decode_hyper(p, res);
38161da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
38171da177e4SLinus Torvalds }
38183110ff80SHarvey Harrison dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
38191da177e4SLinus Torvalds return status;
38201da177e4SLinus Torvalds }
38211da177e4SLinus Torvalds
decode_attr_maxlink(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * maxlink)38221da177e4SLinus Torvalds static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
38231da177e4SLinus Torvalds {
38248687b63aSAl Viro __be32 *p;
38251da177e4SLinus Torvalds int status = 0;
38261da177e4SLinus Torvalds
38271da177e4SLinus Torvalds *maxlink = 1;
38281da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
38291da177e4SLinus Torvalds return -EIO;
38301da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
3831c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3832c0eae66eSBenny Halevy if (unlikely(!p))
3833eb72f484SChuck Lever return -EIO;
3834cccddf4fSBenny Halevy *maxlink = be32_to_cpup(p);
38351da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
38361da177e4SLinus Torvalds }
38373110ff80SHarvey Harrison dprintk("%s: maxlink=%u\n", __func__, *maxlink);
38381da177e4SLinus Torvalds return status;
38391da177e4SLinus Torvalds }
38401da177e4SLinus Torvalds
decode_attr_maxname(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * maxname)38411da177e4SLinus Torvalds static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
38421da177e4SLinus Torvalds {
38438687b63aSAl Viro __be32 *p;
38441da177e4SLinus Torvalds int status = 0;
38451da177e4SLinus Torvalds
38461da177e4SLinus Torvalds *maxname = 1024;
38471da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
38481da177e4SLinus Torvalds return -EIO;
38491da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
3850c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3851c0eae66eSBenny Halevy if (unlikely(!p))
3852eb72f484SChuck Lever return -EIO;
3853cccddf4fSBenny Halevy *maxname = be32_to_cpup(p);
38541da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
38551da177e4SLinus Torvalds }
38563110ff80SHarvey Harrison dprintk("%s: maxname=%u\n", __func__, *maxname);
38571da177e4SLinus Torvalds return status;
38581da177e4SLinus Torvalds }
38591da177e4SLinus Torvalds
decode_attr_maxread(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)38601da177e4SLinus Torvalds static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
38611da177e4SLinus Torvalds {
38628687b63aSAl Viro __be32 *p;
38631da177e4SLinus Torvalds int status = 0;
38641da177e4SLinus Torvalds
38651da177e4SLinus Torvalds *res = 1024;
38661da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
38671da177e4SLinus Torvalds return -EIO;
38681da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
38691da177e4SLinus Torvalds uint64_t maxread;
3870c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3871c0eae66eSBenny Halevy if (unlikely(!p))
3872eb72f484SChuck Lever return -EIO;
3873cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxread);
38741da177e4SLinus Torvalds if (maxread > 0x7FFFFFFF)
38751da177e4SLinus Torvalds maxread = 0x7FFFFFFF;
38761da177e4SLinus Torvalds *res = (uint32_t)maxread;
38771da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
38781da177e4SLinus Torvalds }
38793110ff80SHarvey Harrison dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
38801da177e4SLinus Torvalds return status;
38811da177e4SLinus Torvalds }
38821da177e4SLinus Torvalds
decode_attr_maxwrite(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)38831da177e4SLinus Torvalds static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
38841da177e4SLinus Torvalds {
38858687b63aSAl Viro __be32 *p;
38861da177e4SLinus Torvalds int status = 0;
38871da177e4SLinus Torvalds
38881da177e4SLinus Torvalds *res = 1024;
38891da177e4SLinus Torvalds if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
38901da177e4SLinus Torvalds return -EIO;
38911da177e4SLinus Torvalds if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
38921da177e4SLinus Torvalds uint64_t maxwrite;
3893c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
3894c0eae66eSBenny Halevy if (unlikely(!p))
3895eb72f484SChuck Lever return -EIO;
3896cccddf4fSBenny Halevy xdr_decode_hyper(p, &maxwrite);
38971da177e4SLinus Torvalds if (maxwrite > 0x7FFFFFFF)
38981da177e4SLinus Torvalds maxwrite = 0x7FFFFFFF;
38991da177e4SLinus Torvalds *res = (uint32_t)maxwrite;
39001da177e4SLinus Torvalds bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
39011da177e4SLinus Torvalds }
39023110ff80SHarvey Harrison dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
39031da177e4SLinus Torvalds return status;
39041da177e4SLinus Torvalds }
39051da177e4SLinus Torvalds
decode_attr_mode(struct xdr_stream * xdr,uint32_t * bitmap,umode_t * mode)3906bca79478STrond Myklebust static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
39071da177e4SLinus Torvalds {
3908bca79478STrond Myklebust uint32_t tmp;
39098687b63aSAl Viro __be32 *p;
3910409924e4STrond Myklebust int ret = 0;
39111da177e4SLinus Torvalds
39121da177e4SLinus Torvalds *mode = 0;
39131da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
39141da177e4SLinus Torvalds return -EIO;
39151da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
3916c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3917c0eae66eSBenny Halevy if (unlikely(!p))
3918eb72f484SChuck Lever return -EIO;
3919cccddf4fSBenny Halevy tmp = be32_to_cpup(p);
3920bca79478STrond Myklebust *mode = tmp & ~S_IFMT;
39211da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_MODE;
3922409924e4STrond Myklebust ret = NFS_ATTR_FATTR_MODE;
39231da177e4SLinus Torvalds }
39243110ff80SHarvey Harrison dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
3925409924e4STrond Myklebust return ret;
39261da177e4SLinus Torvalds }
39271da177e4SLinus Torvalds
decode_attr_nlink(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * nlink)39281da177e4SLinus Torvalds static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
39291da177e4SLinus Torvalds {
39308687b63aSAl Viro __be32 *p;
3931409924e4STrond Myklebust int ret = 0;
39321da177e4SLinus Torvalds
39331da177e4SLinus Torvalds *nlink = 1;
39341da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
39351da177e4SLinus Torvalds return -EIO;
39361da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
3937c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
3938c0eae66eSBenny Halevy if (unlikely(!p))
3939eb72f484SChuck Lever return -EIO;
3940cccddf4fSBenny Halevy *nlink = be32_to_cpup(p);
39411da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
3942409924e4STrond Myklebust ret = NFS_ATTR_FATTR_NLINK;
39431da177e4SLinus Torvalds }
39443110ff80SHarvey Harrison dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
3945409924e4STrond Myklebust return ret;
39461da177e4SLinus Torvalds }
39471da177e4SLinus Torvalds
decode_nfs4_string(struct xdr_stream * xdr,struct nfs4_string * name,gfp_t gfp_flags)3948686a816aSTrond Myklebust static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3949686a816aSTrond Myklebust struct nfs4_string *name, gfp_t gfp_flags)
3950686a816aSTrond Myklebust {
3951686a816aSTrond Myklebust ssize_t ret;
3952686a816aSTrond Myklebust
3953686a816aSTrond Myklebust ret = xdr_stream_decode_string_dup(xdr, &name->data,
3954686a816aSTrond Myklebust XDR_MAX_NETOBJ, gfp_flags);
3955686a816aSTrond Myklebust name->len = 0;
3956686a816aSTrond Myklebust if (ret > 0)
3957686a816aSTrond Myklebust name->len = ret;
3958686a816aSTrond Myklebust return ret;
3959686a816aSTrond Myklebust }
3960686a816aSTrond Myklebust
decode_attr_owner(struct xdr_stream * xdr,uint32_t * bitmap,const struct nfs_server * server,kuid_t * uid,struct nfs4_string * owner_name)396180e52aceSTrond Myklebust static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
3962e5782076SEric W. Biederman const struct nfs_server *server, kuid_t *uid,
39636926afd1STrond Myklebust struct nfs4_string *owner_name)
39641da177e4SLinus Torvalds {
3965686a816aSTrond Myklebust ssize_t len;
3966686a816aSTrond Myklebust char *p;
39671da177e4SLinus Torvalds
3968e5782076SEric W. Biederman *uid = make_kuid(&init_user_ns, -2);
39691da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
39701da177e4SLinus Torvalds return -EIO;
3971686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3972686a816aSTrond Myklebust return 0;
39731da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER;
3974686a816aSTrond Myklebust
3975686a816aSTrond Myklebust if (owner_name != NULL) {
3976e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
3977686a816aSTrond Myklebust if (len <= 0)
3978686a816aSTrond Myklebust goto out;
3979686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, owner_name->data);
3980686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER_NAME;
3981686a816aSTrond Myklebust } else {
3982686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3983686a816aSTrond Myklebust XDR_MAX_NETOBJ);
3984686a816aSTrond Myklebust if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3985686a816aSTrond Myklebust goto out;
3986e5782076SEric W. Biederman dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3987686a816aSTrond Myklebust return NFS_ATTR_FATTR_OWNER;
3988686a816aSTrond Myklebust }
3989686a816aSTrond Myklebust out:
3990eb72f484SChuck Lever if (len == -EBADMSG)
3991c0eae66eSBenny Halevy return -EIO;
3992eb72f484SChuck Lever return 0;
39931da177e4SLinus Torvalds }
39941da177e4SLinus Torvalds
decode_attr_group(struct xdr_stream * xdr,uint32_t * bitmap,const struct nfs_server * server,kgid_t * gid,struct nfs4_string * group_name)399580e52aceSTrond Myklebust static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
3996e5782076SEric W. Biederman const struct nfs_server *server, kgid_t *gid,
39976926afd1STrond Myklebust struct nfs4_string *group_name)
39981da177e4SLinus Torvalds {
3999686a816aSTrond Myklebust ssize_t len;
4000686a816aSTrond Myklebust char *p;
40011da177e4SLinus Torvalds
4002e5782076SEric W. Biederman *gid = make_kgid(&init_user_ns, -2);
40031da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
40041da177e4SLinus Torvalds return -EIO;
4005686a816aSTrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
4006686a816aSTrond Myklebust return 0;
40071da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
4008686a816aSTrond Myklebust
4009686a816aSTrond Myklebust if (group_name != NULL) {
4010e8d8aa46STrond Myklebust len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
4011686a816aSTrond Myklebust if (len <= 0)
4012686a816aSTrond Myklebust goto out;
4013686a816aSTrond Myklebust dprintk("%s: name=%s\n", __func__, group_name->data);
40146f1f6220SKinglong Mee return NFS_ATTR_FATTR_GROUP_NAME;
4015686a816aSTrond Myklebust } else {
4016686a816aSTrond Myklebust len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4017686a816aSTrond Myklebust XDR_MAX_NETOBJ);
4018686a816aSTrond Myklebust if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4019686a816aSTrond Myklebust goto out;
4020e5782076SEric W. Biederman dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4021686a816aSTrond Myklebust return NFS_ATTR_FATTR_GROUP;
4022686a816aSTrond Myklebust }
4023686a816aSTrond Myklebust out:
4024eb72f484SChuck Lever if (len == -EBADMSG)
4025c0eae66eSBenny Halevy return -EIO;
4026eb72f484SChuck Lever return 0;
40271da177e4SLinus Torvalds }
40281da177e4SLinus Torvalds
decode_attr_rdev(struct xdr_stream * xdr,uint32_t * bitmap,dev_t * rdev)40291da177e4SLinus Torvalds static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
40301da177e4SLinus Torvalds {
40318687b63aSAl Viro uint32_t major = 0, minor = 0;
40328687b63aSAl Viro __be32 *p;
4033409924e4STrond Myklebust int ret = 0;
40341da177e4SLinus Torvalds
40351da177e4SLinus Torvalds *rdev = MKDEV(0,0);
40361da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
40371da177e4SLinus Torvalds return -EIO;
40381da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
40391da177e4SLinus Torvalds dev_t tmp;
40401da177e4SLinus Torvalds
4041c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
4042c0eae66eSBenny Halevy if (unlikely(!p))
4043eb72f484SChuck Lever return -EIO;
40446f723f77SBenny Halevy major = be32_to_cpup(p++);
4045cccddf4fSBenny Halevy minor = be32_to_cpup(p);
40461da177e4SLinus Torvalds tmp = MKDEV(major, minor);
40471da177e4SLinus Torvalds if (MAJOR(tmp) == major && MINOR(tmp) == minor)
40481da177e4SLinus Torvalds *rdev = tmp;
40491da177e4SLinus Torvalds bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
4050409924e4STrond Myklebust ret = NFS_ATTR_FATTR_RDEV;
40511da177e4SLinus Torvalds }
40523110ff80SHarvey Harrison dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
4053409924e4STrond Myklebust return ret;
40541da177e4SLinus Torvalds }
40551da177e4SLinus Torvalds
decode_attr_space_avail(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res)40561da177e4SLinus Torvalds static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40571da177e4SLinus Torvalds {
40588687b63aSAl Viro __be32 *p;
40591da177e4SLinus Torvalds int status = 0;
40601da177e4SLinus Torvalds
40611da177e4SLinus Torvalds *res = 0;
40621da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
40631da177e4SLinus Torvalds return -EIO;
40641da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
4065c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
4066c0eae66eSBenny Halevy if (unlikely(!p))
4067eb72f484SChuck Lever return -EIO;
4068cccddf4fSBenny Halevy xdr_decode_hyper(p, res);
40691da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
40701da177e4SLinus Torvalds }
40713110ff80SHarvey Harrison dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
40721da177e4SLinus Torvalds return status;
40731da177e4SLinus Torvalds }
40741da177e4SLinus Torvalds
decode_attr_space_free(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res)40751da177e4SLinus Torvalds static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40761da177e4SLinus Torvalds {
40778687b63aSAl Viro __be32 *p;
40781da177e4SLinus Torvalds int status = 0;
40791da177e4SLinus Torvalds
40801da177e4SLinus Torvalds *res = 0;
40811da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
40821da177e4SLinus Torvalds return -EIO;
40831da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
4084c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
4085c0eae66eSBenny Halevy if (unlikely(!p))
4086eb72f484SChuck Lever return -EIO;
4087cccddf4fSBenny Halevy xdr_decode_hyper(p, res);
40881da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
40891da177e4SLinus Torvalds }
40903110ff80SHarvey Harrison dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
40911da177e4SLinus Torvalds return status;
40921da177e4SLinus Torvalds }
40931da177e4SLinus Torvalds
decode_attr_space_total(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res)40941da177e4SLinus Torvalds static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
40951da177e4SLinus Torvalds {
40968687b63aSAl Viro __be32 *p;
40971da177e4SLinus Torvalds int status = 0;
40981da177e4SLinus Torvalds
40991da177e4SLinus Torvalds *res = 0;
41001da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
41011da177e4SLinus Torvalds return -EIO;
41021da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
4103c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
4104c0eae66eSBenny Halevy if (unlikely(!p))
4105eb72f484SChuck Lever return -EIO;
4106cccddf4fSBenny Halevy xdr_decode_hyper(p, res);
41071da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
41081da177e4SLinus Torvalds }
41093110ff80SHarvey Harrison dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
41101da177e4SLinus Torvalds return status;
41111da177e4SLinus Torvalds }
41121da177e4SLinus Torvalds
decode_attr_space_used(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * used)41131da177e4SLinus Torvalds static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
41141da177e4SLinus Torvalds {
41158687b63aSAl Viro __be32 *p;
4116409924e4STrond Myklebust int ret = 0;
41171da177e4SLinus Torvalds
41181da177e4SLinus Torvalds *used = 0;
41191da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
41201da177e4SLinus Torvalds return -EIO;
41211da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
4122c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
4123c0eae66eSBenny Halevy if (unlikely(!p))
4124eb72f484SChuck Lever return -EIO;
4125cccddf4fSBenny Halevy xdr_decode_hyper(p, used);
41261da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
4127409924e4STrond Myklebust ret = NFS_ATTR_FATTR_SPACE_USED;
41281da177e4SLinus Torvalds }
41293110ff80SHarvey Harrison dprintk("%s: space used=%Lu\n", __func__,
41301da177e4SLinus Torvalds (unsigned long long)*used);
4131409924e4STrond Myklebust return ret;
41321da177e4SLinus Torvalds }
41331da177e4SLinus Torvalds
413436b3743fSTrond Myklebust static __be32 *
xdr_decode_nfstime4(__be32 * p,struct timespec64 * t)4135e86d5a02STrond Myklebust xdr_decode_nfstime4(__be32 *p, struct timespec64 *t)
413636b3743fSTrond Myklebust {
413736b3743fSTrond Myklebust __u64 sec;
413836b3743fSTrond Myklebust
413936b3743fSTrond Myklebust p = xdr_decode_hyper(p, &sec);
4140e86d5a02STrond Myklebust t-> tv_sec = sec;
414136b3743fSTrond Myklebust t->tv_nsec = be32_to_cpup(p++);
414236b3743fSTrond Myklebust return p;
414336b3743fSTrond Myklebust }
414436b3743fSTrond Myklebust
decode_attr_time(struct xdr_stream * xdr,struct timespec64 * time)4145e86d5a02STrond Myklebust static int decode_attr_time(struct xdr_stream *xdr, struct timespec64 *time)
41461da177e4SLinus Torvalds {
41478687b63aSAl Viro __be32 *p;
41481da177e4SLinus Torvalds
414936b3743fSTrond Myklebust p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
4150c0eae66eSBenny Halevy if (unlikely(!p))
4151eb72f484SChuck Lever return -EIO;
415236b3743fSTrond Myklebust xdr_decode_nfstime4(p, time);
41531da177e4SLinus Torvalds return 0;
41541da177e4SLinus Torvalds }
41551da177e4SLinus Torvalds
decode_attr_time_access(struct xdr_stream * xdr,uint32_t * bitmap,struct timespec64 * time)4156e86d5a02STrond Myklebust static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
41571da177e4SLinus Torvalds {
41581da177e4SLinus Torvalds int status = 0;
41591da177e4SLinus Torvalds
41601da177e4SLinus Torvalds time->tv_sec = 0;
41611da177e4SLinus Torvalds time->tv_nsec = 0;
41621da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
41631da177e4SLinus Torvalds return -EIO;
41641da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
41651da177e4SLinus Torvalds status = decode_attr_time(xdr, time);
4166409924e4STrond Myklebust if (status == 0)
4167409924e4STrond Myklebust status = NFS_ATTR_FATTR_ATIME;
41681da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
41691da177e4SLinus Torvalds }
4170ae08483cSArnd Bergmann dprintk("%s: atime=%lld\n", __func__, time->tv_sec);
41711da177e4SLinus Torvalds return status;
41721da177e4SLinus Torvalds }
41731da177e4SLinus Torvalds
decode_attr_time_metadata(struct xdr_stream * xdr,uint32_t * bitmap,struct timespec64 * time)4174e86d5a02STrond Myklebust static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
41751da177e4SLinus Torvalds {
41761da177e4SLinus Torvalds int status = 0;
41771da177e4SLinus Torvalds
41781da177e4SLinus Torvalds time->tv_sec = 0;
41791da177e4SLinus Torvalds time->tv_nsec = 0;
41801da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
41811da177e4SLinus Torvalds return -EIO;
41821da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
41831da177e4SLinus Torvalds status = decode_attr_time(xdr, time);
4184409924e4STrond Myklebust if (status == 0)
4185409924e4STrond Myklebust status = NFS_ATTR_FATTR_CTIME;
41861da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
41871da177e4SLinus Torvalds }
4188ae08483cSArnd Bergmann dprintk("%s: ctime=%lld\n", __func__, time->tv_sec);
41891da177e4SLinus Torvalds return status;
41901da177e4SLinus Torvalds }
41911da177e4SLinus Torvalds
decode_attr_time_delta(struct xdr_stream * xdr,uint32_t * bitmap,struct timespec64 * time)419255b6e774SRicardo Labiaga static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4193e86d5a02STrond Myklebust struct timespec64 *time)
419455b6e774SRicardo Labiaga {
419555b6e774SRicardo Labiaga int status = 0;
419655b6e774SRicardo Labiaga
419755b6e774SRicardo Labiaga time->tv_sec = 0;
419855b6e774SRicardo Labiaga time->tv_nsec = 0;
419955b6e774SRicardo Labiaga if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
420055b6e774SRicardo Labiaga return -EIO;
420155b6e774SRicardo Labiaga if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
420255b6e774SRicardo Labiaga status = decode_attr_time(xdr, time);
420355b6e774SRicardo Labiaga bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
420455b6e774SRicardo Labiaga }
4205ae08483cSArnd Bergmann dprintk("%s: time_delta=%lld %ld\n", __func__, time->tv_sec,
4206ae08483cSArnd Bergmann time->tv_nsec);
420755b6e774SRicardo Labiaga return status;
420855b6e774SRicardo Labiaga }
420955b6e774SRicardo Labiaga
decode_attr_security_label(struct xdr_stream * xdr,uint32_t * bitmap,struct nfs4_label * label)4210aa9c2669SDavid Quigley static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4211aa9c2669SDavid Quigley struct nfs4_label *label)
4212aa9c2669SDavid Quigley {
4213aa9c2669SDavid Quigley uint32_t pi = 0;
4214aa9c2669SDavid Quigley uint32_t lfs = 0;
4215aa9c2669SDavid Quigley __u32 len;
4216aa9c2669SDavid Quigley __be32 *p;
4217aa9c2669SDavid Quigley int status = 0;
4218aa9c2669SDavid Quigley
4219aa9c2669SDavid Quigley if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4220aa9c2669SDavid Quigley return -EIO;
4221aa9c2669SDavid Quigley if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4222aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4);
4223aa9c2669SDavid Quigley if (unlikely(!p))
4224eb72f484SChuck Lever return -EIO;
4225aa9c2669SDavid Quigley lfs = be32_to_cpup(p++);
4226aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4);
4227aa9c2669SDavid Quigley if (unlikely(!p))
4228eb72f484SChuck Lever return -EIO;
4229aa9c2669SDavid Quigley pi = be32_to_cpup(p++);
4230aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, 4);
4231aa9c2669SDavid Quigley if (unlikely(!p))
4232eb72f484SChuck Lever return -EIO;
4233aa9c2669SDavid Quigley len = be32_to_cpup(p++);
4234aa9c2669SDavid Quigley p = xdr_inline_decode(xdr, len);
4235aa9c2669SDavid Quigley if (unlikely(!p))
4236eb72f484SChuck Lever return -EIO;
4237eef7314cSTrond Myklebust bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4238aa9c2669SDavid Quigley if (len < NFS4_MAXLABELLEN) {
4239*43c1031fSTrond Myklebust if (label && label->len) {
4240b4487b93SJeffrey Mitchell if (label->len < len)
4241b4487b93SJeffrey Mitchell return -ERANGE;
4242aa9c2669SDavid Quigley memcpy(label->label, p, len);
4243aa9c2669SDavid Quigley label->len = len;
4244aa9c2669SDavid Quigley label->pi = pi;
4245aa9c2669SDavid Quigley label->lfs = lfs;
4246aa9c2669SDavid Quigley status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4247aa9c2669SDavid Quigley }
4248aa9c2669SDavid Quigley } else
4249aa9c2669SDavid Quigley printk(KERN_WARNING "%s: label too long (%u)!\n",
4250aa9c2669SDavid Quigley __func__, len);
4251aa9c2669SDavid Quigley if (label && label->label)
42522c52c837SOlga Kornievskaia dprintk("%s: label=%.*s, len=%d, PI=%d, LFS=%d\n",
42532c52c837SOlga Kornievskaia __func__, label->len, (char *)label->label,
42542c52c837SOlga Kornievskaia label->len, label->pi, label->lfs);
42552c52c837SOlga Kornievskaia }
4256aa9c2669SDavid Quigley return status;
4257aa9c2669SDavid Quigley }
4258aa9c2669SDavid Quigley
decode_attr_time_modify(struct xdr_stream * xdr,uint32_t * bitmap,struct timespec64 * time)4259e86d5a02STrond Myklebust static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec64 *time)
42601da177e4SLinus Torvalds {
42611da177e4SLinus Torvalds int status = 0;
42621da177e4SLinus Torvalds
42631da177e4SLinus Torvalds time->tv_sec = 0;
42641da177e4SLinus Torvalds time->tv_nsec = 0;
42651da177e4SLinus Torvalds if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
42661da177e4SLinus Torvalds return -EIO;
42671da177e4SLinus Torvalds if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
42681da177e4SLinus Torvalds status = decode_attr_time(xdr, time);
4269409924e4STrond Myklebust if (status == 0)
4270409924e4STrond Myklebust status = NFS_ATTR_FATTR_MTIME;
42711da177e4SLinus Torvalds bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
42721da177e4SLinus Torvalds }
4273ae08483cSArnd Bergmann dprintk("%s: mtime=%lld\n", __func__, time->tv_sec);
42741da177e4SLinus Torvalds return status;
42751da177e4SLinus Torvalds }
42761da177e4SLinus Torvalds
decode_attr_xattrsupport(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)4277b78ef845SFrank van der Linden static int decode_attr_xattrsupport(struct xdr_stream *xdr, uint32_t *bitmap,
4278b78ef845SFrank van der Linden uint32_t *res)
4279b78ef845SFrank van der Linden {
4280b78ef845SFrank van der Linden __be32 *p;
4281b78ef845SFrank van der Linden
4282b78ef845SFrank van der Linden *res = 0;
4283b78ef845SFrank van der Linden if (unlikely(bitmap[2] & (FATTR4_WORD2_XATTR_SUPPORT - 1U)))
4284b78ef845SFrank van der Linden return -EIO;
4285b78ef845SFrank van der Linden if (likely(bitmap[2] & FATTR4_WORD2_XATTR_SUPPORT)) {
4286b78ef845SFrank van der Linden p = xdr_inline_decode(xdr, 4);
4287b78ef845SFrank van der Linden if (unlikely(!p))
4288b78ef845SFrank van der Linden return -EIO;
4289b78ef845SFrank van der Linden *res = be32_to_cpup(p);
4290b78ef845SFrank van der Linden bitmap[2] &= ~FATTR4_WORD2_XATTR_SUPPORT;
4291b78ef845SFrank van der Linden }
4292b78ef845SFrank van der Linden dprintk("%s: XATTR support=%s\n", __func__,
4293b78ef845SFrank van der Linden *res == 0 ? "false" : "true");
4294b78ef845SFrank van der Linden return 0;
4295b78ef845SFrank van der Linden }
4296b78ef845SFrank van der Linden
verify_attr_len(struct xdr_stream * xdr,unsigned int savep,uint32_t attrlen)4297256e48bbSTrond Myklebust static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
42981da177e4SLinus Torvalds {
42991da177e4SLinus Torvalds unsigned int attrwords = XDR_QUADLEN(attrlen);
4300256e48bbSTrond Myklebust unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
43011da177e4SLinus Torvalds
43021da177e4SLinus Torvalds if (unlikely(attrwords != nwords)) {
4303fe82a183SChuck Lever dprintk("%s: server returned incorrect attribute length: "
4304fe82a183SChuck Lever "%u %c %u\n",
43053110ff80SHarvey Harrison __func__,
43061da177e4SLinus Torvalds attrwords << 2,
43071da177e4SLinus Torvalds (attrwords < nwords) ? '<' : '>',
43081da177e4SLinus Torvalds nwords << 2);
43091da177e4SLinus Torvalds return -EIO;
43101da177e4SLinus Torvalds }
43111da177e4SLinus Torvalds return 0;
43121da177e4SLinus Torvalds }
43131da177e4SLinus Torvalds
decode_change_info(struct xdr_stream * xdr,struct nfs4_change_info * cinfo)43141da177e4SLinus Torvalds static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
43151da177e4SLinus Torvalds {
43168687b63aSAl Viro __be32 *p;
43171da177e4SLinus Torvalds
4318c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20);
4319c0eae66eSBenny Halevy if (unlikely(!p))
4320eb72f484SChuck Lever return -EIO;
43216f723f77SBenny Halevy cinfo->atomic = be32_to_cpup(p++);
43223ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &cinfo->before);
4323cccddf4fSBenny Halevy xdr_decode_hyper(p, &cinfo->after);
43241da177e4SLinus Torvalds return 0;
43251da177e4SLinus Torvalds }
43261da177e4SLinus Torvalds
decode_access(struct xdr_stream * xdr,u32 * supported,u32 * access)43276168f62cSWeston Andros Adamson static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
43281da177e4SLinus Torvalds {
43298687b63aSAl Viro __be32 *p;
43301da177e4SLinus Torvalds uint32_t supp, acc;
43311da177e4SLinus Torvalds int status;
43321da177e4SLinus Torvalds
43331da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_ACCESS);
43341da177e4SLinus Torvalds if (status)
43351da177e4SLinus Torvalds return status;
4336c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
4337c0eae66eSBenny Halevy if (unlikely(!p))
4338eb72f484SChuck Lever return -EIO;
43396f723f77SBenny Halevy supp = be32_to_cpup(p++);
4340cccddf4fSBenny Halevy acc = be32_to_cpup(p);
43416168f62cSWeston Andros Adamson *supported = supp;
43426168f62cSWeston Andros Adamson *access = acc;
43431da177e4SLinus Torvalds return 0;
43441da177e4SLinus Torvalds }
43451da177e4SLinus Torvalds
decode_opaque_fixed(struct xdr_stream * xdr,void * buf,size_t len)434607d30434SBenny Halevy static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
43471da177e4SLinus Torvalds {
4348ab6e9aafSTrond Myklebust ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4349eb72f484SChuck Lever if (unlikely(ret < 0))
435007d30434SBenny Halevy return -EIO;
4351ab6e9aafSTrond Myklebust return 0;
4352ab6e9aafSTrond Myklebust }
435307d30434SBenny Halevy
decode_stateid(struct xdr_stream * xdr,nfs4_stateid * stateid)435407d30434SBenny Halevy static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
435507d30434SBenny Halevy {
43562d2f24adSTrond Myklebust return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
43571da177e4SLinus Torvalds }
43581da177e4SLinus Torvalds
decode_open_stateid(struct xdr_stream * xdr,nfs4_stateid * stateid)435993b717fdSTrond Myklebust static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
436093b717fdSTrond Myklebust {
436193b717fdSTrond Myklebust stateid->type = NFS4_OPEN_STATEID_TYPE;
436293b717fdSTrond Myklebust return decode_stateid(xdr, stateid);
436393b717fdSTrond Myklebust }
436493b717fdSTrond Myklebust
decode_lock_stateid(struct xdr_stream * xdr,nfs4_stateid * stateid)436593b717fdSTrond Myklebust static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
436693b717fdSTrond Myklebust {
436793b717fdSTrond Myklebust stateid->type = NFS4_LOCK_STATEID_TYPE;
436893b717fdSTrond Myklebust return decode_stateid(xdr, stateid);
436993b717fdSTrond Myklebust }
437093b717fdSTrond Myklebust
decode_delegation_stateid(struct xdr_stream * xdr,nfs4_stateid * stateid)437193b717fdSTrond Myklebust static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
437293b717fdSTrond Myklebust {
437393b717fdSTrond Myklebust stateid->type = NFS4_DELEGATION_STATEID_TYPE;
437493b717fdSTrond Myklebust return decode_stateid(xdr, stateid);
437593b717fdSTrond Myklebust }
437693b717fdSTrond Myklebust
decode_invalid_stateid(struct xdr_stream * xdr,nfs4_stateid * stateid)4377fcd8843cSTrond Myklebust static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4378fcd8843cSTrond Myklebust {
4379fcd8843cSTrond Myklebust nfs4_stateid dummy;
4380fcd8843cSTrond Myklebust
4381fcd8843cSTrond Myklebust nfs4_stateid_copy(stateid, &invalid_stateid);
4382fcd8843cSTrond Myklebust return decode_stateid(xdr, &dummy);
4383fcd8843cSTrond Myklebust }
4384fcd8843cSTrond Myklebust
decode_close(struct xdr_stream * xdr,struct nfs_closeres * res)43851da177e4SLinus Torvalds static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
43861da177e4SLinus Torvalds {
43871da177e4SLinus Torvalds int status;
43881da177e4SLinus Torvalds
43891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CLOSE);
4390c1d51931STrond Myklebust if (status != -EIO)
4391c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid);
439207d30434SBenny Halevy if (!status)
4393fcd8843cSTrond Myklebust status = decode_invalid_stateid(xdr, &res->stateid);
43941da177e4SLinus Torvalds return status;
43951da177e4SLinus Torvalds }
43961da177e4SLinus Torvalds
decode_verifier(struct xdr_stream * xdr,void * verifier)4397db942bbdSBenny Halevy static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4398db942bbdSBenny Halevy {
4399cd93710eSChuck Lever return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
44001da177e4SLinus Torvalds }
44011da177e4SLinus Torvalds
decode_write_verifier(struct xdr_stream * xdr,struct nfs_write_verifier * verifier)44022f2c63bcSTrond Myklebust static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
44032f2c63bcSTrond Myklebust {
44042f2c63bcSTrond Myklebust return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
44052f2c63bcSTrond Myklebust }
44062f2c63bcSTrond Myklebust
decode_commit(struct xdr_stream * xdr,struct nfs_commitres * res)44070b7c0153SFred Isaman static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
44081da177e4SLinus Torvalds {
4409221203ceSTrond Myklebust struct nfs_writeverf *verf = res->verf;
44101da177e4SLinus Torvalds int status;
44111da177e4SLinus Torvalds
44121da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_COMMIT);
4413db942bbdSBenny Halevy if (!status)
4414221203ceSTrond Myklebust status = decode_write_verifier(xdr, &verf->verifier);
4415221203ceSTrond Myklebust if (!status)
4416221203ceSTrond Myklebust verf->committed = NFS_FILE_SYNC;
44171da177e4SLinus Torvalds return status;
44181da177e4SLinus Torvalds }
44191da177e4SLinus Torvalds
decode_create(struct xdr_stream * xdr,struct nfs4_change_info * cinfo)44201da177e4SLinus Torvalds static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
44211da177e4SLinus Torvalds {
44228687b63aSAl Viro __be32 *p;
44231da177e4SLinus Torvalds uint32_t bmlen;
44241da177e4SLinus Torvalds int status;
44251da177e4SLinus Torvalds
44261da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_CREATE);
44271da177e4SLinus Torvalds if (status)
44281da177e4SLinus Torvalds return status;
44291da177e4SLinus Torvalds if ((status = decode_change_info(xdr, cinfo)))
44301da177e4SLinus Torvalds return status;
4431c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
4432c0eae66eSBenny Halevy if (unlikely(!p))
4433eb72f484SChuck Lever return -EIO;
4434cccddf4fSBenny Halevy bmlen = be32_to_cpup(p);
4435c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2);
4436c0eae66eSBenny Halevy if (likely(p))
44371da177e4SLinus Torvalds return 0;
4438c0eae66eSBenny Halevy return -EIO;
44391da177e4SLinus Torvalds }
44401da177e4SLinus Torvalds
decode_server_caps(struct xdr_stream * xdr,struct nfs4_server_caps_res * res)44411da177e4SLinus Torvalds static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
44421da177e4SLinus Torvalds {
4443256e48bbSTrond Myklebust unsigned int savep;
4444dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0};
44451da177e4SLinus Torvalds int status;
44461da177e4SLinus Torvalds
44471da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44481da177e4SLinus Torvalds goto xdr_error;
44491da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44501da177e4SLinus Torvalds goto xdr_error;
44511da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44521da177e4SLinus Torvalds goto xdr_error;
44531da177e4SLinus Torvalds if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
44541da177e4SLinus Torvalds goto xdr_error;
4455264e6351SChuck Lever if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4456264e6351SChuck Lever &res->fh_expire_type)) != 0)
4457264e6351SChuck Lever goto xdr_error;
44581da177e4SLinus Torvalds if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
44591da177e4SLinus Torvalds goto xdr_error;
44601da177e4SLinus Torvalds if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
44611da177e4SLinus Torvalds goto xdr_error;
44621da177e4SLinus Torvalds if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
44631da177e4SLinus Torvalds goto xdr_error;
44641ab5be4aSTrond Myklebust if ((status = decode_attr_case_insensitive(xdr, bitmap, &res->case_insensitive)) != 0)
44651ab5be4aSTrond Myklebust goto xdr_error;
44661ab5be4aSTrond Myklebust if ((status = decode_attr_case_preserving(xdr, bitmap, &res->case_preserving)) != 0)
44671ab5be4aSTrond Myklebust goto xdr_error;
44688c61282fSKinglong Mee if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
44698c61282fSKinglong Mee res->exclcreat_bitmask)) != 0)
44708c61282fSKinglong Mee goto xdr_error;
44711da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen);
44721da177e4SLinus Torvalds xdr_error:
44733110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status);
44741da177e4SLinus Torvalds return status;
44751da177e4SLinus Torvalds }
44761da177e4SLinus Torvalds
decode_statfs(struct xdr_stream * xdr,struct nfs_fsstat * fsstat)44771da177e4SLinus Torvalds static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
44781da177e4SLinus Torvalds {
4479256e48bbSTrond Myklebust unsigned int savep;
4480dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0};
44811da177e4SLinus Torvalds int status;
44821da177e4SLinus Torvalds
44831da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
44841da177e4SLinus Torvalds goto xdr_error;
44851da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
44861da177e4SLinus Torvalds goto xdr_error;
44871da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
44881da177e4SLinus Torvalds goto xdr_error;
44891da177e4SLinus Torvalds
44901da177e4SLinus Torvalds if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
44911da177e4SLinus Torvalds goto xdr_error;
44921da177e4SLinus Torvalds if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
44931da177e4SLinus Torvalds goto xdr_error;
44941da177e4SLinus Torvalds if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
44951da177e4SLinus Torvalds goto xdr_error;
44961ca843a2SAndreas Gruenbacher
44971ca843a2SAndreas Gruenbacher status = -EIO;
44981ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0]))
44991ca843a2SAndreas Gruenbacher goto xdr_error;
45001ca843a2SAndreas Gruenbacher
45011da177e4SLinus Torvalds if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
45021da177e4SLinus Torvalds goto xdr_error;
45031da177e4SLinus Torvalds if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
45041da177e4SLinus Torvalds goto xdr_error;
45051da177e4SLinus Torvalds if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
45061da177e4SLinus Torvalds goto xdr_error;
45071da177e4SLinus Torvalds
45081da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen);
45091da177e4SLinus Torvalds xdr_error:
45103110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status);
45111da177e4SLinus Torvalds return status;
45121da177e4SLinus Torvalds }
45131da177e4SLinus Torvalds
decode_pathconf(struct xdr_stream * xdr,struct nfs_pathconf * pathconf)45141da177e4SLinus Torvalds static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
45151da177e4SLinus Torvalds {
4516256e48bbSTrond Myklebust unsigned int savep;
4517dae100c2SFred Isaman uint32_t attrlen, bitmap[3] = {0};
45181da177e4SLinus Torvalds int status;
45191da177e4SLinus Torvalds
45201da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
45211da177e4SLinus Torvalds goto xdr_error;
45221da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
45231da177e4SLinus Torvalds goto xdr_error;
45241da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
45251da177e4SLinus Torvalds goto xdr_error;
45261da177e4SLinus Torvalds
45271da177e4SLinus Torvalds if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
45281da177e4SLinus Torvalds goto xdr_error;
45291da177e4SLinus Torvalds if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
45301da177e4SLinus Torvalds goto xdr_error;
45311da177e4SLinus Torvalds
45321da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen);
45331da177e4SLinus Torvalds xdr_error:
45343110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status);
45351da177e4SLinus Torvalds return status;
45361da177e4SLinus Torvalds }
45371da177e4SLinus Torvalds
decode_threshold_hint(struct xdr_stream * xdr,uint32_t * bitmap,uint64_t * res,uint32_t hint_bit)453888034c3dSAndy Adamson static int decode_threshold_hint(struct xdr_stream *xdr,
453988034c3dSAndy Adamson uint32_t *bitmap,
454088034c3dSAndy Adamson uint64_t *res,
454188034c3dSAndy Adamson uint32_t hint_bit)
454288034c3dSAndy Adamson {
454388034c3dSAndy Adamson __be32 *p;
454488034c3dSAndy Adamson
454588034c3dSAndy Adamson *res = 0;
454688034c3dSAndy Adamson if (likely(bitmap[0] & hint_bit)) {
454788034c3dSAndy Adamson p = xdr_inline_decode(xdr, 8);
454888034c3dSAndy Adamson if (unlikely(!p))
4549eb72f484SChuck Lever return -EIO;
455088034c3dSAndy Adamson xdr_decode_hyper(p, res);
455188034c3dSAndy Adamson }
455288034c3dSAndy Adamson return 0;
455388034c3dSAndy Adamson }
455488034c3dSAndy Adamson
decode_first_threshold_item4(struct xdr_stream * xdr,struct nfs4_threshold * res)455588034c3dSAndy Adamson static int decode_first_threshold_item4(struct xdr_stream *xdr,
455688034c3dSAndy Adamson struct nfs4_threshold *res)
455788034c3dSAndy Adamson {
4558256e48bbSTrond Myklebust __be32 *p;
4559256e48bbSTrond Myklebust unsigned int savep;
456088034c3dSAndy Adamson uint32_t bitmap[3] = {0,}, attrlen;
456188034c3dSAndy Adamson int status;
456288034c3dSAndy Adamson
456388034c3dSAndy Adamson /* layout type */
456488034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4);
4565eb72f484SChuck Lever if (unlikely(!p))
456688034c3dSAndy Adamson return -EIO;
456788034c3dSAndy Adamson res->l_type = be32_to_cpup(p);
456888034c3dSAndy Adamson
456988034c3dSAndy Adamson /* thi_hintset bitmap */
457088034c3dSAndy Adamson status = decode_attr_bitmap(xdr, bitmap);
457188034c3dSAndy Adamson if (status < 0)
457288034c3dSAndy Adamson goto xdr_error;
457388034c3dSAndy Adamson
457488034c3dSAndy Adamson /* thi_hintlist length */
457588034c3dSAndy Adamson status = decode_attr_length(xdr, &attrlen, &savep);
457688034c3dSAndy Adamson if (status < 0)
457788034c3dSAndy Adamson goto xdr_error;
457888034c3dSAndy Adamson /* thi_hintlist */
457988034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
458088034c3dSAndy Adamson if (status < 0)
458188034c3dSAndy Adamson goto xdr_error;
458288034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
458388034c3dSAndy Adamson if (status < 0)
458488034c3dSAndy Adamson goto xdr_error;
458588034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
458688034c3dSAndy Adamson THRESHOLD_RD_IO);
458788034c3dSAndy Adamson if (status < 0)
458888034c3dSAndy Adamson goto xdr_error;
458988034c3dSAndy Adamson status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
459088034c3dSAndy Adamson THRESHOLD_WR_IO);
459188034c3dSAndy Adamson if (status < 0)
459288034c3dSAndy Adamson goto xdr_error;
459388034c3dSAndy Adamson
459488034c3dSAndy Adamson status = verify_attr_len(xdr, savep, attrlen);
459588034c3dSAndy Adamson res->bm = bitmap[0];
459688034c3dSAndy Adamson
459788034c3dSAndy Adamson dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
459888034c3dSAndy Adamson __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
459988034c3dSAndy Adamson res->wr_io_sz);
460088034c3dSAndy Adamson xdr_error:
460188034c3dSAndy Adamson dprintk("%s ret=%d!\n", __func__, status);
460288034c3dSAndy Adamson return status;
460388034c3dSAndy Adamson }
460488034c3dSAndy Adamson
460588034c3dSAndy Adamson /*
460688034c3dSAndy Adamson * Thresholds on pNFS direct I/O vrs MDS I/O
460788034c3dSAndy Adamson */
decode_attr_mdsthreshold(struct xdr_stream * xdr,uint32_t * bitmap,struct nfs4_threshold * res)460888034c3dSAndy Adamson static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
460988034c3dSAndy Adamson uint32_t *bitmap,
461088034c3dSAndy Adamson struct nfs4_threshold *res)
461188034c3dSAndy Adamson {
461288034c3dSAndy Adamson __be32 *p;
461388034c3dSAndy Adamson int status = 0;
461488034c3dSAndy Adamson uint32_t num;
461588034c3dSAndy Adamson
461688034c3dSAndy Adamson if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
461788034c3dSAndy Adamson return -EIO;
4618029c5347STrond Myklebust if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
46191549210fSTrond Myklebust /* Did the server return an unrequested attribute? */
46201549210fSTrond Myklebust if (unlikely(res == NULL))
46211549210fSTrond Myklebust return -EREMOTEIO;
462288034c3dSAndy Adamson p = xdr_inline_decode(xdr, 4);
462388034c3dSAndy Adamson if (unlikely(!p))
4624eb72f484SChuck Lever return -EIO;
462588034c3dSAndy Adamson num = be32_to_cpup(p);
462688034c3dSAndy Adamson if (num == 0)
462788034c3dSAndy Adamson return 0;
462888034c3dSAndy Adamson if (num > 1)
462988034c3dSAndy Adamson printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
463088034c3dSAndy Adamson "drivers per filesystem not supported\n",
463188034c3dSAndy Adamson __func__);
463288034c3dSAndy Adamson
463388034c3dSAndy Adamson status = decode_first_threshold_item4(xdr, res);
4634029c5347STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
463588034c3dSAndy Adamson }
463688034c3dSAndy Adamson return status;
463788034c3dSAndy Adamson }
463888034c3dSAndy Adamson
decode_getfattr_attrs(struct xdr_stream * xdr,uint32_t * bitmap,struct nfs_fattr * fattr,struct nfs_fh * fh,struct nfs4_fs_locations * fs_loc,const struct nfs_server * server)4639ae42c70aSBryan Schumaker static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4640ae42c70aSBryan Schumaker struct nfs_fattr *fattr, struct nfs_fh *fh,
46411e2f67daSAnna Schumaker struct nfs4_fs_locations *fs_loc, const struct nfs_server *server)
46421da177e4SLinus Torvalds {
4643bca79478STrond Myklebust int status;
4644bca79478STrond Myklebust umode_t fmode = 0;
4645ae42c70aSBryan Schumaker uint32_t type;
4646ee7b75fcSTrond Myklebust int32_t err;
46471da177e4SLinus Torvalds
4648f26c7a78STrond Myklebust status = decode_attr_type(xdr, bitmap, &type);
4649f26c7a78STrond Myklebust if (status < 0)
46501da177e4SLinus Torvalds goto xdr_error;
4651409924e4STrond Myklebust fattr->mode = 0;
4652409924e4STrond Myklebust if (status != 0) {
4653409924e4STrond Myklebust fattr->mode |= nfs_type2fmt[type];
4654409924e4STrond Myklebust fattr->valid |= status;
4655409924e4STrond Myklebust }
46561da177e4SLinus Torvalds
4657f26c7a78STrond Myklebust status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4658f26c7a78STrond Myklebust if (status < 0)
46591da177e4SLinus Torvalds goto xdr_error;
4660409924e4STrond Myklebust fattr->valid |= status;
4661f26c7a78STrond Myklebust
4662f26c7a78STrond Myklebust status = decode_attr_size(xdr, bitmap, &fattr->size);
4663f26c7a78STrond Myklebust if (status < 0)
46641da177e4SLinus Torvalds goto xdr_error;
4665409924e4STrond Myklebust fattr->valid |= status;
4666f26c7a78STrond Myklebust
4667f26c7a78STrond Myklebust status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4668f26c7a78STrond Myklebust if (status < 0)
46691da177e4SLinus Torvalds goto xdr_error;
4670409924e4STrond Myklebust fattr->valid |= status;
4671f26c7a78STrond Myklebust
4672ee7b75fcSTrond Myklebust err = 0;
4673ee7b75fcSTrond Myklebust status = decode_attr_error(xdr, bitmap, &err);
4674ae42c70aSBryan Schumaker if (status < 0)
4675ae42c70aSBryan Schumaker goto xdr_error;
4676ae42c70aSBryan Schumaker
4677ae42c70aSBryan Schumaker status = decode_attr_filehandle(xdr, bitmap, fh);
4678ae42c70aSBryan Schumaker if (status < 0)
4679ae42c70aSBryan Schumaker goto xdr_error;
4680ae42c70aSBryan Schumaker
4681f26c7a78STrond Myklebust status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4682f26c7a78STrond Myklebust if (status < 0)
46831da177e4SLinus Torvalds goto xdr_error;
4684409924e4STrond Myklebust fattr->valid |= status;
4685f26c7a78STrond Myklebust
46868b7e3f49STrond Myklebust status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
4687f26c7a78STrond Myklebust if (status < 0)
4688683b57b4STrond Myklebust goto xdr_error;
4689409924e4STrond Myklebust fattr->valid |= status;
4690f26c7a78STrond Myklebust
46911ca843a2SAndreas Gruenbacher status = -EIO;
46921ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0]))
46931ca843a2SAndreas Gruenbacher goto xdr_error;
46941ca843a2SAndreas Gruenbacher
4695f26c7a78STrond Myklebust status = decode_attr_mode(xdr, bitmap, &fmode);
4696f26c7a78STrond Myklebust if (status < 0)
46971da177e4SLinus Torvalds goto xdr_error;
4698409924e4STrond Myklebust if (status != 0) {
46991da177e4SLinus Torvalds fattr->mode |= fmode;
4700409924e4STrond Myklebust fattr->valid |= status;
4701409924e4STrond Myklebust }
4702f26c7a78STrond Myklebust
4703f26c7a78STrond Myklebust status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4704f26c7a78STrond Myklebust if (status < 0)
47051da177e4SLinus Torvalds goto xdr_error;
4706409924e4STrond Myklebust fattr->valid |= status;
4707f26c7a78STrond Myklebust
47086926afd1STrond Myklebust status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
4709f26c7a78STrond Myklebust if (status < 0)
47101da177e4SLinus Torvalds goto xdr_error;
4711409924e4STrond Myklebust fattr->valid |= status;
4712f26c7a78STrond Myklebust
47136926afd1STrond Myklebust status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
4714f26c7a78STrond Myklebust if (status < 0)
47151da177e4SLinus Torvalds goto xdr_error;
4716409924e4STrond Myklebust fattr->valid |= status;
4717f26c7a78STrond Myklebust
4718f26c7a78STrond Myklebust status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4719f26c7a78STrond Myklebust if (status < 0)
47201da177e4SLinus Torvalds goto xdr_error;
4721409924e4STrond Myklebust fattr->valid |= status;
4722f26c7a78STrond Myklebust
4723f26c7a78STrond Myklebust status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4724f26c7a78STrond Myklebust if (status < 0)
47251da177e4SLinus Torvalds goto xdr_error;
4726409924e4STrond Myklebust fattr->valid |= status;
4727f26c7a78STrond Myklebust
4728f26c7a78STrond Myklebust status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4729f26c7a78STrond Myklebust if (status < 0)
47301da177e4SLinus Torvalds goto xdr_error;
4731409924e4STrond Myklebust fattr->valid |= status;
4732f26c7a78STrond Myklebust
4733f26c7a78STrond Myklebust status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4734f26c7a78STrond Myklebust if (status < 0)
47351da177e4SLinus Torvalds goto xdr_error;
4736409924e4STrond Myklebust fattr->valid |= status;
4737f26c7a78STrond Myklebust
4738f26c7a78STrond Myklebust status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4739f26c7a78STrond Myklebust if (status < 0)
47401da177e4SLinus Torvalds goto xdr_error;
4741409924e4STrond Myklebust fattr->valid |= status;
4742f26c7a78STrond Myklebust
474328331a46STrond Myklebust status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
4744f26c7a78STrond Myklebust if (status < 0)
474599baf625SManoj Naik goto xdr_error;
4746409924e4STrond Myklebust fattr->valid |= status;
4747f26c7a78STrond Myklebust
47481ca843a2SAndreas Gruenbacher status = -EIO;
47491ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1]))
47501ca843a2SAndreas Gruenbacher goto xdr_error;
47511ca843a2SAndreas Gruenbacher
475288034c3dSAndy Adamson status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
475388034c3dSAndy Adamson if (status < 0)
475488034c3dSAndy Adamson goto xdr_error;
475588034c3dSAndy Adamson
47561e2f67daSAnna Schumaker status = decode_attr_security_label(xdr, bitmap, fattr->label);
4757aa9c2669SDavid Quigley if (status < 0)
4758aa9c2669SDavid Quigley goto xdr_error;
4759aa9c2669SDavid Quigley fattr->valid |= status;
4760aa9c2669SDavid Quigley
4761ae42c70aSBryan Schumaker xdr_error:
4762ae42c70aSBryan Schumaker dprintk("%s: xdr returned %d\n", __func__, -status);
4763ae42c70aSBryan Schumaker return status;
4764ae42c70aSBryan Schumaker }
4765ae42c70aSBryan Schumaker
decode_getfattr_generic(struct xdr_stream * xdr,struct nfs_fattr * fattr,struct nfs_fh * fh,struct nfs4_fs_locations * fs_loc,const struct nfs_server * server)4766ae42c70aSBryan Schumaker static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47678b7e3f49STrond Myklebust struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
47681e2f67daSAnna Schumaker const struct nfs_server *server)
4769ae42c70aSBryan Schumaker {
4770256e48bbSTrond Myklebust unsigned int savep;
4771ae42c70aSBryan Schumaker uint32_t attrlen,
4772dae100c2SFred Isaman bitmap[3] = {0};
4773ae42c70aSBryan Schumaker int status;
4774ae42c70aSBryan Schumaker
4775ae42c70aSBryan Schumaker status = decode_op_hdr(xdr, OP_GETATTR);
4776ae42c70aSBryan Schumaker if (status < 0)
4777ae42c70aSBryan Schumaker goto xdr_error;
4778ae42c70aSBryan Schumaker
4779ae42c70aSBryan Schumaker status = decode_attr_bitmap(xdr, bitmap);
4780ae42c70aSBryan Schumaker if (status < 0)
4781ae42c70aSBryan Schumaker goto xdr_error;
4782ae42c70aSBryan Schumaker
4783ae42c70aSBryan Schumaker status = decode_attr_length(xdr, &attrlen, &savep);
4784ae42c70aSBryan Schumaker if (status < 0)
4785ae42c70aSBryan Schumaker goto xdr_error;
4786ae42c70aSBryan Schumaker
47871e2f67daSAnna Schumaker status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc, server);
4788ae42c70aSBryan Schumaker if (status < 0)
4789ae42c70aSBryan Schumaker goto xdr_error;
4790ae42c70aSBryan Schumaker
4791f26c7a78STrond Myklebust status = verify_attr_len(xdr, savep, attrlen);
47921da177e4SLinus Torvalds xdr_error:
47933110ff80SHarvey Harrison dprintk("%s: xdr returned %d\n", __func__, -status);
47941da177e4SLinus Torvalds return status;
47951da177e4SLinus Torvalds }
47961da177e4SLinus Torvalds
decode_getfattr(struct xdr_stream * xdr,struct nfs_fattr * fattr,const struct nfs_server * server)4797ae42c70aSBryan Schumaker static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
47986926afd1STrond Myklebust const struct nfs_server *server)
4799ae42c70aSBryan Schumaker {
48001e2f67daSAnna Schumaker return decode_getfattr_generic(xdr, fattr, NULL, NULL, server);
4801ae42c70aSBryan Schumaker }
48021da177e4SLinus Torvalds
4803504913fbSAndy Adamson /*
48043132e49eSJeff Layton * Decode potentially multiple layout types.
4805504913fbSAndy Adamson */
decode_pnfs_layout_types(struct xdr_stream * xdr,struct nfs_fsinfo * fsinfo)48063132e49eSJeff Layton static int decode_pnfs_layout_types(struct xdr_stream *xdr,
4807ca440c38SJeff Layton struct nfs_fsinfo *fsinfo)
4808504913fbSAndy Adamson {
4809b8a8a0ddSTrond Myklebust __be32 *p;
4810ca440c38SJeff Layton uint32_t i;
4811504913fbSAndy Adamson
4812504913fbSAndy Adamson p = xdr_inline_decode(xdr, 4);
4813504913fbSAndy Adamson if (unlikely(!p))
4814eb72f484SChuck Lever return -EIO;
4815ca440c38SJeff Layton fsinfo->nlayouttypes = be32_to_cpup(p);
4816504913fbSAndy Adamson
4817504913fbSAndy Adamson /* pNFS is not supported by the underlying file system */
4818ca440c38SJeff Layton if (fsinfo->nlayouttypes == 0)
4819504913fbSAndy Adamson return 0;
4820504913fbSAndy Adamson
4821504913fbSAndy Adamson /* Decode and set first layout type, move xdr->p past unused types */
4822ca440c38SJeff Layton p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
4823504913fbSAndy Adamson if (unlikely(!p))
4824eb72f484SChuck Lever return -EIO;
4825ca440c38SJeff Layton
4826ca440c38SJeff Layton /* If we get too many, then just cap it at the max */
4827ca440c38SJeff Layton if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4828ca440c38SJeff Layton printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4829ca440c38SJeff Layton __func__, fsinfo->nlayouttypes);
4830ca440c38SJeff Layton fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4831ca440c38SJeff Layton }
4832ca440c38SJeff Layton
4833ca440c38SJeff Layton for(i = 0; i < fsinfo->nlayouttypes; ++i)
4834ca440c38SJeff Layton fsinfo->layouttype[i] = be32_to_cpup(p++);
4835504913fbSAndy Adamson return 0;
4836504913fbSAndy Adamson }
4837504913fbSAndy Adamson
4838504913fbSAndy Adamson /*
4839504913fbSAndy Adamson * The type of file system exported.
4840504913fbSAndy Adamson * Note we must ensure that layouttype is set in any non-error case.
4841504913fbSAndy Adamson */
decode_attr_pnfstype(struct xdr_stream * xdr,uint32_t * bitmap,struct nfs_fsinfo * fsinfo)4842504913fbSAndy Adamson static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
4843ca440c38SJeff Layton struct nfs_fsinfo *fsinfo)
4844504913fbSAndy Adamson {
4845504913fbSAndy Adamson int status = 0;
4846504913fbSAndy Adamson
4847504913fbSAndy Adamson dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4848504913fbSAndy Adamson if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4849504913fbSAndy Adamson return -EIO;
4850504913fbSAndy Adamson if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
4851ca440c38SJeff Layton status = decode_pnfs_layout_types(xdr, fsinfo);
4852504913fbSAndy Adamson bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
48533132e49eSJeff Layton }
4854504913fbSAndy Adamson return status;
4855504913fbSAndy Adamson }
4856504913fbSAndy Adamson
4857dae100c2SFred Isaman /*
4858dae100c2SFred Isaman * The prefered block size for layout directed io
4859dae100c2SFred Isaman */
decode_attr_layout_blksize(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)4860dae100c2SFred Isaman static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4861dae100c2SFred Isaman uint32_t *res)
4862dae100c2SFred Isaman {
4863dae100c2SFred Isaman __be32 *p;
4864dae100c2SFred Isaman
4865dae100c2SFred Isaman dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4866dae100c2SFred Isaman *res = 0;
4867dae100c2SFred Isaman if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4868dae100c2SFred Isaman p = xdr_inline_decode(xdr, 4);
4869eb72f484SChuck Lever if (unlikely(!p))
4870dae100c2SFred Isaman return -EIO;
4871dae100c2SFred Isaman *res = be32_to_cpup(p);
4872dae100c2SFred Isaman bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4873dae100c2SFred Isaman }
4874dae100c2SFred Isaman return 0;
4875dae100c2SFred Isaman }
4876dae100c2SFred Isaman
48772a92ee92SPeng Tao /*
48782a92ee92SPeng Tao * The granularity of a CLONE operation.
48792a92ee92SPeng Tao */
decode_attr_clone_blksize(struct xdr_stream * xdr,uint32_t * bitmap,uint32_t * res)48802a92ee92SPeng Tao static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
48812a92ee92SPeng Tao uint32_t *res)
48822a92ee92SPeng Tao {
48832a92ee92SPeng Tao __be32 *p;
48842a92ee92SPeng Tao
48852a92ee92SPeng Tao dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
48862a92ee92SPeng Tao *res = 0;
48872a92ee92SPeng Tao if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
48882a92ee92SPeng Tao p = xdr_inline_decode(xdr, 4);
4889eb72f484SChuck Lever if (unlikely(!p))
48902a92ee92SPeng Tao return -EIO;
48912a92ee92SPeng Tao *res = be32_to_cpup(p);
48922a92ee92SPeng Tao bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
48932a92ee92SPeng Tao }
48942a92ee92SPeng Tao return 0;
48952a92ee92SPeng Tao }
48962a92ee92SPeng Tao
decode_attr_change_attr_type(struct xdr_stream * xdr,uint32_t * bitmap,enum nfs4_change_attr_type * res)48977f08a335STrond Myklebust static int decode_attr_change_attr_type(struct xdr_stream *xdr,
48987f08a335STrond Myklebust uint32_t *bitmap,
48997f08a335STrond Myklebust enum nfs4_change_attr_type *res)
49007f08a335STrond Myklebust {
49017f08a335STrond Myklebust u32 tmp = NFS4_CHANGE_TYPE_IS_UNDEFINED;
49027f08a335STrond Myklebust
49037f08a335STrond Myklebust dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
49047f08a335STrond Myklebust if (bitmap[2] & FATTR4_WORD2_CHANGE_ATTR_TYPE) {
49057f08a335STrond Myklebust if (xdr_stream_decode_u32(xdr, &tmp))
49067f08a335STrond Myklebust return -EIO;
49077f08a335STrond Myklebust bitmap[2] &= ~FATTR4_WORD2_CHANGE_ATTR_TYPE;
49087f08a335STrond Myklebust }
49097f08a335STrond Myklebust
49107f08a335STrond Myklebust switch(tmp) {
49117f08a335STrond Myklebust case NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR:
49127f08a335STrond Myklebust case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER:
49137f08a335STrond Myklebust case NFS4_CHANGE_TYPE_IS_VERSION_COUNTER_NOPNFS:
49147f08a335STrond Myklebust case NFS4_CHANGE_TYPE_IS_TIME_METADATA:
49157f08a335STrond Myklebust *res = tmp;
49167f08a335STrond Myklebust break;
49177f08a335STrond Myklebust default:
49187f08a335STrond Myklebust *res = NFS4_CHANGE_TYPE_IS_UNDEFINED;
49197f08a335STrond Myklebust }
49207f08a335STrond Myklebust return 0;
49217f08a335STrond Myklebust }
49227f08a335STrond Myklebust
decode_fsinfo(struct xdr_stream * xdr,struct nfs_fsinfo * fsinfo)49231da177e4SLinus Torvalds static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
49241da177e4SLinus Torvalds {
4925256e48bbSTrond Myklebust unsigned int savep;
4926dae100c2SFred Isaman uint32_t attrlen, bitmap[3];
49271da177e4SLinus Torvalds int status;
49281da177e4SLinus Torvalds
49291da177e4SLinus Torvalds if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
49301da177e4SLinus Torvalds goto xdr_error;
49311da177e4SLinus Torvalds if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
49321da177e4SLinus Torvalds goto xdr_error;
49331da177e4SLinus Torvalds if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
49341da177e4SLinus Torvalds goto xdr_error;
49351da177e4SLinus Torvalds
49361da177e4SLinus Torvalds fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
49371da177e4SLinus Torvalds
49381da177e4SLinus Torvalds if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
49391da177e4SLinus Torvalds goto xdr_error;
49401da177e4SLinus Torvalds if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
49411da177e4SLinus Torvalds goto xdr_error;
49421da177e4SLinus Torvalds if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
49431da177e4SLinus Torvalds goto xdr_error;
49441da177e4SLinus Torvalds fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
49451da177e4SLinus Torvalds if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
49461da177e4SLinus Torvalds goto xdr_error;
49471da177e4SLinus Torvalds fsinfo->wtpref = fsinfo->wtmax;
49481ca843a2SAndreas Gruenbacher
49491ca843a2SAndreas Gruenbacher status = -EIO;
49501ca843a2SAndreas Gruenbacher if (unlikely(bitmap[0]))
49511ca843a2SAndreas Gruenbacher goto xdr_error;
49521ca843a2SAndreas Gruenbacher
495355b6e774SRicardo Labiaga status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
495455b6e774SRicardo Labiaga if (status != 0)
495555b6e774SRicardo Labiaga goto xdr_error;
4956ca440c38SJeff Layton status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
4957504913fbSAndy Adamson if (status != 0)
4958504913fbSAndy Adamson goto xdr_error;
49591ca843a2SAndreas Gruenbacher
49601ca843a2SAndreas Gruenbacher status = -EIO;
49611ca843a2SAndreas Gruenbacher if (unlikely(bitmap[1]))
49621ca843a2SAndreas Gruenbacher goto xdr_error;
49631ca843a2SAndreas Gruenbacher
4964dae100c2SFred Isaman status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4965dae100c2SFred Isaman if (status)
4966dae100c2SFred Isaman goto xdr_error;
49672a92ee92SPeng Tao status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
49682a92ee92SPeng Tao if (status)
49692a92ee92SPeng Tao goto xdr_error;
49701da177e4SLinus Torvalds
49717f08a335STrond Myklebust status = decode_attr_change_attr_type(xdr, bitmap,
49727f08a335STrond Myklebust &fsinfo->change_attr_type);
49737f08a335STrond Myklebust if (status)
49747f08a335STrond Myklebust goto xdr_error;
49757f08a335STrond Myklebust
4976b78ef845SFrank van der Linden status = decode_attr_xattrsupport(xdr, bitmap,
4977b78ef845SFrank van der Linden &fsinfo->xattr_support);
4978b78ef845SFrank van der Linden if (status)
4979b78ef845SFrank van der Linden goto xdr_error;
4980b78ef845SFrank van der Linden
49811da177e4SLinus Torvalds status = verify_attr_len(xdr, savep, attrlen);
49821da177e4SLinus Torvalds xdr_error:
49833110ff80SHarvey Harrison dprintk("%s: xdr returned %d!\n", __func__, -status);
49841da177e4SLinus Torvalds return status;
49851da177e4SLinus Torvalds }
49861da177e4SLinus Torvalds
decode_getfh(struct xdr_stream * xdr,struct nfs_fh * fh)49871da177e4SLinus Torvalds static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
49881da177e4SLinus Torvalds {
49898687b63aSAl Viro __be32 *p;
49901da177e4SLinus Torvalds uint32_t len;
49911da177e4SLinus Torvalds int status;
49921da177e4SLinus Torvalds
49939936781dSTrond Myklebust /* Zero handle first to allow comparisons */
49949936781dSTrond Myklebust memset(fh, 0, sizeof(*fh));
49959936781dSTrond Myklebust
49961da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_GETFH);
49971da177e4SLinus Torvalds if (status)
49981da177e4SLinus Torvalds return status;
49991da177e4SLinus Torvalds
5000c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
5001c0eae66eSBenny Halevy if (unlikely(!p))
5002eb72f484SChuck Lever return -EIO;
5003cccddf4fSBenny Halevy len = be32_to_cpup(p);
5004eb3d58c6STrond Myklebust if (len > NFS4_FHSIZE || len == 0) {
5005eb3d58c6STrond Myklebust trace_nfs4_xdr_bad_filehandle(xdr, OP_GETFH, NFS4ERR_BADHANDLE);
5006eb3d58c6STrond Myklebust return -EREMOTEIO;
5007eb3d58c6STrond Myklebust }
50081da177e4SLinus Torvalds fh->size = len;
5009c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len);
5010c0eae66eSBenny Halevy if (unlikely(!p))
5011eb72f484SChuck Lever return -EIO;
501299398d06SBenny Halevy memcpy(fh->data, p, len);
50131da177e4SLinus Torvalds return 0;
50141da177e4SLinus Torvalds }
50151da177e4SLinus Torvalds
decode_link(struct xdr_stream * xdr,struct nfs4_change_info * cinfo)50161da177e4SLinus Torvalds static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
50171da177e4SLinus Torvalds {
50181da177e4SLinus Torvalds int status;
50191da177e4SLinus Torvalds
50201da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LINK);
50211da177e4SLinus Torvalds if (status)
50221da177e4SLinus Torvalds return status;
50231da177e4SLinus Torvalds return decode_change_info(xdr, cinfo);
50241da177e4SLinus Torvalds }
50251da177e4SLinus Torvalds
50261da177e4SLinus Torvalds /*
50271da177e4SLinus Torvalds * We create the owner, so we know a proper owner.id length is 4.
50281da177e4SLinus Torvalds */
decode_lock_denied(struct xdr_stream * xdr,struct file_lock * fl)5029911d1aafSTrond Myklebust static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
50301da177e4SLinus Torvalds {
5031911d1aafSTrond Myklebust uint64_t offset, length, clientid;
50328687b63aSAl Viro __be32 *p;
5033911d1aafSTrond Myklebust uint32_t namelen, type;
50341da177e4SLinus Torvalds
5035babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
5036c0eae66eSBenny Halevy if (unlikely(!p))
5037eb72f484SChuck Lever return -EIO;
5038babddc72SBryan Schumaker p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
50393ceb4dbbSBenny Halevy p = xdr_decode_hyper(p, &length);
5040babddc72SBryan Schumaker type = be32_to_cpup(p++); /* 4 byte read */
5041babddc72SBryan Schumaker if (fl != NULL) { /* manipulate file lock */
5042911d1aafSTrond Myklebust fl->fl_start = (loff_t)offset;
5043911d1aafSTrond Myklebust fl->fl_end = fl->fl_start + (loff_t)length - 1;
5044911d1aafSTrond Myklebust if (length == ~(uint64_t)0)
5045911d1aafSTrond Myklebust fl->fl_end = OFFSET_MAX;
5046911d1aafSTrond Myklebust fl->fl_type = F_WRLCK;
5047911d1aafSTrond Myklebust if (type & 1)
5048911d1aafSTrond Myklebust fl->fl_type = F_RDLCK;
5049911d1aafSTrond Myklebust fl->fl_pid = 0;
5050911d1aafSTrond Myklebust }
5051babddc72SBryan Schumaker p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5052babddc72SBryan Schumaker namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5053babddc72SBryan Schumaker p = xdr_inline_decode(xdr, namelen); /* variable size field */
5054eb72f484SChuck Lever if (likely(!p))
5055c0eae66eSBenny Halevy return -EIO;
5056eb72f484SChuck Lever return -NFS4ERR_DENIED;
50571da177e4SLinus Torvalds }
50581da177e4SLinus Torvalds
decode_lock(struct xdr_stream * xdr,struct nfs_lock_res * res)5059911d1aafSTrond Myklebust static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
50601da177e4SLinus Torvalds {
50611da177e4SLinus Torvalds int status;
50621da177e4SLinus Torvalds
50631da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCK);
5064c1d51931STrond Myklebust if (status == -EIO)
5065c1d51931STrond Myklebust goto out;
50661da177e4SLinus Torvalds if (status == 0) {
506793b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid);
506807d30434SBenny Halevy if (unlikely(status))
506907d30434SBenny Halevy goto out;
50701da177e4SLinus Torvalds } else if (status == -NFS4ERR_DENIED)
5071c1d51931STrond Myklebust status = decode_lock_denied(xdr, NULL);
5072c1d51931STrond Myklebust if (res->open_seqid != NULL)
5073c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->open_seqid);
5074c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->lock_seqid);
5075c1d51931STrond Myklebust out:
50761da177e4SLinus Torvalds return status;
50771da177e4SLinus Torvalds }
50781da177e4SLinus Torvalds
decode_lockt(struct xdr_stream * xdr,struct nfs_lockt_res * res)5079911d1aafSTrond Myklebust static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
50801da177e4SLinus Torvalds {
50811da177e4SLinus Torvalds int status;
50821da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKT);
50831da177e4SLinus Torvalds if (status == -NFS4ERR_DENIED)
5084911d1aafSTrond Myklebust return decode_lock_denied(xdr, res->denied);
50851da177e4SLinus Torvalds return status;
50861da177e4SLinus Torvalds }
50871da177e4SLinus Torvalds
decode_locku(struct xdr_stream * xdr,struct nfs_locku_res * res)5088911d1aafSTrond Myklebust static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
50891da177e4SLinus Torvalds {
50901da177e4SLinus Torvalds int status;
50911da177e4SLinus Torvalds
50921da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_LOCKU);
5093c1d51931STrond Myklebust if (status != -EIO)
5094c1d51931STrond Myklebust nfs_increment_lock_seqid(status, res->seqid);
509507d30434SBenny Halevy if (status == 0)
509693b717fdSTrond Myklebust status = decode_lock_stateid(xdr, &res->stateid);
50971da177e4SLinus Torvalds return status;
50981da177e4SLinus Torvalds }
50991da177e4SLinus Torvalds
decode_release_lockowner(struct xdr_stream * xdr)5100d3c7b7ccSTrond Myklebust static int decode_release_lockowner(struct xdr_stream *xdr)
5101d3c7b7ccSTrond Myklebust {
5102d3c7b7ccSTrond Myklebust return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5103d3c7b7ccSTrond Myklebust }
5104d3c7b7ccSTrond Myklebust
decode_lookup(struct xdr_stream * xdr)51051da177e4SLinus Torvalds static int decode_lookup(struct xdr_stream *xdr)
51061da177e4SLinus Torvalds {
51071da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_LOOKUP);
51081da177e4SLinus Torvalds }
51091da177e4SLinus Torvalds
decode_lookupp(struct xdr_stream * xdr)51105b5faaf6SJeff Layton static int decode_lookupp(struct xdr_stream *xdr)
51115b5faaf6SJeff Layton {
51125b5faaf6SJeff Layton return decode_op_hdr(xdr, OP_LOOKUPP);
51135b5faaf6SJeff Layton }
51145b5faaf6SJeff Layton
51151da177e4SLinus Torvalds /* This is too sick! */
decode_space_limit(struct xdr_stream * xdr,unsigned long * pagemod_limit)51167d160a6cSTrond Myklebust static int decode_space_limit(struct xdr_stream *xdr,
51177d160a6cSTrond Myklebust unsigned long *pagemod_limit)
51181da177e4SLinus Torvalds {
51198687b63aSAl Viro __be32 *p;
51201da177e4SLinus Torvalds uint32_t limit_type, nblocks, blocksize;
51217d160a6cSTrond Myklebust u64 maxsize = 0;
51221da177e4SLinus Torvalds
5123c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12);
5124c0eae66eSBenny Halevy if (unlikely(!p))
5125eb72f484SChuck Lever return -EIO;
51266f723f77SBenny Halevy limit_type = be32_to_cpup(p++);
51271da177e4SLinus Torvalds switch (limit_type) {
51287d160a6cSTrond Myklebust case NFS4_LIMIT_SIZE:
51297d160a6cSTrond Myklebust xdr_decode_hyper(p, &maxsize);
51301da177e4SLinus Torvalds break;
51317d160a6cSTrond Myklebust case NFS4_LIMIT_BLOCKS:
51326f723f77SBenny Halevy nblocks = be32_to_cpup(p++);
5133cccddf4fSBenny Halevy blocksize = be32_to_cpup(p);
51347d160a6cSTrond Myklebust maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
51351da177e4SLinus Torvalds }
513609cbfeafSKirill A. Shutemov maxsize >>= PAGE_SHIFT;
51377d160a6cSTrond Myklebust *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
51381da177e4SLinus Torvalds return 0;
51391da177e4SLinus Torvalds }
51401da177e4SLinus Torvalds
decode_rw_delegation(struct xdr_stream * xdr,uint32_t delegation_type,struct nfs_openres * res)51416ae37339STrond Myklebust static int decode_rw_delegation(struct xdr_stream *xdr,
51426ae37339STrond Myklebust uint32_t delegation_type,
51436ae37339STrond Myklebust struct nfs_openres *res)
51441da177e4SLinus Torvalds {
51458687b63aSAl Viro __be32 *p;
514607d30434SBenny Halevy int status;
51471da177e4SLinus Torvalds
514893b717fdSTrond Myklebust status = decode_delegation_stateid(xdr, &res->delegation);
514907d30434SBenny Halevy if (unlikely(status))
515007d30434SBenny Halevy return status;
5151c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
5152c0eae66eSBenny Halevy if (unlikely(!p))
5153eb72f484SChuck Lever return -EIO;
5154cccddf4fSBenny Halevy res->do_recall = be32_to_cpup(p);
515505d564feSAndy Adamson
51561da177e4SLinus Torvalds switch (delegation_type) {
51571da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_READ:
51581da177e4SLinus Torvalds res->delegation_type = FMODE_READ;
51591da177e4SLinus Torvalds break;
51601da177e4SLinus Torvalds case NFS4_OPEN_DELEGATE_WRITE:
51611da177e4SLinus Torvalds res->delegation_type = FMODE_WRITE|FMODE_READ;
51627d160a6cSTrond Myklebust if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
51631da177e4SLinus Torvalds return -EIO;
51641da177e4SLinus Torvalds }
51651bbe60ffSTrond Myklebust return decode_ace(xdr, NULL);
51661da177e4SLinus Torvalds }
51671da177e4SLinus Torvalds
decode_no_delegation(struct xdr_stream * xdr,struct nfs_openres * res)51686ae37339STrond Myklebust static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
51696ae37339STrond Myklebust {
51706ae37339STrond Myklebust __be32 *p;
51716ae37339STrond Myklebust uint32_t why_no_delegation;
51726ae37339STrond Myklebust
51736ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4);
51746ae37339STrond Myklebust if (unlikely(!p))
5175eb72f484SChuck Lever return -EIO;
51766ae37339STrond Myklebust why_no_delegation = be32_to_cpup(p);
51776ae37339STrond Myklebust switch (why_no_delegation) {
51786ae37339STrond Myklebust case WND4_CONTENTION:
51796ae37339STrond Myklebust case WND4_RESOURCE:
51806ae37339STrond Myklebust xdr_inline_decode(xdr, 4);
51816ae37339STrond Myklebust /* Ignore for now */
51826ae37339STrond Myklebust }
51836ae37339STrond Myklebust return 0;
51846ae37339STrond Myklebust }
51856ae37339STrond Myklebust
decode_delegation(struct xdr_stream * xdr,struct nfs_openres * res)51866ae37339STrond Myklebust static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
51876ae37339STrond Myklebust {
51886ae37339STrond Myklebust __be32 *p;
51896ae37339STrond Myklebust uint32_t delegation_type;
51906ae37339STrond Myklebust
51916ae37339STrond Myklebust p = xdr_inline_decode(xdr, 4);
51926ae37339STrond Myklebust if (unlikely(!p))
5193eb72f484SChuck Lever return -EIO;
51946ae37339STrond Myklebust delegation_type = be32_to_cpup(p);
51956ae37339STrond Myklebust res->delegation_type = 0;
51966ae37339STrond Myklebust switch (delegation_type) {
51976ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE:
51986ae37339STrond Myklebust return 0;
51996ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_READ:
52006ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_WRITE:
52016ae37339STrond Myklebust return decode_rw_delegation(xdr, delegation_type, res);
52026ae37339STrond Myklebust case NFS4_OPEN_DELEGATE_NONE_EXT:
52036ae37339STrond Myklebust return decode_no_delegation(xdr, res);
52046ae37339STrond Myklebust }
52056ae37339STrond Myklebust return -EIO;
52066ae37339STrond Myklebust }
52076ae37339STrond Myklebust
decode_open(struct xdr_stream * xdr,struct nfs_openres * res)52081da177e4SLinus Torvalds static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
52091da177e4SLinus Torvalds {
52108687b63aSAl Viro __be32 *p;
5211aa53ed54SJeff Layton uint32_t savewords, bmlen, i;
52121da177e4SLinus Torvalds int status;
52131da177e4SLinus Torvalds
5214c7848f69STrond Myklebust if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5215c7848f69STrond Myklebust return status;
5216c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid);
5217c7848f69STrond Myklebust if (status)
5218c7848f69STrond Myklebust return status;
521993b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid);
522007d30434SBenny Halevy if (unlikely(status))
52211da177e4SLinus Torvalds return status;
52221da177e4SLinus Torvalds
52231da177e4SLinus Torvalds decode_change_info(xdr, &res->cinfo);
52241da177e4SLinus Torvalds
5225c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
5226c0eae66eSBenny Halevy if (unlikely(!p))
5227eb72f484SChuck Lever return -EIO;
52286f723f77SBenny Halevy res->rflags = be32_to_cpup(p++);
5229cccddf4fSBenny Halevy bmlen = be32_to_cpup(p);
52301da177e4SLinus Torvalds if (bmlen > 10)
52311da177e4SLinus Torvalds goto xdr_error;
52321da177e4SLinus Torvalds
5233c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, bmlen << 2);
5234c0eae66eSBenny Halevy if (unlikely(!p))
5235eb72f484SChuck Lever return -EIO;
5236aa53ed54SJeff Layton savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5237aa53ed54SJeff Layton for (i = 0; i < savewords; ++i)
52386f723f77SBenny Halevy res->attrset[i] = be32_to_cpup(p++);
5239aa53ed54SJeff Layton for (; i < NFS4_BITMAP_SIZE; i++)
5240aa53ed54SJeff Layton res->attrset[i] = 0;
5241aa53ed54SJeff Layton
52421da177e4SLinus Torvalds return decode_delegation(xdr, res);
52431da177e4SLinus Torvalds xdr_error:
52443110ff80SHarvey Harrison dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
52451da177e4SLinus Torvalds return -EIO;
52461da177e4SLinus Torvalds }
52471da177e4SLinus Torvalds
decode_open_confirm(struct xdr_stream * xdr,struct nfs_open_confirmres * res)52481da177e4SLinus Torvalds static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
52491da177e4SLinus Torvalds {
52501da177e4SLinus Torvalds int status;
52511da177e4SLinus Torvalds
52521da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
5253c1d51931STrond Myklebust if (status != -EIO)
5254c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid);
525507d30434SBenny Halevy if (!status)
525693b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid);
52571da177e4SLinus Torvalds return status;
52581da177e4SLinus Torvalds }
52591da177e4SLinus Torvalds
decode_open_downgrade(struct xdr_stream * xdr,struct nfs_closeres * res)52601da177e4SLinus Torvalds static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
52611da177e4SLinus Torvalds {
52621da177e4SLinus Torvalds int status;
52631da177e4SLinus Torvalds
52641da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
5265c1d51931STrond Myklebust if (status != -EIO)
5266c1d51931STrond Myklebust nfs_increment_open_seqid(status, res->seqid);
526707d30434SBenny Halevy if (!status)
526893b717fdSTrond Myklebust status = decode_open_stateid(xdr, &res->stateid);
52691da177e4SLinus Torvalds return status;
52701da177e4SLinus Torvalds }
52711da177e4SLinus Torvalds
decode_putfh(struct xdr_stream * xdr)52721da177e4SLinus Torvalds static int decode_putfh(struct xdr_stream *xdr)
52731da177e4SLinus Torvalds {
52741da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTFH);
52751da177e4SLinus Torvalds }
52761da177e4SLinus Torvalds
decode_putrootfh(struct xdr_stream * xdr)52771da177e4SLinus Torvalds static int decode_putrootfh(struct xdr_stream *xdr)
52781da177e4SLinus Torvalds {
52791da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_PUTROOTFH);
52801da177e4SLinus Torvalds }
52811da177e4SLinus Torvalds
decode_read(struct xdr_stream * xdr,struct rpc_rqst * req,struct nfs_pgio_res * res)52829137bdf3SAnna Schumaker static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
52839137bdf3SAnna Schumaker struct nfs_pgio_res *res)
52841da177e4SLinus Torvalds {
52858687b63aSAl Viro __be32 *p;
528664bd577eSTrond Myklebust uint32_t count, eof, recvd;
52871da177e4SLinus Torvalds int status;
52881da177e4SLinus Torvalds
52891da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READ);
52901da177e4SLinus Torvalds if (status)
52911da177e4SLinus Torvalds return status;
5292c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
5293c0eae66eSBenny Halevy if (unlikely(!p))
5294eb72f484SChuck Lever return -EIO;
52956f723f77SBenny Halevy eof = be32_to_cpup(p++);
5296cccddf4fSBenny Halevy count = be32_to_cpup(p);
529764bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, count);
52981da177e4SLinus Torvalds if (count > recvd) {
5299fe82a183SChuck Lever dprintk("NFS: server cheating in read reply: "
53001da177e4SLinus Torvalds "count %u > recvd %u\n", count, recvd);
53011da177e4SLinus Torvalds count = recvd;
53021da177e4SLinus Torvalds eof = 0;
53031da177e4SLinus Torvalds }
53041da177e4SLinus Torvalds res->eof = eof;
53051da177e4SLinus Torvalds res->count = count;
53061da177e4SLinus Torvalds return 0;
53071da177e4SLinus Torvalds }
53081da177e4SLinus Torvalds
decode_readdir(struct xdr_stream * xdr,struct rpc_rqst * req,struct nfs4_readdir_res * readdir)53091da177e4SLinus Torvalds static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
53101da177e4SLinus Torvalds {
5311bcecff77SChuck Lever int status;
5312cd93710eSChuck Lever __be32 verf[2];
53131da177e4SLinus Torvalds
53141da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READDIR);
5315db942bbdSBenny Halevy if (!status)
5316db942bbdSBenny Halevy status = decode_verifier(xdr, readdir->verifier.data);
5317db942bbdSBenny Halevy if (unlikely(status))
53181da177e4SLinus Torvalds return status;
5319cd93710eSChuck Lever memcpy(verf, readdir->verifier.data, sizeof(verf));
532044109241SFred Isaman dprintk("%s: verifier = %08x:%08x\n",
5321cd93710eSChuck Lever __func__, verf[0], verf[1]);
532264bd577eSTrond Myklebust return xdr_read_pages(xdr, xdr->buf->page_len);
53231da177e4SLinus Torvalds }
53241da177e4SLinus Torvalds
decode_readlink(struct xdr_stream * xdr,struct rpc_rqst * req)53251da177e4SLinus Torvalds static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
53261da177e4SLinus Torvalds {
53271da177e4SLinus Torvalds struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
5328bcecff77SChuck Lever u32 len, recvd;
53298687b63aSAl Viro __be32 *p;
53301da177e4SLinus Torvalds int status;
53311da177e4SLinus Torvalds
53321da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_READLINK);
53331da177e4SLinus Torvalds if (status)
53341da177e4SLinus Torvalds return status;
53351da177e4SLinus Torvalds
53361da177e4SLinus Torvalds /* Convert length of symlink */
5337c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
5338c0eae66eSBenny Halevy if (unlikely(!p))
5339eb72f484SChuck Lever return -EIO;
5340cccddf4fSBenny Halevy len = be32_to_cpup(p);
53411da177e4SLinus Torvalds if (len >= rcvbuf->page_len || len <= 0) {
5342fe82a183SChuck Lever dprintk("nfs: server returned giant symlink!\n");
53431da177e4SLinus Torvalds return -ENAMETOOLONG;
53441da177e4SLinus Torvalds }
534564bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, len);
53461da177e4SLinus Torvalds if (recvd < len) {
5347fe82a183SChuck Lever dprintk("NFS: server cheating in readlink reply: "
53481da177e4SLinus Torvalds "count %u > recvd %u\n", len, recvd);
53491da177e4SLinus Torvalds return -EIO;
53501da177e4SLinus Torvalds }
53511da177e4SLinus Torvalds /*
53521da177e4SLinus Torvalds * The XDR encode routine has set things up so that
53531da177e4SLinus Torvalds * the link text will be copied directly into the
53541da177e4SLinus Torvalds * buffer. We just have to do overflow-checking,
5355a5032910SRandy Dunlap * and null-terminate the text (the VFS expects
53561da177e4SLinus Torvalds * null-termination).
53571da177e4SLinus Torvalds */
5358b4687da7SChuck Lever xdr_terminate_string(rcvbuf, len);
53591da177e4SLinus Torvalds return 0;
53601da177e4SLinus Torvalds }
53611da177e4SLinus Torvalds
decode_remove(struct xdr_stream * xdr,struct nfs4_change_info * cinfo)53621da177e4SLinus Torvalds static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
53631da177e4SLinus Torvalds {
53641da177e4SLinus Torvalds int status;
53651da177e4SLinus Torvalds
53661da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_REMOVE);
53671da177e4SLinus Torvalds if (status)
53681da177e4SLinus Torvalds goto out;
53691da177e4SLinus Torvalds status = decode_change_info(xdr, cinfo);
53701da177e4SLinus Torvalds out:
53711da177e4SLinus Torvalds return status;
53721da177e4SLinus Torvalds }
53731da177e4SLinus Torvalds
decode_rename(struct xdr_stream * xdr,struct nfs4_change_info * old_cinfo,struct nfs4_change_info * new_cinfo)53741da177e4SLinus Torvalds static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
53751da177e4SLinus Torvalds struct nfs4_change_info *new_cinfo)
53761da177e4SLinus Torvalds {
53771da177e4SLinus Torvalds int status;
53781da177e4SLinus Torvalds
53791da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_RENAME);
53801da177e4SLinus Torvalds if (status)
53811da177e4SLinus Torvalds goto out;
53821da177e4SLinus Torvalds if ((status = decode_change_info(xdr, old_cinfo)))
53831da177e4SLinus Torvalds goto out;
53841da177e4SLinus Torvalds status = decode_change_info(xdr, new_cinfo);
53851da177e4SLinus Torvalds out:
53861da177e4SLinus Torvalds return status;
53871da177e4SLinus Torvalds }
53881da177e4SLinus Torvalds
decode_renew(struct xdr_stream * xdr)53891da177e4SLinus Torvalds static int decode_renew(struct xdr_stream *xdr)
53901da177e4SLinus Torvalds {
53911da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_RENEW);
53921da177e4SLinus Torvalds }
53931da177e4SLinus Torvalds
539456ae19f3STrond Myklebust static int
decode_restorefh(struct xdr_stream * xdr)539556ae19f3STrond Myklebust decode_restorefh(struct xdr_stream *xdr)
539656ae19f3STrond Myklebust {
539756ae19f3STrond Myklebust return decode_op_hdr(xdr, OP_RESTOREFH);
539856ae19f3STrond Myklebust }
539956ae19f3STrond Myklebust
decode_getacl(struct xdr_stream * xdr,struct rpc_rqst * req,struct nfs_getaclres * res,enum nfs4_acl_type type)5400029d105eSJ. Bruce Fields static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
5401db145db0STrond Myklebust struct nfs_getaclres *res, enum nfs4_acl_type type)
5402029d105eSJ. Bruce Fields {
5403256e48bbSTrond Myklebust unsigned int savep;
5404029d105eSJ. Bruce Fields uint32_t attrlen,
5405dae100c2SFred Isaman bitmap[3] = {0};
5406029d105eSJ. Bruce Fields int status;
5407029d105eSJ. Bruce Fields
5408bf118a34SAndy Adamson res->acl_len = 0;
5409029d105eSJ. Bruce Fields if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5410029d105eSJ. Bruce Fields goto out;
54115a006899SSachin Prabhu
5412519d3959STrond Myklebust xdr_enter_page(xdr, xdr->buf->page_len);
5413519d3959STrond Myklebust
5414029d105eSJ. Bruce Fields if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5415029d105eSJ. Bruce Fields goto out;
5416029d105eSJ. Bruce Fields if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5417029d105eSJ. Bruce Fields goto out;
5418029d105eSJ. Bruce Fields
5419db145db0STrond Myklebust switch (type) {
5420db145db0STrond Myklebust default:
5421029d105eSJ. Bruce Fields if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5422029d105eSJ. Bruce Fields return -EIO;
5423db145db0STrond Myklebust if (!(bitmap[0] & FATTR4_WORD0_ACL))
5424db145db0STrond Myklebust return -EOPNOTSUPP;
5425db145db0STrond Myklebust break;
5426db145db0STrond Myklebust case NFS4ACL_DACL:
5427db145db0STrond Myklebust if (unlikely(bitmap[0] || bitmap[1] & (FATTR4_WORD1_DACL - 1U)))
5428db145db0STrond Myklebust return -EIO;
5429db145db0STrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_DACL))
5430db145db0STrond Myklebust return -EOPNOTSUPP;
5431db145db0STrond Myklebust break;
5432db145db0STrond Myklebust case NFS4ACL_SACL:
5433db145db0STrond Myklebust if (unlikely(bitmap[0] || bitmap[1] & (FATTR4_WORD1_SACL - 1U)))
5434db145db0STrond Myklebust return -EIO;
5435db145db0STrond Myklebust if (!(bitmap[1] & FATTR4_WORD1_SACL))
5436db145db0STrond Myklebust return -EOPNOTSUPP;
5437db145db0STrond Myklebust }
5438029d105eSJ. Bruce Fields
5439bf118a34SAndy Adamson /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5440bf118a34SAndy Adamson * are stored with the acl data to handle the problem of
5441bf118a34SAndy Adamson * variable length bitmaps.*/
5442a14a6359SAnna Schumaker res->acl_data_offset = xdr_page_pos(xdr);
5443519d3959STrond Myklebust res->acl_len = attrlen;
54441f1ea6c2STrond Myklebust
54451f1ea6c2STrond Myklebust /* Check for receive buffer overflow */
544617068466STrond Myklebust if (res->acl_len > xdr_stream_remaining(xdr) ||
54471f1ea6c2STrond Myklebust res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
54481f1ea6c2STrond Myklebust res->acl_flags |= NFS4_ACL_TRUNC;
544917068466STrond Myklebust dprintk("NFS: acl reply: attrlen %u > page_len %zu\n",
545017068466STrond Myklebust attrlen, xdr_stream_remaining(xdr));
5451029d105eSJ. Bruce Fields }
5452029d105eSJ. Bruce Fields out:
5453029d105eSJ. Bruce Fields return status;
5454029d105eSJ. Bruce Fields }
5455029d105eSJ. Bruce Fields
54561da177e4SLinus Torvalds static int
decode_savefh(struct xdr_stream * xdr)54571da177e4SLinus Torvalds decode_savefh(struct xdr_stream *xdr)
54581da177e4SLinus Torvalds {
54591da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SAVEFH);
54601da177e4SLinus Torvalds }
54611da177e4SLinus Torvalds
decode_setattr(struct xdr_stream * xdr)54629e9ecc03SBenny Halevy static int decode_setattr(struct xdr_stream *xdr)
54631da177e4SLinus Torvalds {
54641da177e4SLinus Torvalds int status;
54651da177e4SLinus Torvalds
54661da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_SETATTR);
54671da177e4SLinus Torvalds if (status)
54681da177e4SLinus Torvalds return status;
546937c88763STrond Myklebust if (decode_bitmap4(xdr, NULL, 0) >= 0)
54701da177e4SLinus Torvalds return 0;
5471c0eae66eSBenny Halevy return -EIO;
54721da177e4SLinus Torvalds }
54731da177e4SLinus Torvalds
decode_setclientid(struct xdr_stream * xdr,struct nfs4_setclientid_res * res)5474bb8b27e5STrond Myklebust static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
54751da177e4SLinus Torvalds {
54768687b63aSAl Viro __be32 *p;
54771da177e4SLinus Torvalds uint32_t opnum;
54781da177e4SLinus Torvalds int32_t nfserr;
54791da177e4SLinus Torvalds
5480c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
5481c0eae66eSBenny Halevy if (unlikely(!p))
5482eb72f484SChuck Lever return -EIO;
54836f723f77SBenny Halevy opnum = be32_to_cpup(p++);
54841da177e4SLinus Torvalds if (opnum != OP_SETCLIENTID) {
5485fe82a183SChuck Lever dprintk("nfs: decode_setclientid: Server returned operation"
54861da177e4SLinus Torvalds " %d\n", opnum);
54871da177e4SLinus Torvalds return -EIO;
54881da177e4SLinus Torvalds }
5489cccddf4fSBenny Halevy nfserr = be32_to_cpup(p);
54901da177e4SLinus Torvalds if (nfserr == NFS_OK) {
5491c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5492c0eae66eSBenny Halevy if (unlikely(!p))
5493eb72f484SChuck Lever return -EIO;
5494bb8b27e5STrond Myklebust p = xdr_decode_hyper(p, &res->clientid);
5495bb8b27e5STrond Myklebust memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
54961da177e4SLinus Torvalds } else if (nfserr == NFSERR_CLID_INUSE) {
54971da177e4SLinus Torvalds uint32_t len;
54981da177e4SLinus Torvalds
54991da177e4SLinus Torvalds /* skip netid string */
5500c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
5501c0eae66eSBenny Halevy if (unlikely(!p))
5502eb72f484SChuck Lever return -EIO;
5503cccddf4fSBenny Halevy len = be32_to_cpup(p);
5504c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len);
5505c0eae66eSBenny Halevy if (unlikely(!p))
5506eb72f484SChuck Lever return -EIO;
55071da177e4SLinus Torvalds
55081da177e4SLinus Torvalds /* skip uaddr string */
5509c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4);
5510c0eae66eSBenny Halevy if (unlikely(!p))
5511eb72f484SChuck Lever return -EIO;
5512cccddf4fSBenny Halevy len = be32_to_cpup(p);
5513c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, len);
5514c0eae66eSBenny Halevy if (unlikely(!p))
5515eb72f484SChuck Lever return -EIO;
55161da177e4SLinus Torvalds return -NFSERR_CLID_INUSE;
55171da177e4SLinus Torvalds } else
5518856dff3dSBenny Halevy return nfs4_stat_to_errno(nfserr);
55191da177e4SLinus Torvalds
55201da177e4SLinus Torvalds return 0;
55211da177e4SLinus Torvalds }
55221da177e4SLinus Torvalds
decode_setclientid_confirm(struct xdr_stream * xdr)55231da177e4SLinus Torvalds static int decode_setclientid_confirm(struct xdr_stream *xdr)
55241da177e4SLinus Torvalds {
55251da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
55261da177e4SLinus Torvalds }
55271da177e4SLinus Torvalds
decode_write(struct xdr_stream * xdr,struct nfs_pgio_res * res)55289137bdf3SAnna Schumaker static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
55291da177e4SLinus Torvalds {
55308687b63aSAl Viro __be32 *p;
55311da177e4SLinus Torvalds int status;
55321da177e4SLinus Torvalds
55331da177e4SLinus Torvalds status = decode_op_hdr(xdr, OP_WRITE);
55341da177e4SLinus Torvalds if (status)
55351da177e4SLinus Torvalds return status;
55361da177e4SLinus Torvalds
55372f2c63bcSTrond Myklebust p = xdr_inline_decode(xdr, 8);
5538c0eae66eSBenny Halevy if (unlikely(!p))
5539eb72f484SChuck Lever return -EIO;
55406f723f77SBenny Halevy res->count = be32_to_cpup(p++);
55416f723f77SBenny Halevy res->verf->committed = be32_to_cpup(p++);
55422f2c63bcSTrond Myklebust return decode_write_verifier(xdr, &res->verf->verifier);
55431da177e4SLinus Torvalds }
55441da177e4SLinus Torvalds
decode_delegreturn(struct xdr_stream * xdr)55451da177e4SLinus Torvalds static int decode_delegreturn(struct xdr_stream *xdr)
55461da177e4SLinus Torvalds {
55471da177e4SLinus Torvalds return decode_op_hdr(xdr, OP_DELEGRETURN);
55481da177e4SLinus Torvalds }
55491da177e4SLinus Torvalds
decode_secinfo_gss(struct xdr_stream * xdr,struct nfs4_secinfo4 * flavor)5550fb15b26fSChuck Lever static int decode_secinfo_gss(struct xdr_stream *xdr,
5551fb15b26fSChuck Lever struct nfs4_secinfo4 *flavor)
55525a5ea0d4SBryan Schumaker {
5553fb15b26fSChuck Lever u32 oid_len;
55545a5ea0d4SBryan Schumaker __be32 *p;
55555a5ea0d4SBryan Schumaker
55565a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4);
55575a5ea0d4SBryan Schumaker if (unlikely(!p))
5558eb72f484SChuck Lever return -EIO;
5559fb15b26fSChuck Lever oid_len = be32_to_cpup(p);
5560fb15b26fSChuck Lever if (oid_len > GSS_OID_MAX_LEN)
5561eb72f484SChuck Lever return -EINVAL;
55625a5ea0d4SBryan Schumaker
5563fb15b26fSChuck Lever p = xdr_inline_decode(xdr, oid_len);
55645a5ea0d4SBryan Schumaker if (unlikely(!p))
5565eb72f484SChuck Lever return -EIO;
5566fb15b26fSChuck Lever memcpy(flavor->flavor_info.oid.data, p, oid_len);
5567fb15b26fSChuck Lever flavor->flavor_info.oid.len = oid_len;
55685a5ea0d4SBryan Schumaker
55695a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 8);
55705a5ea0d4SBryan Schumaker if (unlikely(!p))
5571eb72f484SChuck Lever return -EIO;
5572fb15b26fSChuck Lever flavor->flavor_info.qop = be32_to_cpup(p++);
5573fb15b26fSChuck Lever flavor->flavor_info.service = be32_to_cpup(p);
55745a5ea0d4SBryan Schumaker
55755a5ea0d4SBryan Schumaker return 0;
55765a5ea0d4SBryan Schumaker }
55775a5ea0d4SBryan Schumaker
decode_secinfo_common(struct xdr_stream * xdr,struct nfs4_secinfo_res * res)557831e4dda4SBryan Schumaker static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
55795a5ea0d4SBryan Schumaker {
5580fb15b26fSChuck Lever struct nfs4_secinfo4 *sec_flavor;
5581fb15b26fSChuck Lever unsigned int i, num_flavors;
55825a5ea0d4SBryan Schumaker int status;
55835a5ea0d4SBryan Schumaker __be32 *p;
55845a5ea0d4SBryan Schumaker
55855a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4);
55865a5ea0d4SBryan Schumaker if (unlikely(!p))
5587eb72f484SChuck Lever return -EIO;
55885a5ea0d4SBryan Schumaker
5589c3dfc280SBryan Schumaker res->flavors->num_flavors = 0;
5590c3dfc280SBryan Schumaker num_flavors = be32_to_cpup(p);
5591c3dfc280SBryan Schumaker
5592c3dfc280SBryan Schumaker for (i = 0; i < num_flavors; i++) {
55935a5ea0d4SBryan Schumaker sec_flavor = &res->flavors->flavors[i];
5594c3dfc280SBryan Schumaker if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
55955a5ea0d4SBryan Schumaker break;
55965a5ea0d4SBryan Schumaker
55975a5ea0d4SBryan Schumaker p = xdr_inline_decode(xdr, 4);
55985a5ea0d4SBryan Schumaker if (unlikely(!p))
5599eb72f484SChuck Lever return -EIO;
56005a5ea0d4SBryan Schumaker sec_flavor->flavor = be32_to_cpup(p);
56015a5ea0d4SBryan Schumaker
56025a5ea0d4SBryan Schumaker if (sec_flavor->flavor == RPC_AUTH_GSS) {
5603613e901eSBryan Schumaker status = decode_secinfo_gss(xdr, sec_flavor);
5604613e901eSBryan Schumaker if (status)
5605613e901eSBryan Schumaker goto out;
56065a5ea0d4SBryan Schumaker }
5607c3dfc280SBryan Schumaker res->flavors->num_flavors++;
56085a5ea0d4SBryan Schumaker }
56095a5ea0d4SBryan Schumaker
561031e4dda4SBryan Schumaker status = 0;
5611613e901eSBryan Schumaker out:
5612613e901eSBryan Schumaker return status;
56135a5ea0d4SBryan Schumaker }
56145a5ea0d4SBryan Schumaker
decode_secinfo(struct xdr_stream * xdr,struct nfs4_secinfo_res * res)561531e4dda4SBryan Schumaker static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
561631e4dda4SBryan Schumaker {
561731e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO);
561831e4dda4SBryan Schumaker if (status)
561931e4dda4SBryan Schumaker return status;
562031e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res);
562131e4dda4SBryan Schumaker }
562231e4dda4SBryan Schumaker
562399fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
decode_secinfo_no_name(struct xdr_stream * xdr,struct nfs4_secinfo_res * res)562431e4dda4SBryan Schumaker static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
562531e4dda4SBryan Schumaker {
562631e4dda4SBryan Schumaker int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
562731e4dda4SBryan Schumaker if (status)
562831e4dda4SBryan Schumaker return status;
562931e4dda4SBryan Schumaker return decode_secinfo_common(xdr, res);
563031e4dda4SBryan Schumaker }
563131e4dda4SBryan Schumaker
decode_op_map(struct xdr_stream * xdr,struct nfs4_op_map * op_map)56322031cd1aSWeston Andros Adamson static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
56332031cd1aSWeston Andros Adamson {
5634f114759cSTrond Myklebust if (xdr_stream_decode_uint32_array(xdr, op_map->u.words,
5635f114759cSTrond Myklebust ARRAY_SIZE(op_map->u.words)) < 0)
56364edabfd7SPan Bian return -EIO;
56372031cd1aSWeston Andros Adamson return 0;
56382031cd1aSWeston Andros Adamson }
56392031cd1aSWeston Andros Adamson
decode_exchange_id(struct xdr_stream * xdr,struct nfs41_exchange_id_res * res)564099fe60d0SBenny Halevy static int decode_exchange_id(struct xdr_stream *xdr,
564199fe60d0SBenny Halevy struct nfs41_exchange_id_res *res)
564299fe60d0SBenny Halevy {
564399fe60d0SBenny Halevy __be32 *p;
564499fe60d0SBenny Halevy uint32_t dummy;
56452460ba57SBenny Halevy char *dummy_str;
564699fe60d0SBenny Halevy int status;
56477d2ed9acSWeston Andros Adamson uint32_t impl_id_count;
564899fe60d0SBenny Halevy
564999fe60d0SBenny Halevy status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
565099fe60d0SBenny Halevy if (status)
565199fe60d0SBenny Halevy return status;
565299fe60d0SBenny Halevy
5653c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
5654c0eae66eSBenny Halevy if (unlikely(!p))
5655eb72f484SChuck Lever return -EIO;
565632b01310STrond Myklebust xdr_decode_hyper(p, &res->clientid);
5657c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 12);
5658c0eae66eSBenny Halevy if (unlikely(!p))
5659eb72f484SChuck Lever return -EIO;
566032b01310STrond Myklebust res->seqid = be32_to_cpup(p++);
566132b01310STrond Myklebust res->flags = be32_to_cpup(p++);
566299fe60d0SBenny Halevy
56632031cd1aSWeston Andros Adamson res->state_protect.how = be32_to_cpup(p);
56642031cd1aSWeston Andros Adamson switch (res->state_protect.how) {
56652031cd1aSWeston Andros Adamson case SP4_NONE:
56662031cd1aSWeston Andros Adamson break;
56672031cd1aSWeston Andros Adamson case SP4_MACH_CRED:
56682031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.enforce);
56692031cd1aSWeston Andros Adamson if (status)
56702031cd1aSWeston Andros Adamson return status;
56712031cd1aSWeston Andros Adamson status = decode_op_map(xdr, &res->state_protect.allow);
56722031cd1aSWeston Andros Adamson if (status)
56732031cd1aSWeston Andros Adamson return status;
56742031cd1aSWeston Andros Adamson break;
56752031cd1aSWeston Andros Adamson default:
56762031cd1aSWeston Andros Adamson WARN_ON_ONCE(1);
567799fe60d0SBenny Halevy return -EIO;
56782031cd1aSWeston Andros Adamson }
567999fe60d0SBenny Halevy
5680acdeb69dSChuck Lever /* server_owner4.so_minor_id */
5681c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
5682c0eae66eSBenny Halevy if (unlikely(!p))
5683eb72f484SChuck Lever return -EIO;
5684acdeb69dSChuck Lever p = xdr_decode_hyper(p, &res->server_owner->minor_id);
568599fe60d0SBenny Halevy
5686acdeb69dSChuck Lever /* server_owner4.so_major_id */
56872460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str);
56882460ba57SBenny Halevy if (unlikely(status))
56892460ba57SBenny Halevy return status;
5690acdeb69dSChuck Lever memcpy(res->server_owner->major_id, dummy_str, dummy);
5691acdeb69dSChuck Lever res->server_owner->major_id_sz = dummy;
569278fe0f41SWeston Andros Adamson
5693acdeb69dSChuck Lever /* server_scope4 */
5694acdeb69dSChuck Lever status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5695acdeb69dSChuck Lever if (unlikely(status))
5696acdeb69dSChuck Lever return status;
569778fe0f41SWeston Andros Adamson memcpy(res->server_scope->server_scope, dummy_str, dummy);
569878fe0f41SWeston Andros Adamson res->server_scope->server_scope_sz = dummy;
569978fe0f41SWeston Andros Adamson
57007d2ed9acSWeston Andros Adamson /* Implementation Id */
57017d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 4);
57027d2ed9acSWeston Andros Adamson if (unlikely(!p))
5703eb72f484SChuck Lever return -EIO;
57047d2ed9acSWeston Andros Adamson impl_id_count = be32_to_cpup(p++);
57057d2ed9acSWeston Andros Adamson
57067d2ed9acSWeston Andros Adamson if (impl_id_count) {
57077d2ed9acSWeston Andros Adamson /* nii_domain */
57082460ba57SBenny Halevy status = decode_opaque_inline(xdr, &dummy, &dummy_str);
57092460ba57SBenny Halevy if (unlikely(status))
57102460ba57SBenny Halevy return status;
57117d2ed9acSWeston Andros Adamson memcpy(res->impl_id->domain, dummy_str, dummy);
571299fe60d0SBenny Halevy
57137d2ed9acSWeston Andros Adamson /* nii_name */
57147d2ed9acSWeston Andros Adamson status = decode_opaque_inline(xdr, &dummy, &dummy_str);
57157d2ed9acSWeston Andros Adamson if (unlikely(status))
57167d2ed9acSWeston Andros Adamson return status;
57177d2ed9acSWeston Andros Adamson memcpy(res->impl_id->name, dummy_str, dummy);
57187d2ed9acSWeston Andros Adamson
57197d2ed9acSWeston Andros Adamson /* nii_date */
57207d2ed9acSWeston Andros Adamson p = xdr_inline_decode(xdr, 12);
57217d2ed9acSWeston Andros Adamson if (unlikely(!p))
5722eb72f484SChuck Lever return -EIO;
57237d2ed9acSWeston Andros Adamson p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
57247d2ed9acSWeston Andros Adamson res->impl_id->date.nseconds = be32_to_cpup(p);
57257d2ed9acSWeston Andros Adamson
57267d2ed9acSWeston Andros Adamson /* if there's more than one entry, ignore the rest */
57277d2ed9acSWeston Andros Adamson }
572899fe60d0SBenny Halevy return 0;
572999fe60d0SBenny Halevy }
5730fc931582SAndy Adamson
decode_chan_attrs(struct xdr_stream * xdr,struct nfs4_channel_attrs * attrs)5731fc931582SAndy Adamson static int decode_chan_attrs(struct xdr_stream *xdr,
5732fc931582SAndy Adamson struct nfs4_channel_attrs *attrs)
5733fc931582SAndy Adamson {
5734fc931582SAndy Adamson __be32 *p;
5735c9c30dd5SBenny Halevy u32 nr_attrs, val;
5736fc931582SAndy Adamson
5737c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 28);
5738c0eae66eSBenny Halevy if (unlikely(!p))
5739eb72f484SChuck Lever return -EIO;
5740c9c30dd5SBenny Halevy val = be32_to_cpup(p++); /* headerpadsz */
5741c9c30dd5SBenny Halevy if (val)
5742c9c30dd5SBenny Halevy return -EINVAL; /* no support for header padding yet */
57436f723f77SBenny Halevy attrs->max_rqst_sz = be32_to_cpup(p++);
57446f723f77SBenny Halevy attrs->max_resp_sz = be32_to_cpup(p++);
57456f723f77SBenny Halevy attrs->max_resp_sz_cached = be32_to_cpup(p++);
57466f723f77SBenny Halevy attrs->max_ops = be32_to_cpup(p++);
57476f723f77SBenny Halevy attrs->max_reqs = be32_to_cpup(p++);
5748cccddf4fSBenny Halevy nr_attrs = be32_to_cpup(p);
5749fc931582SAndy Adamson if (unlikely(nr_attrs > 1)) {
5750a030889aSWeston Andros Adamson printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5751a030889aSWeston Andros Adamson "count %u\n", __func__, nr_attrs);
5752fc931582SAndy Adamson return -EINVAL;
5753fc931582SAndy Adamson }
5754c0eae66eSBenny Halevy if (nr_attrs == 1) {
5755c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5756c0eae66eSBenny Halevy if (unlikely(!p))
5757eb72f484SChuck Lever return -EIO;
5758c0eae66eSBenny Halevy }
5759fc931582SAndy Adamson return 0;
5760fc931582SAndy Adamson }
5761fc931582SAndy Adamson
decode_sessionid(struct xdr_stream * xdr,struct nfs4_sessionid * sid)5762e78291e4SBenny Halevy static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5763e78291e4SBenny Halevy {
5764e78291e4SBenny Halevy return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
5765fc931582SAndy Adamson }
5766fc931582SAndy Adamson
decode_bind_conn_to_session(struct xdr_stream * xdr,struct nfs41_bind_conn_to_session_res * res)57677c44f1aeSWeston Andros Adamson static int decode_bind_conn_to_session(struct xdr_stream *xdr,
57687c44f1aeSWeston Andros Adamson struct nfs41_bind_conn_to_session_res *res)
57697c44f1aeSWeston Andros Adamson {
57707c44f1aeSWeston Andros Adamson __be32 *p;
57717c44f1aeSWeston Andros Adamson int status;
57727c44f1aeSWeston Andros Adamson
57737c44f1aeSWeston Andros Adamson status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
57747c44f1aeSWeston Andros Adamson if (!status)
577571a097c6STrond Myklebust status = decode_sessionid(xdr, &res->sessionid);
57767c44f1aeSWeston Andros Adamson if (unlikely(status))
57777c44f1aeSWeston Andros Adamson return status;
57787c44f1aeSWeston Andros Adamson
57797c44f1aeSWeston Andros Adamson /* dir flags, rdma mode bool */
57807c44f1aeSWeston Andros Adamson p = xdr_inline_decode(xdr, 8);
57817c44f1aeSWeston Andros Adamson if (unlikely(!p))
5782eb72f484SChuck Lever return -EIO;
57837c44f1aeSWeston Andros Adamson
57847c44f1aeSWeston Andros Adamson res->dir = be32_to_cpup(p++);
57857c44f1aeSWeston Andros Adamson if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
57867c44f1aeSWeston Andros Adamson return -EIO;
57877c44f1aeSWeston Andros Adamson if (be32_to_cpup(p) == 0)
57887c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = false;
57897c44f1aeSWeston Andros Adamson else
57907c44f1aeSWeston Andros Adamson res->use_conn_in_rdma_mode = true;
57917c44f1aeSWeston Andros Adamson
57927c44f1aeSWeston Andros Adamson return 0;
57937c44f1aeSWeston Andros Adamson }
57947c44f1aeSWeston Andros Adamson
decode_create_session(struct xdr_stream * xdr,struct nfs41_create_session_res * res)5795fc931582SAndy Adamson static int decode_create_session(struct xdr_stream *xdr,
5796fc931582SAndy Adamson struct nfs41_create_session_res *res)
5797fc931582SAndy Adamson {
5798fc931582SAndy Adamson __be32 *p;
5799fc931582SAndy Adamson int status;
5800fc931582SAndy Adamson
5801fc931582SAndy Adamson status = decode_op_hdr(xdr, OP_CREATE_SESSION);
5802e78291e4SBenny Halevy if (!status)
580379969dd1STrond Myklebust status = decode_sessionid(xdr, &res->sessionid);
5804e78291e4SBenny Halevy if (unlikely(status))
5805fc931582SAndy Adamson return status;
5806fc931582SAndy Adamson
5807fc931582SAndy Adamson /* seqid, flags */
5808c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 8);
5809c0eae66eSBenny Halevy if (unlikely(!p))
5810eb72f484SChuck Lever return -EIO;
581179969dd1STrond Myklebust res->seqid = be32_to_cpup(p++);
581279969dd1STrond Myklebust res->flags = be32_to_cpup(p);
5813fc931582SAndy Adamson
5814fc931582SAndy Adamson /* Channel attributes */
581579969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->fc_attrs);
5816fc931582SAndy Adamson if (!status)
581779969dd1STrond Myklebust status = decode_chan_attrs(xdr, &res->bc_attrs);
5818fc931582SAndy Adamson return status;
5819fc931582SAndy Adamson }
58200f3e66c6SAndy Adamson
decode_destroy_session(struct xdr_stream * xdr,void * dummy)58210f3e66c6SAndy Adamson static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
58220f3e66c6SAndy Adamson {
58230f3e66c6SAndy Adamson return decode_op_hdr(xdr, OP_DESTROY_SESSION);
58240f3e66c6SAndy Adamson }
582518019753SRicardo Labiaga
decode_destroy_clientid(struct xdr_stream * xdr,void * dummy)582666245539STrond Myklebust static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
582766245539STrond Myklebust {
582866245539STrond Myklebust return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
582966245539STrond Myklebust }
583066245539STrond Myklebust
decode_reclaim_complete(struct xdr_stream * xdr,void * dummy)583118019753SRicardo Labiaga static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
583218019753SRicardo Labiaga {
583318019753SRicardo Labiaga return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
583418019753SRicardo Labiaga }
583599fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
583699fe60d0SBenny Halevy
decode_sequence(struct xdr_stream * xdr,struct nfs4_sequence_res * res,struct rpc_rqst * rqstp)58379b7b9fccSAndy Adamson static int decode_sequence(struct xdr_stream *xdr,
58389b7b9fccSAndy Adamson struct nfs4_sequence_res *res,
58399b7b9fccSAndy Adamson struct rpc_rqst *rqstp)
58409b7b9fccSAndy Adamson {
58419b7b9fccSAndy Adamson #if defined(CONFIG_NFS_V4_1)
5842e3725ec0STrond Myklebust struct nfs4_session *session;
5843fc01cea9SAndy Adamson struct nfs4_sessionid id;
5844fc01cea9SAndy Adamson u32 dummy;
5845fc01cea9SAndy Adamson int status;
5846fc01cea9SAndy Adamson __be32 *p;
5847fc01cea9SAndy Adamson
5848e3725ec0STrond Myklebust if (res->sr_slot == NULL)
58499b7b9fccSAndy Adamson return 0;
58503bd2384aSChuck Lever if (!res->sr_slot->table->session)
58513bd2384aSChuck Lever return 0;
58529b7b9fccSAndy Adamson
5853fc01cea9SAndy Adamson status = decode_op_hdr(xdr, OP_SEQUENCE);
5854e78291e4SBenny Halevy if (!status)
5855e78291e4SBenny Halevy status = decode_sessionid(xdr, &id);
5856e78291e4SBenny Halevy if (unlikely(status))
5857fc01cea9SAndy Adamson goto out_err;
58589b7b9fccSAndy Adamson
5859fc01cea9SAndy Adamson /*
5860fc01cea9SAndy Adamson * If the server returns different values for sessionID, slotID or
5861fc01cea9SAndy Adamson * sequence number, the server is looney tunes.
5862fc01cea9SAndy Adamson */
5863fdcb4577STrond Myklebust status = -EREMOTEIO;
5864e3725ec0STrond Myklebust session = res->sr_slot->table->session;
5865fc01cea9SAndy Adamson
5866e3725ec0STrond Myklebust if (memcmp(id.data, session->sess_id.data,
5867fc01cea9SAndy Adamson NFS4_MAX_SESSIONID_LEN)) {
5868fc01cea9SAndy Adamson dprintk("%s Invalid session id\n", __func__);
5869fc01cea9SAndy Adamson goto out_err;
5870fc01cea9SAndy Adamson }
5871e78291e4SBenny Halevy
5872c0eae66eSBenny Halevy p = xdr_inline_decode(xdr, 20);
5873c0eae66eSBenny Halevy if (unlikely(!p))
5874c0eae66eSBenny Halevy goto out_overflow;
5875e78291e4SBenny Halevy
5876fc01cea9SAndy Adamson /* seqid */
58776f723f77SBenny Halevy dummy = be32_to_cpup(p++);
5878dfb4f309SBenny Halevy if (dummy != res->sr_slot->seq_nr) {
5879fc01cea9SAndy Adamson dprintk("%s Invalid sequence number\n", __func__);
5880fc01cea9SAndy Adamson goto out_err;
5881fc01cea9SAndy Adamson }
5882fc01cea9SAndy Adamson /* slot id */
58836f723f77SBenny Halevy dummy = be32_to_cpup(p++);
5884df2fabffSTrond Myklebust if (dummy != res->sr_slot->slot_nr) {
5885fc01cea9SAndy Adamson dprintk("%s Invalid slot id\n", __func__);
5886fc01cea9SAndy Adamson goto out_err;
5887fc01cea9SAndy Adamson }
5888da0507b7STrond Myklebust /* highest slot id */
5889da0507b7STrond Myklebust res->sr_highest_slotid = be32_to_cpup(p++);
5890464ee9f9STrond Myklebust /* target highest slot id */
5891464ee9f9STrond Myklebust res->sr_target_highest_slotid = be32_to_cpup(p++);
58920629e370SAlexandros Batsakis /* result flags */
58930629e370SAlexandros Batsakis res->sr_status_flags = be32_to_cpup(p);
5894fc01cea9SAndy Adamson status = 0;
5895fc01cea9SAndy Adamson out_err:
5896fc01cea9SAndy Adamson res->sr_status = status;
5897fc01cea9SAndy Adamson return status;
5898c0eae66eSBenny Halevy out_overflow:
5899c0eae66eSBenny Halevy status = -EIO;
5900c0eae66eSBenny Halevy goto out_err;
5901fc01cea9SAndy Adamson #else /* CONFIG_NFS_V4_1 */
59029b7b9fccSAndy Adamson return 0;
5903fc01cea9SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
59049b7b9fccSAndy Adamson }
59059b7b9fccSAndy Adamson
5906b1f69b75SAndy Adamson #if defined(CONFIG_NFS_V4_1)
decode_layout_stateid(struct xdr_stream * xdr,nfs4_stateid * stateid)590793b717fdSTrond Myklebust static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
590893b717fdSTrond Myklebust {
590993b717fdSTrond Myklebust stateid->type = NFS4_LAYOUT_STATEID_TYPE;
591093b717fdSTrond Myklebust return decode_stateid(xdr, stateid);
591193b717fdSTrond Myklebust }
591293b717fdSTrond Myklebust
decode_getdeviceinfo(struct xdr_stream * xdr,struct nfs4_getdeviceinfo_res * res)5913b1f69b75SAndy Adamson static int decode_getdeviceinfo(struct xdr_stream *xdr,
59144e590803STrond Myklebust struct nfs4_getdeviceinfo_res *res)
5915b1f69b75SAndy Adamson {
59164e590803STrond Myklebust struct pnfs_device *pdev = res->pdev;
5917b1f69b75SAndy Adamson __be32 *p;
5918b1f69b75SAndy Adamson uint32_t len, type;
5919b1f69b75SAndy Adamson int status;
5920b1f69b75SAndy Adamson
5921b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5922b1f69b75SAndy Adamson if (status) {
5923b1f69b75SAndy Adamson if (status == -ETOOSMALL) {
5924b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4);
5925b1f69b75SAndy Adamson if (unlikely(!p))
5926eb72f484SChuck Lever return -EIO;
5927b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p);
5928b1f69b75SAndy Adamson dprintk("%s: Min count too small. mincnt = %u\n",
5929b1f69b75SAndy Adamson __func__, pdev->mincount);
5930b1f69b75SAndy Adamson }
5931b1f69b75SAndy Adamson return status;
5932b1f69b75SAndy Adamson }
5933b1f69b75SAndy Adamson
5934b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 8);
5935b1f69b75SAndy Adamson if (unlikely(!p))
5936eb72f484SChuck Lever return -EIO;
5937b1f69b75SAndy Adamson type = be32_to_cpup(p++);
5938b1f69b75SAndy Adamson if (type != pdev->layout_type) {
5939b1f69b75SAndy Adamson dprintk("%s: layout mismatch req: %u pdev: %u\n",
5940b1f69b75SAndy Adamson __func__, pdev->layout_type, type);
5941b1f69b75SAndy Adamson return -EINVAL;
5942b1f69b75SAndy Adamson }
5943b1f69b75SAndy Adamson /*
5944b1f69b75SAndy Adamson * Get the length of the opaque device_addr4. xdr_read_pages places
5945b1f69b75SAndy Adamson * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5946b1f69b75SAndy Adamson * and places the remaining xdr data in xdr_buf->tail
5947b1f69b75SAndy Adamson */
5948b1f69b75SAndy Adamson pdev->mincount = be32_to_cpup(p);
594913fe4ba1STrond Myklebust if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5950eb72f484SChuck Lever return -EIO;
5951b1f69b75SAndy Adamson
5952b1f69b75SAndy Adamson /* Parse notification bitmap, verifying that it is zero. */
5953b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4);
5954b1f69b75SAndy Adamson if (unlikely(!p))
5955eb72f484SChuck Lever return -EIO;
5956b1f69b75SAndy Adamson len = be32_to_cpup(p);
5957b1f69b75SAndy Adamson if (len) {
5958ead00597SChuck Lever uint32_t i;
5959b1f69b75SAndy Adamson
5960b1f69b75SAndy Adamson p = xdr_inline_decode(xdr, 4 * len);
5961b1f69b75SAndy Adamson if (unlikely(!p))
5962eb72f484SChuck Lever return -EIO;
596384c9dee3SChristoph Hellwig
59644e590803STrond Myklebust res->notification = be32_to_cpup(p++);
596584c9dee3SChristoph Hellwig for (i = 1; i < len; i++) {
596684c9dee3SChristoph Hellwig if (be32_to_cpup(p++)) {
596784c9dee3SChristoph Hellwig dprintk("%s: unsupported notification\n",
5968b1f69b75SAndy Adamson __func__);
5969b1f69b75SAndy Adamson return -EIO;
5970b1f69b75SAndy Adamson }
5971b1f69b75SAndy Adamson }
5972b1f69b75SAndy Adamson }
5973b1f69b75SAndy Adamson return 0;
5974b1f69b75SAndy Adamson }
5975b1f69b75SAndy Adamson
decode_layoutget(struct xdr_stream * xdr,struct rpc_rqst * req,struct nfs4_layoutget_res * res)5976b1f69b75SAndy Adamson static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5977b1f69b75SAndy Adamson struct nfs4_layoutget_res *res)
5978b1f69b75SAndy Adamson {
5979b1f69b75SAndy Adamson __be32 *p;
5980b1f69b75SAndy Adamson int status;
5981b1f69b75SAndy Adamson u32 layout_count;
598264bd577eSTrond Myklebust u32 recvd;
5983b1f69b75SAndy Adamson
5984b1f69b75SAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTGET);
5985b1f69b75SAndy Adamson if (status)
5986808ba32aSFred Isaman goto out;
5987ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4);
5988b1f69b75SAndy Adamson if (unlikely(!p))
5989b1f69b75SAndy Adamson goto out_overflow;
5990ea9d23f5STrond Myklebust res->return_on_close = be32_to_cpup(p);
599193b717fdSTrond Myklebust decode_layout_stateid(xdr, &res->stateid);
5992ea9d23f5STrond Myklebust p = xdr_inline_decode(xdr, 4);
5993ea9d23f5STrond Myklebust if (unlikely(!p))
5994ea9d23f5STrond Myklebust goto out_overflow;
5995b1f69b75SAndy Adamson layout_count = be32_to_cpup(p);
5996b1f69b75SAndy Adamson if (!layout_count) {
5997b1f69b75SAndy Adamson dprintk("%s: server responded with empty layout array\n",
5998b1f69b75SAndy Adamson __func__);
5999808ba32aSFred Isaman status = -EINVAL;
6000808ba32aSFred Isaman goto out;
6001b1f69b75SAndy Adamson }
6002b1f69b75SAndy Adamson
600335124a09SWeston Andros Adamson p = xdr_inline_decode(xdr, 28);
6004b1f69b75SAndy Adamson if (unlikely(!p))
6005b1f69b75SAndy Adamson goto out_overflow;
6006b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.offset);
6007b1f69b75SAndy Adamson p = xdr_decode_hyper(p, &res->range.length);
6008b1f69b75SAndy Adamson res->range.iomode = be32_to_cpup(p++);
6009b1f69b75SAndy Adamson res->type = be32_to_cpup(p++);
601035124a09SWeston Andros Adamson res->layoutp->len = be32_to_cpup(p);
6011b1f69b75SAndy Adamson
6012b1f69b75SAndy Adamson dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6013b1f69b75SAndy Adamson __func__,
6014b1f69b75SAndy Adamson (unsigned long)res->range.offset,
6015b1f69b75SAndy Adamson (unsigned long)res->range.length,
6016b1f69b75SAndy Adamson res->range.iomode,
6017b1f69b75SAndy Adamson res->type,
601835124a09SWeston Andros Adamson res->layoutp->len);
6019b1f69b75SAndy Adamson
602064bd577eSTrond Myklebust recvd = xdr_read_pages(xdr, res->layoutp->len);
602135124a09SWeston Andros Adamson if (res->layoutp->len > recvd) {
602235124a09SWeston Andros Adamson dprintk("NFS: server cheating in layoutget reply: "
602335124a09SWeston Andros Adamson "layout len %u > recvd %u\n",
602435124a09SWeston Andros Adamson res->layoutp->len, recvd);
6025808ba32aSFred Isaman status = -EINVAL;
6026808ba32aSFred Isaman goto out;
602735124a09SWeston Andros Adamson }
602835124a09SWeston Andros Adamson
6029b1f69b75SAndy Adamson if (layout_count > 1) {
6030b1f69b75SAndy Adamson /* We only handle a length one array at the moment. Any
6031b1f69b75SAndy Adamson * further entries are just ignored. Note that this means
6032b1f69b75SAndy Adamson * the client may see a response that is less than the
6033b1f69b75SAndy Adamson * minimum it requested.
6034b1f69b75SAndy Adamson */
6035b1f69b75SAndy Adamson dprintk("%s: server responded with %d layouts, dropping tail\n",
6036b1f69b75SAndy Adamson __func__, layout_count);
6037b1f69b75SAndy Adamson }
6038b1f69b75SAndy Adamson
6039808ba32aSFred Isaman out:
6040808ba32aSFred Isaman res->status = status;
6041808ba32aSFred Isaman return status;
6042b1f69b75SAndy Adamson out_overflow:
6043808ba32aSFred Isaman status = -EIO;
6044808ba32aSFred Isaman goto out;
6045b1f69b75SAndy Adamson }
6046863a3c6cSAndy Adamson
decode_layoutreturn(struct xdr_stream * xdr,struct nfs4_layoutreturn_res * res)6047cbe82603SBenny Halevy static int decode_layoutreturn(struct xdr_stream *xdr,
6048cbe82603SBenny Halevy struct nfs4_layoutreturn_res *res)
6049cbe82603SBenny Halevy {
6050cbe82603SBenny Halevy __be32 *p;
6051cbe82603SBenny Halevy int status;
6052cbe82603SBenny Halevy
6053cbe82603SBenny Halevy status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6054cbe82603SBenny Halevy if (status)
6055cbe82603SBenny Halevy return status;
6056cbe82603SBenny Halevy p = xdr_inline_decode(xdr, 4);
6057cbe82603SBenny Halevy if (unlikely(!p))
6058eb72f484SChuck Lever return -EIO;
6059cbe82603SBenny Halevy res->lrs_present = be32_to_cpup(p);
6060cbe82603SBenny Halevy if (res->lrs_present)
606193b717fdSTrond Myklebust status = decode_layout_stateid(xdr, &res->stateid);
6062fcd8843cSTrond Myklebust else
6063fcd8843cSTrond Myklebust nfs4_stateid_copy(&res->stateid, &invalid_stateid);
6064cbe82603SBenny Halevy return status;
6065cbe82603SBenny Halevy }
6066cbe82603SBenny Halevy
decode_layoutcommit(struct xdr_stream * xdr,struct rpc_rqst * req,struct nfs4_layoutcommit_res * res)6067863a3c6cSAndy Adamson static int decode_layoutcommit(struct xdr_stream *xdr,
6068863a3c6cSAndy Adamson struct rpc_rqst *req,
6069863a3c6cSAndy Adamson struct nfs4_layoutcommit_res *res)
6070863a3c6cSAndy Adamson {
6071863a3c6cSAndy Adamson __be32 *p;
6072863a3c6cSAndy Adamson __u32 sizechanged;
6073863a3c6cSAndy Adamson int status;
6074863a3c6cSAndy Adamson
6075863a3c6cSAndy Adamson status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
6076db29c089SAndy Adamson res->status = status;
6077863a3c6cSAndy Adamson if (status)
6078863a3c6cSAndy Adamson return status;
6079863a3c6cSAndy Adamson
6080863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 4);
6081863a3c6cSAndy Adamson if (unlikely(!p))
6082eb72f484SChuck Lever return -EIO;
6083863a3c6cSAndy Adamson sizechanged = be32_to_cpup(p);
6084863a3c6cSAndy Adamson
6085863a3c6cSAndy Adamson if (sizechanged) {
6086863a3c6cSAndy Adamson /* throw away new size */
6087863a3c6cSAndy Adamson p = xdr_inline_decode(xdr, 8);
6088863a3c6cSAndy Adamson if (unlikely(!p))
6089eb72f484SChuck Lever return -EIO;
6090863a3c6cSAndy Adamson }
6091863a3c6cSAndy Adamson return 0;
6092863a3c6cSAndy Adamson }
60937d974794SBryan Schumaker
decode_test_stateid(struct xdr_stream * xdr,struct nfs41_test_stateid_res * res)60947d974794SBryan Schumaker static int decode_test_stateid(struct xdr_stream *xdr,
60957d974794SBryan Schumaker struct nfs41_test_stateid_res *res)
60967d974794SBryan Schumaker {
60977d974794SBryan Schumaker __be32 *p;
60987d974794SBryan Schumaker int status;
60997d974794SBryan Schumaker int num_res;
61007d974794SBryan Schumaker
61017d974794SBryan Schumaker status = decode_op_hdr(xdr, OP_TEST_STATEID);
61027d974794SBryan Schumaker if (status)
61037d974794SBryan Schumaker return status;
61047d974794SBryan Schumaker
61057d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4);
61067d974794SBryan Schumaker if (unlikely(!p))
6107eb72f484SChuck Lever return -EIO;
61087d974794SBryan Schumaker num_res = be32_to_cpup(p++);
61097d974794SBryan Schumaker if (num_res != 1)
6110eb72f484SChuck Lever return -EIO;
61117d974794SBryan Schumaker
61127d974794SBryan Schumaker p = xdr_inline_decode(xdr, 4);
61137d974794SBryan Schumaker if (unlikely(!p))
6114eb72f484SChuck Lever return -EIO;
61157d974794SBryan Schumaker res->status = be32_to_cpup(p++);
61161cab0652SBryan Schumaker
61171cab0652SBryan Schumaker return status;
61187d974794SBryan Schumaker }
61199aeda35fSBryan Schumaker
decode_free_stateid(struct xdr_stream * xdr,struct nfs41_free_stateid_res * res)61209aeda35fSBryan Schumaker static int decode_free_stateid(struct xdr_stream *xdr,
61219aeda35fSBryan Schumaker struct nfs41_free_stateid_res *res)
61229aeda35fSBryan Schumaker {
61239f79fb48SAndy Adamson res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
61249aeda35fSBryan Schumaker return res->status;
61259aeda35fSBryan Schumaker }
6126cf805165STrond Myklebust #else
6127cf805165STrond Myklebust static inline
decode_layoutreturn(struct xdr_stream * xdr,struct nfs4_layoutreturn_res * res)6128cf805165STrond Myklebust int decode_layoutreturn(struct xdr_stream *xdr,
6129cf805165STrond Myklebust struct nfs4_layoutreturn_res *res)
6130cf805165STrond Myklebust {
6131cf805165STrond Myklebust return 0;
6132cf805165STrond Myklebust }
613356f487f8SFred Isaman
decode_layoutget(struct xdr_stream * xdr,struct rpc_rqst * req,struct nfs4_layoutget_res * res)613456f487f8SFred Isaman static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
613556f487f8SFred Isaman struct nfs4_layoutget_res *res)
613656f487f8SFred Isaman {
613756f487f8SFred Isaman return 0;
613856f487f8SFred Isaman }
613956f487f8SFred Isaman
6140b1f69b75SAndy Adamson #endif /* CONFIG_NFS_V4_1 */
6141b1f69b75SAndy Adamson
61421da177e4SLinus Torvalds /*
614349c2559eSBenny Halevy * END OF "GENERIC" DECODE ROUTINES.
614449c2559eSBenny Halevy */
614549c2559eSBenny Halevy
614649c2559eSBenny Halevy /*
61471da177e4SLinus Torvalds * Decode OPEN_DOWNGRADE response
61481da177e4SLinus Torvalds */
nfs4_xdr_dec_open_downgrade(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6149bf269551SChuck Lever static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6150bf269551SChuck Lever struct xdr_stream *xdr,
6151fc016483SChristoph Hellwig void *data)
61521da177e4SLinus Torvalds {
6153fc016483SChristoph Hellwig struct nfs_closeres *res = data;
61541da177e4SLinus Torvalds struct compound_hdr hdr;
61551da177e4SLinus Torvalds int status;
61561da177e4SLinus Torvalds
6157bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
61581da177e4SLinus Torvalds if (status)
61591da177e4SLinus Torvalds goto out;
6160bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
61619b7b9fccSAndy Adamson if (status)
61629b7b9fccSAndy Adamson goto out;
6163bf269551SChuck Lever status = decode_putfh(xdr);
61641da177e4SLinus Torvalds if (status)
61651da177e4SLinus Torvalds goto out;
6166b6808145STrond Myklebust if (res->lr_res) {
6167b6808145STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res);
6168b6808145STrond Myklebust res->lr_ret = status;
6169b6808145STrond Myklebust if (status)
6170b6808145STrond Myklebust goto out;
6171b6808145STrond Myklebust }
6172bf269551SChuck Lever status = decode_open_downgrade(xdr, res);
61731da177e4SLinus Torvalds out:
61741da177e4SLinus Torvalds return status;
61751da177e4SLinus Torvalds }
61761da177e4SLinus Torvalds
61771da177e4SLinus Torvalds /*
61781da177e4SLinus Torvalds * Decode ACCESS response
61791da177e4SLinus Torvalds */
nfs4_xdr_dec_access(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6180bf269551SChuck Lever static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6181fc016483SChristoph Hellwig void *data)
61821da177e4SLinus Torvalds {
6183fc016483SChristoph Hellwig struct nfs4_accessres *res = data;
61841da177e4SLinus Torvalds struct compound_hdr hdr;
61851da177e4SLinus Torvalds int status;
61861da177e4SLinus Torvalds
6187bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
61889b7b9fccSAndy Adamson if (status)
61899b7b9fccSAndy Adamson goto out;
6190bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
61919b7b9fccSAndy Adamson if (status)
61921da177e4SLinus Torvalds goto out;
6193bf269551SChuck Lever status = decode_putfh(xdr);
619476b32999STrond Myklebust if (status != 0)
619576b32999STrond Myklebust goto out;
61966168f62cSWeston Andros Adamson status = decode_access(xdr, &res->supported, &res->access);
619776b32999STrond Myklebust if (status != 0)
619876b32999STrond Myklebust goto out;
61998bcbe7d9STrond Myklebust if (res->fattr)
62006926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server);
62011da177e4SLinus Torvalds out:
62021da177e4SLinus Torvalds return status;
62031da177e4SLinus Torvalds }
62041da177e4SLinus Torvalds
62051da177e4SLinus Torvalds /*
62061da177e4SLinus Torvalds * Decode LOOKUP response
62071da177e4SLinus Torvalds */
nfs4_xdr_dec_lookup(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6208bf269551SChuck Lever static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6209fc016483SChristoph Hellwig void *data)
62101da177e4SLinus Torvalds {
6211fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data;
62121da177e4SLinus Torvalds struct compound_hdr hdr;
62131da177e4SLinus Torvalds int status;
62141da177e4SLinus Torvalds
6215bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
62169b7b9fccSAndy Adamson if (status)
62179b7b9fccSAndy Adamson goto out;
6218bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
62199b7b9fccSAndy Adamson if (status)
62201da177e4SLinus Torvalds goto out;
6221bf269551SChuck Lever status = decode_putfh(xdr);
6222bf269551SChuck Lever if (status)
62231da177e4SLinus Torvalds goto out;
6224bf269551SChuck Lever status = decode_lookup(xdr);
6225bf269551SChuck Lever if (status)
62261da177e4SLinus Torvalds goto out;
6227bf269551SChuck Lever status = decode_getfh(xdr, res->fh);
6228bf269551SChuck Lever if (status)
62291da177e4SLinus Torvalds goto out;
62301e2f67daSAnna Schumaker status = decode_getfattr(xdr, res->fattr, res->server);
62311da177e4SLinus Torvalds out:
62321da177e4SLinus Torvalds return status;
62331da177e4SLinus Torvalds }
62341da177e4SLinus Torvalds
62351da177e4SLinus Torvalds /*
62365b5faaf6SJeff Layton * Decode LOOKUPP response
62375b5faaf6SJeff Layton */
nfs4_xdr_dec_lookupp(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)62385b5faaf6SJeff Layton static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
62395b5faaf6SJeff Layton void *data)
62405b5faaf6SJeff Layton {
62415b5faaf6SJeff Layton struct nfs4_lookupp_res *res = data;
62425b5faaf6SJeff Layton struct compound_hdr hdr;
62435b5faaf6SJeff Layton int status;
62445b5faaf6SJeff Layton
62455b5faaf6SJeff Layton status = decode_compound_hdr(xdr, &hdr);
62465b5faaf6SJeff Layton if (status)
62475b5faaf6SJeff Layton goto out;
62485b5faaf6SJeff Layton status = decode_sequence(xdr, &res->seq_res, rqstp);
62495b5faaf6SJeff Layton if (status)
62505b5faaf6SJeff Layton goto out;
62515b5faaf6SJeff Layton status = decode_putfh(xdr);
62525b5faaf6SJeff Layton if (status)
62535b5faaf6SJeff Layton goto out;
62545b5faaf6SJeff Layton status = decode_lookupp(xdr);
62555b5faaf6SJeff Layton if (status)
62565b5faaf6SJeff Layton goto out;
62575b5faaf6SJeff Layton status = decode_getfh(xdr, res->fh);
62585b5faaf6SJeff Layton if (status)
62595b5faaf6SJeff Layton goto out;
62601e2f67daSAnna Schumaker status = decode_getfattr(xdr, res->fattr, res->server);
62615b5faaf6SJeff Layton out:
62625b5faaf6SJeff Layton return status;
62635b5faaf6SJeff Layton }
62645b5faaf6SJeff Layton
62655b5faaf6SJeff Layton /*
62661da177e4SLinus Torvalds * Decode LOOKUP_ROOT response
62671da177e4SLinus Torvalds */
nfs4_xdr_dec_lookup_root(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6268bf269551SChuck Lever static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6269bf269551SChuck Lever struct xdr_stream *xdr,
6270fc016483SChristoph Hellwig void *data)
62711da177e4SLinus Torvalds {
6272fc016483SChristoph Hellwig struct nfs4_lookup_res *res = data;
62731da177e4SLinus Torvalds struct compound_hdr hdr;
62741da177e4SLinus Torvalds int status;
62751da177e4SLinus Torvalds
6276bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
62779b7b9fccSAndy Adamson if (status)
62789b7b9fccSAndy Adamson goto out;
6279bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
62809b7b9fccSAndy Adamson if (status)
62811da177e4SLinus Torvalds goto out;
6282bf269551SChuck Lever status = decode_putrootfh(xdr);
6283bf269551SChuck Lever if (status)
62841da177e4SLinus Torvalds goto out;
6285bf269551SChuck Lever status = decode_getfh(xdr, res->fh);
6286bf269551SChuck Lever if (status == 0)
62871e2f67daSAnna Schumaker status = decode_getfattr(xdr, res->fattr, res->server);
62881da177e4SLinus Torvalds out:
62891da177e4SLinus Torvalds return status;
62901da177e4SLinus Torvalds }
62911da177e4SLinus Torvalds
62921da177e4SLinus Torvalds /*
62931da177e4SLinus Torvalds * Decode REMOVE response
62941da177e4SLinus Torvalds */
nfs4_xdr_dec_remove(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6295bf269551SChuck Lever static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6296fc016483SChristoph Hellwig void *data)
62971da177e4SLinus Torvalds {
6298fc016483SChristoph Hellwig struct nfs_removeres *res = data;
62991da177e4SLinus Torvalds struct compound_hdr hdr;
63001da177e4SLinus Torvalds int status;
63011da177e4SLinus Torvalds
6302bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
63039b7b9fccSAndy Adamson if (status)
63049b7b9fccSAndy Adamson goto out;
6305bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
63069b7b9fccSAndy Adamson if (status)
63071da177e4SLinus Torvalds goto out;
6308bf269551SChuck Lever status = decode_putfh(xdr);
6309bf269551SChuck Lever if (status)
631016e42959STrond Myklebust goto out;
6311bf269551SChuck Lever status = decode_remove(xdr, &res->cinfo);
63121da177e4SLinus Torvalds out:
63131da177e4SLinus Torvalds return status;
63141da177e4SLinus Torvalds }
63151da177e4SLinus Torvalds
63161da177e4SLinus Torvalds /*
63171da177e4SLinus Torvalds * Decode RENAME response
63181da177e4SLinus Torvalds */
nfs4_xdr_dec_rename(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6319bf269551SChuck Lever static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6320fc016483SChristoph Hellwig void *data)
63211da177e4SLinus Torvalds {
6322fc016483SChristoph Hellwig struct nfs_renameres *res = data;
63231da177e4SLinus Torvalds struct compound_hdr hdr;
63241da177e4SLinus Torvalds int status;
63251da177e4SLinus Torvalds
6326bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
63279b7b9fccSAndy Adamson if (status)
63289b7b9fccSAndy Adamson goto out;
6329bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
63309b7b9fccSAndy Adamson if (status)
63311da177e4SLinus Torvalds goto out;
6332bf269551SChuck Lever status = decode_putfh(xdr);
6333bf269551SChuck Lever if (status)
63341da177e4SLinus Torvalds goto out;
6335bf269551SChuck Lever status = decode_savefh(xdr);
6336bf269551SChuck Lever if (status)
63371da177e4SLinus Torvalds goto out;
6338bf269551SChuck Lever status = decode_putfh(xdr);
6339bf269551SChuck Lever if (status)
63401da177e4SLinus Torvalds goto out;
6341bf269551SChuck Lever status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
63421da177e4SLinus Torvalds out:
63431da177e4SLinus Torvalds return status;
63441da177e4SLinus Torvalds }
63451da177e4SLinus Torvalds
63461da177e4SLinus Torvalds /*
63471da177e4SLinus Torvalds * Decode LINK response
63481da177e4SLinus Torvalds */
nfs4_xdr_dec_link(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6349bf269551SChuck Lever static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6350fc016483SChristoph Hellwig void *data)
63511da177e4SLinus Torvalds {
6352fc016483SChristoph Hellwig struct nfs4_link_res *res = data;
63531da177e4SLinus Torvalds struct compound_hdr hdr;
63541da177e4SLinus Torvalds int status;
63551da177e4SLinus Torvalds
6356bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
63579b7b9fccSAndy Adamson if (status)
63589b7b9fccSAndy Adamson goto out;
6359bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
63609b7b9fccSAndy Adamson if (status)
63611da177e4SLinus Torvalds goto out;
6362bf269551SChuck Lever status = decode_putfh(xdr);
6363bf269551SChuck Lever if (status)
63641da177e4SLinus Torvalds goto out;
6365bf269551SChuck Lever status = decode_savefh(xdr);
6366bf269551SChuck Lever if (status)
63671da177e4SLinus Torvalds goto out;
6368bf269551SChuck Lever status = decode_putfh(xdr);
6369bf269551SChuck Lever if (status)
63701da177e4SLinus Torvalds goto out;
6371bf269551SChuck Lever status = decode_link(xdr, &res->cinfo);
6372bf269551SChuck Lever if (status)
637391ba2eeeSTrond Myklebust goto out;
637491ba2eeeSTrond Myklebust /*
637591ba2eeeSTrond Myklebust * Note order: OP_LINK leaves the directory as the current
637691ba2eeeSTrond Myklebust * filehandle.
637791ba2eeeSTrond Myklebust */
6378bf269551SChuck Lever status = decode_restorefh(xdr);
6379bf269551SChuck Lever if (status)
638091ba2eeeSTrond Myklebust goto out;
63811e2f67daSAnna Schumaker decode_getfattr(xdr, res->fattr, res->server);
63821da177e4SLinus Torvalds out:
63831da177e4SLinus Torvalds return status;
63841da177e4SLinus Torvalds }
63851da177e4SLinus Torvalds
63861da177e4SLinus Torvalds /*
63871da177e4SLinus Torvalds * Decode CREATE response
63881da177e4SLinus Torvalds */
nfs4_xdr_dec_create(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6389bf269551SChuck Lever static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6390fc016483SChristoph Hellwig void *data)
63911da177e4SLinus Torvalds {
6392fc016483SChristoph Hellwig struct nfs4_create_res *res = data;
63931da177e4SLinus Torvalds struct compound_hdr hdr;
63941da177e4SLinus Torvalds int status;
63951da177e4SLinus Torvalds
6396bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
63979b7b9fccSAndy Adamson if (status)
63989b7b9fccSAndy Adamson goto out;
6399bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
64009b7b9fccSAndy Adamson if (status)
64011da177e4SLinus Torvalds goto out;
6402bf269551SChuck Lever status = decode_putfh(xdr);
6403bf269551SChuck Lever if (status)
64041da177e4SLinus Torvalds goto out;
6405bf269551SChuck Lever status = decode_create(xdr, &res->dir_cinfo);
6406bf269551SChuck Lever if (status)
64071da177e4SLinus Torvalds goto out;
6408bf269551SChuck Lever status = decode_getfh(xdr, res->fh);
6409bf269551SChuck Lever if (status)
64101da177e4SLinus Torvalds goto out;
64111e2f67daSAnna Schumaker decode_getfattr(xdr, res->fattr, res->server);
64121da177e4SLinus Torvalds out:
64131da177e4SLinus Torvalds return status;
64141da177e4SLinus Torvalds }
64151da177e4SLinus Torvalds
64161da177e4SLinus Torvalds /*
64171da177e4SLinus Torvalds * Decode SYMLINK response
64181da177e4SLinus Torvalds */
nfs4_xdr_dec_symlink(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * res)6419bf269551SChuck Lever static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6420fc016483SChristoph Hellwig void *res)
64211da177e4SLinus Torvalds {
6422bf269551SChuck Lever return nfs4_xdr_dec_create(rqstp, xdr, res);
64231da177e4SLinus Torvalds }
64241da177e4SLinus Torvalds
64251da177e4SLinus Torvalds /*
64261da177e4SLinus Torvalds * Decode GETATTR response
64271da177e4SLinus Torvalds */
nfs4_xdr_dec_getattr(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6428bf269551SChuck Lever static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6429fc016483SChristoph Hellwig void *data)
64301da177e4SLinus Torvalds {
6431fc016483SChristoph Hellwig struct nfs4_getattr_res *res = data;
64321da177e4SLinus Torvalds struct compound_hdr hdr;
64331da177e4SLinus Torvalds int status;
64341da177e4SLinus Torvalds
6435bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
64361da177e4SLinus Torvalds if (status)
64371da177e4SLinus Torvalds goto out;
6438bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
64399b7b9fccSAndy Adamson if (status)
64409b7b9fccSAndy Adamson goto out;
6441bf269551SChuck Lever status = decode_putfh(xdr);
64421da177e4SLinus Torvalds if (status)
64431da177e4SLinus Torvalds goto out;
64441e2f67daSAnna Schumaker status = decode_getfattr(xdr, res->fattr, res->server);
64451da177e4SLinus Torvalds out:
64461da177e4SLinus Torvalds return status;
64471da177e4SLinus Torvalds }
64481da177e4SLinus Torvalds
644923ec6965SJ. Bruce Fields /*
645023ec6965SJ. Bruce Fields * Encode an SETACL request
645123ec6965SJ. Bruce Fields */
nfs4_xdr_enc_setacl(struct rpc_rqst * req,struct xdr_stream * xdr,const void * data)64529f06c719SChuck Lever static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6453fcc85819SChristoph Hellwig const void *data)
645423ec6965SJ. Bruce Fields {
6455fcc85819SChristoph Hellwig const struct nfs_setaclargs *args = data;
645623ec6965SJ. Bruce Fields struct compound_hdr hdr = {
645766cc0429SBenny Halevy .minorversion = nfs4_xdr_minorversion(&args->seq_args),
645823ec6965SJ. Bruce Fields };
645923ec6965SJ. Bruce Fields
64609f06c719SChuck Lever encode_compound_hdr(xdr, req, &hdr);
64619f06c719SChuck Lever encode_sequence(xdr, &args->seq_args, &hdr);
64629f06c719SChuck Lever encode_putfh(xdr, args->fh, &hdr);
64639f06c719SChuck Lever encode_setacl(xdr, args, &hdr);
6464d017931cSAndy Adamson encode_nops(&hdr);
646523ec6965SJ. Bruce Fields }
646605d564feSAndy Adamson
646723ec6965SJ. Bruce Fields /*
646823ec6965SJ. Bruce Fields * Decode SETACL response
646923ec6965SJ. Bruce Fields */
647023ec6965SJ. Bruce Fields static int
nfs4_xdr_dec_setacl(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6471bf269551SChuck Lever nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6472fc016483SChristoph Hellwig void *data)
647323ec6965SJ. Bruce Fields {
6474fc016483SChristoph Hellwig struct nfs_setaclres *res = data;
647523ec6965SJ. Bruce Fields struct compound_hdr hdr;
647623ec6965SJ. Bruce Fields int status;
647723ec6965SJ. Bruce Fields
6478bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
647923ec6965SJ. Bruce Fields if (status)
648023ec6965SJ. Bruce Fields goto out;
6481bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
64829b7b9fccSAndy Adamson if (status)
64839b7b9fccSAndy Adamson goto out;
6484bf269551SChuck Lever status = decode_putfh(xdr);
648523ec6965SJ. Bruce Fields if (status)
648623ec6965SJ. Bruce Fields goto out;
6487bf269551SChuck Lever status = decode_setattr(xdr);
648823ec6965SJ. Bruce Fields out:
648923ec6965SJ. Bruce Fields return status;
649023ec6965SJ. Bruce Fields }
64911da177e4SLinus Torvalds
64921da177e4SLinus Torvalds /*
6493029d105eSJ. Bruce Fields * Decode GETACL response
6494029d105eSJ. Bruce Fields */
6495029d105eSJ. Bruce Fields static int
nfs4_xdr_dec_getacl(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6496bf269551SChuck Lever nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6497fc016483SChristoph Hellwig void *data)
6498029d105eSJ. Bruce Fields {
6499fc016483SChristoph Hellwig struct nfs_getaclres *res = data;
6500029d105eSJ. Bruce Fields struct compound_hdr hdr;
6501029d105eSJ. Bruce Fields int status;
6502029d105eSJ. Bruce Fields
65030ae4c3e8SChuck Lever if (res->acl_scratch != NULL)
65040ae4c3e8SChuck Lever xdr_set_scratch_page(xdr, res->acl_scratch);
6505bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
6506029d105eSJ. Bruce Fields if (status)
6507029d105eSJ. Bruce Fields goto out;
6508bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
65099b7b9fccSAndy Adamson if (status)
65109b7b9fccSAndy Adamson goto out;
6511bf269551SChuck Lever status = decode_putfh(xdr);
6512029d105eSJ. Bruce Fields if (status)
6513029d105eSJ. Bruce Fields goto out;
6514db145db0STrond Myklebust status = decode_getacl(xdr, rqstp, res, res->acl_type);
6515029d105eSJ. Bruce Fields
6516029d105eSJ. Bruce Fields out:
6517029d105eSJ. Bruce Fields return status;
6518029d105eSJ. Bruce Fields }
6519029d105eSJ. Bruce Fields
6520029d105eSJ. Bruce Fields /*
65211da177e4SLinus Torvalds * Decode CLOSE response
65221da177e4SLinus Torvalds */
nfs4_xdr_dec_close(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6523bf269551SChuck Lever static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6524fc016483SChristoph Hellwig void *data)
65251da177e4SLinus Torvalds {
6526fc016483SChristoph Hellwig struct nfs_closeres *res = data;
65271da177e4SLinus Torvalds struct compound_hdr hdr;
65281da177e4SLinus Torvalds int status;
65291da177e4SLinus Torvalds
6530bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
65311da177e4SLinus Torvalds if (status)
65321da177e4SLinus Torvalds goto out;
6533bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
65349b7b9fccSAndy Adamson if (status)
65359b7b9fccSAndy Adamson goto out;
6536bf269551SChuck Lever status = decode_putfh(xdr);
65371da177e4SLinus Torvalds if (status)
65381da177e4SLinus Torvalds goto out;
6539cf805165STrond Myklebust if (res->lr_res) {
6540cf805165STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res);
6541cf805165STrond Myklebust res->lr_ret = status;
6542cf805165STrond Myklebust if (status)
6543cf805165STrond Myklebust goto out;
6544cf805165STrond Myklebust }
6545d8d84983STrond Myklebust if (res->fattr != NULL) {
6546d8d84983STrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server);
6547516a6af6STrond Myklebust if (status != 0)
6548516a6af6STrond Myklebust goto out;
6549d8d84983STrond Myklebust }
6550d8d84983STrond Myklebust status = decode_close(xdr, res);
65511da177e4SLinus Torvalds out:
65521da177e4SLinus Torvalds return status;
65531da177e4SLinus Torvalds }
65541da177e4SLinus Torvalds
65551da177e4SLinus Torvalds /*
65561da177e4SLinus Torvalds * Decode OPEN response
65571da177e4SLinus Torvalds */
nfs4_xdr_dec_open(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6558bf269551SChuck Lever static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6559fc016483SChristoph Hellwig void *data)
65601da177e4SLinus Torvalds {
6561fc016483SChristoph Hellwig struct nfs_openres *res = data;
65621da177e4SLinus Torvalds struct compound_hdr hdr;
65631da177e4SLinus Torvalds int status;
65641da177e4SLinus Torvalds
6565bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
65661da177e4SLinus Torvalds if (status)
65671da177e4SLinus Torvalds goto out;
6568bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
65699b7b9fccSAndy Adamson if (status)
65709b7b9fccSAndy Adamson goto out;
6571bf269551SChuck Lever status = decode_putfh(xdr);
65721da177e4SLinus Torvalds if (status)
65731da177e4SLinus Torvalds goto out;
6574bf269551SChuck Lever status = decode_open(xdr, res);
65751da177e4SLinus Torvalds if (status)
65761da177e4SLinus Torvalds goto out;
657701913b49SWeston Andros Adamson status = decode_getfh(xdr, &res->fh);
657801913b49SWeston Andros Adamson if (status)
65791da177e4SLinus Torvalds goto out;
6580ae2bb032SWeston Andros Adamson if (res->access_request)
65816168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result);
65821e2f67daSAnna Schumaker decode_getfattr(xdr, res->f_attr, res->server);
658356f487f8SFred Isaman if (res->lg_res)
658456f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res);
65851da177e4SLinus Torvalds out:
65861da177e4SLinus Torvalds return status;
65871da177e4SLinus Torvalds }
65881da177e4SLinus Torvalds
65891da177e4SLinus Torvalds /*
65901da177e4SLinus Torvalds * Decode OPEN_CONFIRM response
65911da177e4SLinus Torvalds */
nfs4_xdr_dec_open_confirm(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6592bf269551SChuck Lever static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6593bf269551SChuck Lever struct xdr_stream *xdr,
6594fc016483SChristoph Hellwig void *data)
65951da177e4SLinus Torvalds {
6596fc016483SChristoph Hellwig struct nfs_open_confirmres *res = data;
65971da177e4SLinus Torvalds struct compound_hdr hdr;
65981da177e4SLinus Torvalds int status;
65991da177e4SLinus Torvalds
6600bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
66011da177e4SLinus Torvalds if (status)
66021da177e4SLinus Torvalds goto out;
6603bf269551SChuck Lever status = decode_putfh(xdr);
66041da177e4SLinus Torvalds if (status)
66051da177e4SLinus Torvalds goto out;
6606bf269551SChuck Lever status = decode_open_confirm(xdr, res);
66071da177e4SLinus Torvalds out:
66081da177e4SLinus Torvalds return status;
66091da177e4SLinus Torvalds }
66101da177e4SLinus Torvalds
66111da177e4SLinus Torvalds /*
66121da177e4SLinus Torvalds * Decode OPEN response
66131da177e4SLinus Torvalds */
nfs4_xdr_dec_open_noattr(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6614bf269551SChuck Lever static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6615bf269551SChuck Lever struct xdr_stream *xdr,
6616fc016483SChristoph Hellwig void *data)
66171da177e4SLinus Torvalds {
6618fc016483SChristoph Hellwig struct nfs_openres *res = data;
66191da177e4SLinus Torvalds struct compound_hdr hdr;
66201da177e4SLinus Torvalds int status;
66211da177e4SLinus Torvalds
6622bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
66231da177e4SLinus Torvalds if (status)
66241da177e4SLinus Torvalds goto out;
6625bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
66269b7b9fccSAndy Adamson if (status)
66279b7b9fccSAndy Adamson goto out;
6628bf269551SChuck Lever status = decode_putfh(xdr);
66291da177e4SLinus Torvalds if (status)
66301da177e4SLinus Torvalds goto out;
6631bf269551SChuck Lever status = decode_open(xdr, res);
6632864472e9STrond Myklebust if (status)
6633864472e9STrond Myklebust goto out;
6634ae2bb032SWeston Andros Adamson if (res->access_request)
66356168f62cSWeston Andros Adamson decode_access(xdr, &res->access_supported, &res->access_result);
66366926afd1STrond Myklebust decode_getfattr(xdr, res->f_attr, res->server);
663756f487f8SFred Isaman if (res->lg_res)
663856f487f8SFred Isaman decode_layoutget(xdr, rqstp, res->lg_res);
66391da177e4SLinus Torvalds out:
66401da177e4SLinus Torvalds return status;
66411da177e4SLinus Torvalds }
66421da177e4SLinus Torvalds
66431da177e4SLinus Torvalds /*
66441da177e4SLinus Torvalds * Decode SETATTR response
66451da177e4SLinus Torvalds */
nfs4_xdr_dec_setattr(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6646bf269551SChuck Lever static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6647bf269551SChuck Lever struct xdr_stream *xdr,
6648fc016483SChristoph Hellwig void *data)
66491da177e4SLinus Torvalds {
6650fc016483SChristoph Hellwig struct nfs_setattrres *res = data;
66511da177e4SLinus Torvalds struct compound_hdr hdr;
66521da177e4SLinus Torvalds int status;
66531da177e4SLinus Torvalds
6654bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
66551da177e4SLinus Torvalds if (status)
66561da177e4SLinus Torvalds goto out;
6657bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
66589b7b9fccSAndy Adamson if (status)
66599b7b9fccSAndy Adamson goto out;
6660bf269551SChuck Lever status = decode_putfh(xdr);
66611da177e4SLinus Torvalds if (status)
66621da177e4SLinus Torvalds goto out;
6663bf269551SChuck Lever status = decode_setattr(xdr);
66641da177e4SLinus Torvalds if (status)
66651da177e4SLinus Torvalds goto out;
66661e2f67daSAnna Schumaker decode_getfattr(xdr, res->fattr, res->server);
66671da177e4SLinus Torvalds out:
66681da177e4SLinus Torvalds return status;
66691da177e4SLinus Torvalds }
66701da177e4SLinus Torvalds
66711da177e4SLinus Torvalds /*
66721da177e4SLinus Torvalds * Decode LOCK response
66731da177e4SLinus Torvalds */
nfs4_xdr_dec_lock(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6674bf269551SChuck Lever static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6675fc016483SChristoph Hellwig void *data)
66761da177e4SLinus Torvalds {
6677fc016483SChristoph Hellwig struct nfs_lock_res *res = data;
66781da177e4SLinus Torvalds struct compound_hdr hdr;
66791da177e4SLinus Torvalds int status;
66801da177e4SLinus Torvalds
6681bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
66821da177e4SLinus Torvalds if (status)
66831da177e4SLinus Torvalds goto out;
6684bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
66859b7b9fccSAndy Adamson if (status)
66869b7b9fccSAndy Adamson goto out;
6687bf269551SChuck Lever status = decode_putfh(xdr);
66881da177e4SLinus Torvalds if (status)
66891da177e4SLinus Torvalds goto out;
6690bf269551SChuck Lever status = decode_lock(xdr, res);
66911da177e4SLinus Torvalds out:
66921da177e4SLinus Torvalds return status;
66931da177e4SLinus Torvalds }
66941da177e4SLinus Torvalds
66951da177e4SLinus Torvalds /*
66961da177e4SLinus Torvalds * Decode LOCKT response
66971da177e4SLinus Torvalds */
nfs4_xdr_dec_lockt(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6698bf269551SChuck Lever static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6699fc016483SChristoph Hellwig void *data)
67001da177e4SLinus Torvalds {
6701fc016483SChristoph Hellwig struct nfs_lockt_res *res = data;
67021da177e4SLinus Torvalds struct compound_hdr hdr;
67031da177e4SLinus Torvalds int status;
67041da177e4SLinus Torvalds
6705bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
67061da177e4SLinus Torvalds if (status)
67071da177e4SLinus Torvalds goto out;
6708bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
67099b7b9fccSAndy Adamson if (status)
67109b7b9fccSAndy Adamson goto out;
6711bf269551SChuck Lever status = decode_putfh(xdr);
67121da177e4SLinus Torvalds if (status)
67131da177e4SLinus Torvalds goto out;
6714bf269551SChuck Lever status = decode_lockt(xdr, res);
67151da177e4SLinus Torvalds out:
67161da177e4SLinus Torvalds return status;
67171da177e4SLinus Torvalds }
67181da177e4SLinus Torvalds
67191da177e4SLinus Torvalds /*
67201da177e4SLinus Torvalds * Decode LOCKU response
67211da177e4SLinus Torvalds */
nfs4_xdr_dec_locku(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6722bf269551SChuck Lever static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6723fc016483SChristoph Hellwig void *data)
67241da177e4SLinus Torvalds {
6725fc016483SChristoph Hellwig struct nfs_locku_res *res = data;
67261da177e4SLinus Torvalds struct compound_hdr hdr;
67271da177e4SLinus Torvalds int status;
67281da177e4SLinus Torvalds
6729bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
67301da177e4SLinus Torvalds if (status)
67311da177e4SLinus Torvalds goto out;
6732bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
67339b7b9fccSAndy Adamson if (status)
67349b7b9fccSAndy Adamson goto out;
6735bf269551SChuck Lever status = decode_putfh(xdr);
67361da177e4SLinus Torvalds if (status)
67371da177e4SLinus Torvalds goto out;
6738bf269551SChuck Lever status = decode_locku(xdr, res);
67391da177e4SLinus Torvalds out:
67401da177e4SLinus Torvalds return status;
67411da177e4SLinus Torvalds }
67421da177e4SLinus Torvalds
nfs4_xdr_dec_release_lockowner(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * dummy)6743bf269551SChuck Lever static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6744bf269551SChuck Lever struct xdr_stream *xdr, void *dummy)
6745d3c7b7ccSTrond Myklebust {
6746d3c7b7ccSTrond Myklebust struct compound_hdr hdr;
6747d3c7b7ccSTrond Myklebust int status;
6748d3c7b7ccSTrond Myklebust
6749bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
6750d3c7b7ccSTrond Myklebust if (!status)
6751bf269551SChuck Lever status = decode_release_lockowner(xdr);
6752d3c7b7ccSTrond Myklebust return status;
6753d3c7b7ccSTrond Myklebust }
6754d3c7b7ccSTrond Myklebust
67551da177e4SLinus Torvalds /*
67561da177e4SLinus Torvalds * Decode READLINK response
67571da177e4SLinus Torvalds */
nfs4_xdr_dec_readlink(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6758bf269551SChuck Lever static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6759bf269551SChuck Lever struct xdr_stream *xdr,
6760fc016483SChristoph Hellwig void *data)
67611da177e4SLinus Torvalds {
6762fc016483SChristoph Hellwig struct nfs4_readlink_res *res = data;
67631da177e4SLinus Torvalds struct compound_hdr hdr;
67641da177e4SLinus Torvalds int status;
67651da177e4SLinus Torvalds
6766bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
67671da177e4SLinus Torvalds if (status)
67681da177e4SLinus Torvalds goto out;
6769bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
67709b7b9fccSAndy Adamson if (status)
67719b7b9fccSAndy Adamson goto out;
6772bf269551SChuck Lever status = decode_putfh(xdr);
67731da177e4SLinus Torvalds if (status)
67741da177e4SLinus Torvalds goto out;
6775bf269551SChuck Lever status = decode_readlink(xdr, rqstp);
67761da177e4SLinus Torvalds out:
67771da177e4SLinus Torvalds return status;
67781da177e4SLinus Torvalds }
67791da177e4SLinus Torvalds
67801da177e4SLinus Torvalds /*
67811da177e4SLinus Torvalds * Decode READDIR response
67821da177e4SLinus Torvalds */
nfs4_xdr_dec_readdir(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6783bf269551SChuck Lever static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6784fc016483SChristoph Hellwig void *data)
67851da177e4SLinus Torvalds {
6786fc016483SChristoph Hellwig struct nfs4_readdir_res *res = data;
67871da177e4SLinus Torvalds struct compound_hdr hdr;
67881da177e4SLinus Torvalds int status;
67891da177e4SLinus Torvalds
6790bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
67911da177e4SLinus Torvalds if (status)
67921da177e4SLinus Torvalds goto out;
6793bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
67949b7b9fccSAndy Adamson if (status)
67959b7b9fccSAndy Adamson goto out;
6796bf269551SChuck Lever status = decode_putfh(xdr);
67971da177e4SLinus Torvalds if (status)
67981da177e4SLinus Torvalds goto out;
6799bf269551SChuck Lever status = decode_readdir(xdr, rqstp, res);
68001da177e4SLinus Torvalds out:
68011da177e4SLinus Torvalds return status;
68021da177e4SLinus Torvalds }
68031da177e4SLinus Torvalds
68041da177e4SLinus Torvalds /*
68051da177e4SLinus Torvalds * Decode Read response
68061da177e4SLinus Torvalds */
nfs4_xdr_dec_read(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6807bf269551SChuck Lever static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6808fc016483SChristoph Hellwig void *data)
68091da177e4SLinus Torvalds {
6810fc016483SChristoph Hellwig struct nfs_pgio_res *res = data;
68111da177e4SLinus Torvalds struct compound_hdr hdr;
68121da177e4SLinus Torvalds int status;
68131da177e4SLinus Torvalds
6814bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
6815aabff4ddSPeng Tao res->op_status = hdr.status;
68161da177e4SLinus Torvalds if (status)
68171da177e4SLinus Torvalds goto out;
6818bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
68199b7b9fccSAndy Adamson if (status)
68209b7b9fccSAndy Adamson goto out;
6821bf269551SChuck Lever status = decode_putfh(xdr);
68221da177e4SLinus Torvalds if (status)
68231da177e4SLinus Torvalds goto out;
6824bf269551SChuck Lever status = decode_read(xdr, rqstp, res);
68251da177e4SLinus Torvalds if (!status)
68261da177e4SLinus Torvalds status = res->count;
68271da177e4SLinus Torvalds out:
68281da177e4SLinus Torvalds return status;
68291da177e4SLinus Torvalds }
68301da177e4SLinus Torvalds
68311da177e4SLinus Torvalds /*
68321da177e4SLinus Torvalds * Decode WRITE response
68331da177e4SLinus Torvalds */
nfs4_xdr_dec_write(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6834bf269551SChuck Lever static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6835fc016483SChristoph Hellwig void *data)
68361da177e4SLinus Torvalds {
6837fc016483SChristoph Hellwig struct nfs_pgio_res *res = data;
68381da177e4SLinus Torvalds struct compound_hdr hdr;
68391da177e4SLinus Torvalds int status;
68401da177e4SLinus Torvalds
6841bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
6842aabff4ddSPeng Tao res->op_status = hdr.status;
68431da177e4SLinus Torvalds if (status)
68441da177e4SLinus Torvalds goto out;
6845bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
68469b7b9fccSAndy Adamson if (status)
68479b7b9fccSAndy Adamson goto out;
6848bf269551SChuck Lever status = decode_putfh(xdr);
68491da177e4SLinus Torvalds if (status)
68501da177e4SLinus Torvalds goto out;
6851bf269551SChuck Lever status = decode_write(xdr, res);
68524f9838c7STrond Myklebust if (status)
68534f9838c7STrond Myklebust goto out;
68547ffd1064SFred Isaman if (res->fattr)
68556926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server);
68561da177e4SLinus Torvalds if (!status)
68571da177e4SLinus Torvalds status = res->count;
68581da177e4SLinus Torvalds out:
68591da177e4SLinus Torvalds return status;
68601da177e4SLinus Torvalds }
68611da177e4SLinus Torvalds
68621da177e4SLinus Torvalds /*
68631da177e4SLinus Torvalds * Decode COMMIT response
68641da177e4SLinus Torvalds */
nfs4_xdr_dec_commit(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)6865bf269551SChuck Lever static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6866fc016483SChristoph Hellwig void *data)
68671da177e4SLinus Torvalds {
6868fc016483SChristoph Hellwig struct nfs_commitres *res = data;
68691da177e4SLinus Torvalds struct compound_hdr hdr;
68701da177e4SLinus Torvalds int status;
68711da177e4SLinus Torvalds
6872bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
6873aabff4ddSPeng Tao res->op_status = hdr.status;
68741da177e4SLinus Torvalds if (status)
68751da177e4SLinus Torvalds goto out;
6876bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
68779b7b9fccSAndy Adamson if (status)
68789b7b9fccSAndy Adamson goto out;
6879bf269551SChuck Lever status = decode_putfh(xdr);
68801da177e4SLinus Torvalds if (status)
68811da177e4SLinus Torvalds goto out;
6882bf269551SChuck Lever status = decode_commit(xdr, res);
68831da177e4SLinus Torvalds out:
68841da177e4SLinus Torvalds return status;
68851da177e4SLinus Torvalds }
68861da177e4SLinus Torvalds
68871da177e4SLinus Torvalds /*
68888b173218SRicardo Labiaga * Decode FSINFO response
68891da177e4SLinus Torvalds */
nfs4_xdr_dec_fsinfo(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)6890bf269551SChuck Lever static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
6891fc016483SChristoph Hellwig void *data)
68921da177e4SLinus Torvalds {
6893fc016483SChristoph Hellwig struct nfs4_fsinfo_res *res = data;
68941da177e4SLinus Torvalds struct compound_hdr hdr;
68951da177e4SLinus Torvalds int status;
68961da177e4SLinus Torvalds
6897bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
68981da177e4SLinus Torvalds if (!status)
6899bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req);
69009b7b9fccSAndy Adamson if (!status)
6901bf269551SChuck Lever status = decode_putfh(xdr);
69021da177e4SLinus Torvalds if (!status)
6903bf269551SChuck Lever status = decode_fsinfo(xdr, res->fsinfo);
69041da177e4SLinus Torvalds return status;
69051da177e4SLinus Torvalds }
69061da177e4SLinus Torvalds
69071da177e4SLinus Torvalds /*
69088b173218SRicardo Labiaga * Decode PATHCONF response
69091da177e4SLinus Torvalds */
nfs4_xdr_dec_pathconf(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)6910bf269551SChuck Lever static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
6911fc016483SChristoph Hellwig void *data)
69121da177e4SLinus Torvalds {
6913fc016483SChristoph Hellwig struct nfs4_pathconf_res *res = data;
69141da177e4SLinus Torvalds struct compound_hdr hdr;
69151da177e4SLinus Torvalds int status;
69161da177e4SLinus Torvalds
6917bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
69181da177e4SLinus Torvalds if (!status)
6919bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req);
69209b7b9fccSAndy Adamson if (!status)
6921bf269551SChuck Lever status = decode_putfh(xdr);
69221da177e4SLinus Torvalds if (!status)
6923bf269551SChuck Lever status = decode_pathconf(xdr, res->pathconf);
69241da177e4SLinus Torvalds return status;
69251da177e4SLinus Torvalds }
69261da177e4SLinus Torvalds
69271da177e4SLinus Torvalds /*
69288b173218SRicardo Labiaga * Decode STATFS response
69291da177e4SLinus Torvalds */
nfs4_xdr_dec_statfs(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)6930bf269551SChuck Lever static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
6931fc016483SChristoph Hellwig void *data)
69321da177e4SLinus Torvalds {
6933fc016483SChristoph Hellwig struct nfs4_statfs_res *res = data;
69341da177e4SLinus Torvalds struct compound_hdr hdr;
69351da177e4SLinus Torvalds int status;
69361da177e4SLinus Torvalds
6937bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
69381da177e4SLinus Torvalds if (!status)
6939bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req);
69409b7b9fccSAndy Adamson if (!status)
6941bf269551SChuck Lever status = decode_putfh(xdr);
69421da177e4SLinus Torvalds if (!status)
6943bf269551SChuck Lever status = decode_statfs(xdr, res->fsstat);
69441da177e4SLinus Torvalds return status;
69451da177e4SLinus Torvalds }
69461da177e4SLinus Torvalds
69471da177e4SLinus Torvalds /*
69488b173218SRicardo Labiaga * Decode GETATTR_BITMAP response
69491da177e4SLinus Torvalds */
nfs4_xdr_dec_server_caps(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)6950bf269551SChuck Lever static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6951bf269551SChuck Lever struct xdr_stream *xdr,
6952fc016483SChristoph Hellwig void *data)
69531da177e4SLinus Torvalds {
6954fc016483SChristoph Hellwig struct nfs4_server_caps_res *res = data;
69551da177e4SLinus Torvalds struct compound_hdr hdr;
69561da177e4SLinus Torvalds int status;
69571da177e4SLinus Torvalds
6958bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
69599b7b9fccSAndy Adamson if (status)
69609b7b9fccSAndy Adamson goto out;
6961bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req);
69629b7b9fccSAndy Adamson if (status)
69631da177e4SLinus Torvalds goto out;
6964bf269551SChuck Lever status = decode_putfh(xdr);
6965bf269551SChuck Lever if (status)
69661da177e4SLinus Torvalds goto out;
6967bf269551SChuck Lever status = decode_server_caps(xdr, res);
69681da177e4SLinus Torvalds out:
69691da177e4SLinus Torvalds return status;
69701da177e4SLinus Torvalds }
69711da177e4SLinus Torvalds
69721da177e4SLinus Torvalds /*
69731da177e4SLinus Torvalds * Decode RENEW response
69741da177e4SLinus Torvalds */
nfs4_xdr_dec_renew(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * __unused)6975bf269551SChuck Lever static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6976bf269551SChuck Lever void *__unused)
69771da177e4SLinus Torvalds {
69781da177e4SLinus Torvalds struct compound_hdr hdr;
69791da177e4SLinus Torvalds int status;
69801da177e4SLinus Torvalds
6981bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
69821da177e4SLinus Torvalds if (!status)
6983bf269551SChuck Lever status = decode_renew(xdr);
69841da177e4SLinus Torvalds return status;
69851da177e4SLinus Torvalds }
69861da177e4SLinus Torvalds
69871da177e4SLinus Torvalds /*
69888b173218SRicardo Labiaga * Decode SETCLIENTID response
69891da177e4SLinus Torvalds */
nfs4_xdr_dec_setclientid(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)6990bf269551SChuck Lever static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6991bf269551SChuck Lever struct xdr_stream *xdr,
6992fc016483SChristoph Hellwig void *data)
69931da177e4SLinus Torvalds {
6994fc016483SChristoph Hellwig struct nfs4_setclientid_res *res = data;
69951da177e4SLinus Torvalds struct compound_hdr hdr;
69961da177e4SLinus Torvalds int status;
69971da177e4SLinus Torvalds
6998bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
69991da177e4SLinus Torvalds if (!status)
7000bf269551SChuck Lever status = decode_setclientid(xdr, res);
70011da177e4SLinus Torvalds return status;
70021da177e4SLinus Torvalds }
70031da177e4SLinus Torvalds
70041da177e4SLinus Torvalds /*
70058b173218SRicardo Labiaga * Decode SETCLIENTID_CONFIRM response
70061da177e4SLinus Torvalds */
nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)7007bf269551SChuck Lever static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
7008fc016483SChristoph Hellwig struct xdr_stream *xdr,
7009fc016483SChristoph Hellwig void *data)
70101da177e4SLinus Torvalds {
70111da177e4SLinus Torvalds struct compound_hdr hdr;
70121da177e4SLinus Torvalds int status;
70131da177e4SLinus Torvalds
7014bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
70151da177e4SLinus Torvalds if (!status)
7016bf269551SChuck Lever status = decode_setclientid_confirm(xdr);
70171da177e4SLinus Torvalds return status;
70181da177e4SLinus Torvalds }
70191da177e4SLinus Torvalds
70201da177e4SLinus Torvalds /*
70218b173218SRicardo Labiaga * Decode DELEGRETURN response
70221da177e4SLinus Torvalds */
nfs4_xdr_dec_delegreturn(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7023bf269551SChuck Lever static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7024bf269551SChuck Lever struct xdr_stream *xdr,
7025fc016483SChristoph Hellwig void *data)
70261da177e4SLinus Torvalds {
7027fc016483SChristoph Hellwig struct nfs4_delegreturnres *res = data;
70281da177e4SLinus Torvalds struct compound_hdr hdr;
70291da177e4SLinus Torvalds int status;
70301da177e4SLinus Torvalds
7031bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
70329b7b9fccSAndy Adamson if (status)
70339b7b9fccSAndy Adamson goto out;
7034bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
70359b7b9fccSAndy Adamson if (status)
7036fa178f29STrond Myklebust goto out;
7037bf269551SChuck Lever status = decode_putfh(xdr);
7038fa178f29STrond Myklebust if (status != 0)
7039fa178f29STrond Myklebust goto out;
7040586f1c39STrond Myklebust if (res->lr_res) {
7041586f1c39STrond Myklebust status = decode_layoutreturn(xdr, res->lr_res);
7042586f1c39STrond Myklebust res->lr_ret = status;
7043586f1c39STrond Myklebust if (status)
7044586f1c39STrond Myklebust goto out;
7045586f1c39STrond Myklebust }
70468ac2b422STrond Myklebust if (res->fattr) {
7047e144cbccSTrond Myklebust status = decode_getfattr(xdr, res->fattr, res->server);
7048556ae3bbSJeff Layton if (status != 0)
7049556ae3bbSJeff Layton goto out;
70508ac2b422STrond Myklebust }
7051e144cbccSTrond Myklebust status = decode_delegreturn(xdr);
7052fa178f29STrond Myklebust out:
70531da177e4SLinus Torvalds return status;
70541da177e4SLinus Torvalds }
70551da177e4SLinus Torvalds
7056683b57b4STrond Myklebust /*
70578b173218SRicardo Labiaga * Decode FS_LOCATIONS response
7058683b57b4STrond Myklebust */
nfs4_xdr_dec_fs_locations(struct rpc_rqst * req,struct xdr_stream * xdr,void * data)7059bf269551SChuck Lever static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7060bf269551SChuck Lever struct xdr_stream *xdr,
7061fc016483SChristoph Hellwig void *data)
7062683b57b4STrond Myklebust {
7063fc016483SChristoph Hellwig struct nfs4_fs_locations_res *res = data;
7064683b57b4STrond Myklebust struct compound_hdr hdr;
7065683b57b4STrond Myklebust int status;
7066683b57b4STrond Myklebust
7067bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
70689b7b9fccSAndy Adamson if (status)
70699b7b9fccSAndy Adamson goto out;
7070bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, req);
70719b7b9fccSAndy Adamson if (status)
7072683b57b4STrond Myklebust goto out;
7073bf269551SChuck Lever status = decode_putfh(xdr);
7074bf269551SChuck Lever if (status)
7075683b57b4STrond Myklebust goto out;
7076b03d735bSChuck Lever if (res->migration) {
7077b03d735bSChuck Lever xdr_enter_page(xdr, PAGE_SIZE);
7078b03d735bSChuck Lever status = decode_getfattr_generic(xdr,
7079c3ed2227SBenjamin Coddington res->fs_locations->fattr,
7080b03d735bSChuck Lever NULL, res->fs_locations,
70811e2f67daSAnna Schumaker res->fs_locations->server);
7082b03d735bSChuck Lever if (status)
7083b03d735bSChuck Lever goto out;
7084b03d735bSChuck Lever if (res->renew)
7085b03d735bSChuck Lever status = decode_renew(xdr);
7086b03d735bSChuck Lever } else {
7087bf269551SChuck Lever status = decode_lookup(xdr);
7088bf269551SChuck Lever if (status)
7089683b57b4STrond Myklebust goto out;
7090bf269551SChuck Lever xdr_enter_page(xdr, PAGE_SIZE);
7091b03d735bSChuck Lever status = decode_getfattr_generic(xdr,
7092c3ed2227SBenjamin Coddington res->fs_locations->fattr,
70938b7e3f49STrond Myklebust NULL, res->fs_locations,
70941e2f67daSAnna Schumaker res->fs_locations->server);
7095b03d735bSChuck Lever }
7096683b57b4STrond Myklebust out:
7097683b57b4STrond Myklebust return status;
7098683b57b4STrond Myklebust }
7099683b57b4STrond Myklebust
71005a5ea0d4SBryan Schumaker /*
71015a5ea0d4SBryan Schumaker * Decode SECINFO response
71025a5ea0d4SBryan Schumaker */
nfs4_xdr_dec_secinfo(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)71035a5ea0d4SBryan Schumaker static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
71045a5ea0d4SBryan Schumaker struct xdr_stream *xdr,
7105fc016483SChristoph Hellwig void *data)
71065a5ea0d4SBryan Schumaker {
7107fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data;
71085a5ea0d4SBryan Schumaker struct compound_hdr hdr;
71095a5ea0d4SBryan Schumaker int status;
71105a5ea0d4SBryan Schumaker
71115a5ea0d4SBryan Schumaker status = decode_compound_hdr(xdr, &hdr);
71125a5ea0d4SBryan Schumaker if (status)
71135a5ea0d4SBryan Schumaker goto out;
71145a5ea0d4SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp);
71155a5ea0d4SBryan Schumaker if (status)
71165a5ea0d4SBryan Schumaker goto out;
71175a5ea0d4SBryan Schumaker status = decode_putfh(xdr);
71185a5ea0d4SBryan Schumaker if (status)
71195a5ea0d4SBryan Schumaker goto out;
71205a5ea0d4SBryan Schumaker status = decode_secinfo(xdr, res);
71215a5ea0d4SBryan Schumaker out:
71225a5ea0d4SBryan Schumaker return status;
71235a5ea0d4SBryan Schumaker }
71245a5ea0d4SBryan Schumaker
712544c99933SChuck Lever /*
712644c99933SChuck Lever * Decode FSID_PRESENT response
712744c99933SChuck Lever */
nfs4_xdr_dec_fsid_present(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)712844c99933SChuck Lever static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
712944c99933SChuck Lever struct xdr_stream *xdr,
7130fc016483SChristoph Hellwig void *data)
713144c99933SChuck Lever {
7132fc016483SChristoph Hellwig struct nfs4_fsid_present_res *res = data;
713344c99933SChuck Lever struct compound_hdr hdr;
713444c99933SChuck Lever int status;
713544c99933SChuck Lever
713644c99933SChuck Lever status = decode_compound_hdr(xdr, &hdr);
713744c99933SChuck Lever if (status)
713844c99933SChuck Lever goto out;
713944c99933SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
714044c99933SChuck Lever if (status)
714144c99933SChuck Lever goto out;
714244c99933SChuck Lever status = decode_putfh(xdr);
714344c99933SChuck Lever if (status)
714444c99933SChuck Lever goto out;
714544c99933SChuck Lever status = decode_getfh(xdr, res->fh);
714644c99933SChuck Lever if (status)
714744c99933SChuck Lever goto out;
714844c99933SChuck Lever if (res->renew)
714944c99933SChuck Lever status = decode_renew(xdr);
715044c99933SChuck Lever out:
715144c99933SChuck Lever return status;
715244c99933SChuck Lever }
715344c99933SChuck Lever
715499fe60d0SBenny Halevy #if defined(CONFIG_NFS_V4_1)
715599fe60d0SBenny Halevy /*
71567c44f1aeSWeston Andros Adamson * Decode BIND_CONN_TO_SESSION response
71577c44f1aeSWeston Andros Adamson */
nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * res)71587c44f1aeSWeston Andros Adamson static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
71597c44f1aeSWeston Andros Adamson struct xdr_stream *xdr,
71607c44f1aeSWeston Andros Adamson void *res)
71617c44f1aeSWeston Andros Adamson {
71627c44f1aeSWeston Andros Adamson struct compound_hdr hdr;
71637c44f1aeSWeston Andros Adamson int status;
71647c44f1aeSWeston Andros Adamson
71657c44f1aeSWeston Andros Adamson status = decode_compound_hdr(xdr, &hdr);
71667c44f1aeSWeston Andros Adamson if (!status)
71677c44f1aeSWeston Andros Adamson status = decode_bind_conn_to_session(xdr, res);
71687c44f1aeSWeston Andros Adamson return status;
71697c44f1aeSWeston Andros Adamson }
71707c44f1aeSWeston Andros Adamson
71717c44f1aeSWeston Andros Adamson /*
71728b173218SRicardo Labiaga * Decode EXCHANGE_ID response
717399fe60d0SBenny Halevy */
nfs4_xdr_dec_exchange_id(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * res)7174bf269551SChuck Lever static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7175bf269551SChuck Lever struct xdr_stream *xdr,
717699fe60d0SBenny Halevy void *res)
717799fe60d0SBenny Halevy {
717899fe60d0SBenny Halevy struct compound_hdr hdr;
717999fe60d0SBenny Halevy int status;
718099fe60d0SBenny Halevy
7181bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
718299fe60d0SBenny Halevy if (!status)
7183bf269551SChuck Lever status = decode_exchange_id(xdr, res);
718499fe60d0SBenny Halevy return status;
718599fe60d0SBenny Halevy }
71862050f0ccSAndy Adamson
71872050f0ccSAndy Adamson /*
71888b173218SRicardo Labiaga * Decode CREATE_SESSION response
7189fc931582SAndy Adamson */
nfs4_xdr_dec_create_session(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * res)7190bf269551SChuck Lever static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7191bf269551SChuck Lever struct xdr_stream *xdr,
7192fc016483SChristoph Hellwig void *res)
7193fc931582SAndy Adamson {
7194fc931582SAndy Adamson struct compound_hdr hdr;
7195fc931582SAndy Adamson int status;
7196fc931582SAndy Adamson
7197bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
7198fc931582SAndy Adamson if (!status)
7199bf269551SChuck Lever status = decode_create_session(xdr, res);
7200fc931582SAndy Adamson return status;
7201fc931582SAndy Adamson }
7202fc931582SAndy Adamson
7203fc931582SAndy Adamson /*
72048b173218SRicardo Labiaga * Decode DESTROY_SESSION response
72050f3e66c6SAndy Adamson */
nfs4_xdr_dec_destroy_session(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * res)7206bf269551SChuck Lever static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7207bf269551SChuck Lever struct xdr_stream *xdr,
7208bf269551SChuck Lever void *res)
72090f3e66c6SAndy Adamson {
72100f3e66c6SAndy Adamson struct compound_hdr hdr;
72110f3e66c6SAndy Adamson int status;
72120f3e66c6SAndy Adamson
7213bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
72140f3e66c6SAndy Adamson if (!status)
7215bf269551SChuck Lever status = decode_destroy_session(xdr, res);
72160f3e66c6SAndy Adamson return status;
72170f3e66c6SAndy Adamson }
72180f3e66c6SAndy Adamson
72190f3e66c6SAndy Adamson /*
722066245539STrond Myklebust * Decode DESTROY_CLIENTID response
722166245539STrond Myklebust */
nfs4_xdr_dec_destroy_clientid(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * res)722266245539STrond Myklebust static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
722366245539STrond Myklebust struct xdr_stream *xdr,
722466245539STrond Myklebust void *res)
722566245539STrond Myklebust {
722666245539STrond Myklebust struct compound_hdr hdr;
722766245539STrond Myklebust int status;
722866245539STrond Myklebust
722966245539STrond Myklebust status = decode_compound_hdr(xdr, &hdr);
723066245539STrond Myklebust if (!status)
723166245539STrond Myklebust status = decode_destroy_clientid(xdr, res);
723266245539STrond Myklebust return status;
723366245539STrond Myklebust }
723466245539STrond Myklebust
723566245539STrond Myklebust /*
72368b173218SRicardo Labiaga * Decode SEQUENCE response
7237fc01cea9SAndy Adamson */
nfs4_xdr_dec_sequence(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * res)7238bf269551SChuck Lever static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7239bf269551SChuck Lever struct xdr_stream *xdr,
7240fc016483SChristoph Hellwig void *res)
7241fc01cea9SAndy Adamson {
7242fc01cea9SAndy Adamson struct compound_hdr hdr;
7243fc01cea9SAndy Adamson int status;
7244fc01cea9SAndy Adamson
7245bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
7246fc01cea9SAndy Adamson if (!status)
7247bf269551SChuck Lever status = decode_sequence(xdr, res, rqstp);
7248fc01cea9SAndy Adamson return status;
7249fc01cea9SAndy Adamson }
7250fc01cea9SAndy Adamson
72510efb01b2SDonald Buczek #endif
72520efb01b2SDonald Buczek
7253fc01cea9SAndy Adamson /*
72548b173218SRicardo Labiaga * Decode GET_LEASE_TIME response
72552050f0ccSAndy Adamson */
nfs4_xdr_dec_get_lease_time(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7256bf269551SChuck Lever static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7257bf269551SChuck Lever struct xdr_stream *xdr,
7258fc016483SChristoph Hellwig void *data)
72592050f0ccSAndy Adamson {
7260fc016483SChristoph Hellwig struct nfs4_get_lease_time_res *res = data;
72612050f0ccSAndy Adamson struct compound_hdr hdr;
72622050f0ccSAndy Adamson int status;
72632050f0ccSAndy Adamson
7264bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
72652050f0ccSAndy Adamson if (!status)
7266bf269551SChuck Lever status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
72672050f0ccSAndy Adamson if (!status)
7268bf269551SChuck Lever status = decode_putrootfh(xdr);
72692050f0ccSAndy Adamson if (!status)
7270bf269551SChuck Lever status = decode_fsinfo(xdr, res->lr_fsinfo);
72712050f0ccSAndy Adamson return status;
72722050f0ccSAndy Adamson }
727318019753SRicardo Labiaga
72740efb01b2SDonald Buczek #ifdef CONFIG_NFS_V4_1
72750efb01b2SDonald Buczek
727618019753SRicardo Labiaga /*
727718019753SRicardo Labiaga * Decode RECLAIM_COMPLETE response
727818019753SRicardo Labiaga */
nfs4_xdr_dec_reclaim_complete(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7279bf269551SChuck Lever static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7280bf269551SChuck Lever struct xdr_stream *xdr,
7281fc016483SChristoph Hellwig void *data)
728218019753SRicardo Labiaga {
7283fc016483SChristoph Hellwig struct nfs41_reclaim_complete_res *res = data;
728418019753SRicardo Labiaga struct compound_hdr hdr;
728518019753SRicardo Labiaga int status;
728618019753SRicardo Labiaga
7287bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
728818019753SRicardo Labiaga if (!status)
7289bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
729018019753SRicardo Labiaga if (!status)
72918ee2b78aSHimangi Saraogi status = decode_reclaim_complete(xdr, NULL);
729218019753SRicardo Labiaga return status;
729318019753SRicardo Labiaga }
7294b1f69b75SAndy Adamson
7295b1f69b75SAndy Adamson /*
7296b1f69b75SAndy Adamson * Decode GETDEVINFO response
7297b1f69b75SAndy Adamson */
nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7298bf269551SChuck Lever static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7299bf269551SChuck Lever struct xdr_stream *xdr,
7300fc016483SChristoph Hellwig void *data)
7301b1f69b75SAndy Adamson {
7302fc016483SChristoph Hellwig struct nfs4_getdeviceinfo_res *res = data;
7303b1f69b75SAndy Adamson struct compound_hdr hdr;
7304b1f69b75SAndy Adamson int status;
7305b1f69b75SAndy Adamson
7306bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
7307b1f69b75SAndy Adamson if (status != 0)
7308b1f69b75SAndy Adamson goto out;
7309bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
7310b1f69b75SAndy Adamson if (status != 0)
7311b1f69b75SAndy Adamson goto out;
73124e590803STrond Myklebust status = decode_getdeviceinfo(xdr, res);
7313b1f69b75SAndy Adamson out:
7314b1f69b75SAndy Adamson return status;
7315b1f69b75SAndy Adamson }
7316b1f69b75SAndy Adamson
7317b1f69b75SAndy Adamson /*
7318b1f69b75SAndy Adamson * Decode LAYOUTGET response
7319b1f69b75SAndy Adamson */
nfs4_xdr_dec_layoutget(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7320bf269551SChuck Lever static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7321bf269551SChuck Lever struct xdr_stream *xdr,
7322fc016483SChristoph Hellwig void *data)
7323b1f69b75SAndy Adamson {
7324fc016483SChristoph Hellwig struct nfs4_layoutget_res *res = data;
7325b1f69b75SAndy Adamson struct compound_hdr hdr;
7326b1f69b75SAndy Adamson int status;
7327b1f69b75SAndy Adamson
7328bf269551SChuck Lever status = decode_compound_hdr(xdr, &hdr);
7329b1f69b75SAndy Adamson if (status)
7330b1f69b75SAndy Adamson goto out;
7331bf269551SChuck Lever status = decode_sequence(xdr, &res->seq_res, rqstp);
7332b1f69b75SAndy Adamson if (status)
7333b1f69b75SAndy Adamson goto out;
7334bf269551SChuck Lever status = decode_putfh(xdr);
7335b1f69b75SAndy Adamson if (status)
7336b1f69b75SAndy Adamson goto out;
7337bf269551SChuck Lever status = decode_layoutget(xdr, rqstp, res);
7338b1f69b75SAndy Adamson out:
7339b1f69b75SAndy Adamson return status;
7340b1f69b75SAndy Adamson }
7341863a3c6cSAndy Adamson
7342863a3c6cSAndy Adamson /*
7343cbe82603SBenny Halevy * Decode LAYOUTRETURN response
7344cbe82603SBenny Halevy */
nfs4_xdr_dec_layoutreturn(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7345cbe82603SBenny Halevy static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7346cbe82603SBenny Halevy struct xdr_stream *xdr,
7347fc016483SChristoph Hellwig void *data)
7348cbe82603SBenny Halevy {
7349fc016483SChristoph Hellwig struct nfs4_layoutreturn_res *res = data;
7350cbe82603SBenny Halevy struct compound_hdr hdr;
7351cbe82603SBenny Halevy int status;
7352cbe82603SBenny Halevy
7353cbe82603SBenny Halevy status = decode_compound_hdr(xdr, &hdr);
7354cbe82603SBenny Halevy if (status)
7355cbe82603SBenny Halevy goto out;
7356cbe82603SBenny Halevy status = decode_sequence(xdr, &res->seq_res, rqstp);
7357cbe82603SBenny Halevy if (status)
7358cbe82603SBenny Halevy goto out;
7359cbe82603SBenny Halevy status = decode_putfh(xdr);
7360cbe82603SBenny Halevy if (status)
7361cbe82603SBenny Halevy goto out;
7362cbe82603SBenny Halevy status = decode_layoutreturn(xdr, res);
7363cbe82603SBenny Halevy out:
7364cbe82603SBenny Halevy return status;
7365cbe82603SBenny Halevy }
7366cbe82603SBenny Halevy
7367cbe82603SBenny Halevy /*
7368863a3c6cSAndy Adamson * Decode LAYOUTCOMMIT response
7369863a3c6cSAndy Adamson */
nfs4_xdr_dec_layoutcommit(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7370863a3c6cSAndy Adamson static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7371863a3c6cSAndy Adamson struct xdr_stream *xdr,
7372fc016483SChristoph Hellwig void *data)
7373863a3c6cSAndy Adamson {
7374fc016483SChristoph Hellwig struct nfs4_layoutcommit_res *res = data;
7375863a3c6cSAndy Adamson struct compound_hdr hdr;
7376863a3c6cSAndy Adamson int status;
7377863a3c6cSAndy Adamson
7378863a3c6cSAndy Adamson status = decode_compound_hdr(xdr, &hdr);
7379863a3c6cSAndy Adamson if (status)
7380863a3c6cSAndy Adamson goto out;
7381863a3c6cSAndy Adamson status = decode_sequence(xdr, &res->seq_res, rqstp);
7382863a3c6cSAndy Adamson if (status)
7383863a3c6cSAndy Adamson goto out;
7384863a3c6cSAndy Adamson status = decode_putfh(xdr);
7385863a3c6cSAndy Adamson if (status)
7386863a3c6cSAndy Adamson goto out;
7387863a3c6cSAndy Adamson status = decode_layoutcommit(xdr, rqstp, res);
7388863a3c6cSAndy Adamson if (status)
7389863a3c6cSAndy Adamson goto out;
73906926afd1STrond Myklebust decode_getfattr(xdr, res->fattr, res->server);
7391863a3c6cSAndy Adamson out:
7392863a3c6cSAndy Adamson return status;
7393863a3c6cSAndy Adamson }
7394fca78d6dSBryan Schumaker
7395fca78d6dSBryan Schumaker /*
7396fca78d6dSBryan Schumaker * Decode SECINFO_NO_NAME response
7397fca78d6dSBryan Schumaker */
nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)7398fca78d6dSBryan Schumaker static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7399fca78d6dSBryan Schumaker struct xdr_stream *xdr,
7400fc016483SChristoph Hellwig void *data)
7401fca78d6dSBryan Schumaker {
7402fc016483SChristoph Hellwig struct nfs4_secinfo_res *res = data;
7403fca78d6dSBryan Schumaker struct compound_hdr hdr;
7404fca78d6dSBryan Schumaker int status;
7405fca78d6dSBryan Schumaker
7406fca78d6dSBryan Schumaker status = decode_compound_hdr(xdr, &hdr);
7407fca78d6dSBryan Schumaker if (status)
7408fca78d6dSBryan Schumaker goto out;
7409fca78d6dSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp);
7410fca78d6dSBryan Schumaker if (status)
7411fca78d6dSBryan Schumaker goto out;
7412fca78d6dSBryan Schumaker status = decode_putrootfh(xdr);
7413fca78d6dSBryan Schumaker if (status)
7414fca78d6dSBryan Schumaker goto out;
741531e4dda4SBryan Schumaker status = decode_secinfo_no_name(xdr, res);
7416fca78d6dSBryan Schumaker out:
7417fca78d6dSBryan Schumaker return status;
7418fca78d6dSBryan Schumaker }
74197d974794SBryan Schumaker
74207d974794SBryan Schumaker /*
74217d974794SBryan Schumaker * Decode TEST_STATEID response
74227d974794SBryan Schumaker */
nfs4_xdr_dec_test_stateid(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)74237d974794SBryan Schumaker static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
74247d974794SBryan Schumaker struct xdr_stream *xdr,
7425fc016483SChristoph Hellwig void *data)
74267d974794SBryan Schumaker {
7427fc016483SChristoph Hellwig struct nfs41_test_stateid_res *res = data;
74287d974794SBryan Schumaker struct compound_hdr hdr;
74297d974794SBryan Schumaker int status;
74307d974794SBryan Schumaker
74317d974794SBryan Schumaker status = decode_compound_hdr(xdr, &hdr);
74327d974794SBryan Schumaker if (status)
74337d974794SBryan Schumaker goto out;
74347d974794SBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp);
74357d974794SBryan Schumaker if (status)
74367d974794SBryan Schumaker goto out;
74377d974794SBryan Schumaker status = decode_test_stateid(xdr, res);
74387d974794SBryan Schumaker out:
74397d974794SBryan Schumaker return status;
74407d974794SBryan Schumaker }
74419aeda35fSBryan Schumaker
74429aeda35fSBryan Schumaker /*
74439aeda35fSBryan Schumaker * Decode FREE_STATEID response
74449aeda35fSBryan Schumaker */
nfs4_xdr_dec_free_stateid(struct rpc_rqst * rqstp,struct xdr_stream * xdr,void * data)74459aeda35fSBryan Schumaker static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
74469aeda35fSBryan Schumaker struct xdr_stream *xdr,
7447fc016483SChristoph Hellwig void *data)
74489aeda35fSBryan Schumaker {
7449fc016483SChristoph Hellwig struct nfs41_free_stateid_res *res = data;
74509aeda35fSBryan Schumaker struct compound_hdr hdr;
74519aeda35fSBryan Schumaker int status;
74529aeda35fSBryan Schumaker
74539aeda35fSBryan Schumaker status = decode_compound_hdr(xdr, &hdr);
74549aeda35fSBryan Schumaker if (status)
74559aeda35fSBryan Schumaker goto out;
74569aeda35fSBryan Schumaker status = decode_sequence(xdr, &res->seq_res, rqstp);
74579aeda35fSBryan Schumaker if (status)
74589aeda35fSBryan Schumaker goto out;
74599aeda35fSBryan Schumaker status = decode_free_stateid(xdr, res);
74609aeda35fSBryan Schumaker out:
74619aeda35fSBryan Schumaker return status;
74629aeda35fSBryan Schumaker }
746399fe60d0SBenny Halevy #endif /* CONFIG_NFS_V4_1 */
746499fe60d0SBenny Halevy
7465573c4e1eSChuck Lever /**
7466573c4e1eSChuck Lever * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7467573c4e1eSChuck Lever * the local page cache.
7468573c4e1eSChuck Lever * @xdr: XDR stream where entry resides
7469573c4e1eSChuck Lever * @entry: buffer to fill in with entry data
7470573c4e1eSChuck Lever * @plus: boolean indicating whether this should be a readdirplus entry
7471573c4e1eSChuck Lever *
7472573c4e1eSChuck Lever * Returns zero if successful, otherwise a negative errno value is
7473573c4e1eSChuck Lever * returned.
7474573c4e1eSChuck Lever *
7475573c4e1eSChuck Lever * This function is not invoked during READDIR reply decoding, but
7476573c4e1eSChuck Lever * rather whenever an application invokes the getdents(2) system call
7477573c4e1eSChuck Lever * on a directory already in our cache.
7478573c4e1eSChuck Lever */
nfs4_decode_dirent(struct xdr_stream * xdr,struct nfs_entry * entry,bool plus)7479573c4e1eSChuck Lever int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7480a7a3b1e9SBenjamin Coddington bool plus)
74811da177e4SLinus Torvalds {
7482256e48bbSTrond Myklebust unsigned int savep;
7483dae100c2SFred Isaman uint32_t bitmap[3] = {0};
74841da177e4SLinus Torvalds uint32_t len;
748598de9ce6SFrank Sorenson uint64_t new_cookie;
7486babddc72SBryan Schumaker __be32 *p = xdr_inline_decode(xdr, 4);
7487babddc72SBryan Schumaker if (unlikely(!p))
7488eb72f484SChuck Lever return -EAGAIN;
7489c08e76d0SChuck Lever if (*p == xdr_zero) {
7490babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 4);
7491babddc72SBryan Schumaker if (unlikely(!p))
7492eb72f484SChuck Lever return -EAGAIN;
7493c08e76d0SChuck Lever if (*p == xdr_zero)
7494573c4e1eSChuck Lever return -EAGAIN;
74951da177e4SLinus Torvalds entry->eof = 1;
7496573c4e1eSChuck Lever return -EBADCOOKIE;
74971da177e4SLinus Torvalds }
74981da177e4SLinus Torvalds
7499babddc72SBryan Schumaker p = xdr_inline_decode(xdr, 12);
7500babddc72SBryan Schumaker if (unlikely(!p))
7501eb72f484SChuck Lever return -EAGAIN;
750298de9ce6SFrank Sorenson p = xdr_decode_hyper(p, &new_cookie);
7503c08e76d0SChuck Lever entry->len = be32_to_cpup(p);
7504babddc72SBryan Schumaker
75059af8c222STrond Myklebust p = xdr_inline_decode(xdr, entry->len);
7506babddc72SBryan Schumaker if (unlikely(!p))
7507eb72f484SChuck Lever return -EAGAIN;
75081da177e4SLinus Torvalds entry->name = (const char *) p;
75091da177e4SLinus Torvalds
75101da177e4SLinus Torvalds /*
75111da177e4SLinus Torvalds * In case the server doesn't return an inode number,
75121da177e4SLinus Torvalds * we fake one here. (We don't use inode number 0,
75131da177e4SLinus Torvalds * since glibc seems to choke on it...)
75141da177e4SLinus Torvalds */
75151da177e4SLinus Torvalds entry->ino = 1;
75164f082222STrond Myklebust entry->fattr->valid = 0;
75171da177e4SLinus Torvalds
75189af8c222STrond Myklebust if (decode_attr_bitmap(xdr, bitmap) < 0)
7519eb72f484SChuck Lever return -EAGAIN;
75209af8c222STrond Myklebust
7521256e48bbSTrond Myklebust if (decode_attr_length(xdr, &len, &savep) < 0)
7522eb72f484SChuck Lever return -EAGAIN;
75239af8c222STrond Myklebust
7524573c4e1eSChuck Lever if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
75251e2f67daSAnna Schumaker NULL, entry->server) < 0)
7526eb72f484SChuck Lever return -EAGAIN;
752728331a46STrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
752828331a46STrond Myklebust entry->ino = entry->fattr->mounted_on_fileid;
752928331a46STrond Myklebust else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
753082f2e547SBryan Schumaker entry->ino = entry->fattr->fileid;
75319af8c222STrond Myklebust
75320b26a0bfSTrond Myklebust entry->d_type = DT_UNKNOWN;
75330b26a0bfSTrond Myklebust if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
75340b26a0bfSTrond Myklebust entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
75350b26a0bfSTrond Myklebust
753698de9ce6SFrank Sorenson entry->cookie = new_cookie;
753798de9ce6SFrank Sorenson
7538573c4e1eSChuck Lever return 0;
75391da177e4SLinus Torvalds }
75401da177e4SLinus Torvalds
75411da177e4SLinus Torvalds /*
75421da177e4SLinus Torvalds * We need to translate between nfs status return values and
75431da177e4SLinus Torvalds * the local errno values which may not be the same.
75441da177e4SLinus Torvalds */
75451da177e4SLinus Torvalds static struct {
75461da177e4SLinus Torvalds int stat;
75471da177e4SLinus Torvalds int errno;
75481da177e4SLinus Torvalds } nfs_errtbl[] = {
75491da177e4SLinus Torvalds { NFS4_OK, 0 },
7550856dff3dSBenny Halevy { NFS4ERR_PERM, -EPERM },
7551856dff3dSBenny Halevy { NFS4ERR_NOENT, -ENOENT },
7552856dff3dSBenny Halevy { NFS4ERR_IO, -errno_NFSERR_IO},
7553856dff3dSBenny Halevy { NFS4ERR_NXIO, -ENXIO },
7554856dff3dSBenny Halevy { NFS4ERR_ACCESS, -EACCES },
7555856dff3dSBenny Halevy { NFS4ERR_EXIST, -EEXIST },
7556856dff3dSBenny Halevy { NFS4ERR_XDEV, -EXDEV },
7557856dff3dSBenny Halevy { NFS4ERR_NOTDIR, -ENOTDIR },
7558856dff3dSBenny Halevy { NFS4ERR_ISDIR, -EISDIR },
7559856dff3dSBenny Halevy { NFS4ERR_INVAL, -EINVAL },
7560856dff3dSBenny Halevy { NFS4ERR_FBIG, -EFBIG },
7561856dff3dSBenny Halevy { NFS4ERR_NOSPC, -ENOSPC },
7562856dff3dSBenny Halevy { NFS4ERR_ROFS, -EROFS },
7563856dff3dSBenny Halevy { NFS4ERR_MLINK, -EMLINK },
7564856dff3dSBenny Halevy { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7565856dff3dSBenny Halevy { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7566856dff3dSBenny Halevy { NFS4ERR_DQUOT, -EDQUOT },
7567856dff3dSBenny Halevy { NFS4ERR_STALE, -ESTALE },
7568856dff3dSBenny Halevy { NFS4ERR_BADHANDLE, -EBADHANDLE },
7569856dff3dSBenny Halevy { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7570856dff3dSBenny Halevy { NFS4ERR_NOTSUPP, -ENOTSUPP },
7571856dff3dSBenny Halevy { NFS4ERR_TOOSMALL, -ETOOSMALL },
7572fdcb4577STrond Myklebust { NFS4ERR_SERVERFAULT, -EREMOTEIO },
7573856dff3dSBenny Halevy { NFS4ERR_BADTYPE, -EBADTYPE },
7574856dff3dSBenny Halevy { NFS4ERR_LOCKED, -EAGAIN },
7575856dff3dSBenny Halevy { NFS4ERR_SYMLINK, -ELOOP },
7576856dff3dSBenny Halevy { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7577856dff3dSBenny Halevy { NFS4ERR_DEADLOCK, -EDEADLK },
75783e1f0212SFrank van der Linden { NFS4ERR_NOXATTR, -ENODATA },
75793e1f0212SFrank van der Linden { NFS4ERR_XATTR2BIG, -E2BIG },
7580856dff3dSBenny Halevy { -1, -EIO }
75811da177e4SLinus Torvalds };
75821da177e4SLinus Torvalds
75831da177e4SLinus Torvalds /*
75841da177e4SLinus Torvalds * Convert an NFS error code to a local one.
75851da177e4SLinus Torvalds * This one is used jointly by NFSv2 and NFSv3.
75861da177e4SLinus Torvalds */
75871da177e4SLinus Torvalds static int
nfs4_stat_to_errno(int stat)75880a8ea437SDavid Howells nfs4_stat_to_errno(int stat)
75891da177e4SLinus Torvalds {
75901da177e4SLinus Torvalds int i;
75911da177e4SLinus Torvalds for (i = 0; nfs_errtbl[i].stat != -1; i++) {
75921da177e4SLinus Torvalds if (nfs_errtbl[i].stat == stat)
75931da177e4SLinus Torvalds return nfs_errtbl[i].errno;
75941da177e4SLinus Torvalds }
75951da177e4SLinus Torvalds if (stat <= 10000 || stat > 10100) {
75961da177e4SLinus Torvalds /* The server is looney tunes. */
7597fdcb4577STrond Myklebust return -EREMOTEIO;
75981da177e4SLinus Torvalds }
75991da177e4SLinus Torvalds /* If we cannot translate the error, the recovery routines should
76001da177e4SLinus Torvalds * handle it.
76011da177e4SLinus Torvalds * Note: remaining NFSv4 error codes have values > 10000, so should
76021da177e4SLinus Torvalds * not conflict with native Linux error codes.
76031da177e4SLinus Torvalds */
7604856dff3dSBenny Halevy return -stat;
76051da177e4SLinus Torvalds }
76061da177e4SLinus Torvalds
76071c6dcbe5SAnna Schumaker #ifdef CONFIG_NFS_V4_2
76081c6dcbe5SAnna Schumaker #include "nfs42xdr.c"
76091c6dcbe5SAnna Schumaker #endif /* CONFIG_NFS_V4_2 */
76101c6dcbe5SAnna Schumaker
76111da177e4SLinus Torvalds #define PROC(proc, argtype, restype) \
76121da177e4SLinus Torvalds [NFSPROC4_CLNT_##proc] = { \
76131da177e4SLinus Torvalds .p_proc = NFSPROC4_COMPOUND, \
7614fcc85819SChristoph Hellwig .p_encode = nfs4_xdr_##argtype, \
7615fc016483SChristoph Hellwig .p_decode = nfs4_xdr_##restype, \
76162bea90d4SChuck Lever .p_arglen = NFS4_##argtype##_sz, \
76172bea90d4SChuck Lever .p_replen = NFS4_##restype##_sz, \
7618cc0175c1SChuck Lever .p_statidx = NFSPROC4_CLNT_##proc, \
7619cc0175c1SChuck Lever .p_name = #proc, \
76201da177e4SLinus Torvalds }
76211da177e4SLinus Torvalds
76227c61f0d3SAnna Schumaker #define STUB(proc) \
76237c61f0d3SAnna Schumaker [NFSPROC4_CLNT_##proc] = { \
76247c61f0d3SAnna Schumaker .p_name = #proc, \
76257c61f0d3SAnna Schumaker }
76267c61f0d3SAnna Schumaker
76278634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_1)
76288634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \
76298634ef5eSTrond Myklebust PROC(proc, argtype, restype)
76308634ef5eSTrond Myklebust #else
76318634ef5eSTrond Myklebust #define PROC41(proc, argtype, restype) \
76328634ef5eSTrond Myklebust STUB(proc)
76338634ef5eSTrond Myklebust #endif
76348634ef5eSTrond Myklebust
76358634ef5eSTrond Myklebust #if defined(CONFIG_NFS_V4_2)
76368634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \
76378634ef5eSTrond Myklebust PROC(proc, argtype, restype)
76388634ef5eSTrond Myklebust #else
76398634ef5eSTrond Myklebust #define PROC42(proc, argtype, restype) \
76408634ef5eSTrond Myklebust STUB(proc)
76418634ef5eSTrond Myklebust #endif
76428634ef5eSTrond Myklebust
7643511e936bSChristoph Hellwig const struct rpc_procinfo nfs4_procedures[] = {
76441da177e4SLinus Torvalds PROC(READ, enc_read, dec_read),
76451da177e4SLinus Torvalds PROC(WRITE, enc_write, dec_write),
76461da177e4SLinus Torvalds PROC(COMMIT, enc_commit, dec_commit),
76471da177e4SLinus Torvalds PROC(OPEN, enc_open, dec_open),
76481da177e4SLinus Torvalds PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
76491da177e4SLinus Torvalds PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
76501da177e4SLinus Torvalds PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
76511da177e4SLinus Torvalds PROC(CLOSE, enc_close, dec_close),
76521da177e4SLinus Torvalds PROC(SETATTR, enc_setattr, dec_setattr),
76531da177e4SLinus Torvalds PROC(FSINFO, enc_fsinfo, dec_fsinfo),
76541da177e4SLinus Torvalds PROC(RENEW, enc_renew, dec_renew),
76551da177e4SLinus Torvalds PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
76561da177e4SLinus Torvalds PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
76571da177e4SLinus Torvalds PROC(LOCK, enc_lock, dec_lock),
76581da177e4SLinus Torvalds PROC(LOCKT, enc_lockt, dec_lockt),
76591da177e4SLinus Torvalds PROC(LOCKU, enc_locku, dec_locku),
76601da177e4SLinus Torvalds PROC(ACCESS, enc_access, dec_access),
76611da177e4SLinus Torvalds PROC(GETATTR, enc_getattr, dec_getattr),
76621da177e4SLinus Torvalds PROC(LOOKUP, enc_lookup, dec_lookup),
76631da177e4SLinus Torvalds PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
76641da177e4SLinus Torvalds PROC(REMOVE, enc_remove, dec_remove),
76651da177e4SLinus Torvalds PROC(RENAME, enc_rename, dec_rename),
76661da177e4SLinus Torvalds PROC(LINK, enc_link, dec_link),
76671da177e4SLinus Torvalds PROC(SYMLINK, enc_symlink, dec_symlink),
76681da177e4SLinus Torvalds PROC(CREATE, enc_create, dec_create),
76691da177e4SLinus Torvalds PROC(PATHCONF, enc_pathconf, dec_pathconf),
76701da177e4SLinus Torvalds PROC(STATFS, enc_statfs, dec_statfs),
76711da177e4SLinus Torvalds PROC(READLINK, enc_readlink, dec_readlink),
76721da177e4SLinus Torvalds PROC(READDIR, enc_readdir, dec_readdir),
76731da177e4SLinus Torvalds PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
76741da177e4SLinus Torvalds PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7675029d105eSJ. Bruce Fields PROC(GETACL, enc_getacl, dec_getacl),
767623ec6965SJ. Bruce Fields PROC(SETACL, enc_setacl, dec_setacl),
7677683b57b4STrond Myklebust PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7678d3c7b7ccSTrond Myklebust PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
76795a5ea0d4SBryan Schumaker PROC(SECINFO, enc_secinfo, dec_secinfo),
768044c99933SChuck Lever PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
76818634ef5eSTrond Myklebust PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
76828634ef5eSTrond Myklebust PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
76838634ef5eSTrond Myklebust PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
76848634ef5eSTrond Myklebust PROC41(SEQUENCE, enc_sequence, dec_sequence),
76850efb01b2SDonald Buczek PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
76868634ef5eSTrond Myklebust PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
76878634ef5eSTrond Myklebust PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
76888634ef5eSTrond Myklebust PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
76898634ef5eSTrond Myklebust PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
76908634ef5eSTrond Myklebust PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
76918634ef5eSTrond Myklebust PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
76928634ef5eSTrond Myklebust PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
76938634ef5eSTrond Myklebust PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
76947c61f0d3SAnna Schumaker STUB(GETDEVICELIST),
76958634ef5eSTrond Myklebust PROC41(BIND_CONN_TO_SESSION,
7696ad24ecfbSTrond Myklebust enc_bind_conn_to_session, dec_bind_conn_to_session),
76978634ef5eSTrond Myklebust PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
76988634ef5eSTrond Myklebust PROC42(SEEK, enc_seek, dec_seek),
76998634ef5eSTrond Myklebust PROC42(ALLOCATE, enc_allocate, dec_allocate),
77008634ef5eSTrond Myklebust PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
77018634ef5eSTrond Myklebust PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
77028634ef5eSTrond Myklebust PROC42(CLONE, enc_clone, dec_clone),
77038634ef5eSTrond Myklebust PROC42(COPY, enc_copy, dec_copy),
7704cb95deeaSOlga Kornievskaia PROC42(OFFLOAD_CANCEL, enc_offload_cancel, dec_offload_cancel),
77050491567bSOlga Kornievskaia PROC42(COPY_NOTIFY, enc_copy_notify, dec_copy_notify),
77068634ef5eSTrond Myklebust PROC(LOOKUPP, enc_lookupp, dec_lookupp),
77073eb86093STrond Myklebust PROC42(LAYOUTERROR, enc_layouterror, dec_layouterror),
77083e1f0212SFrank van der Linden PROC42(GETXATTR, enc_getxattr, dec_getxattr),
77093e1f0212SFrank van der Linden PROC42(SETXATTR, enc_setxattr, dec_setxattr),
77103e1f0212SFrank van der Linden PROC42(LISTXATTRS, enc_listxattrs, dec_listxattrs),
77113e1f0212SFrank van der Linden PROC42(REMOVEXATTR, enc_removexattr, dec_removexattr),
7712c5675526SAnna Schumaker PROC42(READ_PLUS, enc_read_plus, dec_read_plus),
77131da177e4SLinus Torvalds };
77141da177e4SLinus Torvalds
7715c551858aSChristoph Hellwig static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
7716a613fa16STrond Myklebust const struct rpc_version nfs_version4 = {
77171da177e4SLinus Torvalds .number = 4,
7718e8c96f8cSTobias Klauser .nrprocs = ARRAY_SIZE(nfs4_procedures),
7719c551858aSChristoph Hellwig .procs = nfs4_procedures,
7720c551858aSChristoph Hellwig .counts = nfs_version4_counts,
77211da177e4SLinus Torvalds };
7722