blob: 738a7be019d2f696737ba6ccd46d04e996644c22 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
Chuck Leverf0920752012-05-21 22:45:41 -040055
Trond Myklebust4ce79712005-06-22 17:16:21 +000056#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050057#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040058#include "nfs4idmap.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050059#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040060#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040061#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63#define NFSDBG_FACILITY NFSDBG_XDR
64
65/* Mapping from NFS error code to "errno" error code. */
66#define errno_NFSERR_IO EIO
67
Fred Isaman56f487f2016-09-21 11:43:41 -040068struct compound_hdr;
David Howells0a8ea432006-08-22 20:06:08 -040069static int nfs4_stat_to_errno(int);
Fred Isaman56f487f2016-09-21 11:43:41 -040070static void encode_layoutget(struct xdr_stream *xdr,
71 const struct nfs4_layoutget_args *args,
72 struct compound_hdr *hdr);
73static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
74 struct nfs4_layoutget_res *res);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
77#ifdef DEBUG
78#define NFS4_MAXTAGLEN 20
79#else
80#define NFS4_MAXTAGLEN 0
81#endif
82
Andy Adamson6c0195a2008-12-23 16:06:15 -050083/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040084 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040086#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050087#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040088#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
90#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
91#define op_encode_hdr_maxsz (1)
92#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040093#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
94#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
95#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
96#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
98 (NFS4_FHSIZE >> 2))
99#define decode_putfh_maxsz (op_decode_hdr_maxsz)
100#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
101#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
102#define encode_getfh_maxsz (op_encode_hdr_maxsz)
103#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
104 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -0400105#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000106#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Trond Myklebust36b37432018-03-20 17:03:10 -0400107#define nfstime4_maxsz (3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
109#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400110#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
111#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400112#ifdef CONFIG_NFS_V4_SECURITY_LABEL
113/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
114#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400115#else
116#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400117#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400118/* We support only one layout type per file system */
119#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000120/* This is based on getfattr, which uses the most attributes: */
121#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400122 3*nfstime4_maxsz + \
123 nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400124 nfs4_group_maxsz + nfs4_label_maxsz + \
125 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000126#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
127 nfs4_fattr_value_maxsz)
128#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400129#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
130 1 + 2 + 1 + \
131 nfs4_owner_maxsz + \
132 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400133 nfs4_label_maxsz + \
Trond Myklebust36b37432018-03-20 17:03:10 -0400134 1 + nfstime4_maxsz + \
135 1 + nfstime4_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#define encode_savefh_maxsz (op_encode_hdr_maxsz)
137#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400138#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
139#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200140#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400141/* The 5 accounts for the PNFS attributes, and assumes that at most three
142 * layout types will be returned.
143 */
144#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
145 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
147#define decode_renew_maxsz (op_decode_hdr_maxsz)
148#define encode_setclientid_maxsz \
149 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500150 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400151 /* client name */ \
152 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500153 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500154 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
155 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500156 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#define decode_setclientid_maxsz \
158 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500159 2 /* clientid */ + \
160 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
161 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
162 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#define encode_setclientid_confirm_maxsz \
164 (op_encode_hdr_maxsz + \
165 3 + (NFS4_VERIFIER_SIZE >> 2))
166#define decode_setclientid_confirm_maxsz \
167 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400168#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
169#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700170#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
171#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400172#define encode_share_access_maxsz \
173 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500174#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400175#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
176#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
177#define encode_open_maxsz (op_encode_hdr_maxsz + \
178 2 + encode_share_access_maxsz + 2 + \
179 open_owner_id_maxsz + \
180 encode_opentype_maxsz + \
181 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500182#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400183#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400184#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500185 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400186 decode_ace_maxsz)
187#define decode_change_info_maxsz (5)
188#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400189 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400190 decode_change_info_maxsz + 1 + \
191 nfs4_fattr_bitmap_maxsz + \
192 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400193#define encode_open_confirm_maxsz \
194 (op_encode_hdr_maxsz + \
195 encode_stateid_maxsz + 1)
196#define decode_open_confirm_maxsz \
197 (op_decode_hdr_maxsz + \
198 decode_stateid_maxsz)
199#define encode_open_downgrade_maxsz \
200 (op_encode_hdr_maxsz + \
201 encode_stateid_maxsz + 1 + \
202 encode_share_access_maxsz)
203#define decode_open_downgrade_maxsz \
204 (op_decode_hdr_maxsz + \
205 decode_stateid_maxsz)
206#define encode_close_maxsz (op_encode_hdr_maxsz + \
207 1 + encode_stateid_maxsz)
208#define decode_close_maxsz (op_decode_hdr_maxsz + \
209 decode_stateid_maxsz)
210#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
211 encode_stateid_maxsz + \
212 encode_attrs_maxsz)
213#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
214 nfs4_fattr_bitmap_maxsz)
215#define encode_read_maxsz (op_encode_hdr_maxsz + \
216 encode_stateid_maxsz + 3)
217#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
218#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400219 2 + encode_verifier_maxsz + 5 + \
220 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400221#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400222 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400223#define encode_readlink_maxsz (op_encode_hdr_maxsz)
224#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
225#define encode_write_maxsz (op_encode_hdr_maxsz + \
226 encode_stateid_maxsz + 4)
227#define decode_write_maxsz (op_decode_hdr_maxsz + \
228 2 + decode_verifier_maxsz)
229#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
230#define decode_commit_maxsz (op_decode_hdr_maxsz + \
231 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232#define encode_remove_maxsz (op_encode_hdr_maxsz + \
233 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400234#define decode_remove_maxsz (op_decode_hdr_maxsz + \
235 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#define encode_rename_maxsz (op_encode_hdr_maxsz + \
237 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400238#define decode_rename_maxsz (op_decode_hdr_maxsz + \
239 decode_change_info_maxsz + \
240 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241#define encode_link_maxsz (op_encode_hdr_maxsz + \
242 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400243#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400244#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400245#define encode_lock_maxsz (op_encode_hdr_maxsz + \
246 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400247 1 + encode_stateid_maxsz + 1 + \
248 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400249#define decode_lock_denied_maxsz \
250 (8 + decode_lockowner_maxsz)
251#define decode_lock_maxsz (op_decode_hdr_maxsz + \
252 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400253#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
254 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400255#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
256 decode_lock_denied_maxsz)
257#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
258 encode_stateid_maxsz + \
259 4)
260#define decode_locku_maxsz (op_decode_hdr_maxsz + \
261 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400262#define encode_release_lockowner_maxsz \
263 (op_encode_hdr_maxsz + \
264 encode_lockowner_maxsz)
265#define decode_release_lockowner_maxsz \
266 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400267#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
268#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
270 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400271 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000272 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
274#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400275 1 + 2 + nfs4_name_maxsz + \
276 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400277#define decode_create_maxsz (op_decode_hdr_maxsz + \
278 decode_change_info_maxsz + \
279 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400280#define encode_statfs_maxsz (encode_getattr_maxsz)
281#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
283#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400284#define encode_getacl_maxsz (encode_getattr_maxsz)
285#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
286 nfs4_fattr_bitmap_maxsz + 1)
287#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
288 encode_stateid_maxsz + 3)
289#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400290#define encode_fs_locations_maxsz \
291 (encode_getattr_maxsz)
292#define decode_fs_locations_maxsz \
293 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000294#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400295#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400296
297#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400298#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500299#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
300 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400301
Benny Halevy99fe60d2009-04-01 09:22:29 -0400302#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
303 encode_verifier_maxsz + \
304 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400305 /* eia_clientowner */ \
306 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400307 1 /* flags */ + \
308 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400309 /* max is SP4_MACH_CRED (for now) */ + \
310 1 + NFS4_OP_MAP_NUM_WORDS + \
311 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500312 1 /* implementation id array of size 1 */ + \
313 1 /* nii_domain */ + \
314 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
315 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500316 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500317 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400318#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
319 2 /* eir_clientid */ + \
320 1 /* eir_sequenceid */ + \
321 1 /* eir_flags */ + \
322 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400323 /* max is SP4_MACH_CRED (for now) */ + \
324 1 + NFS4_OP_MAP_NUM_WORDS + \
325 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400326 2 /* eir_server_owner.so_minor_id */ + \
327 /* eir_server_owner.so_major_id<> */ \
328 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
329 /* eir_server_scope<> */ \
330 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
331 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500332 1 /* nii_domain */ + \
333 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
334 1 /* nii_name */ + \
335 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
336 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400337#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
338#define decode_channel_attrs_maxsz (6 + \
339 1 /* ca_rdma_ird.len */ + \
340 1 /* ca_rdma_ird */)
341#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
342 2 /* csa_clientid */ + \
343 1 /* csa_sequence */ + \
344 1 /* csa_flags */ + \
345 encode_channel_attrs_maxsz + \
346 encode_channel_attrs_maxsz + \
347 1 /* csa_cb_program */ + \
348 1 /* csa_sec_parms.len (1) */ + \
349 1 /* cb_secflavor (AUTH_SYS) */ + \
350 1 /* stamp */ + \
351 1 /* machinename.len */ + \
352 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
353 1 /* uid */ + \
354 1 /* gid */ + \
355 1 /* gids.len (0) */)
356#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
357 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
358 1 /* csr_sequence */ + \
359 1 /* csr_flags */ + \
360 decode_channel_attrs_maxsz + \
361 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400362#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
363 /* bctsa_sessid */ \
364 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
365 1 /* bctsa_dir */ + \
366 1 /* bctsa_use_conn_in_rdma_mode */)
367#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
368 /* bctsr_sessid */ \
369 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
370 1 /* bctsr_dir */ + \
371 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400372#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
373#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400374#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
375#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400376#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
377 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
378#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
379 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500380#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
381#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700382#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
383 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
384 1 /* layout type */ + \
385 1 /* maxcount */ + \
386 1 /* bitmap size */ + \
387 1 /* notification bitmap length */ + \
388 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400389#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
390 1 /* layout type */ + \
391 1 /* opaque devaddr4 length */ + \
392 /* devaddr4 payload is read into page */ \
393 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700394 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400395#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
396 encode_stateid_maxsz)
397#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
398 decode_stateid_maxsz + \
399 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000400#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
401 2 /* offset */ + \
402 2 /* length */ + \
403 1 /* reclaim */ + \
404 encode_stateid_maxsz + \
405 1 /* new offset (true) */ + \
406 2 /* last byte written */ + \
407 1 /* nt_timechanged (false) */ + \
408 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500409 1 /* layoutupdate4 opaqueue len */)
410 /* the actual content of layoutupdate4 should
411 be allocated by drivers and spliced in
412 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000413#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300414#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
415 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400416 1 + \
417 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300418#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
419 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400420#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
421#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400422#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
423 XDR_QUADLEN(NFS4_STATEID_SIZE))
424#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400425#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
426 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400427#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428#else /* CONFIG_NFS_V4_1 */
429#define encode_sequence_maxsz 0
430#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500431#define encode_layoutreturn_maxsz 0
432#define decode_layoutreturn_maxsz 0
Fred Isaman56f487f2016-09-21 11:43:41 -0400433#define encode_layoutget_maxsz 0
434#define decode_layoutget_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400435#endif /* CONFIG_NFS_V4_1 */
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
438#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
439#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400440 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400442 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400444 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400446 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400448 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400450 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400454 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400456 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400458 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400460 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400462 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400466 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400467 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400469 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400471 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400472 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400474 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400476 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400478 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400480 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400482 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400483 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400484 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400485 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400486 encode_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400487 encode_getattr_maxsz + \
488 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400490 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400491 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400492 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400493 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 decode_getfh_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400495 decode_getattr_maxsz + \
496 decode_layoutget_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400497#define NFS4_enc_open_confirm_sz \
498 (compound_encode_hdr_maxsz + \
499 encode_putfh_maxsz + \
500 encode_open_confirm_maxsz)
501#define NFS4_dec_open_confirm_sz \
502 (compound_decode_hdr_maxsz + \
503 decode_putfh_maxsz + \
504 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400506 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400508 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400509 encode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400510 encode_getattr_maxsz + \
511 encode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400515 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400516 decode_access_maxsz + \
Fred Isaman56f487f2016-09-21 11:43:41 -0400517 decode_getattr_maxsz + \
518 decode_layoutget_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519#define NFS4_enc_open_downgrade_sz \
520 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400521 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400522 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500523 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400524 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525#define NFS4_dec_open_downgrade_sz \
526 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400527 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400528 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500529 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400530 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400531#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400532 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400533 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500534 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400535 encode_close_maxsz + \
536 encode_getattr_maxsz)
537#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400539 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500540 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400541 decode_close_maxsz + \
542 decode_getattr_maxsz)
543#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400544 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400545 encode_putfh_maxsz + \
546 encode_setattr_maxsz + \
547 encode_getattr_maxsz)
548#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400549 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400550 decode_putfh_maxsz + \
551 decode_setattr_maxsz + \
552 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400554 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 encode_putfh_maxsz + \
556 encode_fsinfo_maxsz)
557#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400558 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 decode_putfh_maxsz + \
560 decode_fsinfo_maxsz)
561#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
562 encode_renew_maxsz)
563#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
564 decode_renew_maxsz)
565#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
566 encode_setclientid_maxsz)
567#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
568 decode_setclientid_maxsz)
569#define NFS4_enc_setclientid_confirm_sz \
570 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400571 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572#define NFS4_dec_setclientid_confirm_sz \
573 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400574 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400578 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400582 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400584 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400586 encode_lockt_maxsz)
587#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400588 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400589 decode_putfh_maxsz + \
590 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400594 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400596 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400598 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400599#define NFS4_enc_release_lockowner_sz \
600 (compound_encode_hdr_maxsz + \
601 encode_lockowner_maxsz)
602#define NFS4_dec_release_lockowner_sz \
603 (compound_decode_hdr_maxsz + \
604 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400606 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400608 encode_access_maxsz + \
609 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400611 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400613 decode_access_maxsz + \
614 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400618 encode_getattr_maxsz + \
619 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400621 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400623 decode_getattr_maxsz + \
624 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400626 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 encode_putfh_maxsz + \
628 encode_lookup_maxsz + \
629 encode_getattr_maxsz + \
630 encode_getfh_maxsz)
631#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400634 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 decode_getattr_maxsz + \
636 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700637#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
638 encode_sequence_maxsz + \
639 encode_putfh_maxsz + \
640 encode_lookupp_maxsz + \
641 encode_getattr_maxsz + \
642 encode_getfh_maxsz)
643#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
644 decode_sequence_maxsz + \
645 decode_putfh_maxsz + \
646 decode_lookupp_maxsz + \
647 decode_getattr_maxsz + \
648 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 encode_putrootfh_maxsz + \
652 encode_getattr_maxsz + \
653 encode_getfh_maxsz)
654#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400655 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 decode_putrootfh_maxsz + \
657 decode_getattr_maxsz + \
658 decode_getfh_maxsz)
659#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400662 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400664 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400666 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
670 encode_savefh_maxsz + \
671 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400672 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 decode_putfh_maxsz + \
676 decode_savefh_maxsz + \
677 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400678 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
682 encode_savefh_maxsz + \
683 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400684 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400685 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400686 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 decode_putfh_maxsz + \
690 decode_savefh_maxsz + \
691 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400692 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400693 decode_restorefh_maxsz + \
694 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 encode_putfh_maxsz + \
698 encode_symlink_maxsz + \
699 encode_getattr_maxsz + \
700 encode_getfh_maxsz)
701#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400702 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 decode_putfh_maxsz + \
704 decode_symlink_maxsz + \
705 decode_getattr_maxsz + \
706 decode_getfh_maxsz)
707#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400708 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 encode_putfh_maxsz + \
710 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400711 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400712 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400714 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 decode_putfh_maxsz + \
716 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400717 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400718 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400720 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 encode_putfh_maxsz + \
722 encode_getattr_maxsz)
723#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400724 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 decode_putfh_maxsz + \
726 decode_getattr_maxsz)
727#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400730 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400734 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400736 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800737 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 encode_getattr_maxsz)
739#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400740 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800741 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 decode_getattr_maxsz)
743#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400744 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500746 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100747 encode_delegreturn_maxsz + \
748 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400750 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500751 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500752 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100753 decode_delegreturn_maxsz + \
754 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000755#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400756 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000757 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400758 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000759#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400760 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000761 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400762 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000763#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400764 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000765 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400766 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000767#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400768 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000769 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400770 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400771#define NFS4_enc_fs_locations_sz \
772 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400773 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400774 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400775 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400776 encode_fs_locations_maxsz + \
777 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400778#define NFS4_dec_fs_locations_sz \
779 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400780 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400781 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400782 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400783 decode_fs_locations_maxsz + \
784 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000785#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
786 encode_sequence_maxsz + \
787 encode_putfh_maxsz + \
788 encode_secinfo_maxsz)
789#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
790 decode_sequence_maxsz + \
791 decode_putfh_maxsz + \
792 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400793#define NFS4_enc_fsid_present_sz \
794 (compound_encode_hdr_maxsz + \
795 encode_sequence_maxsz + \
796 encode_putfh_maxsz + \
797 encode_getfh_maxsz + \
798 encode_renew_maxsz)
799#define NFS4_dec_fsid_present_sz \
800 (compound_decode_hdr_maxsz + \
801 decode_sequence_maxsz + \
802 decode_putfh_maxsz + \
803 decode_getfh_maxsz + \
804 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400805#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400806#define NFS4_enc_bind_conn_to_session_sz \
807 (compound_encode_hdr_maxsz + \
808 encode_bind_conn_to_session_maxsz)
809#define NFS4_dec_bind_conn_to_session_sz \
810 (compound_decode_hdr_maxsz + \
811 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400812#define NFS4_enc_exchange_id_sz \
813 (compound_encode_hdr_maxsz + \
814 encode_exchange_id_maxsz)
815#define NFS4_dec_exchange_id_sz \
816 (compound_decode_hdr_maxsz + \
817 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400818#define NFS4_enc_create_session_sz \
819 (compound_encode_hdr_maxsz + \
820 encode_create_session_maxsz)
821#define NFS4_dec_create_session_sz \
822 (compound_decode_hdr_maxsz + \
823 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400824#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
825 encode_destroy_session_maxsz)
826#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
827 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400828#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
829 encode_destroy_clientid_maxsz)
830#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
831 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400832#define NFS4_enc_sequence_sz \
833 (compound_decode_hdr_maxsz + \
834 encode_sequence_maxsz)
835#define NFS4_dec_sequence_sz \
836 (compound_decode_hdr_maxsz + \
837 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400838#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
839 encode_sequence_maxsz + \
840 encode_putrootfh_maxsz + \
841 encode_fsinfo_maxsz)
842#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
843 decode_sequence_maxsz + \
844 decode_putrootfh_maxsz + \
845 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500846#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
847 encode_sequence_maxsz + \
848 encode_reclaim_complete_maxsz)
849#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
850 decode_sequence_maxsz + \
851 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400852#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz +\
854 encode_getdeviceinfo_maxsz)
855#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
856 decode_sequence_maxsz + \
857 decode_getdeviceinfo_maxsz)
858#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
859 encode_sequence_maxsz + \
860 encode_putfh_maxsz + \
861 encode_layoutget_maxsz)
862#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
863 decode_sequence_maxsz + \
864 decode_putfh_maxsz + \
865 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000866#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
867 encode_sequence_maxsz +\
868 encode_putfh_maxsz + \
869 encode_layoutcommit_maxsz + \
870 encode_getattr_maxsz)
871#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
872 decode_sequence_maxsz + \
873 decode_putfh_maxsz + \
874 decode_layoutcommit_maxsz + \
875 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300876#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
877 encode_sequence_maxsz + \
878 encode_putfh_maxsz + \
879 encode_layoutreturn_maxsz)
880#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
881 decode_sequence_maxsz + \
882 decode_putfh_maxsz + \
883 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400884#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
885 encode_sequence_maxsz + \
886 encode_putrootfh_maxsz +\
887 encode_secinfo_no_name_maxsz)
888#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
889 decode_sequence_maxsz + \
890 decode_putrootfh_maxsz + \
891 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400892#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
893 encode_sequence_maxsz + \
894 encode_test_stateid_maxsz)
895#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
896 decode_sequence_maxsz + \
897 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400898#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
899 encode_sequence_maxsz + \
900 encode_free_stateid_maxsz)
901#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
902 decode_sequence_maxsz + \
903 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500904
905const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
906 compound_encode_hdr_maxsz +
907 encode_sequence_maxsz +
908 encode_putfh_maxsz +
909 encode_getattr_maxsz) *
910 XDR_UNIT);
911
912const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
913 compound_decode_hdr_maxsz +
914 decode_sequence_maxsz +
915 decode_putfh_maxsz) *
916 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400917
918const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
919 compound_decode_hdr_maxsz +
920 decode_sequence_maxsz) *
921 XDR_UNIT);
922EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400923#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Trond Myklebustbca79472009-03-11 14:10:26 -0400925static const umode_t nfs_type2fmt[] = {
926 [NF4BAD] = 0,
927 [NF4REG] = S_IFREG,
928 [NF4DIR] = S_IFDIR,
929 [NF4BLK] = S_IFBLK,
930 [NF4CHR] = S_IFCHR,
931 [NF4LNK] = S_IFLNK,
932 [NF4SOCK] = S_IFSOCK,
933 [NF4FIFO] = S_IFIFO,
934 [NF4ATTRDIR] = 0,
935 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936};
937
938struct compound_hdr {
939 int32_t status;
940 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500941 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 uint32_t taglen;
943 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400944 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400945 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946};
947
Benny Halevy13c65ce2009-08-14 17:19:25 +0300948static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
949{
950 __be32 *p = xdr_reserve_space(xdr, nbytes);
951 BUG_ON(!p);
952 return p;
953}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
Trond Myklebustcb17e552012-03-04 18:13:56 -0500955static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
956{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500957 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500958}
959
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
961{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500962 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963}
964
Trond Myklebust4ade9822012-03-04 18:13:57 -0500965static void encode_uint32(struct xdr_stream *xdr, u32 n)
966{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500967 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500968}
969
Trond Myklebustff2eb682012-03-05 11:40:12 -0500970static void encode_uint64(struct xdr_stream *xdr, u64 n)
971{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500972 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500973}
974
Trond Myklebust37c88762018-03-20 17:03:08 -0400975static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
976 const __u32 *bitmap, size_t len)
977{
978 ssize_t ret;
979
980 /* Trim empty words */
981 while (len > 0 && bitmap[len-1] == 0)
982 len--;
983 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
984 if (WARN_ON_ONCE(ret < 0))
985 return ret;
986 return len;
987}
988
989static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
990 __u32 *res, size_t len)
991{
992 size_t i;
993 __u32 tmp;
994
995 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
996 len--;
997 for (i = len; i-- > 0;) {
998 tmp = bitmap[i] & mask[i];
999 res[i] = tmp;
1000 }
1001 return len;
1002}
1003
Trond Myklebust4ade9822012-03-04 18:13:57 -05001004static void encode_nfs4_seqid(struct xdr_stream *xdr,
1005 const struct nfs_seqid *seqid)
1006{
Trond Myklebusta6796412015-01-23 19:04:44 -05001007 if (seqid != NULL)
1008 encode_uint32(xdr, seqid->sequence->counter);
1009 else
1010 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001011}
1012
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001013static void encode_compound_hdr(struct xdr_stream *xdr,
1014 struct rpc_rqst *req,
1015 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Al Viro8687b632006-10-19 23:28:48 -07001017 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -04001018 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001019
1020 /* initialize running count of expected bytes in reply.
1021 * NOTE: the replied tag SHOULD be the same is the one sent,
1022 * but this is not required as a MUST for the server to do so. */
1023 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
Trond Myklebust7fc38842012-10-15 11:51:21 -04001025 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001026 encode_string(xdr, hdr->taglen, hdr->tag);
1027 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001028 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001029 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001030 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001031}
1032
Trond Myklebustab19b482012-03-04 18:13:57 -05001033static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1034 uint32_t replen,
1035 struct compound_hdr *hdr)
1036{
1037 encode_uint32(xdr, op);
1038 hdr->nops++;
1039 hdr->replen += replen;
1040}
1041
Andy Adamsond0179312008-12-23 16:06:17 -05001042static void encode_nops(struct compound_hdr *hdr)
1043{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001044 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001045 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046}
1047
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001048static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1049{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001050 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001051}
1052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1054{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001055 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056}
1057
Trond Myklebust36b37432018-03-20 17:03:10 -04001058static __be32 *
1059xdr_encode_nfstime4(__be32 *p, const struct timespec *t)
1060{
1061 p = xdr_encode_hyper(p, (__s64)t->tv_sec);
1062 *p++ = cpu_to_be32(t->tv_nsec);
1063 return p;
1064}
1065
David Quigleyaa9c2662013-05-22 12:50:44 -04001066static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1067 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001068 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001069 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001070 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071{
1072 char owner_name[IDMAP_NAMESZ];
1073 char owner_group[IDMAP_NAMESZ];
1074 int owner_namelen = 0;
1075 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001076 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001077 uint32_t len = 0;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001078 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 /*
1081 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001083 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001084 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001086 }
1087 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001088 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001089 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1090 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001091 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001092 bmval[1] |= FATTR4_WORD1_MODE;
1093 len += 4;
1094 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001095 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001096 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001097 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001099 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001100 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 /* XXX */
1102 strcpy(owner_name, "nobody");
1103 owner_namelen = sizeof("nobody") - 1;
1104 /* goto out; */
1105 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001106 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1108 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001109 if ((iap->ia_valid & ATTR_GID) &&
1110 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001111 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001113 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001114 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 strcpy(owner_group, "nobody");
1116 owner_grouplen = sizeof("nobody") - 1;
1117 /* goto out; */
1118 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001119 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1121 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001122 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1123 if (iap->ia_valid & ATTR_ATIME_SET) {
1124 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001125 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001126 } else if (iap->ia_valid & ATTR_ATIME) {
1127 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1128 len += 4;
1129 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001131 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1132 if (iap->ia_valid & ATTR_MTIME_SET) {
1133 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
Trond Myklebust36b37432018-03-20 17:03:10 -04001134 len += 4 + (nfstime4_maxsz << 2);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001135 } else if (iap->ia_valid & ATTR_MTIME) {
1136 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1137 len += 4;
1138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001140
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001141 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001142 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1143 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1144 }
1145
Trond Myklebust40a3426c2018-03-20 17:03:09 -04001146 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1147 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001148
1149 if (bmval[0] & FATTR4_WORD0_SIZE)
1150 p = xdr_encode_hyper(p, iap->ia_size);
1151 if (bmval[1] & FATTR4_WORD1_MODE)
1152 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1153 if (bmval[1] & FATTR4_WORD1_OWNER)
1154 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1155 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1156 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1157 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1158 if (iap->ia_valid & ATTR_ATIME_SET) {
1159 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebust36b37432018-03-20 17:03:10 -04001160 p = xdr_encode_nfstime4(p, &iap->ia_atime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001161 } else
1162 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1163 }
1164 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1165 if (iap->ia_valid & ATTR_MTIME_SET) {
1166 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
Trond Myklebust36b37432018-03-20 17:03:10 -04001167 p = xdr_encode_nfstime4(p, &iap->ia_mtime);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001168 } else
1169 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1170 }
1171 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001172 *p++ = cpu_to_be32(label->lfs);
1173 *p++ = cpu_to_be32(label->pi);
1174 *p++ = cpu_to_be32(label->len);
1175 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1176 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001177 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1178 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1179 *p++ = cpu_to_be32(*umask);
1180 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183}
1184
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001185static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001187 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1188 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001191static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Trond Myklebustab19b482012-03-04 18:13:57 -05001193 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001194 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001195 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196}
1197
Fred Isaman0b7c0152012-04-20 14:47:39 -04001198static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199{
Al Viro8687b632006-10-19 23:28:48 -07001200 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001201
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001202 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1203 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001204 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001205 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
1207
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001208static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Al Viro8687b632006-10-19 23:28:48 -07001210 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001211
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001212 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1213 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 switch (create->ftype) {
1216 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001217 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001218 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001219 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1220 create->u.symlink.len);
1221 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 break;
1223
1224 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001225 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001226 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001227 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 break;
1229
1230 default:
1231 break;
1232 }
1233
Benny Halevy811652b2009-08-14 17:19:34 +03001234 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001235 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1236 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237}
1238
Trond Myklebust37c88762018-03-20 17:03:08 -04001239static void encode_getattr(struct xdr_stream *xdr,
1240 const __u32 *bitmap, const __u32 *mask, size_t len,
1241 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
Trond Myklebust37c88762018-03-20 17:03:08 -04001243 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001245 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001246 if (mask) {
1247 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1248 len = ARRAY_SIZE(masked_bitmap);
1249 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1250 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001251 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001252 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001253}
1254
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001255static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256{
Trond Myklebust37c88762018-03-20 17:03:08 -04001257 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1258 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259}
1260
Andy Adamson88034c32012-05-23 05:02:34 -04001261static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001262 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001263 struct compound_hdr *hdr)
1264{
Trond Myklebust37c88762018-03-20 17:03:08 -04001265 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001266}
1267
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001268static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
Trond Myklebust37c88762018-03-20 17:03:08 -04001270 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1271 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272}
1273
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001274static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001275{
Trond Myklebust37c88762018-03-20 17:03:08 -04001276 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1277 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001278}
1279
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001280static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281{
Trond Myklebustab19b482012-03-04 18:13:57 -05001282 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283}
1284
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001285static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286{
Trond Myklebustab19b482012-03-04 18:13:57 -05001287 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001288 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289}
1290
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001291static inline int nfs4_lock_type(struct file_lock *fl, int block)
1292{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001293 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001294 return block ? NFS4_READW_LT : NFS4_READ_LT;
1295 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1296}
1297
1298static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1299{
1300 if (fl->fl_end == OFFSET_MAX)
1301 return ~(uint64_t)0;
1302 return fl->fl_end - fl->fl_start + 1;
1303}
1304
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001305static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1306{
1307 __be32 *p;
1308
Trond Myklebustd035c362010-12-21 10:45:27 -05001309 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001310 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001311 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001312 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001313 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001314 xdr_encode_hyper(p, lowner->id);
1315}
1316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317/*
1318 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1319 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1320 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001321static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322{
Al Viro8687b632006-10-19 23:28:48 -07001323 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001325 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1326 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001327 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1328 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001329 p = xdr_encode_hyper(p, args->fl->fl_start);
1330 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001331 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001332 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001333 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001334 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001335 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001336 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
1338 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001339 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001340 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342}
1343
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001344static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345{
Al Viro8687b632006-10-19 23:28:48 -07001346 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001348 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1349 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001350 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001351 p = xdr_encode_hyper(p, args->fl->fl_start);
1352 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001353 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354}
1355
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001356static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357{
Al Viro8687b632006-10-19 23:28:48 -07001358 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001360 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1361 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001362 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001363 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001364 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001365 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001366 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367}
1368
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001369static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1370{
Trond Myklebustab19b482012-03-04 18:13:57 -05001371 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001372 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001373}
1374
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001375static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
Trond Myklebustab19b482012-03-04 18:13:57 -05001377 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001378 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379}
1380
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001381static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1382{
1383 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1384}
1385
Trond Myklebust6ae37332015-01-30 14:21:14 -05001386static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387{
Al Viro8687b632006-10-19 23:28:48 -07001388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Benny Halevy13c65ce2009-08-14 17:19:25 +03001390 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001391 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001392 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393}
1394
1395static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1396{
Al Viro8687b632006-10-19 23:28:48 -07001397 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 /*
1399 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1400 * owner 4 = 32
1401 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001402 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001403 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001404 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001405 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001406 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001407 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001408 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001409 *p++ = cpu_to_be32(arg->id.uniquifier);
1410 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
1413static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1414{
Al Viro8687b632006-10-19 23:28:48 -07001415 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Benny Halevy13c65ce2009-08-14 17:19:25 +03001417 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001418 switch(arg->createmode) {
1419 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001420 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001421 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1422 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001423 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001424 case NFS4_CREATE_GUARDED:
1425 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001426 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1427 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001428 break;
1429 case NFS4_CREATE_EXCLUSIVE:
1430 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1431 encode_nfs4_verifier(xdr, &arg->u.verifier);
1432 break;
1433 case NFS4_CREATE_EXCLUSIVE4_1:
1434 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1435 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001436 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1437 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 }
1439}
1440
1441static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1442{
Al Viro8687b632006-10-19 23:28:48 -07001443 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
Benny Halevy13c65ce2009-08-14 17:19:25 +03001445 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001447 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001448 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001449 break;
1450 default:
Benny Halevy34558512009-08-14 17:19:30 +03001451 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001452 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454}
1455
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001456static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457{
Al Viro8687b632006-10-19 23:28:48 -07001458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Benny Halevy13c65ce2009-08-14 17:19:25 +03001460 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001462 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001463 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001464 break;
1465 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001466 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001467 break;
1468 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001469 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001470 break;
1471 default:
1472 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 }
1474}
1475
1476static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1477{
Al Viro8687b632006-10-19 23:28:48 -07001478 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Benny Halevy13c65ce2009-08-14 17:19:25 +03001480 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001481 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 encode_string(xdr, name->len, name->name);
1483}
1484
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001485static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486{
Al Viro8687b632006-10-19 23:28:48 -07001487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Benny Halevy13c65ce2009-08-14 17:19:25 +03001489 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001490 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 encode_delegation_type(xdr, type);
1492}
1493
1494static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1495{
Al Viro8687b632006-10-19 23:28:48 -07001496 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001498 p = reserve_space(xdr, 4);
1499 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1500 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 encode_string(xdr, name->len, name->name);
1502}
1503
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001504static inline void encode_claim_fh(struct xdr_stream *xdr)
1505{
1506 __be32 *p;
1507
1508 p = reserve_space(xdr, 4);
1509 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1510}
1511
1512static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1513{
1514 __be32 *p;
1515
1516 p = reserve_space(xdr, 4);
1517 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1518 encode_nfs4_stateid(xdr, stateid);
1519}
1520
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001521static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522{
Trond Myklebustab19b482012-03-04 18:13:57 -05001523 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 encode_openhdr(xdr, arg);
1525 encode_opentype(xdr, arg);
1526 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001527 case NFS4_OPEN_CLAIM_NULL:
1528 encode_claim_null(xdr, arg->name);
1529 break;
1530 case NFS4_OPEN_CLAIM_PREVIOUS:
1531 encode_claim_previous(xdr, arg->u.delegation_type);
1532 break;
1533 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1534 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1535 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001536 case NFS4_OPEN_CLAIM_FH:
1537 encode_claim_fh(xdr);
1538 break;
1539 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1540 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1541 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001542 default:
1543 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static void encode_open_confirm(struct xdr_stream *xdr, const struct nfs_open_confirmargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Trond Myklebustab19b482012-03-04 18:13:57 -05001549 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001550 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001551 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001554static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Trond Myklebustab19b482012-03-04 18:13:57 -05001556 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001557 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001558 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001559 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562static void
Andy Adamsond0179312008-12-23 16:06:17 -05001563encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564{
Trond Myklebustab19b482012-03-04 18:13:57 -05001565 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001566 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567}
1568
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001569static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570{
Trond Myklebustab19b482012-03-04 18:13:57 -05001571 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001574static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1575 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576{
Al Viro8687b632006-10-19 23:28:48 -07001577 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Trond Myklebustab19b482012-03-04 18:13:57 -05001579 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001580 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
Benny Halevy13c65ce2009-08-14 17:19:25 +03001582 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001583 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001584 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585}
1586
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001587static void encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg *readdir, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588{
David Quigleyaa9c2662013-05-22 12:50:44 -04001589 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001590 FATTR4_WORD0_RDATTR_ERROR,
1591 FATTR4_WORD1_MOUNTED_ON_FILEID,
1592 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001593 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001594 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001595 uint32_t attrlen = 0;
1596 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001598 if (readdir->plus) {
1599 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001600 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001601 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1602 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1603 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1604 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001605 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001606 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001607 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001608 /* Use mounted_on_fileid only if the server supports it */
1609 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1610 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001611 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1612 attrs[i] &= readdir->bitmask[i];
1613 if (attrs[i] != 0)
1614 attrlen = i+1;
1615 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001616
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001617 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001618 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001619 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001620 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001621 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001622 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001623 *p++ = cpu_to_be32(attrlen);
1624 for (i = 0; i < attrlen; i++)
1625 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001626 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001627
1628 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001629 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001630 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001631 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001632 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001633 attrs[1] & readdir->bitmask[1],
1634 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635}
1636
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001637static void encode_readlink(struct xdr_stream *xdr, const struct nfs4_readlink *readlink, struct rpc_rqst *req, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638{
Trond Myklebustab19b482012-03-04 18:13:57 -05001639 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001642static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643{
Trond Myklebustab19b482012-03-04 18:13:57 -05001644 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001645 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646}
1647
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001648static void encode_rename(struct xdr_stream *xdr, const struct qstr *oldname, const struct qstr *newname, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649{
Trond Myklebustab19b482012-03-04 18:13:57 -05001650 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001651 encode_string(xdr, oldname->len, oldname->name);
1652 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Chuck Leverbb4dae52012-03-01 17:01:48 -05001655static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1656 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001658 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001659 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001662static void
Andy Adamsond0179312008-12-23 16:06:17 -05001663encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001664{
Trond Myklebustab19b482012-03-04 18:13:57 -05001665 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001666}
1667
Chuck Lever9f06c712010-12-14 14:59:18 +00001668static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001669encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1670 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001671{
Al Viro8687b632006-10-19 23:28:48 -07001672 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001673
Trond Myklebustab19b482012-03-04 18:13:57 -05001674 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001675 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001676 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001677 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001678 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001679 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001680 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001681 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001682}
1683
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001684static void
Andy Adamsond0179312008-12-23 16:06:17 -05001685encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686{
Trond Myklebustab19b482012-03-04 18:13:57 -05001687 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688}
1689
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001690static void encode_setattr(struct xdr_stream *xdr, const struct nfs_setattrargs *arg, const struct nfs_server *server, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
Trond Myklebustab19b482012-03-04 18:13:57 -05001692 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001693 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001694 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1695 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696}
1697
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001698static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699{
Al Viro8687b632006-10-19 23:28:48 -07001700 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Trond Myklebust70019512012-03-04 20:49:32 -05001702 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001703 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
Jeff Layton3a6bb732015-06-09 19:43:57 -04001705 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1706 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001707 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001708 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1710 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001711 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001712 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713}
1714
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001715static void encode_setclientid_confirm(struct xdr_stream *xdr, const struct nfs4_setclientid_res *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001717 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1718 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001719 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001720 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721}
1722
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001723static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1724 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
Al Viro8687b632006-10-19 23:28:48 -07001726 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Trond Myklebustab19b482012-03-04 18:13:57 -05001728 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001729 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
Benny Halevy13c65ce2009-08-14 17:19:25 +03001731 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001732 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001733 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001734 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
1736 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737}
1738
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001739static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740{
Trond Myklebustab19b482012-03-04 18:13:57 -05001741 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001742 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001744
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001745static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1746{
Trond Myklebustab19b482012-03-04 18:13:57 -05001747 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001748 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001749}
1750
Benny Halevy99fe60d2009-04-01 09:22:29 -04001751#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001752/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001753static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001754 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001755 struct compound_hdr *hdr)
1756{
1757 __be32 *p;
1758
1759 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1760 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001761 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001762 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001763 *p++ = cpu_to_be32(args->dir);
1764 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001765}
1766
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001767static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001768{
1769 unsigned int i;
1770 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1771 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1772 encode_uint32(xdr, op_map->u.words[i]);
1773}
1774
Benny Halevy99fe60d2009-04-01 09:22:29 -04001775static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001776 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001777 struct compound_hdr *hdr)
1778{
1779 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001780 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001781 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001782
Trond Myklebust70019512012-03-04 20:49:32 -05001783 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001784 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001785
Jeff Layton3a6bb732015-06-09 19:43:57 -04001786 encode_string(xdr, strlen(args->client->cl_owner_id),
1787 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001788
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001789 encode_uint32(xdr, args->flags);
1790 encode_uint32(xdr, args->state_protect.how);
1791
1792 switch (args->state_protect.how) {
1793 case SP4_NONE:
1794 break;
1795 case SP4_MACH_CRED:
1796 encode_op_map(xdr, &args->state_protect.enforce);
1797 encode_op_map(xdr, &args->state_protect.allow);
1798 break;
1799 default:
1800 WARN_ON_ONCE(1);
1801 break;
1802 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001803
1804 if (send_implementation_id &&
1805 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1806 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001807 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001808 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1809 utsname()->sysname, utsname()->release,
1810 utsname()->version, utsname()->machine);
1811
1812 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001813 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001814
1815 encode_string(xdr,
1816 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1817 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1818 encode_string(xdr, len, impl_name);
1819 /* just send zeros for nii_date - the date is in nii_name */
1820 p = reserve_space(xdr, 12);
1821 p = xdr_encode_hyper(p, 0);
1822 *p = cpu_to_be32(0);
1823 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001824 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001825}
Andy Adamsonfc931582009-04-01 09:22:31 -04001826
1827static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001828 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001829 struct compound_hdr *hdr)
1830{
1831 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001832 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001833 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001834 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001835 u32 max_resp_sz_cached;
1836
1837 /*
1838 * Assumes OPEN is the biggest non-idempotent compound.
1839 * 2 is the verifier.
1840 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001841 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1842 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001843
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001844 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001845 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001846 p = xdr_encode_hyper(p, args->clientid);
1847 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001849
Andy Adamsonfc931582009-04-01 09:22:31 -04001850 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001851 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1853 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001854 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001855 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1856 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1857 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001858
1859 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001860 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001861 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1862 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1863 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1864 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1865 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1866 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001867
Benny Halevye75bc1c2009-08-14 17:18:54 +03001868 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001869 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001870 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001871
1872 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001873 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001874 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001875 *p++ = cpu_to_be32(0); /* UID */
1876 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001877 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001878}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001879
1880static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001881 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001882 struct compound_hdr *hdr)
1883{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001884 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1885 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001886}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001887
Trond Myklebust66245532012-05-25 17:18:09 -04001888static void encode_destroy_clientid(struct xdr_stream *xdr,
1889 uint64_t clientid,
1890 struct compound_hdr *hdr)
1891{
1892 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1893 encode_uint64(xdr, clientid);
1894}
1895
Ricardo Labiaga180197532009-12-05 16:08:40 -05001896static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001897 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001898 struct compound_hdr *hdr)
1899{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001900 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1901 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001902}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001903#endif /* CONFIG_NFS_V4_1 */
1904
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001905static void encode_sequence(struct xdr_stream *xdr,
1906 const struct nfs4_sequence_args *args,
1907 struct compound_hdr *hdr)
1908{
1909#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001910 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001911 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001912 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001913 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001914
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001915 tp = slot->table;
1916 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001917 if (!session)
1918 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001919
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001920 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001921
1922 /*
1923 * Sessionid + seqid + slotid + max slotid + cache_this
1924 */
1925 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1926 "max_slotid=%d cache_this=%d\n",
1927 __func__,
1928 ((u32 *)session->sess_id.data)[0],
1929 ((u32 *)session->sess_id.data)[1],
1930 ((u32 *)session->sess_id.data)[2],
1931 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001932 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001933 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001934 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001935 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001936 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001937 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001938 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001939 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001940#endif /* CONFIG_NFS_V4_1 */
1941}
1942
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001943#ifdef CONFIG_NFS_V4_1
1944static void
1945encode_getdeviceinfo(struct xdr_stream *xdr,
1946 const struct nfs4_getdeviceinfo_args *args,
1947 struct compound_hdr *hdr)
1948{
1949 __be32 *p;
1950
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001951 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001952 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001953 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1954 NFS4_DEVICEID4_SIZE);
1955 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001956 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001957
1958 p = reserve_space(xdr, 4 + 4);
1959 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001960 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001961}
1962
1963static void
1964encode_layoutget(struct xdr_stream *xdr,
1965 const struct nfs4_layoutget_args *args,
1966 struct compound_hdr *hdr)
1967{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001968 __be32 *p;
1969
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001970 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1971 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001972 *p++ = cpu_to_be32(0); /* Signal layout available */
1973 *p++ = cpu_to_be32(args->type);
1974 *p++ = cpu_to_be32(args->range.iomode);
1975 p = xdr_encode_hyper(p, args->range.offset);
1976 p = xdr_encode_hyper(p, args->range.length);
1977 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001978 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001979 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001980
1981 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1982 __func__,
1983 args->type,
1984 args->range.iomode,
1985 (unsigned long)args->range.offset,
1986 (unsigned long)args->range.length,
1987 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001988}
Andy Adamson863a3c62011-03-23 13:27:54 +00001989
1990static int
1991encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001992 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001993 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001994 struct compound_hdr *hdr)
1995{
1996 __be32 *p;
1997
1998 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1999 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2000
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002001 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2002 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002003 /* Only whole file layouts */
2004 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002005 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002006 *p = cpu_to_be32(0); /* reclaim */
2007 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002008 if (args->lastbytewritten != U64_MAX) {
2009 p = reserve_space(xdr, 20);
2010 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2011 p = xdr_encode_hyper(p, args->lastbytewritten);
2012 } else {
2013 p = reserve_space(xdr, 12);
2014 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2015 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002016 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2017 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002018
Trond Myklebust73504742017-04-20 16:48:14 -04002019 encode_uint32(xdr, args->layoutupdate_len);
2020 if (args->layoutupdate_pages)
2021 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2022 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002023
Andy Adamson863a3c62011-03-23 13:27:54 +00002024 return 0;
2025}
Benny Halevycbe82602011-05-22 19:52:37 +03002026
2027static void
2028encode_layoutreturn(struct xdr_stream *xdr,
2029 const struct nfs4_layoutreturn_args *args,
2030 struct compound_hdr *hdr)
2031{
2032 __be32 *p;
2033
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002034 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2035 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002036 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2037 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002038 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002039 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002040 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002041 p = xdr_encode_hyper(p, args->range.offset);
2042 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002043 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002044 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002045 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002046 if (args->ld_private->ops && args->ld_private->ops->encode)
2047 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002048 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002049 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002050}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002051
2052static int
2053encode_secinfo_no_name(struct xdr_stream *xdr,
2054 const struct nfs41_secinfo_no_name_args *args,
2055 struct compound_hdr *hdr)
2056{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002057 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2058 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002059 return 0;
2060}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002061
2062static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002063 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002064 struct compound_hdr *hdr)
2065{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002066 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2067 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002068 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002069}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002070
2071static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002072 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002073 struct compound_hdr *hdr)
2074{
Trond Myklebustab19b482012-03-04 18:13:57 -05002075 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002076 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002077}
Trond Myklebustcf805162016-11-15 14:56:07 -05002078#else
2079static inline void
2080encode_layoutreturn(struct xdr_stream *xdr,
2081 const struct nfs4_layoutreturn_args *args,
2082 struct compound_hdr *hdr)
2083{
2084}
Fred Isaman56f487f2016-09-21 11:43:41 -04002085
2086static void
2087encode_layoutget(struct xdr_stream *xdr,
2088 const struct nfs4_layoutget_args *args,
2089 struct compound_hdr *hdr)
2090{
2091}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002092#endif /* CONFIG_NFS_V4_1 */
2093
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094/*
2095 * END OF "GENERIC" ENCODE ROUTINES.
2096 */
2097
Benny Halevy66cc0422009-04-01 09:22:10 -04002098static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2099{
2100#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002101 struct nfs4_session *session = args->sa_slot->table->session;
2102 if (session)
2103 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002104#endif /* CONFIG_NFS_V4_1 */
2105 return 0;
2106}
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108/*
2109 * Encode an ACCESS request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002112 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002114 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Chuck Lever9f06c712010-12-14 14:59:18 +00002119 encode_compound_hdr(xdr, req, &hdr);
2120 encode_sequence(xdr, &args->seq_args, &hdr);
2121 encode_putfh(xdr, args->fh, &hdr);
2122 encode_access(xdr, args->access, &hdr);
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04002123 if (args->bitmask)
2124 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002125 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
2128/*
2129 * Encode LOOKUP request
2130 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002131static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002132 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002134 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002136 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Chuck Lever9f06c712010-12-14 14:59:18 +00002139 encode_compound_hdr(xdr, req, &hdr);
2140 encode_sequence(xdr, &args->seq_args, &hdr);
2141 encode_putfh(xdr, args->dir_fh, &hdr);
2142 encode_lookup(xdr, args->name, &hdr);
2143 encode_getfh(xdr, &hdr);
2144 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002145 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146}
2147
2148/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002149 * Encode LOOKUPP request
2150 */
2151static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2152 const void *data)
2153{
2154 const struct nfs4_lookupp_arg *args = data;
2155 struct compound_hdr hdr = {
2156 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2157 };
2158
2159 encode_compound_hdr(xdr, req, &hdr);
2160 encode_sequence(xdr, &args->seq_args, &hdr);
2161 encode_putfh(xdr, args->fh, &hdr);
2162 encode_lookupp(xdr, &hdr);
2163 encode_getfh(xdr, &hdr);
2164 encode_getfattr(xdr, args->bitmask, &hdr);
2165 encode_nops(&hdr);
2166}
2167
2168/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 * Encode LOOKUP_ROOT request
2170 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002171static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2172 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002173 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002175 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002177 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
Chuck Lever9f06c712010-12-14 14:59:18 +00002180 encode_compound_hdr(xdr, req, &hdr);
2181 encode_sequence(xdr, &args->seq_args, &hdr);
2182 encode_putrootfh(xdr, &hdr);
2183 encode_getfh(xdr, &hdr);
2184 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002185 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186}
2187
2188/*
2189 * Encode REMOVE request
2190 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002191static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002192 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002194 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002196 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
Chuck Lever9f06c712010-12-14 14:59:18 +00002199 encode_compound_hdr(xdr, req, &hdr);
2200 encode_sequence(xdr, &args->seq_args, &hdr);
2201 encode_putfh(xdr, args->fh, &hdr);
2202 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002203 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204}
2205
2206/*
2207 * Encode RENAME request
2208 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002209static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002210 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002212 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002214 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
Chuck Lever9f06c712010-12-14 14:59:18 +00002217 encode_compound_hdr(xdr, req, &hdr);
2218 encode_sequence(xdr, &args->seq_args, &hdr);
2219 encode_putfh(xdr, args->old_dir, &hdr);
2220 encode_savefh(xdr, &hdr);
2221 encode_putfh(xdr, args->new_dir, &hdr);
2222 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002223 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224}
2225
2226/*
2227 * Encode LINK request
2228 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002229static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002230 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002232 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002234 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Chuck Lever9f06c712010-12-14 14:59:18 +00002237 encode_compound_hdr(xdr, req, &hdr);
2238 encode_sequence(xdr, &args->seq_args, &hdr);
2239 encode_putfh(xdr, args->fh, &hdr);
2240 encode_savefh(xdr, &hdr);
2241 encode_putfh(xdr, args->dir_fh, &hdr);
2242 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002243 encode_restorefh(xdr, &hdr);
2244 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002245 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * Encode CREATE request
2250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002251static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002252 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002254 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002256 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
Chuck Lever9f06c712010-12-14 14:59:18 +00002259 encode_compound_hdr(xdr, req, &hdr);
2260 encode_sequence(xdr, &args->seq_args, &hdr);
2261 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002262 encode_create(xdr, args, &hdr);
2263 encode_getfh(xdr, &hdr);
2264 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002265 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266}
2267
2268/*
2269 * Encode SYMLINK request
2270 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002271static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002272 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002274 const struct nfs4_create_arg *args = data;
2275
Chuck Lever9f06c712010-12-14 14:59:18 +00002276 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277}
2278
2279/*
2280 * Encode GETATTR request
2281 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002282static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002283 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002285 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002287 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
Chuck Lever9f06c712010-12-14 14:59:18 +00002290 encode_compound_hdr(xdr, req, &hdr);
2291 encode_sequence(xdr, &args->seq_args, &hdr);
2292 encode_putfh(xdr, args->fh, &hdr);
2293 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002294 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295}
2296
2297/*
2298 * Encode a CLOSE request
2299 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002300static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002301 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002303 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002304 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002305 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002306 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
Chuck Lever9f06c712010-12-14 14:59:18 +00002308 encode_compound_hdr(xdr, req, &hdr);
2309 encode_sequence(xdr, &args->seq_args, &hdr);
2310 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002311 if (args->lr_args)
2312 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002313 if (args->bitmask != NULL)
2314 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002315 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002316 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317}
2318
2319/*
2320 * Encode an OPEN request
2321 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002322static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002323 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002325 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002327 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
Chuck Lever9f06c712010-12-14 14:59:18 +00002330 encode_compound_hdr(xdr, req, &hdr);
2331 encode_sequence(xdr, &args->seq_args, &hdr);
2332 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002333 encode_open(xdr, args, &hdr);
2334 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002335 if (args->access)
2336 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002337 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002338 if (args->lg_args) {
2339 encode_layoutget(xdr, args->lg_args, &hdr);
2340 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2341 args->lg_args->layout.pages,
2342 0, args->lg_args->layout.pglen);
2343 }
Andy Adamsond0179312008-12-23 16:06:17 -05002344 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
2347/*
2348 * Encode an OPEN_CONFIRM request
2349 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002350static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2351 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002352 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002354 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002356 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Chuck Lever9f06c712010-12-14 14:59:18 +00002359 encode_compound_hdr(xdr, req, &hdr);
2360 encode_putfh(xdr, args->fh, &hdr);
2361 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002362 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363}
2364
2365/*
2366 * Encode an OPEN request with no attributes.
2367 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002368static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2369 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002370 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002372 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002374 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
Chuck Lever9f06c712010-12-14 14:59:18 +00002377 encode_compound_hdr(xdr, req, &hdr);
2378 encode_sequence(xdr, &args->seq_args, &hdr);
2379 encode_putfh(xdr, args->fh, &hdr);
2380 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002381 if (args->access)
2382 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002383 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Fred Isaman56f487f2016-09-21 11:43:41 -04002384 if (args->lg_args) {
2385 encode_layoutget(xdr, args->lg_args, &hdr);
2386 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2387 args->lg_args->layout.pages,
2388 0, args->lg_args->layout.pglen);
2389 }
Andy Adamsond0179312008-12-23 16:06:17 -05002390 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391}
2392
2393/*
2394 * Encode an OPEN_DOWNGRADE request
2395 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002396static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2397 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002398 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002400 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002402 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404
Chuck Lever9f06c712010-12-14 14:59:18 +00002405 encode_compound_hdr(xdr, req, &hdr);
2406 encode_sequence(xdr, &args->seq_args, &hdr);
2407 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002408 if (args->lr_args)
2409 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002410 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002411 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412}
2413
2414/*
2415 * Encode a LOCK request
2416 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002417static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002418 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002420 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002422 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
Chuck Lever9f06c712010-12-14 14:59:18 +00002425 encode_compound_hdr(xdr, req, &hdr);
2426 encode_sequence(xdr, &args->seq_args, &hdr);
2427 encode_putfh(xdr, args->fh, &hdr);
2428 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002429 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430}
2431
2432/*
2433 * Encode a LOCKT request
2434 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002435static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002436 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002438 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002440 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
Chuck Lever9f06c712010-12-14 14:59:18 +00002443 encode_compound_hdr(xdr, req, &hdr);
2444 encode_sequence(xdr, &args->seq_args, &hdr);
2445 encode_putfh(xdr, args->fh, &hdr);
2446 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002447 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448}
2449
2450/*
2451 * Encode a LOCKU request
2452 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002453static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002454 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002456 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002458 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460
Chuck Lever9f06c712010-12-14 14:59:18 +00002461 encode_compound_hdr(xdr, req, &hdr);
2462 encode_sequence(xdr, &args->seq_args, &hdr);
2463 encode_putfh(xdr, args->fh, &hdr);
2464 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002465 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466}
2467
Chuck Lever9f06c712010-12-14 14:59:18 +00002468static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2469 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002470 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002471{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002472 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002473 struct compound_hdr hdr = {
2474 .minorversion = 0,
2475 };
2476
Chuck Lever9f06c712010-12-14 14:59:18 +00002477 encode_compound_hdr(xdr, req, &hdr);
2478 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002479 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002480}
2481
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482/*
2483 * Encode a READLINK request
2484 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002485static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002486 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002488 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002490 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Chuck Lever9f06c712010-12-14 14:59:18 +00002493 encode_compound_hdr(xdr, req, &hdr);
2494 encode_sequence(xdr, &args->seq_args, &hdr);
2495 encode_putfh(xdr, args->fh, &hdr);
2496 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002497
Benny Halevy28f56692009-04-01 09:22:09 -04002498 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002499 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002500 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501}
2502
2503/*
2504 * Encode a READDIR request
2505 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002506static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002507 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002509 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002511 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
Chuck Lever9f06c712010-12-14 14:59:18 +00002514 encode_compound_hdr(xdr, req, &hdr);
2515 encode_sequence(xdr, &args->seq_args, &hdr);
2516 encode_putfh(xdr, args->fh, &hdr);
2517 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002518
Benny Halevy28f56692009-04-01 09:22:09 -04002519 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002520 args->pgbase, args->count);
2521 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002522 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002523 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002524 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525}
2526
2527/*
2528 * Encode a READ request
2529 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002530static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002531 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002533 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002535 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537
Chuck Lever9f06c712010-12-14 14:59:18 +00002538 encode_compound_hdr(xdr, req, &hdr);
2539 encode_sequence(xdr, &args->seq_args, &hdr);
2540 encode_putfh(xdr, args->fh, &hdr);
2541 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542
Benny Halevy28f56692009-04-01 09:22:09 -04002543 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002545 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002546 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547}
2548
2549/*
2550 * Encode an SETATTR request
2551 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002552static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002553 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002555 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002556 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002557 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002558 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
Chuck Lever9f06c712010-12-14 14:59:18 +00002560 encode_compound_hdr(xdr, req, &hdr);
2561 encode_sequence(xdr, &args->seq_args, &hdr);
2562 encode_putfh(xdr, args->fh, &hdr);
2563 encode_setattr(xdr, args, args->server, &hdr);
2564 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002565 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566}
2567
2568/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002569 * Encode a GETACL request
2570 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002571static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002572 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002573{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002574 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002575 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002576 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002577 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002578 const __u32 nfs4_acl_bitmap[1] = {
2579 [0] = FATTR4_WORD0_ACL,
2580 };
Benny Halevy28f56692009-04-01 09:22:09 -04002581 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002582
Chuck Lever9f06c712010-12-14 14:59:18 +00002583 encode_compound_hdr(xdr, req, &hdr);
2584 encode_sequence(xdr, &args->seq_args, &hdr);
2585 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002586 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002587 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2588 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002589
Benny Halevy28f56692009-04-01 09:22:09 -04002590 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002591 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002592
Andy Adamsond0179312008-12-23 16:06:17 -05002593 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002594}
2595
2596/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 * Encode a WRITE request
2598 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002599static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002600 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002602 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002604 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
Chuck Lever9f06c712010-12-14 14:59:18 +00002607 encode_compound_hdr(xdr, req, &hdr);
2608 encode_sequence(xdr, &args->seq_args, &hdr);
2609 encode_putfh(xdr, args->fh, &hdr);
2610 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002611 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002612 if (args->bitmask)
2613 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002614 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615}
2616
2617/*
2618 * a COMMIT request
2619 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002620static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002621 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002623 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002625 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627
Chuck Lever9f06c712010-12-14 14:59:18 +00002628 encode_compound_hdr(xdr, req, &hdr);
2629 encode_sequence(xdr, &args->seq_args, &hdr);
2630 encode_putfh(xdr, args->fh, &hdr);
2631 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002632 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633}
2634
2635/*
2636 * FSINFO request
2637 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002638static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002639 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002641 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002643 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
Chuck Lever9f06c712010-12-14 14:59:18 +00002646 encode_compound_hdr(xdr, req, &hdr);
2647 encode_sequence(xdr, &args->seq_args, &hdr);
2648 encode_putfh(xdr, args->fh, &hdr);
2649 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002650 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651}
2652
2653/*
2654 * a PATHCONF request
2655 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002656static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002657 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002659 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002661 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Chuck Lever9f06c712010-12-14 14:59:18 +00002664 encode_compound_hdr(xdr, req, &hdr);
2665 encode_sequence(xdr, &args->seq_args, &hdr);
2666 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002667 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2668 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002669 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670}
2671
2672/*
2673 * a STATFS request
2674 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002675static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002676 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002678 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002680 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_compound_hdr(xdr, req, &hdr);
2684 encode_sequence(xdr, &args->seq_args, &hdr);
2685 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002686 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2687 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002688 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689}
2690
2691/*
2692 * GETATTR_BITMAP request
2693 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002694static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2695 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002696 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002698 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002699 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002701 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703
Chuck Lever9f06c712010-12-14 14:59:18 +00002704 encode_compound_hdr(xdr, req, &hdr);
2705 encode_sequence(xdr, &args->seq_args, &hdr);
2706 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002707 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002708 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709}
2710
2711/*
2712 * a RENEW request
2713 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002714static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002715 const void *data)
2716
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002718 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002720 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 };
2722
Chuck Lever9f06c712010-12-14 14:59:18 +00002723 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002724 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002725 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726}
2727
2728/*
2729 * a SETCLIENTID request
2730 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002731static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2732 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002733 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002735 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002737 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 };
2739
Chuck Lever9f06c712010-12-14 14:59:18 +00002740 encode_compound_hdr(xdr, req, &hdr);
2741 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002742 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743}
2744
2745/*
2746 * a SETCLIENTID_CONFIRM request
2747 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002748static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2749 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002750 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002752 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002754 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
Chuck Lever9f06c712010-12-14 14:59:18 +00002757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002759 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760}
2761
2762/*
2763 * DELEGRETURN request
2764 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002765static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2766 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002767 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002769 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002771 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773
Chuck Lever9f06c712010-12-14 14:59:18 +00002774 encode_compound_hdr(xdr, req, &hdr);
2775 encode_sequence(xdr, &args->seq_args, &hdr);
2776 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002777 if (args->lr_args)
2778 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002779 if (args->bitmask)
2780 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002781 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002782 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783}
2784
2785/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002786 * Encode FS_LOCATIONS request
2787 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002788static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2789 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002790 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002791{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002792 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002793 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002794 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002795 };
Benny Halevy28f56692009-04-01 09:22:09 -04002796 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002797
Chuck Lever9f06c712010-12-14 14:59:18 +00002798 encode_compound_hdr(xdr, req, &hdr);
2799 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002800 if (args->migration) {
2801 encode_putfh(xdr, args->fh, &hdr);
2802 replen = hdr.replen;
2803 encode_fs_locations(xdr, args->bitmask, &hdr);
2804 if (args->renew)
2805 encode_renew(xdr, args->clientid, &hdr);
2806 } else {
2807 encode_putfh(xdr, args->dir_fh, &hdr);
2808 encode_lookup(xdr, args->name, &hdr);
2809 replen = hdr.replen;
2810 encode_fs_locations(xdr, args->bitmask, &hdr);
2811 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002812
Chuck Leverb03d7352013-10-17 14:12:50 -04002813 /* Set up reply kvec to capture returned fs_locations array. */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002814 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2815 (struct page **)&args->page, 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002816 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002817}
2818
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002819/*
2820 * Encode SECINFO request
2821 */
2822static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2823 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002824 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002825{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002826 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002827 struct compound_hdr hdr = {
2828 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2829 };
2830
2831 encode_compound_hdr(xdr, req, &hdr);
2832 encode_sequence(xdr, &args->seq_args, &hdr);
2833 encode_putfh(xdr, args->dir_fh, &hdr);
2834 encode_secinfo(xdr, args->name, &hdr);
2835 encode_nops(&hdr);
2836}
2837
Chuck Lever44c99932013-10-17 14:13:30 -04002838/*
2839 * Encode FSID_PRESENT request
2840 */
2841static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2842 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002843 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002844{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002845 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002846 struct compound_hdr hdr = {
2847 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2848 };
2849
2850 encode_compound_hdr(xdr, req, &hdr);
2851 encode_sequence(xdr, &args->seq_args, &hdr);
2852 encode_putfh(xdr, args->fh, &hdr);
2853 encode_getfh(xdr, &hdr);
2854 if (args->renew)
2855 encode_renew(xdr, args->clientid, &hdr);
2856 encode_nops(&hdr);
2857}
2858
Benny Halevy99fe60d2009-04-01 09:22:29 -04002859#if defined(CONFIG_NFS_V4_1)
2860/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002861 * BIND_CONN_TO_SESSION request
2862 */
2863static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2864 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002865 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002866{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002867 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002868 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002869 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002870 };
2871
2872 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002873 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002874 encode_nops(&hdr);
2875}
2876
2877/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002878 * EXCHANGE_ID request
2879 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002880static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2881 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002882 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002883{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002884 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002885 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002886 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002887 };
2888
Chuck Lever9f06c712010-12-14 14:59:18 +00002889 encode_compound_hdr(xdr, req, &hdr);
2890 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002891 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002892}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002893
2894/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002895 * a CREATE_SESSION request
2896 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002897static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2898 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002899 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002900{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002901 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002902 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002903 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002904 };
2905
Chuck Lever9f06c712010-12-14 14:59:18 +00002906 encode_compound_hdr(xdr, req, &hdr);
2907 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002908 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002909}
2910
2911/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002912 * a DESTROY_SESSION request
2913 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002914static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2915 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002916 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002917{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002918 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002919 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002920 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002921 };
2922
Chuck Lever9f06c712010-12-14 14:59:18 +00002923 encode_compound_hdr(xdr, req, &hdr);
2924 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002925 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002926}
2927
2928/*
Trond Myklebust66245532012-05-25 17:18:09 -04002929 * a DESTROY_CLIENTID request
2930 */
2931static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2932 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002933 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002934{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002935 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002936 struct compound_hdr hdr = {
2937 .minorversion = clp->cl_mvops->minor_version,
2938 };
2939
2940 encode_compound_hdr(xdr, req, &hdr);
2941 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2942 encode_nops(&hdr);
2943}
2944
2945/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002946 * a SEQUENCE request
2947 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002948static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002949 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002950{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002951 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002952 struct compound_hdr hdr = {
2953 .minorversion = nfs4_xdr_minorversion(args),
2954 };
2955
Chuck Lever9f06c712010-12-14 14:59:18 +00002956 encode_compound_hdr(xdr, req, &hdr);
2957 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002958 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002959}
2960
2961/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002962 * a GET_LEASE_TIME request
2963 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002964static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2965 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002966 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002967{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002968 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002969 struct compound_hdr hdr = {
2970 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2971 };
Fred Isamandae100c2011-07-30 20:52:37 -04002972 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002973
Chuck Lever9f06c712010-12-14 14:59:18 +00002974 encode_compound_hdr(xdr, req, &hdr);
2975 encode_sequence(xdr, &args->la_seq_args, &hdr);
2976 encode_putrootfh(xdr, &hdr);
2977 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002978 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002979}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002980
2981/*
2982 * a RECLAIM_COMPLETE request
2983 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002984static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2985 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002986 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002987{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002988 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002989 struct compound_hdr hdr = {
2990 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2991 };
2992
Chuck Lever9f06c712010-12-14 14:59:18 +00002993 encode_compound_hdr(xdr, req, &hdr);
2994 encode_sequence(xdr, &args->seq_args, &hdr);
2995 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002996 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002997}
2998
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002999/*
3000 * Encode GETDEVICEINFO request
3001 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003002static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
3003 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003004 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003005{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003006 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003007 struct compound_hdr hdr = {
3008 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3009 };
3010
Chuck Lever9f06c712010-12-14 14:59:18 +00003011 encode_compound_hdr(xdr, req, &hdr);
3012 encode_sequence(xdr, &args->seq_args, &hdr);
3013 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003014
3015 /* set up reply kvec. Subtract notification bitmap max size (2)
3016 * so that notification bitmap is put in xdr_buf tail */
3017 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
3018 args->pdev->pages, args->pdev->pgbase,
3019 args->pdev->pglen);
3020
3021 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003022}
3023
3024/*
3025 * Encode LAYOUTGET request
3026 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003027static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3028 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003029 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003030{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003031 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003032 struct compound_hdr hdr = {
3033 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3034 };
3035
Chuck Lever9f06c712010-12-14 14:59:18 +00003036 encode_compound_hdr(xdr, req, &hdr);
3037 encode_sequence(xdr, &args->seq_args, &hdr);
3038 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3039 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003040
3041 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
3042 args->layout.pages, 0, args->layout.pglen);
3043
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003044 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003045}
Andy Adamson863a3c62011-03-23 13:27:54 +00003046
3047/*
3048 * Encode LAYOUTCOMMIT request
3049 */
Benny Halevycbe82602011-05-22 19:52:37 +03003050static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3051 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003052 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003053{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003054 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003055 struct nfs4_layoutcommit_data *data =
3056 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003057 struct compound_hdr hdr = {
3058 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3059 };
3060
3061 encode_compound_hdr(xdr, req, &hdr);
3062 encode_sequence(xdr, &args->seq_args, &hdr);
3063 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003064 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003065 encode_getfattr(xdr, args->bitmask, &hdr);
3066 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003067}
3068
3069/*
3070 * Encode LAYOUTRETURN request
3071 */
3072static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3073 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003074 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003075{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003076 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003077 struct compound_hdr hdr = {
3078 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3079 };
3080
3081 encode_compound_hdr(xdr, req, &hdr);
3082 encode_sequence(xdr, &args->seq_args, &hdr);
3083 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3084 encode_layoutreturn(xdr, args, &hdr);
3085 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003086}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003087
3088/*
3089 * Encode SECINFO_NO_NAME request
3090 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003091static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003092 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003093 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003094{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003095 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003096 struct compound_hdr hdr = {
3097 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3098 };
3099
3100 encode_compound_hdr(xdr, req, &hdr);
3101 encode_sequence(xdr, &args->seq_args, &hdr);
3102 encode_putrootfh(xdr, &hdr);
3103 encode_secinfo_no_name(xdr, args, &hdr);
3104 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003105}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003106
3107/*
3108 * Encode TEST_STATEID request
3109 */
3110static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3111 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003112 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003113{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003114 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003115 struct compound_hdr hdr = {
3116 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3117 };
3118
3119 encode_compound_hdr(xdr, req, &hdr);
3120 encode_sequence(xdr, &args->seq_args, &hdr);
3121 encode_test_stateid(xdr, args, &hdr);
3122 encode_nops(&hdr);
3123}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003124
3125/*
3126 * Encode FREE_STATEID request
3127 */
3128static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3129 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003130 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003131{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003132 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003133 struct compound_hdr hdr = {
3134 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3135 };
3136
3137 encode_compound_hdr(xdr, req, &hdr);
3138 encode_sequence(xdr, &args->seq_args, &hdr);
3139 encode_free_stateid(xdr, args, &hdr);
3140 encode_nops(&hdr);
3141}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003142#endif /* CONFIG_NFS_V4_1 */
3143
Benny Halevy686841b2009-08-14 17:19:48 +03003144static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3145{
3146 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3147 "Remaining buffer length is %tu words.\n",
3148 func, xdr->end - xdr->p);
3149}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
Trond Myklebust683b57b2006-06-09 09:34:22 -04003151static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003153 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3154 NFS4_OPAQUE_LIMIT);
3155 if (unlikely(ret < 0)) {
3156 if (ret == -EBADMSG)
3157 print_overflow_msg(__func__, xdr);
3158 return -EIO;
3159 }
3160 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 return 0;
3162}
3163
3164static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3165{
Al Viro8687b632006-10-19 23:28:48 -07003166 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167
Benny Halevyc0eae662009-08-14 17:20:14 +03003168 p = xdr_inline_decode(xdr, 8);
3169 if (unlikely(!p))
3170 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003171 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003172 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003173
Benny Halevyc0eae662009-08-14 17:20:14 +03003174 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3175 if (unlikely(!p))
3176 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 hdr->tag = (char *)p;
3178 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003179 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003180 if (unlikely(hdr->nops < 1))
3181 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003183out_overflow:
3184 print_overflow_msg(__func__, xdr);
3185 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186}
3187
Trond Myklebustc7848f62013-12-04 17:39:23 -05003188static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3189 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190{
Al Viro8687b632006-10-19 23:28:48 -07003191 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 uint32_t opnum;
3193 int32_t nfserr;
3194
Benny Halevyc0eae662009-08-14 17:20:14 +03003195 p = xdr_inline_decode(xdr, 8);
3196 if (unlikely(!p))
3197 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003198 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003199 if (unlikely(opnum != expected))
3200 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003201 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003202 if (nfserr == NFS_OK)
3203 *nfs_retval = 0;
3204 else
3205 *nfs_retval = nfs4_stat_to_errno(nfserr);
3206 return true;
3207out_bad_operation:
3208 dprintk("nfs: Server returned operation"
3209 " %d but we issued a request for %d\n",
3210 opnum, expected);
3211 *nfs_retval = -EREMOTEIO;
3212 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003213out_overflow:
3214 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003215 *nfs_retval = -EIO;
3216 return false;
3217}
3218
3219static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3220{
3221 int retval;
3222
3223 __decode_op_hdr(xdr, expected, &retval);
3224 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225}
3226
3227/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003228static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229{
Al Viro8687b632006-10-19 23:28:48 -07003230 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003231 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 char *str;
3233
Benny Halevyc0eae662009-08-14 17:20:14 +03003234 p = xdr_inline_decode(xdr, 12);
3235 if (likely(p))
3236 return decode_opaque_inline(xdr, &strlen, &str);
3237 print_overflow_msg(__func__, xdr);
3238 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239}
3240
Trond Myklebust37c88762018-03-20 17:03:08 -04003241static ssize_t
3242decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243{
Trond Myklebust37c88762018-03-20 17:03:08 -04003244 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
Trond Myklebust37c88762018-03-20 17:03:08 -04003246 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3247 if (likely(ret >= 0))
3248 return ret;
3249 if (ret == -EMSGSIZE)
3250 return sz;
Benny Halevyc0eae662009-08-14 17:20:14 +03003251 print_overflow_msg(__func__, xdr);
3252 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253}
3254
Trond Myklebust37c88762018-03-20 17:03:08 -04003255static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3256{
3257 ssize_t ret;
3258 ret = decode_bitmap4(xdr, bitmap, 3);
3259 return ret < 0 ? ret : 0;
3260}
3261
Trond Myklebust256e48b2012-06-21 11:18:13 -04003262static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263{
Al Viro8687b632006-10-19 23:28:48 -07003264 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
Benny Halevyc0eae662009-08-14 17:20:14 +03003266 p = xdr_inline_decode(xdr, 4);
3267 if (unlikely(!p))
3268 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003269 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003270 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003272out_overflow:
3273 print_overflow_msg(__func__, xdr);
3274 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275}
3276
3277static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3278{
3279 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003280 int ret;
3281 ret = decode_attr_bitmap(xdr, bitmask);
3282 if (unlikely(ret < 0))
3283 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3285 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003286 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3287 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3288 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 return 0;
3290}
3291
3292static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3293{
Al Viro8687b632006-10-19 23:28:48 -07003294 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003295 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
3297 *type = 0;
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003301 p = xdr_inline_decode(xdr, 4);
3302 if (unlikely(!p))
3303 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003304 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003306 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 return -EIO;
3308 }
3309 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003310 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003312 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003313 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003314out_overflow:
3315 print_overflow_msg(__func__, xdr);
3316 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317}
3318
Chuck Lever264e6352012-03-01 17:02:05 -05003319static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3320 uint32_t *bitmap, uint32_t *type)
3321{
3322 __be32 *p;
3323
3324 *type = 0;
3325 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3326 return -EIO;
3327 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3328 p = xdr_inline_decode(xdr, 4);
3329 if (unlikely(!p))
3330 goto out_overflow;
3331 *type = be32_to_cpup(p);
3332 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3333 }
3334 dprintk("%s: expire type=0x%x\n", __func__, *type);
3335 return 0;
3336out_overflow:
3337 print_overflow_msg(__func__, xdr);
3338 return -EIO;
3339}
3340
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3342{
Al Viro8687b632006-10-19 23:28:48 -07003343 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003344 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345
3346 *change = 0;
3347 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3348 return -EIO;
3349 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003350 p = xdr_inline_decode(xdr, 8);
3351 if (unlikely(!p))
3352 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003353 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003355 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003357 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003359 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003360out_overflow:
3361 print_overflow_msg(__func__, xdr);
3362 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363}
3364
3365static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3366{
Al Viro8687b632006-10-19 23:28:48 -07003367 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003368 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369
3370 *size = 0;
3371 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3372 return -EIO;
3373 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003374 p = xdr_inline_decode(xdr, 8);
3375 if (unlikely(!p))
3376 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003377 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003379 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003381 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003382 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003383out_overflow:
3384 print_overflow_msg(__func__, xdr);
3385 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386}
3387
3388static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3389{
Al Viro8687b632006-10-19 23:28:48 -07003390 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
3392 *res = 0;
3393 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3394 return -EIO;
3395 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003396 p = xdr_inline_decode(xdr, 4);
3397 if (unlikely(!p))
3398 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003399 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3401 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003402 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003404out_overflow:
3405 print_overflow_msg(__func__, xdr);
3406 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407}
3408
3409static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3410{
Al Viro8687b632006-10-19 23:28:48 -07003411 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412
3413 *res = 0;
3414 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3415 return -EIO;
3416 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003417 p = xdr_inline_decode(xdr, 4);
3418 if (unlikely(!p))
3419 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003420 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3422 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003423 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003425out_overflow:
3426 print_overflow_msg(__func__, xdr);
3427 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428}
3429
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003430static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431{
Al Viro8687b632006-10-19 23:28:48 -07003432 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003433 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
3435 fsid->major = 0;
3436 fsid->minor = 0;
3437 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3438 return -EIO;
3439 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003440 p = xdr_inline_decode(xdr, 16);
3441 if (unlikely(!p))
3442 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003443 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003444 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003446 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003448 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 (unsigned long long)fsid->major,
3450 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003451 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003452out_overflow:
3453 print_overflow_msg(__func__, xdr);
3454 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455}
3456
3457static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3458{
Al Viro8687b632006-10-19 23:28:48 -07003459 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
3461 *res = 60;
3462 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3463 return -EIO;
3464 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003465 p = xdr_inline_decode(xdr, 4);
3466 if (unlikely(!p))
3467 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003468 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3470 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003471 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003473out_overflow:
3474 print_overflow_msg(__func__, xdr);
3475 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476}
3477
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003478static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003479{
3480 __be32 *p;
3481
3482 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3483 return -EIO;
3484 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3485 p = xdr_inline_decode(xdr, 4);
3486 if (unlikely(!p))
3487 goto out_overflow;
3488 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003489 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003490 }
3491 return 0;
3492out_overflow:
3493 print_overflow_msg(__func__, xdr);
3494 return -EIO;
3495}
3496
Kinglong Mee8c612822015-08-26 21:12:58 +08003497static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3498 uint32_t *bitmap, uint32_t *bitmask)
3499{
3500 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3501 int ret;
3502 ret = decode_attr_bitmap(xdr, bitmask);
3503 if (unlikely(ret < 0))
3504 return ret;
3505 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3506 } else
3507 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3508 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3509 bitmask[0], bitmask[1], bitmask[2]);
3510 return 0;
3511}
3512
Bryan Schumakerae42c702010-10-21 16:33:17 -04003513static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3514{
3515 __be32 *p;
3516 int len;
3517
Trond Myklebust7ad07352010-10-23 15:34:20 -04003518 if (fh != NULL)
3519 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003520
3521 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3522 return -EIO;
3523 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3524 p = xdr_inline_decode(xdr, 4);
3525 if (unlikely(!p))
3526 goto out_overflow;
3527 len = be32_to_cpup(p);
3528 if (len > NFS4_FHSIZE)
3529 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003530 p = xdr_inline_decode(xdr, len);
3531 if (unlikely(!p))
3532 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003533 if (fh != NULL) {
3534 memcpy(fh->data, p, len);
3535 fh->size = len;
3536 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003537 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3538 }
3539 return 0;
3540out_overflow:
3541 print_overflow_msg(__func__, xdr);
3542 return -EIO;
3543}
3544
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3546{
Al Viro8687b632006-10-19 23:28:48 -07003547 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003549 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3551 return -EIO;
3552 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003553 p = xdr_inline_decode(xdr, 4);
3554 if (unlikely(!p))
3555 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003556 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3558 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003559 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003561out_overflow:
3562 print_overflow_msg(__func__, xdr);
3563 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564}
3565
3566static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3567{
Al Viro8687b632006-10-19 23:28:48 -07003568 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003569 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570
3571 *fileid = 0;
3572 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3573 return -EIO;
3574 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003575 p = xdr_inline_decode(xdr, 8);
3576 if (unlikely(!p))
3577 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003578 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003580 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003582 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003583 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003584out_overflow:
3585 print_overflow_msg(__func__, xdr);
3586 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003587}
3588
Manoj Naik99baf622006-06-09 09:34:24 -04003589static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3590{
Al Viro8687b632006-10-19 23:28:48 -07003591 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003592 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003593
3594 *fileid = 0;
3595 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3596 return -EIO;
3597 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003598 p = xdr_inline_decode(xdr, 8);
3599 if (unlikely(!p))
3600 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003601 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003602 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003603 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003604 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003605 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003606 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003607out_overflow:
3608 print_overflow_msg(__func__, xdr);
3609 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003610}
3611
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3613{
Al Viro8687b632006-10-19 23:28:48 -07003614 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 int status = 0;
3616
3617 *res = 0;
3618 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3619 return -EIO;
3620 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003621 p = xdr_inline_decode(xdr, 8);
3622 if (unlikely(!p))
3623 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003624 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3626 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003627 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003628 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003629out_overflow:
3630 print_overflow_msg(__func__, xdr);
3631 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632}
3633
3634static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3635{
Al Viro8687b632006-10-19 23:28:48 -07003636 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 int status = 0;
3638
3639 *res = 0;
3640 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3641 return -EIO;
3642 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003643 p = xdr_inline_decode(xdr, 8);
3644 if (unlikely(!p))
3645 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003646 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3648 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003649 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003651out_overflow:
3652 print_overflow_msg(__func__, xdr);
3653 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654}
3655
3656static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3657{
Al Viro8687b632006-10-19 23:28:48 -07003658 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 int status = 0;
3660
3661 *res = 0;
3662 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3663 return -EIO;
3664 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003665 p = xdr_inline_decode(xdr, 8);
3666 if (unlikely(!p))
3667 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003668 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3670 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003671 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003673out_overflow:
3674 print_overflow_msg(__func__, xdr);
3675 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676}
3677
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003678static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3679{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003680 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003681 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003682 int status = 0;
3683
Benny Halevyc0eae662009-08-14 17:20:14 +03003684 p = xdr_inline_decode(xdr, 4);
3685 if (unlikely(!p))
3686 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003687 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003688 if (n == 0)
3689 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003690 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003691 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3692 dprintk("cannot parse %d components in path\n", n);
3693 goto out_eio;
3694 }
3695 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003696 struct nfs4_string *component = &path->components[path->ncomponents];
3697 status = decode_opaque_inline(xdr, &component->len, &component->data);
3698 if (unlikely(status != 0))
3699 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003700 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003701 pr_cont("%s%.*s ",
3702 (path->ncomponents != n ? "/ " : ""),
3703 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003704 }
3705out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003706 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003707root_path:
3708/* a root pathname is sent as a zero component4 */
3709 path->ncomponents = 1;
3710 path->components[0].len=0;
3711 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003712 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003713 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003714out_eio:
3715 dprintk(" status %d", status);
3716 status = -EIO;
3717 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003718out_overflow:
3719 print_overflow_msg(__func__, xdr);
3720 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003721}
3722
3723static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003724{
3725 int n;
Al Viro8687b632006-10-19 23:28:48 -07003726 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003727 int status = -EIO;
3728
3729 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3730 goto out;
3731 status = 0;
3732 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3733 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003734 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003735 status = -EIO;
3736 /* Ignore borken servers that return unrequested attrs */
3737 if (unlikely(res == NULL))
3738 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003739 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003740 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003741 if (unlikely(status != 0))
3742 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003743 p = xdr_inline_decode(xdr, 4);
3744 if (unlikely(!p))
3745 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003746 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003747 if (n <= 0)
3748 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003749 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003750 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003751 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003752
Trond Myklebust809b4262013-03-27 11:54:45 -04003753 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3754 break;
3755 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003756 p = xdr_inline_decode(xdr, 4);
3757 if (unlikely(!p))
3758 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003759 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003760
Chuck Lever02a29762012-03-01 17:00:31 -05003761 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003762 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3763 struct nfs4_string *server;
3764
3765 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003766 unsigned int i;
3767 dprintk("%s: using first %u of %u servers "
3768 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003769 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003770 NFS4_FS_LOCATION_MAXSERVERS,
3771 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003772 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003773 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003774 char *data;
3775 status = decode_opaque_inline(xdr, &len, &data);
3776 if (unlikely(status != 0))
3777 goto out_eio;
3778 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003779 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003780 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003781 server = &loc->servers[loc->nservers];
3782 status = decode_opaque_inline(xdr, &server->len, &server->data);
3783 if (unlikely(status != 0))
3784 goto out_eio;
3785 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003786 }
3787 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003788 if (unlikely(status != 0))
3789 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003790 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003791 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003792 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003793out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003794 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003795 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003796out_overflow:
3797 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003798out_eio:
3799 status = -EIO;
3800 goto out;
3801}
3802
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3804{
Al Viro8687b632006-10-19 23:28:48 -07003805 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 int status = 0;
3807
3808 *res = 0;
3809 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3810 return -EIO;
3811 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003812 p = xdr_inline_decode(xdr, 8);
3813 if (unlikely(!p))
3814 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003815 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3817 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003818 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003820out_overflow:
3821 print_overflow_msg(__func__, xdr);
3822 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823}
3824
3825static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3826{
Al Viro8687b632006-10-19 23:28:48 -07003827 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 int status = 0;
3829
3830 *maxlink = 1;
3831 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3832 return -EIO;
3833 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003834 p = xdr_inline_decode(xdr, 4);
3835 if (unlikely(!p))
3836 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003837 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3839 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003840 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003842out_overflow:
3843 print_overflow_msg(__func__, xdr);
3844 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845}
3846
3847static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3848{
Al Viro8687b632006-10-19 23:28:48 -07003849 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 int status = 0;
3851
3852 *maxname = 1024;
3853 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3854 return -EIO;
3855 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003856 p = xdr_inline_decode(xdr, 4);
3857 if (unlikely(!p))
3858 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003859 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3861 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003862 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003864out_overflow:
3865 print_overflow_msg(__func__, xdr);
3866 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867}
3868
3869static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3870{
Al Viro8687b632006-10-19 23:28:48 -07003871 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 int status = 0;
3873
3874 *res = 1024;
3875 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3876 return -EIO;
3877 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3878 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003879 p = xdr_inline_decode(xdr, 8);
3880 if (unlikely(!p))
3881 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003882 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 if (maxread > 0x7FFFFFFF)
3884 maxread = 0x7FFFFFFF;
3885 *res = (uint32_t)maxread;
3886 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3887 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003888 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003889 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003890out_overflow:
3891 print_overflow_msg(__func__, xdr);
3892 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893}
3894
3895static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3896{
Al Viro8687b632006-10-19 23:28:48 -07003897 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 int status = 0;
3899
3900 *res = 1024;
3901 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3902 return -EIO;
3903 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3904 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003905 p = xdr_inline_decode(xdr, 8);
3906 if (unlikely(!p))
3907 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003908 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 if (maxwrite > 0x7FFFFFFF)
3910 maxwrite = 0x7FFFFFFF;
3911 *res = (uint32_t)maxwrite;
3912 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3913 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003914 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003916out_overflow:
3917 print_overflow_msg(__func__, xdr);
3918 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919}
3920
Trond Myklebustbca79472009-03-11 14:10:26 -04003921static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922{
Trond Myklebustbca79472009-03-11 14:10:26 -04003923 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003924 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003925 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926
3927 *mode = 0;
3928 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3929 return -EIO;
3930 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003931 p = xdr_inline_decode(xdr, 4);
3932 if (unlikely(!p))
3933 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003934 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003935 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003937 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003939 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003940 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003941out_overflow:
3942 print_overflow_msg(__func__, xdr);
3943 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944}
3945
3946static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3947{
Al Viro8687b632006-10-19 23:28:48 -07003948 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003949 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950
3951 *nlink = 1;
3952 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3953 return -EIO;
3954 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003955 p = xdr_inline_decode(xdr, 4);
3956 if (unlikely(!p))
3957 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003958 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003959 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003960 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003962 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003963 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003964out_overflow:
3965 print_overflow_msg(__func__, xdr);
3966 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967}
3968
Trond Myklebust686a8162017-02-19 16:08:32 -05003969static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3970 struct nfs4_string *name, gfp_t gfp_flags)
3971{
3972 ssize_t ret;
3973
3974 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3975 XDR_MAX_NETOBJ, gfp_flags);
3976 name->len = 0;
3977 if (ret > 0)
3978 name->len = ret;
3979 return ret;
3980}
3981
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003982static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003983 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003984 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985{
Trond Myklebust686a8162017-02-19 16:08:32 -05003986 ssize_t len;
3987 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988
Eric W. Biedermane5782072013-02-01 14:22:02 -08003989 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3991 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003992 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3993 return 0;
3994 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3995
3996 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003997 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003998 if (len <= 0)
3999 goto out;
4000 dprintk("%s: name=%s\n", __func__, owner_name->data);
4001 return NFS_ATTR_FATTR_OWNER_NAME;
4002 } else {
4003 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4004 XDR_MAX_NETOBJ);
4005 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
4006 goto out;
4007 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
4008 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004009 }
Trond Myklebust686a8162017-02-19 16:08:32 -05004010out:
4011 if (len != -EBADMSG)
4012 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004013 print_overflow_msg(__func__, xdr);
4014 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015}
4016
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004017static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08004018 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004019 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020{
Trond Myklebust686a8162017-02-19 16:08:32 -05004021 ssize_t len;
4022 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023
Eric W. Biedermane5782072013-02-01 14:22:02 -08004024 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
4026 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05004027 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
4028 return 0;
4029 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
4030
4031 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04004032 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05004033 if (len <= 0)
4034 goto out;
4035 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08004036 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05004037 } else {
4038 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4039 XDR_MAX_NETOBJ);
4040 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4041 goto out;
4042 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4043 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044 }
Trond Myklebust686a8162017-02-19 16:08:32 -05004045out:
4046 if (len != -EBADMSG)
4047 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004048 print_overflow_msg(__func__, xdr);
4049 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050}
4051
4052static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
4053{
Al Viro8687b632006-10-19 23:28:48 -07004054 uint32_t major = 0, minor = 0;
4055 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004056 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057
4058 *rdev = MKDEV(0,0);
4059 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
4060 return -EIO;
4061 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
4062 dev_t tmp;
4063
Benny Halevyc0eae662009-08-14 17:20:14 +03004064 p = xdr_inline_decode(xdr, 8);
4065 if (unlikely(!p))
4066 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004067 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004068 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 tmp = MKDEV(major, minor);
4070 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
4071 *rdev = tmp;
4072 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04004073 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004075 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04004076 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004077out_overflow:
4078 print_overflow_msg(__func__, xdr);
4079 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080}
4081
4082static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4083{
Al Viro8687b632006-10-19 23:28:48 -07004084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 int status = 0;
4086
4087 *res = 0;
4088 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4089 return -EIO;
4090 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004091 p = xdr_inline_decode(xdr, 8);
4092 if (unlikely(!p))
4093 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004094 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004095 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4096 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004097 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004099out_overflow:
4100 print_overflow_msg(__func__, xdr);
4101 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102}
4103
4104static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4105{
Al Viro8687b632006-10-19 23:28:48 -07004106 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 int status = 0;
4108
4109 *res = 0;
4110 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4111 return -EIO;
4112 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004113 p = xdr_inline_decode(xdr, 8);
4114 if (unlikely(!p))
4115 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004116 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004117 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4118 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004119 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004120 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004121out_overflow:
4122 print_overflow_msg(__func__, xdr);
4123 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124}
4125
4126static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4127{
Al Viro8687b632006-10-19 23:28:48 -07004128 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 int status = 0;
4130
4131 *res = 0;
4132 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4133 return -EIO;
4134 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004135 p = xdr_inline_decode(xdr, 8);
4136 if (unlikely(!p))
4137 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004138 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4140 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004141 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004143out_overflow:
4144 print_overflow_msg(__func__, xdr);
4145 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146}
4147
4148static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4149{
Al Viro8687b632006-10-19 23:28:48 -07004150 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004151 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152
4153 *used = 0;
4154 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4155 return -EIO;
4156 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004157 p = xdr_inline_decode(xdr, 8);
4158 if (unlikely(!p))
4159 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004160 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004162 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004164 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004166 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004167out_overflow:
4168 print_overflow_msg(__func__, xdr);
4169 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170}
4171
Trond Myklebust36b37432018-03-20 17:03:10 -04004172static __be32 *
4173xdr_decode_nfstime4(__be32 *p, struct timespec *t)
4174{
4175 __u64 sec;
4176
4177 p = xdr_decode_hyper(p, &sec);
4178 t-> tv_sec = (time_t)sec;
4179 t->tv_nsec = be32_to_cpup(p++);
4180 return p;
4181}
4182
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4184{
Al Viro8687b632006-10-19 23:28:48 -07004185 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
Trond Myklebust36b37432018-03-20 17:03:10 -04004187 p = xdr_inline_decode(xdr, nfstime4_maxsz << 2);
Benny Halevyc0eae662009-08-14 17:20:14 +03004188 if (unlikely(!p))
4189 goto out_overflow;
Trond Myklebust36b37432018-03-20 17:03:10 -04004190 xdr_decode_nfstime4(p, time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004192out_overflow:
4193 print_overflow_msg(__func__, xdr);
4194 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195}
4196
4197static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4198{
4199 int status = 0;
4200
4201 time->tv_sec = 0;
4202 time->tv_nsec = 0;
4203 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4204 return -EIO;
4205 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4206 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004207 if (status == 0)
4208 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4210 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004211 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 return status;
4213}
4214
4215static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4216{
4217 int status = 0;
4218
4219 time->tv_sec = 0;
4220 time->tv_nsec = 0;
4221 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4222 return -EIO;
4223 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4224 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004225 if (status == 0)
4226 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4228 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004229 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 return status;
4231}
4232
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004233static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4234 struct timespec *time)
4235{
4236 int status = 0;
4237
4238 time->tv_sec = 0;
4239 time->tv_nsec = 0;
4240 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4241 return -EIO;
4242 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4243 status = decode_attr_time(xdr, time);
4244 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4245 }
4246 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4247 (long)time->tv_nsec);
4248 return status;
4249}
4250
David Quigleyaa9c2662013-05-22 12:50:44 -04004251static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4252 struct nfs4_label *label)
4253{
4254 uint32_t pi = 0;
4255 uint32_t lfs = 0;
4256 __u32 len;
4257 __be32 *p;
4258 int status = 0;
4259
4260 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4261 return -EIO;
4262 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4263 p = xdr_inline_decode(xdr, 4);
4264 if (unlikely(!p))
4265 goto out_overflow;
4266 lfs = be32_to_cpup(p++);
4267 p = xdr_inline_decode(xdr, 4);
4268 if (unlikely(!p))
4269 goto out_overflow;
4270 pi = be32_to_cpup(p++);
4271 p = xdr_inline_decode(xdr, 4);
4272 if (unlikely(!p))
4273 goto out_overflow;
4274 len = be32_to_cpup(p++);
4275 p = xdr_inline_decode(xdr, len);
4276 if (unlikely(!p))
4277 goto out_overflow;
4278 if (len < NFS4_MAXLABELLEN) {
4279 if (label) {
4280 memcpy(label->label, p, len);
4281 label->len = len;
4282 label->pi = pi;
4283 label->lfs = lfs;
4284 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4285 }
4286 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4287 } else
4288 printk(KERN_WARNING "%s: label too long (%u)!\n",
4289 __func__, len);
4290 }
4291 if (label && label->label)
4292 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4293 (char *)label->label, label->len, label->pi, label->lfs);
4294 return status;
4295
4296out_overflow:
4297 print_overflow_msg(__func__, xdr);
4298 return -EIO;
4299}
4300
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4302{
4303 int status = 0;
4304
4305 time->tv_sec = 0;
4306 time->tv_nsec = 0;
4307 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4308 return -EIO;
4309 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4310 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004311 if (status == 0)
4312 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4314 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004315 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 return status;
4317}
4318
Trond Myklebust256e48b2012-06-21 11:18:13 -04004319static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320{
4321 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004322 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323
4324 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004325 dprintk("%s: server returned incorrect attribute length: "
4326 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004327 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 attrwords << 2,
4329 (attrwords < nwords) ? '<' : '>',
4330 nwords << 2);
4331 return -EIO;
4332 }
4333 return 0;
4334}
4335
4336static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4337{
Al Viro8687b632006-10-19 23:28:48 -07004338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339
Benny Halevyc0eae662009-08-14 17:20:14 +03004340 p = xdr_inline_decode(xdr, 20);
4341 if (unlikely(!p))
4342 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004343 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004344 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004345 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004347out_overflow:
4348 print_overflow_msg(__func__, xdr);
4349 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350}
4351
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004352static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353{
Al Viro8687b632006-10-19 23:28:48 -07004354 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 uint32_t supp, acc;
4356 int status;
4357
4358 status = decode_op_hdr(xdr, OP_ACCESS);
4359 if (status)
4360 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004361 p = xdr_inline_decode(xdr, 8);
4362 if (unlikely(!p))
4363 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004364 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004365 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004366 *supported = supp;
4367 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004369out_overflow:
4370 print_overflow_msg(__func__, xdr);
4371 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372}
4373
Benny Halevy07d30432009-08-14 17:19:52 +03004374static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004375{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004376 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4377 if (unlikely(ret < 0)) {
4378 print_overflow_msg(__func__, xdr);
4379 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004380 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004381 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004382}
4383
4384static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4385{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004386 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387}
4388
Trond Myklebust93b717f2016-05-16 17:42:43 -04004389static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4390{
4391 stateid->type = NFS4_OPEN_STATEID_TYPE;
4392 return decode_stateid(xdr, stateid);
4393}
4394
4395static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4396{
4397 stateid->type = NFS4_LOCK_STATEID_TYPE;
4398 return decode_stateid(xdr, stateid);
4399}
4400
4401static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4402{
4403 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4404 return decode_stateid(xdr, stateid);
4405}
4406
Trond Myklebustfcd88432017-11-07 12:39:44 -05004407static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4408{
4409 nfs4_stateid dummy;
4410
4411 nfs4_stateid_copy(stateid, &invalid_stateid);
4412 return decode_stateid(xdr, &dummy);
4413}
4414
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4416{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 int status;
4418
4419 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004420 if (status != -EIO)
4421 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004422 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004423 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004424 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004425}
4426
Benny Halevydb942bb2009-08-14 17:19:56 +03004427static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4428{
Chuck Levercd937102012-03-02 17:14:31 -05004429 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004430}
4431
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004432static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4433{
4434 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4435}
4436
Fred Isaman0b7c0152012-04-20 14:47:39 -04004437static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004439 int status;
4440
4441 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004442 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004443 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004444 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004445}
4446
4447static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4448{
Al Viro8687b632006-10-19 23:28:48 -07004449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 uint32_t bmlen;
4451 int status;
4452
4453 status = decode_op_hdr(xdr, OP_CREATE);
4454 if (status)
4455 return status;
4456 if ((status = decode_change_info(xdr, cinfo)))
4457 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004458 p = xdr_inline_decode(xdr, 4);
4459 if (unlikely(!p))
4460 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004461 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004462 p = xdr_inline_decode(xdr, bmlen << 2);
4463 if (likely(p))
4464 return 0;
4465out_overflow:
4466 print_overflow_msg(__func__, xdr);
4467 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468}
4469
4470static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4471{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004472 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004473 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004474 int status;
4475
4476 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4477 goto xdr_error;
4478 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4479 goto xdr_error;
4480 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4481 goto xdr_error;
4482 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4483 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004484 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4485 &res->fh_expire_type)) != 0)
4486 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4488 goto xdr_error;
4489 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4490 goto xdr_error;
4491 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4492 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004493 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4494 res->exclcreat_bitmask)) != 0)
4495 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004496 status = verify_attr_len(xdr, savep, attrlen);
4497xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004498 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 return status;
4500}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004501
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4503{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004504 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004505 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004506 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004507
Linus Torvalds1da177e2005-04-16 15:20:36 -07004508 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4509 goto xdr_error;
4510 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4511 goto xdr_error;
4512 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4513 goto xdr_error;
4514
4515 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4516 goto xdr_error;
4517 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4518 goto xdr_error;
4519 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4520 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004521
4522 status = -EIO;
4523 if (unlikely(bitmap[0]))
4524 goto xdr_error;
4525
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4527 goto xdr_error;
4528 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4529 goto xdr_error;
4530 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4531 goto xdr_error;
4532
4533 status = verify_attr_len(xdr, savep, attrlen);
4534xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004535 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004536 return status;
4537}
4538
4539static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4540{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004541 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004542 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004544
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4546 goto xdr_error;
4547 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4548 goto xdr_error;
4549 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4550 goto xdr_error;
4551
4552 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4553 goto xdr_error;
4554 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4555 goto xdr_error;
4556
4557 status = verify_attr_len(xdr, savep, attrlen);
4558xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004559 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004560 return status;
4561}
4562
Andy Adamson88034c32012-05-23 05:02:34 -04004563static int decode_threshold_hint(struct xdr_stream *xdr,
4564 uint32_t *bitmap,
4565 uint64_t *res,
4566 uint32_t hint_bit)
4567{
4568 __be32 *p;
4569
4570 *res = 0;
4571 if (likely(bitmap[0] & hint_bit)) {
4572 p = xdr_inline_decode(xdr, 8);
4573 if (unlikely(!p))
4574 goto out_overflow;
4575 xdr_decode_hyper(p, res);
4576 }
4577 return 0;
4578out_overflow:
4579 print_overflow_msg(__func__, xdr);
4580 return -EIO;
4581}
4582
4583static int decode_first_threshold_item4(struct xdr_stream *xdr,
4584 struct nfs4_threshold *res)
4585{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004586 __be32 *p;
4587 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004588 uint32_t bitmap[3] = {0,}, attrlen;
4589 int status;
4590
4591 /* layout type */
4592 p = xdr_inline_decode(xdr, 4);
4593 if (unlikely(!p)) {
4594 print_overflow_msg(__func__, xdr);
4595 return -EIO;
4596 }
4597 res->l_type = be32_to_cpup(p);
4598
4599 /* thi_hintset bitmap */
4600 status = decode_attr_bitmap(xdr, bitmap);
4601 if (status < 0)
4602 goto xdr_error;
4603
4604 /* thi_hintlist length */
4605 status = decode_attr_length(xdr, &attrlen, &savep);
4606 if (status < 0)
4607 goto xdr_error;
4608 /* thi_hintlist */
4609 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4610 if (status < 0)
4611 goto xdr_error;
4612 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4613 if (status < 0)
4614 goto xdr_error;
4615 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4616 THRESHOLD_RD_IO);
4617 if (status < 0)
4618 goto xdr_error;
4619 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4620 THRESHOLD_WR_IO);
4621 if (status < 0)
4622 goto xdr_error;
4623
4624 status = verify_attr_len(xdr, savep, attrlen);
4625 res->bm = bitmap[0];
4626
4627 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4628 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4629 res->wr_io_sz);
4630xdr_error:
4631 dprintk("%s ret=%d!\n", __func__, status);
4632 return status;
4633}
4634
4635/*
4636 * Thresholds on pNFS direct I/O vrs MDS I/O
4637 */
4638static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4639 uint32_t *bitmap,
4640 struct nfs4_threshold *res)
4641{
4642 __be32 *p;
4643 int status = 0;
4644 uint32_t num;
4645
4646 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4647 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004648 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004649 /* Did the server return an unrequested attribute? */
4650 if (unlikely(res == NULL))
4651 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004652 p = xdr_inline_decode(xdr, 4);
4653 if (unlikely(!p))
4654 goto out_overflow;
4655 num = be32_to_cpup(p);
4656 if (num == 0)
4657 return 0;
4658 if (num > 1)
4659 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4660 "drivers per filesystem not supported\n",
4661 __func__);
4662
4663 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004664 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004665 }
4666 return status;
4667out_overflow:
4668 print_overflow_msg(__func__, xdr);
4669 return -EIO;
4670}
4671
Bryan Schumakerae42c702010-10-21 16:33:17 -04004672static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4673 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004674 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004675 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676{
Trond Myklebustbca79472009-03-11 14:10:26 -04004677 int status;
4678 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004679 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004680 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004681
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004682 status = decode_attr_type(xdr, bitmap, &type);
4683 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004685 fattr->mode = 0;
4686 if (status != 0) {
4687 fattr->mode |= nfs_type2fmt[type];
4688 fattr->valid |= status;
4689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004691 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4692 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004694 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004695
4696 status = decode_attr_size(xdr, bitmap, &fattr->size);
4697 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004699 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004700
4701 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4702 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004704 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004705
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004706 err = 0;
4707 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004708 if (status < 0)
4709 goto xdr_error;
4710
4711 status = decode_attr_filehandle(xdr, bitmap, fh);
4712 if (status < 0)
4713 goto xdr_error;
4714
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004715 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4716 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004718 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004719
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004720 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004721 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004722 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004723 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004724
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004725 status = -EIO;
4726 if (unlikely(bitmap[0]))
4727 goto xdr_error;
4728
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004729 status = decode_attr_mode(xdr, bitmap, &fmode);
4730 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004732 if (status != 0) {
4733 fattr->mode |= fmode;
4734 fattr->valid |= status;
4735 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004736
4737 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4738 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004740 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004741
Trond Myklebust6926afd2012-01-07 13:22:46 -05004742 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004743 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004744 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004745 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004746
Trond Myklebust6926afd2012-01-07 13:22:46 -05004747 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004748 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004749 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004750 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004751
4752 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4753 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004754 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004755 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004756
4757 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4758 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004759 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004760 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004761
4762 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4763 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004765 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004766
4767 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4768 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004769 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004770 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004771
4772 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4773 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004774 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004775 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004776
Trond Myklebust28331a42011-04-27 13:47:52 -04004777 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004778 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004779 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004780 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004781
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004782 status = -EIO;
4783 if (unlikely(bitmap[1]))
4784 goto xdr_error;
4785
Andy Adamson88034c32012-05-23 05:02:34 -04004786 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4787 if (status < 0)
4788 goto xdr_error;
4789
David Quigleyaa9c2662013-05-22 12:50:44 -04004790 if (label) {
4791 status = decode_attr_security_label(xdr, bitmap, label);
4792 if (status < 0)
4793 goto xdr_error;
4794 fattr->valid |= status;
4795 }
4796
Bryan Schumakerae42c702010-10-21 16:33:17 -04004797xdr_error:
4798 dprintk("%s: xdr returned %d\n", __func__, -status);
4799 return status;
4800}
4801
4802static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004803 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004804 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004805{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004806 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004807 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004808 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004809 int status;
4810
4811 status = decode_op_hdr(xdr, OP_GETATTR);
4812 if (status < 0)
4813 goto xdr_error;
4814
4815 status = decode_attr_bitmap(xdr, bitmap);
4816 if (status < 0)
4817 goto xdr_error;
4818
4819 status = decode_attr_length(xdr, &attrlen, &savep);
4820 if (status < 0)
4821 goto xdr_error;
4822
David Quigleyaa9c2662013-05-22 12:50:44 -04004823 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4824 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004825 if (status < 0)
4826 goto xdr_error;
4827
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004828 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004829xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004830 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004831 return status;
4832}
4833
David Quigleyaa9c2662013-05-22 12:50:44 -04004834static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4835 struct nfs4_label *label, const struct nfs_server *server)
4836{
4837 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4838}
4839
Bryan Schumakerae42c702010-10-21 16:33:17 -04004840static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004841 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004842{
David Quigleyaa9c2662013-05-22 12:50:44 -04004843 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004844}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004845
Andy Adamson504913f2010-10-20 00:17:57 -04004846/*
Jeff Layton3132e492016-08-10 15:58:24 -04004847 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004848 */
Jeff Layton3132e492016-08-10 15:58:24 -04004849static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004850 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004851{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004852 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004853 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004854
4855 p = xdr_inline_decode(xdr, 4);
4856 if (unlikely(!p))
4857 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004858 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004859
4860 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004861 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004862 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004863
4864 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004865 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004866 if (unlikely(!p))
4867 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004868
4869 /* If we get too many, then just cap it at the max */
4870 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4871 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4872 __func__, fsinfo->nlayouttypes);
4873 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4874 }
4875
4876 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4877 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004878 return 0;
4879out_overflow:
4880 print_overflow_msg(__func__, xdr);
4881 return -EIO;
4882}
4883
4884/*
4885 * The type of file system exported.
4886 * Note we must ensure that layouttype is set in any non-error case.
4887 */
4888static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004889 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004890{
4891 int status = 0;
4892
4893 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4894 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4895 return -EIO;
4896 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004897 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004898 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004899 }
Andy Adamson504913f2010-10-20 00:17:57 -04004900 return status;
4901}
4902
Fred Isamandae100c2011-07-30 20:52:37 -04004903/*
4904 * The prefered block size for layout directed io
4905 */
4906static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4907 uint32_t *res)
4908{
4909 __be32 *p;
4910
4911 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4912 *res = 0;
4913 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4914 p = xdr_inline_decode(xdr, 4);
4915 if (unlikely(!p)) {
4916 print_overflow_msg(__func__, xdr);
4917 return -EIO;
4918 }
4919 *res = be32_to_cpup(p);
4920 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4921 }
4922 return 0;
4923}
4924
Peng Tao2a92ee92015-09-26 02:24:37 +08004925/*
4926 * The granularity of a CLONE operation.
4927 */
4928static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4929 uint32_t *res)
4930{
4931 __be32 *p;
4932
4933 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4934 *res = 0;
4935 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4936 p = xdr_inline_decode(xdr, 4);
4937 if (unlikely(!p)) {
4938 print_overflow_msg(__func__, xdr);
4939 return -EIO;
4940 }
4941 *res = be32_to_cpup(p);
4942 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4943 }
4944 return 0;
4945}
4946
Linus Torvalds1da177e2005-04-16 15:20:36 -07004947static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4948{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004949 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004950 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004951 int status;
4952
4953 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4954 goto xdr_error;
4955 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4956 goto xdr_error;
4957 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4958 goto xdr_error;
4959
4960 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4961
4962 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4963 goto xdr_error;
4964 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4965 goto xdr_error;
4966 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4967 goto xdr_error;
4968 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4969 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4970 goto xdr_error;
4971 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004972
4973 status = -EIO;
4974 if (unlikely(bitmap[0]))
4975 goto xdr_error;
4976
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004977 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4978 if (status != 0)
4979 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004980 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004981 if (status != 0)
4982 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004983
4984 status = -EIO;
4985 if (unlikely(bitmap[1]))
4986 goto xdr_error;
4987
Fred Isamandae100c2011-07-30 20:52:37 -04004988 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4989 if (status)
4990 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004991 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4992 if (status)
4993 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994
4995 status = verify_attr_len(xdr, savep, attrlen);
4996xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004997 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 return status;
4999}
5000
5001static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
5002{
Al Viro8687b632006-10-19 23:28:48 -07005003 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005004 uint32_t len;
5005 int status;
5006
Trond Myklebust99367812007-07-17 21:52:41 -04005007 /* Zero handle first to allow comparisons */
5008 memset(fh, 0, sizeof(*fh));
5009
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010 status = decode_op_hdr(xdr, OP_GETFH);
5011 if (status)
5012 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013
Benny Halevyc0eae662009-08-14 17:20:14 +03005014 p = xdr_inline_decode(xdr, 4);
5015 if (unlikely(!p))
5016 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005017 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 if (len > NFS4_FHSIZE)
5019 return -EIO;
5020 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03005021 p = xdr_inline_decode(xdr, len);
5022 if (unlikely(!p))
5023 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03005024 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005026out_overflow:
5027 print_overflow_msg(__func__, xdr);
5028 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005029}
5030
5031static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5032{
5033 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005034
Linus Torvalds1da177e2005-04-16 15:20:36 -07005035 status = decode_op_hdr(xdr, OP_LINK);
5036 if (status)
5037 return status;
5038 return decode_change_info(xdr, cinfo);
5039}
5040
5041/*
5042 * We create the owner, so we know a proper owner.id length is 4.
5043 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005044static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005046 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07005047 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005048 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005049
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005050 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03005051 if (unlikely(!p))
5052 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005053 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03005054 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005055 type = be32_to_cpup(p++); /* 4 byte read */
5056 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005057 fl->fl_start = (loff_t)offset;
5058 fl->fl_end = fl->fl_start + (loff_t)length - 1;
5059 if (length == ~(uint64_t)0)
5060 fl->fl_end = OFFSET_MAX;
5061 fl->fl_type = F_WRLCK;
5062 if (type & 1)
5063 fl->fl_type = F_RDLCK;
5064 fl->fl_pid = 0;
5065 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005066 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5067 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5068 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03005069 if (likely(p))
5070 return -NFS4ERR_DENIED;
5071out_overflow:
5072 print_overflow_msg(__func__, xdr);
5073 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074}
5075
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005076static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078 int status;
5079
5080 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005081 if (status == -EIO)
5082 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04005084 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005085 if (unlikely(status))
5086 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04005088 status = decode_lock_denied(xdr, NULL);
5089 if (res->open_seqid != NULL)
5090 nfs_increment_open_seqid(status, res->open_seqid);
5091 nfs_increment_lock_seqid(status, res->lock_seqid);
5092out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093 return status;
5094}
5095
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005096static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005097{
5098 int status;
5099 status = decode_op_hdr(xdr, OP_LOCKT);
5100 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005101 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 return status;
5103}
5104
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005105static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005107 int status;
5108
5109 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005110 if (status != -EIO)
5111 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005112 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005113 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005114 return status;
5115}
5116
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005117static int decode_release_lockowner(struct xdr_stream *xdr)
5118{
5119 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5120}
5121
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122static int decode_lookup(struct xdr_stream *xdr)
5123{
5124 return decode_op_hdr(xdr, OP_LOOKUP);
5125}
5126
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005127static int decode_lookupp(struct xdr_stream *xdr)
5128{
5129 return decode_op_hdr(xdr, OP_LOOKUPP);
5130}
5131
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005133static int decode_space_limit(struct xdr_stream *xdr,
5134 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005135{
Andy Adamson05d564f2008-12-23 16:06:15 -05005136 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005138 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005139
Benny Halevyc0eae662009-08-14 17:20:14 +03005140 p = xdr_inline_decode(xdr, 12);
5141 if (unlikely(!p))
5142 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005143 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005145 case NFS4_LIMIT_SIZE:
5146 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005147 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005148 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005149 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005150 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005151 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005153 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005154 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005156out_overflow:
5157 print_overflow_msg(__func__, xdr);
5158 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159}
5160
Trond Myklebust6ae37332015-01-30 14:21:14 -05005161static int decode_rw_delegation(struct xdr_stream *xdr,
5162 uint32_t delegation_type,
5163 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164{
Andy Adamson05d564f2008-12-23 16:06:15 -05005165 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005166 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005167
Trond Myklebust93b717f2016-05-16 17:42:43 -04005168 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005169 if (unlikely(status))
5170 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005171 p = xdr_inline_decode(xdr, 4);
5172 if (unlikely(!p))
5173 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005174 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005175
Linus Torvalds1da177e2005-04-16 15:20:36 -07005176 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005177 case NFS4_OPEN_DELEGATE_READ:
5178 res->delegation_type = FMODE_READ;
5179 break;
5180 case NFS4_OPEN_DELEGATE_WRITE:
5181 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005182 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183 return -EIO;
5184 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005185 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005186out_overflow:
5187 print_overflow_msg(__func__, xdr);
5188 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005189}
5190
Trond Myklebust6ae37332015-01-30 14:21:14 -05005191static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5192{
5193 __be32 *p;
5194 uint32_t why_no_delegation;
5195
5196 p = xdr_inline_decode(xdr, 4);
5197 if (unlikely(!p))
5198 goto out_overflow;
5199 why_no_delegation = be32_to_cpup(p);
5200 switch (why_no_delegation) {
5201 case WND4_CONTENTION:
5202 case WND4_RESOURCE:
5203 xdr_inline_decode(xdr, 4);
5204 /* Ignore for now */
5205 }
5206 return 0;
5207out_overflow:
5208 print_overflow_msg(__func__, xdr);
5209 return -EIO;
5210}
5211
5212static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5213{
5214 __be32 *p;
5215 uint32_t delegation_type;
5216
5217 p = xdr_inline_decode(xdr, 4);
5218 if (unlikely(!p))
5219 goto out_overflow;
5220 delegation_type = be32_to_cpup(p);
5221 res->delegation_type = 0;
5222 switch (delegation_type) {
5223 case NFS4_OPEN_DELEGATE_NONE:
5224 return 0;
5225 case NFS4_OPEN_DELEGATE_READ:
5226 case NFS4_OPEN_DELEGATE_WRITE:
5227 return decode_rw_delegation(xdr, delegation_type, res);
5228 case NFS4_OPEN_DELEGATE_NONE_EXT:
5229 return decode_no_delegation(xdr, res);
5230 }
5231 return -EIO;
5232out_overflow:
5233 print_overflow_msg(__func__, xdr);
5234 return -EIO;
5235}
5236
Linus Torvalds1da177e2005-04-16 15:20:36 -07005237static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5238{
Andy Adamson05d564f2008-12-23 16:06:15 -05005239 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005240 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005241 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242
Trond Myklebustc7848f62013-12-04 17:39:23 -05005243 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5244 return status;
5245 nfs_increment_open_seqid(status, res->seqid);
5246 if (status)
5247 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005248 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005249 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005250 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005251
Andy Adamson05d564f2008-12-23 16:06:15 -05005252 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253
Benny Halevyc0eae662009-08-14 17:20:14 +03005254 p = xdr_inline_decode(xdr, 8);
5255 if (unlikely(!p))
5256 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005257 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005258 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005259 if (bmlen > 10)
5260 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261
Benny Halevyc0eae662009-08-14 17:20:14 +03005262 p = xdr_inline_decode(xdr, bmlen << 2);
5263 if (unlikely(!p))
5264 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005265 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5266 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005267 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005268 for (; i < NFS4_BITMAP_SIZE; i++)
5269 res->attrset[i] = 0;
5270
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271 return decode_delegation(xdr, res);
5272xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005273 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005275out_overflow:
5276 print_overflow_msg(__func__, xdr);
5277 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278}
5279
5280static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5281{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 int status;
5283
Andy Adamson05d564f2008-12-23 16:06:15 -05005284 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005285 if (status != -EIO)
5286 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005287 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005288 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005289 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290}
5291
5292static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5293{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005294 int status;
5295
5296 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005297 if (status != -EIO)
5298 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005299 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005300 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005301 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302}
5303
5304static int decode_putfh(struct xdr_stream *xdr)
5305{
5306 return decode_op_hdr(xdr, OP_PUTFH);
5307}
5308
5309static int decode_putrootfh(struct xdr_stream *xdr)
5310{
5311 return decode_op_hdr(xdr, OP_PUTROOTFH);
5312}
5313
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005314static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5315 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005316{
Al Viro8687b632006-10-19 23:28:48 -07005317 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005318 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 int status;
5320
5321 status = decode_op_hdr(xdr, OP_READ);
5322 if (status)
5323 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005324 p = xdr_inline_decode(xdr, 8);
5325 if (unlikely(!p))
5326 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005327 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005328 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005329 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005331 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 "count %u > recvd %u\n", count, recvd);
5333 count = recvd;
5334 eof = 0;
5335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005336 res->eof = eof;
5337 res->count = count;
5338 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005339out_overflow:
5340 print_overflow_msg(__func__, xdr);
5341 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342}
5343
5344static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5345{
Chuck Leverbcecff72007-10-26 13:32:03 -04005346 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005347 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348
5349 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005350 if (!status)
5351 status = decode_verifier(xdr, readdir->verifier.data);
5352 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005354 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005355 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005356 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005357 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005358}
5359
5360static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5361{
5362 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005363 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005364 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365 int status;
5366
5367 status = decode_op_hdr(xdr, OP_READLINK);
5368 if (status)
5369 return status;
5370
5371 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005372 p = xdr_inline_decode(xdr, 4);
5373 if (unlikely(!p))
5374 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005375 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005376 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005377 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 return -ENAMETOOLONG;
5379 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005380 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005381 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005382 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005383 "count %u > recvd %u\n", len, recvd);
5384 return -EIO;
5385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386 /*
5387 * The XDR encode routine has set things up so that
5388 * the link text will be copied directly into the
5389 * buffer. We just have to do overflow-checking,
5390 * and and null-terminate the text (the VFS expects
5391 * null-termination).
5392 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005393 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005395out_overflow:
5396 print_overflow_msg(__func__, xdr);
5397 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398}
5399
5400static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5401{
5402 int status;
5403
5404 status = decode_op_hdr(xdr, OP_REMOVE);
5405 if (status)
5406 goto out;
5407 status = decode_change_info(xdr, cinfo);
5408out:
5409 return status;
5410}
5411
5412static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5413 struct nfs4_change_info *new_cinfo)
5414{
5415 int status;
5416
5417 status = decode_op_hdr(xdr, OP_RENAME);
5418 if (status)
5419 goto out;
5420 if ((status = decode_change_info(xdr, old_cinfo)))
5421 goto out;
5422 status = decode_change_info(xdr, new_cinfo);
5423out:
5424 return status;
5425}
5426
5427static int decode_renew(struct xdr_stream *xdr)
5428{
5429 return decode_op_hdr(xdr, OP_RENEW);
5430}
5431
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005432static int
5433decode_restorefh(struct xdr_stream *xdr)
5434{
5435 return decode_op_hdr(xdr, OP_RESTOREFH);
5436}
5437
J. Bruce Fields029d1052005-06-22 17:16:22 +00005438static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005439 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005440{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005441 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005442 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005443 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005444 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005445 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005446
Andy Adamsonbf118a32011-12-07 11:55:27 -05005447 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005448 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5449 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005450
Trond Myklebust519d3952012-08-14 17:30:10 -04005451 xdr_enter_page(xdr, xdr->buf->page_len);
5452
Trond Myklebustcff298c2012-08-14 17:14:17 -04005453 /* Calculate the offset of the page data */
5454 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005455
J. Bruce Fields029d1052005-06-22 17:16:22 +00005456 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5457 goto out;
5458 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5459 goto out;
5460
5461 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5462 return -EIO;
5463 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005464
Andy Adamsonbf118a32011-12-07 11:55:27 -05005465 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5466 * are stored with the acl data to handle the problem of
5467 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005468 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005469 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005470
5471 /* Check for receive buffer overflow */
5472 if (res->acl_len > (xdr->nwords << 2) ||
5473 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5474 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005475 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005476 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005477 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005478 } else
5479 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005480
5481out:
5482 return status;
5483}
5484
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485static int
5486decode_savefh(struct xdr_stream *xdr)
5487{
5488 return decode_op_hdr(xdr, OP_SAVEFH);
5489}
5490
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005491static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005492{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493 int status;
5494
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 status = decode_op_hdr(xdr, OP_SETATTR);
5496 if (status)
5497 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005498 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005499 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005500 print_overflow_msg(__func__, xdr);
5501 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005502}
5503
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005504static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005505{
Al Viro8687b632006-10-19 23:28:48 -07005506 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507 uint32_t opnum;
5508 int32_t nfserr;
5509
Benny Halevyc0eae662009-08-14 17:20:14 +03005510 p = xdr_inline_decode(xdr, 8);
5511 if (unlikely(!p))
5512 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005513 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005515 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005516 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517 return -EIO;
5518 }
Benny Halevycccddf42009-08-14 17:20:19 +03005519 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005521 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5522 if (unlikely(!p))
5523 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005524 p = xdr_decode_hyper(p, &res->clientid);
5525 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526 } else if (nfserr == NFSERR_CLID_INUSE) {
5527 uint32_t len;
5528
5529 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005530 p = xdr_inline_decode(xdr, 4);
5531 if (unlikely(!p))
5532 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005533 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005534 p = xdr_inline_decode(xdr, len);
5535 if (unlikely(!p))
5536 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005537
5538 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005539 p = xdr_inline_decode(xdr, 4);
5540 if (unlikely(!p))
5541 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005542 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005543 p = xdr_inline_decode(xdr, len);
5544 if (unlikely(!p))
5545 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546 return -NFSERR_CLID_INUSE;
5547 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005548 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549
5550 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005551out_overflow:
5552 print_overflow_msg(__func__, xdr);
5553 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005554}
5555
5556static int decode_setclientid_confirm(struct xdr_stream *xdr)
5557{
5558 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5559}
5560
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005561static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562{
Al Viro8687b632006-10-19 23:28:48 -07005563 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005564 int status;
5565
5566 status = decode_op_hdr(xdr, OP_WRITE);
5567 if (status)
5568 return status;
5569
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005570 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005571 if (unlikely(!p))
5572 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005573 res->count = be32_to_cpup(p++);
5574 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005575 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005576out_overflow:
5577 print_overflow_msg(__func__, xdr);
5578 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579}
5580
5581static int decode_delegreturn(struct xdr_stream *xdr)
5582{
5583 return decode_op_hdr(xdr, OP_DELEGRETURN);
5584}
5585
Chuck Leverfb15b262013-03-16 15:54:34 -04005586static int decode_secinfo_gss(struct xdr_stream *xdr,
5587 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005588{
Chuck Leverfb15b262013-03-16 15:54:34 -04005589 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005590 __be32 *p;
5591
5592 p = xdr_inline_decode(xdr, 4);
5593 if (unlikely(!p))
5594 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005595 oid_len = be32_to_cpup(p);
5596 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005597 goto out_err;
5598
Chuck Leverfb15b262013-03-16 15:54:34 -04005599 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005600 if (unlikely(!p))
5601 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005602 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5603 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005604
5605 p = xdr_inline_decode(xdr, 8);
5606 if (unlikely(!p))
5607 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005608 flavor->flavor_info.qop = be32_to_cpup(p++);
5609 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005610
5611 return 0;
5612
5613out_overflow:
5614 print_overflow_msg(__func__, xdr);
5615 return -EIO;
5616out_err:
5617 return -EINVAL;
5618}
5619
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005620static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005621{
Chuck Leverfb15b262013-03-16 15:54:34 -04005622 struct nfs4_secinfo4 *sec_flavor;
5623 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005624 int status;
5625 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005626
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005627 p = xdr_inline_decode(xdr, 4);
5628 if (unlikely(!p))
5629 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005630
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005631 res->flavors->num_flavors = 0;
5632 num_flavors = be32_to_cpup(p);
5633
5634 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005635 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005636 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005637 break;
5638
5639 p = xdr_inline_decode(xdr, 4);
5640 if (unlikely(!p))
5641 goto out_overflow;
5642 sec_flavor->flavor = be32_to_cpup(p);
5643
5644 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005645 status = decode_secinfo_gss(xdr, sec_flavor);
5646 if (status)
5647 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005648 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005649 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005650 }
5651
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005652 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005653out:
5654 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005655out_overflow:
5656 print_overflow_msg(__func__, xdr);
5657 return -EIO;
5658}
5659
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005660static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5661{
5662 int status = decode_op_hdr(xdr, OP_SECINFO);
5663 if (status)
5664 return status;
5665 return decode_secinfo_common(xdr, res);
5666}
5667
Benny Halevy99fe60d2009-04-01 09:22:29 -04005668#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005669static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5670{
5671 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5672 if (status)
5673 return status;
5674 return decode_secinfo_common(xdr, res);
5675}
5676
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005677static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5678{
5679 __be32 *p;
5680 uint32_t bitmap_words;
5681 unsigned int i;
5682
5683 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005684 if (!p)
5685 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005686 bitmap_words = be32_to_cpup(p++);
5687 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5688 return -EIO;
5689 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5690 for (i = 0; i < bitmap_words; i++)
5691 op_map->u.words[i] = be32_to_cpup(p++);
5692
5693 return 0;
5694}
5695
Benny Halevy99fe60d2009-04-01 09:22:29 -04005696static int decode_exchange_id(struct xdr_stream *xdr,
5697 struct nfs41_exchange_id_res *res)
5698{
5699 __be32 *p;
5700 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005701 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005702 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005703 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005704
5705 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5706 if (status)
5707 return status;
5708
Benny Halevyc0eae662009-08-14 17:20:14 +03005709 p = xdr_inline_decode(xdr, 8);
5710 if (unlikely(!p))
5711 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005712 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005713 p = xdr_inline_decode(xdr, 12);
5714 if (unlikely(!p))
5715 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005716 res->seqid = be32_to_cpup(p++);
5717 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005718
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005719 res->state_protect.how = be32_to_cpup(p);
5720 switch (res->state_protect.how) {
5721 case SP4_NONE:
5722 break;
5723 case SP4_MACH_CRED:
5724 status = decode_op_map(xdr, &res->state_protect.enforce);
5725 if (status)
5726 return status;
5727 status = decode_op_map(xdr, &res->state_protect.allow);
5728 if (status)
5729 return status;
5730 break;
5731 default:
5732 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005733 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005734 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005735
Chuck Leveracdeb692012-05-21 22:46:16 -04005736 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005737 p = xdr_inline_decode(xdr, 8);
5738 if (unlikely(!p))
5739 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005740 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005741
Chuck Leveracdeb692012-05-21 22:46:16 -04005742 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005743 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5744 if (unlikely(status))
5745 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005746 memcpy(res->server_owner->major_id, dummy_str, dummy);
5747 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005748
Chuck Leveracdeb692012-05-21 22:46:16 -04005749 /* server_scope4 */
5750 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5751 if (unlikely(status))
5752 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005753 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5754 res->server_scope->server_scope_sz = dummy;
5755
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005756 /* Implementation Id */
5757 p = xdr_inline_decode(xdr, 4);
5758 if (unlikely(!p))
5759 goto out_overflow;
5760 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005761
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005762 if (impl_id_count) {
5763 /* nii_domain */
5764 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5765 if (unlikely(status))
5766 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005767 memcpy(res->impl_id->domain, dummy_str, dummy);
5768
5769 /* nii_name */
5770 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5771 if (unlikely(status))
5772 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005773 memcpy(res->impl_id->name, dummy_str, dummy);
5774
5775 /* nii_date */
5776 p = xdr_inline_decode(xdr, 12);
5777 if (unlikely(!p))
5778 goto out_overflow;
5779 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5780 res->impl_id->date.nseconds = be32_to_cpup(p);
5781
5782 /* if there's more than one entry, ignore the rest */
5783 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005784 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005785out_overflow:
5786 print_overflow_msg(__func__, xdr);
5787 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005788}
Andy Adamsonfc931582009-04-01 09:22:31 -04005789
5790static int decode_chan_attrs(struct xdr_stream *xdr,
5791 struct nfs4_channel_attrs *attrs)
5792{
5793 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005794 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005795
Benny Halevyc0eae662009-08-14 17:20:14 +03005796 p = xdr_inline_decode(xdr, 28);
5797 if (unlikely(!p))
5798 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005799 val = be32_to_cpup(p++); /* headerpadsz */
5800 if (val)
5801 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005802 attrs->max_rqst_sz = be32_to_cpup(p++);
5803 attrs->max_resp_sz = be32_to_cpup(p++);
5804 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5805 attrs->max_ops = be32_to_cpup(p++);
5806 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005807 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005808 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005809 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5810 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005811 return -EINVAL;
5812 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005813 if (nr_attrs == 1) {
5814 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5815 if (unlikely(!p))
5816 goto out_overflow;
5817 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005818 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005819out_overflow:
5820 print_overflow_msg(__func__, xdr);
5821 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005822}
5823
Benny Halevye78291e2009-08-14 17:20:00 +03005824static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5825{
5826 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005827}
5828
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005829static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5830 struct nfs41_bind_conn_to_session_res *res)
5831{
5832 __be32 *p;
5833 int status;
5834
5835 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5836 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005837 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005838 if (unlikely(status))
5839 return status;
5840
5841 /* dir flags, rdma mode bool */
5842 p = xdr_inline_decode(xdr, 8);
5843 if (unlikely(!p))
5844 goto out_overflow;
5845
5846 res->dir = be32_to_cpup(p++);
5847 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5848 return -EIO;
5849 if (be32_to_cpup(p) == 0)
5850 res->use_conn_in_rdma_mode = false;
5851 else
5852 res->use_conn_in_rdma_mode = true;
5853
5854 return 0;
5855out_overflow:
5856 print_overflow_msg(__func__, xdr);
5857 return -EIO;
5858}
5859
Andy Adamsonfc931582009-04-01 09:22:31 -04005860static int decode_create_session(struct xdr_stream *xdr,
5861 struct nfs41_create_session_res *res)
5862{
5863 __be32 *p;
5864 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005865
5866 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005867 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005868 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005869 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005870 return status;
5871
Andy Adamsonfc931582009-04-01 09:22:31 -04005872 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005873 p = xdr_inline_decode(xdr, 8);
5874 if (unlikely(!p))
5875 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005876 res->seqid = be32_to_cpup(p++);
5877 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005878
5879 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005880 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005881 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005882 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005883 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005884out_overflow:
5885 print_overflow_msg(__func__, xdr);
5886 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005887}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005888
5889static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5890{
5891 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5892}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005893
Trond Myklebust66245532012-05-25 17:18:09 -04005894static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5895{
5896 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5897}
5898
Ricardo Labiaga180197532009-12-05 16:08:40 -05005899static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5900{
5901 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5902}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005903#endif /* CONFIG_NFS_V4_1 */
5904
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005905static int decode_sequence(struct xdr_stream *xdr,
5906 struct nfs4_sequence_res *res,
5907 struct rpc_rqst *rqstp)
5908{
5909#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005910 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005911 struct nfs4_sessionid id;
5912 u32 dummy;
5913 int status;
5914 __be32 *p;
5915
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005916 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005917 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005918 if (!res->sr_slot->table->session)
5919 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005920
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005921 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005922 if (!status)
5923 status = decode_sessionid(xdr, &id);
5924 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005925 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005926
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005927 /*
5928 * If the server returns different values for sessionID, slotID or
5929 * sequence number, the server is looney tunes.
5930 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005931 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005932 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005933
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005934 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005935 NFS4_MAX_SESSIONID_LEN)) {
5936 dprintk("%s Invalid session id\n", __func__);
5937 goto out_err;
5938 }
Benny Halevye78291e2009-08-14 17:20:00 +03005939
Benny Halevyc0eae662009-08-14 17:20:14 +03005940 p = xdr_inline_decode(xdr, 20);
5941 if (unlikely(!p))
5942 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005943
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005944 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005945 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005946 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005947 dprintk("%s Invalid sequence number\n", __func__);
5948 goto out_err;
5949 }
5950 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005951 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005952 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005953 dprintk("%s Invalid slot id\n", __func__);
5954 goto out_err;
5955 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005956 /* highest slot id */
5957 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005958 /* target highest slot id */
5959 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005960 /* result flags */
5961 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005962 status = 0;
5963out_err:
5964 res->sr_status = status;
5965 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005966out_overflow:
5967 print_overflow_msg(__func__, xdr);
5968 status = -EIO;
5969 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005970#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005971 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005972#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005973}
5974
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005975#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005976static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5977{
5978 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5979 return decode_stateid(xdr, stateid);
5980}
5981
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005982static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005983 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005984{
Trond Myklebust4e590802015-03-09 14:01:25 -04005985 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005986 __be32 *p;
5987 uint32_t len, type;
5988 int status;
5989
5990 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5991 if (status) {
5992 if (status == -ETOOSMALL) {
5993 p = xdr_inline_decode(xdr, 4);
5994 if (unlikely(!p))
5995 goto out_overflow;
5996 pdev->mincount = be32_to_cpup(p);
5997 dprintk("%s: Min count too small. mincnt = %u\n",
5998 __func__, pdev->mincount);
5999 }
6000 return status;
6001 }
6002
6003 p = xdr_inline_decode(xdr, 8);
6004 if (unlikely(!p))
6005 goto out_overflow;
6006 type = be32_to_cpup(p++);
6007 if (type != pdev->layout_type) {
6008 dprintk("%s: layout mismatch req: %u pdev: %u\n",
6009 __func__, pdev->layout_type, type);
6010 return -EINVAL;
6011 }
6012 /*
6013 * Get the length of the opaque device_addr4. xdr_read_pages places
6014 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
6015 * and places the remaining xdr data in xdr_buf->tail
6016 */
6017 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04006018 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
6019 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006020
6021 /* Parse notification bitmap, verifying that it is zero. */
6022 p = xdr_inline_decode(xdr, 4);
6023 if (unlikely(!p))
6024 goto out_overflow;
6025 len = be32_to_cpup(p);
6026 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00006027 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006028
6029 p = xdr_inline_decode(xdr, 4 * len);
6030 if (unlikely(!p))
6031 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006032
Trond Myklebust4e590802015-03-09 14:01:25 -04006033 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006034 for (i = 1; i < len; i++) {
6035 if (be32_to_cpup(p++)) {
6036 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006037 __func__);
6038 return -EIO;
6039 }
6040 }
6041 }
6042 return 0;
6043out_overflow:
6044 print_overflow_msg(__func__, xdr);
6045 return -EIO;
6046}
6047
6048static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6049 struct nfs4_layoutget_res *res)
6050{
6051 __be32 *p;
6052 int status;
6053 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04006054 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006055
6056 status = decode_op_hdr(xdr, OP_LAYOUTGET);
6057 if (status)
Fred Isaman808ba322016-10-04 15:02:21 -04006058 goto out;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006059 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006060 if (unlikely(!p))
6061 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006062 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04006063 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006064 p = xdr_inline_decode(xdr, 4);
6065 if (unlikely(!p))
6066 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006067 layout_count = be32_to_cpup(p);
6068 if (!layout_count) {
6069 dprintk("%s: server responded with empty layout array\n",
6070 __func__);
Fred Isaman808ba322016-10-04 15:02:21 -04006071 status = -EINVAL;
6072 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006073 }
6074
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006075 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006076 if (unlikely(!p))
6077 goto out_overflow;
6078 p = xdr_decode_hyper(p, &res->range.offset);
6079 p = xdr_decode_hyper(p, &res->range.length);
6080 res->range.iomode = be32_to_cpup(p++);
6081 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006082 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006083
6084 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6085 __func__,
6086 (unsigned long)res->range.offset,
6087 (unsigned long)res->range.length,
6088 res->range.iomode,
6089 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006090 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006091
Trond Myklebust64bd5772012-06-20 22:35:05 -04006092 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006093 if (res->layoutp->len > recvd) {
6094 dprintk("NFS: server cheating in layoutget reply: "
6095 "layout len %u > recvd %u\n",
6096 res->layoutp->len, recvd);
Fred Isaman808ba322016-10-04 15:02:21 -04006097 status = -EINVAL;
6098 goto out;
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006099 }
6100
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006101 if (layout_count > 1) {
6102 /* We only handle a length one array at the moment. Any
6103 * further entries are just ignored. Note that this means
6104 * the client may see a response that is less than the
6105 * minimum it requested.
6106 */
6107 dprintk("%s: server responded with %d layouts, dropping tail\n",
6108 __func__, layout_count);
6109 }
6110
Fred Isaman808ba322016-10-04 15:02:21 -04006111out:
6112 res->status = status;
6113 return status;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006114out_overflow:
6115 print_overflow_msg(__func__, xdr);
Fred Isaman808ba322016-10-04 15:02:21 -04006116 status = -EIO;
6117 goto out;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006118}
Andy Adamson863a3c62011-03-23 13:27:54 +00006119
Benny Halevycbe82602011-05-22 19:52:37 +03006120static int decode_layoutreturn(struct xdr_stream *xdr,
6121 struct nfs4_layoutreturn_res *res)
6122{
6123 __be32 *p;
6124 int status;
6125
6126 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6127 if (status)
6128 return status;
6129 p = xdr_inline_decode(xdr, 4);
6130 if (unlikely(!p))
6131 goto out_overflow;
6132 res->lrs_present = be32_to_cpup(p);
6133 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006134 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05006135 else
6136 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006137 return status;
6138out_overflow:
6139 print_overflow_msg(__func__, xdr);
6140 return -EIO;
6141}
6142
Andy Adamson863a3c62011-03-23 13:27:54 +00006143static int decode_layoutcommit(struct xdr_stream *xdr,
6144 struct rpc_rqst *req,
6145 struct nfs4_layoutcommit_res *res)
6146{
6147 __be32 *p;
6148 __u32 sizechanged;
6149 int status;
6150
6151 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006152 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006153 if (status)
6154 return status;
6155
6156 p = xdr_inline_decode(xdr, 4);
6157 if (unlikely(!p))
6158 goto out_overflow;
6159 sizechanged = be32_to_cpup(p);
6160
6161 if (sizechanged) {
6162 /* throw away new size */
6163 p = xdr_inline_decode(xdr, 8);
6164 if (unlikely(!p))
6165 goto out_overflow;
6166 }
6167 return 0;
6168out_overflow:
6169 print_overflow_msg(__func__, xdr);
6170 return -EIO;
6171}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006172
6173static int decode_test_stateid(struct xdr_stream *xdr,
6174 struct nfs41_test_stateid_res *res)
6175{
6176 __be32 *p;
6177 int status;
6178 int num_res;
6179
6180 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6181 if (status)
6182 return status;
6183
6184 p = xdr_inline_decode(xdr, 4);
6185 if (unlikely(!p))
6186 goto out_overflow;
6187 num_res = be32_to_cpup(p++);
6188 if (num_res != 1)
6189 goto out;
6190
6191 p = xdr_inline_decode(xdr, 4);
6192 if (unlikely(!p))
6193 goto out_overflow;
6194 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006195
6196 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006197out_overflow:
6198 print_overflow_msg(__func__, xdr);
6199out:
6200 return -EIO;
6201}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006202
6203static int decode_free_stateid(struct xdr_stream *xdr,
6204 struct nfs41_free_stateid_res *res)
6205{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006206 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006207 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006208}
Trond Myklebustcf805162016-11-15 14:56:07 -05006209#else
6210static inline
6211int decode_layoutreturn(struct xdr_stream *xdr,
6212 struct nfs4_layoutreturn_res *res)
6213{
6214 return 0;
6215}
Fred Isaman56f487f2016-09-21 11:43:41 -04006216
6217static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6218 struct nfs4_layoutget_res *res)
6219{
6220 return 0;
6221}
6222
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006223#endif /* CONFIG_NFS_V4_1 */
6224
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225/*
Benny Halevy49c25592008-12-23 16:06:16 -05006226 * END OF "GENERIC" DECODE ROUTINES.
6227 */
6228
6229/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230 * Decode OPEN_DOWNGRADE response
6231 */
Chuck Leverbf269552010-12-14 14:59:29 +00006232static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6233 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006234 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006236 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006237 struct compound_hdr hdr;
6238 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239
Chuck Leverbf269552010-12-14 14:59:29 +00006240 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006241 if (status)
6242 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006243 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006244 if (status)
6245 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006247 if (status)
6248 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006249 if (res->lr_res) {
6250 status = decode_layoutreturn(xdr, res->lr_res);
6251 res->lr_ret = status;
6252 if (status)
6253 goto out;
6254 }
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006256out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006257 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258}
6259
6260/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006261 * Decode ACCESS response
6262 */
Chuck Leverbf269552010-12-14 14:59:29 +00006263static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006264 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006266 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006267 struct compound_hdr hdr;
6268 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006269
Chuck Leverbf269552010-12-14 14:59:29 +00006270 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006271 if (status)
6272 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006273 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006274 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006275 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006276 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006277 if (status != 0)
6278 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006279 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006280 if (status != 0)
6281 goto out;
Trond Myklebust8bcbe7d2018-03-20 17:03:11 -04006282 if (res->fattr)
6283 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006284out:
6285 return status;
6286}
6287
6288/*
6289 * Decode LOOKUP response
6290 */
Chuck Leverbf269552010-12-14 14:59:29 +00006291static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006292 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006293{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006294 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 struct compound_hdr hdr;
6296 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006297
Chuck Leverbf269552010-12-14 14:59:29 +00006298 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006299 if (status)
6300 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006301 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006302 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006304 status = decode_putfh(xdr);
6305 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006306 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006307 status = decode_lookup(xdr);
6308 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006310 status = decode_getfh(xdr, res->fh);
6311 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006312 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006313 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006314out:
6315 return status;
6316}
6317
6318/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006319 * Decode LOOKUPP response
6320 */
6321static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6322 void *data)
6323{
6324 struct nfs4_lookupp_res *res = data;
6325 struct compound_hdr hdr;
6326 int status;
6327
6328 status = decode_compound_hdr(xdr, &hdr);
6329 if (status)
6330 goto out;
6331 status = decode_sequence(xdr, &res->seq_res, rqstp);
6332 if (status)
6333 goto out;
6334 status = decode_putfh(xdr);
6335 if (status)
6336 goto out;
6337 status = decode_lookupp(xdr);
6338 if (status)
6339 goto out;
6340 status = decode_getfh(xdr, res->fh);
6341 if (status)
6342 goto out;
6343 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6344out:
6345 return status;
6346}
6347
6348/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349 * Decode LOOKUP_ROOT response
6350 */
Chuck Leverbf269552010-12-14 14:59:29 +00006351static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6352 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006353 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006354{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006355 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356 struct compound_hdr hdr;
6357 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006358
Chuck Leverbf269552010-12-14 14:59:29 +00006359 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006360 if (status)
6361 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006363 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_putrootfh(xdr);
6366 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_getfh(xdr, res->fh);
6369 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006370 status = decode_getfattr_label(xdr, res->fattr,
6371 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372out:
6373 return status;
6374}
6375
6376/*
6377 * Decode REMOVE response
6378 */
Chuck Leverbf269552010-12-14 14:59:29 +00006379static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006380 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006382 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383 struct compound_hdr hdr;
6384 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006385
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006387 if (status)
6388 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006390 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006392 status = decode_putfh(xdr);
6393 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006396out:
6397 return status;
6398}
6399
6400/*
6401 * Decode RENAME response
6402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006404 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006406 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407 struct compound_hdr hdr;
6408 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006409
Chuck Leverbf269552010-12-14 14:59:29 +00006410 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006411 if (status)
6412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006413 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006414 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_putfh(xdr);
6417 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_savefh(xdr);
6420 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_putfh(xdr);
6423 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426out:
6427 return status;
6428}
6429
6430/*
6431 * Decode LINK response
6432 */
Chuck Leverbf269552010-12-14 14:59:29 +00006433static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006434 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006436 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 struct compound_hdr hdr;
6438 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006439
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006441 if (status)
6442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006444 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_putfh(xdr);
6447 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006449 status = decode_savefh(xdr);
6450 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006452 status = decode_putfh(xdr);
6453 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006454 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006455 status = decode_link(xdr, &res->cinfo);
6456 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006457 goto out;
6458 /*
6459 * Note order: OP_LINK leaves the directory as the current
6460 * filehandle.
6461 */
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_restorefh(xdr);
6463 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006464 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006465 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466out:
6467 return status;
6468}
6469
6470/*
6471 * Decode CREATE response
6472 */
Chuck Leverbf269552010-12-14 14:59:29 +00006473static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006474 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006476 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006477 struct compound_hdr hdr;
6478 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006479
Chuck Leverbf269552010-12-14 14:59:29 +00006480 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006481 if (status)
6482 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006483 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006484 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006486 status = decode_putfh(xdr);
6487 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006488 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006489 status = decode_create(xdr, &res->dir_cinfo);
6490 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006491 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006492 status = decode_getfh(xdr, res->fh);
6493 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006494 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006495 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496out:
6497 return status;
6498}
6499
6500/*
6501 * Decode SYMLINK response
6502 */
Chuck Leverbf269552010-12-14 14:59:29 +00006503static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006504 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505{
Chuck Leverbf269552010-12-14 14:59:29 +00006506 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507}
6508
6509/*
6510 * Decode GETATTR response
6511 */
Chuck Leverbf269552010-12-14 14:59:29 +00006512static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006513 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006514{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006515 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516 struct compound_hdr hdr;
6517 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006518
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520 if (status)
6521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006523 if (status)
6524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006526 if (status)
6527 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006528 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529out:
6530 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531}
6532
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006533/*
6534 * Encode an SETACL request
6535 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006536static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006537 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006538{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006539 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006540 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006541 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006542 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006543
Chuck Lever9f06c712010-12-14 14:59:18 +00006544 encode_compound_hdr(xdr, req, &hdr);
6545 encode_sequence(xdr, &args->seq_args, &hdr);
6546 encode_putfh(xdr, args->fh, &hdr);
6547 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006548 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006549}
Andy Adamson05d564f2008-12-23 16:06:15 -05006550
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006551/*
6552 * Decode SETACL response
6553 */
6554static int
Chuck Leverbf269552010-12-14 14:59:29 +00006555nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006556 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006557{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006558 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006559 struct compound_hdr hdr;
6560 int status;
6561
Chuck Leverbf269552010-12-14 14:59:29 +00006562 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006563 if (status)
6564 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006565 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006566 if (status)
6567 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006568 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006569 if (status)
6570 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006571 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006572out:
6573 return status;
6574}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006575
6576/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006577 * Decode GETACL response
6578 */
6579static int
Chuck Leverbf269552010-12-14 14:59:29 +00006580nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006581 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006582{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006583 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006584 struct compound_hdr hdr;
6585 int status;
6586
Trond Myklebust331818f2012-02-03 18:30:53 -05006587 if (res->acl_scratch != NULL) {
6588 void *p = page_address(res->acl_scratch);
6589 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6590 }
Chuck Leverbf269552010-12-14 14:59:29 +00006591 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006592 if (status)
6593 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006594 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006595 if (status)
6596 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006597 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006598 if (status)
6599 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006600 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006601
6602out:
6603 return status;
6604}
6605
6606/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 * Decode CLOSE response
6608 */
Chuck Leverbf269552010-12-14 14:59:29 +00006609static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006610 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006612 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006613 struct compound_hdr hdr;
6614 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615
Chuck Leverbf269552010-12-14 14:59:29 +00006616 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006617 if (status)
6618 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006620 if (status)
6621 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006622 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006623 if (status)
6624 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006625 if (res->lr_res) {
6626 status = decode_layoutreturn(xdr, res->lr_res);
6627 res->lr_ret = status;
6628 if (status)
6629 goto out;
6630 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006631 if (res->fattr != NULL) {
6632 status = decode_getfattr(xdr, res->fattr, res->server);
6633 if (status != 0)
6634 goto out;
6635 }
Chuck Leverbf269552010-12-14 14:59:29 +00006636 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006638 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006639}
6640
6641/*
6642 * Decode OPEN response
6643 */
Chuck Leverbf269552010-12-14 14:59:29 +00006644static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006645 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006647 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006648 struct compound_hdr hdr;
6649 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006650
Chuck Leverbf269552010-12-14 14:59:29 +00006651 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006652 if (status)
6653 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006654 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006655 if (status)
6656 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006657 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006658 if (status)
6659 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006661 if (status)
6662 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006663 status = decode_getfh(xdr, &res->fh);
6664 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006666 if (res->access_request)
6667 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006668 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006669 if (res->lg_res)
6670 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006671out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006672 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006673}
6674
6675/*
6676 * Decode OPEN_CONFIRM response
6677 */
Chuck Leverbf269552010-12-14 14:59:29 +00006678static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6679 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006680 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006682 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006683 struct compound_hdr hdr;
6684 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006687 if (status)
6688 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006689 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006690 if (status)
6691 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006694 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006695}
6696
6697/*
6698 * Decode OPEN response
6699 */
Chuck Leverbf269552010-12-14 14:59:29 +00006700static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6701 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006702 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006704 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006705 struct compound_hdr hdr;
6706 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707
Chuck Leverbf269552010-12-14 14:59:29 +00006708 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006709 if (status)
6710 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006711 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006712 if (status)
6713 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006714 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006715 if (status)
6716 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006718 if (status)
6719 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006720 if (res->access_request)
6721 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006722 decode_getfattr(xdr, res->f_attr, res->server);
Fred Isaman56f487f2016-09-21 11:43:41 -04006723 if (res->lg_res)
6724 decode_layoutget(xdr, rqstp, res->lg_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006726 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727}
6728
6729/*
6730 * Decode SETATTR response
6731 */
Chuck Leverbf269552010-12-14 14:59:29 +00006732static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6733 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006734 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006736 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006737 struct compound_hdr hdr;
6738 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006739
Chuck Leverbf269552010-12-14 14:59:29 +00006740 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006741 if (status)
6742 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006743 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006744 if (status)
6745 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006746 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006747 if (status)
6748 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006749 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006750 if (status)
6751 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006752 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006754 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006755}
6756
6757/*
6758 * Decode LOCK response
6759 */
Chuck Leverbf269552010-12-14 14:59:29 +00006760static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006761 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006763 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764 struct compound_hdr hdr;
6765 int status;
6766
Chuck Leverbf269552010-12-14 14:59:29 +00006767 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 if (status)
6769 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006770 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006771 if (status)
6772 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006773 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774 if (status)
6775 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006776 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006777out:
6778 return status;
6779}
6780
6781/*
6782 * Decode LOCKT response
6783 */
Chuck Leverbf269552010-12-14 14:59:29 +00006784static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006785 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006787 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 struct compound_hdr hdr;
6789 int status;
6790
Chuck Leverbf269552010-12-14 14:59:29 +00006791 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792 if (status)
6793 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006794 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006795 if (status)
6796 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006797 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006798 if (status)
6799 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006800 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006801out:
6802 return status;
6803}
6804
6805/*
6806 * Decode LOCKU response
6807 */
Chuck Leverbf269552010-12-14 14:59:29 +00006808static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006809 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006811 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812 struct compound_hdr hdr;
6813 int status;
6814
Chuck Leverbf269552010-12-14 14:59:29 +00006815 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006816 if (status)
6817 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006819 if (status)
6820 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006821 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006822 if (status)
6823 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006824 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825out:
6826 return status;
6827}
6828
Chuck Leverbf269552010-12-14 14:59:29 +00006829static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6830 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006831{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006832 struct compound_hdr hdr;
6833 int status;
6834
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006836 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006838 return status;
6839}
6840
Linus Torvalds1da177e2005-04-16 15:20:36 -07006841/*
6842 * Decode READLINK response
6843 */
Chuck Leverbf269552010-12-14 14:59:29 +00006844static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6845 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006846 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006847{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006848 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849 struct compound_hdr hdr;
6850 int status;
6851
Chuck Leverbf269552010-12-14 14:59:29 +00006852 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006853 if (status)
6854 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006855 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006856 if (status)
6857 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006858 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859 if (status)
6860 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006861 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006862out:
6863 return status;
6864}
6865
6866/*
6867 * Decode READDIR response
6868 */
Chuck Leverbf269552010-12-14 14:59:29 +00006869static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006870 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006872 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 struct compound_hdr hdr;
6874 int status;
6875
Chuck Leverbf269552010-12-14 14:59:29 +00006876 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877 if (status)
6878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006879 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006880 if (status)
6881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006882 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006883 if (status)
6884 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006885 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006886out:
6887 return status;
6888}
6889
6890/*
6891 * Decode Read response
6892 */
Chuck Leverbf269552010-12-14 14:59:29 +00006893static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006894 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006896 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 struct compound_hdr hdr;
6898 int status;
6899
Chuck Leverbf269552010-12-14 14:59:29 +00006900 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006901 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006902 if (status)
6903 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006904 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006905 if (status)
6906 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006907 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006908 if (status)
6909 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006910 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006911 if (!status)
6912 status = res->count;
6913out:
6914 return status;
6915}
6916
6917/*
6918 * Decode WRITE response
6919 */
Chuck Leverbf269552010-12-14 14:59:29 +00006920static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006921 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006922{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006923 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 struct compound_hdr hdr;
6925 int status;
6926
Chuck Leverbf269552010-12-14 14:59:29 +00006927 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006928 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006929 if (status)
6930 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006931 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006932 if (status)
6933 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006935 if (status)
6936 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006937 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006938 if (status)
6939 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006940 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006941 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006942 if (!status)
6943 status = res->count;
6944out:
6945 return status;
6946}
6947
6948/*
6949 * Decode COMMIT response
6950 */
Chuck Leverbf269552010-12-14 14:59:29 +00006951static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006952 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006953{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006954 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006955 struct compound_hdr hdr;
6956 int status;
6957
Chuck Leverbf269552010-12-14 14:59:29 +00006958 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006959 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960 if (status)
6961 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006962 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006963 if (status)
6964 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006965 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006966 if (status)
6967 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006968 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006969out:
6970 return status;
6971}
6972
6973/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006974 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006975 */
Chuck Leverbf269552010-12-14 14:59:29 +00006976static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006977 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006978{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006979 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006980 struct compound_hdr hdr;
6981 int status;
6982
Chuck Leverbf269552010-12-14 14:59:29 +00006983 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006984 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006985 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006986 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006987 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006988 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006989 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990 return status;
6991}
6992
6993/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006994 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006995 */
Chuck Leverbf269552010-12-14 14:59:29 +00006996static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006997 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006998{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006999 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000 struct compound_hdr hdr;
7001 int status;
7002
Chuck Leverbf269552010-12-14 14:59:29 +00007003 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007004 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007005 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007006 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007007 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007008 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007009 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007010 return status;
7011}
7012
7013/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007014 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007015 */
Chuck Leverbf269552010-12-14 14:59:29 +00007016static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007017 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007018{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007019 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007020 struct compound_hdr hdr;
7021 int status;
7022
Chuck Leverbf269552010-12-14 14:59:29 +00007023 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007025 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007026 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007027 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007028 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007029 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007030 return status;
7031}
7032
7033/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007034 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007035 */
Chuck Leverbf269552010-12-14 14:59:29 +00007036static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
7037 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007038 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007039{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007040 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007041 struct compound_hdr hdr;
7042 int status;
7043
Chuck Leverbf269552010-12-14 14:59:29 +00007044 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007045 if (status)
7046 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007047 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007048 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007049 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007050 status = decode_putfh(xdr);
7051 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007053 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007054out:
7055 return status;
7056}
7057
7058/*
7059 * Decode RENEW response
7060 */
Chuck Leverbf269552010-12-14 14:59:29 +00007061static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
7062 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007063{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064 struct compound_hdr hdr;
7065 int status;
7066
Chuck Leverbf269552010-12-14 14:59:29 +00007067 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007068 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007069 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007070 return status;
7071}
7072
7073/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007074 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007075 */
Chuck Leverbf269552010-12-14 14:59:29 +00007076static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
7077 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007078 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007079{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007080 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007081 struct compound_hdr hdr;
7082 int status;
7083
Chuck Leverbf269552010-12-14 14:59:29 +00007084 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007085 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007086 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007087 return status;
7088}
7089
7090/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007091 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007092 */
Chuck Leverbf269552010-12-14 14:59:29 +00007093static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007094 struct xdr_stream *xdr,
7095 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007096{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007097 struct compound_hdr hdr;
7098 int status;
7099
Chuck Leverbf269552010-12-14 14:59:29 +00007100 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007101 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007102 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007103 return status;
7104}
7105
7106/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007107 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007108 */
Chuck Leverbf269552010-12-14 14:59:29 +00007109static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7110 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007111 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007112{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007113 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007114 struct compound_hdr hdr;
7115 int status;
7116
Chuck Leverbf269552010-12-14 14:59:29 +00007117 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007118 if (status)
7119 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007120 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007121 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01007122 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007123 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007124 if (status != 0)
7125 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05007126 if (res->lr_res) {
7127 status = decode_layoutreturn(xdr, res->lr_res);
7128 res->lr_ret = status;
7129 if (status)
7130 goto out;
7131 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05007132 if (res->fattr) {
7133 status = decode_getfattr(xdr, res->fattr, res->server);
7134 if (status != 0)
7135 goto out;
7136 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04007137 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007138out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007139 return status;
7140}
7141
Trond Myklebust683b57b2006-06-09 09:34:22 -04007142/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007143 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04007144 */
Chuck Leverbf269552010-12-14 14:59:29 +00007145static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7146 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007147 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007148{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007149 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04007150 struct compound_hdr hdr;
7151 int status;
7152
Chuck Leverbf269552010-12-14 14:59:29 +00007153 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007154 if (status)
7155 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007156 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007157 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007158 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007159 status = decode_putfh(xdr);
7160 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007161 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04007162 if (res->migration) {
7163 xdr_enter_page(xdr, PAGE_SIZE);
7164 status = decode_getfattr_generic(xdr,
7165 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007166 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04007167 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007168 if (status)
7169 goto out;
7170 if (res->renew)
7171 status = decode_renew(xdr);
7172 } else {
7173 status = decode_lookup(xdr);
7174 if (status)
7175 goto out;
7176 xdr_enter_page(xdr, PAGE_SIZE);
7177 status = decode_getfattr_generic(xdr,
7178 &res->fs_locations->fattr,
7179 NULL, res->fs_locations,
7180 NULL, res->fs_locations->server);
7181 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007182out:
7183 return status;
7184}
7185
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007186/*
7187 * Decode SECINFO response
7188 */
7189static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7190 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007191 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007192{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007193 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007194 struct compound_hdr hdr;
7195 int status;
7196
7197 status = decode_compound_hdr(xdr, &hdr);
7198 if (status)
7199 goto out;
7200 status = decode_sequence(xdr, &res->seq_res, rqstp);
7201 if (status)
7202 goto out;
7203 status = decode_putfh(xdr);
7204 if (status)
7205 goto out;
7206 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007207out:
7208 return status;
7209}
7210
Chuck Lever44c99932013-10-17 14:13:30 -04007211/*
7212 * Decode FSID_PRESENT response
7213 */
7214static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7215 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007216 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007217{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007218 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007219 struct compound_hdr hdr;
7220 int status;
7221
7222 status = decode_compound_hdr(xdr, &hdr);
7223 if (status)
7224 goto out;
7225 status = decode_sequence(xdr, &res->seq_res, rqstp);
7226 if (status)
7227 goto out;
7228 status = decode_putfh(xdr);
7229 if (status)
7230 goto out;
7231 status = decode_getfh(xdr, res->fh);
7232 if (status)
7233 goto out;
7234 if (res->renew)
7235 status = decode_renew(xdr);
7236out:
7237 return status;
7238}
7239
Benny Halevy99fe60d2009-04-01 09:22:29 -04007240#if defined(CONFIG_NFS_V4_1)
7241/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007242 * Decode BIND_CONN_TO_SESSION response
7243 */
7244static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7245 struct xdr_stream *xdr,
7246 void *res)
7247{
7248 struct compound_hdr hdr;
7249 int status;
7250
7251 status = decode_compound_hdr(xdr, &hdr);
7252 if (!status)
7253 status = decode_bind_conn_to_session(xdr, res);
7254 return status;
7255}
7256
7257/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007258 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007259 */
Chuck Leverbf269552010-12-14 14:59:29 +00007260static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7261 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007262 void *res)
7263{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007264 struct compound_hdr hdr;
7265 int status;
7266
Chuck Leverbf269552010-12-14 14:59:29 +00007267 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007268 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007269 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007270 return status;
7271}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007272
7273/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007274 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007275 */
Chuck Leverbf269552010-12-14 14:59:29 +00007276static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7277 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007278 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007279{
Andy Adamsonfc931582009-04-01 09:22:31 -04007280 struct compound_hdr hdr;
7281 int status;
7282
Chuck Leverbf269552010-12-14 14:59:29 +00007283 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007284 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007285 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007286 return status;
7287}
7288
7289/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007290 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007291 */
Chuck Leverbf269552010-12-14 14:59:29 +00007292static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7293 struct xdr_stream *xdr,
7294 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007295{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007296 struct compound_hdr hdr;
7297 int status;
7298
Chuck Leverbf269552010-12-14 14:59:29 +00007299 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007300 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007301 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007302 return status;
7303}
7304
7305/*
Trond Myklebust66245532012-05-25 17:18:09 -04007306 * Decode DESTROY_CLIENTID response
7307 */
7308static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7309 struct xdr_stream *xdr,
7310 void *res)
7311{
7312 struct compound_hdr hdr;
7313 int status;
7314
7315 status = decode_compound_hdr(xdr, &hdr);
7316 if (!status)
7317 status = decode_destroy_clientid(xdr, res);
7318 return status;
7319}
7320
7321/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007322 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007323 */
Chuck Leverbf269552010-12-14 14:59:29 +00007324static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7325 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007326 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007327{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007328 struct compound_hdr hdr;
7329 int status;
7330
Chuck Leverbf269552010-12-14 14:59:29 +00007331 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007332 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007333 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007334 return status;
7335}
7336
7337/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007338 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007339 */
Chuck Leverbf269552010-12-14 14:59:29 +00007340static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7341 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007342 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007343{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007344 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007345 struct compound_hdr hdr;
7346 int status;
7347
Chuck Leverbf269552010-12-14 14:59:29 +00007348 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007349 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007350 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007351 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007352 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007353 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007354 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007355 return status;
7356}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007357
7358/*
7359 * Decode RECLAIM_COMPLETE response
7360 */
Chuck Leverbf269552010-12-14 14:59:29 +00007361static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7362 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007363 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007364{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007365 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007366 struct compound_hdr hdr;
7367 int status;
7368
Chuck Leverbf269552010-12-14 14:59:29 +00007369 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007370 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007371 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007372 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307373 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007374 return status;
7375}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007376
7377/*
7378 * Decode GETDEVINFO response
7379 */
Chuck Leverbf269552010-12-14 14:59:29 +00007380static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7381 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007382 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007383{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007384 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007385 struct compound_hdr hdr;
7386 int status;
7387
Chuck Leverbf269552010-12-14 14:59:29 +00007388 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007389 if (status != 0)
7390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007391 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007392 if (status != 0)
7393 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007394 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007395out:
7396 return status;
7397}
7398
7399/*
7400 * Decode LAYOUTGET response
7401 */
Chuck Leverbf269552010-12-14 14:59:29 +00007402static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7403 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007404 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007405{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007406 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007407 struct compound_hdr hdr;
7408 int status;
7409
Chuck Leverbf269552010-12-14 14:59:29 +00007410 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007411 if (status)
7412 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007413 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007414 if (status)
7415 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007416 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007417 if (status)
7418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007419 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007420out:
7421 return status;
7422}
Andy Adamson863a3c62011-03-23 13:27:54 +00007423
7424/*
Benny Halevycbe82602011-05-22 19:52:37 +03007425 * Decode LAYOUTRETURN response
7426 */
7427static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7428 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007429 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007430{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007431 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007432 struct compound_hdr hdr;
7433 int status;
7434
7435 status = decode_compound_hdr(xdr, &hdr);
7436 if (status)
7437 goto out;
7438 status = decode_sequence(xdr, &res->seq_res, rqstp);
7439 if (status)
7440 goto out;
7441 status = decode_putfh(xdr);
7442 if (status)
7443 goto out;
7444 status = decode_layoutreturn(xdr, res);
7445out:
7446 return status;
7447}
7448
7449/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007450 * Decode LAYOUTCOMMIT response
7451 */
7452static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7453 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007454 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007455{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007456 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007457 struct compound_hdr hdr;
7458 int status;
7459
7460 status = decode_compound_hdr(xdr, &hdr);
7461 if (status)
7462 goto out;
7463 status = decode_sequence(xdr, &res->seq_res, rqstp);
7464 if (status)
7465 goto out;
7466 status = decode_putfh(xdr);
7467 if (status)
7468 goto out;
7469 status = decode_layoutcommit(xdr, rqstp, res);
7470 if (status)
7471 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007472 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007473out:
7474 return status;
7475}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007476
7477/*
7478 * Decode SECINFO_NO_NAME response
7479 */
7480static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7481 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007482 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007483{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007484 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007485 struct compound_hdr hdr;
7486 int status;
7487
7488 status = decode_compound_hdr(xdr, &hdr);
7489 if (status)
7490 goto out;
7491 status = decode_sequence(xdr, &res->seq_res, rqstp);
7492 if (status)
7493 goto out;
7494 status = decode_putrootfh(xdr);
7495 if (status)
7496 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007497 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007498out:
7499 return status;
7500}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007501
7502/*
7503 * Decode TEST_STATEID response
7504 */
7505static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7506 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007507 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007508{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007509 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007510 struct compound_hdr hdr;
7511 int status;
7512
7513 status = decode_compound_hdr(xdr, &hdr);
7514 if (status)
7515 goto out;
7516 status = decode_sequence(xdr, &res->seq_res, rqstp);
7517 if (status)
7518 goto out;
7519 status = decode_test_stateid(xdr, res);
7520out:
7521 return status;
7522}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007523
7524/*
7525 * Decode FREE_STATEID response
7526 */
7527static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7528 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007529 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007530{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007531 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007532 struct compound_hdr hdr;
7533 int status;
7534
7535 status = decode_compound_hdr(xdr, &hdr);
7536 if (status)
7537 goto out;
7538 status = decode_sequence(xdr, &res->seq_res, rqstp);
7539 if (status)
7540 goto out;
7541 status = decode_free_stateid(xdr, res);
7542out:
7543 return status;
7544}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007545#endif /* CONFIG_NFS_V4_1 */
7546
Chuck Lever573c4e12010-12-14 14:58:11 +00007547/**
7548 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7549 * the local page cache.
7550 * @xdr: XDR stream where entry resides
7551 * @entry: buffer to fill in with entry data
7552 * @plus: boolean indicating whether this should be a readdirplus entry
7553 *
7554 * Returns zero if successful, otherwise a negative errno value is
7555 * returned.
7556 *
7557 * This function is not invoked during READDIR reply decoding, but
7558 * rather whenever an application invokes the getdents(2) system call
7559 * on a directory already in our cache.
7560 */
7561int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007562 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007563{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007564 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007565 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007566 uint32_t len;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007567 uint64_t new_cookie;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007568 __be32 *p = xdr_inline_decode(xdr, 4);
7569 if (unlikely(!p))
7570 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007571 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007572 p = xdr_inline_decode(xdr, 4);
7573 if (unlikely(!p))
7574 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007575 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007576 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007577 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007578 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007579 }
7580
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007581 p = xdr_inline_decode(xdr, 12);
7582 if (unlikely(!p))
7583 goto out_overflow;
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007584 p = xdr_decode_hyper(p, &new_cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007585 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007586
Trond Myklebust9af8c222010-10-24 11:52:55 -04007587 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007588 if (unlikely(!p))
7589 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007590 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007591
7592 /*
7593 * In case the server doesn't return an inode number,
7594 * we fake one here. (We don't use inode number 0,
7595 * since glibc seems to choke on it...)
7596 */
7597 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007598 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007599
Trond Myklebust9af8c222010-10-24 11:52:55 -04007600 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007601 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007602
Trond Myklebust256e48b2012-06-21 11:18:13 -04007603 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007604 goto out_overflow;
7605
Chuck Lever573c4e12010-12-14 14:58:11 +00007606 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007607 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007608 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007609 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7610 entry->ino = entry->fattr->mounted_on_fileid;
7611 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007612 entry->ino = entry->fattr->fileid;
7613
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007614 entry->d_type = DT_UNKNOWN;
7615 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7616 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7617
Frank Sorenson98de9ce2018-04-02 16:12:45 -05007618 entry->prev_cookie = entry->cookie;
7619 entry->cookie = new_cookie;
7620
Chuck Lever573c4e12010-12-14 14:58:11 +00007621 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007622
7623out_overflow:
7624 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007625 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007626}
7627
7628/*
7629 * We need to translate between nfs status return values and
7630 * the local errno values which may not be the same.
7631 */
7632static struct {
7633 int stat;
7634 int errno;
7635} nfs_errtbl[] = {
7636 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007637 { NFS4ERR_PERM, -EPERM },
7638 { NFS4ERR_NOENT, -ENOENT },
7639 { NFS4ERR_IO, -errno_NFSERR_IO},
7640 { NFS4ERR_NXIO, -ENXIO },
7641 { NFS4ERR_ACCESS, -EACCES },
7642 { NFS4ERR_EXIST, -EEXIST },
7643 { NFS4ERR_XDEV, -EXDEV },
7644 { NFS4ERR_NOTDIR, -ENOTDIR },
7645 { NFS4ERR_ISDIR, -EISDIR },
7646 { NFS4ERR_INVAL, -EINVAL },
7647 { NFS4ERR_FBIG, -EFBIG },
7648 { NFS4ERR_NOSPC, -ENOSPC },
7649 { NFS4ERR_ROFS, -EROFS },
7650 { NFS4ERR_MLINK, -EMLINK },
7651 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7652 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7653 { NFS4ERR_DQUOT, -EDQUOT },
7654 { NFS4ERR_STALE, -ESTALE },
7655 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007656 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7657 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7658 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007659 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007660 { NFS4ERR_BADTYPE, -EBADTYPE },
7661 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007662 { NFS4ERR_SYMLINK, -ELOOP },
7663 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7664 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007665 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007666};
7667
7668/*
7669 * Convert an NFS error code to a local one.
7670 * This one is used jointly by NFSv2 and NFSv3.
7671 */
7672static int
David Howells0a8ea432006-08-22 20:06:08 -04007673nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007674{
7675 int i;
7676 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7677 if (nfs_errtbl[i].stat == stat)
7678 return nfs_errtbl[i].errno;
7679 }
7680 if (stat <= 10000 || stat > 10100) {
7681 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007682 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007683 }
7684 /* If we cannot translate the error, the recovery routines should
7685 * handle it.
7686 * Note: remaining NFSv4 error codes have values > 10000, so should
7687 * not conflict with native Linux error codes.
7688 */
Benny Halevy856dff32008-03-31 17:39:06 +03007689 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007690}
7691
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007692#ifdef CONFIG_NFS_V4_2
7693#include "nfs42xdr.c"
7694#endif /* CONFIG_NFS_V4_2 */
7695
Linus Torvalds1da177e2005-04-16 15:20:36 -07007696#define PROC(proc, argtype, restype) \
7697[NFSPROC4_CLNT_##proc] = { \
7698 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007699 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007700 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007701 .p_arglen = NFS4_##argtype##_sz, \
7702 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007703 .p_statidx = NFSPROC4_CLNT_##proc, \
7704 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007705}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007706
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007707#define STUB(proc) \
7708[NFSPROC4_CLNT_##proc] = { \
7709 .p_name = #proc, \
7710}
7711
Trond Myklebust8634ef52018-01-06 09:53:49 -05007712#if defined(CONFIG_NFS_V4_1)
7713#define PROC41(proc, argtype, restype) \
7714 PROC(proc, argtype, restype)
7715#else
7716#define PROC41(proc, argtype, restype) \
7717 STUB(proc)
7718#endif
7719
7720#if defined(CONFIG_NFS_V4_2)
7721#define PROC42(proc, argtype, restype) \
7722 PROC(proc, argtype, restype)
7723#else
7724#define PROC42(proc, argtype, restype) \
7725 STUB(proc)
7726#endif
7727
Christoph Hellwig511e9362017-05-12 15:36:49 +02007728const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007729 PROC(READ, enc_read, dec_read),
7730 PROC(WRITE, enc_write, dec_write),
7731 PROC(COMMIT, enc_commit, dec_commit),
7732 PROC(OPEN, enc_open, dec_open),
7733 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7734 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7735 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7736 PROC(CLOSE, enc_close, dec_close),
7737 PROC(SETATTR, enc_setattr, dec_setattr),
7738 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7739 PROC(RENEW, enc_renew, dec_renew),
7740 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7741 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7742 PROC(LOCK, enc_lock, dec_lock),
7743 PROC(LOCKT, enc_lockt, dec_lockt),
7744 PROC(LOCKU, enc_locku, dec_locku),
7745 PROC(ACCESS, enc_access, dec_access),
7746 PROC(GETATTR, enc_getattr, dec_getattr),
7747 PROC(LOOKUP, enc_lookup, dec_lookup),
7748 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7749 PROC(REMOVE, enc_remove, dec_remove),
7750 PROC(RENAME, enc_rename, dec_rename),
7751 PROC(LINK, enc_link, dec_link),
7752 PROC(SYMLINK, enc_symlink, dec_symlink),
7753 PROC(CREATE, enc_create, dec_create),
7754 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7755 PROC(STATFS, enc_statfs, dec_statfs),
7756 PROC(READLINK, enc_readlink, dec_readlink),
7757 PROC(READDIR, enc_readdir, dec_readdir),
7758 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7759 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7760 PROC(GETACL, enc_getacl, dec_getacl),
7761 PROC(SETACL, enc_setacl, dec_setacl),
7762 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7763 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007764 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007765 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007766 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7767 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7768 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7769 PROC41(SEQUENCE, enc_sequence, dec_sequence),
7770 PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7771 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7772 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7773 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7774 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7775 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7776 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7777 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7778 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007779 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007780 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007781 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007782 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7783 PROC42(SEEK, enc_seek, dec_seek),
7784 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7785 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7786 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7787 PROC42(CLONE, enc_clone, dec_clone),
7788 PROC42(COPY, enc_copy, dec_copy),
7789 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007790};
7791
Christoph Hellwigc5518582017-05-08 23:27:10 +02007792static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007793const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007794 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007795 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007796 .procs = nfs4_procedures,
7797 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007798};
7799
7800/*
7801 * Local variables:
7802 * c-basic-offset: 8
7803 * End:
7804 */