blob: 80c5b519fd6aea5ce6d44b2e6876f9858f413281 [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>
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -050055#include <linux/fs_struct.h>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040059#include "nfs4idmap.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050060#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040061#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040062#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#define NFSDBG_FACILITY NFSDBG_XDR
65
66/* Mapping from NFS error code to "errno" error code. */
67#define errno_NFSERR_IO EIO
68
David Howells0a8ea432006-08-22 20:06:08 -040069static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
72#ifdef DEBUG
73#define NFS4_MAXTAGLEN 20
74#else
75#define NFS4_MAXTAGLEN 0
76#endif
77
Andy Adamson6c0195a2008-12-23 16:06:15 -050078/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040079 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040081#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050082#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040083#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
86#define op_encode_hdr_maxsz (1)
87#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040088#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
90#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
93 (NFS4_FHSIZE >> 2))
94#define decode_putfh_maxsz (op_decode_hdr_maxsz)
95#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
96#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
97#define encode_getfh_maxsz (op_encode_hdr_maxsz)
98#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
99 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -0400100#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
103#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400106#ifdef CONFIG_NFS_V4_SECURITY_LABEL
107/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400109#else
110#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400111#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400112/* We support only one layout type per file system */
113#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000114/* This is based on getfattr, which uses the most attributes: */
115#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400116 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400117 nfs4_group_maxsz + nfs4_label_maxsz + \
118 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000119#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
120 nfs4_fattr_value_maxsz)
121#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400122#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
123 1 + 2 + 1 + \
124 nfs4_owner_maxsz + \
125 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400126 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400127 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#define encode_savefh_maxsz (op_encode_hdr_maxsz)
129#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400130#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
131#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200132#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400133/* The 5 accounts for the PNFS attributes, and assumes that at most three
134 * layout types will be returned.
135 */
136#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
137 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
139#define decode_renew_maxsz (op_decode_hdr_maxsz)
140#define encode_setclientid_maxsz \
141 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500142 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400143 /* client name */ \
144 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500145 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500146 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
147 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500148 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define decode_setclientid_maxsz \
150 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500151 2 /* clientid */ + \
152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
154 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158#define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400160#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700162#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
163#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400164#define encode_share_access_maxsz \
165 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500166#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400167#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
168#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
169#define encode_open_maxsz (op_encode_hdr_maxsz + \
170 2 + encode_share_access_maxsz + 2 + \
171 open_owner_id_maxsz + \
172 encode_opentype_maxsz + \
173 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500174#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400175#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400176#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500177 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400178 decode_ace_maxsz)
179#define decode_change_info_maxsz (5)
180#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400181 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400182 decode_change_info_maxsz + 1 + \
183 nfs4_fattr_bitmap_maxsz + \
184 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400185#define encode_open_confirm_maxsz \
186 (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 1)
188#define decode_open_confirm_maxsz \
189 (op_decode_hdr_maxsz + \
190 decode_stateid_maxsz)
191#define encode_open_downgrade_maxsz \
192 (op_encode_hdr_maxsz + \
193 encode_stateid_maxsz + 1 + \
194 encode_share_access_maxsz)
195#define decode_open_downgrade_maxsz \
196 (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198#define encode_close_maxsz (op_encode_hdr_maxsz + \
199 1 + encode_stateid_maxsz)
200#define decode_close_maxsz (op_decode_hdr_maxsz + \
201 decode_stateid_maxsz)
202#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + \
204 encode_attrs_maxsz)
205#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
206 nfs4_fattr_bitmap_maxsz)
207#define encode_read_maxsz (op_encode_hdr_maxsz + \
208 encode_stateid_maxsz + 3)
209#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
210#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400211 2 + encode_verifier_maxsz + 5 + \
212 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400213#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400214 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400215#define encode_readlink_maxsz (op_encode_hdr_maxsz)
216#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
217#define encode_write_maxsz (op_encode_hdr_maxsz + \
218 encode_stateid_maxsz + 4)
219#define decode_write_maxsz (op_decode_hdr_maxsz + \
220 2 + decode_verifier_maxsz)
221#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
222#define decode_commit_maxsz (op_decode_hdr_maxsz + \
223 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#define encode_remove_maxsz (op_encode_hdr_maxsz + \
225 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400226#define decode_remove_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#define encode_rename_maxsz (op_encode_hdr_maxsz + \
229 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400230#define decode_rename_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#define encode_link_maxsz (op_encode_hdr_maxsz + \
234 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400235#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400236#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define encode_lock_maxsz (op_encode_hdr_maxsz + \
238 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400239 1 + encode_stateid_maxsz + 1 + \
240 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define decode_lock_denied_maxsz \
242 (8 + decode_lockowner_maxsz)
243#define decode_lock_maxsz (op_decode_hdr_maxsz + \
244 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400245#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
246 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
248 decode_lock_denied_maxsz)
249#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
250 encode_stateid_maxsz + \
251 4)
252#define decode_locku_maxsz (op_decode_hdr_maxsz + \
253 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400254#define encode_release_lockowner_maxsz \
255 (op_encode_hdr_maxsz + \
256 encode_lockowner_maxsz)
257#define decode_release_lockowner_maxsz \
258 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400259#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
260#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
262 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400263 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000264 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
266#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400267 1 + 2 + nfs4_name_maxsz + \
268 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400269#define decode_create_maxsz (op_decode_hdr_maxsz + \
270 decode_change_info_maxsz + \
271 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400272#define encode_statfs_maxsz (encode_getattr_maxsz)
273#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
275#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400276#define encode_getacl_maxsz (encode_getattr_maxsz)
277#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
278 nfs4_fattr_bitmap_maxsz + 1)
279#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
280 encode_stateid_maxsz + 3)
281#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400282#define encode_fs_locations_maxsz \
283 (encode_getattr_maxsz)
284#define decode_fs_locations_maxsz \
285 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000286#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400287#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 -0400288
289#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400290#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500291#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
292 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400293
Benny Halevy99fe60d2009-04-01 09:22:29 -0400294#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
295 encode_verifier_maxsz + \
296 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400297 /* eia_clientowner */ \
298 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400299 1 /* flags */ + \
300 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400301 /* max is SP4_MACH_CRED (for now) */ + \
302 1 + NFS4_OP_MAP_NUM_WORDS + \
303 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500304 1 /* implementation id array of size 1 */ + \
305 1 /* nii_domain */ + \
306 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
307 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500308 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500309 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400310#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
311 2 /* eir_clientid */ + \
312 1 /* eir_sequenceid */ + \
313 1 /* eir_flags */ + \
314 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400315 /* max is SP4_MACH_CRED (for now) */ + \
316 1 + NFS4_OP_MAP_NUM_WORDS + \
317 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400318 2 /* eir_server_owner.so_minor_id */ + \
319 /* eir_server_owner.so_major_id<> */ \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
321 /* eir_server_scope<> */ \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
323 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500324 1 /* nii_domain */ + \
325 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
326 1 /* nii_name */ + \
327 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
328 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400329#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
330#define decode_channel_attrs_maxsz (6 + \
331 1 /* ca_rdma_ird.len */ + \
332 1 /* ca_rdma_ird */)
333#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
334 2 /* csa_clientid */ + \
335 1 /* csa_sequence */ + \
336 1 /* csa_flags */ + \
337 encode_channel_attrs_maxsz + \
338 encode_channel_attrs_maxsz + \
339 1 /* csa_cb_program */ + \
340 1 /* csa_sec_parms.len (1) */ + \
341 1 /* cb_secflavor (AUTH_SYS) */ + \
342 1 /* stamp */ + \
343 1 /* machinename.len */ + \
344 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
345 1 /* uid */ + \
346 1 /* gid */ + \
347 1 /* gids.len (0) */)
348#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
350 1 /* csr_sequence */ + \
351 1 /* csr_flags */ + \
352 decode_channel_attrs_maxsz + \
353 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400354#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
355 /* bctsa_sessid */ \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsa_dir */ + \
358 1 /* bctsa_use_conn_in_rdma_mode */)
359#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
360 /* bctsr_sessid */ \
361 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
362 1 /* bctsr_dir */ + \
363 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400364#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
365#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400366#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
367#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400368#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
369 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
370#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
371 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500372#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
373#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700374#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
375 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
376 1 /* layout type */ + \
377 1 /* maxcount */ + \
378 1 /* bitmap size */ + \
379 1 /* notification bitmap length */ + \
380 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400381#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
382 1 /* layout type */ + \
383 1 /* opaque devaddr4 length */ + \
384 /* devaddr4 payload is read into page */ \
385 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700386 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400387#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
388 encode_stateid_maxsz)
389#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
390 decode_stateid_maxsz + \
391 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000392#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
393 2 /* offset */ + \
394 2 /* length */ + \
395 1 /* reclaim */ + \
396 encode_stateid_maxsz + \
397 1 /* new offset (true) */ + \
398 2 /* last byte written */ + \
399 1 /* nt_timechanged (false) */ + \
400 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500401 1 /* layoutupdate4 opaqueue len */)
402 /* the actual content of layoutupdate4 should
403 be allocated by drivers and spliced in
404 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000405#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300406#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
407 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400408 1 + \
409 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300410#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
411 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400412#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
413#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400414#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
415 XDR_QUADLEN(NFS4_STATEID_SIZE))
416#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400417#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
418 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400419#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420#else /* CONFIG_NFS_V4_1 */
421#define encode_sequence_maxsz 0
422#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500423#define encode_layoutreturn_maxsz 0
424#define decode_layoutreturn_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425#endif /* CONFIG_NFS_V4_1 */
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
428#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
429#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400456 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400457 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400461 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400462 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_commit_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 Myklebust85827152012-04-29 10:44:42 -0400466 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400470 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400475 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400477 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400481 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400482 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400483 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400484 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400485#define NFS4_enc_open_confirm_sz \
486 (compound_encode_hdr_maxsz + \
487 encode_putfh_maxsz + \
488 encode_open_confirm_maxsz)
489#define NFS4_dec_open_confirm_sz \
490 (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
492 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400497 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400498 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400502 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400503 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400504 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#define NFS4_enc_open_downgrade_sz \
506 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400508 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500509 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400510 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#define NFS4_dec_open_downgrade_sz \
512 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500515 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400516 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400517#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400519 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500520 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_close_maxsz + \
522 encode_getattr_maxsz)
523#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500526 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400527 decode_close_maxsz + \
528 decode_getattr_maxsz)
529#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400531 encode_putfh_maxsz + \
532 encode_setattr_maxsz + \
533 encode_getattr_maxsz)
534#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400535 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 decode_putfh_maxsz + \
537 decode_setattr_maxsz + \
538 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 encode_putfh_maxsz + \
542 encode_fsinfo_maxsz)
543#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400544 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 decode_putfh_maxsz + \
546 decode_fsinfo_maxsz)
547#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
548 encode_renew_maxsz)
549#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
550 decode_renew_maxsz)
551#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
552 encode_setclientid_maxsz)
553#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
554 decode_setclientid_maxsz)
555#define NFS4_enc_setclientid_confirm_sz \
556 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400557 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_dec_setclientid_confirm_sz \
559 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400560 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400568 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400572 encode_lockt_maxsz)
573#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400575 decode_putfh_maxsz + \
576 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400580 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400584 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400585#define NFS4_enc_release_lockowner_sz \
586 (compound_encode_hdr_maxsz + \
587 encode_lockowner_maxsz)
588#define NFS4_dec_release_lockowner_sz \
589 (compound_decode_hdr_maxsz + \
590 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_access_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 Myklebust76b32992007-08-10 17:45:11 -0400594 encode_access_maxsz + \
595 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400599 decode_access_maxsz + \
600 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400604 encode_getattr_maxsz + \
605 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400609 decode_getattr_maxsz + \
610 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putfh_maxsz + \
614 encode_lookup_maxsz + \
615 encode_getattr_maxsz + \
616 encode_getfh_maxsz)
617#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400620 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 decode_getattr_maxsz + \
622 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700623#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
624 encode_sequence_maxsz + \
625 encode_putfh_maxsz + \
626 encode_lookupp_maxsz + \
627 encode_getattr_maxsz + \
628 encode_getfh_maxsz)
629#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
630 decode_sequence_maxsz + \
631 decode_putfh_maxsz + \
632 decode_lookupp_maxsz + \
633 decode_getattr_maxsz + \
634 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 encode_putrootfh_maxsz + \
638 encode_getattr_maxsz + \
639 encode_getfh_maxsz)
640#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400641 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 decode_putrootfh_maxsz + \
643 decode_getattr_maxsz + \
644 decode_getfh_maxsz)
645#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400648 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400652 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
656 encode_savefh_maxsz + \
657 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400658 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 decode_putfh_maxsz + \
662 decode_savefh_maxsz + \
663 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400664 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 encode_putfh_maxsz + \
668 encode_savefh_maxsz + \
669 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400670 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400671 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400672 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#define NFS4_dec_link_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 Myklebust91ba2ee2005-10-27 22:12:42 -0400678 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400679 decode_restorefh_maxsz + \
680 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_symlink_maxsz + \
685 encode_getattr_maxsz + \
686 encode_getfh_maxsz)
687#define NFS4_dec_symlink_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_symlink_maxsz + \
691 decode_getattr_maxsz + \
692 decode_getfh_maxsz)
693#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 encode_putfh_maxsz + \
696 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400697 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400698 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 decode_putfh_maxsz + \
702 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400703 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400704 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 encode_putfh_maxsz + \
708 encode_getattr_maxsz)
709#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400710 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 decode_putfh_maxsz + \
712 decode_getattr_maxsz)
713#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400714 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400716 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400718 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400720 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800723 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 encode_getattr_maxsz)
725#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400726 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800727 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 decode_getattr_maxsz)
729#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400730 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500732 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100733 encode_delegreturn_maxsz + \
734 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400736 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500737 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500738 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100739 decode_delegreturn_maxsz + \
740 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000741#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400742 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000743 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400744 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000745#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400746 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000747 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400748 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000749#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400750 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000751 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400752 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000753#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400754 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000755 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400756 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400757#define NFS4_enc_fs_locations_sz \
758 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400759 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400760 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400761 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400762 encode_fs_locations_maxsz + \
763 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400764#define NFS4_dec_fs_locations_sz \
765 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400766 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400767 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400768 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400769 decode_fs_locations_maxsz + \
770 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000771#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_putfh_maxsz + \
774 encode_secinfo_maxsz)
775#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
776 decode_sequence_maxsz + \
777 decode_putfh_maxsz + \
778 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400779#define NFS4_enc_fsid_present_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz + \
782 encode_putfh_maxsz + \
783 encode_getfh_maxsz + \
784 encode_renew_maxsz)
785#define NFS4_dec_fsid_present_sz \
786 (compound_decode_hdr_maxsz + \
787 decode_sequence_maxsz + \
788 decode_putfh_maxsz + \
789 decode_getfh_maxsz + \
790 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400791#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400792#define NFS4_enc_bind_conn_to_session_sz \
793 (compound_encode_hdr_maxsz + \
794 encode_bind_conn_to_session_maxsz)
795#define NFS4_dec_bind_conn_to_session_sz \
796 (compound_decode_hdr_maxsz + \
797 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400798#define NFS4_enc_exchange_id_sz \
799 (compound_encode_hdr_maxsz + \
800 encode_exchange_id_maxsz)
801#define NFS4_dec_exchange_id_sz \
802 (compound_decode_hdr_maxsz + \
803 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400804#define NFS4_enc_create_session_sz \
805 (compound_encode_hdr_maxsz + \
806 encode_create_session_maxsz)
807#define NFS4_dec_create_session_sz \
808 (compound_decode_hdr_maxsz + \
809 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400810#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
811 encode_destroy_session_maxsz)
812#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
813 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400814#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
815 encode_destroy_clientid_maxsz)
816#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
817 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400818#define NFS4_enc_sequence_sz \
819 (compound_decode_hdr_maxsz + \
820 encode_sequence_maxsz)
821#define NFS4_dec_sequence_sz \
822 (compound_decode_hdr_maxsz + \
823 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400824#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
825 encode_sequence_maxsz + \
826 encode_putrootfh_maxsz + \
827 encode_fsinfo_maxsz)
828#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_putrootfh_maxsz + \
831 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500832#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
833 encode_sequence_maxsz + \
834 encode_reclaim_complete_maxsz)
835#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
836 decode_sequence_maxsz + \
837 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400838#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
839 encode_sequence_maxsz +\
840 encode_getdeviceinfo_maxsz)
841#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_getdeviceinfo_maxsz)
844#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
845 encode_sequence_maxsz + \
846 encode_putfh_maxsz + \
847 encode_layoutget_maxsz)
848#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_putfh_maxsz + \
851 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000852#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz +\
854 encode_putfh_maxsz + \
855 encode_layoutcommit_maxsz + \
856 encode_getattr_maxsz)
857#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
858 decode_sequence_maxsz + \
859 decode_putfh_maxsz + \
860 decode_layoutcommit_maxsz + \
861 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300862#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
863 encode_sequence_maxsz + \
864 encode_putfh_maxsz + \
865 encode_layoutreturn_maxsz)
866#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
867 decode_sequence_maxsz + \
868 decode_putfh_maxsz + \
869 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400870#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
871 encode_sequence_maxsz + \
872 encode_putrootfh_maxsz +\
873 encode_secinfo_no_name_maxsz)
874#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
875 decode_sequence_maxsz + \
876 decode_putrootfh_maxsz + \
877 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400878#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
879 encode_sequence_maxsz + \
880 encode_test_stateid_maxsz)
881#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
882 decode_sequence_maxsz + \
883 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400884#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
885 encode_sequence_maxsz + \
886 encode_free_stateid_maxsz)
887#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
888 decode_sequence_maxsz + \
889 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500890
891const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
892 compound_encode_hdr_maxsz +
893 encode_sequence_maxsz +
894 encode_putfh_maxsz +
895 encode_getattr_maxsz) *
896 XDR_UNIT);
897
898const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
899 compound_decode_hdr_maxsz +
900 decode_sequence_maxsz +
901 decode_putfh_maxsz) *
902 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400903
904const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
905 compound_decode_hdr_maxsz +
906 decode_sequence_maxsz) *
907 XDR_UNIT);
908EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400909#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Trond Myklebustbca79472009-03-11 14:10:26 -0400911static const umode_t nfs_type2fmt[] = {
912 [NF4BAD] = 0,
913 [NF4REG] = S_IFREG,
914 [NF4DIR] = S_IFDIR,
915 [NF4BLK] = S_IFBLK,
916 [NF4CHR] = S_IFCHR,
917 [NF4LNK] = S_IFLNK,
918 [NF4SOCK] = S_IFSOCK,
919 [NF4FIFO] = S_IFIFO,
920 [NF4ATTRDIR] = 0,
921 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922};
923
924struct compound_hdr {
925 int32_t status;
926 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500927 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 uint32_t taglen;
929 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400930 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400931 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932};
933
Benny Halevy13c65ce2009-08-14 17:19:25 +0300934static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
935{
936 __be32 *p = xdr_reserve_space(xdr, nbytes);
937 BUG_ON(!p);
938 return p;
939}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Trond Myklebustcb17e552012-03-04 18:13:56 -0500941static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
942{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500943 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500944}
945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
947{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500948 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Trond Myklebust4ade9822012-03-04 18:13:57 -0500951static void encode_uint32(struct xdr_stream *xdr, u32 n)
952{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500953 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500954}
955
Trond Myklebustff2eb682012-03-05 11:40:12 -0500956static void encode_uint64(struct xdr_stream *xdr, u64 n)
957{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500958 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500959}
960
Trond Myklebust37c88762018-03-20 17:03:08 -0400961static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
962 const __u32 *bitmap, size_t len)
963{
964 ssize_t ret;
965
966 /* Trim empty words */
967 while (len > 0 && bitmap[len-1] == 0)
968 len--;
969 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
970 if (WARN_ON_ONCE(ret < 0))
971 return ret;
972 return len;
973}
974
975static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
976 __u32 *res, size_t len)
977{
978 size_t i;
979 __u32 tmp;
980
981 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
982 len--;
983 for (i = len; i-- > 0;) {
984 tmp = bitmap[i] & mask[i];
985 res[i] = tmp;
986 }
987 return len;
988}
989
Trond Myklebust4ade9822012-03-04 18:13:57 -0500990static void encode_nfs4_seqid(struct xdr_stream *xdr,
991 const struct nfs_seqid *seqid)
992{
Trond Myklebusta6796412015-01-23 19:04:44 -0500993 if (seqid != NULL)
994 encode_uint32(xdr, seqid->sequence->counter);
995 else
996 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500997}
998
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400999static void encode_compound_hdr(struct xdr_stream *xdr,
1000 struct rpc_rqst *req,
1001 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Al Viro8687b632006-10-19 23:28:48 -07001003 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -04001004 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001005
1006 /* initialize running count of expected bytes in reply.
1007 * NOTE: the replied tag SHOULD be the same is the one sent,
1008 * but this is not required as a MUST for the server to do so. */
1009 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Trond Myklebust7fc38842012-10-15 11:51:21 -04001011 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001012 encode_string(xdr, hdr->taglen, hdr->tag);
1013 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001014 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001015 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001016 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001017}
1018
Trond Myklebustab19b482012-03-04 18:13:57 -05001019static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1020 uint32_t replen,
1021 struct compound_hdr *hdr)
1022{
1023 encode_uint32(xdr, op);
1024 hdr->nops++;
1025 hdr->replen += replen;
1026}
1027
Andy Adamsond0179312008-12-23 16:06:17 -05001028static void encode_nops(struct compound_hdr *hdr)
1029{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001030 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001031 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001034static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1035{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001036 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001037}
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1040{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001041 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042}
1043
David Quigleyaa9c2662013-05-22 12:50:44 -04001044static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1045 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001046 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001047 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001048 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049{
1050 char owner_name[IDMAP_NAMESZ];
1051 char owner_group[IDMAP_NAMESZ];
1052 int owner_namelen = 0;
1053 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001054 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001055 unsigned i;
1056 uint32_t len = 0;
1057 uint32_t bmval_len;
1058 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 /*
1061 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001063 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001064 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001066 }
1067 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001068 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001069 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1070 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001071 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001072 bmval[1] |= FATTR4_WORD1_MODE;
1073 len += 4;
1074 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001075 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001076 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001077 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001079 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001080 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 /* XXX */
1082 strcpy(owner_name, "nobody");
1083 owner_namelen = sizeof("nobody") - 1;
1084 /* goto out; */
1085 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001086 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1088 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001089 if ((iap->ia_valid & ATTR_GID) &&
1090 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001091 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001093 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001094 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 strcpy(owner_group, "nobody");
1096 owner_grouplen = sizeof("nobody") - 1;
1097 /* goto out; */
1098 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001099 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1101 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001102 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1103 if (iap->ia_valid & ATTR_ATIME_SET) {
1104 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1105 len += 16;
1106 } else if (iap->ia_valid & ATTR_ATIME) {
1107 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1108 len += 4;
1109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001111 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1112 if (iap->ia_valid & ATTR_MTIME_SET) {
1113 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1114 len += 16;
1115 } else if (iap->ia_valid & ATTR_MTIME) {
1116 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1117 len += 4;
1118 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001120
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001121 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001122 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1123 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1124 }
1125
1126 if (bmval[2] != 0)
1127 bmval_len = 3;
1128 else if (bmval[1] != 0)
1129 bmval_len = 2;
1130 else
1131 bmval_len = 1;
1132
1133 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1134
1135 *p++ = cpu_to_be32(bmval_len);
1136 for (i = 0; i < bmval_len; i++)
1137 *p++ = cpu_to_be32(bmval[i]);
1138 *p++ = cpu_to_be32(len);
1139
1140 if (bmval[0] & FATTR4_WORD0_SIZE)
1141 p = xdr_encode_hyper(p, iap->ia_size);
1142 if (bmval[1] & FATTR4_WORD1_MODE)
1143 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1144 if (bmval[1] & FATTR4_WORD1_OWNER)
1145 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1146 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1147 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1148 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1149 if (iap->ia_valid & ATTR_ATIME_SET) {
1150 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1151 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1152 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1153 } else
1154 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1155 }
1156 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1157 if (iap->ia_valid & ATTR_MTIME_SET) {
1158 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1159 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1160 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1161 } else
1162 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1163 }
1164 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001165 *p++ = cpu_to_be32(label->lfs);
1166 *p++ = cpu_to_be32(label->pi);
1167 *p++ = cpu_to_be32(label->len);
1168 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1169 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001170 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1171 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1172 *p++ = cpu_to_be32(*umask);
1173 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001174
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001178static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001180 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1181 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001184static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185{
Trond Myklebustab19b482012-03-04 18:13:57 -05001186 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001187 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001188 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189}
1190
Fred Isaman0b7c0152012-04-20 14:47:39 -04001191static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192{
Al Viro8687b632006-10-19 23:28:48 -07001193 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001194
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001195 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1196 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001197 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001198 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001201static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
Al Viro8687b632006-10-19 23:28:48 -07001203 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001204
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001205 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1206 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
1208 switch (create->ftype) {
1209 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001210 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001211 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001212 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1213 create->u.symlink.len);
1214 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 break;
1216
1217 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001218 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001219 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001220 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 break;
1222
1223 default:
1224 break;
1225 }
1226
Benny Halevy811652b2009-08-14 17:19:34 +03001227 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001228 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1229 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230}
1231
Trond Myklebust37c88762018-03-20 17:03:08 -04001232static void encode_getattr(struct xdr_stream *xdr,
1233 const __u32 *bitmap, const __u32 *mask, size_t len,
1234 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235{
Trond Myklebust37c88762018-03-20 17:03:08 -04001236 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001238 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001239 if (mask) {
1240 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1241 len = ARRAY_SIZE(masked_bitmap);
1242 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1243 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001244 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001245 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001246}
1247
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Trond Myklebust37c88762018-03-20 17:03:08 -04001250 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1251 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Andy Adamson88034c32012-05-23 05:02:34 -04001254static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001255 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001256 struct compound_hdr *hdr)
1257{
Trond Myklebust37c88762018-03-20 17:03:08 -04001258 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001259}
1260
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001261static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Trond Myklebust37c88762018-03-20 17:03:08 -04001263 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1264 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265}
1266
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001267static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001268{
Trond Myklebust37c88762018-03-20 17:03:08 -04001269 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1270 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001271}
1272
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001273static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
Trond Myklebustab19b482012-03-04 18:13:57 -05001275 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001278static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279{
Trond Myklebustab19b482012-03-04 18:13:57 -05001280 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001281 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282}
1283
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001284static inline int nfs4_lock_type(struct file_lock *fl, int block)
1285{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001286 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001287 return block ? NFS4_READW_LT : NFS4_READ_LT;
1288 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1289}
1290
1291static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1292{
1293 if (fl->fl_end == OFFSET_MAX)
1294 return ~(uint64_t)0;
1295 return fl->fl_end - fl->fl_start + 1;
1296}
1297
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001298static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1299{
1300 __be32 *p;
1301
Trond Myklebustd035c362010-12-21 10:45:27 -05001302 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001303 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001304 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001305 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001306 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001307 xdr_encode_hyper(p, lowner->id);
1308}
1309
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310/*
1311 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1312 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1313 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001314static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Al Viro8687b632006-10-19 23:28:48 -07001316 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001318 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1319 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001320 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1321 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001322 p = xdr_encode_hyper(p, args->fl->fl_start);
1323 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001324 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001325 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001326 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001327 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001328 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001329 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001332 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001333 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001337static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338{
Al Viro8687b632006-10-19 23:28:48 -07001339 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001341 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1342 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001343 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001344 p = xdr_encode_hyper(p, args->fl->fl_start);
1345 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001346 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001349static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
Al Viro8687b632006-10-19 23:28:48 -07001351 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001353 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1354 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001355 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001356 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001357 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001358 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001359 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001362static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1363{
Trond Myklebustab19b482012-03-04 18:13:57 -05001364 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001365 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001366}
1367
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001368static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369{
Trond Myklebustab19b482012-03-04 18:13:57 -05001370 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001371 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372}
1373
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001374static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1375{
1376 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1377}
1378
Trond Myklebust6ae37332015-01-30 14:21:14 -05001379static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380{
Al Viro8687b632006-10-19 23:28:48 -07001381 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Benny Halevy13c65ce2009-08-14 17:19:25 +03001383 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001384 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001385 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386}
1387
1388static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1389{
Al Viro8687b632006-10-19 23:28:48 -07001390 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 /*
1392 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1393 * owner 4 = 32
1394 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001395 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001396 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001397 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001398 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001399 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001400 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001401 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001402 *p++ = cpu_to_be32(arg->id.uniquifier);
1403 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404}
1405
1406static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1407{
Al Viro8687b632006-10-19 23:28:48 -07001408 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Benny Halevy13c65ce2009-08-14 17:19:25 +03001410 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001411 switch(arg->createmode) {
1412 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001413 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001414 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1415 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001416 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001417 case NFS4_CREATE_GUARDED:
1418 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001419 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1420 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001421 break;
1422 case NFS4_CREATE_EXCLUSIVE:
1423 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1424 encode_nfs4_verifier(xdr, &arg->u.verifier);
1425 break;
1426 case NFS4_CREATE_EXCLUSIVE4_1:
1427 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1428 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001429 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1430 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432}
1433
1434static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1435{
Al Viro8687b632006-10-19 23:28:48 -07001436 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
Benny Halevy13c65ce2009-08-14 17:19:25 +03001438 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001441 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001442 break;
1443 default:
Benny Halevy34558512009-08-14 17:19:30 +03001444 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001445 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 }
1447}
1448
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001449static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450{
Al Viro8687b632006-10-19 23:28:48 -07001451 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452
Benny Halevy13c65ce2009-08-14 17:19:25 +03001453 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001455 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001456 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001457 break;
1458 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001459 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001460 break;
1461 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001462 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001463 break;
1464 default:
1465 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 }
1467}
1468
1469static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1470{
Al Viro8687b632006-10-19 23:28:48 -07001471 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
Benny Halevy13c65ce2009-08-14 17:19:25 +03001473 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001474 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 encode_string(xdr, name->len, name->name);
1476}
1477
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001478static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Al Viro8687b632006-10-19 23:28:48 -07001480 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Benny Halevy13c65ce2009-08-14 17:19:25 +03001482 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001483 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 encode_delegation_type(xdr, type);
1485}
1486
1487static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1488{
Al Viro8687b632006-10-19 23:28:48 -07001489 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001491 p = reserve_space(xdr, 4);
1492 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1493 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 encode_string(xdr, name->len, name->name);
1495}
1496
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001497static inline void encode_claim_fh(struct xdr_stream *xdr)
1498{
1499 __be32 *p;
1500
1501 p = reserve_space(xdr, 4);
1502 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1503}
1504
1505static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1506{
1507 __be32 *p;
1508
1509 p = reserve_space(xdr, 4);
1510 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1511 encode_nfs4_stateid(xdr, stateid);
1512}
1513
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001514static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
Trond Myklebustab19b482012-03-04 18:13:57 -05001516 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 encode_openhdr(xdr, arg);
1518 encode_opentype(xdr, arg);
1519 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001520 case NFS4_OPEN_CLAIM_NULL:
1521 encode_claim_null(xdr, arg->name);
1522 break;
1523 case NFS4_OPEN_CLAIM_PREVIOUS:
1524 encode_claim_previous(xdr, arg->u.delegation_type);
1525 break;
1526 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1527 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1528 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001529 case NFS4_OPEN_CLAIM_FH:
1530 encode_claim_fh(xdr);
1531 break;
1532 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1533 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1534 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001535 default:
1536 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538}
1539
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001540static 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 -07001541{
Trond Myklebustab19b482012-03-04 18:13:57 -05001542 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001543 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001544 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545}
1546
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001547static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *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_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001550 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001551 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001552 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553}
1554
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001555static void
Andy Adamsond0179312008-12-23 16:06:17 -05001556encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
Trond Myklebustab19b482012-03-04 18:13:57 -05001558 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001559 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560}
1561
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001562static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563{
Trond Myklebustab19b482012-03-04 18:13:57 -05001564 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001567static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1568 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569{
Al Viro8687b632006-10-19 23:28:48 -07001570 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
Trond Myklebustab19b482012-03-04 18:13:57 -05001572 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001573 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Benny Halevy13c65ce2009-08-14 17:19:25 +03001575 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001576 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001577 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578}
1579
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001580static 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 -07001581{
David Quigleyaa9c2662013-05-22 12:50:44 -04001582 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001583 FATTR4_WORD0_RDATTR_ERROR,
1584 FATTR4_WORD1_MOUNTED_ON_FILEID,
1585 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001586 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001587 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001588 uint32_t attrlen = 0;
1589 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001591 if (readdir->plus) {
1592 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001593 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001594 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1595 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1596 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1597 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001598 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001599 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001600 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001601 /* Use mounted_on_fileid only if the server supports it */
1602 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1603 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001604 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1605 attrs[i] &= readdir->bitmask[i];
1606 if (attrs[i] != 0)
1607 attrlen = i+1;
1608 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001609
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001610 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001611 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001612 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001613 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001614 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001615 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001616 *p++ = cpu_to_be32(attrlen);
1617 for (i = 0; i < attrlen; i++)
1618 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001619 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001620
1621 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001622 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001623 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001624 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001625 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001626 attrs[1] & readdir->bitmask[1],
1627 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628}
1629
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001630static 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 -07001631{
Trond Myklebustab19b482012-03-04 18:13:57 -05001632 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001635static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636{
Trond Myklebustab19b482012-03-04 18:13:57 -05001637 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001638 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639}
1640
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001641static 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 -07001642{
Trond Myklebustab19b482012-03-04 18:13:57 -05001643 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001644 encode_string(xdr, oldname->len, oldname->name);
1645 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646}
1647
Chuck Leverbb4dae52012-03-01 17:01:48 -05001648static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1649 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001651 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001652 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653}
1654
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001655static void
Andy Adamsond0179312008-12-23 16:06:17 -05001656encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001657{
Trond Myklebustab19b482012-03-04 18:13:57 -05001658 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001659}
1660
Chuck Lever9f06c712010-12-14 14:59:18 +00001661static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001662encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1663 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001664{
Al Viro8687b632006-10-19 23:28:48 -07001665 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001666
Trond Myklebustab19b482012-03-04 18:13:57 -05001667 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001668 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001669 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001670 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001671 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001672 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001673 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001674 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001675}
1676
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001677static void
Andy Adamsond0179312008-12-23 16:06:17 -05001678encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
Trond Myklebustab19b482012-03-04 18:13:57 -05001680 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681}
1682
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001683static 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 -07001684{
Trond Myklebustab19b482012-03-04 18:13:57 -05001685 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001686 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001687 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1688 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689}
1690
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001691static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692{
Al Viro8687b632006-10-19 23:28:48 -07001693 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694
Trond Myklebust70019512012-03-04 20:49:32 -05001695 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001696 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Jeff Layton3a6bb732015-06-09 19:43:57 -04001698 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1699 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001700 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001701 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1703 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001704 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001705 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706}
1707
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001708static 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 -07001709{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001710 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1711 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001712 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001713 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714}
1715
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001716static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1717 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718{
Al Viro8687b632006-10-19 23:28:48 -07001719 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
Trond Myklebustab19b482012-03-04 18:13:57 -05001721 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001722 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
Benny Halevy13c65ce2009-08-14 17:19:25 +03001724 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001725 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001726 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001727 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
1729 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730}
1731
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001732static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733{
Trond Myklebustab19b482012-03-04 18:13:57 -05001734 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001735 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001737
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001738static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1739{
Trond Myklebustab19b482012-03-04 18:13:57 -05001740 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001741 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001742}
1743
Benny Halevy99fe60d2009-04-01 09:22:29 -04001744#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001745/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001746static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001747 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001748 struct compound_hdr *hdr)
1749{
1750 __be32 *p;
1751
1752 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1753 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001754 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001755 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001756 *p++ = cpu_to_be32(args->dir);
1757 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001758}
1759
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001760static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001761{
1762 unsigned int i;
1763 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1764 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1765 encode_uint32(xdr, op_map->u.words[i]);
1766}
1767
Benny Halevy99fe60d2009-04-01 09:22:29 -04001768static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001769 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001770 struct compound_hdr *hdr)
1771{
1772 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001773 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001774 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001775
Trond Myklebust70019512012-03-04 20:49:32 -05001776 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001777 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001778
Jeff Layton3a6bb732015-06-09 19:43:57 -04001779 encode_string(xdr, strlen(args->client->cl_owner_id),
1780 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001781
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001782 encode_uint32(xdr, args->flags);
1783 encode_uint32(xdr, args->state_protect.how);
1784
1785 switch (args->state_protect.how) {
1786 case SP4_NONE:
1787 break;
1788 case SP4_MACH_CRED:
1789 encode_op_map(xdr, &args->state_protect.enforce);
1790 encode_op_map(xdr, &args->state_protect.allow);
1791 break;
1792 default:
1793 WARN_ON_ONCE(1);
1794 break;
1795 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001796
1797 if (send_implementation_id &&
1798 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1799 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001800 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001801 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1802 utsname()->sysname, utsname()->release,
1803 utsname()->version, utsname()->machine);
1804
1805 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001806 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001807
1808 encode_string(xdr,
1809 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1810 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1811 encode_string(xdr, len, impl_name);
1812 /* just send zeros for nii_date - the date is in nii_name */
1813 p = reserve_space(xdr, 12);
1814 p = xdr_encode_hyper(p, 0);
1815 *p = cpu_to_be32(0);
1816 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001817 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001818}
Andy Adamsonfc931582009-04-01 09:22:31 -04001819
1820static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001821 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001822 struct compound_hdr *hdr)
1823{
1824 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001825 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001826 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001827 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001828 u32 max_resp_sz_cached;
1829
1830 /*
1831 * Assumes OPEN is the biggest non-idempotent compound.
1832 * 2 is the verifier.
1833 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001834 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1835 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001836
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001837 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001838 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001839 p = xdr_encode_hyper(p, args->clientid);
1840 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001841 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001842
Andy Adamsonfc931582009-04-01 09:22:31 -04001843 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001844 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001845 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1846 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001847 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1849 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1850 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001851
1852 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001853 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001854 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1855 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1856 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1857 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1858 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1859 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001860
Benny Halevye75bc1c2009-08-14 17:18:54 +03001861 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001862 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001863 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001864
1865 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001866 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001867 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001868 *p++ = cpu_to_be32(0); /* UID */
1869 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001870 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001871}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001872
1873static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001874 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001875 struct compound_hdr *hdr)
1876{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001877 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1878 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001879}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001880
Trond Myklebust66245532012-05-25 17:18:09 -04001881static void encode_destroy_clientid(struct xdr_stream *xdr,
1882 uint64_t clientid,
1883 struct compound_hdr *hdr)
1884{
1885 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1886 encode_uint64(xdr, clientid);
1887}
1888
Ricardo Labiaga180197532009-12-05 16:08:40 -05001889static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001890 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001891 struct compound_hdr *hdr)
1892{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001893 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1894 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001895}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001896#endif /* CONFIG_NFS_V4_1 */
1897
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001898static void encode_sequence(struct xdr_stream *xdr,
1899 const struct nfs4_sequence_args *args,
1900 struct compound_hdr *hdr)
1901{
1902#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001903 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001904 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001905 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001906 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001907
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001908 tp = slot->table;
1909 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001910 if (!session)
1911 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001912
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001913 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001914
1915 /*
1916 * Sessionid + seqid + slotid + max slotid + cache_this
1917 */
1918 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1919 "max_slotid=%d cache_this=%d\n",
1920 __func__,
1921 ((u32 *)session->sess_id.data)[0],
1922 ((u32 *)session->sess_id.data)[1],
1923 ((u32 *)session->sess_id.data)[2],
1924 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001925 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001926 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001927 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001928 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001929 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001930 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001931 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001932 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001933#endif /* CONFIG_NFS_V4_1 */
1934}
1935
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001936#ifdef CONFIG_NFS_V4_1
1937static void
1938encode_getdeviceinfo(struct xdr_stream *xdr,
1939 const struct nfs4_getdeviceinfo_args *args,
1940 struct compound_hdr *hdr)
1941{
1942 __be32 *p;
1943
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001944 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001945 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001946 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1947 NFS4_DEVICEID4_SIZE);
1948 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001949 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001950
1951 p = reserve_space(xdr, 4 + 4);
1952 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001953 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001954}
1955
1956static void
1957encode_layoutget(struct xdr_stream *xdr,
1958 const struct nfs4_layoutget_args *args,
1959 struct compound_hdr *hdr)
1960{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001961 __be32 *p;
1962
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001963 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1964 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001965 *p++ = cpu_to_be32(0); /* Signal layout available */
1966 *p++ = cpu_to_be32(args->type);
1967 *p++ = cpu_to_be32(args->range.iomode);
1968 p = xdr_encode_hyper(p, args->range.offset);
1969 p = xdr_encode_hyper(p, args->range.length);
1970 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001971 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001972 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001973
1974 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1975 __func__,
1976 args->type,
1977 args->range.iomode,
1978 (unsigned long)args->range.offset,
1979 (unsigned long)args->range.length,
1980 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001981}
Andy Adamson863a3c62011-03-23 13:27:54 +00001982
1983static int
1984encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001985 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001986 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001987 struct compound_hdr *hdr)
1988{
1989 __be32 *p;
1990
1991 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1992 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1993
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001994 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1995 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001996 /* Only whole file layouts */
1997 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001998 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001999 *p = cpu_to_be32(0); /* reclaim */
2000 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002001 if (args->lastbytewritten != U64_MAX) {
2002 p = reserve_space(xdr, 20);
2003 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2004 p = xdr_encode_hyper(p, args->lastbytewritten);
2005 } else {
2006 p = reserve_space(xdr, 12);
2007 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2008 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002009 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2010 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002011
Trond Myklebust73504742017-04-20 16:48:14 -04002012 encode_uint32(xdr, args->layoutupdate_len);
2013 if (args->layoutupdate_pages)
2014 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2015 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002016
Andy Adamson863a3c62011-03-23 13:27:54 +00002017 return 0;
2018}
Benny Halevycbe82602011-05-22 19:52:37 +03002019
2020static void
2021encode_layoutreturn(struct xdr_stream *xdr,
2022 const struct nfs4_layoutreturn_args *args,
2023 struct compound_hdr *hdr)
2024{
2025 __be32 *p;
2026
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002027 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2028 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002029 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2030 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002031 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002032 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002033 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002034 p = xdr_encode_hyper(p, args->range.offset);
2035 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002036 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002037 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002038 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002039 if (args->ld_private->ops && args->ld_private->ops->encode)
2040 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002041 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002042 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002043}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002044
2045static int
2046encode_secinfo_no_name(struct xdr_stream *xdr,
2047 const struct nfs41_secinfo_no_name_args *args,
2048 struct compound_hdr *hdr)
2049{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002050 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2051 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002052 return 0;
2053}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002054
2055static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002056 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002057 struct compound_hdr *hdr)
2058{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002059 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2060 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002061 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002062}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002063
2064static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002065 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002066 struct compound_hdr *hdr)
2067{
Trond Myklebustab19b482012-03-04 18:13:57 -05002068 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002069 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002070}
Trond Myklebustcf805162016-11-15 14:56:07 -05002071#else
2072static inline void
2073encode_layoutreturn(struct xdr_stream *xdr,
2074 const struct nfs4_layoutreturn_args *args,
2075 struct compound_hdr *hdr)
2076{
2077}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002078#endif /* CONFIG_NFS_V4_1 */
2079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080/*
2081 * END OF "GENERIC" ENCODE ROUTINES.
2082 */
2083
Benny Halevy66cc0422009-04-01 09:22:10 -04002084static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2085{
2086#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002087 struct nfs4_session *session = args->sa_slot->table->session;
2088 if (session)
2089 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002090#endif /* CONFIG_NFS_V4_1 */
2091 return 0;
2092}
2093
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094/*
2095 * Encode an ACCESS request
2096 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002097static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002098 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002100 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002102 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
Chuck Lever9f06c712010-12-14 14:59:18 +00002105 encode_compound_hdr(xdr, req, &hdr);
2106 encode_sequence(xdr, &args->seq_args, &hdr);
2107 encode_putfh(xdr, args->fh, &hdr);
2108 encode_access(xdr, args->access, &hdr);
2109 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002110 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
2112
2113/*
2114 * Encode LOOKUP request
2115 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002116static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002117 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002119 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002121 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Chuck Lever9f06c712010-12-14 14:59:18 +00002124 encode_compound_hdr(xdr, req, &hdr);
2125 encode_sequence(xdr, &args->seq_args, &hdr);
2126 encode_putfh(xdr, args->dir_fh, &hdr);
2127 encode_lookup(xdr, args->name, &hdr);
2128 encode_getfh(xdr, &hdr);
2129 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002130 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131}
2132
2133/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002134 * Encode LOOKUPP request
2135 */
2136static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2137 const void *data)
2138{
2139 const struct nfs4_lookupp_arg *args = data;
2140 struct compound_hdr hdr = {
2141 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2142 };
2143
2144 encode_compound_hdr(xdr, req, &hdr);
2145 encode_sequence(xdr, &args->seq_args, &hdr);
2146 encode_putfh(xdr, args->fh, &hdr);
2147 encode_lookupp(xdr, &hdr);
2148 encode_getfh(xdr, &hdr);
2149 encode_getfattr(xdr, args->bitmask, &hdr);
2150 encode_nops(&hdr);
2151}
2152
2153/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 * Encode LOOKUP_ROOT request
2155 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002156static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2157 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002158 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002160 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002162 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Chuck Lever9f06c712010-12-14 14:59:18 +00002165 encode_compound_hdr(xdr, req, &hdr);
2166 encode_sequence(xdr, &args->seq_args, &hdr);
2167 encode_putrootfh(xdr, &hdr);
2168 encode_getfh(xdr, &hdr);
2169 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002170 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171}
2172
2173/*
2174 * Encode REMOVE request
2175 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002176static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002177 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002179 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002181 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183
Chuck Lever9f06c712010-12-14 14:59:18 +00002184 encode_compound_hdr(xdr, req, &hdr);
2185 encode_sequence(xdr, &args->seq_args, &hdr);
2186 encode_putfh(xdr, args->fh, &hdr);
2187 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002188 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189}
2190
2191/*
2192 * Encode RENAME request
2193 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002194static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002195 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002197 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002199 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Chuck Lever9f06c712010-12-14 14:59:18 +00002202 encode_compound_hdr(xdr, req, &hdr);
2203 encode_sequence(xdr, &args->seq_args, &hdr);
2204 encode_putfh(xdr, args->old_dir, &hdr);
2205 encode_savefh(xdr, &hdr);
2206 encode_putfh(xdr, args->new_dir, &hdr);
2207 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002208 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209}
2210
2211/*
2212 * Encode LINK request
2213 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002214static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002215 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002217 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002219 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
Chuck Lever9f06c712010-12-14 14:59:18 +00002222 encode_compound_hdr(xdr, req, &hdr);
2223 encode_sequence(xdr, &args->seq_args, &hdr);
2224 encode_putfh(xdr, args->fh, &hdr);
2225 encode_savefh(xdr, &hdr);
2226 encode_putfh(xdr, args->dir_fh, &hdr);
2227 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002228 encode_restorefh(xdr, &hdr);
2229 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002230 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231}
2232
2233/*
2234 * Encode CREATE request
2235 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002236static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002237 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002239 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002241 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Chuck Lever9f06c712010-12-14 14:59:18 +00002244 encode_compound_hdr(xdr, req, &hdr);
2245 encode_sequence(xdr, &args->seq_args, &hdr);
2246 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002247 encode_create(xdr, args, &hdr);
2248 encode_getfh(xdr, &hdr);
2249 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002250 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251}
2252
2253/*
2254 * Encode SYMLINK request
2255 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002256static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002257 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002259 const struct nfs4_create_arg *args = data;
2260
Chuck Lever9f06c712010-12-14 14:59:18 +00002261 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262}
2263
2264/*
2265 * Encode GETATTR request
2266 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002267static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002268 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002270 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002272 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
Chuck Lever9f06c712010-12-14 14:59:18 +00002275 encode_compound_hdr(xdr, req, &hdr);
2276 encode_sequence(xdr, &args->seq_args, &hdr);
2277 encode_putfh(xdr, args->fh, &hdr);
2278 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002279 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280}
2281
2282/*
2283 * Encode a CLOSE request
2284 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002285static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002286 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002288 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002289 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002290 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002291 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292
Chuck Lever9f06c712010-12-14 14:59:18 +00002293 encode_compound_hdr(xdr, req, &hdr);
2294 encode_sequence(xdr, &args->seq_args, &hdr);
2295 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002296 if (args->lr_args)
2297 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002298 if (args->bitmask != NULL)
2299 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002300 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002301 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302}
2303
2304/*
2305 * Encode an OPEN request
2306 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002307static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002308 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002310 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002312 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
Chuck Lever9f06c712010-12-14 14:59:18 +00002315 encode_compound_hdr(xdr, req, &hdr);
2316 encode_sequence(xdr, &args->seq_args, &hdr);
2317 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002318 encode_open(xdr, args, &hdr);
2319 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002320 if (args->access)
2321 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002322 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002323 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324}
2325
2326/*
2327 * Encode an OPEN_CONFIRM request
2328 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002329static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2330 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002331 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002333 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002335 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Chuck Lever9f06c712010-12-14 14:59:18 +00002338 encode_compound_hdr(xdr, req, &hdr);
2339 encode_putfh(xdr, args->fh, &hdr);
2340 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002341 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342}
2343
2344/*
2345 * Encode an OPEN request with no attributes.
2346 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002347static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2348 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002349 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002351 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002353 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Chuck Lever9f06c712010-12-14 14:59:18 +00002356 encode_compound_hdr(xdr, req, &hdr);
2357 encode_sequence(xdr, &args->seq_args, &hdr);
2358 encode_putfh(xdr, args->fh, &hdr);
2359 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002360 if (args->access)
2361 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002362 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002363 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364}
2365
2366/*
2367 * Encode an OPEN_DOWNGRADE request
2368 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002369static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2370 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002371 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002373 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002375 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377
Chuck Lever9f06c712010-12-14 14:59:18 +00002378 encode_compound_hdr(xdr, req, &hdr);
2379 encode_sequence(xdr, &args->seq_args, &hdr);
2380 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002381 if (args->lr_args)
2382 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002383 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002384 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385}
2386
2387/*
2388 * Encode a LOCK request
2389 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002390static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002391 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002393 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002395 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397
Chuck Lever9f06c712010-12-14 14:59:18 +00002398 encode_compound_hdr(xdr, req, &hdr);
2399 encode_sequence(xdr, &args->seq_args, &hdr);
2400 encode_putfh(xdr, args->fh, &hdr);
2401 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002402 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
2405/*
2406 * Encode a LOCKT request
2407 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002408static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002409 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002411 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002413 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415
Chuck Lever9f06c712010-12-14 14:59:18 +00002416 encode_compound_hdr(xdr, req, &hdr);
2417 encode_sequence(xdr, &args->seq_args, &hdr);
2418 encode_putfh(xdr, args->fh, &hdr);
2419 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002420 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421}
2422
2423/*
2424 * Encode a LOCKU request
2425 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002426static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002427 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002429 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002431 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433
Chuck Lever9f06c712010-12-14 14:59:18 +00002434 encode_compound_hdr(xdr, req, &hdr);
2435 encode_sequence(xdr, &args->seq_args, &hdr);
2436 encode_putfh(xdr, args->fh, &hdr);
2437 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002438 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439}
2440
Chuck Lever9f06c712010-12-14 14:59:18 +00002441static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2442 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002443 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002444{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002445 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002446 struct compound_hdr hdr = {
2447 .minorversion = 0,
2448 };
2449
Chuck Lever9f06c712010-12-14 14:59:18 +00002450 encode_compound_hdr(xdr, req, &hdr);
2451 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002452 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002453}
2454
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455/*
2456 * Encode a READLINK request
2457 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002458static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002459 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002461 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002463 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465
Chuck Lever9f06c712010-12-14 14:59:18 +00002466 encode_compound_hdr(xdr, req, &hdr);
2467 encode_sequence(xdr, &args->seq_args, &hdr);
2468 encode_putfh(xdr, args->fh, &hdr);
2469 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002470
Benny Halevy28f56692009-04-01 09:22:09 -04002471 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002472 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002473 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474}
2475
2476/*
2477 * Encode a READDIR request
2478 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002479static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002480 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002482 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002484 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Chuck Lever9f06c712010-12-14 14:59:18 +00002487 encode_compound_hdr(xdr, req, &hdr);
2488 encode_sequence(xdr, &args->seq_args, &hdr);
2489 encode_putfh(xdr, args->fh, &hdr);
2490 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002491
Benny Halevy28f56692009-04-01 09:22:09 -04002492 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002493 args->pgbase, args->count);
2494 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002495 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002496 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002497 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498}
2499
2500/*
2501 * Encode a READ request
2502 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002503static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002504 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002506 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002508 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
Chuck Lever9f06c712010-12-14 14:59:18 +00002511 encode_compound_hdr(xdr, req, &hdr);
2512 encode_sequence(xdr, &args->seq_args, &hdr);
2513 encode_putfh(xdr, args->fh, &hdr);
2514 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515
Benny Halevy28f56692009-04-01 09:22:09 -04002516 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002518 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002519 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520}
2521
2522/*
2523 * Encode an SETATTR request
2524 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002525static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002526 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002528 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002529 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002530 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002531 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Chuck Lever9f06c712010-12-14 14:59:18 +00002533 encode_compound_hdr(xdr, req, &hdr);
2534 encode_sequence(xdr, &args->seq_args, &hdr);
2535 encode_putfh(xdr, args->fh, &hdr);
2536 encode_setattr(xdr, args, args->server, &hdr);
2537 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002538 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539}
2540
2541/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002542 * Encode a GETACL request
2543 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002544static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002545 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002546{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002547 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002548 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002549 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002550 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002551 const __u32 nfs4_acl_bitmap[1] = {
2552 [0] = FATTR4_WORD0_ACL,
2553 };
Benny Halevy28f56692009-04-01 09:22:09 -04002554 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002555
Chuck Lever9f06c712010-12-14 14:59:18 +00002556 encode_compound_hdr(xdr, req, &hdr);
2557 encode_sequence(xdr, &args->seq_args, &hdr);
2558 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002559 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002560 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2561 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002562
Benny Halevy28f56692009-04-01 09:22:09 -04002563 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002564 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002565
Andy Adamsond0179312008-12-23 16:06:17 -05002566 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002567}
2568
2569/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 * Encode a WRITE request
2571 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002572static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002573 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002575 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002577 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579
Chuck Lever9f06c712010-12-14 14:59:18 +00002580 encode_compound_hdr(xdr, req, &hdr);
2581 encode_sequence(xdr, &args->seq_args, &hdr);
2582 encode_putfh(xdr, args->fh, &hdr);
2583 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002584 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002585 if (args->bitmask)
2586 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002587 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588}
2589
2590/*
2591 * a COMMIT request
2592 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002593static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002594 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002596 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002598 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
Chuck Lever9f06c712010-12-14 14:59:18 +00002601 encode_compound_hdr(xdr, req, &hdr);
2602 encode_sequence(xdr, &args->seq_args, &hdr);
2603 encode_putfh(xdr, args->fh, &hdr);
2604 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002605 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606}
2607
2608/*
2609 * FSINFO request
2610 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002611static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002612 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002614 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002616 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
Chuck Lever9f06c712010-12-14 14:59:18 +00002619 encode_compound_hdr(xdr, req, &hdr);
2620 encode_sequence(xdr, &args->seq_args, &hdr);
2621 encode_putfh(xdr, args->fh, &hdr);
2622 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002623 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624}
2625
2626/*
2627 * a PATHCONF request
2628 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002629static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002630 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002632 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002634 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
Chuck Lever9f06c712010-12-14 14:59:18 +00002637 encode_compound_hdr(xdr, req, &hdr);
2638 encode_sequence(xdr, &args->seq_args, &hdr);
2639 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002640 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2641 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002642 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643}
2644
2645/*
2646 * a STATFS request
2647 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002648static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002649 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002651 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002653 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
Chuck Lever9f06c712010-12-14 14:59:18 +00002656 encode_compound_hdr(xdr, req, &hdr);
2657 encode_sequence(xdr, &args->seq_args, &hdr);
2658 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002659 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2660 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002661 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662}
2663
2664/*
2665 * GETATTR_BITMAP request
2666 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002667static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2668 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002669 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002671 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002672 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002674 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Chuck Lever9f06c712010-12-14 14:59:18 +00002677 encode_compound_hdr(xdr, req, &hdr);
2678 encode_sequence(xdr, &args->seq_args, &hdr);
2679 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002680 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002681 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682}
2683
2684/*
2685 * a RENEW request
2686 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002687static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002688 const void *data)
2689
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002691 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002693 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 };
2695
Chuck Lever9f06c712010-12-14 14:59:18 +00002696 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002697 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002698 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699}
2700
2701/*
2702 * a SETCLIENTID request
2703 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002704static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2705 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002706 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002708 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002710 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 };
2712
Chuck Lever9f06c712010-12-14 14:59:18 +00002713 encode_compound_hdr(xdr, req, &hdr);
2714 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002715 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716}
2717
2718/*
2719 * a SETCLIENTID_CONFIRM request
2720 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002721static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2722 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002723 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002725 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002727 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
Chuck Lever9f06c712010-12-14 14:59:18 +00002730 encode_compound_hdr(xdr, req, &hdr);
2731 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002732 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733}
2734
2735/*
2736 * DELEGRETURN request
2737 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002738static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2739 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002740 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002742 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002744 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
Chuck Lever9f06c712010-12-14 14:59:18 +00002747 encode_compound_hdr(xdr, req, &hdr);
2748 encode_sequence(xdr, &args->seq_args, &hdr);
2749 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002750 if (args->lr_args)
2751 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002752 if (args->bitmask)
2753 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002754 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002755 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756}
2757
2758/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002759 * Encode FS_LOCATIONS request
2760 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002761static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2762 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002763 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002764{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002765 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002766 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002767 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002768 };
Benny Halevy28f56692009-04-01 09:22:09 -04002769 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002770
Chuck Lever9f06c712010-12-14 14:59:18 +00002771 encode_compound_hdr(xdr, req, &hdr);
2772 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002773 if (args->migration) {
2774 encode_putfh(xdr, args->fh, &hdr);
2775 replen = hdr.replen;
2776 encode_fs_locations(xdr, args->bitmask, &hdr);
2777 if (args->renew)
2778 encode_renew(xdr, args->clientid, &hdr);
2779 } else {
2780 encode_putfh(xdr, args->dir_fh, &hdr);
2781 encode_lookup(xdr, args->name, &hdr);
2782 replen = hdr.replen;
2783 encode_fs_locations(xdr, args->bitmask, &hdr);
2784 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002785
Chuck Leverb03d7352013-10-17 14:12:50 -04002786 /* Set up reply kvec to capture returned fs_locations array. */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002787 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2788 (struct page **)&args->page, 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002789 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002790}
2791
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002792/*
2793 * Encode SECINFO request
2794 */
2795static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2796 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002797 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002798{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002799 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002800 struct compound_hdr hdr = {
2801 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2802 };
2803
2804 encode_compound_hdr(xdr, req, &hdr);
2805 encode_sequence(xdr, &args->seq_args, &hdr);
2806 encode_putfh(xdr, args->dir_fh, &hdr);
2807 encode_secinfo(xdr, args->name, &hdr);
2808 encode_nops(&hdr);
2809}
2810
Chuck Lever44c99932013-10-17 14:13:30 -04002811/*
2812 * Encode FSID_PRESENT request
2813 */
2814static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2815 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002816 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002817{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002818 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002819 struct compound_hdr hdr = {
2820 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2821 };
2822
2823 encode_compound_hdr(xdr, req, &hdr);
2824 encode_sequence(xdr, &args->seq_args, &hdr);
2825 encode_putfh(xdr, args->fh, &hdr);
2826 encode_getfh(xdr, &hdr);
2827 if (args->renew)
2828 encode_renew(xdr, args->clientid, &hdr);
2829 encode_nops(&hdr);
2830}
2831
Benny Halevy99fe60d2009-04-01 09:22:29 -04002832#if defined(CONFIG_NFS_V4_1)
2833/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002834 * BIND_CONN_TO_SESSION request
2835 */
2836static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2837 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002838 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002839{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002840 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002841 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002842 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002843 };
2844
2845 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002846 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002847 encode_nops(&hdr);
2848}
2849
2850/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002851 * EXCHANGE_ID request
2852 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002853static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2854 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002855 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002856{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002857 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002858 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002859 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002860 };
2861
Chuck Lever9f06c712010-12-14 14:59:18 +00002862 encode_compound_hdr(xdr, req, &hdr);
2863 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002864 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002865}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002866
2867/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002868 * a CREATE_SESSION request
2869 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002870static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2871 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002872 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002873{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002874 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002875 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002876 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002877 };
2878
Chuck Lever9f06c712010-12-14 14:59:18 +00002879 encode_compound_hdr(xdr, req, &hdr);
2880 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002881 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002882}
2883
2884/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002885 * a DESTROY_SESSION request
2886 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002887static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2888 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002889 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002890{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002891 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002892 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002893 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002894 };
2895
Chuck Lever9f06c712010-12-14 14:59:18 +00002896 encode_compound_hdr(xdr, req, &hdr);
2897 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002898 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002899}
2900
2901/*
Trond Myklebust66245532012-05-25 17:18:09 -04002902 * a DESTROY_CLIENTID request
2903 */
2904static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2905 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002906 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002907{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002908 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002909 struct compound_hdr hdr = {
2910 .minorversion = clp->cl_mvops->minor_version,
2911 };
2912
2913 encode_compound_hdr(xdr, req, &hdr);
2914 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2915 encode_nops(&hdr);
2916}
2917
2918/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002919 * a SEQUENCE request
2920 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002921static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002922 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002923{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002924 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002925 struct compound_hdr hdr = {
2926 .minorversion = nfs4_xdr_minorversion(args),
2927 };
2928
Chuck Lever9f06c712010-12-14 14:59:18 +00002929 encode_compound_hdr(xdr, req, &hdr);
2930 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002931 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002932}
2933
2934/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002935 * a GET_LEASE_TIME request
2936 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002937static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2938 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002939 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002940{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002941 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002942 struct compound_hdr hdr = {
2943 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2944 };
Fred Isamandae100c2011-07-30 20:52:37 -04002945 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002946
Chuck Lever9f06c712010-12-14 14:59:18 +00002947 encode_compound_hdr(xdr, req, &hdr);
2948 encode_sequence(xdr, &args->la_seq_args, &hdr);
2949 encode_putrootfh(xdr, &hdr);
2950 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002951 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002952}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002953
2954/*
2955 * a RECLAIM_COMPLETE request
2956 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002957static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2958 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002959 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002960{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002961 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002962 struct compound_hdr hdr = {
2963 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2964 };
2965
Chuck Lever9f06c712010-12-14 14:59:18 +00002966 encode_compound_hdr(xdr, req, &hdr);
2967 encode_sequence(xdr, &args->seq_args, &hdr);
2968 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002969 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002970}
2971
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002972/*
2973 * Encode GETDEVICEINFO request
2974 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002975static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2976 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002977 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002978{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002979 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002980 struct compound_hdr hdr = {
2981 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2982 };
2983
Chuck Lever9f06c712010-12-14 14:59:18 +00002984 encode_compound_hdr(xdr, req, &hdr);
2985 encode_sequence(xdr, &args->seq_args, &hdr);
2986 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002987
2988 /* set up reply kvec. Subtract notification bitmap max size (2)
2989 * so that notification bitmap is put in xdr_buf tail */
2990 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2991 args->pdev->pages, args->pdev->pgbase,
2992 args->pdev->pglen);
2993
2994 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002995}
2996
2997/*
2998 * Encode LAYOUTGET request
2999 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003000static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3001 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003002 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003003{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003004 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003005 struct compound_hdr hdr = {
3006 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3007 };
3008
Chuck Lever9f06c712010-12-14 14:59:18 +00003009 encode_compound_hdr(xdr, req, &hdr);
3010 encode_sequence(xdr, &args->seq_args, &hdr);
3011 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3012 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003013
3014 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
3015 args->layout.pages, 0, args->layout.pglen);
3016
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003017 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003018}
Andy Adamson863a3c62011-03-23 13:27:54 +00003019
3020/*
3021 * Encode LAYOUTCOMMIT request
3022 */
Benny Halevycbe82602011-05-22 19:52:37 +03003023static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3024 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003025 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003026{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003027 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003028 struct nfs4_layoutcommit_data *data =
3029 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003030 struct compound_hdr hdr = {
3031 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3032 };
3033
3034 encode_compound_hdr(xdr, req, &hdr);
3035 encode_sequence(xdr, &args->seq_args, &hdr);
3036 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003037 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003038 encode_getfattr(xdr, args->bitmask, &hdr);
3039 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003040}
3041
3042/*
3043 * Encode LAYOUTRETURN request
3044 */
3045static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3046 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003047 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003048{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003049 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003050 struct compound_hdr hdr = {
3051 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3052 };
3053
3054 encode_compound_hdr(xdr, req, &hdr);
3055 encode_sequence(xdr, &args->seq_args, &hdr);
3056 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3057 encode_layoutreturn(xdr, args, &hdr);
3058 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003059}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003060
3061/*
3062 * Encode SECINFO_NO_NAME request
3063 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003064static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003065 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003066 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003067{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003068 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003069 struct compound_hdr hdr = {
3070 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3071 };
3072
3073 encode_compound_hdr(xdr, req, &hdr);
3074 encode_sequence(xdr, &args->seq_args, &hdr);
3075 encode_putrootfh(xdr, &hdr);
3076 encode_secinfo_no_name(xdr, args, &hdr);
3077 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003078}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003079
3080/*
3081 * Encode TEST_STATEID request
3082 */
3083static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3084 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003085 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003086{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003087 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003088 struct compound_hdr hdr = {
3089 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3090 };
3091
3092 encode_compound_hdr(xdr, req, &hdr);
3093 encode_sequence(xdr, &args->seq_args, &hdr);
3094 encode_test_stateid(xdr, args, &hdr);
3095 encode_nops(&hdr);
3096}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003097
3098/*
3099 * Encode FREE_STATEID request
3100 */
3101static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3102 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003103 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003104{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003105 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003106 struct compound_hdr hdr = {
3107 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3108 };
3109
3110 encode_compound_hdr(xdr, req, &hdr);
3111 encode_sequence(xdr, &args->seq_args, &hdr);
3112 encode_free_stateid(xdr, args, &hdr);
3113 encode_nops(&hdr);
3114}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003115#endif /* CONFIG_NFS_V4_1 */
3116
Benny Halevy686841b2009-08-14 17:19:48 +03003117static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3118{
3119 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3120 "Remaining buffer length is %tu words.\n",
3121 func, xdr->end - xdr->p);
3122}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
Trond Myklebust683b57b2006-06-09 09:34:22 -04003124static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003126 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3127 NFS4_OPAQUE_LIMIT);
3128 if (unlikely(ret < 0)) {
3129 if (ret == -EBADMSG)
3130 print_overflow_msg(__func__, xdr);
3131 return -EIO;
3132 }
3133 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134 return 0;
3135}
3136
3137static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3138{
Al Viro8687b632006-10-19 23:28:48 -07003139 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
Benny Halevyc0eae662009-08-14 17:20:14 +03003141 p = xdr_inline_decode(xdr, 8);
3142 if (unlikely(!p))
3143 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003144 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003145 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003146
Benny Halevyc0eae662009-08-14 17:20:14 +03003147 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3148 if (unlikely(!p))
3149 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 hdr->tag = (char *)p;
3151 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003152 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003153 if (unlikely(hdr->nops < 1))
3154 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003156out_overflow:
3157 print_overflow_msg(__func__, xdr);
3158 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159}
3160
Trond Myklebustc7848f62013-12-04 17:39:23 -05003161static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3162 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163{
Al Viro8687b632006-10-19 23:28:48 -07003164 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 uint32_t opnum;
3166 int32_t nfserr;
3167
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 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003172 if (unlikely(opnum != expected))
3173 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003174 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003175 if (nfserr == NFS_OK)
3176 *nfs_retval = 0;
3177 else
3178 *nfs_retval = nfs4_stat_to_errno(nfserr);
3179 return true;
3180out_bad_operation:
3181 dprintk("nfs: Server returned operation"
3182 " %d but we issued a request for %d\n",
3183 opnum, expected);
3184 *nfs_retval = -EREMOTEIO;
3185 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003186out_overflow:
3187 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003188 *nfs_retval = -EIO;
3189 return false;
3190}
3191
3192static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3193{
3194 int retval;
3195
3196 __decode_op_hdr(xdr, expected, &retval);
3197 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198}
3199
3200/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003201static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202{
Al Viro8687b632006-10-19 23:28:48 -07003203 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003204 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 char *str;
3206
Benny Halevyc0eae662009-08-14 17:20:14 +03003207 p = xdr_inline_decode(xdr, 12);
3208 if (likely(p))
3209 return decode_opaque_inline(xdr, &strlen, &str);
3210 print_overflow_msg(__func__, xdr);
3211 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212}
3213
Trond Myklebust37c88762018-03-20 17:03:08 -04003214static ssize_t
3215decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216{
Trond Myklebust37c88762018-03-20 17:03:08 -04003217 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218
Trond Myklebust37c88762018-03-20 17:03:08 -04003219 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3220 if (likely(ret >= 0))
3221 return ret;
3222 if (ret == -EMSGSIZE)
3223 return sz;
Benny Halevyc0eae662009-08-14 17:20:14 +03003224 print_overflow_msg(__func__, xdr);
3225 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226}
3227
Trond Myklebust37c88762018-03-20 17:03:08 -04003228static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3229{
3230 ssize_t ret;
3231 ret = decode_bitmap4(xdr, bitmap, 3);
3232 return ret < 0 ? ret : 0;
3233}
3234
Trond Myklebust256e48b2012-06-21 11:18:13 -04003235static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236{
Al Viro8687b632006-10-19 23:28:48 -07003237 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Benny Halevyc0eae662009-08-14 17:20:14 +03003239 p = xdr_inline_decode(xdr, 4);
3240 if (unlikely(!p))
3241 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003242 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003243 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003245out_overflow:
3246 print_overflow_msg(__func__, xdr);
3247 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248}
3249
3250static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3251{
3252 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003253 int ret;
3254 ret = decode_attr_bitmap(xdr, bitmask);
3255 if (unlikely(ret < 0))
3256 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3258 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003259 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3260 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3261 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 return 0;
3263}
3264
3265static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3266{
Al Viro8687b632006-10-19 23:28:48 -07003267 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003268 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269
3270 *type = 0;
3271 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3272 return -EIO;
3273 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003274 p = xdr_inline_decode(xdr, 4);
3275 if (unlikely(!p))
3276 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003277 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003279 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 return -EIO;
3281 }
3282 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003283 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003285 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003286 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003287out_overflow:
3288 print_overflow_msg(__func__, xdr);
3289 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290}
3291
Chuck Lever264e6352012-03-01 17:02:05 -05003292static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3293 uint32_t *bitmap, uint32_t *type)
3294{
3295 __be32 *p;
3296
3297 *type = 0;
3298 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3299 return -EIO;
3300 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3301 p = xdr_inline_decode(xdr, 4);
3302 if (unlikely(!p))
3303 goto out_overflow;
3304 *type = be32_to_cpup(p);
3305 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3306 }
3307 dprintk("%s: expire type=0x%x\n", __func__, *type);
3308 return 0;
3309out_overflow:
3310 print_overflow_msg(__func__, xdr);
3311 return -EIO;
3312}
3313
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3315{
Al Viro8687b632006-10-19 23:28:48 -07003316 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003317 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318
3319 *change = 0;
3320 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3321 return -EIO;
3322 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003323 p = xdr_inline_decode(xdr, 8);
3324 if (unlikely(!p))
3325 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003326 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003328 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003330 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003332 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003333out_overflow:
3334 print_overflow_msg(__func__, xdr);
3335 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336}
3337
3338static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3339{
Al Viro8687b632006-10-19 23:28:48 -07003340 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003341 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342
3343 *size = 0;
3344 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3345 return -EIO;
3346 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003347 p = xdr_inline_decode(xdr, 8);
3348 if (unlikely(!p))
3349 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003350 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003352 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003354 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003355 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003356out_overflow:
3357 print_overflow_msg(__func__, xdr);
3358 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359}
3360
3361static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3362{
Al Viro8687b632006-10-19 23:28:48 -07003363 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364
3365 *res = 0;
3366 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3367 return -EIO;
3368 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003369 p = xdr_inline_decode(xdr, 4);
3370 if (unlikely(!p))
3371 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003372 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3374 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003375 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003377out_overflow:
3378 print_overflow_msg(__func__, xdr);
3379 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380}
3381
3382static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3383{
Al Viro8687b632006-10-19 23:28:48 -07003384 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385
3386 *res = 0;
3387 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3388 return -EIO;
3389 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003390 p = xdr_inline_decode(xdr, 4);
3391 if (unlikely(!p))
3392 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003393 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3395 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003396 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003398out_overflow:
3399 print_overflow_msg(__func__, xdr);
3400 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401}
3402
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003403static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404{
Al Viro8687b632006-10-19 23:28:48 -07003405 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003406 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407
3408 fsid->major = 0;
3409 fsid->minor = 0;
3410 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3411 return -EIO;
3412 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003413 p = xdr_inline_decode(xdr, 16);
3414 if (unlikely(!p))
3415 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003416 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003417 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003419 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003421 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 (unsigned long long)fsid->major,
3423 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003424 return ret;
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
3430static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3431{
Al Viro8687b632006-10-19 23:28:48 -07003432 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433
3434 *res = 60;
3435 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3436 return -EIO;
3437 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003438 p = xdr_inline_decode(xdr, 4);
3439 if (unlikely(!p))
3440 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003441 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3443 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003444 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003446out_overflow:
3447 print_overflow_msg(__func__, xdr);
3448 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449}
3450
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003451static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003452{
3453 __be32 *p;
3454
3455 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3456 return -EIO;
3457 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3458 p = xdr_inline_decode(xdr, 4);
3459 if (unlikely(!p))
3460 goto out_overflow;
3461 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003462 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003463 }
3464 return 0;
3465out_overflow:
3466 print_overflow_msg(__func__, xdr);
3467 return -EIO;
3468}
3469
Kinglong Mee8c612822015-08-26 21:12:58 +08003470static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3471 uint32_t *bitmap, uint32_t *bitmask)
3472{
3473 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3474 int ret;
3475 ret = decode_attr_bitmap(xdr, bitmask);
3476 if (unlikely(ret < 0))
3477 return ret;
3478 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3479 } else
3480 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3481 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3482 bitmask[0], bitmask[1], bitmask[2]);
3483 return 0;
3484}
3485
Bryan Schumakerae42c702010-10-21 16:33:17 -04003486static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3487{
3488 __be32 *p;
3489 int len;
3490
Trond Myklebust7ad07352010-10-23 15:34:20 -04003491 if (fh != NULL)
3492 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003493
3494 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3495 return -EIO;
3496 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3497 p = xdr_inline_decode(xdr, 4);
3498 if (unlikely(!p))
3499 goto out_overflow;
3500 len = be32_to_cpup(p);
3501 if (len > NFS4_FHSIZE)
3502 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003503 p = xdr_inline_decode(xdr, len);
3504 if (unlikely(!p))
3505 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003506 if (fh != NULL) {
3507 memcpy(fh->data, p, len);
3508 fh->size = len;
3509 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003510 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3511 }
3512 return 0;
3513out_overflow:
3514 print_overflow_msg(__func__, xdr);
3515 return -EIO;
3516}
3517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3519{
Al Viro8687b632006-10-19 23:28:48 -07003520 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003522 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3524 return -EIO;
3525 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003526 p = xdr_inline_decode(xdr, 4);
3527 if (unlikely(!p))
3528 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003529 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3531 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003532 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003534out_overflow:
3535 print_overflow_msg(__func__, xdr);
3536 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537}
3538
3539static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3540{
Al Viro8687b632006-10-19 23:28:48 -07003541 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003542 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003543
3544 *fileid = 0;
3545 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3546 return -EIO;
3547 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003548 p = xdr_inline_decode(xdr, 8);
3549 if (unlikely(!p))
3550 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003551 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003553 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003555 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003556 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003557out_overflow:
3558 print_overflow_msg(__func__, xdr);
3559 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560}
3561
Manoj Naik99baf622006-06-09 09:34:24 -04003562static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3563{
Al Viro8687b632006-10-19 23:28:48 -07003564 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003565 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003566
3567 *fileid = 0;
3568 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3569 return -EIO;
3570 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003571 p = xdr_inline_decode(xdr, 8);
3572 if (unlikely(!p))
3573 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003574 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003575 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003576 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003577 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003578 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003579 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003580out_overflow:
3581 print_overflow_msg(__func__, xdr);
3582 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003583}
3584
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3586{
Al Viro8687b632006-10-19 23:28:48 -07003587 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 int status = 0;
3589
3590 *res = 0;
3591 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3592 return -EIO;
3593 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003594 p = xdr_inline_decode(xdr, 8);
3595 if (unlikely(!p))
3596 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003597 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3599 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003600 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003602out_overflow:
3603 print_overflow_msg(__func__, xdr);
3604 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605}
3606
3607static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3608{
Al Viro8687b632006-10-19 23:28:48 -07003609 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 int status = 0;
3611
3612 *res = 0;
3613 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3614 return -EIO;
3615 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003616 p = xdr_inline_decode(xdr, 8);
3617 if (unlikely(!p))
3618 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003619 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3621 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003622 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003624out_overflow:
3625 print_overflow_msg(__func__, xdr);
3626 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627}
3628
3629static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3630{
Al Viro8687b632006-10-19 23:28:48 -07003631 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 int status = 0;
3633
3634 *res = 0;
3635 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3636 return -EIO;
3637 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003638 p = xdr_inline_decode(xdr, 8);
3639 if (unlikely(!p))
3640 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003641 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003642 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3643 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003644 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003646out_overflow:
3647 print_overflow_msg(__func__, xdr);
3648 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649}
3650
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003651static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3652{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003653 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003654 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003655 int status = 0;
3656
Benny Halevyc0eae662009-08-14 17:20:14 +03003657 p = xdr_inline_decode(xdr, 4);
3658 if (unlikely(!p))
3659 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003660 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003661 if (n == 0)
3662 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003663 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003664 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3665 dprintk("cannot parse %d components in path\n", n);
3666 goto out_eio;
3667 }
3668 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003669 struct nfs4_string *component = &path->components[path->ncomponents];
3670 status = decode_opaque_inline(xdr, &component->len, &component->data);
3671 if (unlikely(status != 0))
3672 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003673 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003674 pr_cont("%s%.*s ",
3675 (path->ncomponents != n ? "/ " : ""),
3676 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003677 }
3678out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003679 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003680root_path:
3681/* a root pathname is sent as a zero component4 */
3682 path->ncomponents = 1;
3683 path->components[0].len=0;
3684 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003685 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003686 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003687out_eio:
3688 dprintk(" status %d", status);
3689 status = -EIO;
3690 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003691out_overflow:
3692 print_overflow_msg(__func__, xdr);
3693 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003694}
3695
3696static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003697{
3698 int n;
Al Viro8687b632006-10-19 23:28:48 -07003699 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003700 int status = -EIO;
3701
3702 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3703 goto out;
3704 status = 0;
3705 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3706 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003707 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003708 status = -EIO;
3709 /* Ignore borken servers that return unrequested attrs */
3710 if (unlikely(res == NULL))
3711 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003712 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003713 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003714 if (unlikely(status != 0))
3715 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003716 p = xdr_inline_decode(xdr, 4);
3717 if (unlikely(!p))
3718 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003719 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003720 if (n <= 0)
3721 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003722 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003723 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003724 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003725
Trond Myklebust809b4262013-03-27 11:54:45 -04003726 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3727 break;
3728 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003729 p = xdr_inline_decode(xdr, 4);
3730 if (unlikely(!p))
3731 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003732 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003733
Chuck Lever02a29762012-03-01 17:00:31 -05003734 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003735 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3736 struct nfs4_string *server;
3737
3738 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003739 unsigned int i;
3740 dprintk("%s: using first %u of %u servers "
3741 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003742 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003743 NFS4_FS_LOCATION_MAXSERVERS,
3744 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003745 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003746 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003747 char *data;
3748 status = decode_opaque_inline(xdr, &len, &data);
3749 if (unlikely(status != 0))
3750 goto out_eio;
3751 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003752 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003753 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003754 server = &loc->servers[loc->nservers];
3755 status = decode_opaque_inline(xdr, &server->len, &server->data);
3756 if (unlikely(status != 0))
3757 goto out_eio;
3758 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003759 }
3760 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003761 if (unlikely(status != 0))
3762 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003763 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003764 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003765 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003766out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003767 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003768 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003769out_overflow:
3770 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003771out_eio:
3772 status = -EIO;
3773 goto out;
3774}
3775
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3777{
Al Viro8687b632006-10-19 23:28:48 -07003778 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 int status = 0;
3780
3781 *res = 0;
3782 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3783 return -EIO;
3784 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003785 p = xdr_inline_decode(xdr, 8);
3786 if (unlikely(!p))
3787 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003788 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3790 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003791 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003793out_overflow:
3794 print_overflow_msg(__func__, xdr);
3795 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796}
3797
3798static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3799{
Al Viro8687b632006-10-19 23:28:48 -07003800 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 int status = 0;
3802
3803 *maxlink = 1;
3804 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3805 return -EIO;
3806 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003807 p = xdr_inline_decode(xdr, 4);
3808 if (unlikely(!p))
3809 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003810 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3812 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003813 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003815out_overflow:
3816 print_overflow_msg(__func__, xdr);
3817 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818}
3819
3820static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3821{
Al Viro8687b632006-10-19 23:28:48 -07003822 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 int status = 0;
3824
3825 *maxname = 1024;
3826 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3827 return -EIO;
3828 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003829 p = xdr_inline_decode(xdr, 4);
3830 if (unlikely(!p))
3831 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003832 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3834 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003835 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003837out_overflow:
3838 print_overflow_msg(__func__, xdr);
3839 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840}
3841
3842static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3843{
Al Viro8687b632006-10-19 23:28:48 -07003844 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 int status = 0;
3846
3847 *res = 1024;
3848 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3849 return -EIO;
3850 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3851 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003852 p = xdr_inline_decode(xdr, 8);
3853 if (unlikely(!p))
3854 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003855 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856 if (maxread > 0x7FFFFFFF)
3857 maxread = 0x7FFFFFFF;
3858 *res = (uint32_t)maxread;
3859 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3860 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003861 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003863out_overflow:
3864 print_overflow_msg(__func__, xdr);
3865 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866}
3867
3868static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3869{
Al Viro8687b632006-10-19 23:28:48 -07003870 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 int status = 0;
3872
3873 *res = 1024;
3874 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3875 return -EIO;
3876 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3877 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003878 p = xdr_inline_decode(xdr, 8);
3879 if (unlikely(!p))
3880 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003881 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882 if (maxwrite > 0x7FFFFFFF)
3883 maxwrite = 0x7FFFFFFF;
3884 *res = (uint32_t)maxwrite;
3885 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3886 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003887 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003889out_overflow:
3890 print_overflow_msg(__func__, xdr);
3891 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892}
3893
Trond Myklebustbca79472009-03-11 14:10:26 -04003894static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895{
Trond Myklebustbca79472009-03-11 14:10:26 -04003896 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003897 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003898 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899
3900 *mode = 0;
3901 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3902 return -EIO;
3903 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003904 p = xdr_inline_decode(xdr, 4);
3905 if (unlikely(!p))
3906 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003907 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003908 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003910 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003912 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003913 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003914out_overflow:
3915 print_overflow_msg(__func__, xdr);
3916 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003917}
3918
3919static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3920{
Al Viro8687b632006-10-19 23:28:48 -07003921 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003922 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923
3924 *nlink = 1;
3925 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3926 return -EIO;
3927 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003928 p = xdr_inline_decode(xdr, 4);
3929 if (unlikely(!p))
3930 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003931 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003932 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003933 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003935 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003936 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003937out_overflow:
3938 print_overflow_msg(__func__, xdr);
3939 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940}
3941
Trond Myklebust686a8162017-02-19 16:08:32 -05003942static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3943 struct nfs4_string *name, gfp_t gfp_flags)
3944{
3945 ssize_t ret;
3946
3947 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3948 XDR_MAX_NETOBJ, gfp_flags);
3949 name->len = 0;
3950 if (ret > 0)
3951 name->len = ret;
3952 return ret;
3953}
3954
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003955static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003956 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003957 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958{
Trond Myklebust686a8162017-02-19 16:08:32 -05003959 ssize_t len;
3960 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003961
Eric W. Biedermane5782072013-02-01 14:22:02 -08003962 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3964 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003965 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3966 return 0;
3967 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3968
3969 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003970 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003971 if (len <= 0)
3972 goto out;
3973 dprintk("%s: name=%s\n", __func__, owner_name->data);
3974 return NFS_ATTR_FATTR_OWNER_NAME;
3975 } else {
3976 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3977 XDR_MAX_NETOBJ);
3978 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3979 goto out;
3980 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3981 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003983out:
3984 if (len != -EBADMSG)
3985 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003986 print_overflow_msg(__func__, xdr);
3987 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988}
3989
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003990static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003991 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003992 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993{
Trond Myklebust686a8162017-02-19 16:08:32 -05003994 ssize_t len;
3995 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996
Eric W. Biedermane5782072013-02-01 14:22:02 -08003997 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3999 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05004000 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
4001 return 0;
4002 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
4003
4004 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04004005 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05004006 if (len <= 0)
4007 goto out;
4008 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08004009 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05004010 } else {
4011 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4012 XDR_MAX_NETOBJ);
4013 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4014 goto out;
4015 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4016 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 }
Trond Myklebust686a8162017-02-19 16:08:32 -05004018out:
4019 if (len != -EBADMSG)
4020 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004021 print_overflow_msg(__func__, xdr);
4022 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004023}
4024
4025static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
4026{
Al Viro8687b632006-10-19 23:28:48 -07004027 uint32_t major = 0, minor = 0;
4028 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004029 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030
4031 *rdev = MKDEV(0,0);
4032 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
4033 return -EIO;
4034 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
4035 dev_t tmp;
4036
Benny Halevyc0eae662009-08-14 17:20:14 +03004037 p = xdr_inline_decode(xdr, 8);
4038 if (unlikely(!p))
4039 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004040 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004041 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 tmp = MKDEV(major, minor);
4043 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
4044 *rdev = tmp;
4045 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04004046 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004048 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04004049 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004050out_overflow:
4051 print_overflow_msg(__func__, xdr);
4052 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053}
4054
4055static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4056{
Al Viro8687b632006-10-19 23:28:48 -07004057 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 int status = 0;
4059
4060 *res = 0;
4061 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4062 return -EIO;
4063 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004064 p = xdr_inline_decode(xdr, 8);
4065 if (unlikely(!p))
4066 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004067 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4069 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004070 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004072out_overflow:
4073 print_overflow_msg(__func__, xdr);
4074 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075}
4076
4077static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4078{
Al Viro8687b632006-10-19 23:28:48 -07004079 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 int status = 0;
4081
4082 *res = 0;
4083 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4084 return -EIO;
4085 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004086 p = xdr_inline_decode(xdr, 8);
4087 if (unlikely(!p))
4088 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004089 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4091 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004092 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004094out_overflow:
4095 print_overflow_msg(__func__, xdr);
4096 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097}
4098
4099static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4100{
Al Viro8687b632006-10-19 23:28:48 -07004101 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 int status = 0;
4103
4104 *res = 0;
4105 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4106 return -EIO;
4107 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004108 p = xdr_inline_decode(xdr, 8);
4109 if (unlikely(!p))
4110 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004111 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4113 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004114 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004116out_overflow:
4117 print_overflow_msg(__func__, xdr);
4118 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119}
4120
4121static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4122{
Al Viro8687b632006-10-19 23:28:48 -07004123 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004124 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125
4126 *used = 0;
4127 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4128 return -EIO;
4129 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004130 p = xdr_inline_decode(xdr, 8);
4131 if (unlikely(!p))
4132 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004133 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004135 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004137 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004139 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004140out_overflow:
4141 print_overflow_msg(__func__, xdr);
4142 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143}
4144
4145static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4146{
Al Viro8687b632006-10-19 23:28:48 -07004147 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 uint64_t sec;
4149 uint32_t nsec;
4150
Benny Halevyc0eae662009-08-14 17:20:14 +03004151 p = xdr_inline_decode(xdr, 12);
4152 if (unlikely(!p))
4153 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004154 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004155 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 time->tv_sec = (time_t)sec;
4157 time->tv_nsec = (long)nsec;
4158 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004159out_overflow:
4160 print_overflow_msg(__func__, xdr);
4161 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162}
4163
4164static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4165{
4166 int status = 0;
4167
4168 time->tv_sec = 0;
4169 time->tv_nsec = 0;
4170 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4171 return -EIO;
4172 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4173 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004174 if (status == 0)
4175 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4177 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004178 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 return status;
4180}
4181
4182static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4183{
4184 int status = 0;
4185
4186 time->tv_sec = 0;
4187 time->tv_nsec = 0;
4188 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4189 return -EIO;
4190 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4191 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004192 if (status == 0)
4193 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4195 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004196 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 return status;
4198}
4199
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004200static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4201 struct timespec *time)
4202{
4203 int status = 0;
4204
4205 time->tv_sec = 0;
4206 time->tv_nsec = 0;
4207 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4208 return -EIO;
4209 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4210 status = decode_attr_time(xdr, time);
4211 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4212 }
4213 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4214 (long)time->tv_nsec);
4215 return status;
4216}
4217
David Quigleyaa9c2662013-05-22 12:50:44 -04004218static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4219 struct nfs4_label *label)
4220{
4221 uint32_t pi = 0;
4222 uint32_t lfs = 0;
4223 __u32 len;
4224 __be32 *p;
4225 int status = 0;
4226
4227 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4228 return -EIO;
4229 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4230 p = xdr_inline_decode(xdr, 4);
4231 if (unlikely(!p))
4232 goto out_overflow;
4233 lfs = be32_to_cpup(p++);
4234 p = xdr_inline_decode(xdr, 4);
4235 if (unlikely(!p))
4236 goto out_overflow;
4237 pi = be32_to_cpup(p++);
4238 p = xdr_inline_decode(xdr, 4);
4239 if (unlikely(!p))
4240 goto out_overflow;
4241 len = be32_to_cpup(p++);
4242 p = xdr_inline_decode(xdr, len);
4243 if (unlikely(!p))
4244 goto out_overflow;
4245 if (len < NFS4_MAXLABELLEN) {
4246 if (label) {
4247 memcpy(label->label, p, len);
4248 label->len = len;
4249 label->pi = pi;
4250 label->lfs = lfs;
4251 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4252 }
4253 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4254 } else
4255 printk(KERN_WARNING "%s: label too long (%u)!\n",
4256 __func__, len);
4257 }
4258 if (label && label->label)
4259 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4260 (char *)label->label, label->len, label->pi, label->lfs);
4261 return status;
4262
4263out_overflow:
4264 print_overflow_msg(__func__, xdr);
4265 return -EIO;
4266}
4267
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4269{
4270 int status = 0;
4271
4272 time->tv_sec = 0;
4273 time->tv_nsec = 0;
4274 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4275 return -EIO;
4276 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4277 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004278 if (status == 0)
4279 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4281 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004282 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 return status;
4284}
4285
Trond Myklebust256e48b2012-06-21 11:18:13 -04004286static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287{
4288 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004289 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004290
4291 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004292 dprintk("%s: server returned incorrect attribute length: "
4293 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004294 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 attrwords << 2,
4296 (attrwords < nwords) ? '<' : '>',
4297 nwords << 2);
4298 return -EIO;
4299 }
4300 return 0;
4301}
4302
4303static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4304{
Al Viro8687b632006-10-19 23:28:48 -07004305 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004306
Benny Halevyc0eae662009-08-14 17:20:14 +03004307 p = xdr_inline_decode(xdr, 20);
4308 if (unlikely(!p))
4309 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004310 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004311 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004312 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004313 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004314out_overflow:
4315 print_overflow_msg(__func__, xdr);
4316 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317}
4318
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004319static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320{
Al Viro8687b632006-10-19 23:28:48 -07004321 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 uint32_t supp, acc;
4323 int status;
4324
4325 status = decode_op_hdr(xdr, OP_ACCESS);
4326 if (status)
4327 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004328 p = xdr_inline_decode(xdr, 8);
4329 if (unlikely(!p))
4330 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004331 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004332 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004333 *supported = supp;
4334 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004336out_overflow:
4337 print_overflow_msg(__func__, xdr);
4338 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339}
4340
Benny Halevy07d30432009-08-14 17:19:52 +03004341static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004343 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4344 if (unlikely(ret < 0)) {
4345 print_overflow_msg(__func__, xdr);
4346 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004347 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004348 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004349}
4350
4351static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4352{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004353 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354}
4355
Trond Myklebust93b717f2016-05-16 17:42:43 -04004356static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4357{
4358 stateid->type = NFS4_OPEN_STATEID_TYPE;
4359 return decode_stateid(xdr, stateid);
4360}
4361
4362static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4363{
4364 stateid->type = NFS4_LOCK_STATEID_TYPE;
4365 return decode_stateid(xdr, stateid);
4366}
4367
4368static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4369{
4370 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4371 return decode_stateid(xdr, stateid);
4372}
4373
Trond Myklebustfcd88432017-11-07 12:39:44 -05004374static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4375{
4376 nfs4_stateid dummy;
4377
4378 nfs4_stateid_copy(stateid, &invalid_stateid);
4379 return decode_stateid(xdr, &dummy);
4380}
4381
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4383{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384 int status;
4385
4386 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004387 if (status != -EIO)
4388 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004389 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004390 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004391 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392}
4393
Benny Halevydb942bb2009-08-14 17:19:56 +03004394static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4395{
Chuck Levercd937102012-03-02 17:14:31 -05004396 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397}
4398
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004399static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4400{
4401 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4402}
4403
Fred Isaman0b7c0152012-04-20 14:47:39 -04004404static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406 int status;
4407
4408 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004409 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004410 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004411 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412}
4413
4414static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4415{
Al Viro8687b632006-10-19 23:28:48 -07004416 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417 uint32_t bmlen;
4418 int status;
4419
4420 status = decode_op_hdr(xdr, OP_CREATE);
4421 if (status)
4422 return status;
4423 if ((status = decode_change_info(xdr, cinfo)))
4424 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004425 p = xdr_inline_decode(xdr, 4);
4426 if (unlikely(!p))
4427 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004428 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004429 p = xdr_inline_decode(xdr, bmlen << 2);
4430 if (likely(p))
4431 return 0;
4432out_overflow:
4433 print_overflow_msg(__func__, xdr);
4434 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004435}
4436
4437static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4438{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004439 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004440 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 int status;
4442
4443 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4444 goto xdr_error;
4445 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4446 goto xdr_error;
4447 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4448 goto xdr_error;
4449 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4450 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004451 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4452 &res->fh_expire_type)) != 0)
4453 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004454 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4455 goto xdr_error;
4456 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4457 goto xdr_error;
4458 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4459 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004460 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4461 res->exclcreat_bitmask)) != 0)
4462 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 status = verify_attr_len(xdr, savep, attrlen);
4464xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004465 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004466 return status;
4467}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004468
Linus Torvalds1da177e2005-04-16 15:20:36 -07004469static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4470{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004471 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004472 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004473 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004474
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4476 goto xdr_error;
4477 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4478 goto xdr_error;
4479 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4480 goto xdr_error;
4481
4482 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4483 goto xdr_error;
4484 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4485 goto xdr_error;
4486 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4487 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004488
4489 status = -EIO;
4490 if (unlikely(bitmap[0]))
4491 goto xdr_error;
4492
Linus Torvalds1da177e2005-04-16 15:20:36 -07004493 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4494 goto xdr_error;
4495 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4496 goto xdr_error;
4497 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4498 goto xdr_error;
4499
4500 status = verify_attr_len(xdr, savep, attrlen);
4501xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004502 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004503 return status;
4504}
4505
4506static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4507{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004508 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004509 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004510 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004511
Linus Torvalds1da177e2005-04-16 15:20:36 -07004512 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4513 goto xdr_error;
4514 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4515 goto xdr_error;
4516 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4517 goto xdr_error;
4518
4519 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4520 goto xdr_error;
4521 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4522 goto xdr_error;
4523
4524 status = verify_attr_len(xdr, savep, attrlen);
4525xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004526 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004527 return status;
4528}
4529
Andy Adamson88034c32012-05-23 05:02:34 -04004530static int decode_threshold_hint(struct xdr_stream *xdr,
4531 uint32_t *bitmap,
4532 uint64_t *res,
4533 uint32_t hint_bit)
4534{
4535 __be32 *p;
4536
4537 *res = 0;
4538 if (likely(bitmap[0] & hint_bit)) {
4539 p = xdr_inline_decode(xdr, 8);
4540 if (unlikely(!p))
4541 goto out_overflow;
4542 xdr_decode_hyper(p, res);
4543 }
4544 return 0;
4545out_overflow:
4546 print_overflow_msg(__func__, xdr);
4547 return -EIO;
4548}
4549
4550static int decode_first_threshold_item4(struct xdr_stream *xdr,
4551 struct nfs4_threshold *res)
4552{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004553 __be32 *p;
4554 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004555 uint32_t bitmap[3] = {0,}, attrlen;
4556 int status;
4557
4558 /* layout type */
4559 p = xdr_inline_decode(xdr, 4);
4560 if (unlikely(!p)) {
4561 print_overflow_msg(__func__, xdr);
4562 return -EIO;
4563 }
4564 res->l_type = be32_to_cpup(p);
4565
4566 /* thi_hintset bitmap */
4567 status = decode_attr_bitmap(xdr, bitmap);
4568 if (status < 0)
4569 goto xdr_error;
4570
4571 /* thi_hintlist length */
4572 status = decode_attr_length(xdr, &attrlen, &savep);
4573 if (status < 0)
4574 goto xdr_error;
4575 /* thi_hintlist */
4576 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4577 if (status < 0)
4578 goto xdr_error;
4579 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4580 if (status < 0)
4581 goto xdr_error;
4582 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4583 THRESHOLD_RD_IO);
4584 if (status < 0)
4585 goto xdr_error;
4586 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4587 THRESHOLD_WR_IO);
4588 if (status < 0)
4589 goto xdr_error;
4590
4591 status = verify_attr_len(xdr, savep, attrlen);
4592 res->bm = bitmap[0];
4593
4594 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4595 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4596 res->wr_io_sz);
4597xdr_error:
4598 dprintk("%s ret=%d!\n", __func__, status);
4599 return status;
4600}
4601
4602/*
4603 * Thresholds on pNFS direct I/O vrs MDS I/O
4604 */
4605static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4606 uint32_t *bitmap,
4607 struct nfs4_threshold *res)
4608{
4609 __be32 *p;
4610 int status = 0;
4611 uint32_t num;
4612
4613 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4614 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004615 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004616 /* Did the server return an unrequested attribute? */
4617 if (unlikely(res == NULL))
4618 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004619 p = xdr_inline_decode(xdr, 4);
4620 if (unlikely(!p))
4621 goto out_overflow;
4622 num = be32_to_cpup(p);
4623 if (num == 0)
4624 return 0;
4625 if (num > 1)
4626 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4627 "drivers per filesystem not supported\n",
4628 __func__);
4629
4630 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004631 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004632 }
4633 return status;
4634out_overflow:
4635 print_overflow_msg(__func__, xdr);
4636 return -EIO;
4637}
4638
Bryan Schumakerae42c702010-10-21 16:33:17 -04004639static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4640 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004641 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004642 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004643{
Trond Myklebustbca79472009-03-11 14:10:26 -04004644 int status;
4645 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004646 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004647 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004648
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004649 status = decode_attr_type(xdr, bitmap, &type);
4650 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004651 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004652 fattr->mode = 0;
4653 if (status != 0) {
4654 fattr->mode |= nfs_type2fmt[type];
4655 fattr->valid |= status;
4656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004658 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4659 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004661 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004662
4663 status = decode_attr_size(xdr, bitmap, &fattr->size);
4664 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004666 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004667
4668 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4669 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004670 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004671 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004672
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004673 err = 0;
4674 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004675 if (status < 0)
4676 goto xdr_error;
4677
4678 status = decode_attr_filehandle(xdr, bitmap, fh);
4679 if (status < 0)
4680 goto xdr_error;
4681
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004682 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4683 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004684 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004685 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004686
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004687 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004688 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004689 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004690 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004691
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004692 status = -EIO;
4693 if (unlikely(bitmap[0]))
4694 goto xdr_error;
4695
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004696 status = decode_attr_mode(xdr, bitmap, &fmode);
4697 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004699 if (status != 0) {
4700 fattr->mode |= fmode;
4701 fattr->valid |= status;
4702 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004703
4704 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4705 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004706 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004707 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004708
Trond Myklebust6926afd2012-01-07 13:22:46 -05004709 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004710 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004712 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004713
Trond Myklebust6926afd2012-01-07 13:22:46 -05004714 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004715 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004716 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004717 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004718
4719 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4720 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004721 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004722 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004723
4724 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4725 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004727 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004728
4729 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4730 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004732 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004733
4734 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4735 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004737 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004738
4739 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4740 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004741 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004742 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004743
Trond Myklebust28331a42011-04-27 13:47:52 -04004744 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004745 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004746 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004747 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004748
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004749 status = -EIO;
4750 if (unlikely(bitmap[1]))
4751 goto xdr_error;
4752
Andy Adamson88034c32012-05-23 05:02:34 -04004753 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4754 if (status < 0)
4755 goto xdr_error;
4756
David Quigleyaa9c2662013-05-22 12:50:44 -04004757 if (label) {
4758 status = decode_attr_security_label(xdr, bitmap, label);
4759 if (status < 0)
4760 goto xdr_error;
4761 fattr->valid |= status;
4762 }
4763
Bryan Schumakerae42c702010-10-21 16:33:17 -04004764xdr_error:
4765 dprintk("%s: xdr returned %d\n", __func__, -status);
4766 return status;
4767}
4768
4769static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004770 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004771 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004772{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004773 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004774 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004775 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004776 int status;
4777
4778 status = decode_op_hdr(xdr, OP_GETATTR);
4779 if (status < 0)
4780 goto xdr_error;
4781
4782 status = decode_attr_bitmap(xdr, bitmap);
4783 if (status < 0)
4784 goto xdr_error;
4785
4786 status = decode_attr_length(xdr, &attrlen, &savep);
4787 if (status < 0)
4788 goto xdr_error;
4789
David Quigleyaa9c2662013-05-22 12:50:44 -04004790 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4791 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004792 if (status < 0)
4793 goto xdr_error;
4794
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004795 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004796xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004797 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004798 return status;
4799}
4800
David Quigleyaa9c2662013-05-22 12:50:44 -04004801static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4802 struct nfs4_label *label, const struct nfs_server *server)
4803{
4804 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4805}
4806
Bryan Schumakerae42c702010-10-21 16:33:17 -04004807static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004808 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004809{
David Quigleyaa9c2662013-05-22 12:50:44 -04004810 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004811}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812
Andy Adamson504913f2010-10-20 00:17:57 -04004813/*
Jeff Layton3132e492016-08-10 15:58:24 -04004814 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004815 */
Jeff Layton3132e492016-08-10 15:58:24 -04004816static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004817 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004818{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004819 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004820 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004821
4822 p = xdr_inline_decode(xdr, 4);
4823 if (unlikely(!p))
4824 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004825 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004826
4827 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004828 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004829 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004830
4831 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004832 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004833 if (unlikely(!p))
4834 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004835
4836 /* If we get too many, then just cap it at the max */
4837 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4838 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4839 __func__, fsinfo->nlayouttypes);
4840 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4841 }
4842
4843 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4844 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004845 return 0;
4846out_overflow:
4847 print_overflow_msg(__func__, xdr);
4848 return -EIO;
4849}
4850
4851/*
4852 * The type of file system exported.
4853 * Note we must ensure that layouttype is set in any non-error case.
4854 */
4855static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004856 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004857{
4858 int status = 0;
4859
4860 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4861 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4862 return -EIO;
4863 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004864 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004865 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004866 }
Andy Adamson504913f2010-10-20 00:17:57 -04004867 return status;
4868}
4869
Fred Isamandae100c2011-07-30 20:52:37 -04004870/*
4871 * The prefered block size for layout directed io
4872 */
4873static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4874 uint32_t *res)
4875{
4876 __be32 *p;
4877
4878 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4879 *res = 0;
4880 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4881 p = xdr_inline_decode(xdr, 4);
4882 if (unlikely(!p)) {
4883 print_overflow_msg(__func__, xdr);
4884 return -EIO;
4885 }
4886 *res = be32_to_cpup(p);
4887 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4888 }
4889 return 0;
4890}
4891
Peng Tao2a92ee92015-09-26 02:24:37 +08004892/*
4893 * The granularity of a CLONE operation.
4894 */
4895static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4896 uint32_t *res)
4897{
4898 __be32 *p;
4899
4900 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4901 *res = 0;
4902 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4903 p = xdr_inline_decode(xdr, 4);
4904 if (unlikely(!p)) {
4905 print_overflow_msg(__func__, xdr);
4906 return -EIO;
4907 }
4908 *res = be32_to_cpup(p);
4909 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4910 }
4911 return 0;
4912}
4913
Linus Torvalds1da177e2005-04-16 15:20:36 -07004914static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4915{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004916 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004917 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 int status;
4919
4920 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4921 goto xdr_error;
4922 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4923 goto xdr_error;
4924 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4925 goto xdr_error;
4926
4927 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4928
4929 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4930 goto xdr_error;
4931 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4932 goto xdr_error;
4933 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4934 goto xdr_error;
4935 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4936 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4937 goto xdr_error;
4938 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004939
4940 status = -EIO;
4941 if (unlikely(bitmap[0]))
4942 goto xdr_error;
4943
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004944 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4945 if (status != 0)
4946 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004947 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004948 if (status != 0)
4949 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004950
4951 status = -EIO;
4952 if (unlikely(bitmap[1]))
4953 goto xdr_error;
4954
Fred Isamandae100c2011-07-30 20:52:37 -04004955 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4956 if (status)
4957 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004958 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4959 if (status)
4960 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961
4962 status = verify_attr_len(xdr, savep, attrlen);
4963xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004964 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 return status;
4966}
4967
4968static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4969{
Al Viro8687b632006-10-19 23:28:48 -07004970 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 uint32_t len;
4972 int status;
4973
Trond Myklebust99367812007-07-17 21:52:41 -04004974 /* Zero handle first to allow comparisons */
4975 memset(fh, 0, sizeof(*fh));
4976
Linus Torvalds1da177e2005-04-16 15:20:36 -07004977 status = decode_op_hdr(xdr, OP_GETFH);
4978 if (status)
4979 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004980
Benny Halevyc0eae662009-08-14 17:20:14 +03004981 p = xdr_inline_decode(xdr, 4);
4982 if (unlikely(!p))
4983 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004984 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 if (len > NFS4_FHSIZE)
4986 return -EIO;
4987 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004988 p = xdr_inline_decode(xdr, len);
4989 if (unlikely(!p))
4990 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004991 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004993out_overflow:
4994 print_overflow_msg(__func__, xdr);
4995 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004996}
4997
4998static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4999{
5000 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005001
Linus Torvalds1da177e2005-04-16 15:20:36 -07005002 status = decode_op_hdr(xdr, OP_LINK);
5003 if (status)
5004 return status;
5005 return decode_change_info(xdr, cinfo);
5006}
5007
5008/*
5009 * We create the owner, so we know a proper owner.id length is 4.
5010 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005011static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005012{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005013 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07005014 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005015 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005017 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03005018 if (unlikely(!p))
5019 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005020 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03005021 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005022 type = be32_to_cpup(p++); /* 4 byte read */
5023 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005024 fl->fl_start = (loff_t)offset;
5025 fl->fl_end = fl->fl_start + (loff_t)length - 1;
5026 if (length == ~(uint64_t)0)
5027 fl->fl_end = OFFSET_MAX;
5028 fl->fl_type = F_WRLCK;
5029 if (type & 1)
5030 fl->fl_type = F_RDLCK;
5031 fl->fl_pid = 0;
5032 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005033 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5034 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5035 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03005036 if (likely(p))
5037 return -NFS4ERR_DENIED;
5038out_overflow:
5039 print_overflow_msg(__func__, xdr);
5040 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041}
5042
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005043static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005044{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045 int status;
5046
5047 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005048 if (status == -EIO)
5049 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04005051 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005052 if (unlikely(status))
5053 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005054 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04005055 status = decode_lock_denied(xdr, NULL);
5056 if (res->open_seqid != NULL)
5057 nfs_increment_open_seqid(status, res->open_seqid);
5058 nfs_increment_lock_seqid(status, res->lock_seqid);
5059out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060 return status;
5061}
5062
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005063static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064{
5065 int status;
5066 status = decode_op_hdr(xdr, OP_LOCKT);
5067 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005068 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 return status;
5070}
5071
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005072static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005073{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 int status;
5075
5076 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005077 if (status != -EIO)
5078 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005079 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005080 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005081 return status;
5082}
5083
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005084static int decode_release_lockowner(struct xdr_stream *xdr)
5085{
5086 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5087}
5088
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089static int decode_lookup(struct xdr_stream *xdr)
5090{
5091 return decode_op_hdr(xdr, OP_LOOKUP);
5092}
5093
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005094static int decode_lookupp(struct xdr_stream *xdr)
5095{
5096 return decode_op_hdr(xdr, OP_LOOKUPP);
5097}
5098
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005100static int decode_space_limit(struct xdr_stream *xdr,
5101 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102{
Andy Adamson05d564f2008-12-23 16:06:15 -05005103 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005105 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106
Benny Halevyc0eae662009-08-14 17:20:14 +03005107 p = xdr_inline_decode(xdr, 12);
5108 if (unlikely(!p))
5109 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005110 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005111 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005112 case NFS4_LIMIT_SIZE:
5113 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005114 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005115 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005116 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005117 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005118 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005119 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005120 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005121 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005123out_overflow:
5124 print_overflow_msg(__func__, xdr);
5125 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005126}
5127
Trond Myklebust6ae37332015-01-30 14:21:14 -05005128static int decode_rw_delegation(struct xdr_stream *xdr,
5129 uint32_t delegation_type,
5130 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131{
Andy Adamson05d564f2008-12-23 16:06:15 -05005132 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005133 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134
Trond Myklebust93b717f2016-05-16 17:42:43 -04005135 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005136 if (unlikely(status))
5137 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005138 p = xdr_inline_decode(xdr, 4);
5139 if (unlikely(!p))
5140 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005141 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005142
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005144 case NFS4_OPEN_DELEGATE_READ:
5145 res->delegation_type = FMODE_READ;
5146 break;
5147 case NFS4_OPEN_DELEGATE_WRITE:
5148 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005149 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150 return -EIO;
5151 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005152 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005153out_overflow:
5154 print_overflow_msg(__func__, xdr);
5155 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005156}
5157
Trond Myklebust6ae37332015-01-30 14:21:14 -05005158static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5159{
5160 __be32 *p;
5161 uint32_t why_no_delegation;
5162
5163 p = xdr_inline_decode(xdr, 4);
5164 if (unlikely(!p))
5165 goto out_overflow;
5166 why_no_delegation = be32_to_cpup(p);
5167 switch (why_no_delegation) {
5168 case WND4_CONTENTION:
5169 case WND4_RESOURCE:
5170 xdr_inline_decode(xdr, 4);
5171 /* Ignore for now */
5172 }
5173 return 0;
5174out_overflow:
5175 print_overflow_msg(__func__, xdr);
5176 return -EIO;
5177}
5178
5179static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5180{
5181 __be32 *p;
5182 uint32_t delegation_type;
5183
5184 p = xdr_inline_decode(xdr, 4);
5185 if (unlikely(!p))
5186 goto out_overflow;
5187 delegation_type = be32_to_cpup(p);
5188 res->delegation_type = 0;
5189 switch (delegation_type) {
5190 case NFS4_OPEN_DELEGATE_NONE:
5191 return 0;
5192 case NFS4_OPEN_DELEGATE_READ:
5193 case NFS4_OPEN_DELEGATE_WRITE:
5194 return decode_rw_delegation(xdr, delegation_type, res);
5195 case NFS4_OPEN_DELEGATE_NONE_EXT:
5196 return decode_no_delegation(xdr, res);
5197 }
5198 return -EIO;
5199out_overflow:
5200 print_overflow_msg(__func__, xdr);
5201 return -EIO;
5202}
5203
Linus Torvalds1da177e2005-04-16 15:20:36 -07005204static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5205{
Andy Adamson05d564f2008-12-23 16:06:15 -05005206 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005207 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005208 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005209
Trond Myklebustc7848f62013-12-04 17:39:23 -05005210 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5211 return status;
5212 nfs_increment_open_seqid(status, res->seqid);
5213 if (status)
5214 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005215 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005216 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005217 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218
Andy Adamson05d564f2008-12-23 16:06:15 -05005219 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005220
Benny Halevyc0eae662009-08-14 17:20:14 +03005221 p = xdr_inline_decode(xdr, 8);
5222 if (unlikely(!p))
5223 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005224 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005225 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005226 if (bmlen > 10)
5227 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228
Benny Halevyc0eae662009-08-14 17:20:14 +03005229 p = xdr_inline_decode(xdr, bmlen << 2);
5230 if (unlikely(!p))
5231 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005232 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5233 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005234 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005235 for (; i < NFS4_BITMAP_SIZE; i++)
5236 res->attrset[i] = 0;
5237
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 return decode_delegation(xdr, res);
5239xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005240 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005242out_overflow:
5243 print_overflow_msg(__func__, xdr);
5244 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245}
5246
5247static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5248{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005249 int status;
5250
Andy Adamson05d564f2008-12-23 16:06:15 -05005251 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005252 if (status != -EIO)
5253 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005254 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005255 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005256 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257}
5258
5259static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5260{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261 int status;
5262
5263 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005264 if (status != -EIO)
5265 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005266 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005267 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005268 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269}
5270
5271static int decode_putfh(struct xdr_stream *xdr)
5272{
5273 return decode_op_hdr(xdr, OP_PUTFH);
5274}
5275
5276static int decode_putrootfh(struct xdr_stream *xdr)
5277{
5278 return decode_op_hdr(xdr, OP_PUTROOTFH);
5279}
5280
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005281static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5282 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283{
Al Viro8687b632006-10-19 23:28:48 -07005284 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005285 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 int status;
5287
5288 status = decode_op_hdr(xdr, OP_READ);
5289 if (status)
5290 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005291 p = xdr_inline_decode(xdr, 8);
5292 if (unlikely(!p))
5293 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005294 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005295 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005296 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005298 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005299 "count %u > recvd %u\n", count, recvd);
5300 count = recvd;
5301 eof = 0;
5302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 res->eof = eof;
5304 res->count = count;
5305 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005306out_overflow:
5307 print_overflow_msg(__func__, xdr);
5308 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309}
5310
5311static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5312{
Chuck Leverbcecff72007-10-26 13:32:03 -04005313 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005314 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315
5316 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005317 if (!status)
5318 status = decode_verifier(xdr, readdir->verifier.data);
5319 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005320 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005321 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005322 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005323 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005324 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325}
5326
5327static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5328{
5329 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005330 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005331 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 int status;
5333
5334 status = decode_op_hdr(xdr, OP_READLINK);
5335 if (status)
5336 return status;
5337
5338 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005339 p = xdr_inline_decode(xdr, 4);
5340 if (unlikely(!p))
5341 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005342 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005343 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005344 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005345 return -ENAMETOOLONG;
5346 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005347 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005349 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005350 "count %u > recvd %u\n", len, recvd);
5351 return -EIO;
5352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005353 /*
5354 * The XDR encode routine has set things up so that
5355 * the link text will be copied directly into the
5356 * buffer. We just have to do overflow-checking,
5357 * and and null-terminate the text (the VFS expects
5358 * null-termination).
5359 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005360 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005362out_overflow:
5363 print_overflow_msg(__func__, xdr);
5364 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365}
5366
5367static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5368{
5369 int status;
5370
5371 status = decode_op_hdr(xdr, OP_REMOVE);
5372 if (status)
5373 goto out;
5374 status = decode_change_info(xdr, cinfo);
5375out:
5376 return status;
5377}
5378
5379static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5380 struct nfs4_change_info *new_cinfo)
5381{
5382 int status;
5383
5384 status = decode_op_hdr(xdr, OP_RENAME);
5385 if (status)
5386 goto out;
5387 if ((status = decode_change_info(xdr, old_cinfo)))
5388 goto out;
5389 status = decode_change_info(xdr, new_cinfo);
5390out:
5391 return status;
5392}
5393
5394static int decode_renew(struct xdr_stream *xdr)
5395{
5396 return decode_op_hdr(xdr, OP_RENEW);
5397}
5398
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005399static int
5400decode_restorefh(struct xdr_stream *xdr)
5401{
5402 return decode_op_hdr(xdr, OP_RESTOREFH);
5403}
5404
J. Bruce Fields029d1052005-06-22 17:16:22 +00005405static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005406 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005407{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005408 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005409 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005410 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005411 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005412 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005413
Andy Adamsonbf118a32011-12-07 11:55:27 -05005414 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005415 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5416 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005417
Trond Myklebust519d3952012-08-14 17:30:10 -04005418 xdr_enter_page(xdr, xdr->buf->page_len);
5419
Trond Myklebustcff298c2012-08-14 17:14:17 -04005420 /* Calculate the offset of the page data */
5421 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005422
J. Bruce Fields029d1052005-06-22 17:16:22 +00005423 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5424 goto out;
5425 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5426 goto out;
5427
5428 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5429 return -EIO;
5430 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005431
Andy Adamsonbf118a32011-12-07 11:55:27 -05005432 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5433 * are stored with the acl data to handle the problem of
5434 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005435 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005436 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005437
5438 /* Check for receive buffer overflow */
5439 if (res->acl_len > (xdr->nwords << 2) ||
5440 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5441 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005442 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005443 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005444 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005445 } else
5446 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005447
5448out:
5449 return status;
5450}
5451
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452static int
5453decode_savefh(struct xdr_stream *xdr)
5454{
5455 return decode_op_hdr(xdr, OP_SAVEFH);
5456}
5457
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005458static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005460 int status;
5461
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462 status = decode_op_hdr(xdr, OP_SETATTR);
5463 if (status)
5464 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005465 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005466 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005467 print_overflow_msg(__func__, xdr);
5468 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005469}
5470
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005471static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472{
Al Viro8687b632006-10-19 23:28:48 -07005473 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474 uint32_t opnum;
5475 int32_t nfserr;
5476
Benny Halevyc0eae662009-08-14 17:20:14 +03005477 p = xdr_inline_decode(xdr, 8);
5478 if (unlikely(!p))
5479 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005480 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005481 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005482 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005483 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005484 return -EIO;
5485 }
Benny Halevycccddf42009-08-14 17:20:19 +03005486 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005487 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005488 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5489 if (unlikely(!p))
5490 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005491 p = xdr_decode_hyper(p, &res->clientid);
5492 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005493 } else if (nfserr == NFSERR_CLID_INUSE) {
5494 uint32_t len;
5495
5496 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005497 p = xdr_inline_decode(xdr, 4);
5498 if (unlikely(!p))
5499 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005500 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005501 p = xdr_inline_decode(xdr, len);
5502 if (unlikely(!p))
5503 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005504
5505 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005506 p = xdr_inline_decode(xdr, 4);
5507 if (unlikely(!p))
5508 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005509 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005510 p = xdr_inline_decode(xdr, len);
5511 if (unlikely(!p))
5512 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005513 return -NFSERR_CLID_INUSE;
5514 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005515 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516
5517 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005518out_overflow:
5519 print_overflow_msg(__func__, xdr);
5520 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521}
5522
5523static int decode_setclientid_confirm(struct xdr_stream *xdr)
5524{
5525 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5526}
5527
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005528static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005529{
Al Viro8687b632006-10-19 23:28:48 -07005530 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005531 int status;
5532
5533 status = decode_op_hdr(xdr, OP_WRITE);
5534 if (status)
5535 return status;
5536
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005537 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005538 if (unlikely(!p))
5539 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005540 res->count = be32_to_cpup(p++);
5541 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005542 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005543out_overflow:
5544 print_overflow_msg(__func__, xdr);
5545 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546}
5547
5548static int decode_delegreturn(struct xdr_stream *xdr)
5549{
5550 return decode_op_hdr(xdr, OP_DELEGRETURN);
5551}
5552
Chuck Leverfb15b262013-03-16 15:54:34 -04005553static int decode_secinfo_gss(struct xdr_stream *xdr,
5554 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005555{
Chuck Leverfb15b262013-03-16 15:54:34 -04005556 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005557 __be32 *p;
5558
5559 p = xdr_inline_decode(xdr, 4);
5560 if (unlikely(!p))
5561 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005562 oid_len = be32_to_cpup(p);
5563 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005564 goto out_err;
5565
Chuck Leverfb15b262013-03-16 15:54:34 -04005566 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005567 if (unlikely(!p))
5568 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005569 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5570 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005571
5572 p = xdr_inline_decode(xdr, 8);
5573 if (unlikely(!p))
5574 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005575 flavor->flavor_info.qop = be32_to_cpup(p++);
5576 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005577
5578 return 0;
5579
5580out_overflow:
5581 print_overflow_msg(__func__, xdr);
5582 return -EIO;
5583out_err:
5584 return -EINVAL;
5585}
5586
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005587static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005588{
Chuck Leverfb15b262013-03-16 15:54:34 -04005589 struct nfs4_secinfo4 *sec_flavor;
5590 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005591 int status;
5592 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005593
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005594 p = xdr_inline_decode(xdr, 4);
5595 if (unlikely(!p))
5596 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005597
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005598 res->flavors->num_flavors = 0;
5599 num_flavors = be32_to_cpup(p);
5600
5601 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005602 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005603 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005604 break;
5605
5606 p = xdr_inline_decode(xdr, 4);
5607 if (unlikely(!p))
5608 goto out_overflow;
5609 sec_flavor->flavor = be32_to_cpup(p);
5610
5611 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005612 status = decode_secinfo_gss(xdr, sec_flavor);
5613 if (status)
5614 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005615 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005616 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005617 }
5618
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005619 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005620out:
5621 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005622out_overflow:
5623 print_overflow_msg(__func__, xdr);
5624 return -EIO;
5625}
5626
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005627static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5628{
5629 int status = decode_op_hdr(xdr, OP_SECINFO);
5630 if (status)
5631 return status;
5632 return decode_secinfo_common(xdr, res);
5633}
5634
Benny Halevy99fe60d2009-04-01 09:22:29 -04005635#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005636static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5637{
5638 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5639 if (status)
5640 return status;
5641 return decode_secinfo_common(xdr, res);
5642}
5643
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005644static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5645{
5646 __be32 *p;
5647 uint32_t bitmap_words;
5648 unsigned int i;
5649
5650 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005651 if (!p)
5652 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005653 bitmap_words = be32_to_cpup(p++);
5654 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5655 return -EIO;
5656 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5657 for (i = 0; i < bitmap_words; i++)
5658 op_map->u.words[i] = be32_to_cpup(p++);
5659
5660 return 0;
5661}
5662
Benny Halevy99fe60d2009-04-01 09:22:29 -04005663static int decode_exchange_id(struct xdr_stream *xdr,
5664 struct nfs41_exchange_id_res *res)
5665{
5666 __be32 *p;
5667 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005668 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005669 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005670 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005671
5672 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5673 if (status)
5674 return status;
5675
Benny Halevyc0eae662009-08-14 17:20:14 +03005676 p = xdr_inline_decode(xdr, 8);
5677 if (unlikely(!p))
5678 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005679 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005680 p = xdr_inline_decode(xdr, 12);
5681 if (unlikely(!p))
5682 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005683 res->seqid = be32_to_cpup(p++);
5684 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005685
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005686 res->state_protect.how = be32_to_cpup(p);
5687 switch (res->state_protect.how) {
5688 case SP4_NONE:
5689 break;
5690 case SP4_MACH_CRED:
5691 status = decode_op_map(xdr, &res->state_protect.enforce);
5692 if (status)
5693 return status;
5694 status = decode_op_map(xdr, &res->state_protect.allow);
5695 if (status)
5696 return status;
5697 break;
5698 default:
5699 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005700 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005701 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005702
Chuck Leveracdeb692012-05-21 22:46:16 -04005703 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005704 p = xdr_inline_decode(xdr, 8);
5705 if (unlikely(!p))
5706 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005707 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005708
Chuck Leveracdeb692012-05-21 22:46:16 -04005709 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005710 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5711 if (unlikely(status))
5712 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005713 memcpy(res->server_owner->major_id, dummy_str, dummy);
5714 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005715
Chuck Leveracdeb692012-05-21 22:46:16 -04005716 /* server_scope4 */
5717 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5718 if (unlikely(status))
5719 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005720 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5721 res->server_scope->server_scope_sz = dummy;
5722
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005723 /* Implementation Id */
5724 p = xdr_inline_decode(xdr, 4);
5725 if (unlikely(!p))
5726 goto out_overflow;
5727 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005728
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005729 if (impl_id_count) {
5730 /* nii_domain */
5731 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5732 if (unlikely(status))
5733 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005734 memcpy(res->impl_id->domain, dummy_str, dummy);
5735
5736 /* nii_name */
5737 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5738 if (unlikely(status))
5739 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005740 memcpy(res->impl_id->name, dummy_str, dummy);
5741
5742 /* nii_date */
5743 p = xdr_inline_decode(xdr, 12);
5744 if (unlikely(!p))
5745 goto out_overflow;
5746 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5747 res->impl_id->date.nseconds = be32_to_cpup(p);
5748
5749 /* if there's more than one entry, ignore the rest */
5750 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005751 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005752out_overflow:
5753 print_overflow_msg(__func__, xdr);
5754 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005755}
Andy Adamsonfc931582009-04-01 09:22:31 -04005756
5757static int decode_chan_attrs(struct xdr_stream *xdr,
5758 struct nfs4_channel_attrs *attrs)
5759{
5760 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005761 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005762
Benny Halevyc0eae662009-08-14 17:20:14 +03005763 p = xdr_inline_decode(xdr, 28);
5764 if (unlikely(!p))
5765 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005766 val = be32_to_cpup(p++); /* headerpadsz */
5767 if (val)
5768 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005769 attrs->max_rqst_sz = be32_to_cpup(p++);
5770 attrs->max_resp_sz = be32_to_cpup(p++);
5771 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5772 attrs->max_ops = be32_to_cpup(p++);
5773 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005774 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005775 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005776 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5777 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005778 return -EINVAL;
5779 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005780 if (nr_attrs == 1) {
5781 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5782 if (unlikely(!p))
5783 goto out_overflow;
5784 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005785 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005786out_overflow:
5787 print_overflow_msg(__func__, xdr);
5788 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005789}
5790
Benny Halevye78291e2009-08-14 17:20:00 +03005791static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5792{
5793 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005794}
5795
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005796static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5797 struct nfs41_bind_conn_to_session_res *res)
5798{
5799 __be32 *p;
5800 int status;
5801
5802 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5803 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005804 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005805 if (unlikely(status))
5806 return status;
5807
5808 /* dir flags, rdma mode bool */
5809 p = xdr_inline_decode(xdr, 8);
5810 if (unlikely(!p))
5811 goto out_overflow;
5812
5813 res->dir = be32_to_cpup(p++);
5814 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5815 return -EIO;
5816 if (be32_to_cpup(p) == 0)
5817 res->use_conn_in_rdma_mode = false;
5818 else
5819 res->use_conn_in_rdma_mode = true;
5820
5821 return 0;
5822out_overflow:
5823 print_overflow_msg(__func__, xdr);
5824 return -EIO;
5825}
5826
Andy Adamsonfc931582009-04-01 09:22:31 -04005827static int decode_create_session(struct xdr_stream *xdr,
5828 struct nfs41_create_session_res *res)
5829{
5830 __be32 *p;
5831 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005832
5833 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005834 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005835 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005836 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005837 return status;
5838
Andy Adamsonfc931582009-04-01 09:22:31 -04005839 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005840 p = xdr_inline_decode(xdr, 8);
5841 if (unlikely(!p))
5842 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005843 res->seqid = be32_to_cpup(p++);
5844 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005845
5846 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005847 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005848 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005849 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005850 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005851out_overflow:
5852 print_overflow_msg(__func__, xdr);
5853 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005854}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005855
5856static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5857{
5858 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5859}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005860
Trond Myklebust66245532012-05-25 17:18:09 -04005861static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5862{
5863 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5864}
5865
Ricardo Labiaga180197532009-12-05 16:08:40 -05005866static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5867{
5868 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5869}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005870#endif /* CONFIG_NFS_V4_1 */
5871
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005872static int decode_sequence(struct xdr_stream *xdr,
5873 struct nfs4_sequence_res *res,
5874 struct rpc_rqst *rqstp)
5875{
5876#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005877 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005878 struct nfs4_sessionid id;
5879 u32 dummy;
5880 int status;
5881 __be32 *p;
5882
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005883 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005884 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005885 if (!res->sr_slot->table->session)
5886 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005887
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005888 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005889 if (!status)
5890 status = decode_sessionid(xdr, &id);
5891 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005892 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005893
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005894 /*
5895 * If the server returns different values for sessionID, slotID or
5896 * sequence number, the server is looney tunes.
5897 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005898 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005899 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005900
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005901 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005902 NFS4_MAX_SESSIONID_LEN)) {
5903 dprintk("%s Invalid session id\n", __func__);
5904 goto out_err;
5905 }
Benny Halevye78291e2009-08-14 17:20:00 +03005906
Benny Halevyc0eae662009-08-14 17:20:14 +03005907 p = xdr_inline_decode(xdr, 20);
5908 if (unlikely(!p))
5909 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005910
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005911 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005912 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005913 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005914 dprintk("%s Invalid sequence number\n", __func__);
5915 goto out_err;
5916 }
5917 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005918 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005919 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005920 dprintk("%s Invalid slot id\n", __func__);
5921 goto out_err;
5922 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005923 /* highest slot id */
5924 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005925 /* target highest slot id */
5926 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005927 /* result flags */
5928 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005929 status = 0;
5930out_err:
5931 res->sr_status = status;
5932 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005933out_overflow:
5934 print_overflow_msg(__func__, xdr);
5935 status = -EIO;
5936 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005937#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005938 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005939#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005940}
5941
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005942#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005943static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5944{
5945 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5946 return decode_stateid(xdr, stateid);
5947}
5948
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005949static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005950 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005951{
Trond Myklebust4e590802015-03-09 14:01:25 -04005952 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005953 __be32 *p;
5954 uint32_t len, type;
5955 int status;
5956
5957 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5958 if (status) {
5959 if (status == -ETOOSMALL) {
5960 p = xdr_inline_decode(xdr, 4);
5961 if (unlikely(!p))
5962 goto out_overflow;
5963 pdev->mincount = be32_to_cpup(p);
5964 dprintk("%s: Min count too small. mincnt = %u\n",
5965 __func__, pdev->mincount);
5966 }
5967 return status;
5968 }
5969
5970 p = xdr_inline_decode(xdr, 8);
5971 if (unlikely(!p))
5972 goto out_overflow;
5973 type = be32_to_cpup(p++);
5974 if (type != pdev->layout_type) {
5975 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5976 __func__, pdev->layout_type, type);
5977 return -EINVAL;
5978 }
5979 /*
5980 * Get the length of the opaque device_addr4. xdr_read_pages places
5981 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5982 * and places the remaining xdr data in xdr_buf->tail
5983 */
5984 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005985 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5986 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005987
5988 /* Parse notification bitmap, verifying that it is zero. */
5989 p = xdr_inline_decode(xdr, 4);
5990 if (unlikely(!p))
5991 goto out_overflow;
5992 len = be32_to_cpup(p);
5993 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005994 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005995
5996 p = xdr_inline_decode(xdr, 4 * len);
5997 if (unlikely(!p))
5998 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005999
Trond Myklebust4e590802015-03-09 14:01:25 -04006000 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006001 for (i = 1; i < len; i++) {
6002 if (be32_to_cpup(p++)) {
6003 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006004 __func__);
6005 return -EIO;
6006 }
6007 }
6008 }
6009 return 0;
6010out_overflow:
6011 print_overflow_msg(__func__, xdr);
6012 return -EIO;
6013}
6014
6015static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6016 struct nfs4_layoutget_res *res)
6017{
6018 __be32 *p;
6019 int status;
6020 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04006021 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006022
6023 status = decode_op_hdr(xdr, OP_LAYOUTGET);
6024 if (status)
6025 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006026 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006027 if (unlikely(!p))
6028 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006029 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04006030 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006031 p = xdr_inline_decode(xdr, 4);
6032 if (unlikely(!p))
6033 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006034 layout_count = be32_to_cpup(p);
6035 if (!layout_count) {
6036 dprintk("%s: server responded with empty layout array\n",
6037 __func__);
6038 return -EINVAL;
6039 }
6040
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006041 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006042 if (unlikely(!p))
6043 goto out_overflow;
6044 p = xdr_decode_hyper(p, &res->range.offset);
6045 p = xdr_decode_hyper(p, &res->range.length);
6046 res->range.iomode = be32_to_cpup(p++);
6047 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006048 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006049
6050 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6051 __func__,
6052 (unsigned long)res->range.offset,
6053 (unsigned long)res->range.length,
6054 res->range.iomode,
6055 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006056 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006057
Trond Myklebust64bd5772012-06-20 22:35:05 -04006058 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006059 if (res->layoutp->len > recvd) {
6060 dprintk("NFS: server cheating in layoutget reply: "
6061 "layout len %u > recvd %u\n",
6062 res->layoutp->len, recvd);
6063 return -EINVAL;
6064 }
6065
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006066 if (layout_count > 1) {
6067 /* We only handle a length one array at the moment. Any
6068 * further entries are just ignored. Note that this means
6069 * the client may see a response that is less than the
6070 * minimum it requested.
6071 */
6072 dprintk("%s: server responded with %d layouts, dropping tail\n",
6073 __func__, layout_count);
6074 }
6075
6076 return 0;
6077out_overflow:
6078 print_overflow_msg(__func__, xdr);
6079 return -EIO;
6080}
Andy Adamson863a3c62011-03-23 13:27:54 +00006081
Benny Halevycbe82602011-05-22 19:52:37 +03006082static int decode_layoutreturn(struct xdr_stream *xdr,
6083 struct nfs4_layoutreturn_res *res)
6084{
6085 __be32 *p;
6086 int status;
6087
6088 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6089 if (status)
6090 return status;
6091 p = xdr_inline_decode(xdr, 4);
6092 if (unlikely(!p))
6093 goto out_overflow;
6094 res->lrs_present = be32_to_cpup(p);
6095 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006096 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05006097 else
6098 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006099 return status;
6100out_overflow:
6101 print_overflow_msg(__func__, xdr);
6102 return -EIO;
6103}
6104
Andy Adamson863a3c62011-03-23 13:27:54 +00006105static int decode_layoutcommit(struct xdr_stream *xdr,
6106 struct rpc_rqst *req,
6107 struct nfs4_layoutcommit_res *res)
6108{
6109 __be32 *p;
6110 __u32 sizechanged;
6111 int status;
6112
6113 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006114 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006115 if (status)
6116 return status;
6117
6118 p = xdr_inline_decode(xdr, 4);
6119 if (unlikely(!p))
6120 goto out_overflow;
6121 sizechanged = be32_to_cpup(p);
6122
6123 if (sizechanged) {
6124 /* throw away new size */
6125 p = xdr_inline_decode(xdr, 8);
6126 if (unlikely(!p))
6127 goto out_overflow;
6128 }
6129 return 0;
6130out_overflow:
6131 print_overflow_msg(__func__, xdr);
6132 return -EIO;
6133}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006134
6135static int decode_test_stateid(struct xdr_stream *xdr,
6136 struct nfs41_test_stateid_res *res)
6137{
6138 __be32 *p;
6139 int status;
6140 int num_res;
6141
6142 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6143 if (status)
6144 return status;
6145
6146 p = xdr_inline_decode(xdr, 4);
6147 if (unlikely(!p))
6148 goto out_overflow;
6149 num_res = be32_to_cpup(p++);
6150 if (num_res != 1)
6151 goto out;
6152
6153 p = xdr_inline_decode(xdr, 4);
6154 if (unlikely(!p))
6155 goto out_overflow;
6156 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006157
6158 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006159out_overflow:
6160 print_overflow_msg(__func__, xdr);
6161out:
6162 return -EIO;
6163}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006164
6165static int decode_free_stateid(struct xdr_stream *xdr,
6166 struct nfs41_free_stateid_res *res)
6167{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006168 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006169 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006170}
Trond Myklebustcf805162016-11-15 14:56:07 -05006171#else
6172static inline
6173int decode_layoutreturn(struct xdr_stream *xdr,
6174 struct nfs4_layoutreturn_res *res)
6175{
6176 return 0;
6177}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006178#endif /* CONFIG_NFS_V4_1 */
6179
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180/*
Benny Halevy49c25592008-12-23 16:06:16 -05006181 * END OF "GENERIC" DECODE ROUTINES.
6182 */
6183
6184/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006185 * Decode OPEN_DOWNGRADE response
6186 */
Chuck Leverbf269552010-12-14 14:59:29 +00006187static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6188 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006189 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006190{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006191 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006192 struct compound_hdr hdr;
6193 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194
Chuck Leverbf269552010-12-14 14:59:29 +00006195 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006196 if (status)
6197 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006198 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006199 if (status)
6200 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006201 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006202 if (status)
6203 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006204 if (res->lr_res) {
6205 status = decode_layoutreturn(xdr, res->lr_res);
6206 res->lr_ret = status;
6207 if (status)
6208 goto out;
6209 }
Chuck Leverbf269552010-12-14 14:59:29 +00006210 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006211out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006212 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006213}
6214
6215/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216 * Decode ACCESS response
6217 */
Chuck Leverbf269552010-12-14 14:59:29 +00006218static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006219 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006221 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222 struct compound_hdr hdr;
6223 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006224
Chuck Leverbf269552010-12-14 14:59:29 +00006225 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006226 if (status)
6227 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006228 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006229 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006231 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006232 if (status != 0)
6233 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006234 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006235 if (status != 0)
6236 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006237 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238out:
6239 return status;
6240}
6241
6242/*
6243 * Decode LOOKUP response
6244 */
Chuck Leverbf269552010-12-14 14:59:29 +00006245static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006246 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006248 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249 struct compound_hdr hdr;
6250 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006251
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006253 if (status)
6254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006256 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_putfh(xdr);
6259 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_lookup(xdr);
6262 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006263 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006264 status = decode_getfh(xdr, res->fh);
6265 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006267 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268out:
6269 return status;
6270}
6271
6272/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006273 * Decode LOOKUPP response
6274 */
6275static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6276 void *data)
6277{
6278 struct nfs4_lookupp_res *res = data;
6279 struct compound_hdr hdr;
6280 int status;
6281
6282 status = decode_compound_hdr(xdr, &hdr);
6283 if (status)
6284 goto out;
6285 status = decode_sequence(xdr, &res->seq_res, rqstp);
6286 if (status)
6287 goto out;
6288 status = decode_putfh(xdr);
6289 if (status)
6290 goto out;
6291 status = decode_lookupp(xdr);
6292 if (status)
6293 goto out;
6294 status = decode_getfh(xdr, res->fh);
6295 if (status)
6296 goto out;
6297 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6298out:
6299 return status;
6300}
6301
6302/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006303 * Decode LOOKUP_ROOT response
6304 */
Chuck Leverbf269552010-12-14 14:59:29 +00006305static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6306 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006307 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006309 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310 struct compound_hdr hdr;
6311 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006312
Chuck Leverbf269552010-12-14 14:59:29 +00006313 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006314 if (status)
6315 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006316 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006317 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006318 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006319 status = decode_putrootfh(xdr);
6320 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006321 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006322 status = decode_getfh(xdr, res->fh);
6323 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006324 status = decode_getfattr_label(xdr, res->fattr,
6325 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006326out:
6327 return status;
6328}
6329
6330/*
6331 * Decode REMOVE response
6332 */
Chuck Leverbf269552010-12-14 14:59:29 +00006333static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006334 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006335{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006336 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337 struct compound_hdr hdr;
6338 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006339
Chuck Leverbf269552010-12-14 14:59:29 +00006340 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006341 if (status)
6342 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006343 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006344 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006345 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006346 status = decode_putfh(xdr);
6347 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006348 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006349 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350out:
6351 return status;
6352}
6353
6354/*
6355 * Decode RENAME response
6356 */
Chuck Leverbf269552010-12-14 14:59:29 +00006357static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006358 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006360 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006361 struct compound_hdr hdr;
6362 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006363
Chuck Leverbf269552010-12-14 14:59:29 +00006364 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006365 if (status)
6366 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006367 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006368 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006369 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006370 status = decode_putfh(xdr);
6371 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006373 status = decode_savefh(xdr);
6374 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006375 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006376 status = decode_putfh(xdr);
6377 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006379 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006380out:
6381 return status;
6382}
6383
6384/*
6385 * Decode LINK response
6386 */
Chuck Leverbf269552010-12-14 14:59:29 +00006387static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006388 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006390 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 struct compound_hdr hdr;
6392 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006393
Chuck Leverbf269552010-12-14 14:59:29 +00006394 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006395 if (status)
6396 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006397 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006398 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006399 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006400 status = decode_putfh(xdr);
6401 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_savefh(xdr);
6404 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006405 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006406 status = decode_putfh(xdr);
6407 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006408 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006409 status = decode_link(xdr, &res->cinfo);
6410 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006411 goto out;
6412 /*
6413 * Note order: OP_LINK leaves the directory as the current
6414 * filehandle.
6415 */
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_restorefh(xdr);
6417 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006418 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006419 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006420out:
6421 return status;
6422}
6423
6424/*
6425 * Decode CREATE response
6426 */
Chuck Leverbf269552010-12-14 14:59:29 +00006427static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006428 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006430 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006431 struct compound_hdr hdr;
6432 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006433
Chuck Leverbf269552010-12-14 14:59:29 +00006434 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006435 if (status)
6436 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006437 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006438 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006439 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006440 status = decode_putfh(xdr);
6441 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006443 status = decode_create(xdr, &res->dir_cinfo);
6444 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006445 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006446 status = decode_getfh(xdr, res->fh);
6447 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006449 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006450out:
6451 return status;
6452}
6453
6454/*
6455 * Decode SYMLINK response
6456 */
Chuck Leverbf269552010-12-14 14:59:29 +00006457static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006458 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006459{
Chuck Leverbf269552010-12-14 14:59:29 +00006460 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461}
6462
6463/*
6464 * Decode GETATTR response
6465 */
Chuck Leverbf269552010-12-14 14:59:29 +00006466static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006467 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006469 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 struct compound_hdr hdr;
6471 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006472
Chuck Leverbf269552010-12-14 14:59:29 +00006473 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006474 if (status)
6475 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006476 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006477 if (status)
6478 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006480 if (status)
6481 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006482 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483out:
6484 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006485}
6486
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006487/*
6488 * Encode an SETACL request
6489 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006490static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006491 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006492{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006493 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006496 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006497
Chuck Lever9f06c712010-12-14 14:59:18 +00006498 encode_compound_hdr(xdr, req, &hdr);
6499 encode_sequence(xdr, &args->seq_args, &hdr);
6500 encode_putfh(xdr, args->fh, &hdr);
6501 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006502 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006503}
Andy Adamson05d564f2008-12-23 16:06:15 -05006504
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006505/*
6506 * Decode SETACL response
6507 */
6508static int
Chuck Leverbf269552010-12-14 14:59:29 +00006509nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006510 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006511{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006512 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006513 struct compound_hdr hdr;
6514 int status;
6515
Chuck Leverbf269552010-12-14 14:59:29 +00006516 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006517 if (status)
6518 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006519 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006520 if (status)
6521 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006522 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006523 if (status)
6524 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006525 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006526out:
6527 return status;
6528}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006529
6530/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006531 * Decode GETACL response
6532 */
6533static int
Chuck Leverbf269552010-12-14 14:59:29 +00006534nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006535 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006536{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006537 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006538 struct compound_hdr hdr;
6539 int status;
6540
Trond Myklebust331818f2012-02-03 18:30:53 -05006541 if (res->acl_scratch != NULL) {
6542 void *p = page_address(res->acl_scratch);
6543 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6544 }
Chuck Leverbf269552010-12-14 14:59:29 +00006545 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006546 if (status)
6547 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006548 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006549 if (status)
6550 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006551 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006552 if (status)
6553 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006554 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006555
6556out:
6557 return status;
6558}
6559
6560/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006561 * Decode CLOSE response
6562 */
Chuck Leverbf269552010-12-14 14:59:29 +00006563static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006564 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006565{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006566 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006567 struct compound_hdr hdr;
6568 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006569
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006571 if (status)
6572 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006574 if (status)
6575 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006576 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006577 if (status)
6578 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006579 if (res->lr_res) {
6580 status = decode_layoutreturn(xdr, res->lr_res);
6581 res->lr_ret = status;
6582 if (status)
6583 goto out;
6584 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006585 if (res->fattr != NULL) {
6586 status = decode_getfattr(xdr, res->fattr, res->server);
6587 if (status != 0)
6588 goto out;
6589 }
Chuck Leverbf269552010-12-14 14:59:29 +00006590 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006592 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006593}
6594
6595/*
6596 * Decode OPEN response
6597 */
Chuck Leverbf269552010-12-14 14:59:29 +00006598static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006599 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006600{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006601 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006602 struct compound_hdr hdr;
6603 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006604
Chuck Leverbf269552010-12-14 14:59:29 +00006605 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006606 if (status)
6607 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006608 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006609 if (status)
6610 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006611 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006612 if (status)
6613 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006614 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006615 if (status)
6616 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006617 status = decode_getfh(xdr, &res->fh);
6618 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006619 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006620 if (res->access_request)
6621 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006622 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006623out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006624 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006625}
6626
6627/*
6628 * Decode OPEN_CONFIRM response
6629 */
Chuck Leverbf269552010-12-14 14:59:29 +00006630static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6631 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006632 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006633{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006634 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006635 struct compound_hdr hdr;
6636 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006637
Chuck Leverbf269552010-12-14 14:59:29 +00006638 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006639 if (status)
6640 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006641 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006642 if (status)
6643 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006644 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006645out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006646 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006647}
6648
6649/*
6650 * Decode OPEN response
6651 */
Chuck Leverbf269552010-12-14 14:59:29 +00006652static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6653 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006654 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006655{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006656 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006657 struct compound_hdr hdr;
6658 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659
Chuck Leverbf269552010-12-14 14:59:29 +00006660 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006661 if (status)
6662 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006663 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006664 if (status)
6665 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006667 if (status)
6668 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006670 if (status)
6671 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006672 if (res->access_request)
6673 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006674 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006675out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006676 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677}
6678
6679/*
6680 * Decode SETATTR response
6681 */
Chuck Leverbf269552010-12-14 14:59:29 +00006682static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6683 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006684 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006685{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006686 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006687 struct compound_hdr hdr;
6688 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689
Chuck Leverbf269552010-12-14 14:59:29 +00006690 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006691 if (status)
6692 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006693 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006694 if (status)
6695 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006696 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006697 if (status)
6698 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006699 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006700 if (status)
6701 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006702 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006703out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006704 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705}
6706
6707/*
6708 * Decode LOCK response
6709 */
Chuck Leverbf269552010-12-14 14:59:29 +00006710static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006711 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006713 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006714 struct compound_hdr hdr;
6715 int status;
6716
Chuck Leverbf269552010-12-14 14:59:29 +00006717 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006718 if (status)
6719 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006720 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006721 if (status)
6722 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006723 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006724 if (status)
6725 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006726 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727out:
6728 return status;
6729}
6730
6731/*
6732 * Decode LOCKT response
6733 */
Chuck Leverbf269552010-12-14 14:59:29 +00006734static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006735 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006737 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 struct compound_hdr hdr;
6739 int status;
6740
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006742 if (status)
6743 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006744 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006745 if (status)
6746 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006747 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006748 if (status)
6749 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006750 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006751out:
6752 return status;
6753}
6754
6755/*
6756 * Decode LOCKU response
6757 */
Chuck Leverbf269552010-12-14 14:59:29 +00006758static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006759 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006761 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762 struct compound_hdr hdr;
6763 int status;
6764
Chuck Leverbf269552010-12-14 14:59:29 +00006765 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006766 if (status)
6767 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006768 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006769 if (status)
6770 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006772 if (status)
6773 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006775out:
6776 return status;
6777}
6778
Chuck Leverbf269552010-12-14 14:59:29 +00006779static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6780 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006781{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006782 struct compound_hdr hdr;
6783 int status;
6784
Chuck Leverbf269552010-12-14 14:59:29 +00006785 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006786 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006788 return status;
6789}
6790
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791/*
6792 * Decode READLINK response
6793 */
Chuck Leverbf269552010-12-14 14:59:29 +00006794static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6795 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006796 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006797{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006798 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799 struct compound_hdr hdr;
6800 int status;
6801
Chuck Leverbf269552010-12-14 14:59:29 +00006802 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006803 if (status)
6804 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006805 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006806 if (status)
6807 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006808 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006809 if (status)
6810 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006811 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006812out:
6813 return status;
6814}
6815
6816/*
6817 * Decode READDIR response
6818 */
Chuck Leverbf269552010-12-14 14:59:29 +00006819static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006820 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006822 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006823 struct compound_hdr hdr;
6824 int status;
6825
Chuck Leverbf269552010-12-14 14:59:29 +00006826 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006827 if (status)
6828 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006829 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006830 if (status)
6831 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006832 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006833 if (status)
6834 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006836out:
6837 return status;
6838}
6839
6840/*
6841 * Decode Read response
6842 */
Chuck Leverbf269552010-12-14 14:59:29 +00006843static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006844 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006846 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006847 struct compound_hdr hdr;
6848 int status;
6849
Chuck Leverbf269552010-12-14 14:59:29 +00006850 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006851 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006852 if (status)
6853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006855 if (status)
6856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 if (status)
6859 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006860 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006861 if (!status)
6862 status = res->count;
6863out:
6864 return status;
6865}
6866
6867/*
6868 * Decode WRITE response
6869 */
Chuck Leverbf269552010-12-14 14:59:29 +00006870static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006871 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006873 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 struct compound_hdr hdr;
6875 int status;
6876
Chuck Leverbf269552010-12-14 14:59:29 +00006877 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006878 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 if (status)
6880 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006881 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006882 if (status)
6883 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006884 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006885 if (status)
6886 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006887 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006888 if (status)
6889 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006890 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006891 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 if (!status)
6893 status = res->count;
6894out:
6895 return status;
6896}
6897
6898/*
6899 * Decode COMMIT response
6900 */
Chuck Leverbf269552010-12-14 14:59:29 +00006901static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006902 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006904 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006905 struct compound_hdr hdr;
6906 int status;
6907
Chuck Leverbf269552010-12-14 14:59:29 +00006908 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006909 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 if (status)
6911 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006912 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006913 if (status)
6914 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006915 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916 if (status)
6917 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006918 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919out:
6920 return status;
6921}
6922
6923/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006924 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925 */
Chuck Leverbf269552010-12-14 14:59:29 +00006926static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006927 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006928{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006929 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006930 struct compound_hdr hdr;
6931 int status;
6932
Chuck Leverbf269552010-12-14 14:59:29 +00006933 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006934 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006935 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006936 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006937 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006939 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006940 return status;
6941}
6942
6943/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006944 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 */
Chuck Leverbf269552010-12-14 14:59:29 +00006946static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006947 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006948{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006949 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006950 struct compound_hdr hdr;
6951 int status;
6952
Chuck Leverbf269552010-12-14 14:59:29 +00006953 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006954 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006955 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006956 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006957 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006958 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006959 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960 return status;
6961}
6962
6963/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006964 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006965 */
Chuck Leverbf269552010-12-14 14:59:29 +00006966static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006967 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006968{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006969 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006970 struct compound_hdr hdr;
6971 int status;
6972
Chuck Leverbf269552010-12-14 14:59:29 +00006973 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006974 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006975 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006976 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006977 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006978 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006979 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006980 return status;
6981}
6982
6983/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006984 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006985 */
Chuck Leverbf269552010-12-14 14:59:29 +00006986static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6987 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006988 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006989{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006990 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006991 struct compound_hdr hdr;
6992 int status;
6993
Chuck Leverbf269552010-12-14 14:59:29 +00006994 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006995 if (status)
6996 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006997 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006998 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006999 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007000 status = decode_putfh(xdr);
7001 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007003 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007004out:
7005 return status;
7006}
7007
7008/*
7009 * Decode RENEW response
7010 */
Chuck Leverbf269552010-12-14 14:59:29 +00007011static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
7012 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007013{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007014 struct compound_hdr hdr;
7015 int status;
7016
Chuck Leverbf269552010-12-14 14:59:29 +00007017 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007018 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007019 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007020 return status;
7021}
7022
7023/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007024 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007025 */
Chuck Leverbf269552010-12-14 14:59:29 +00007026static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
7027 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007028 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007029{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007030 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007031 struct compound_hdr hdr;
7032 int status;
7033
Chuck Leverbf269552010-12-14 14:59:29 +00007034 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007035 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007036 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037 return status;
7038}
7039
7040/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007041 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007042 */
Chuck Leverbf269552010-12-14 14:59:29 +00007043static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007044 struct xdr_stream *xdr,
7045 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007046{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007047 struct compound_hdr hdr;
7048 int status;
7049
Chuck Leverbf269552010-12-14 14:59:29 +00007050 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007051 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007052 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 return status;
7054}
7055
7056/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007057 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007058 */
Chuck Leverbf269552010-12-14 14:59:29 +00007059static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7060 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007061 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007062{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007063 struct nfs4_delegreturnres *res = data;
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);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007068 if (status)
7069 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007070 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007071 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01007072 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007073 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007074 if (status != 0)
7075 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05007076 if (res->lr_res) {
7077 status = decode_layoutreturn(xdr, res->lr_res);
7078 res->lr_ret = status;
7079 if (status)
7080 goto out;
7081 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05007082 if (res->fattr) {
7083 status = decode_getfattr(xdr, res->fattr, res->server);
7084 if (status != 0)
7085 goto out;
7086 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04007087 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007088out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007089 return status;
7090}
7091
Trond Myklebust683b57b2006-06-09 09:34:22 -04007092/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007093 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04007094 */
Chuck Leverbf269552010-12-14 14:59:29 +00007095static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7096 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007097 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007098{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007099 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04007100 struct compound_hdr hdr;
7101 int status;
7102
Chuck Leverbf269552010-12-14 14:59:29 +00007103 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007104 if (status)
7105 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007106 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007107 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007108 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007109 status = decode_putfh(xdr);
7110 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007111 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04007112 if (res->migration) {
7113 xdr_enter_page(xdr, PAGE_SIZE);
7114 status = decode_getfattr_generic(xdr,
7115 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007116 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04007117 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007118 if (status)
7119 goto out;
7120 if (res->renew)
7121 status = decode_renew(xdr);
7122 } else {
7123 status = decode_lookup(xdr);
7124 if (status)
7125 goto out;
7126 xdr_enter_page(xdr, PAGE_SIZE);
7127 status = decode_getfattr_generic(xdr,
7128 &res->fs_locations->fattr,
7129 NULL, res->fs_locations,
7130 NULL, res->fs_locations->server);
7131 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007132out:
7133 return status;
7134}
7135
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007136/*
7137 * Decode SECINFO response
7138 */
7139static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7140 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007141 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007142{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007143 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007144 struct compound_hdr hdr;
7145 int status;
7146
7147 status = decode_compound_hdr(xdr, &hdr);
7148 if (status)
7149 goto out;
7150 status = decode_sequence(xdr, &res->seq_res, rqstp);
7151 if (status)
7152 goto out;
7153 status = decode_putfh(xdr);
7154 if (status)
7155 goto out;
7156 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007157out:
7158 return status;
7159}
7160
Chuck Lever44c99932013-10-17 14:13:30 -04007161/*
7162 * Decode FSID_PRESENT response
7163 */
7164static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7165 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007166 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007167{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007168 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007169 struct compound_hdr hdr;
7170 int status;
7171
7172 status = decode_compound_hdr(xdr, &hdr);
7173 if (status)
7174 goto out;
7175 status = decode_sequence(xdr, &res->seq_res, rqstp);
7176 if (status)
7177 goto out;
7178 status = decode_putfh(xdr);
7179 if (status)
7180 goto out;
7181 status = decode_getfh(xdr, res->fh);
7182 if (status)
7183 goto out;
7184 if (res->renew)
7185 status = decode_renew(xdr);
7186out:
7187 return status;
7188}
7189
Benny Halevy99fe60d2009-04-01 09:22:29 -04007190#if defined(CONFIG_NFS_V4_1)
7191/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007192 * Decode BIND_CONN_TO_SESSION response
7193 */
7194static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7195 struct xdr_stream *xdr,
7196 void *res)
7197{
7198 struct compound_hdr hdr;
7199 int status;
7200
7201 status = decode_compound_hdr(xdr, &hdr);
7202 if (!status)
7203 status = decode_bind_conn_to_session(xdr, res);
7204 return status;
7205}
7206
7207/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007208 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007209 */
Chuck Leverbf269552010-12-14 14:59:29 +00007210static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7211 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007212 void *res)
7213{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007214 struct compound_hdr hdr;
7215 int status;
7216
Chuck Leverbf269552010-12-14 14:59:29 +00007217 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007218 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007219 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007220 return status;
7221}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007222
7223/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007224 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007225 */
Chuck Leverbf269552010-12-14 14:59:29 +00007226static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7227 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007228 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007229{
Andy Adamsonfc931582009-04-01 09:22:31 -04007230 struct compound_hdr hdr;
7231 int status;
7232
Chuck Leverbf269552010-12-14 14:59:29 +00007233 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007234 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007235 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007236 return status;
7237}
7238
7239/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007240 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007241 */
Chuck Leverbf269552010-12-14 14:59:29 +00007242static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7243 struct xdr_stream *xdr,
7244 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007245{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007246 struct compound_hdr hdr;
7247 int status;
7248
Chuck Leverbf269552010-12-14 14:59:29 +00007249 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007250 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007251 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007252 return status;
7253}
7254
7255/*
Trond Myklebust66245532012-05-25 17:18:09 -04007256 * Decode DESTROY_CLIENTID response
7257 */
7258static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7259 struct xdr_stream *xdr,
7260 void *res)
7261{
7262 struct compound_hdr hdr;
7263 int status;
7264
7265 status = decode_compound_hdr(xdr, &hdr);
7266 if (!status)
7267 status = decode_destroy_clientid(xdr, res);
7268 return status;
7269}
7270
7271/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007272 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007273 */
Chuck Leverbf269552010-12-14 14:59:29 +00007274static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7275 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007276 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007277{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007278 struct compound_hdr hdr;
7279 int status;
7280
Chuck Leverbf269552010-12-14 14:59:29 +00007281 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007282 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007283 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007284 return status;
7285}
7286
7287/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007288 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007289 */
Chuck Leverbf269552010-12-14 14:59:29 +00007290static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7291 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007292 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007293{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007294 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007295 struct compound_hdr hdr;
7296 int status;
7297
Chuck Leverbf269552010-12-14 14:59:29 +00007298 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007299 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007300 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007301 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007302 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007303 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007304 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007305 return status;
7306}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007307
7308/*
7309 * Decode RECLAIM_COMPLETE response
7310 */
Chuck Leverbf269552010-12-14 14:59:29 +00007311static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7312 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007313 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007314{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007315 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007316 struct compound_hdr hdr;
7317 int status;
7318
Chuck Leverbf269552010-12-14 14:59:29 +00007319 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007320 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007321 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007322 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307323 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007324 return status;
7325}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007326
7327/*
7328 * Decode GETDEVINFO response
7329 */
Chuck Leverbf269552010-12-14 14:59:29 +00007330static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7331 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007332 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007333{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007334 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007335 struct compound_hdr hdr;
7336 int status;
7337
Chuck Leverbf269552010-12-14 14:59:29 +00007338 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007339 if (status != 0)
7340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007341 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007342 if (status != 0)
7343 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007344 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007345out:
7346 return status;
7347}
7348
7349/*
7350 * Decode LAYOUTGET response
7351 */
Chuck Leverbf269552010-12-14 14:59:29 +00007352static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7353 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007354 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007355{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007356 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007357 struct compound_hdr hdr;
7358 int status;
7359
Chuck Leverbf269552010-12-14 14:59:29 +00007360 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007361 if (status)
7362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007363 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007364 if (status)
7365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007366 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007367 if (status)
7368 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007369 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007370out:
7371 return status;
7372}
Andy Adamson863a3c62011-03-23 13:27:54 +00007373
7374/*
Benny Halevycbe82602011-05-22 19:52:37 +03007375 * Decode LAYOUTRETURN response
7376 */
7377static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7378 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007379 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007380{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007381 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007382 struct compound_hdr hdr;
7383 int status;
7384
7385 status = decode_compound_hdr(xdr, &hdr);
7386 if (status)
7387 goto out;
7388 status = decode_sequence(xdr, &res->seq_res, rqstp);
7389 if (status)
7390 goto out;
7391 status = decode_putfh(xdr);
7392 if (status)
7393 goto out;
7394 status = decode_layoutreturn(xdr, res);
7395out:
7396 return status;
7397}
7398
7399/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007400 * Decode LAYOUTCOMMIT response
7401 */
7402static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7403 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007404 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007405{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007406 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007407 struct compound_hdr hdr;
7408 int status;
7409
7410 status = decode_compound_hdr(xdr, &hdr);
7411 if (status)
7412 goto out;
7413 status = decode_sequence(xdr, &res->seq_res, rqstp);
7414 if (status)
7415 goto out;
7416 status = decode_putfh(xdr);
7417 if (status)
7418 goto out;
7419 status = decode_layoutcommit(xdr, rqstp, res);
7420 if (status)
7421 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007422 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007423out:
7424 return status;
7425}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007426
7427/*
7428 * Decode SECINFO_NO_NAME response
7429 */
7430static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7431 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007432 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007433{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007434 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007435 struct compound_hdr hdr;
7436 int status;
7437
7438 status = decode_compound_hdr(xdr, &hdr);
7439 if (status)
7440 goto out;
7441 status = decode_sequence(xdr, &res->seq_res, rqstp);
7442 if (status)
7443 goto out;
7444 status = decode_putrootfh(xdr);
7445 if (status)
7446 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007447 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007448out:
7449 return status;
7450}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007451
7452/*
7453 * Decode TEST_STATEID response
7454 */
7455static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7456 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007457 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007458{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007459 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007460 struct compound_hdr hdr;
7461 int status;
7462
7463 status = decode_compound_hdr(xdr, &hdr);
7464 if (status)
7465 goto out;
7466 status = decode_sequence(xdr, &res->seq_res, rqstp);
7467 if (status)
7468 goto out;
7469 status = decode_test_stateid(xdr, res);
7470out:
7471 return status;
7472}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007473
7474/*
7475 * Decode FREE_STATEID response
7476 */
7477static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7478 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007479 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007480{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007481 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007482 struct compound_hdr hdr;
7483 int status;
7484
7485 status = decode_compound_hdr(xdr, &hdr);
7486 if (status)
7487 goto out;
7488 status = decode_sequence(xdr, &res->seq_res, rqstp);
7489 if (status)
7490 goto out;
7491 status = decode_free_stateid(xdr, res);
7492out:
7493 return status;
7494}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007495#endif /* CONFIG_NFS_V4_1 */
7496
Chuck Lever573c4e12010-12-14 14:58:11 +00007497/**
7498 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7499 * the local page cache.
7500 * @xdr: XDR stream where entry resides
7501 * @entry: buffer to fill in with entry data
7502 * @plus: boolean indicating whether this should be a readdirplus entry
7503 *
7504 * Returns zero if successful, otherwise a negative errno value is
7505 * returned.
7506 *
7507 * This function is not invoked during READDIR reply decoding, but
7508 * rather whenever an application invokes the getdents(2) system call
7509 * on a directory already in our cache.
7510 */
7511int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007512 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007513{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007514 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007515 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007516 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007517 __be32 *p = xdr_inline_decode(xdr, 4);
7518 if (unlikely(!p))
7519 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007520 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007521 p = xdr_inline_decode(xdr, 4);
7522 if (unlikely(!p))
7523 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007524 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007525 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007526 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007527 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007528 }
7529
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007530 p = xdr_inline_decode(xdr, 12);
7531 if (unlikely(!p))
7532 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007533 entry->prev_cookie = entry->cookie;
7534 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007535 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007536
Trond Myklebust9af8c222010-10-24 11:52:55 -04007537 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007538 if (unlikely(!p))
7539 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007540 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007541
7542 /*
7543 * In case the server doesn't return an inode number,
7544 * we fake one here. (We don't use inode number 0,
7545 * since glibc seems to choke on it...)
7546 */
7547 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007548 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007549
Trond Myklebust9af8c222010-10-24 11:52:55 -04007550 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007551 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007552
Trond Myklebust256e48b2012-06-21 11:18:13 -04007553 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007554 goto out_overflow;
7555
Chuck Lever573c4e12010-12-14 14:58:11 +00007556 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007557 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007558 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007559 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7560 entry->ino = entry->fattr->mounted_on_fileid;
7561 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007562 entry->ino = entry->fattr->fileid;
7563
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007564 entry->d_type = DT_UNKNOWN;
7565 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7566 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7567
Chuck Lever573c4e12010-12-14 14:58:11 +00007568 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007569
7570out_overflow:
7571 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007572 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007573}
7574
7575/*
7576 * We need to translate between nfs status return values and
7577 * the local errno values which may not be the same.
7578 */
7579static struct {
7580 int stat;
7581 int errno;
7582} nfs_errtbl[] = {
7583 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007584 { NFS4ERR_PERM, -EPERM },
7585 { NFS4ERR_NOENT, -ENOENT },
7586 { NFS4ERR_IO, -errno_NFSERR_IO},
7587 { NFS4ERR_NXIO, -ENXIO },
7588 { NFS4ERR_ACCESS, -EACCES },
7589 { NFS4ERR_EXIST, -EEXIST },
7590 { NFS4ERR_XDEV, -EXDEV },
7591 { NFS4ERR_NOTDIR, -ENOTDIR },
7592 { NFS4ERR_ISDIR, -EISDIR },
7593 { NFS4ERR_INVAL, -EINVAL },
7594 { NFS4ERR_FBIG, -EFBIG },
7595 { NFS4ERR_NOSPC, -ENOSPC },
7596 { NFS4ERR_ROFS, -EROFS },
7597 { NFS4ERR_MLINK, -EMLINK },
7598 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7599 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7600 { NFS4ERR_DQUOT, -EDQUOT },
7601 { NFS4ERR_STALE, -ESTALE },
7602 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007603 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7604 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7605 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007606 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007607 { NFS4ERR_BADTYPE, -EBADTYPE },
7608 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007609 { NFS4ERR_SYMLINK, -ELOOP },
7610 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7611 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007612 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007613};
7614
7615/*
7616 * Convert an NFS error code to a local one.
7617 * This one is used jointly by NFSv2 and NFSv3.
7618 */
7619static int
David Howells0a8ea432006-08-22 20:06:08 -04007620nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007621{
7622 int i;
7623 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7624 if (nfs_errtbl[i].stat == stat)
7625 return nfs_errtbl[i].errno;
7626 }
7627 if (stat <= 10000 || stat > 10100) {
7628 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007629 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007630 }
7631 /* If we cannot translate the error, the recovery routines should
7632 * handle it.
7633 * Note: remaining NFSv4 error codes have values > 10000, so should
7634 * not conflict with native Linux error codes.
7635 */
Benny Halevy856dff32008-03-31 17:39:06 +03007636 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007637}
7638
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007639#ifdef CONFIG_NFS_V4_2
7640#include "nfs42xdr.c"
7641#endif /* CONFIG_NFS_V4_2 */
7642
Linus Torvalds1da177e2005-04-16 15:20:36 -07007643#define PROC(proc, argtype, restype) \
7644[NFSPROC4_CLNT_##proc] = { \
7645 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007646 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007647 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007648 .p_arglen = NFS4_##argtype##_sz, \
7649 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007650 .p_statidx = NFSPROC4_CLNT_##proc, \
7651 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007652}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007653
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007654#define STUB(proc) \
7655[NFSPROC4_CLNT_##proc] = { \
7656 .p_name = #proc, \
7657}
7658
Trond Myklebust8634ef52018-01-06 09:53:49 -05007659#if defined(CONFIG_NFS_V4_1)
7660#define PROC41(proc, argtype, restype) \
7661 PROC(proc, argtype, restype)
7662#else
7663#define PROC41(proc, argtype, restype) \
7664 STUB(proc)
7665#endif
7666
7667#if defined(CONFIG_NFS_V4_2)
7668#define PROC42(proc, argtype, restype) \
7669 PROC(proc, argtype, restype)
7670#else
7671#define PROC42(proc, argtype, restype) \
7672 STUB(proc)
7673#endif
7674
Christoph Hellwig511e9362017-05-12 15:36:49 +02007675const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007676 PROC(READ, enc_read, dec_read),
7677 PROC(WRITE, enc_write, dec_write),
7678 PROC(COMMIT, enc_commit, dec_commit),
7679 PROC(OPEN, enc_open, dec_open),
7680 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7681 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7682 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7683 PROC(CLOSE, enc_close, dec_close),
7684 PROC(SETATTR, enc_setattr, dec_setattr),
7685 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7686 PROC(RENEW, enc_renew, dec_renew),
7687 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7688 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7689 PROC(LOCK, enc_lock, dec_lock),
7690 PROC(LOCKT, enc_lockt, dec_lockt),
7691 PROC(LOCKU, enc_locku, dec_locku),
7692 PROC(ACCESS, enc_access, dec_access),
7693 PROC(GETATTR, enc_getattr, dec_getattr),
7694 PROC(LOOKUP, enc_lookup, dec_lookup),
7695 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7696 PROC(REMOVE, enc_remove, dec_remove),
7697 PROC(RENAME, enc_rename, dec_rename),
7698 PROC(LINK, enc_link, dec_link),
7699 PROC(SYMLINK, enc_symlink, dec_symlink),
7700 PROC(CREATE, enc_create, dec_create),
7701 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7702 PROC(STATFS, enc_statfs, dec_statfs),
7703 PROC(READLINK, enc_readlink, dec_readlink),
7704 PROC(READDIR, enc_readdir, dec_readdir),
7705 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7706 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7707 PROC(GETACL, enc_getacl, dec_getacl),
7708 PROC(SETACL, enc_setacl, dec_setacl),
7709 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7710 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007711 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007712 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007713 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7714 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7715 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7716 PROC41(SEQUENCE, enc_sequence, dec_sequence),
7717 PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7718 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7719 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7720 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7721 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7722 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7723 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7724 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7725 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007726 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007727 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007728 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007729 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7730 PROC42(SEEK, enc_seek, dec_seek),
7731 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7732 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7733 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7734 PROC42(CLONE, enc_clone, dec_clone),
7735 PROC42(COPY, enc_copy, dec_copy),
7736 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007737};
7738
Christoph Hellwigc5518582017-05-08 23:27:10 +02007739static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007740const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007741 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007742 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007743 .procs = nfs4_procedures,
7744 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007745};
7746
7747/*
7748 * Local variables:
7749 * c-basic-offset: 8
7750 * End:
7751 */