blob: 77c6729e57f0ebfcfa1082c6a399704ea742d22f [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 Myklebust4ade9822012-03-04 18:13:57 -0500961static void encode_nfs4_seqid(struct xdr_stream *xdr,
962 const struct nfs_seqid *seqid)
963{
Trond Myklebusta6796412015-01-23 19:04:44 -0500964 if (seqid != NULL)
965 encode_uint32(xdr, seqid->sequence->counter);
966 else
967 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500968}
969
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400970static void encode_compound_hdr(struct xdr_stream *xdr,
971 struct rpc_rqst *req,
972 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973{
Al Viro8687b632006-10-19 23:28:48 -0700974 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400975 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400976
977 /* initialize running count of expected bytes in reply.
978 * NOTE: the replied tag SHOULD be the same is the one sent,
979 * but this is not required as a MUST for the server to do so. */
980 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Trond Myklebust7fc38842012-10-15 11:51:21 -0400982 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500983 encode_string(xdr, hdr->taglen, hdr->tag);
984 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300985 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500986 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300987 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500988}
989
Trond Myklebustab19b482012-03-04 18:13:57 -0500990static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
991 uint32_t replen,
992 struct compound_hdr *hdr)
993{
994 encode_uint32(xdr, op);
995 hdr->nops++;
996 hdr->replen += replen;
997}
998
Andy Adamsond0179312008-12-23 16:06:17 -0500999static void encode_nops(struct compound_hdr *hdr)
1000{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001001 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001002 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
1004
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001005static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1006{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001007 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001008}
1009
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1011{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001012 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
David Quigleyaa9c2662013-05-22 12:50:44 -04001015static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1016 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001017 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001018 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001019 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020{
1021 char owner_name[IDMAP_NAMESZ];
1022 char owner_group[IDMAP_NAMESZ];
1023 int owner_namelen = 0;
1024 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001025 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001026 unsigned i;
1027 uint32_t len = 0;
1028 uint32_t bmval_len;
1029 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 /*
1032 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001034 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001035 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001037 }
1038 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001039 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001040 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1041 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001042 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001043 bmval[1] |= FATTR4_WORD1_MODE;
1044 len += 4;
1045 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001046 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001047 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001048 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001050 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001051 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 /* XXX */
1053 strcpy(owner_name, "nobody");
1054 owner_namelen = sizeof("nobody") - 1;
1055 /* goto out; */
1056 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001057 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1059 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001060 if ((iap->ia_valid & ATTR_GID) &&
1061 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001062 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001064 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001065 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 strcpy(owner_group, "nobody");
1067 owner_grouplen = sizeof("nobody") - 1;
1068 /* goto out; */
1069 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001070 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1072 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001073 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1074 if (iap->ia_valid & ATTR_ATIME_SET) {
1075 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1076 len += 16;
1077 } else if (iap->ia_valid & ATTR_ATIME) {
1078 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1079 len += 4;
1080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001082 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1083 if (iap->ia_valid & ATTR_MTIME_SET) {
1084 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1085 len += 16;
1086 } else if (iap->ia_valid & ATTR_MTIME) {
1087 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1088 len += 4;
1089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001091
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001092 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001093 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1094 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1095 }
1096
1097 if (bmval[2] != 0)
1098 bmval_len = 3;
1099 else if (bmval[1] != 0)
1100 bmval_len = 2;
1101 else
1102 bmval_len = 1;
1103
1104 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1105
1106 *p++ = cpu_to_be32(bmval_len);
1107 for (i = 0; i < bmval_len; i++)
1108 *p++ = cpu_to_be32(bmval[i]);
1109 *p++ = cpu_to_be32(len);
1110
1111 if (bmval[0] & FATTR4_WORD0_SIZE)
1112 p = xdr_encode_hyper(p, iap->ia_size);
1113 if (bmval[1] & FATTR4_WORD1_MODE)
1114 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1115 if (bmval[1] & FATTR4_WORD1_OWNER)
1116 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1117 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1118 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1119 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1120 if (iap->ia_valid & ATTR_ATIME_SET) {
1121 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1122 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1123 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1124 } else
1125 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1126 }
1127 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1128 if (iap->ia_valid & ATTR_MTIME_SET) {
1129 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1130 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1131 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1132 } else
1133 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1134 }
1135 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001136 *p++ = cpu_to_be32(label->lfs);
1137 *p++ = cpu_to_be32(label->pi);
1138 *p++ = cpu_to_be32(label->len);
1139 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1140 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001141 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1142 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1143 *p++ = cpu_to_be32(*umask);
1144 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147}
1148
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001149static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001151 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1152 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153}
1154
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001155static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156{
Trond Myklebustab19b482012-03-04 18:13:57 -05001157 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001158 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001159 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160}
1161
Fred Isaman0b7c0152012-04-20 14:47:39 -04001162static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Al Viro8687b632006-10-19 23:28:48 -07001164 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001165
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001166 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1167 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001168 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001169 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001172static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
Al Viro8687b632006-10-19 23:28:48 -07001174 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001175
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001176 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1177 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
1179 switch (create->ftype) {
1180 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001181 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001182 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001183 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1184 create->u.symlink.len);
1185 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 break;
1187
1188 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001189 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001190 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001191 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 break;
1193
1194 default:
1195 break;
1196 }
1197
Benny Halevy811652b2009-08-14 17:19:34 +03001198 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001199 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1200 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001203static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204{
Andy Adamson05d564f2008-12-23 16:06:15 -05001205 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001207 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1208 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001209 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001210 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001213static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
Andy Adamson05d564f2008-12-23 16:06:15 -05001215 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001217 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1218 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001219 *p++ = cpu_to_be32(2);
1220 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001221 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222}
1223
Fred Isamandae100c2011-07-30 20:52:37 -04001224static void
1225encode_getattr_three(struct xdr_stream *xdr,
1226 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1227 struct compound_hdr *hdr)
1228{
1229 __be32 *p;
1230
Trond Myklebustab19b482012-03-04 18:13:57 -05001231 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001232 if (bm2) {
1233 p = reserve_space(xdr, 16);
1234 *p++ = cpu_to_be32(3);
1235 *p++ = cpu_to_be32(bm0);
1236 *p++ = cpu_to_be32(bm1);
1237 *p = cpu_to_be32(bm2);
1238 } else if (bm1) {
1239 p = reserve_space(xdr, 12);
1240 *p++ = cpu_to_be32(2);
1241 *p++ = cpu_to_be32(bm0);
1242 *p = cpu_to_be32(bm1);
1243 } else {
1244 p = reserve_space(xdr, 8);
1245 *p++ = cpu_to_be32(1);
1246 *p = cpu_to_be32(bm0);
1247 }
Fred Isamandae100c2011-07-30 20:52:37 -04001248}
1249
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001250static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
David Quigleya09df2c2013-05-22 12:50:41 -04001252 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1253 bitmask[1] & nfs4_fattr_bitmap[1],
1254 bitmask[2] & nfs4_fattr_bitmap[2],
1255 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256}
1257
Andy Adamson88034c32012-05-23 05:02:34 -04001258static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001259 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001260 struct compound_hdr *hdr)
1261{
1262 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001263 bitmask[0] & open_bitmap[0],
1264 bitmask[1] & open_bitmap[1],
1265 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001266 hdr);
1267}
1268
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001269static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Fred Isamandae100c2011-07-30 20:52:37 -04001271 encode_getattr_three(xdr,
1272 bitmask[0] & nfs4_fsinfo_bitmap[0],
1273 bitmask[1] & nfs4_fsinfo_bitmap[1],
1274 bitmask[2] & nfs4_fsinfo_bitmap[2],
1275 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276}
1277
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001278static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001279{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001280 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1281 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001282}
1283
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001284static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285{
Trond Myklebustab19b482012-03-04 18:13:57 -05001286 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287}
1288
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001289static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290{
Trond Myklebustab19b482012-03-04 18:13:57 -05001291 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001292 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293}
1294
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001295static inline int nfs4_lock_type(struct file_lock *fl, int block)
1296{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001297 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001298 return block ? NFS4_READW_LT : NFS4_READ_LT;
1299 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1300}
1301
1302static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1303{
1304 if (fl->fl_end == OFFSET_MAX)
1305 return ~(uint64_t)0;
1306 return fl->fl_end - fl->fl_start + 1;
1307}
1308
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001309static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1310{
1311 __be32 *p;
1312
Trond Myklebustd035c362010-12-21 10:45:27 -05001313 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001314 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001315 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001316 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001317 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001318 xdr_encode_hyper(p, lowner->id);
1319}
1320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321/*
1322 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1323 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1324 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001325static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326{
Al Viro8687b632006-10-19 23:28:48 -07001327 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001329 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1330 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001331 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1332 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001333 p = xdr_encode_hyper(p, args->fl->fl_start);
1334 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001335 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001336 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001337 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001338 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001339 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001340 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
1342 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001343 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001344 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346}
1347
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001348static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Al Viro8687b632006-10-19 23:28:48 -07001350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001352 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1353 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001354 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001355 p = xdr_encode_hyper(p, args->fl->fl_start);
1356 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001357 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
1359
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001360static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
Al Viro8687b632006-10-19 23:28:48 -07001362 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001364 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1365 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001366 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001367 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001368 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001369 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001370 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371}
1372
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001373static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1374{
Trond Myklebustab19b482012-03-04 18:13:57 -05001375 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001376 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001377}
1378
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001379static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380{
Trond Myklebustab19b482012-03-04 18:13:57 -05001381 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001382 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383}
1384
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001385static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1386{
1387 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1388}
1389
Trond Myklebust6ae37332015-01-30 14:21:14 -05001390static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
Al Viro8687b632006-10-19 23:28:48 -07001392 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Benny Halevy13c65ce2009-08-14 17:19:25 +03001394 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001395 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001396 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397}
1398
1399static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1400{
Al Viro8687b632006-10-19 23:28:48 -07001401 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 /*
1403 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1404 * owner 4 = 32
1405 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001406 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001407 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001408 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001409 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001410 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001411 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001412 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001413 *p++ = cpu_to_be32(arg->id.uniquifier);
1414 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415}
1416
1417static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1418{
Al Viro8687b632006-10-19 23:28:48 -07001419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Benny Halevy13c65ce2009-08-14 17:19:25 +03001421 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001422 switch(arg->createmode) {
1423 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001424 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001425 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1426 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001427 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001428 case NFS4_CREATE_GUARDED:
1429 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001430 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1431 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001432 break;
1433 case NFS4_CREATE_EXCLUSIVE:
1434 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1435 encode_nfs4_verifier(xdr, &arg->u.verifier);
1436 break;
1437 case NFS4_CREATE_EXCLUSIVE4_1:
1438 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1439 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001440 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1441 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 }
1443}
1444
1445static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1446{
Al Viro8687b632006-10-19 23:28:48 -07001447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
Benny Halevy13c65ce2009-08-14 17:19:25 +03001449 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001451 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001452 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 break;
1454 default:
Benny Halevy34558512009-08-14 17:19:30 +03001455 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001456 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 }
1458}
1459
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001460static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461{
Al Viro8687b632006-10-19 23:28:48 -07001462 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
Benny Halevy13c65ce2009-08-14 17:19:25 +03001464 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001466 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001467 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001468 break;
1469 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001470 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001471 break;
1472 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001473 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001474 break;
1475 default:
1476 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 }
1478}
1479
1480static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1481{
Al Viro8687b632006-10-19 23:28:48 -07001482 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Benny Halevy13c65ce2009-08-14 17:19:25 +03001484 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001485 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 encode_string(xdr, name->len, name->name);
1487}
1488
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001489static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490{
Al Viro8687b632006-10-19 23:28:48 -07001491 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Benny Halevy13c65ce2009-08-14 17:19:25 +03001493 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001494 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 encode_delegation_type(xdr, type);
1496}
1497
1498static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1499{
Al Viro8687b632006-10-19 23:28:48 -07001500 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001502 p = reserve_space(xdr, 4);
1503 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1504 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 encode_string(xdr, name->len, name->name);
1506}
1507
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001508static inline void encode_claim_fh(struct xdr_stream *xdr)
1509{
1510 __be32 *p;
1511
1512 p = reserve_space(xdr, 4);
1513 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1514}
1515
1516static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1517{
1518 __be32 *p;
1519
1520 p = reserve_space(xdr, 4);
1521 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1522 encode_nfs4_stateid(xdr, stateid);
1523}
1524
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001525static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
Trond Myklebustab19b482012-03-04 18:13:57 -05001527 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 encode_openhdr(xdr, arg);
1529 encode_opentype(xdr, arg);
1530 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001531 case NFS4_OPEN_CLAIM_NULL:
1532 encode_claim_null(xdr, arg->name);
1533 break;
1534 case NFS4_OPEN_CLAIM_PREVIOUS:
1535 encode_claim_previous(xdr, arg->u.delegation_type);
1536 break;
1537 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1538 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1539 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001540 case NFS4_OPEN_CLAIM_FH:
1541 encode_claim_fh(xdr);
1542 break;
1543 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1544 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1545 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001546 default:
1547 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549}
1550
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001551static 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 -07001552{
Trond Myklebustab19b482012-03-04 18:13:57 -05001553 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001554 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001555 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556}
1557
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001558static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
Trond Myklebustab19b482012-03-04 18:13:57 -05001560 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001561 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001562 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001563 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564}
1565
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001566static void
Andy Adamsond0179312008-12-23 16:06:17 -05001567encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568{
Trond Myklebustab19b482012-03-04 18:13:57 -05001569 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001570 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001573static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574{
Trond Myklebustab19b482012-03-04 18:13:57 -05001575 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001578static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1579 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
Al Viro8687b632006-10-19 23:28:48 -07001581 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582
Trond Myklebustab19b482012-03-04 18:13:57 -05001583 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001584 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Benny Halevy13c65ce2009-08-14 17:19:25 +03001586 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001587 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001588 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589}
1590
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001591static 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 -07001592{
David Quigleyaa9c2662013-05-22 12:50:44 -04001593 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001594 FATTR4_WORD0_RDATTR_ERROR,
1595 FATTR4_WORD1_MOUNTED_ON_FILEID,
1596 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001597 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001598 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001599 uint32_t attrlen = 0;
1600 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001602 if (readdir->plus) {
1603 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001604 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001605 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1606 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1607 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1608 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001609 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001610 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001611 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001612 /* Use mounted_on_fileid only if the server supports it */
1613 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1614 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001615 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1616 attrs[i] &= readdir->bitmask[i];
1617 if (attrs[i] != 0)
1618 attrlen = i+1;
1619 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001620
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001621 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001622 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001623 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001624 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001625 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001626 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001627 *p++ = cpu_to_be32(attrlen);
1628 for (i = 0; i < attrlen; i++)
1629 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001630 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001631
1632 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001633 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001634 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001635 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001636 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001637 attrs[1] & readdir->bitmask[1],
1638 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639}
1640
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001641static 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 -07001642{
Trond Myklebustab19b482012-03-04 18:13:57 -05001643 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644}
1645
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001646static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647{
Trond Myklebustab19b482012-03-04 18:13:57 -05001648 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001649 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650}
1651
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001652static 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 -07001653{
Trond Myklebustab19b482012-03-04 18:13:57 -05001654 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001655 encode_string(xdr, oldname->len, oldname->name);
1656 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657}
1658
Chuck Leverbb4dae52012-03-01 17:01:48 -05001659static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1660 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001662 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001663 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664}
1665
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001666static void
Andy Adamsond0179312008-12-23 16:06:17 -05001667encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001668{
Trond Myklebustab19b482012-03-04 18:13:57 -05001669 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001670}
1671
Chuck Lever9f06c712010-12-14 14:59:18 +00001672static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001673encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1674 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001675{
Al Viro8687b632006-10-19 23:28:48 -07001676 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001677
Trond Myklebustab19b482012-03-04 18:13:57 -05001678 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001679 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001680 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001681 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001682 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001683 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001684 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001685 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001686}
1687
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001688static void
Andy Adamsond0179312008-12-23 16:06:17 -05001689encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690{
Trond Myklebustab19b482012-03-04 18:13:57 -05001691 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692}
1693
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001694static 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 -07001695{
Trond Myklebustab19b482012-03-04 18:13:57 -05001696 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001697 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001698 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1699 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001702static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703{
Al Viro8687b632006-10-19 23:28:48 -07001704 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Trond Myklebust70019512012-03-04 20:49:32 -05001706 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001707 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Jeff Layton3a6bb732015-06-09 19:43:57 -04001709 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1710 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001711 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001712 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1714 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001715 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001716 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001719static 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 -07001720{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001721 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1722 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001723 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001724 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725}
1726
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001727static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1728 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
Al Viro8687b632006-10-19 23:28:48 -07001730 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731
Trond Myklebustab19b482012-03-04 18:13:57 -05001732 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001733 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Benny Halevy13c65ce2009-08-14 17:19:25 +03001735 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001736 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001737 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001738 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741}
1742
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001743static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744{
Trond Myklebustab19b482012-03-04 18:13:57 -05001745 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001746 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001748
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001749static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1750{
Trond Myklebustab19b482012-03-04 18:13:57 -05001751 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001752 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001753}
1754
Benny Halevy99fe60d2009-04-01 09:22:29 -04001755#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001756/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001757static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001758 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001759 struct compound_hdr *hdr)
1760{
1761 __be32 *p;
1762
1763 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1764 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001765 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001766 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001767 *p++ = cpu_to_be32(args->dir);
1768 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001769}
1770
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001771static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001772{
1773 unsigned int i;
1774 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1775 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1776 encode_uint32(xdr, op_map->u.words[i]);
1777}
1778
Benny Halevy99fe60d2009-04-01 09:22:29 -04001779static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001780 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001781 struct compound_hdr *hdr)
1782{
1783 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001784 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001785 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001786
Trond Myklebust70019512012-03-04 20:49:32 -05001787 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001788 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001789
Jeff Layton3a6bb732015-06-09 19:43:57 -04001790 encode_string(xdr, strlen(args->client->cl_owner_id),
1791 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001792
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001793 encode_uint32(xdr, args->flags);
1794 encode_uint32(xdr, args->state_protect.how);
1795
1796 switch (args->state_protect.how) {
1797 case SP4_NONE:
1798 break;
1799 case SP4_MACH_CRED:
1800 encode_op_map(xdr, &args->state_protect.enforce);
1801 encode_op_map(xdr, &args->state_protect.allow);
1802 break;
1803 default:
1804 WARN_ON_ONCE(1);
1805 break;
1806 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001807
1808 if (send_implementation_id &&
1809 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1810 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001811 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001812 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1813 utsname()->sysname, utsname()->release,
1814 utsname()->version, utsname()->machine);
1815
1816 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001817 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001818
1819 encode_string(xdr,
1820 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1821 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1822 encode_string(xdr, len, impl_name);
1823 /* just send zeros for nii_date - the date is in nii_name */
1824 p = reserve_space(xdr, 12);
1825 p = xdr_encode_hyper(p, 0);
1826 *p = cpu_to_be32(0);
1827 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001828 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001829}
Andy Adamsonfc931582009-04-01 09:22:31 -04001830
1831static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001832 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001833 struct compound_hdr *hdr)
1834{
1835 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001836 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001837 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001838 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001839 u32 max_resp_sz_cached;
1840
1841 /*
1842 * Assumes OPEN is the biggest non-idempotent compound.
1843 * 2 is the verifier.
1844 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001845 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1846 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001847
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001848 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001849 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001850 p = xdr_encode_hyper(p, args->clientid);
1851 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001852 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001853
Andy Adamsonfc931582009-04-01 09:22:31 -04001854 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001855 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001856 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1857 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001858 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001859 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1860 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1861 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001862
1863 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001864 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001865 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1866 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1867 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1868 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1869 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1870 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001871
Benny Halevye75bc1c2009-08-14 17:18:54 +03001872 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001873 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001874 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001875
1876 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001877 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001878 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001879 *p++ = cpu_to_be32(0); /* UID */
1880 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001881 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001882}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001883
1884static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001885 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001886 struct compound_hdr *hdr)
1887{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001888 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1889 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001890}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001891
Trond Myklebust66245532012-05-25 17:18:09 -04001892static void encode_destroy_clientid(struct xdr_stream *xdr,
1893 uint64_t clientid,
1894 struct compound_hdr *hdr)
1895{
1896 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1897 encode_uint64(xdr, clientid);
1898}
1899
Ricardo Labiaga180197532009-12-05 16:08:40 -05001900static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001901 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001902 struct compound_hdr *hdr)
1903{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001904 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1905 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001906}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001907#endif /* CONFIG_NFS_V4_1 */
1908
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001909static void encode_sequence(struct xdr_stream *xdr,
1910 const struct nfs4_sequence_args *args,
1911 struct compound_hdr *hdr)
1912{
1913#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001914 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001915 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001916 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001917 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001918
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001919 tp = slot->table;
1920 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001921 if (!session)
1922 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001923
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001924 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001925
1926 /*
1927 * Sessionid + seqid + slotid + max slotid + cache_this
1928 */
1929 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1930 "max_slotid=%d cache_this=%d\n",
1931 __func__,
1932 ((u32 *)session->sess_id.data)[0],
1933 ((u32 *)session->sess_id.data)[1],
1934 ((u32 *)session->sess_id.data)[2],
1935 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001936 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001937 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001938 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001939 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001940 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001941 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001942 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001943 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001944#endif /* CONFIG_NFS_V4_1 */
1945}
1946
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001947#ifdef CONFIG_NFS_V4_1
1948static void
1949encode_getdeviceinfo(struct xdr_stream *xdr,
1950 const struct nfs4_getdeviceinfo_args *args,
1951 struct compound_hdr *hdr)
1952{
1953 __be32 *p;
1954
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001955 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001956 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001957 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1958 NFS4_DEVICEID4_SIZE);
1959 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001960 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001961
1962 p = reserve_space(xdr, 4 + 4);
1963 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001964 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001965}
1966
1967static void
1968encode_layoutget(struct xdr_stream *xdr,
1969 const struct nfs4_layoutget_args *args,
1970 struct compound_hdr *hdr)
1971{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001972 __be32 *p;
1973
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001974 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1975 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001976 *p++ = cpu_to_be32(0); /* Signal layout available */
1977 *p++ = cpu_to_be32(args->type);
1978 *p++ = cpu_to_be32(args->range.iomode);
1979 p = xdr_encode_hyper(p, args->range.offset);
1980 p = xdr_encode_hyper(p, args->range.length);
1981 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001982 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001983 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001984
1985 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1986 __func__,
1987 args->type,
1988 args->range.iomode,
1989 (unsigned long)args->range.offset,
1990 (unsigned long)args->range.length,
1991 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001992}
Andy Adamson863a3c62011-03-23 13:27:54 +00001993
1994static int
1995encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001996 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001997 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001998 struct compound_hdr *hdr)
1999{
2000 __be32 *p;
2001
2002 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
2003 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
2004
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002005 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
2006 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00002007 /* Only whole file layouts */
2008 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04002009 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002010 *p = cpu_to_be32(0); /* reclaim */
2011 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04002012 if (args->lastbytewritten != U64_MAX) {
2013 p = reserve_space(xdr, 20);
2014 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2015 p = xdr_encode_hyper(p, args->lastbytewritten);
2016 } else {
2017 p = reserve_space(xdr, 12);
2018 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2019 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002020 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2021 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002022
Trond Myklebust73504742017-04-20 16:48:14 -04002023 encode_uint32(xdr, args->layoutupdate_len);
2024 if (args->layoutupdate_pages)
2025 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2026 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002027
Andy Adamson863a3c62011-03-23 13:27:54 +00002028 return 0;
2029}
Benny Halevycbe82602011-05-22 19:52:37 +03002030
2031static void
2032encode_layoutreturn(struct xdr_stream *xdr,
2033 const struct nfs4_layoutreturn_args *args,
2034 struct compound_hdr *hdr)
2035{
2036 __be32 *p;
2037
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002038 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2039 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002040 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2041 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002042 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002043 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002044 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002045 p = xdr_encode_hyper(p, args->range.offset);
2046 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002047 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002048 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002049 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002050 if (args->ld_private->ops && args->ld_private->ops->encode)
2051 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002052 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002053 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002054}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002055
2056static int
2057encode_secinfo_no_name(struct xdr_stream *xdr,
2058 const struct nfs41_secinfo_no_name_args *args,
2059 struct compound_hdr *hdr)
2060{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002061 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2062 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002063 return 0;
2064}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002065
2066static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002067 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002068 struct compound_hdr *hdr)
2069{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002070 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2071 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002072 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002073}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002074
2075static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002076 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002077 struct compound_hdr *hdr)
2078{
Trond Myklebustab19b482012-03-04 18:13:57 -05002079 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002080 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002081}
Trond Myklebustcf805162016-11-15 14:56:07 -05002082#else
2083static inline void
2084encode_layoutreturn(struct xdr_stream *xdr,
2085 const struct nfs4_layoutreturn_args *args,
2086 struct compound_hdr *hdr)
2087{
2088}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002089#endif /* CONFIG_NFS_V4_1 */
2090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091/*
2092 * END OF "GENERIC" ENCODE ROUTINES.
2093 */
2094
Benny Halevy66cc0422009-04-01 09:22:10 -04002095static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2096{
2097#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002098 struct nfs4_session *session = args->sa_slot->table->session;
2099 if (session)
2100 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002101#endif /* CONFIG_NFS_V4_1 */
2102 return 0;
2103}
2104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105/*
2106 * Encode an ACCESS request
2107 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002108static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002109 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002111 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002113 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Chuck Lever9f06c712010-12-14 14:59:18 +00002116 encode_compound_hdr(xdr, req, &hdr);
2117 encode_sequence(xdr, &args->seq_args, &hdr);
2118 encode_putfh(xdr, args->fh, &hdr);
2119 encode_access(xdr, args->access, &hdr);
2120 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002121 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122}
2123
2124/*
2125 * Encode LOOKUP request
2126 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002127static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002128 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002130 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002132 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134
Chuck Lever9f06c712010-12-14 14:59:18 +00002135 encode_compound_hdr(xdr, req, &hdr);
2136 encode_sequence(xdr, &args->seq_args, &hdr);
2137 encode_putfh(xdr, args->dir_fh, &hdr);
2138 encode_lookup(xdr, args->name, &hdr);
2139 encode_getfh(xdr, &hdr);
2140 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002141 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142}
2143
2144/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002145 * Encode LOOKUPP request
2146 */
2147static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2148 const void *data)
2149{
2150 const struct nfs4_lookupp_arg *args = data;
2151 struct compound_hdr hdr = {
2152 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2153 };
2154
2155 encode_compound_hdr(xdr, req, &hdr);
2156 encode_sequence(xdr, &args->seq_args, &hdr);
2157 encode_putfh(xdr, args->fh, &hdr);
2158 encode_lookupp(xdr, &hdr);
2159 encode_getfh(xdr, &hdr);
2160 encode_getfattr(xdr, args->bitmask, &hdr);
2161 encode_nops(&hdr);
2162}
2163
2164/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 * Encode LOOKUP_ROOT request
2166 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002167static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2168 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002169 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002171 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002173 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
Chuck Lever9f06c712010-12-14 14:59:18 +00002176 encode_compound_hdr(xdr, req, &hdr);
2177 encode_sequence(xdr, &args->seq_args, &hdr);
2178 encode_putrootfh(xdr, &hdr);
2179 encode_getfh(xdr, &hdr);
2180 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002181 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182}
2183
2184/*
2185 * Encode REMOVE request
2186 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002187static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002188 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002190 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002192 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Chuck Lever9f06c712010-12-14 14:59:18 +00002195 encode_compound_hdr(xdr, req, &hdr);
2196 encode_sequence(xdr, &args->seq_args, &hdr);
2197 encode_putfh(xdr, args->fh, &hdr);
2198 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002199 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200}
2201
2202/*
2203 * Encode RENAME request
2204 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002205static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002206 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002208 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->old_dir, &hdr);
2216 encode_savefh(xdr, &hdr);
2217 encode_putfh(xdr, args->new_dir, &hdr);
2218 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002219 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220}
2221
2222/*
2223 * Encode LINK request
2224 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002225static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002226 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002228 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002230 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
Chuck Lever9f06c712010-12-14 14:59:18 +00002233 encode_compound_hdr(xdr, req, &hdr);
2234 encode_sequence(xdr, &args->seq_args, &hdr);
2235 encode_putfh(xdr, args->fh, &hdr);
2236 encode_savefh(xdr, &hdr);
2237 encode_putfh(xdr, args->dir_fh, &hdr);
2238 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002239 encode_restorefh(xdr, &hdr);
2240 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002241 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242}
2243
2244/*
2245 * Encode CREATE request
2246 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002247static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002248 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002250 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002252 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Chuck Lever9f06c712010-12-14 14:59:18 +00002255 encode_compound_hdr(xdr, req, &hdr);
2256 encode_sequence(xdr, &args->seq_args, &hdr);
2257 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_create(xdr, args, &hdr);
2259 encode_getfh(xdr, &hdr);
2260 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002261 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262}
2263
2264/*
2265 * Encode SYMLINK request
2266 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002267static void nfs4_xdr_enc_symlink(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_create_arg *args = data;
2271
Chuck Lever9f06c712010-12-14 14:59:18 +00002272 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
2275/*
2276 * Encode GETATTR request
2277 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002278static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002279 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002281 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002283 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
Chuck Lever9f06c712010-12-14 14:59:18 +00002286 encode_compound_hdr(xdr, req, &hdr);
2287 encode_sequence(xdr, &args->seq_args, &hdr);
2288 encode_putfh(xdr, args->fh, &hdr);
2289 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002290 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291}
2292
2293/*
2294 * Encode a CLOSE request
2295 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002296static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002297 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002299 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002300 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002301 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002302 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
Chuck Lever9f06c712010-12-14 14:59:18 +00002304 encode_compound_hdr(xdr, req, &hdr);
2305 encode_sequence(xdr, &args->seq_args, &hdr);
2306 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002307 if (args->lr_args)
2308 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002309 if (args->bitmask != NULL)
2310 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002311 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002312 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313}
2314
2315/*
2316 * Encode an OPEN request
2317 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002318static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002319 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002321 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002323 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Chuck Lever9f06c712010-12-14 14:59:18 +00002326 encode_compound_hdr(xdr, req, &hdr);
2327 encode_sequence(xdr, &args->seq_args, &hdr);
2328 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002329 encode_open(xdr, args, &hdr);
2330 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002331 if (args->access)
2332 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002333 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002334 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335}
2336
2337/*
2338 * Encode an OPEN_CONFIRM request
2339 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002340static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2341 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002342 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002344 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002346 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
Chuck Lever9f06c712010-12-14 14:59:18 +00002349 encode_compound_hdr(xdr, req, &hdr);
2350 encode_putfh(xdr, args->fh, &hdr);
2351 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002352 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353}
2354
2355/*
2356 * Encode an OPEN request with no attributes.
2357 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002358static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2359 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002360 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002362 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002364 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Chuck Lever9f06c712010-12-14 14:59:18 +00002367 encode_compound_hdr(xdr, req, &hdr);
2368 encode_sequence(xdr, &args->seq_args, &hdr);
2369 encode_putfh(xdr, args->fh, &hdr);
2370 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002371 if (args->access)
2372 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002373 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002374 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375}
2376
2377/*
2378 * Encode an OPEN_DOWNGRADE request
2379 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002380static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2381 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002382 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002384 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002386 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
Chuck Lever9f06c712010-12-14 14:59:18 +00002389 encode_compound_hdr(xdr, req, &hdr);
2390 encode_sequence(xdr, &args->seq_args, &hdr);
2391 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002392 if (args->lr_args)
2393 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002394 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002395 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396}
2397
2398/*
2399 * Encode a LOCK request
2400 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002401static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002402 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002404 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002406 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Chuck Lever9f06c712010-12-14 14:59:18 +00002409 encode_compound_hdr(xdr, req, &hdr);
2410 encode_sequence(xdr, &args->seq_args, &hdr);
2411 encode_putfh(xdr, args->fh, &hdr);
2412 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002413 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414}
2415
2416/*
2417 * Encode a LOCKT request
2418 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002419static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002420 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002422 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002424 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
Chuck Lever9f06c712010-12-14 14:59:18 +00002427 encode_compound_hdr(xdr, req, &hdr);
2428 encode_sequence(xdr, &args->seq_args, &hdr);
2429 encode_putfh(xdr, args->fh, &hdr);
2430 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002431 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432}
2433
2434/*
2435 * Encode a LOCKU request
2436 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002437static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002438 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002440 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002442 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
Chuck Lever9f06c712010-12-14 14:59:18 +00002445 encode_compound_hdr(xdr, req, &hdr);
2446 encode_sequence(xdr, &args->seq_args, &hdr);
2447 encode_putfh(xdr, args->fh, &hdr);
2448 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002449 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450}
2451
Chuck Lever9f06c712010-12-14 14:59:18 +00002452static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2453 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002454 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002455{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002456 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002457 struct compound_hdr hdr = {
2458 .minorversion = 0,
2459 };
2460
Chuck Lever9f06c712010-12-14 14:59:18 +00002461 encode_compound_hdr(xdr, req, &hdr);
2462 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002463 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002464}
2465
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466/*
2467 * Encode a READLINK request
2468 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002469static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002470 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002472 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002474 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Chuck Lever9f06c712010-12-14 14:59:18 +00002477 encode_compound_hdr(xdr, req, &hdr);
2478 encode_sequence(xdr, &args->seq_args, &hdr);
2479 encode_putfh(xdr, args->fh, &hdr);
2480 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002481
Benny Halevy28f56692009-04-01 09:22:09 -04002482 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002483 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002484 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485}
2486
2487/*
2488 * Encode a READDIR request
2489 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002490static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002491 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002493 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002495 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
Chuck Lever9f06c712010-12-14 14:59:18 +00002498 encode_compound_hdr(xdr, req, &hdr);
2499 encode_sequence(xdr, &args->seq_args, &hdr);
2500 encode_putfh(xdr, args->fh, &hdr);
2501 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002502
Benny Halevy28f56692009-04-01 09:22:09 -04002503 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002504 args->pgbase, args->count);
2505 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002506 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002507 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002508 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509}
2510
2511/*
2512 * Encode a READ request
2513 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002514static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002515 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002517 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002519 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Chuck Lever9f06c712010-12-14 14:59:18 +00002522 encode_compound_hdr(xdr, req, &hdr);
2523 encode_sequence(xdr, &args->seq_args, &hdr);
2524 encode_putfh(xdr, args->fh, &hdr);
2525 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
Benny Halevy28f56692009-04-01 09:22:09 -04002527 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002529 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002530 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531}
2532
2533/*
2534 * Encode an SETATTR request
2535 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002536static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002537 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002539 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002540 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002541 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002542 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
Chuck Lever9f06c712010-12-14 14:59:18 +00002544 encode_compound_hdr(xdr, req, &hdr);
2545 encode_sequence(xdr, &args->seq_args, &hdr);
2546 encode_putfh(xdr, args->fh, &hdr);
2547 encode_setattr(xdr, args, args->server, &hdr);
2548 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002549 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550}
2551
2552/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002553 * Encode a GETACL request
2554 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002555static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002556 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002557{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002558 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002559 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002560 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002561 };
Benny Halevy28f56692009-04-01 09:22:09 -04002562 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002563
Chuck Lever9f06c712010-12-14 14:59:18 +00002564 encode_compound_hdr(xdr, req, &hdr);
2565 encode_sequence(xdr, &args->seq_args, &hdr);
2566 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002567 replen = hdr.replen + op_decode_hdr_maxsz;
Chuck Lever9f06c712010-12-14 14:59:18 +00002568 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002569
Benny Halevy28f56692009-04-01 09:22:09 -04002570 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002571 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002572
Andy Adamsond0179312008-12-23 16:06:17 -05002573 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002574}
2575
2576/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 * Encode a WRITE request
2578 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002579static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002580 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002582 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002584 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586
Chuck Lever9f06c712010-12-14 14:59:18 +00002587 encode_compound_hdr(xdr, req, &hdr);
2588 encode_sequence(xdr, &args->seq_args, &hdr);
2589 encode_putfh(xdr, args->fh, &hdr);
2590 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002591 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002592 if (args->bitmask)
2593 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002594 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595}
2596
2597/*
2598 * a COMMIT request
2599 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002600static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002601 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002603 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002605 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607
Chuck Lever9f06c712010-12-14 14:59:18 +00002608 encode_compound_hdr(xdr, req, &hdr);
2609 encode_sequence(xdr, &args->seq_args, &hdr);
2610 encode_putfh(xdr, args->fh, &hdr);
2611 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002612 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613}
2614
2615/*
2616 * FSINFO request
2617 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002618static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002619 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002621 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002623 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
Chuck Lever9f06c712010-12-14 14:59:18 +00002626 encode_compound_hdr(xdr, req, &hdr);
2627 encode_sequence(xdr, &args->seq_args, &hdr);
2628 encode_putfh(xdr, args->fh, &hdr);
2629 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002630 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631}
2632
2633/*
2634 * a PATHCONF request
2635 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002636static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002637 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002639 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002641 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643
Chuck Lever9f06c712010-12-14 14:59:18 +00002644 encode_compound_hdr(xdr, req, &hdr);
2645 encode_sequence(xdr, &args->seq_args, &hdr);
2646 encode_putfh(xdr, args->fh, &hdr);
2647 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002648 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002649 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650}
2651
2652/*
2653 * a STATFS request
2654 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002655static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002656 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002658 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002660 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Chuck Lever9f06c712010-12-14 14:59:18 +00002663 encode_compound_hdr(xdr, req, &hdr);
2664 encode_sequence(xdr, &args->seq_args, &hdr);
2665 encode_putfh(xdr, args->fh, &hdr);
2666 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002667 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002668 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669}
2670
2671/*
2672 * GETATTR_BITMAP request
2673 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002674static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2675 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002676 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002678 const struct nfs4_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002679 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
Chuck Lever9f06c712010-12-14 14:59:18 +00002684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_sequence(xdr, &args->seq_args, &hdr);
2686 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002687 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002688 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689}
2690
2691/*
2692 * a RENEW request
2693 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002694static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002695 const void *data)
2696
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002698 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002700 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 };
2702
Chuck Lever9f06c712010-12-14 14:59:18 +00002703 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002704 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002705 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706}
2707
2708/*
2709 * a SETCLIENTID request
2710 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002711static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2712 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002713 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002715 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002717 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 };
2719
Chuck Lever9f06c712010-12-14 14:59:18 +00002720 encode_compound_hdr(xdr, req, &hdr);
2721 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002722 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723}
2724
2725/*
2726 * a SETCLIENTID_CONFIRM request
2727 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002728static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2729 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002730 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002732 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002734 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
Chuck Lever9f06c712010-12-14 14:59:18 +00002737 encode_compound_hdr(xdr, req, &hdr);
2738 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002739 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740}
2741
2742/*
2743 * DELEGRETURN request
2744 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002745static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2746 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002747 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002749 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002751 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
Chuck Lever9f06c712010-12-14 14:59:18 +00002754 encode_compound_hdr(xdr, req, &hdr);
2755 encode_sequence(xdr, &args->seq_args, &hdr);
2756 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002757 if (args->lr_args)
2758 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002759 if (args->bitmask)
2760 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002761 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002762 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763}
2764
2765/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002766 * Encode FS_LOCATIONS request
2767 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002768static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2769 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002770 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002771{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002772 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002773 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002774 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002775 };
Benny Halevy28f56692009-04-01 09:22:09 -04002776 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002777
Chuck Lever9f06c712010-12-14 14:59:18 +00002778 encode_compound_hdr(xdr, req, &hdr);
2779 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002780 if (args->migration) {
2781 encode_putfh(xdr, args->fh, &hdr);
2782 replen = hdr.replen;
2783 encode_fs_locations(xdr, args->bitmask, &hdr);
2784 if (args->renew)
2785 encode_renew(xdr, args->clientid, &hdr);
2786 } else {
2787 encode_putfh(xdr, args->dir_fh, &hdr);
2788 encode_lookup(xdr, args->name, &hdr);
2789 replen = hdr.replen;
2790 encode_fs_locations(xdr, args->bitmask, &hdr);
2791 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002792
Chuck Leverb03d7352013-10-17 14:12:50 -04002793 /* Set up reply kvec to capture returned fs_locations array. */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002794 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2795 (struct page **)&args->page, 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002796 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002797}
2798
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002799/*
2800 * Encode SECINFO request
2801 */
2802static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002804 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002805{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002806 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002807 struct compound_hdr hdr = {
2808 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2809 };
2810
2811 encode_compound_hdr(xdr, req, &hdr);
2812 encode_sequence(xdr, &args->seq_args, &hdr);
2813 encode_putfh(xdr, args->dir_fh, &hdr);
2814 encode_secinfo(xdr, args->name, &hdr);
2815 encode_nops(&hdr);
2816}
2817
Chuck Lever44c99932013-10-17 14:13:30 -04002818/*
2819 * Encode FSID_PRESENT request
2820 */
2821static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2822 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002823 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002824{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002825 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002826 struct compound_hdr hdr = {
2827 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2828 };
2829
2830 encode_compound_hdr(xdr, req, &hdr);
2831 encode_sequence(xdr, &args->seq_args, &hdr);
2832 encode_putfh(xdr, args->fh, &hdr);
2833 encode_getfh(xdr, &hdr);
2834 if (args->renew)
2835 encode_renew(xdr, args->clientid, &hdr);
2836 encode_nops(&hdr);
2837}
2838
Benny Halevy99fe60d2009-04-01 09:22:29 -04002839#if defined(CONFIG_NFS_V4_1)
2840/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002841 * BIND_CONN_TO_SESSION request
2842 */
2843static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2844 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002845 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002846{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002847 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002848 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002849 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002850 };
2851
2852 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002853 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002854 encode_nops(&hdr);
2855}
2856
2857/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002858 * EXCHANGE_ID request
2859 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002860static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2861 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002862 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002863{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002864 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002865 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002866 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002867 };
2868
Chuck Lever9f06c712010-12-14 14:59:18 +00002869 encode_compound_hdr(xdr, req, &hdr);
2870 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002871 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002872}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002873
2874/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002875 * a CREATE_SESSION request
2876 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002877static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2878 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002879 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002880{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002881 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002882 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002883 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002884 };
2885
Chuck Lever9f06c712010-12-14 14:59:18 +00002886 encode_compound_hdr(xdr, req, &hdr);
2887 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002888 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002889}
2890
2891/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002892 * a DESTROY_SESSION request
2893 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002894static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2895 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002896 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002897{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002898 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002899 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002900 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002901 };
2902
Chuck Lever9f06c712010-12-14 14:59:18 +00002903 encode_compound_hdr(xdr, req, &hdr);
2904 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002905 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002906}
2907
2908/*
Trond Myklebust66245532012-05-25 17:18:09 -04002909 * a DESTROY_CLIENTID request
2910 */
2911static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2912 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002913 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002914{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002915 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002916 struct compound_hdr hdr = {
2917 .minorversion = clp->cl_mvops->minor_version,
2918 };
2919
2920 encode_compound_hdr(xdr, req, &hdr);
2921 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2922 encode_nops(&hdr);
2923}
2924
2925/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002926 * a SEQUENCE request
2927 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002928static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002929 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002930{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002931 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002932 struct compound_hdr hdr = {
2933 .minorversion = nfs4_xdr_minorversion(args),
2934 };
2935
Chuck Lever9f06c712010-12-14 14:59:18 +00002936 encode_compound_hdr(xdr, req, &hdr);
2937 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002938 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002939}
2940
2941/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002942 * a GET_LEASE_TIME request
2943 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002944static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2945 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002946 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002947{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002948 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002949 struct compound_hdr hdr = {
2950 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2951 };
Fred Isamandae100c2011-07-30 20:52:37 -04002952 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002953
Chuck Lever9f06c712010-12-14 14:59:18 +00002954 encode_compound_hdr(xdr, req, &hdr);
2955 encode_sequence(xdr, &args->la_seq_args, &hdr);
2956 encode_putrootfh(xdr, &hdr);
2957 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002958 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002959}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002960
2961/*
2962 * a RECLAIM_COMPLETE request
2963 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002964static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2965 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002966 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002967{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002968 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002969 struct compound_hdr hdr = {
2970 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2971 };
2972
Chuck Lever9f06c712010-12-14 14:59:18 +00002973 encode_compound_hdr(xdr, req, &hdr);
2974 encode_sequence(xdr, &args->seq_args, &hdr);
2975 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002976 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002977}
2978
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002979/*
2980 * Encode GETDEVICEINFO request
2981 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002982static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2983 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002984 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002985{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002986 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002987 struct compound_hdr hdr = {
2988 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2989 };
2990
Chuck Lever9f06c712010-12-14 14:59:18 +00002991 encode_compound_hdr(xdr, req, &hdr);
2992 encode_sequence(xdr, &args->seq_args, &hdr);
2993 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002994
2995 /* set up reply kvec. Subtract notification bitmap max size (2)
2996 * so that notification bitmap is put in xdr_buf tail */
2997 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2998 args->pdev->pages, args->pdev->pgbase,
2999 args->pdev->pglen);
3000
3001 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003002}
3003
3004/*
3005 * Encode LAYOUTGET request
3006 */
Chuck Lever9f06c712010-12-14 14:59:18 +00003007static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
3008 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003009 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003010{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003011 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003012 struct compound_hdr hdr = {
3013 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3014 };
3015
Chuck Lever9f06c712010-12-14 14:59:18 +00003016 encode_compound_hdr(xdr, req, &hdr);
3017 encode_sequence(xdr, &args->seq_args, &hdr);
3018 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3019 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003020
3021 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
3022 args->layout.pages, 0, args->layout.pglen);
3023
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003024 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003025}
Andy Adamson863a3c62011-03-23 13:27:54 +00003026
3027/*
3028 * Encode LAYOUTCOMMIT request
3029 */
Benny Halevycbe82602011-05-22 19:52:37 +03003030static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3031 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003032 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003033{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003034 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003035 struct nfs4_layoutcommit_data *data =
3036 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003037 struct compound_hdr hdr = {
3038 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3039 };
3040
3041 encode_compound_hdr(xdr, req, &hdr);
3042 encode_sequence(xdr, &args->seq_args, &hdr);
3043 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003044 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003045 encode_getfattr(xdr, args->bitmask, &hdr);
3046 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003047}
3048
3049/*
3050 * Encode LAYOUTRETURN request
3051 */
3052static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3053 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003054 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003055{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003056 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003057 struct compound_hdr hdr = {
3058 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3059 };
3060
3061 encode_compound_hdr(xdr, req, &hdr);
3062 encode_sequence(xdr, &args->seq_args, &hdr);
3063 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
3064 encode_layoutreturn(xdr, args, &hdr);
3065 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003066}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003067
3068/*
3069 * Encode SECINFO_NO_NAME request
3070 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003071static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003072 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003073 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003074{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003075 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003076 struct compound_hdr hdr = {
3077 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3078 };
3079
3080 encode_compound_hdr(xdr, req, &hdr);
3081 encode_sequence(xdr, &args->seq_args, &hdr);
3082 encode_putrootfh(xdr, &hdr);
3083 encode_secinfo_no_name(xdr, args, &hdr);
3084 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003085}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003086
3087/*
3088 * Encode TEST_STATEID request
3089 */
3090static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3091 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003092 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003093{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003094 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003095 struct compound_hdr hdr = {
3096 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3097 };
3098
3099 encode_compound_hdr(xdr, req, &hdr);
3100 encode_sequence(xdr, &args->seq_args, &hdr);
3101 encode_test_stateid(xdr, args, &hdr);
3102 encode_nops(&hdr);
3103}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003104
3105/*
3106 * Encode FREE_STATEID request
3107 */
3108static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3109 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003110 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003111{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003112 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003113 struct compound_hdr hdr = {
3114 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3115 };
3116
3117 encode_compound_hdr(xdr, req, &hdr);
3118 encode_sequence(xdr, &args->seq_args, &hdr);
3119 encode_free_stateid(xdr, args, &hdr);
3120 encode_nops(&hdr);
3121}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003122#endif /* CONFIG_NFS_V4_1 */
3123
Benny Halevy686841b2009-08-14 17:19:48 +03003124static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3125{
3126 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3127 "Remaining buffer length is %tu words.\n",
3128 func, xdr->end - xdr->p);
3129}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130
Trond Myklebust683b57b2006-06-09 09:34:22 -04003131static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003133 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3134 NFS4_OPAQUE_LIMIT);
3135 if (unlikely(ret < 0)) {
3136 if (ret == -EBADMSG)
3137 print_overflow_msg(__func__, xdr);
3138 return -EIO;
3139 }
3140 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 return 0;
3142}
3143
3144static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3145{
Al Viro8687b632006-10-19 23:28:48 -07003146 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147
Benny Halevyc0eae662009-08-14 17:20:14 +03003148 p = xdr_inline_decode(xdr, 8);
3149 if (unlikely(!p))
3150 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003151 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003152 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003153
Benny Halevyc0eae662009-08-14 17:20:14 +03003154 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3155 if (unlikely(!p))
3156 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 hdr->tag = (char *)p;
3158 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003159 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003160 if (unlikely(hdr->nops < 1))
3161 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003163out_overflow:
3164 print_overflow_msg(__func__, xdr);
3165 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166}
3167
Trond Myklebustc7848f62013-12-04 17:39:23 -05003168static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3169 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170{
Al Viro8687b632006-10-19 23:28:48 -07003171 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 uint32_t opnum;
3173 int32_t nfserr;
3174
Benny Halevyc0eae662009-08-14 17:20:14 +03003175 p = xdr_inline_decode(xdr, 8);
3176 if (unlikely(!p))
3177 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003178 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003179 if (unlikely(opnum != expected))
3180 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003181 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003182 if (nfserr == NFS_OK)
3183 *nfs_retval = 0;
3184 else
3185 *nfs_retval = nfs4_stat_to_errno(nfserr);
3186 return true;
3187out_bad_operation:
3188 dprintk("nfs: Server returned operation"
3189 " %d but we issued a request for %d\n",
3190 opnum, expected);
3191 *nfs_retval = -EREMOTEIO;
3192 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003193out_overflow:
3194 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003195 *nfs_retval = -EIO;
3196 return false;
3197}
3198
3199static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3200{
3201 int retval;
3202
3203 __decode_op_hdr(xdr, expected, &retval);
3204 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205}
3206
3207/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003208static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209{
Al Viro8687b632006-10-19 23:28:48 -07003210 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003211 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 char *str;
3213
Benny Halevyc0eae662009-08-14 17:20:14 +03003214 p = xdr_inline_decode(xdr, 12);
3215 if (likely(p))
3216 return decode_opaque_inline(xdr, &strlen, &str);
3217 print_overflow_msg(__func__, xdr);
3218 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219}
3220
3221static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3222{
Al Viro8687b632006-10-19 23:28:48 -07003223 uint32_t bmlen;
3224 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
Benny Halevyc0eae662009-08-14 17:20:14 +03003226 p = xdr_inline_decode(xdr, 4);
3227 if (unlikely(!p))
3228 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003229 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
Fred Isamandae100c2011-07-30 20:52:37 -04003231 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003232 p = xdr_inline_decode(xdr, (bmlen << 2));
3233 if (unlikely(!p))
3234 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003236 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003237 if (bmlen > 1) {
3238 bitmap[1] = be32_to_cpup(p++);
3239 if (bmlen > 2)
3240 bitmap[2] = be32_to_cpup(p);
3241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 }
3243 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003244out_overflow:
3245 print_overflow_msg(__func__, xdr);
3246 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247}
3248
Trond Myklebust256e48b2012-06-21 11:18:13 -04003249static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250{
Al Viro8687b632006-10-19 23:28:48 -07003251 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
Benny Halevyc0eae662009-08-14 17:20:14 +03003253 p = xdr_inline_decode(xdr, 4);
3254 if (unlikely(!p))
3255 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003256 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003257 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003259out_overflow:
3260 print_overflow_msg(__func__, xdr);
3261 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262}
3263
3264static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3265{
3266 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003267 int ret;
3268 ret = decode_attr_bitmap(xdr, bitmask);
3269 if (unlikely(ret < 0))
3270 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3272 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003273 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3274 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3275 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 return 0;
3277}
3278
3279static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3280{
Al Viro8687b632006-10-19 23:28:48 -07003281 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003282 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
3284 *type = 0;
3285 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3286 return -EIO;
3287 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003288 p = xdr_inline_decode(xdr, 4);
3289 if (unlikely(!p))
3290 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003291 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003293 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 return -EIO;
3295 }
3296 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003297 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003299 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003300 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003301out_overflow:
3302 print_overflow_msg(__func__, xdr);
3303 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304}
3305
Chuck Lever264e6352012-03-01 17:02:05 -05003306static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3307 uint32_t *bitmap, uint32_t *type)
3308{
3309 __be32 *p;
3310
3311 *type = 0;
3312 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3313 return -EIO;
3314 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3315 p = xdr_inline_decode(xdr, 4);
3316 if (unlikely(!p))
3317 goto out_overflow;
3318 *type = be32_to_cpup(p);
3319 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3320 }
3321 dprintk("%s: expire type=0x%x\n", __func__, *type);
3322 return 0;
3323out_overflow:
3324 print_overflow_msg(__func__, xdr);
3325 return -EIO;
3326}
3327
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3329{
Al Viro8687b632006-10-19 23:28:48 -07003330 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003331 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332
3333 *change = 0;
3334 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3335 return -EIO;
3336 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003337 p = xdr_inline_decode(xdr, 8);
3338 if (unlikely(!p))
3339 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003340 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003342 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003344 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003346 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003347out_overflow:
3348 print_overflow_msg(__func__, xdr);
3349 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350}
3351
3352static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3353{
Al Viro8687b632006-10-19 23:28:48 -07003354 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003355 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356
3357 *size = 0;
3358 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3359 return -EIO;
3360 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003361 p = xdr_inline_decode(xdr, 8);
3362 if (unlikely(!p))
3363 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003364 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003366 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003368 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003369 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003370out_overflow:
3371 print_overflow_msg(__func__, xdr);
3372 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373}
3374
3375static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3376{
Al Viro8687b632006-10-19 23:28:48 -07003377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378
3379 *res = 0;
3380 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3381 return -EIO;
3382 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003383 p = xdr_inline_decode(xdr, 4);
3384 if (unlikely(!p))
3385 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003386 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3388 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003389 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003391out_overflow:
3392 print_overflow_msg(__func__, xdr);
3393 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394}
3395
3396static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3397{
Al Viro8687b632006-10-19 23:28:48 -07003398 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399
3400 *res = 0;
3401 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3402 return -EIO;
3403 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003404 p = xdr_inline_decode(xdr, 4);
3405 if (unlikely(!p))
3406 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003407 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3409 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003410 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003412out_overflow:
3413 print_overflow_msg(__func__, xdr);
3414 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415}
3416
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003417static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418{
Al Viro8687b632006-10-19 23:28:48 -07003419 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003420 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421
3422 fsid->major = 0;
3423 fsid->minor = 0;
3424 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3425 return -EIO;
3426 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003427 p = xdr_inline_decode(xdr, 16);
3428 if (unlikely(!p))
3429 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003430 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003431 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003433 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003435 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 (unsigned long long)fsid->major,
3437 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003438 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003439out_overflow:
3440 print_overflow_msg(__func__, xdr);
3441 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442}
3443
3444static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3445{
Al Viro8687b632006-10-19 23:28:48 -07003446 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447
3448 *res = 60;
3449 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3450 return -EIO;
3451 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003452 p = xdr_inline_decode(xdr, 4);
3453 if (unlikely(!p))
3454 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003455 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3457 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003458 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003460out_overflow:
3461 print_overflow_msg(__func__, xdr);
3462 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463}
3464
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003465static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003466{
3467 __be32 *p;
3468
3469 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3470 return -EIO;
3471 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3472 p = xdr_inline_decode(xdr, 4);
3473 if (unlikely(!p))
3474 goto out_overflow;
3475 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003476 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003477 }
3478 return 0;
3479out_overflow:
3480 print_overflow_msg(__func__, xdr);
3481 return -EIO;
3482}
3483
Kinglong Mee8c612822015-08-26 21:12:58 +08003484static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3485 uint32_t *bitmap, uint32_t *bitmask)
3486{
3487 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3488 int ret;
3489 ret = decode_attr_bitmap(xdr, bitmask);
3490 if (unlikely(ret < 0))
3491 return ret;
3492 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3493 } else
3494 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3495 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3496 bitmask[0], bitmask[1], bitmask[2]);
3497 return 0;
3498}
3499
Bryan Schumakerae42c702010-10-21 16:33:17 -04003500static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3501{
3502 __be32 *p;
3503 int len;
3504
Trond Myklebust7ad07352010-10-23 15:34:20 -04003505 if (fh != NULL)
3506 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003507
3508 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3509 return -EIO;
3510 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3511 p = xdr_inline_decode(xdr, 4);
3512 if (unlikely(!p))
3513 goto out_overflow;
3514 len = be32_to_cpup(p);
3515 if (len > NFS4_FHSIZE)
3516 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003517 p = xdr_inline_decode(xdr, len);
3518 if (unlikely(!p))
3519 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003520 if (fh != NULL) {
3521 memcpy(fh->data, p, len);
3522 fh->size = len;
3523 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003524 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3525 }
3526 return 0;
3527out_overflow:
3528 print_overflow_msg(__func__, xdr);
3529 return -EIO;
3530}
3531
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3533{
Al Viro8687b632006-10-19 23:28:48 -07003534 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003536 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3538 return -EIO;
3539 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003540 p = xdr_inline_decode(xdr, 4);
3541 if (unlikely(!p))
3542 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003543 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3545 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003546 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003548out_overflow:
3549 print_overflow_msg(__func__, xdr);
3550 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551}
3552
3553static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3554{
Al Viro8687b632006-10-19 23:28:48 -07003555 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003556 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557
3558 *fileid = 0;
3559 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3560 return -EIO;
3561 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003562 p = xdr_inline_decode(xdr, 8);
3563 if (unlikely(!p))
3564 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003565 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003567 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003569 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003570 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003571out_overflow:
3572 print_overflow_msg(__func__, xdr);
3573 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574}
3575
Manoj Naik99baf622006-06-09 09:34:24 -04003576static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3577{
Al Viro8687b632006-10-19 23:28:48 -07003578 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003579 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003580
3581 *fileid = 0;
3582 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3583 return -EIO;
3584 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003585 p = xdr_inline_decode(xdr, 8);
3586 if (unlikely(!p))
3587 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003588 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003589 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003590 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003591 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003592 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003593 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003594out_overflow:
3595 print_overflow_msg(__func__, xdr);
3596 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003597}
3598
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3600{
Al Viro8687b632006-10-19 23:28:48 -07003601 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602 int status = 0;
3603
3604 *res = 0;
3605 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3606 return -EIO;
3607 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003608 p = xdr_inline_decode(xdr, 8);
3609 if (unlikely(!p))
3610 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003611 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3613 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003614 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003616out_overflow:
3617 print_overflow_msg(__func__, xdr);
3618 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619}
3620
3621static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3622{
Al Viro8687b632006-10-19 23:28:48 -07003623 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624 int status = 0;
3625
3626 *res = 0;
3627 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3628 return -EIO;
3629 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003630 p = xdr_inline_decode(xdr, 8);
3631 if (unlikely(!p))
3632 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003633 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3635 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003636 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003638out_overflow:
3639 print_overflow_msg(__func__, xdr);
3640 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641}
3642
3643static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3644{
Al Viro8687b632006-10-19 23:28:48 -07003645 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 int status = 0;
3647
3648 *res = 0;
3649 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3650 return -EIO;
3651 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003652 p = xdr_inline_decode(xdr, 8);
3653 if (unlikely(!p))
3654 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003655 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3657 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003658 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003659 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003660out_overflow:
3661 print_overflow_msg(__func__, xdr);
3662 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663}
3664
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003665static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3666{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003667 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003668 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003669 int status = 0;
3670
Benny Halevyc0eae662009-08-14 17:20:14 +03003671 p = xdr_inline_decode(xdr, 4);
3672 if (unlikely(!p))
3673 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003674 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003675 if (n == 0)
3676 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003677 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003678 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3679 dprintk("cannot parse %d components in path\n", n);
3680 goto out_eio;
3681 }
3682 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003683 struct nfs4_string *component = &path->components[path->ncomponents];
3684 status = decode_opaque_inline(xdr, &component->len, &component->data);
3685 if (unlikely(status != 0))
3686 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003687 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003688 pr_cont("%s%.*s ",
3689 (path->ncomponents != n ? "/ " : ""),
3690 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003691 }
3692out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003693 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003694root_path:
3695/* a root pathname is sent as a zero component4 */
3696 path->ncomponents = 1;
3697 path->components[0].len=0;
3698 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003699 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003700 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003701out_eio:
3702 dprintk(" status %d", status);
3703 status = -EIO;
3704 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003705out_overflow:
3706 print_overflow_msg(__func__, xdr);
3707 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003708}
3709
3710static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003711{
3712 int n;
Al Viro8687b632006-10-19 23:28:48 -07003713 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003714 int status = -EIO;
3715
3716 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3717 goto out;
3718 status = 0;
3719 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3720 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003721 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003722 status = -EIO;
3723 /* Ignore borken servers that return unrequested attrs */
3724 if (unlikely(res == NULL))
3725 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003726 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003727 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003728 if (unlikely(status != 0))
3729 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003730 p = xdr_inline_decode(xdr, 4);
3731 if (unlikely(!p))
3732 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003733 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003734 if (n <= 0)
3735 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003736 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003737 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003738 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003739
Trond Myklebust809b4262013-03-27 11:54:45 -04003740 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3741 break;
3742 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003743 p = xdr_inline_decode(xdr, 4);
3744 if (unlikely(!p))
3745 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003746 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003747
Chuck Lever02a29762012-03-01 17:00:31 -05003748 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003749 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3750 struct nfs4_string *server;
3751
3752 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003753 unsigned int i;
3754 dprintk("%s: using first %u of %u servers "
3755 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003756 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003757 NFS4_FS_LOCATION_MAXSERVERS,
3758 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003759 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003760 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003761 char *data;
3762 status = decode_opaque_inline(xdr, &len, &data);
3763 if (unlikely(status != 0))
3764 goto out_eio;
3765 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003766 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003767 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003768 server = &loc->servers[loc->nservers];
3769 status = decode_opaque_inline(xdr, &server->len, &server->data);
3770 if (unlikely(status != 0))
3771 goto out_eio;
3772 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003773 }
3774 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003775 if (unlikely(status != 0))
3776 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003777 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003778 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003779 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003780out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003781 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003782 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003783out_overflow:
3784 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003785out_eio:
3786 status = -EIO;
3787 goto out;
3788}
3789
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3791{
Al Viro8687b632006-10-19 23:28:48 -07003792 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793 int status = 0;
3794
3795 *res = 0;
3796 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3797 return -EIO;
3798 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003799 p = xdr_inline_decode(xdr, 8);
3800 if (unlikely(!p))
3801 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003802 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3804 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003805 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003807out_overflow:
3808 print_overflow_msg(__func__, xdr);
3809 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810}
3811
3812static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3813{
Al Viro8687b632006-10-19 23:28:48 -07003814 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 int status = 0;
3816
3817 *maxlink = 1;
3818 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3819 return -EIO;
3820 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003821 p = xdr_inline_decode(xdr, 4);
3822 if (unlikely(!p))
3823 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003824 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3826 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003827 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003829out_overflow:
3830 print_overflow_msg(__func__, xdr);
3831 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832}
3833
3834static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3835{
Al Viro8687b632006-10-19 23:28:48 -07003836 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 int status = 0;
3838
3839 *maxname = 1024;
3840 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3841 return -EIO;
3842 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003843 p = xdr_inline_decode(xdr, 4);
3844 if (unlikely(!p))
3845 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003846 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003847 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3848 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003849 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003851out_overflow:
3852 print_overflow_msg(__func__, xdr);
3853 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854}
3855
3856static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3857{
Al Viro8687b632006-10-19 23:28:48 -07003858 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 int status = 0;
3860
3861 *res = 1024;
3862 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3863 return -EIO;
3864 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3865 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003866 p = xdr_inline_decode(xdr, 8);
3867 if (unlikely(!p))
3868 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003869 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 if (maxread > 0x7FFFFFFF)
3871 maxread = 0x7FFFFFFF;
3872 *res = (uint32_t)maxread;
3873 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3874 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003875 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003876 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003877out_overflow:
3878 print_overflow_msg(__func__, xdr);
3879 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880}
3881
3882static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3883{
Al Viro8687b632006-10-19 23:28:48 -07003884 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885 int status = 0;
3886
3887 *res = 1024;
3888 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3889 return -EIO;
3890 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3891 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003892 p = xdr_inline_decode(xdr, 8);
3893 if (unlikely(!p))
3894 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003895 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 if (maxwrite > 0x7FFFFFFF)
3897 maxwrite = 0x7FFFFFFF;
3898 *res = (uint32_t)maxwrite;
3899 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3900 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003901 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003903out_overflow:
3904 print_overflow_msg(__func__, xdr);
3905 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906}
3907
Trond Myklebustbca79472009-03-11 14:10:26 -04003908static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909{
Trond Myklebustbca79472009-03-11 14:10:26 -04003910 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003911 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003912 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913
3914 *mode = 0;
3915 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3916 return -EIO;
3917 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003918 p = xdr_inline_decode(xdr, 4);
3919 if (unlikely(!p))
3920 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003921 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003922 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003924 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003926 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003927 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003928out_overflow:
3929 print_overflow_msg(__func__, xdr);
3930 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931}
3932
3933static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3934{
Al Viro8687b632006-10-19 23:28:48 -07003935 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003936 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937
3938 *nlink = 1;
3939 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3940 return -EIO;
3941 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003942 p = xdr_inline_decode(xdr, 4);
3943 if (unlikely(!p))
3944 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003945 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003946 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003947 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003949 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003950 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003951out_overflow:
3952 print_overflow_msg(__func__, xdr);
3953 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954}
3955
Trond Myklebust686a8162017-02-19 16:08:32 -05003956static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3957 struct nfs4_string *name, gfp_t gfp_flags)
3958{
3959 ssize_t ret;
3960
3961 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3962 XDR_MAX_NETOBJ, gfp_flags);
3963 name->len = 0;
3964 if (ret > 0)
3965 name->len = ret;
3966 return ret;
3967}
3968
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003969static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003970 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003971 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972{
Trond Myklebust686a8162017-02-19 16:08:32 -05003973 ssize_t len;
3974 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975
Eric W. Biedermane5782072013-02-01 14:22:02 -08003976 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3978 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003979 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3980 return 0;
3981 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3982
3983 if (owner_name != NULL) {
3984 len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT);
3985 if (len <= 0)
3986 goto out;
3987 dprintk("%s: name=%s\n", __func__, owner_name->data);
3988 return NFS_ATTR_FATTR_OWNER_NAME;
3989 } else {
3990 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3991 XDR_MAX_NETOBJ);
3992 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3993 goto out;
3994 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3995 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003997out:
3998 if (len != -EBADMSG)
3999 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004000 print_overflow_msg(__func__, xdr);
4001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002}
4003
Trond Myklebust80e52ac2009-08-09 15:06:19 -04004004static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08004005 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004006 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007{
Trond Myklebust686a8162017-02-19 16:08:32 -05004008 ssize_t len;
4009 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010
Eric W. Biedermane5782072013-02-01 14:22:02 -08004011 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
4013 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05004014 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
4015 return 0;
4016 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
4017
4018 if (group_name != NULL) {
4019 len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT);
4020 if (len <= 0)
4021 goto out;
4022 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08004023 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05004024 } else {
4025 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
4026 XDR_MAX_NETOBJ);
4027 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4028 goto out;
4029 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4030 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 }
Trond Myklebust686a8162017-02-19 16:08:32 -05004032out:
4033 if (len != -EBADMSG)
4034 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004035 print_overflow_msg(__func__, xdr);
4036 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004037}
4038
4039static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
4040{
Al Viro8687b632006-10-19 23:28:48 -07004041 uint32_t major = 0, minor = 0;
4042 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004043 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004044
4045 *rdev = MKDEV(0,0);
4046 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
4047 return -EIO;
4048 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
4049 dev_t tmp;
4050
Benny Halevyc0eae662009-08-14 17:20:14 +03004051 p = xdr_inline_decode(xdr, 8);
4052 if (unlikely(!p))
4053 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004054 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004055 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056 tmp = MKDEV(major, minor);
4057 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
4058 *rdev = tmp;
4059 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04004060 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004062 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04004063 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004064out_overflow:
4065 print_overflow_msg(__func__, xdr);
4066 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067}
4068
4069static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4070{
Al Viro8687b632006-10-19 23:28:48 -07004071 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072 int status = 0;
4073
4074 *res = 0;
4075 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4076 return -EIO;
4077 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004078 p = xdr_inline_decode(xdr, 8);
4079 if (unlikely(!p))
4080 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004081 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4083 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004084 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004086out_overflow:
4087 print_overflow_msg(__func__, xdr);
4088 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089}
4090
4091static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4092{
Al Viro8687b632006-10-19 23:28:48 -07004093 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 int status = 0;
4095
4096 *res = 0;
4097 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4098 return -EIO;
4099 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004100 p = xdr_inline_decode(xdr, 8);
4101 if (unlikely(!p))
4102 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004103 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4105 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004106 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004108out_overflow:
4109 print_overflow_msg(__func__, xdr);
4110 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111}
4112
4113static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4114{
Al Viro8687b632006-10-19 23:28:48 -07004115 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004116 int status = 0;
4117
4118 *res = 0;
4119 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4120 return -EIO;
4121 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004122 p = xdr_inline_decode(xdr, 8);
4123 if (unlikely(!p))
4124 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004125 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4127 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004128 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004130out_overflow:
4131 print_overflow_msg(__func__, xdr);
4132 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133}
4134
4135static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4136{
Al Viro8687b632006-10-19 23:28:48 -07004137 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004138 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
4140 *used = 0;
4141 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4142 return -EIO;
4143 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004144 p = xdr_inline_decode(xdr, 8);
4145 if (unlikely(!p))
4146 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004147 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004149 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004151 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004153 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004154out_overflow:
4155 print_overflow_msg(__func__, xdr);
4156 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157}
4158
4159static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4160{
Al Viro8687b632006-10-19 23:28:48 -07004161 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 uint64_t sec;
4163 uint32_t nsec;
4164
Benny Halevyc0eae662009-08-14 17:20:14 +03004165 p = xdr_inline_decode(xdr, 12);
4166 if (unlikely(!p))
4167 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004168 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004169 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004170 time->tv_sec = (time_t)sec;
4171 time->tv_nsec = (long)nsec;
4172 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004173out_overflow:
4174 print_overflow_msg(__func__, xdr);
4175 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176}
4177
4178static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4179{
4180 int status = 0;
4181
4182 time->tv_sec = 0;
4183 time->tv_nsec = 0;
4184 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4185 return -EIO;
4186 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4187 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004188 if (status == 0)
4189 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4191 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004192 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 return status;
4194}
4195
4196static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4197{
4198 int status = 0;
4199
4200 time->tv_sec = 0;
4201 time->tv_nsec = 0;
4202 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4203 return -EIO;
4204 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4205 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004206 if (status == 0)
4207 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4209 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004210 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211 return status;
4212}
4213
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004214static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4215 struct timespec *time)
4216{
4217 int status = 0;
4218
4219 time->tv_sec = 0;
4220 time->tv_nsec = 0;
4221 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4222 return -EIO;
4223 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4224 status = decode_attr_time(xdr, time);
4225 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4226 }
4227 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4228 (long)time->tv_nsec);
4229 return status;
4230}
4231
David Quigleyaa9c2662013-05-22 12:50:44 -04004232static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4233 struct nfs4_label *label)
4234{
4235 uint32_t pi = 0;
4236 uint32_t lfs = 0;
4237 __u32 len;
4238 __be32 *p;
4239 int status = 0;
4240
4241 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4242 return -EIO;
4243 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4244 p = xdr_inline_decode(xdr, 4);
4245 if (unlikely(!p))
4246 goto out_overflow;
4247 lfs = be32_to_cpup(p++);
4248 p = xdr_inline_decode(xdr, 4);
4249 if (unlikely(!p))
4250 goto out_overflow;
4251 pi = be32_to_cpup(p++);
4252 p = xdr_inline_decode(xdr, 4);
4253 if (unlikely(!p))
4254 goto out_overflow;
4255 len = be32_to_cpup(p++);
4256 p = xdr_inline_decode(xdr, len);
4257 if (unlikely(!p))
4258 goto out_overflow;
4259 if (len < NFS4_MAXLABELLEN) {
4260 if (label) {
4261 memcpy(label->label, p, len);
4262 label->len = len;
4263 label->pi = pi;
4264 label->lfs = lfs;
4265 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4266 }
4267 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4268 } else
4269 printk(KERN_WARNING "%s: label too long (%u)!\n",
4270 __func__, len);
4271 }
4272 if (label && label->label)
4273 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4274 (char *)label->label, label->len, label->pi, label->lfs);
4275 return status;
4276
4277out_overflow:
4278 print_overflow_msg(__func__, xdr);
4279 return -EIO;
4280}
4281
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4283{
4284 int status = 0;
4285
4286 time->tv_sec = 0;
4287 time->tv_nsec = 0;
4288 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4289 return -EIO;
4290 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4291 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004292 if (status == 0)
4293 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4295 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004296 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 return status;
4298}
4299
Trond Myklebust256e48b2012-06-21 11:18:13 -04004300static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301{
4302 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004303 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304
4305 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004306 dprintk("%s: server returned incorrect attribute length: "
4307 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004308 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 attrwords << 2,
4310 (attrwords < nwords) ? '<' : '>',
4311 nwords << 2);
4312 return -EIO;
4313 }
4314 return 0;
4315}
4316
4317static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4318{
Al Viro8687b632006-10-19 23:28:48 -07004319 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004320
Benny Halevyc0eae662009-08-14 17:20:14 +03004321 p = xdr_inline_decode(xdr, 20);
4322 if (unlikely(!p))
4323 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004324 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004325 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004326 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004327 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004328out_overflow:
4329 print_overflow_msg(__func__, xdr);
4330 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331}
4332
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004333static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334{
Al Viro8687b632006-10-19 23:28:48 -07004335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 uint32_t supp, acc;
4337 int status;
4338
4339 status = decode_op_hdr(xdr, OP_ACCESS);
4340 if (status)
4341 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004342 p = xdr_inline_decode(xdr, 8);
4343 if (unlikely(!p))
4344 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004345 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004346 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004347 *supported = supp;
4348 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004349 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004350out_overflow:
4351 print_overflow_msg(__func__, xdr);
4352 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353}
4354
Benny Halevy07d30432009-08-14 17:19:52 +03004355static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004357 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4358 if (unlikely(ret < 0)) {
4359 print_overflow_msg(__func__, xdr);
4360 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004361 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004362 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004363}
4364
4365static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4366{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004367 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368}
4369
Trond Myklebust93b717f2016-05-16 17:42:43 -04004370static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4371{
4372 stateid->type = NFS4_OPEN_STATEID_TYPE;
4373 return decode_stateid(xdr, stateid);
4374}
4375
4376static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4377{
4378 stateid->type = NFS4_LOCK_STATEID_TYPE;
4379 return decode_stateid(xdr, stateid);
4380}
4381
4382static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4383{
4384 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4385 return decode_stateid(xdr, stateid);
4386}
4387
Trond Myklebustfcd88432017-11-07 12:39:44 -05004388static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4389{
4390 nfs4_stateid dummy;
4391
4392 nfs4_stateid_copy(stateid, &invalid_stateid);
4393 return decode_stateid(xdr, &dummy);
4394}
4395
Linus Torvalds1da177e2005-04-16 15:20:36 -07004396static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4397{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004398 int status;
4399
4400 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004401 if (status != -EIO)
4402 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004403 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004404 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004405 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004406}
4407
Benny Halevydb942bb2009-08-14 17:19:56 +03004408static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4409{
Chuck Levercd937102012-03-02 17:14:31 -05004410 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411}
4412
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004413static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4414{
4415 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4416}
4417
Fred Isaman0b7c0152012-04-20 14:47:39 -04004418static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004419{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004420 int status;
4421
4422 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004423 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004424 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004425 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426}
4427
4428static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4429{
Al Viro8687b632006-10-19 23:28:48 -07004430 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 uint32_t bmlen;
4432 int status;
4433
4434 status = decode_op_hdr(xdr, OP_CREATE);
4435 if (status)
4436 return status;
4437 if ((status = decode_change_info(xdr, cinfo)))
4438 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004439 p = xdr_inline_decode(xdr, 4);
4440 if (unlikely(!p))
4441 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004442 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004443 p = xdr_inline_decode(xdr, bmlen << 2);
4444 if (likely(p))
4445 return 0;
4446out_overflow:
4447 print_overflow_msg(__func__, xdr);
4448 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449}
4450
4451static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4452{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004453 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004454 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 int status;
4456
4457 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4458 goto xdr_error;
4459 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4460 goto xdr_error;
4461 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4462 goto xdr_error;
4463 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4464 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004465 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4466 &res->fh_expire_type)) != 0)
4467 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004468 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4469 goto xdr_error;
4470 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4471 goto xdr_error;
4472 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4473 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004474 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4475 res->exclcreat_bitmask)) != 0)
4476 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004477 status = verify_attr_len(xdr, savep, attrlen);
4478xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004479 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 return status;
4481}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004482
Linus Torvalds1da177e2005-04-16 15:20:36 -07004483static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4484{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004485 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004486 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004488
Linus Torvalds1da177e2005-04-16 15:20:36 -07004489 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4490 goto xdr_error;
4491 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4492 goto xdr_error;
4493 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4494 goto xdr_error;
4495
4496 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4497 goto xdr_error;
4498 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4499 goto xdr_error;
4500 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4501 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004502
4503 status = -EIO;
4504 if (unlikely(bitmap[0]))
4505 goto xdr_error;
4506
Linus Torvalds1da177e2005-04-16 15:20:36 -07004507 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4508 goto xdr_error;
4509 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4510 goto xdr_error;
4511 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4512 goto xdr_error;
4513
4514 status = verify_attr_len(xdr, savep, attrlen);
4515xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004516 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004517 return status;
4518}
4519
4520static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4521{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004522 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004523 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004524 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004525
Linus Torvalds1da177e2005-04-16 15:20:36 -07004526 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4527 goto xdr_error;
4528 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4529 goto xdr_error;
4530 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4531 goto xdr_error;
4532
4533 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4534 goto xdr_error;
4535 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4536 goto xdr_error;
4537
4538 status = verify_attr_len(xdr, savep, attrlen);
4539xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004540 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004541 return status;
4542}
4543
Andy Adamson88034c32012-05-23 05:02:34 -04004544static int decode_threshold_hint(struct xdr_stream *xdr,
4545 uint32_t *bitmap,
4546 uint64_t *res,
4547 uint32_t hint_bit)
4548{
4549 __be32 *p;
4550
4551 *res = 0;
4552 if (likely(bitmap[0] & hint_bit)) {
4553 p = xdr_inline_decode(xdr, 8);
4554 if (unlikely(!p))
4555 goto out_overflow;
4556 xdr_decode_hyper(p, res);
4557 }
4558 return 0;
4559out_overflow:
4560 print_overflow_msg(__func__, xdr);
4561 return -EIO;
4562}
4563
4564static int decode_first_threshold_item4(struct xdr_stream *xdr,
4565 struct nfs4_threshold *res)
4566{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004567 __be32 *p;
4568 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004569 uint32_t bitmap[3] = {0,}, attrlen;
4570 int status;
4571
4572 /* layout type */
4573 p = xdr_inline_decode(xdr, 4);
4574 if (unlikely(!p)) {
4575 print_overflow_msg(__func__, xdr);
4576 return -EIO;
4577 }
4578 res->l_type = be32_to_cpup(p);
4579
4580 /* thi_hintset bitmap */
4581 status = decode_attr_bitmap(xdr, bitmap);
4582 if (status < 0)
4583 goto xdr_error;
4584
4585 /* thi_hintlist length */
4586 status = decode_attr_length(xdr, &attrlen, &savep);
4587 if (status < 0)
4588 goto xdr_error;
4589 /* thi_hintlist */
4590 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4591 if (status < 0)
4592 goto xdr_error;
4593 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4594 if (status < 0)
4595 goto xdr_error;
4596 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4597 THRESHOLD_RD_IO);
4598 if (status < 0)
4599 goto xdr_error;
4600 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4601 THRESHOLD_WR_IO);
4602 if (status < 0)
4603 goto xdr_error;
4604
4605 status = verify_attr_len(xdr, savep, attrlen);
4606 res->bm = bitmap[0];
4607
4608 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4609 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4610 res->wr_io_sz);
4611xdr_error:
4612 dprintk("%s ret=%d!\n", __func__, status);
4613 return status;
4614}
4615
4616/*
4617 * Thresholds on pNFS direct I/O vrs MDS I/O
4618 */
4619static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4620 uint32_t *bitmap,
4621 struct nfs4_threshold *res)
4622{
4623 __be32 *p;
4624 int status = 0;
4625 uint32_t num;
4626
4627 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4628 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004629 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004630 /* Did the server return an unrequested attribute? */
4631 if (unlikely(res == NULL))
4632 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004633 p = xdr_inline_decode(xdr, 4);
4634 if (unlikely(!p))
4635 goto out_overflow;
4636 num = be32_to_cpup(p);
4637 if (num == 0)
4638 return 0;
4639 if (num > 1)
4640 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4641 "drivers per filesystem not supported\n",
4642 __func__);
4643
4644 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004645 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004646 }
4647 return status;
4648out_overflow:
4649 print_overflow_msg(__func__, xdr);
4650 return -EIO;
4651}
4652
Bryan Schumakerae42c702010-10-21 16:33:17 -04004653static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4654 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004655 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004656 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657{
Trond Myklebustbca79472009-03-11 14:10:26 -04004658 int status;
4659 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004660 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004661 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004663 status = decode_attr_type(xdr, bitmap, &type);
4664 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004665 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004666 fattr->mode = 0;
4667 if (status != 0) {
4668 fattr->mode |= nfs_type2fmt[type];
4669 fattr->valid |= status;
4670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004672 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4673 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004675 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004676
4677 status = decode_attr_size(xdr, bitmap, &fattr->size);
4678 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004679 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004680 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004681
4682 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
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 Myklebustee7b75f2011-06-16 13:15:41 -04004687 err = 0;
4688 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004689 if (status < 0)
4690 goto xdr_error;
4691
4692 status = decode_attr_filehandle(xdr, bitmap, fh);
4693 if (status < 0)
4694 goto xdr_error;
4695
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004696 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4697 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004698 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004699 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004700
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004701 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004702 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004703 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004704 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004705
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004706 status = -EIO;
4707 if (unlikely(bitmap[0]))
4708 goto xdr_error;
4709
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004710 status = decode_attr_mode(xdr, bitmap, &fmode);
4711 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004712 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004713 if (status != 0) {
4714 fattr->mode |= fmode;
4715 fattr->valid |= status;
4716 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004717
4718 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4719 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004720 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004721 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004722
Trond Myklebust6926afd2012-01-07 13:22:46 -05004723 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004724 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004725 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004726 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004727
Trond Myklebust6926afd2012-01-07 13:22:46 -05004728 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004729 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004730 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004731 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004732
4733 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4734 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004735 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004736 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004737
4738 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4739 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004740 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004741 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004742
4743 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4744 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004745 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004746 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004747
4748 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4749 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004750 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004751 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004752
4753 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4754 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004756 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004757
Trond Myklebust28331a42011-04-27 13:47:52 -04004758 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004759 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004760 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004761 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004762
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004763 status = -EIO;
4764 if (unlikely(bitmap[1]))
4765 goto xdr_error;
4766
Andy Adamson88034c32012-05-23 05:02:34 -04004767 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4768 if (status < 0)
4769 goto xdr_error;
4770
David Quigleyaa9c2662013-05-22 12:50:44 -04004771 if (label) {
4772 status = decode_attr_security_label(xdr, bitmap, label);
4773 if (status < 0)
4774 goto xdr_error;
4775 fattr->valid |= status;
4776 }
4777
Bryan Schumakerae42c702010-10-21 16:33:17 -04004778xdr_error:
4779 dprintk("%s: xdr returned %d\n", __func__, -status);
4780 return status;
4781}
4782
4783static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004784 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004785 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004786{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004787 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004788 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004789 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004790 int status;
4791
4792 status = decode_op_hdr(xdr, OP_GETATTR);
4793 if (status < 0)
4794 goto xdr_error;
4795
4796 status = decode_attr_bitmap(xdr, bitmap);
4797 if (status < 0)
4798 goto xdr_error;
4799
4800 status = decode_attr_length(xdr, &attrlen, &savep);
4801 if (status < 0)
4802 goto xdr_error;
4803
David Quigleyaa9c2662013-05-22 12:50:44 -04004804 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4805 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004806 if (status < 0)
4807 goto xdr_error;
4808
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004809 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004810xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004811 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004812 return status;
4813}
4814
David Quigleyaa9c2662013-05-22 12:50:44 -04004815static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4816 struct nfs4_label *label, const struct nfs_server *server)
4817{
4818 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4819}
4820
Bryan Schumakerae42c702010-10-21 16:33:17 -04004821static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004822 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004823{
David Quigleyaa9c2662013-05-22 12:50:44 -04004824 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004825}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004826
Andy Adamson504913f2010-10-20 00:17:57 -04004827/*
Jeff Layton3132e492016-08-10 15:58:24 -04004828 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004829 */
Jeff Layton3132e492016-08-10 15:58:24 -04004830static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004831 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004832{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004833 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004834 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004835
4836 p = xdr_inline_decode(xdr, 4);
4837 if (unlikely(!p))
4838 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004839 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004840
4841 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004842 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004843 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004844
4845 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004846 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004847 if (unlikely(!p))
4848 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004849
4850 /* If we get too many, then just cap it at the max */
4851 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4852 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4853 __func__, fsinfo->nlayouttypes);
4854 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4855 }
4856
4857 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4858 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004859 return 0;
4860out_overflow:
4861 print_overflow_msg(__func__, xdr);
4862 return -EIO;
4863}
4864
4865/*
4866 * The type of file system exported.
4867 * Note we must ensure that layouttype is set in any non-error case.
4868 */
4869static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004870 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004871{
4872 int status = 0;
4873
4874 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4875 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4876 return -EIO;
4877 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004878 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004879 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004880 }
Andy Adamson504913f2010-10-20 00:17:57 -04004881 return status;
4882}
4883
Fred Isamandae100c2011-07-30 20:52:37 -04004884/*
4885 * The prefered block size for layout directed io
4886 */
4887static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4888 uint32_t *res)
4889{
4890 __be32 *p;
4891
4892 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4893 *res = 0;
4894 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4895 p = xdr_inline_decode(xdr, 4);
4896 if (unlikely(!p)) {
4897 print_overflow_msg(__func__, xdr);
4898 return -EIO;
4899 }
4900 *res = be32_to_cpup(p);
4901 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4902 }
4903 return 0;
4904}
4905
Peng Tao2a92ee92015-09-26 02:24:37 +08004906/*
4907 * The granularity of a CLONE operation.
4908 */
4909static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4910 uint32_t *res)
4911{
4912 __be32 *p;
4913
4914 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4915 *res = 0;
4916 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4917 p = xdr_inline_decode(xdr, 4);
4918 if (unlikely(!p)) {
4919 print_overflow_msg(__func__, xdr);
4920 return -EIO;
4921 }
4922 *res = be32_to_cpup(p);
4923 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4924 }
4925 return 0;
4926}
4927
Linus Torvalds1da177e2005-04-16 15:20:36 -07004928static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4929{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004930 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004931 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004932 int status;
4933
4934 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4935 goto xdr_error;
4936 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4937 goto xdr_error;
4938 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4939 goto xdr_error;
4940
4941 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4942
4943 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4944 goto xdr_error;
4945 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4946 goto xdr_error;
4947 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4948 goto xdr_error;
4949 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4950 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4951 goto xdr_error;
4952 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004953
4954 status = -EIO;
4955 if (unlikely(bitmap[0]))
4956 goto xdr_error;
4957
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004958 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4959 if (status != 0)
4960 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004961 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004962 if (status != 0)
4963 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004964
4965 status = -EIO;
4966 if (unlikely(bitmap[1]))
4967 goto xdr_error;
4968
Fred Isamandae100c2011-07-30 20:52:37 -04004969 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4970 if (status)
4971 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004972 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4973 if (status)
4974 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004975
4976 status = verify_attr_len(xdr, savep, attrlen);
4977xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004978 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 return status;
4980}
4981
4982static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4983{
Al Viro8687b632006-10-19 23:28:48 -07004984 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004985 uint32_t len;
4986 int status;
4987
Trond Myklebust99367812007-07-17 21:52:41 -04004988 /* Zero handle first to allow comparisons */
4989 memset(fh, 0, sizeof(*fh));
4990
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991 status = decode_op_hdr(xdr, OP_GETFH);
4992 if (status)
4993 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004994
Benny Halevyc0eae662009-08-14 17:20:14 +03004995 p = xdr_inline_decode(xdr, 4);
4996 if (unlikely(!p))
4997 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004998 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 if (len > NFS4_FHSIZE)
5000 return -EIO;
5001 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03005002 p = xdr_inline_decode(xdr, len);
5003 if (unlikely(!p))
5004 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03005005 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005006 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005007out_overflow:
5008 print_overflow_msg(__func__, xdr);
5009 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005010}
5011
5012static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5013{
5014 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05005015
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016 status = decode_op_hdr(xdr, OP_LINK);
5017 if (status)
5018 return status;
5019 return decode_change_info(xdr, cinfo);
5020}
5021
5022/*
5023 * We create the owner, so we know a proper owner.id length is 4.
5024 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005025static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005026{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005027 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07005028 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005029 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005031 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03005032 if (unlikely(!p))
5033 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005034 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03005035 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005036 type = be32_to_cpup(p++); /* 4 byte read */
5037 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005038 fl->fl_start = (loff_t)offset;
5039 fl->fl_end = fl->fl_start + (loff_t)length - 1;
5040 if (length == ~(uint64_t)0)
5041 fl->fl_end = OFFSET_MAX;
5042 fl->fl_type = F_WRLCK;
5043 if (type & 1)
5044 fl->fl_type = F_RDLCK;
5045 fl->fl_pid = 0;
5046 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005047 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5048 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5049 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03005050 if (likely(p))
5051 return -NFS4ERR_DENIED;
5052out_overflow:
5053 print_overflow_msg(__func__, xdr);
5054 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005055}
5056
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005057static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005059 int status;
5060
5061 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005062 if (status == -EIO)
5063 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04005065 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005066 if (unlikely(status))
5067 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04005069 status = decode_lock_denied(xdr, NULL);
5070 if (res->open_seqid != NULL)
5071 nfs_increment_open_seqid(status, res->open_seqid);
5072 nfs_increment_lock_seqid(status, res->lock_seqid);
5073out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005074 return status;
5075}
5076
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005077static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005078{
5079 int status;
5080 status = decode_op_hdr(xdr, OP_LOCKT);
5081 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005082 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083 return status;
5084}
5085
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005086static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005088 int status;
5089
5090 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005091 if (status != -EIO)
5092 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005093 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005094 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005095 return status;
5096}
5097
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005098static int decode_release_lockowner(struct xdr_stream *xdr)
5099{
5100 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5101}
5102
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103static int decode_lookup(struct xdr_stream *xdr)
5104{
5105 return decode_op_hdr(xdr, OP_LOOKUP);
5106}
5107
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005108static int decode_lookupp(struct xdr_stream *xdr)
5109{
5110 return decode_op_hdr(xdr, OP_LOOKUPP);
5111}
5112
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005114static int decode_space_limit(struct xdr_stream *xdr,
5115 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005116{
Andy Adamson05d564f2008-12-23 16:06:15 -05005117 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005119 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005120
Benny Halevyc0eae662009-08-14 17:20:14 +03005121 p = xdr_inline_decode(xdr, 12);
5122 if (unlikely(!p))
5123 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005124 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005125 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005126 case NFS4_LIMIT_SIZE:
5127 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005128 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005129 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005130 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005131 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005132 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005134 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005135 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005136 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005137out_overflow:
5138 print_overflow_msg(__func__, xdr);
5139 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140}
5141
Trond Myklebust6ae37332015-01-30 14:21:14 -05005142static int decode_rw_delegation(struct xdr_stream *xdr,
5143 uint32_t delegation_type,
5144 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005145{
Andy Adamson05d564f2008-12-23 16:06:15 -05005146 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005147 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148
Trond Myklebust93b717f2016-05-16 17:42:43 -04005149 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005150 if (unlikely(status))
5151 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005152 p = xdr_inline_decode(xdr, 4);
5153 if (unlikely(!p))
5154 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005155 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005156
Linus Torvalds1da177e2005-04-16 15:20:36 -07005157 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005158 case NFS4_OPEN_DELEGATE_READ:
5159 res->delegation_type = FMODE_READ;
5160 break;
5161 case NFS4_OPEN_DELEGATE_WRITE:
5162 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005163 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005164 return -EIO;
5165 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005166 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005167out_overflow:
5168 print_overflow_msg(__func__, xdr);
5169 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005170}
5171
Trond Myklebust6ae37332015-01-30 14:21:14 -05005172static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5173{
5174 __be32 *p;
5175 uint32_t why_no_delegation;
5176
5177 p = xdr_inline_decode(xdr, 4);
5178 if (unlikely(!p))
5179 goto out_overflow;
5180 why_no_delegation = be32_to_cpup(p);
5181 switch (why_no_delegation) {
5182 case WND4_CONTENTION:
5183 case WND4_RESOURCE:
5184 xdr_inline_decode(xdr, 4);
5185 /* Ignore for now */
5186 }
5187 return 0;
5188out_overflow:
5189 print_overflow_msg(__func__, xdr);
5190 return -EIO;
5191}
5192
5193static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5194{
5195 __be32 *p;
5196 uint32_t delegation_type;
5197
5198 p = xdr_inline_decode(xdr, 4);
5199 if (unlikely(!p))
5200 goto out_overflow;
5201 delegation_type = be32_to_cpup(p);
5202 res->delegation_type = 0;
5203 switch (delegation_type) {
5204 case NFS4_OPEN_DELEGATE_NONE:
5205 return 0;
5206 case NFS4_OPEN_DELEGATE_READ:
5207 case NFS4_OPEN_DELEGATE_WRITE:
5208 return decode_rw_delegation(xdr, delegation_type, res);
5209 case NFS4_OPEN_DELEGATE_NONE_EXT:
5210 return decode_no_delegation(xdr, res);
5211 }
5212 return -EIO;
5213out_overflow:
5214 print_overflow_msg(__func__, xdr);
5215 return -EIO;
5216}
5217
Linus Torvalds1da177e2005-04-16 15:20:36 -07005218static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5219{
Andy Adamson05d564f2008-12-23 16:06:15 -05005220 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005221 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005222 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223
Trond Myklebustc7848f62013-12-04 17:39:23 -05005224 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5225 return status;
5226 nfs_increment_open_seqid(status, res->seqid);
5227 if (status)
5228 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005229 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005230 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005231 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232
Andy Adamson05d564f2008-12-23 16:06:15 -05005233 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234
Benny Halevyc0eae662009-08-14 17:20:14 +03005235 p = xdr_inline_decode(xdr, 8);
5236 if (unlikely(!p))
5237 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005238 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005239 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005240 if (bmlen > 10)
5241 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005242
Benny Halevyc0eae662009-08-14 17:20:14 +03005243 p = xdr_inline_decode(xdr, bmlen << 2);
5244 if (unlikely(!p))
5245 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005246 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5247 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005248 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005249 for (; i < NFS4_BITMAP_SIZE; i++)
5250 res->attrset[i] = 0;
5251
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252 return decode_delegation(xdr, res);
5253xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005254 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005256out_overflow:
5257 print_overflow_msg(__func__, xdr);
5258 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259}
5260
5261static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5262{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263 int status;
5264
Andy Adamson05d564f2008-12-23 16:06:15 -05005265 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005266 if (status != -EIO)
5267 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005268 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005269 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005270 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005271}
5272
5273static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5274{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275 int status;
5276
5277 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005278 if (status != -EIO)
5279 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005280 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005281 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005282 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005283}
5284
5285static int decode_putfh(struct xdr_stream *xdr)
5286{
5287 return decode_op_hdr(xdr, OP_PUTFH);
5288}
5289
5290static int decode_putrootfh(struct xdr_stream *xdr)
5291{
5292 return decode_op_hdr(xdr, OP_PUTROOTFH);
5293}
5294
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005295static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5296 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297{
Al Viro8687b632006-10-19 23:28:48 -07005298 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005299 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 int status;
5301
5302 status = decode_op_hdr(xdr, OP_READ);
5303 if (status)
5304 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005305 p = xdr_inline_decode(xdr, 8);
5306 if (unlikely(!p))
5307 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005308 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005309 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005310 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005311 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005312 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313 "count %u > recvd %u\n", count, recvd);
5314 count = recvd;
5315 eof = 0;
5316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005317 res->eof = eof;
5318 res->count = count;
5319 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005320out_overflow:
5321 print_overflow_msg(__func__, xdr);
5322 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005323}
5324
5325static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5326{
Chuck Leverbcecff72007-10-26 13:32:03 -04005327 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005328 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329
5330 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005331 if (!status)
5332 status = decode_verifier(xdr, readdir->verifier.data);
5333 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005334 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005335 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005336 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005337 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005338 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339}
5340
5341static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5342{
5343 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005344 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005345 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346 int status;
5347
5348 status = decode_op_hdr(xdr, OP_READLINK);
5349 if (status)
5350 return status;
5351
5352 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005353 p = xdr_inline_decode(xdr, 4);
5354 if (unlikely(!p))
5355 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005356 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005358 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359 return -ENAMETOOLONG;
5360 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005361 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005362 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005363 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005364 "count %u > recvd %u\n", len, recvd);
5365 return -EIO;
5366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367 /*
5368 * The XDR encode routine has set things up so that
5369 * the link text will be copied directly into the
5370 * buffer. We just have to do overflow-checking,
5371 * and and null-terminate the text (the VFS expects
5372 * null-termination).
5373 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005374 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005376out_overflow:
5377 print_overflow_msg(__func__, xdr);
5378 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379}
5380
5381static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5382{
5383 int status;
5384
5385 status = decode_op_hdr(xdr, OP_REMOVE);
5386 if (status)
5387 goto out;
5388 status = decode_change_info(xdr, cinfo);
5389out:
5390 return status;
5391}
5392
5393static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5394 struct nfs4_change_info *new_cinfo)
5395{
5396 int status;
5397
5398 status = decode_op_hdr(xdr, OP_RENAME);
5399 if (status)
5400 goto out;
5401 if ((status = decode_change_info(xdr, old_cinfo)))
5402 goto out;
5403 status = decode_change_info(xdr, new_cinfo);
5404out:
5405 return status;
5406}
5407
5408static int decode_renew(struct xdr_stream *xdr)
5409{
5410 return decode_op_hdr(xdr, OP_RENEW);
5411}
5412
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005413static int
5414decode_restorefh(struct xdr_stream *xdr)
5415{
5416 return decode_op_hdr(xdr, OP_RESTOREFH);
5417}
5418
J. Bruce Fields029d1052005-06-22 17:16:22 +00005419static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005420 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005421{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005422 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005423 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005424 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005425 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005426 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005427
Andy Adamsonbf118a32011-12-07 11:55:27 -05005428 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005429 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5430 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005431
Trond Myklebust519d3952012-08-14 17:30:10 -04005432 xdr_enter_page(xdr, xdr->buf->page_len);
5433
Trond Myklebustcff298c2012-08-14 17:14:17 -04005434 /* Calculate the offset of the page data */
5435 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005436
J. Bruce Fields029d1052005-06-22 17:16:22 +00005437 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5438 goto out;
5439 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5440 goto out;
5441
5442 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5443 return -EIO;
5444 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005445
Andy Adamsonbf118a32011-12-07 11:55:27 -05005446 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5447 * are stored with the acl data to handle the problem of
5448 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005449 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005450 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005451
5452 /* Check for receive buffer overflow */
5453 if (res->acl_len > (xdr->nwords << 2) ||
5454 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5455 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005456 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005457 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005458 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005459 } else
5460 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005461
5462out:
5463 return status;
5464}
5465
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466static int
5467decode_savefh(struct xdr_stream *xdr)
5468{
5469 return decode_op_hdr(xdr, OP_SAVEFH);
5470}
5471
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005472static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005473{
Al Viro8687b632006-10-19 23:28:48 -07005474 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475 uint32_t bmlen;
5476 int status;
5477
Linus Torvalds1da177e2005-04-16 15:20:36 -07005478 status = decode_op_hdr(xdr, OP_SETATTR);
5479 if (status)
5480 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005481 p = xdr_inline_decode(xdr, 4);
5482 if (unlikely(!p))
5483 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005484 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005485 p = xdr_inline_decode(xdr, bmlen << 2);
5486 if (likely(p))
5487 return 0;
5488out_overflow:
5489 print_overflow_msg(__func__, xdr);
5490 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491}
5492
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005493static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005494{
Al Viro8687b632006-10-19 23:28:48 -07005495 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005496 uint32_t opnum;
5497 int32_t nfserr;
5498
Benny Halevyc0eae662009-08-14 17:20:14 +03005499 p = xdr_inline_decode(xdr, 8);
5500 if (unlikely(!p))
5501 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005502 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005503 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005504 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005505 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506 return -EIO;
5507 }
Benny Halevycccddf42009-08-14 17:20:19 +03005508 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005509 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005510 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5511 if (unlikely(!p))
5512 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005513 p = xdr_decode_hyper(p, &res->clientid);
5514 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005515 } else if (nfserr == NFSERR_CLID_INUSE) {
5516 uint32_t len;
5517
5518 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005519 p = xdr_inline_decode(xdr, 4);
5520 if (unlikely(!p))
5521 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005522 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005523 p = xdr_inline_decode(xdr, len);
5524 if (unlikely(!p))
5525 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005526
5527 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005528 p = xdr_inline_decode(xdr, 4);
5529 if (unlikely(!p))
5530 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005531 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005532 p = xdr_inline_decode(xdr, len);
5533 if (unlikely(!p))
5534 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005535 return -NFSERR_CLID_INUSE;
5536 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005537 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538
5539 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005540out_overflow:
5541 print_overflow_msg(__func__, xdr);
5542 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005543}
5544
5545static int decode_setclientid_confirm(struct xdr_stream *xdr)
5546{
5547 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5548}
5549
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005550static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005551{
Al Viro8687b632006-10-19 23:28:48 -07005552 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005553 int status;
5554
5555 status = decode_op_hdr(xdr, OP_WRITE);
5556 if (status)
5557 return status;
5558
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005559 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005560 if (unlikely(!p))
5561 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005562 res->count = be32_to_cpup(p++);
5563 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005564 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005565out_overflow:
5566 print_overflow_msg(__func__, xdr);
5567 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005568}
5569
5570static int decode_delegreturn(struct xdr_stream *xdr)
5571{
5572 return decode_op_hdr(xdr, OP_DELEGRETURN);
5573}
5574
Chuck Leverfb15b262013-03-16 15:54:34 -04005575static int decode_secinfo_gss(struct xdr_stream *xdr,
5576 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005577{
Chuck Leverfb15b262013-03-16 15:54:34 -04005578 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005579 __be32 *p;
5580
5581 p = xdr_inline_decode(xdr, 4);
5582 if (unlikely(!p))
5583 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005584 oid_len = be32_to_cpup(p);
5585 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005586 goto out_err;
5587
Chuck Leverfb15b262013-03-16 15:54:34 -04005588 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005589 if (unlikely(!p))
5590 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005591 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5592 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005593
5594 p = xdr_inline_decode(xdr, 8);
5595 if (unlikely(!p))
5596 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005597 flavor->flavor_info.qop = be32_to_cpup(p++);
5598 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005599
5600 return 0;
5601
5602out_overflow:
5603 print_overflow_msg(__func__, xdr);
5604 return -EIO;
5605out_err:
5606 return -EINVAL;
5607}
5608
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005609static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005610{
Chuck Leverfb15b262013-03-16 15:54:34 -04005611 struct nfs4_secinfo4 *sec_flavor;
5612 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005613 int status;
5614 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005615
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005616 p = xdr_inline_decode(xdr, 4);
5617 if (unlikely(!p))
5618 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005619
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005620 res->flavors->num_flavors = 0;
5621 num_flavors = be32_to_cpup(p);
5622
5623 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005624 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005625 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005626 break;
5627
5628 p = xdr_inline_decode(xdr, 4);
5629 if (unlikely(!p))
5630 goto out_overflow;
5631 sec_flavor->flavor = be32_to_cpup(p);
5632
5633 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005634 status = decode_secinfo_gss(xdr, sec_flavor);
5635 if (status)
5636 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005637 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005638 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005639 }
5640
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005641 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005642out:
5643 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005644out_overflow:
5645 print_overflow_msg(__func__, xdr);
5646 return -EIO;
5647}
5648
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005649static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5650{
5651 int status = decode_op_hdr(xdr, OP_SECINFO);
5652 if (status)
5653 return status;
5654 return decode_secinfo_common(xdr, res);
5655}
5656
Benny Halevy99fe60d2009-04-01 09:22:29 -04005657#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005658static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5659{
5660 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5661 if (status)
5662 return status;
5663 return decode_secinfo_common(xdr, res);
5664}
5665
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005666static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5667{
5668 __be32 *p;
5669 uint32_t bitmap_words;
5670 unsigned int i;
5671
5672 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005673 if (!p)
5674 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005675 bitmap_words = be32_to_cpup(p++);
5676 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5677 return -EIO;
5678 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5679 for (i = 0; i < bitmap_words; i++)
5680 op_map->u.words[i] = be32_to_cpup(p++);
5681
5682 return 0;
5683}
5684
Benny Halevy99fe60d2009-04-01 09:22:29 -04005685static int decode_exchange_id(struct xdr_stream *xdr,
5686 struct nfs41_exchange_id_res *res)
5687{
5688 __be32 *p;
5689 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005690 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005691 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005692 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005693
5694 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5695 if (status)
5696 return status;
5697
Benny Halevyc0eae662009-08-14 17:20:14 +03005698 p = xdr_inline_decode(xdr, 8);
5699 if (unlikely(!p))
5700 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005701 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005702 p = xdr_inline_decode(xdr, 12);
5703 if (unlikely(!p))
5704 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005705 res->seqid = be32_to_cpup(p++);
5706 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005707
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005708 res->state_protect.how = be32_to_cpup(p);
5709 switch (res->state_protect.how) {
5710 case SP4_NONE:
5711 break;
5712 case SP4_MACH_CRED:
5713 status = decode_op_map(xdr, &res->state_protect.enforce);
5714 if (status)
5715 return status;
5716 status = decode_op_map(xdr, &res->state_protect.allow);
5717 if (status)
5718 return status;
5719 break;
5720 default:
5721 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005722 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005723 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005724
Chuck Leveracdeb692012-05-21 22:46:16 -04005725 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005726 p = xdr_inline_decode(xdr, 8);
5727 if (unlikely(!p))
5728 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005729 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005730
Chuck Leveracdeb692012-05-21 22:46:16 -04005731 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005732 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5733 if (unlikely(status))
5734 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005735 memcpy(res->server_owner->major_id, dummy_str, dummy);
5736 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005737
Chuck Leveracdeb692012-05-21 22:46:16 -04005738 /* server_scope4 */
5739 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5740 if (unlikely(status))
5741 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005742 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5743 res->server_scope->server_scope_sz = dummy;
5744
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005745 /* Implementation Id */
5746 p = xdr_inline_decode(xdr, 4);
5747 if (unlikely(!p))
5748 goto out_overflow;
5749 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005750
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005751 if (impl_id_count) {
5752 /* nii_domain */
5753 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5754 if (unlikely(status))
5755 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005756 memcpy(res->impl_id->domain, dummy_str, dummy);
5757
5758 /* nii_name */
5759 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5760 if (unlikely(status))
5761 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005762 memcpy(res->impl_id->name, dummy_str, dummy);
5763
5764 /* nii_date */
5765 p = xdr_inline_decode(xdr, 12);
5766 if (unlikely(!p))
5767 goto out_overflow;
5768 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5769 res->impl_id->date.nseconds = be32_to_cpup(p);
5770
5771 /* if there's more than one entry, ignore the rest */
5772 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005773 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005774out_overflow:
5775 print_overflow_msg(__func__, xdr);
5776 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005777}
Andy Adamsonfc931582009-04-01 09:22:31 -04005778
5779static int decode_chan_attrs(struct xdr_stream *xdr,
5780 struct nfs4_channel_attrs *attrs)
5781{
5782 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005783 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005784
Benny Halevyc0eae662009-08-14 17:20:14 +03005785 p = xdr_inline_decode(xdr, 28);
5786 if (unlikely(!p))
5787 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005788 val = be32_to_cpup(p++); /* headerpadsz */
5789 if (val)
5790 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005791 attrs->max_rqst_sz = be32_to_cpup(p++);
5792 attrs->max_resp_sz = be32_to_cpup(p++);
5793 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5794 attrs->max_ops = be32_to_cpup(p++);
5795 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005796 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005797 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005798 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5799 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005800 return -EINVAL;
5801 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005802 if (nr_attrs == 1) {
5803 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5804 if (unlikely(!p))
5805 goto out_overflow;
5806 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005807 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005808out_overflow:
5809 print_overflow_msg(__func__, xdr);
5810 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005811}
5812
Benny Halevye78291e2009-08-14 17:20:00 +03005813static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5814{
5815 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005816}
5817
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005818static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5819 struct nfs41_bind_conn_to_session_res *res)
5820{
5821 __be32 *p;
5822 int status;
5823
5824 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5825 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005826 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005827 if (unlikely(status))
5828 return status;
5829
5830 /* dir flags, rdma mode bool */
5831 p = xdr_inline_decode(xdr, 8);
5832 if (unlikely(!p))
5833 goto out_overflow;
5834
5835 res->dir = be32_to_cpup(p++);
5836 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5837 return -EIO;
5838 if (be32_to_cpup(p) == 0)
5839 res->use_conn_in_rdma_mode = false;
5840 else
5841 res->use_conn_in_rdma_mode = true;
5842
5843 return 0;
5844out_overflow:
5845 print_overflow_msg(__func__, xdr);
5846 return -EIO;
5847}
5848
Andy Adamsonfc931582009-04-01 09:22:31 -04005849static int decode_create_session(struct xdr_stream *xdr,
5850 struct nfs41_create_session_res *res)
5851{
5852 __be32 *p;
5853 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005854
5855 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005856 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005857 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005858 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005859 return status;
5860
Andy Adamsonfc931582009-04-01 09:22:31 -04005861 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005862 p = xdr_inline_decode(xdr, 8);
5863 if (unlikely(!p))
5864 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005865 res->seqid = be32_to_cpup(p++);
5866 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005867
5868 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005869 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005870 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005871 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005872 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005873out_overflow:
5874 print_overflow_msg(__func__, xdr);
5875 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005876}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005877
5878static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5879{
5880 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5881}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005882
Trond Myklebust66245532012-05-25 17:18:09 -04005883static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5884{
5885 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5886}
5887
Ricardo Labiaga180197532009-12-05 16:08:40 -05005888static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5889{
5890 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5891}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005892#endif /* CONFIG_NFS_V4_1 */
5893
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005894static int decode_sequence(struct xdr_stream *xdr,
5895 struct nfs4_sequence_res *res,
5896 struct rpc_rqst *rqstp)
5897{
5898#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005899 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005900 struct nfs4_sessionid id;
5901 u32 dummy;
5902 int status;
5903 __be32 *p;
5904
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005905 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005906 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005907 if (!res->sr_slot->table->session)
5908 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005909
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005910 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005911 if (!status)
5912 status = decode_sessionid(xdr, &id);
5913 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005914 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005915
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005916 /*
5917 * If the server returns different values for sessionID, slotID or
5918 * sequence number, the server is looney tunes.
5919 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005920 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005921 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005922
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005923 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005924 NFS4_MAX_SESSIONID_LEN)) {
5925 dprintk("%s Invalid session id\n", __func__);
5926 goto out_err;
5927 }
Benny Halevye78291e2009-08-14 17:20:00 +03005928
Benny Halevyc0eae662009-08-14 17:20:14 +03005929 p = xdr_inline_decode(xdr, 20);
5930 if (unlikely(!p))
5931 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005932
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005933 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005934 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005935 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005936 dprintk("%s Invalid sequence number\n", __func__);
5937 goto out_err;
5938 }
5939 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005940 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005941 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005942 dprintk("%s Invalid slot id\n", __func__);
5943 goto out_err;
5944 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005945 /* highest slot id */
5946 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005947 /* target highest slot id */
5948 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005949 /* result flags */
5950 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005951 status = 0;
5952out_err:
5953 res->sr_status = status;
5954 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005955out_overflow:
5956 print_overflow_msg(__func__, xdr);
5957 status = -EIO;
5958 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005959#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005960 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005961#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005962}
5963
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005964#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005965static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5966{
5967 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5968 return decode_stateid(xdr, stateid);
5969}
5970
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005971static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005972 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005973{
Trond Myklebust4e590802015-03-09 14:01:25 -04005974 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005975 __be32 *p;
5976 uint32_t len, type;
5977 int status;
5978
5979 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5980 if (status) {
5981 if (status == -ETOOSMALL) {
5982 p = xdr_inline_decode(xdr, 4);
5983 if (unlikely(!p))
5984 goto out_overflow;
5985 pdev->mincount = be32_to_cpup(p);
5986 dprintk("%s: Min count too small. mincnt = %u\n",
5987 __func__, pdev->mincount);
5988 }
5989 return status;
5990 }
5991
5992 p = xdr_inline_decode(xdr, 8);
5993 if (unlikely(!p))
5994 goto out_overflow;
5995 type = be32_to_cpup(p++);
5996 if (type != pdev->layout_type) {
5997 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5998 __func__, pdev->layout_type, type);
5999 return -EINVAL;
6000 }
6001 /*
6002 * Get the length of the opaque device_addr4. xdr_read_pages places
6003 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
6004 * and places the remaining xdr data in xdr_buf->tail
6005 */
6006 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04006007 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
6008 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006009
6010 /* Parse notification bitmap, verifying that it is zero. */
6011 p = xdr_inline_decode(xdr, 4);
6012 if (unlikely(!p))
6013 goto out_overflow;
6014 len = be32_to_cpup(p);
6015 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00006016 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006017
6018 p = xdr_inline_decode(xdr, 4 * len);
6019 if (unlikely(!p))
6020 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006021
Trond Myklebust4e590802015-03-09 14:01:25 -04006022 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07006023 for (i = 1; i < len; i++) {
6024 if (be32_to_cpup(p++)) {
6025 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006026 __func__);
6027 return -EIO;
6028 }
6029 }
6030 }
6031 return 0;
6032out_overflow:
6033 print_overflow_msg(__func__, xdr);
6034 return -EIO;
6035}
6036
6037static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6038 struct nfs4_layoutget_res *res)
6039{
6040 __be32 *p;
6041 int status;
6042 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04006043 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006044
6045 status = decode_op_hdr(xdr, OP_LAYOUTGET);
6046 if (status)
6047 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006048 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006049 if (unlikely(!p))
6050 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006051 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04006052 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006053 p = xdr_inline_decode(xdr, 4);
6054 if (unlikely(!p))
6055 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006056 layout_count = be32_to_cpup(p);
6057 if (!layout_count) {
6058 dprintk("%s: server responded with empty layout array\n",
6059 __func__);
6060 return -EINVAL;
6061 }
6062
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006063 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006064 if (unlikely(!p))
6065 goto out_overflow;
6066 p = xdr_decode_hyper(p, &res->range.offset);
6067 p = xdr_decode_hyper(p, &res->range.length);
6068 res->range.iomode = be32_to_cpup(p++);
6069 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006070 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006071
6072 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6073 __func__,
6074 (unsigned long)res->range.offset,
6075 (unsigned long)res->range.length,
6076 res->range.iomode,
6077 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006078 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006079
Trond Myklebust64bd5772012-06-20 22:35:05 -04006080 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006081 if (res->layoutp->len > recvd) {
6082 dprintk("NFS: server cheating in layoutget reply: "
6083 "layout len %u > recvd %u\n",
6084 res->layoutp->len, recvd);
6085 return -EINVAL;
6086 }
6087
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006088 if (layout_count > 1) {
6089 /* We only handle a length one array at the moment. Any
6090 * further entries are just ignored. Note that this means
6091 * the client may see a response that is less than the
6092 * minimum it requested.
6093 */
6094 dprintk("%s: server responded with %d layouts, dropping tail\n",
6095 __func__, layout_count);
6096 }
6097
6098 return 0;
6099out_overflow:
6100 print_overflow_msg(__func__, xdr);
6101 return -EIO;
6102}
Andy Adamson863a3c62011-03-23 13:27:54 +00006103
Benny Halevycbe82602011-05-22 19:52:37 +03006104static int decode_layoutreturn(struct xdr_stream *xdr,
6105 struct nfs4_layoutreturn_res *res)
6106{
6107 __be32 *p;
6108 int status;
6109
6110 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6111 if (status)
6112 return status;
6113 p = xdr_inline_decode(xdr, 4);
6114 if (unlikely(!p))
6115 goto out_overflow;
6116 res->lrs_present = be32_to_cpup(p);
6117 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006118 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05006119 else
6120 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006121 return status;
6122out_overflow:
6123 print_overflow_msg(__func__, xdr);
6124 return -EIO;
6125}
6126
Andy Adamson863a3c62011-03-23 13:27:54 +00006127static int decode_layoutcommit(struct xdr_stream *xdr,
6128 struct rpc_rqst *req,
6129 struct nfs4_layoutcommit_res *res)
6130{
6131 __be32 *p;
6132 __u32 sizechanged;
6133 int status;
6134
6135 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006136 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006137 if (status)
6138 return status;
6139
6140 p = xdr_inline_decode(xdr, 4);
6141 if (unlikely(!p))
6142 goto out_overflow;
6143 sizechanged = be32_to_cpup(p);
6144
6145 if (sizechanged) {
6146 /* throw away new size */
6147 p = xdr_inline_decode(xdr, 8);
6148 if (unlikely(!p))
6149 goto out_overflow;
6150 }
6151 return 0;
6152out_overflow:
6153 print_overflow_msg(__func__, xdr);
6154 return -EIO;
6155}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006156
6157static int decode_test_stateid(struct xdr_stream *xdr,
6158 struct nfs41_test_stateid_res *res)
6159{
6160 __be32 *p;
6161 int status;
6162 int num_res;
6163
6164 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6165 if (status)
6166 return status;
6167
6168 p = xdr_inline_decode(xdr, 4);
6169 if (unlikely(!p))
6170 goto out_overflow;
6171 num_res = be32_to_cpup(p++);
6172 if (num_res != 1)
6173 goto out;
6174
6175 p = xdr_inline_decode(xdr, 4);
6176 if (unlikely(!p))
6177 goto out_overflow;
6178 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006179
6180 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006181out_overflow:
6182 print_overflow_msg(__func__, xdr);
6183out:
6184 return -EIO;
6185}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006186
6187static int decode_free_stateid(struct xdr_stream *xdr,
6188 struct nfs41_free_stateid_res *res)
6189{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006190 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006191 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006192}
Trond Myklebustcf805162016-11-15 14:56:07 -05006193#else
6194static inline
6195int decode_layoutreturn(struct xdr_stream *xdr,
6196 struct nfs4_layoutreturn_res *res)
6197{
6198 return 0;
6199}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006200#endif /* CONFIG_NFS_V4_1 */
6201
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202/*
Benny Halevy49c25592008-12-23 16:06:16 -05006203 * END OF "GENERIC" DECODE ROUTINES.
6204 */
6205
6206/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 * Decode OPEN_DOWNGRADE response
6208 */
Chuck Leverbf269552010-12-14 14:59:29 +00006209static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6210 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006211 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006212{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006213 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006214 struct compound_hdr hdr;
6215 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216
Chuck Leverbf269552010-12-14 14:59:29 +00006217 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006218 if (status)
6219 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006220 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006221 if (status)
6222 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006224 if (status)
6225 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006226 if (res->lr_res) {
6227 status = decode_layoutreturn(xdr, res->lr_res);
6228 res->lr_ret = status;
6229 if (status)
6230 goto out;
6231 }
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006234 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006235}
6236
6237/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006238 * Decode ACCESS response
6239 */
Chuck Leverbf269552010-12-14 14:59:29 +00006240static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006241 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006243 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244 struct compound_hdr hdr;
6245 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006246
Chuck Leverbf269552010-12-14 14:59:29 +00006247 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006248 if (status)
6249 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006250 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006251 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006252 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006253 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006254 if (status != 0)
6255 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006256 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006257 if (status != 0)
6258 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006259 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260out:
6261 return status;
6262}
6263
6264/*
6265 * Decode LOOKUP response
6266 */
Chuck Leverbf269552010-12-14 14:59:29 +00006267static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006268 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006269{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006270 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271 struct compound_hdr hdr;
6272 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006273
Chuck Leverbf269552010-12-14 14:59:29 +00006274 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006275 if (status)
6276 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006277 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006278 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006279 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006280 status = decode_putfh(xdr);
6281 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006282 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006283 status = decode_lookup(xdr);
6284 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006285 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006286 status = decode_getfh(xdr, res->fh);
6287 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006289 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290out:
6291 return status;
6292}
6293
6294/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006295 * Decode LOOKUPP response
6296 */
6297static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6298 void *data)
6299{
6300 struct nfs4_lookupp_res *res = data;
6301 struct compound_hdr hdr;
6302 int status;
6303
6304 status = decode_compound_hdr(xdr, &hdr);
6305 if (status)
6306 goto out;
6307 status = decode_sequence(xdr, &res->seq_res, rqstp);
6308 if (status)
6309 goto out;
6310 status = decode_putfh(xdr);
6311 if (status)
6312 goto out;
6313 status = decode_lookupp(xdr);
6314 if (status)
6315 goto out;
6316 status = decode_getfh(xdr, res->fh);
6317 if (status)
6318 goto out;
6319 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6320out:
6321 return status;
6322}
6323
6324/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 * Decode LOOKUP_ROOT response
6326 */
Chuck Leverbf269552010-12-14 14:59:29 +00006327static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6328 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006329 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006331 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 struct compound_hdr hdr;
6333 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006334
Chuck Leverbf269552010-12-14 14:59:29 +00006335 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006336 if (status)
6337 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006338 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006339 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006341 status = decode_putrootfh(xdr);
6342 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006343 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006344 status = decode_getfh(xdr, res->fh);
6345 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006346 status = decode_getfattr_label(xdr, res->fattr,
6347 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348out:
6349 return status;
6350}
6351
6352/*
6353 * Decode REMOVE response
6354 */
Chuck Leverbf269552010-12-14 14:59:29 +00006355static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006356 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006357{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006358 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 struct compound_hdr hdr;
6360 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006361
Chuck Leverbf269552010-12-14 14:59:29 +00006362 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006363 if (status)
6364 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006365 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006366 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006368 status = decode_putfh(xdr);
6369 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006370 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006371 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006372out:
6373 return status;
6374}
6375
6376/*
6377 * Decode RENAME response
6378 */
Chuck Leverbf269552010-12-14 14:59:29 +00006379static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006380 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006382 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006383 struct compound_hdr hdr;
6384 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006385
Chuck Leverbf269552010-12-14 14:59:29 +00006386 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006387 if (status)
6388 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006389 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006390 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006391 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006392 status = decode_putfh(xdr);
6393 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006394 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006395 status = decode_savefh(xdr);
6396 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006397 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006398 status = decode_putfh(xdr);
6399 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006400 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006401 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006402out:
6403 return status;
6404}
6405
6406/*
6407 * Decode LINK response
6408 */
Chuck Leverbf269552010-12-14 14:59:29 +00006409static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006410 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006411{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006412 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006413 struct compound_hdr hdr;
6414 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006415
Chuck Leverbf269552010-12-14 14:59:29 +00006416 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006417 if (status)
6418 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006419 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006420 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006421 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006422 status = decode_putfh(xdr);
6423 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006424 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006425 status = decode_savefh(xdr);
6426 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006427 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006428 status = decode_putfh(xdr);
6429 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006430 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006431 status = decode_link(xdr, &res->cinfo);
6432 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006433 goto out;
6434 /*
6435 * Note order: OP_LINK leaves the directory as the current
6436 * filehandle.
6437 */
Chuck Leverbf269552010-12-14 14:59:29 +00006438 status = decode_restorefh(xdr);
6439 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006440 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006441 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006442out:
6443 return status;
6444}
6445
6446/*
6447 * Decode CREATE response
6448 */
Chuck Leverbf269552010-12-14 14:59:29 +00006449static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006450 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006451{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006452 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006453 struct compound_hdr hdr;
6454 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006455
Chuck Leverbf269552010-12-14 14:59:29 +00006456 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006457 if (status)
6458 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006459 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006460 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006462 status = decode_putfh(xdr);
6463 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006464 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_create(xdr, &res->dir_cinfo);
6466 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006468 status = decode_getfh(xdr, res->fh);
6469 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006471 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472out:
6473 return status;
6474}
6475
6476/*
6477 * Decode SYMLINK response
6478 */
Chuck Leverbf269552010-12-14 14:59:29 +00006479static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006480 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006481{
Chuck Leverbf269552010-12-14 14:59:29 +00006482 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006483}
6484
6485/*
6486 * Decode GETATTR response
6487 */
Chuck Leverbf269552010-12-14 14:59:29 +00006488static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006489 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006490{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006491 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006492 struct compound_hdr hdr;
6493 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006494
Chuck Leverbf269552010-12-14 14:59:29 +00006495 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006496 if (status)
6497 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006498 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006499 if (status)
6500 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006501 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006502 if (status)
6503 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006504 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006505out:
6506 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507}
6508
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006509/*
6510 * Encode an SETACL request
6511 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006512static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006513 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006514{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006515 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006516 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006517 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006518 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006519
Chuck Lever9f06c712010-12-14 14:59:18 +00006520 encode_compound_hdr(xdr, req, &hdr);
6521 encode_sequence(xdr, &args->seq_args, &hdr);
6522 encode_putfh(xdr, args->fh, &hdr);
6523 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006524 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006525}
Andy Adamson05d564f2008-12-23 16:06:15 -05006526
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006527/*
6528 * Decode SETACL response
6529 */
6530static int
Chuck Leverbf269552010-12-14 14:59:29 +00006531nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006532 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006533{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006534 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006535 struct compound_hdr hdr;
6536 int status;
6537
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006539 if (status)
6540 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006542 if (status)
6543 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006544 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006545 if (status)
6546 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006547 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006548out:
6549 return status;
6550}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006551
6552/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006553 * Decode GETACL response
6554 */
6555static int
Chuck Leverbf269552010-12-14 14:59:29 +00006556nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006557 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006558{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006559 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006560 struct compound_hdr hdr;
6561 int status;
6562
Trond Myklebust331818f2012-02-03 18:30:53 -05006563 if (res->acl_scratch != NULL) {
6564 void *p = page_address(res->acl_scratch);
6565 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6566 }
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006568 if (status)
6569 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006571 if (status)
6572 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006573 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006574 if (status)
6575 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006576 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006577
6578out:
6579 return status;
6580}
6581
6582/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583 * Decode CLOSE response
6584 */
Chuck Leverbf269552010-12-14 14:59:29 +00006585static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006586 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006587{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006588 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006589 struct compound_hdr hdr;
6590 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006591
Chuck Leverbf269552010-12-14 14:59:29 +00006592 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006593 if (status)
6594 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006595 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006596 if (status)
6597 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006598 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006599 if (status)
6600 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006601 if (res->lr_res) {
6602 status = decode_layoutreturn(xdr, res->lr_res);
6603 res->lr_ret = status;
6604 if (status)
6605 goto out;
6606 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006607 if (res->fattr != NULL) {
6608 status = decode_getfattr(xdr, res->fattr, res->server);
6609 if (status != 0)
6610 goto out;
6611 }
Chuck Leverbf269552010-12-14 14:59:29 +00006612 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006613out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006614 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006615}
6616
6617/*
6618 * Decode OPEN response
6619 */
Chuck Leverbf269552010-12-14 14:59:29 +00006620static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006621 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006622{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006623 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006624 struct compound_hdr hdr;
6625 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006626
Chuck Leverbf269552010-12-14 14:59:29 +00006627 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006628 if (status)
6629 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006630 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006631 if (status)
6632 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006634 if (status)
6635 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006636 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006637 if (status)
6638 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006639 status = decode_getfh(xdr, &res->fh);
6640 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006641 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006642 if (res->access_request)
6643 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006644 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
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_CONFIRM response
6651 */
Chuck Leverbf269552010-12-14 14:59:29 +00006652static int nfs4_xdr_dec_open_confirm(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_open_confirmres *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_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006664 if (status)
6665 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006666 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006667out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006668 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006669}
6670
6671/*
6672 * Decode OPEN response
6673 */
Chuck Leverbf269552010-12-14 14:59:29 +00006674static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6675 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006676 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006677{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006678 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006679 struct compound_hdr hdr;
6680 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006681
Chuck Leverbf269552010-12-14 14:59:29 +00006682 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006683 if (status)
6684 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006685 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006686 if (status)
6687 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006688 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006689 if (status)
6690 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006691 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006692 if (status)
6693 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006694 if (res->access_request)
6695 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006696 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006697out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006698 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699}
6700
6701/*
6702 * Decode SETATTR response
6703 */
Chuck Leverbf269552010-12-14 14:59:29 +00006704static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6705 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006706 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006707{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006708 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006709 struct compound_hdr hdr;
6710 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711
Chuck Leverbf269552010-12-14 14:59:29 +00006712 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006713 if (status)
6714 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006716 if (status)
6717 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006718 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006719 if (status)
6720 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006721 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006722 if (status)
6723 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006724 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006726 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006727}
6728
6729/*
6730 * Decode LOCK response
6731 */
Chuck Leverbf269552010-12-14 14:59:29 +00006732static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006733 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006734{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006735 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006736 struct compound_hdr hdr;
6737 int status;
6738
Chuck Leverbf269552010-12-14 14:59:29 +00006739 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006740 if (status)
6741 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006742 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006743 if (status)
6744 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006746 if (status)
6747 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006748 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749out:
6750 return status;
6751}
6752
6753/*
6754 * Decode LOCKT response
6755 */
Chuck Leverbf269552010-12-14 14:59:29 +00006756static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006757 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006758{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006759 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006760 struct compound_hdr hdr;
6761 int status;
6762
Chuck Leverbf269552010-12-14 14:59:29 +00006763 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006764 if (status)
6765 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006766 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006767 if (status)
6768 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006769 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006770 if (status)
6771 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006772 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773out:
6774 return status;
6775}
6776
6777/*
6778 * Decode LOCKU response
6779 */
Chuck Leverbf269552010-12-14 14:59:29 +00006780static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006781 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006782{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006783 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784 struct compound_hdr hdr;
6785 int status;
6786
Chuck Leverbf269552010-12-14 14:59:29 +00006787 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 if (status)
6789 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006790 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006791 if (status)
6792 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006793 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006794 if (status)
6795 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006796 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006797out:
6798 return status;
6799}
6800
Chuck Leverbf269552010-12-14 14:59:29 +00006801static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6802 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006803{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006804 struct compound_hdr hdr;
6805 int status;
6806
Chuck Leverbf269552010-12-14 14:59:29 +00006807 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006808 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006809 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006810 return status;
6811}
6812
Linus Torvalds1da177e2005-04-16 15:20:36 -07006813/*
6814 * Decode READLINK response
6815 */
Chuck Leverbf269552010-12-14 14:59:29 +00006816static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6817 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006818 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006820 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821 struct compound_hdr hdr;
6822 int status;
6823
Chuck Leverbf269552010-12-14 14:59:29 +00006824 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006825 if (status)
6826 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006827 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006828 if (status)
6829 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006830 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006831 if (status)
6832 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834out:
6835 return status;
6836}
6837
6838/*
6839 * Decode READDIR response
6840 */
Chuck Leverbf269552010-12-14 14:59:29 +00006841static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006842 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006843{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006844 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845 struct compound_hdr hdr;
6846 int status;
6847
Chuck Leverbf269552010-12-14 14:59:29 +00006848 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849 if (status)
6850 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006851 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006852 if (status)
6853 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006854 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006855 if (status)
6856 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006857 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858out:
6859 return status;
6860}
6861
6862/*
6863 * Decode Read response
6864 */
Chuck Leverbf269552010-12-14 14:59:29 +00006865static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006866 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006868 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006869 struct compound_hdr hdr;
6870 int status;
6871
Chuck Leverbf269552010-12-14 14:59:29 +00006872 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006873 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006874 if (status)
6875 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006876 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006877 if (status)
6878 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006879 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006880 if (status)
6881 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006882 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006883 if (!status)
6884 status = res->count;
6885out:
6886 return status;
6887}
6888
6889/*
6890 * Decode WRITE response
6891 */
Chuck Leverbf269552010-12-14 14:59:29 +00006892static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006893 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006894{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006895 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 struct compound_hdr hdr;
6897 int status;
6898
Chuck Leverbf269552010-12-14 14:59:29 +00006899 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006900 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006901 if (status)
6902 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006903 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006904 if (status)
6905 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006906 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006907 if (status)
6908 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006909 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006910 if (status)
6911 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006912 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006913 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006914 if (!status)
6915 status = res->count;
6916out:
6917 return status;
6918}
6919
6920/*
6921 * Decode COMMIT response
6922 */
Chuck Leverbf269552010-12-14 14:59:29 +00006923static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006924 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006926 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006927 struct compound_hdr hdr;
6928 int status;
6929
Chuck Leverbf269552010-12-14 14:59:29 +00006930 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006931 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006932 if (status)
6933 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006934 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006935 if (status)
6936 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006937 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938 if (status)
6939 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006940 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006941out:
6942 return status;
6943}
6944
6945/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006946 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006947 */
Chuck Leverbf269552010-12-14 14:59:29 +00006948static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006949 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006950{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006951 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006952 struct compound_hdr hdr;
6953 int status;
6954
Chuck Leverbf269552010-12-14 14:59:29 +00006955 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006956 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006957 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006958 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006959 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006960 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006961 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006962 return status;
6963}
6964
6965/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006966 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006967 */
Chuck Leverbf269552010-12-14 14:59:29 +00006968static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006969 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006970{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006971 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006972 struct compound_hdr hdr;
6973 int status;
6974
Chuck Leverbf269552010-12-14 14:59:29 +00006975 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006977 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006978 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006979 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006980 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006981 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006982 return status;
6983}
6984
6985/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006986 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006987 */
Chuck Leverbf269552010-12-14 14:59:29 +00006988static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006989 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006990{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006991 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992 struct compound_hdr hdr;
6993 int status;
6994
Chuck Leverbf269552010-12-14 14:59:29 +00006995 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006996 if (!status)
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)
Chuck Leverbf269552010-12-14 14:59:29 +00006999 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007001 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007002 return status;
7003}
7004
7005/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007006 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007 */
Chuck Leverbf269552010-12-14 14:59:29 +00007008static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
7009 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007010 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007011{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007012 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007013 struct compound_hdr hdr;
7014 int status;
7015
Chuck Leverbf269552010-12-14 14:59:29 +00007016 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007017 if (status)
7018 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007019 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007020 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007021 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007022 status = decode_putfh(xdr);
7023 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007025 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007026out:
7027 return status;
7028}
7029
7030/*
7031 * Decode RENEW response
7032 */
Chuck Leverbf269552010-12-14 14:59:29 +00007033static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
7034 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007035{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007036 struct compound_hdr hdr;
7037 int status;
7038
Chuck Leverbf269552010-12-14 14:59:29 +00007039 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007041 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007042 return status;
7043}
7044
7045/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007046 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007047 */
Chuck Leverbf269552010-12-14 14:59:29 +00007048static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
7049 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007050 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007051{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007052 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007053 struct compound_hdr hdr;
7054 int status;
7055
Chuck Leverbf269552010-12-14 14:59:29 +00007056 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007057 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007058 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007059 return status;
7060}
7061
7062/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007063 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007064 */
Chuck Leverbf269552010-12-14 14:59:29 +00007065static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007066 struct xdr_stream *xdr,
7067 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007068{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007069 struct compound_hdr hdr;
7070 int status;
7071
Chuck Leverbf269552010-12-14 14:59:29 +00007072 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007073 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007074 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007075 return status;
7076}
7077
7078/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007079 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007080 */
Chuck Leverbf269552010-12-14 14:59:29 +00007081static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7082 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007083 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007084{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007085 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007086 struct compound_hdr hdr;
7087 int status;
7088
Chuck Leverbf269552010-12-14 14:59:29 +00007089 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007090 if (status)
7091 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007092 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007093 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01007094 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007095 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007096 if (status != 0)
7097 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05007098 if (res->lr_res) {
7099 status = decode_layoutreturn(xdr, res->lr_res);
7100 res->lr_ret = status;
7101 if (status)
7102 goto out;
7103 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05007104 if (res->fattr) {
7105 status = decode_getfattr(xdr, res->fattr, res->server);
7106 if (status != 0)
7107 goto out;
7108 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04007109 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007110out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007111 return status;
7112}
7113
Trond Myklebust683b57b2006-06-09 09:34:22 -04007114/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007115 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04007116 */
Chuck Leverbf269552010-12-14 14:59:29 +00007117static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7118 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007119 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007120{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007121 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04007122 struct compound_hdr hdr;
7123 int status;
7124
Chuck Leverbf269552010-12-14 14:59:29 +00007125 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007126 if (status)
7127 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007128 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007129 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007130 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007131 status = decode_putfh(xdr);
7132 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007133 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04007134 if (res->migration) {
7135 xdr_enter_page(xdr, PAGE_SIZE);
7136 status = decode_getfattr_generic(xdr,
7137 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007138 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04007139 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007140 if (status)
7141 goto out;
7142 if (res->renew)
7143 status = decode_renew(xdr);
7144 } else {
7145 status = decode_lookup(xdr);
7146 if (status)
7147 goto out;
7148 xdr_enter_page(xdr, PAGE_SIZE);
7149 status = decode_getfattr_generic(xdr,
7150 &res->fs_locations->fattr,
7151 NULL, res->fs_locations,
7152 NULL, res->fs_locations->server);
7153 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007154out:
7155 return status;
7156}
7157
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007158/*
7159 * Decode SECINFO response
7160 */
7161static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7162 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007163 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007164{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007165 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007166 struct compound_hdr hdr;
7167 int status;
7168
7169 status = decode_compound_hdr(xdr, &hdr);
7170 if (status)
7171 goto out;
7172 status = decode_sequence(xdr, &res->seq_res, rqstp);
7173 if (status)
7174 goto out;
7175 status = decode_putfh(xdr);
7176 if (status)
7177 goto out;
7178 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007179out:
7180 return status;
7181}
7182
Chuck Lever44c99932013-10-17 14:13:30 -04007183/*
7184 * Decode FSID_PRESENT response
7185 */
7186static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7187 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007188 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007189{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007190 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007191 struct compound_hdr hdr;
7192 int status;
7193
7194 status = decode_compound_hdr(xdr, &hdr);
7195 if (status)
7196 goto out;
7197 status = decode_sequence(xdr, &res->seq_res, rqstp);
7198 if (status)
7199 goto out;
7200 status = decode_putfh(xdr);
7201 if (status)
7202 goto out;
7203 status = decode_getfh(xdr, res->fh);
7204 if (status)
7205 goto out;
7206 if (res->renew)
7207 status = decode_renew(xdr);
7208out:
7209 return status;
7210}
7211
Benny Halevy99fe60d2009-04-01 09:22:29 -04007212#if defined(CONFIG_NFS_V4_1)
7213/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007214 * Decode BIND_CONN_TO_SESSION response
7215 */
7216static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7217 struct xdr_stream *xdr,
7218 void *res)
7219{
7220 struct compound_hdr hdr;
7221 int status;
7222
7223 status = decode_compound_hdr(xdr, &hdr);
7224 if (!status)
7225 status = decode_bind_conn_to_session(xdr, res);
7226 return status;
7227}
7228
7229/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007230 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007231 */
Chuck Leverbf269552010-12-14 14:59:29 +00007232static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7233 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007234 void *res)
7235{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007236 struct compound_hdr hdr;
7237 int status;
7238
Chuck Leverbf269552010-12-14 14:59:29 +00007239 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007240 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007241 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007242 return status;
7243}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007244
7245/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007246 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007247 */
Chuck Leverbf269552010-12-14 14:59:29 +00007248static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7249 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007250 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007251{
Andy Adamsonfc931582009-04-01 09:22:31 -04007252 struct compound_hdr hdr;
7253 int status;
7254
Chuck Leverbf269552010-12-14 14:59:29 +00007255 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007256 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007257 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007258 return status;
7259}
7260
7261/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007262 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007263 */
Chuck Leverbf269552010-12-14 14:59:29 +00007264static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7265 struct xdr_stream *xdr,
7266 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007267{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007268 struct compound_hdr hdr;
7269 int status;
7270
Chuck Leverbf269552010-12-14 14:59:29 +00007271 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007272 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007273 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007274 return status;
7275}
7276
7277/*
Trond Myklebust66245532012-05-25 17:18:09 -04007278 * Decode DESTROY_CLIENTID response
7279 */
7280static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7281 struct xdr_stream *xdr,
7282 void *res)
7283{
7284 struct compound_hdr hdr;
7285 int status;
7286
7287 status = decode_compound_hdr(xdr, &hdr);
7288 if (!status)
7289 status = decode_destroy_clientid(xdr, res);
7290 return status;
7291}
7292
7293/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007294 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007295 */
Chuck Leverbf269552010-12-14 14:59:29 +00007296static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7297 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007298 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007299{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007300 struct compound_hdr hdr;
7301 int status;
7302
Chuck Leverbf269552010-12-14 14:59:29 +00007303 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007304 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007305 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007306 return status;
7307}
7308
7309/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007310 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007311 */
Chuck Leverbf269552010-12-14 14:59:29 +00007312static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7313 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007314 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007315{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007316 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007317 struct compound_hdr hdr;
7318 int status;
7319
Chuck Leverbf269552010-12-14 14:59:29 +00007320 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007321 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007322 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007323 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007324 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007325 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007326 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007327 return status;
7328}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007329
7330/*
7331 * Decode RECLAIM_COMPLETE response
7332 */
Chuck Leverbf269552010-12-14 14:59:29 +00007333static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7334 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007335 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007336{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007337 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007338 struct compound_hdr hdr;
7339 int status;
7340
Chuck Leverbf269552010-12-14 14:59:29 +00007341 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007342 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007343 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007344 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307345 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007346 return status;
7347}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007348
7349/*
7350 * Decode GETDEVINFO response
7351 */
Chuck Leverbf269552010-12-14 14:59:29 +00007352static int nfs4_xdr_dec_getdeviceinfo(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_getdeviceinfo_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 != 0)
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 != 0)
7365 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007366 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007367out:
7368 return status;
7369}
7370
7371/*
7372 * Decode LAYOUTGET response
7373 */
Chuck Leverbf269552010-12-14 14:59:29 +00007374static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7375 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007376 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007377{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007378 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007379 struct compound_hdr hdr;
7380 int status;
7381
Chuck Leverbf269552010-12-14 14:59:29 +00007382 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007383 if (status)
7384 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007385 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007386 if (status)
7387 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007388 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007389 if (status)
7390 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007391 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007392out:
7393 return status;
7394}
Andy Adamson863a3c62011-03-23 13:27:54 +00007395
7396/*
Benny Halevycbe82602011-05-22 19:52:37 +03007397 * Decode LAYOUTRETURN response
7398 */
7399static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7400 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007401 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007402{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007403 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007404 struct compound_hdr hdr;
7405 int status;
7406
7407 status = decode_compound_hdr(xdr, &hdr);
7408 if (status)
7409 goto out;
7410 status = decode_sequence(xdr, &res->seq_res, rqstp);
7411 if (status)
7412 goto out;
7413 status = decode_putfh(xdr);
7414 if (status)
7415 goto out;
7416 status = decode_layoutreturn(xdr, res);
7417out:
7418 return status;
7419}
7420
7421/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007422 * Decode LAYOUTCOMMIT response
7423 */
7424static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7425 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007426 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007427{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007428 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007429 struct compound_hdr hdr;
7430 int status;
7431
7432 status = decode_compound_hdr(xdr, &hdr);
7433 if (status)
7434 goto out;
7435 status = decode_sequence(xdr, &res->seq_res, rqstp);
7436 if (status)
7437 goto out;
7438 status = decode_putfh(xdr);
7439 if (status)
7440 goto out;
7441 status = decode_layoutcommit(xdr, rqstp, res);
7442 if (status)
7443 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007444 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007445out:
7446 return status;
7447}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007448
7449/*
7450 * Decode SECINFO_NO_NAME response
7451 */
7452static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7453 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007454 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007455{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007456 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007457 struct compound_hdr hdr;
7458 int status;
7459
7460 status = decode_compound_hdr(xdr, &hdr);
7461 if (status)
7462 goto out;
7463 status = decode_sequence(xdr, &res->seq_res, rqstp);
7464 if (status)
7465 goto out;
7466 status = decode_putrootfh(xdr);
7467 if (status)
7468 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007469 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007470out:
7471 return status;
7472}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007473
7474/*
7475 * Decode TEST_STATEID response
7476 */
7477static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7478 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007479 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007480{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007481 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -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_test_stateid(xdr, res);
7492out:
7493 return status;
7494}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007495
7496/*
7497 * Decode FREE_STATEID response
7498 */
7499static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7500 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007501 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007502{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007503 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007504 struct compound_hdr hdr;
7505 int status;
7506
7507 status = decode_compound_hdr(xdr, &hdr);
7508 if (status)
7509 goto out;
7510 status = decode_sequence(xdr, &res->seq_res, rqstp);
7511 if (status)
7512 goto out;
7513 status = decode_free_stateid(xdr, res);
7514out:
7515 return status;
7516}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007517#endif /* CONFIG_NFS_V4_1 */
7518
Chuck Lever573c4e12010-12-14 14:58:11 +00007519/**
7520 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7521 * the local page cache.
7522 * @xdr: XDR stream where entry resides
7523 * @entry: buffer to fill in with entry data
7524 * @plus: boolean indicating whether this should be a readdirplus entry
7525 *
7526 * Returns zero if successful, otherwise a negative errno value is
7527 * returned.
7528 *
7529 * This function is not invoked during READDIR reply decoding, but
7530 * rather whenever an application invokes the getdents(2) system call
7531 * on a directory already in our cache.
7532 */
7533int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007534 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007535{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007536 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007537 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007538 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007539 __be32 *p = xdr_inline_decode(xdr, 4);
7540 if (unlikely(!p))
7541 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007542 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007543 p = xdr_inline_decode(xdr, 4);
7544 if (unlikely(!p))
7545 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007546 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007547 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007548 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007549 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007550 }
7551
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007552 p = xdr_inline_decode(xdr, 12);
7553 if (unlikely(!p))
7554 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007555 entry->prev_cookie = entry->cookie;
7556 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007557 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007558
Trond Myklebust9af8c222010-10-24 11:52:55 -04007559 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007560 if (unlikely(!p))
7561 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007562 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007563
7564 /*
7565 * In case the server doesn't return an inode number,
7566 * we fake one here. (We don't use inode number 0,
7567 * since glibc seems to choke on it...)
7568 */
7569 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007570 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007571
Trond Myklebust9af8c222010-10-24 11:52:55 -04007572 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007573 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007574
Trond Myklebust256e48b2012-06-21 11:18:13 -04007575 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007576 goto out_overflow;
7577
Chuck Lever573c4e12010-12-14 14:58:11 +00007578 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007579 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007580 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007581 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7582 entry->ino = entry->fattr->mounted_on_fileid;
7583 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007584 entry->ino = entry->fattr->fileid;
7585
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007586 entry->d_type = DT_UNKNOWN;
7587 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7588 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7589
Chuck Lever573c4e12010-12-14 14:58:11 +00007590 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007591
7592out_overflow:
7593 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007594 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007595}
7596
7597/*
7598 * We need to translate between nfs status return values and
7599 * the local errno values which may not be the same.
7600 */
7601static struct {
7602 int stat;
7603 int errno;
7604} nfs_errtbl[] = {
7605 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007606 { NFS4ERR_PERM, -EPERM },
7607 { NFS4ERR_NOENT, -ENOENT },
7608 { NFS4ERR_IO, -errno_NFSERR_IO},
7609 { NFS4ERR_NXIO, -ENXIO },
7610 { NFS4ERR_ACCESS, -EACCES },
7611 { NFS4ERR_EXIST, -EEXIST },
7612 { NFS4ERR_XDEV, -EXDEV },
7613 { NFS4ERR_NOTDIR, -ENOTDIR },
7614 { NFS4ERR_ISDIR, -EISDIR },
7615 { NFS4ERR_INVAL, -EINVAL },
7616 { NFS4ERR_FBIG, -EFBIG },
7617 { NFS4ERR_NOSPC, -ENOSPC },
7618 { NFS4ERR_ROFS, -EROFS },
7619 { NFS4ERR_MLINK, -EMLINK },
7620 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7621 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7622 { NFS4ERR_DQUOT, -EDQUOT },
7623 { NFS4ERR_STALE, -ESTALE },
7624 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007625 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7626 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7627 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007628 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007629 { NFS4ERR_BADTYPE, -EBADTYPE },
7630 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007631 { NFS4ERR_SYMLINK, -ELOOP },
7632 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7633 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007634 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007635};
7636
7637/*
7638 * Convert an NFS error code to a local one.
7639 * This one is used jointly by NFSv2 and NFSv3.
7640 */
7641static int
David Howells0a8ea432006-08-22 20:06:08 -04007642nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007643{
7644 int i;
7645 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7646 if (nfs_errtbl[i].stat == stat)
7647 return nfs_errtbl[i].errno;
7648 }
7649 if (stat <= 10000 || stat > 10100) {
7650 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007651 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007652 }
7653 /* If we cannot translate the error, the recovery routines should
7654 * handle it.
7655 * Note: remaining NFSv4 error codes have values > 10000, so should
7656 * not conflict with native Linux error codes.
7657 */
Benny Halevy856dff32008-03-31 17:39:06 +03007658 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007659}
7660
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007661#ifdef CONFIG_NFS_V4_2
7662#include "nfs42xdr.c"
7663#endif /* CONFIG_NFS_V4_2 */
7664
Linus Torvalds1da177e2005-04-16 15:20:36 -07007665#define PROC(proc, argtype, restype) \
7666[NFSPROC4_CLNT_##proc] = { \
7667 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007668 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007669 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007670 .p_arglen = NFS4_##argtype##_sz, \
7671 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007672 .p_statidx = NFSPROC4_CLNT_##proc, \
7673 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007674}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007675
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007676#define STUB(proc) \
7677[NFSPROC4_CLNT_##proc] = { \
7678 .p_name = #proc, \
7679}
7680
Christoph Hellwig511e9362017-05-12 15:36:49 +02007681const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007682 PROC(READ, enc_read, dec_read),
7683 PROC(WRITE, enc_write, dec_write),
7684 PROC(COMMIT, enc_commit, dec_commit),
7685 PROC(OPEN, enc_open, dec_open),
7686 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7687 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7688 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7689 PROC(CLOSE, enc_close, dec_close),
7690 PROC(SETATTR, enc_setattr, dec_setattr),
7691 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7692 PROC(RENEW, enc_renew, dec_renew),
7693 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7694 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7695 PROC(LOCK, enc_lock, dec_lock),
7696 PROC(LOCKT, enc_lockt, dec_lockt),
7697 PROC(LOCKU, enc_locku, dec_locku),
7698 PROC(ACCESS, enc_access, dec_access),
7699 PROC(GETATTR, enc_getattr, dec_getattr),
7700 PROC(LOOKUP, enc_lookup, dec_lookup),
Jeff Layton5b5faaf2017-06-29 06:34:52 -07007701 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Chuck Lever7d93bd712010-12-14 14:57:42 +00007702 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7703 PROC(REMOVE, enc_remove, dec_remove),
7704 PROC(RENAME, enc_rename, dec_rename),
7705 PROC(LINK, enc_link, dec_link),
7706 PROC(SYMLINK, enc_symlink, dec_symlink),
7707 PROC(CREATE, enc_create, dec_create),
7708 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7709 PROC(STATFS, enc_statfs, dec_statfs),
7710 PROC(READLINK, enc_readlink, dec_readlink),
7711 PROC(READDIR, enc_readdir, dec_readdir),
7712 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7713 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7714 PROC(GETACL, enc_getacl, dec_getacl),
7715 PROC(SETACL, enc_setacl, dec_setacl),
7716 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7717 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007718 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007719 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007720#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007721 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7722 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7723 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7724 PROC(SEQUENCE, enc_sequence, dec_sequence),
7725 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7726 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7727 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7728 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007729 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007730 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007731 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007732 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007733 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007734 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007735 PROC(BIND_CONN_TO_SESSION,
7736 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007737 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007738#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007739#ifdef CONFIG_NFS_V4_2
7740 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007741 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007742 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007743 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007744 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007745 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007746#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007747};
7748
Christoph Hellwigc5518582017-05-08 23:27:10 +02007749static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007750const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007751 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007752 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007753 .procs = nfs4_procedures,
7754 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007755};
7756
7757/*
7758 * Local variables:
7759 * c-basic-offset: 8
7760 * End:
7761 */