blob: 3d088230c975c02c9f035fb3ebe757d400779624 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/nfs/nfs4xdr.c
3 *
4 * Client-side XDR for NFSv4.
5 *
6 * Copyright (c) 2002 The Regents of the University of Michigan.
7 * All rights reserved.
8 *
9 * Kendrick Smith <kmsmith@umich.edu>
10 * Andy Adamson <andros@umich.edu>
Andy Adamson6c0195a2008-12-23 16:06:15 -050011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include <linux/param.h>
39#include <linux/time.h>
40#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/errno.h>
42#include <linux/string.h>
43#include <linux/in.h>
44#include <linux/pagemap.h>
45#include <linux/proc_fs.h>
46#include <linux/kdev_t.h>
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -050047#include <linux/module.h>
48#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/sunrpc/clnt.h>
Alexandros Batsakis2449ea22009-12-05 13:36:55 -050050#include <linux/sunrpc/msg_prot.h>
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +000051#include <linux/sunrpc/gss_api.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/nfs.h>
53#include <linux/nfs4.h>
54#include <linux/nfs_fs.h>
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -050055#include <linux/fs_struct.h>
Chuck Leverf0920752012-05-21 22:45:41 -040056
Trond Myklebust4ce79712005-06-22 17:16:21 +000057#include "nfs4_fs.h"
Alexandros Batsakis4882ef72009-12-05 13:30:21 -050058#include "internal.h"
Anna Schumaker40c64c22015-04-15 13:00:05 -040059#include "nfs4idmap.h"
Trond Myklebust76e697b2012-11-26 14:20:49 -050060#include "nfs4session.h"
Andy Adamsonb1f69b72010-10-20 00:18:03 -040061#include "pnfs.h"
Chuck Leverf0920752012-05-21 22:45:41 -040062#include "netns.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#define NFSDBG_FACILITY NFSDBG_XDR
65
66/* Mapping from NFS error code to "errno" error code. */
67#define errno_NFSERR_IO EIO
68
David Howells0a8ea432006-08-22 20:06:08 -040069static int nfs4_stat_to_errno(int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71/* NFSv4 COMPOUND tags are only wanted for debugging purposes */
72#ifdef DEBUG
73#define NFS4_MAXTAGLEN 20
74#else
75#define NFS4_MAXTAGLEN 0
76#endif
77
Andy Adamson6c0195a2008-12-23 16:06:15 -050078/* lock,open owner id:
Trond Myklebust9f958ab2007-07-02 13:58:33 -040079 * we currently use size 2 (u64) out of (NFS4_OPAQUE_LIMIT >> 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 */
Trond Myklebust95b72eb2012-04-20 19:24:51 -040081#define open_owner_id_maxsz (1 + 2 + 1 + 1 + 2)
Trond Myklebustd035c362010-12-21 10:45:27 -050082#define lock_owner_id_maxsz (1 + 1 + 4)
Trond Myklebust9104a552007-07-17 21:52:42 -040083#define decode_lockowner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#define compound_encode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
85#define compound_decode_hdr_maxsz (3 + (NFS4_MAXTAGLEN >> 2))
86#define op_encode_hdr_maxsz (1)
87#define op_decode_hdr_maxsz (2)
Trond Myklebust9104a552007-07-17 21:52:42 -040088#define encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
89#define decode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
90#define encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
91#define decode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#define encode_putfh_maxsz (op_encode_hdr_maxsz + 1 + \
93 (NFS4_FHSIZE >> 2))
94#define decode_putfh_maxsz (op_decode_hdr_maxsz)
95#define encode_putrootfh_maxsz (op_encode_hdr_maxsz)
96#define decode_putrootfh_maxsz (op_decode_hdr_maxsz)
97#define encode_getfh_maxsz (op_encode_hdr_maxsz)
98#define decode_getfh_maxsz (op_decode_hdr_maxsz + 1 + \
99 ((3+NFS4_FHSIZE) >> 2))
Andy Adamsone5012d12011-07-11 17:17:42 -0400100#define nfs4_fattr_bitmap_maxsz 4
J. Bruce Fields96928202005-06-22 17:16:22 +0000101#define encode_getattr_maxsz (op_encode_hdr_maxsz + nfs4_fattr_bitmap_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define nfs4_name_maxsz (1 + ((3 + NFS4_MAXNAMLEN) >> 2))
103#define nfs4_path_maxsz (1 + ((3 + NFS4_MAXPATHLEN) >> 2))
Trond Myklebustbd625ba2007-07-08 18:38:23 -0400104#define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
105#define nfs4_group_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
David Quigleyaa9c2662013-05-22 12:50:44 -0400106#ifdef CONFIG_NFS_V4_SECURITY_LABEL
107/* PI(4 bytes) + LFS(4 bytes) + 1(for null terminator?) + MAXLABELLEN */
108#define nfs4_label_maxsz (4 + 4 + 1 + XDR_QUADLEN(NFS4_MAXLABELLEN))
David Quigleyaa9c2662013-05-22 12:50:44 -0400109#else
110#define nfs4_label_maxsz 0
David Quigleyaa9c2662013-05-22 12:50:44 -0400111#endif
Andy Adamson88034c32012-05-23 05:02:34 -0400112/* We support only one layout type per file system */
113#define decode_mdsthreshold_maxsz (1 + 1 + nfs4_fattr_bitmap_maxsz + 1 + 8)
J. Bruce Fields96928202005-06-22 17:16:22 +0000114/* This is based on getfattr, which uses the most attributes: */
115#define nfs4_fattr_value_maxsz (1 + (1 + 2 + 2 + 4 + 2 + 1 + 1 + 2 + 2 + \
Andy Adamson88034c32012-05-23 05:02:34 -0400116 3 + 3 + 3 + nfs4_owner_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400117 nfs4_group_maxsz + nfs4_label_maxsz + \
118 decode_mdsthreshold_maxsz))
J. Bruce Fields96928202005-06-22 17:16:22 +0000119#define nfs4_fattr_maxsz (nfs4_fattr_bitmap_maxsz + \
120 nfs4_fattr_value_maxsz)
121#define decode_getattr_maxsz (op_decode_hdr_maxsz + nfs4_fattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400122#define encode_attrs_maxsz (nfs4_fattr_bitmap_maxsz + \
123 1 + 2 + 1 + \
124 nfs4_owner_maxsz + \
125 nfs4_group_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400126 nfs4_label_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400127 4 + 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#define encode_savefh_maxsz (op_encode_hdr_maxsz)
129#define decode_savefh_maxsz (op_decode_hdr_maxsz)
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400130#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
131#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
Fred Isaman2f42b5d2008-03-13 15:26:30 +0200132#define encode_fsinfo_maxsz (encode_getattr_maxsz)
Fred Isamandae100c2011-07-30 20:52:37 -0400133/* The 5 accounts for the PNFS attributes, and assumes that at most three
134 * layout types will be returned.
135 */
136#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + \
137 nfs4_fattr_bitmap_maxsz + 4 + 8 + 5)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
139#define decode_renew_maxsz (op_decode_hdr_maxsz)
140#define encode_setclientid_maxsz \
141 (op_encode_hdr_maxsz + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500142 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400143 /* client name */ \
144 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500145 1 /* sc_prog */ + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500146 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
147 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN) + \
Chuck Levercc38bac2007-12-10 14:56:54 -0500148 1) /* sc_cb_ident */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define decode_setclientid_maxsz \
150 (op_decode_hdr_maxsz + \
Chuck Lever6dd34362014-11-08 20:15:18 -0500151 2 /* clientid */ + \
152 XDR_QUADLEN(NFS4_VERIFIER_SIZE) + \
153 1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN) + \
154 1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#define encode_setclientid_confirm_maxsz \
156 (op_encode_hdr_maxsz + \
157 3 + (NFS4_VERIFIER_SIZE >> 2))
158#define decode_setclientid_confirm_maxsz \
159 (op_decode_hdr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400160#define encode_lookup_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
161#define decode_lookup_maxsz (op_decode_hdr_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700162#define encode_lookupp_maxsz (op_encode_hdr_maxsz)
163#define decode_lookupp_maxsz (op_decode_hdr_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400164#define encode_share_access_maxsz \
165 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500166#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400167#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
168#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
169#define encode_open_maxsz (op_encode_hdr_maxsz + \
170 2 + encode_share_access_maxsz + 2 + \
171 open_owner_id_maxsz + \
172 encode_opentype_maxsz + \
173 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500174#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400175#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400176#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500177 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400178 decode_ace_maxsz)
179#define decode_change_info_maxsz (5)
180#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400181 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400182 decode_change_info_maxsz + 1 + \
183 nfs4_fattr_bitmap_maxsz + \
184 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400185#define encode_open_confirm_maxsz \
186 (op_encode_hdr_maxsz + \
187 encode_stateid_maxsz + 1)
188#define decode_open_confirm_maxsz \
189 (op_decode_hdr_maxsz + \
190 decode_stateid_maxsz)
191#define encode_open_downgrade_maxsz \
192 (op_encode_hdr_maxsz + \
193 encode_stateid_maxsz + 1 + \
194 encode_share_access_maxsz)
195#define decode_open_downgrade_maxsz \
196 (op_decode_hdr_maxsz + \
197 decode_stateid_maxsz)
198#define encode_close_maxsz (op_encode_hdr_maxsz + \
199 1 + encode_stateid_maxsz)
200#define decode_close_maxsz (op_decode_hdr_maxsz + \
201 decode_stateid_maxsz)
202#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
203 encode_stateid_maxsz + \
204 encode_attrs_maxsz)
205#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
206 nfs4_fattr_bitmap_maxsz)
207#define encode_read_maxsz (op_encode_hdr_maxsz + \
208 encode_stateid_maxsz + 3)
209#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
210#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400211 2 + encode_verifier_maxsz + 5 + \
212 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400213#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400214 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400215#define encode_readlink_maxsz (op_encode_hdr_maxsz)
216#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
217#define encode_write_maxsz (op_encode_hdr_maxsz + \
218 encode_stateid_maxsz + 4)
219#define decode_write_maxsz (op_decode_hdr_maxsz + \
220 2 + decode_verifier_maxsz)
221#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
222#define decode_commit_maxsz (op_decode_hdr_maxsz + \
223 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224#define encode_remove_maxsz (op_encode_hdr_maxsz + \
225 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400226#define decode_remove_maxsz (op_decode_hdr_maxsz + \
227 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228#define encode_rename_maxsz (op_encode_hdr_maxsz + \
229 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400230#define decode_rename_maxsz (op_decode_hdr_maxsz + \
231 decode_change_info_maxsz + \
232 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233#define encode_link_maxsz (op_encode_hdr_maxsz + \
234 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400235#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400236#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400237#define encode_lock_maxsz (op_encode_hdr_maxsz + \
238 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400239 1 + encode_stateid_maxsz + 1 + \
240 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400241#define decode_lock_denied_maxsz \
242 (8 + decode_lockowner_maxsz)
243#define decode_lock_maxsz (op_decode_hdr_maxsz + \
244 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400245#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
246 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400247#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
248 decode_lock_denied_maxsz)
249#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
250 encode_stateid_maxsz + \
251 4)
252#define decode_locku_maxsz (op_decode_hdr_maxsz + \
253 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400254#define encode_release_lockowner_maxsz \
255 (op_encode_hdr_maxsz + \
256 encode_lockowner_maxsz)
257#define decode_release_lockowner_maxsz \
258 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400259#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
260#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
262 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400263 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000264 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
266#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400267 1 + 2 + nfs4_name_maxsz + \
268 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400269#define decode_create_maxsz (op_decode_hdr_maxsz + \
270 decode_change_info_maxsz + \
271 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400272#define encode_statfs_maxsz (encode_getattr_maxsz)
273#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
275#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400276#define encode_getacl_maxsz (encode_getattr_maxsz)
277#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
278 nfs4_fattr_bitmap_maxsz + 1)
279#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
280 encode_stateid_maxsz + 3)
281#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400282#define encode_fs_locations_maxsz \
283 (encode_getattr_maxsz)
284#define decode_fs_locations_maxsz \
285 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000286#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400287#define decode_secinfo_maxsz (op_decode_hdr_maxsz + 1 + ((NFS_MAX_SECFLAVORS * (16 + GSS_OID_MAX_LEN)) / 4))
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400288
289#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400290#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500291#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
292 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400293
Benny Halevy99fe60d2009-04-01 09:22:29 -0400294#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
295 encode_verifier_maxsz + \
296 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400297 /* eia_clientowner */ \
298 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400299 1 /* flags */ + \
300 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400301 /* max is SP4_MACH_CRED (for now) */ + \
302 1 + NFS4_OP_MAP_NUM_WORDS + \
303 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500304 1 /* implementation id array of size 1 */ + \
305 1 /* nii_domain */ + \
306 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
307 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500308 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500309 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400310#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
311 2 /* eir_clientid */ + \
312 1 /* eir_sequenceid */ + \
313 1 /* eir_flags */ + \
314 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400315 /* max is SP4_MACH_CRED (for now) */ + \
316 1 + NFS4_OP_MAP_NUM_WORDS + \
317 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400318 2 /* eir_server_owner.so_minor_id */ + \
319 /* eir_server_owner.so_major_id<> */ \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
321 /* eir_server_scope<> */ \
322 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
323 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500324 1 /* nii_domain */ + \
325 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
326 1 /* nii_name */ + \
327 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
328 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400329#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
330#define decode_channel_attrs_maxsz (6 + \
331 1 /* ca_rdma_ird.len */ + \
332 1 /* ca_rdma_ird */)
333#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
334 2 /* csa_clientid */ + \
335 1 /* csa_sequence */ + \
336 1 /* csa_flags */ + \
337 encode_channel_attrs_maxsz + \
338 encode_channel_attrs_maxsz + \
339 1 /* csa_cb_program */ + \
340 1 /* csa_sec_parms.len (1) */ + \
341 1 /* cb_secflavor (AUTH_SYS) */ + \
342 1 /* stamp */ + \
343 1 /* machinename.len */ + \
344 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
345 1 /* uid */ + \
346 1 /* gid */ + \
347 1 /* gids.len (0) */)
348#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
349 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
350 1 /* csr_sequence */ + \
351 1 /* csr_flags */ + \
352 decode_channel_attrs_maxsz + \
353 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400354#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
355 /* bctsa_sessid */ \
356 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
357 1 /* bctsa_dir */ + \
358 1 /* bctsa_use_conn_in_rdma_mode */)
359#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
360 /* bctsr_sessid */ \
361 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
362 1 /* bctsr_dir */ + \
363 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400364#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
365#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400366#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
367#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400368#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
369 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
370#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
371 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500372#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
373#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700374#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
375 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
376 1 /* layout type */ + \
377 1 /* maxcount */ + \
378 1 /* bitmap size */ + \
379 1 /* notification bitmap length */ + \
380 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400381#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
382 1 /* layout type */ + \
383 1 /* opaque devaddr4 length */ + \
384 /* devaddr4 payload is read into page */ \
385 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700386 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400387#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
388 encode_stateid_maxsz)
389#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
390 decode_stateid_maxsz + \
391 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000392#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
393 2 /* offset */ + \
394 2 /* length */ + \
395 1 /* reclaim */ + \
396 encode_stateid_maxsz + \
397 1 /* new offset (true) */ + \
398 2 /* last byte written */ + \
399 1 /* nt_timechanged (false) */ + \
400 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500401 1 /* layoutupdate4 opaqueue len */)
402 /* the actual content of layoutupdate4 should
403 be allocated by drivers and spliced in
404 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000405#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300406#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
407 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400408 1 + \
409 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300410#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
411 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400412#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
413#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400414#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
415 XDR_QUADLEN(NFS4_STATEID_SIZE))
416#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400417#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
418 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400419#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400420#else /* CONFIG_NFS_V4_1 */
421#define encode_sequence_maxsz 0
422#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500423#define encode_layoutreturn_maxsz 0
424#define decode_layoutreturn_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400425#endif /* CONFIG_NFS_V4_1 */
426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
428#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
429#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400430 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400432 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400434 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400436 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400438 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400440 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400442 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400444 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400446 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400448 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400450 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400452 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400454 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400456 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400457 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400459 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400461 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400462 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400464 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400466 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400468 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400470 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400472 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400473 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400475 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400476 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400477 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400479 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400480 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400481 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400482 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400483 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400484 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400485#define NFS4_enc_open_confirm_sz \
486 (compound_encode_hdr_maxsz + \
487 encode_putfh_maxsz + \
488 encode_open_confirm_maxsz)
489#define NFS4_dec_open_confirm_sz \
490 (compound_decode_hdr_maxsz + \
491 decode_putfh_maxsz + \
492 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400494 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400497 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400498 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400500 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400502 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400503 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400504 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505#define NFS4_enc_open_downgrade_sz \
506 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400507 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400508 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500509 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400510 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#define NFS4_dec_open_downgrade_sz \
512 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400513 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400514 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500515 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400516 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400517#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400518 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400519 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500520 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400521 encode_close_maxsz + \
522 encode_getattr_maxsz)
523#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400524 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500526 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400527 decode_close_maxsz + \
528 decode_getattr_maxsz)
529#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400530 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400531 encode_putfh_maxsz + \
532 encode_setattr_maxsz + \
533 encode_getattr_maxsz)
534#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400535 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400536 decode_putfh_maxsz + \
537 decode_setattr_maxsz + \
538 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400540 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 encode_putfh_maxsz + \
542 encode_fsinfo_maxsz)
543#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400544 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 decode_putfh_maxsz + \
546 decode_fsinfo_maxsz)
547#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
548 encode_renew_maxsz)
549#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
550 decode_renew_maxsz)
551#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
552 encode_setclientid_maxsz)
553#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
554 decode_setclientid_maxsz)
555#define NFS4_enc_setclientid_confirm_sz \
556 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400557 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558#define NFS4_dec_setclientid_confirm_sz \
559 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400560 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400562 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400564 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400566 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400568 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400570 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400572 encode_lockt_maxsz)
573#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400574 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400575 decode_putfh_maxsz + \
576 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400578 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400580 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400582 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400584 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400585#define NFS4_enc_release_lockowner_sz \
586 (compound_encode_hdr_maxsz + \
587 encode_lockowner_maxsz)
588#define NFS4_dec_release_lockowner_sz \
589 (compound_decode_hdr_maxsz + \
590 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400592 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400594 encode_access_maxsz + \
595 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400597 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400599 decode_access_maxsz + \
600 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400602 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400604 encode_getattr_maxsz + \
605 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400607 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400609 decode_getattr_maxsz + \
610 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400612 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 encode_putfh_maxsz + \
614 encode_lookup_maxsz + \
615 encode_getattr_maxsz + \
616 encode_getfh_maxsz)
617#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400618 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400620 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 decode_getattr_maxsz + \
622 decode_getfh_maxsz)
Jeff Layton5b5faaf2017-06-29 06:34:52 -0700623#define NFS4_enc_lookupp_sz (compound_encode_hdr_maxsz + \
624 encode_sequence_maxsz + \
625 encode_putfh_maxsz + \
626 encode_lookupp_maxsz + \
627 encode_getattr_maxsz + \
628 encode_getfh_maxsz)
629#define NFS4_dec_lookupp_sz (compound_decode_hdr_maxsz + \
630 decode_sequence_maxsz + \
631 decode_putfh_maxsz + \
632 decode_lookupp_maxsz + \
633 decode_getattr_maxsz + \
634 decode_getfh_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 encode_putrootfh_maxsz + \
638 encode_getattr_maxsz + \
639 encode_getfh_maxsz)
640#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400641 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 decode_putrootfh_maxsz + \
643 decode_getattr_maxsz + \
644 decode_getfh_maxsz)
645#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400648 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400650 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400652 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400654 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 encode_putfh_maxsz + \
656 encode_savefh_maxsz + \
657 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400658 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400660 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 decode_putfh_maxsz + \
662 decode_savefh_maxsz + \
663 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400664 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400666 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 encode_putfh_maxsz + \
668 encode_savefh_maxsz + \
669 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400670 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400671 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400672 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673#define NFS4_dec_link_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400674 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 decode_putfh_maxsz + \
676 decode_savefh_maxsz + \
677 decode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400678 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400679 decode_restorefh_maxsz + \
680 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400682 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 encode_putfh_maxsz + \
684 encode_symlink_maxsz + \
685 encode_getattr_maxsz + \
686 encode_getfh_maxsz)
687#define NFS4_dec_symlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400688 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 decode_putfh_maxsz + \
690 decode_symlink_maxsz + \
691 decode_getattr_maxsz + \
692 decode_getfh_maxsz)
693#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400694 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 encode_putfh_maxsz + \
696 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400697 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400698 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 decode_putfh_maxsz + \
702 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400703 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400704 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400706 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 encode_putfh_maxsz + \
708 encode_getattr_maxsz)
709#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400710 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 decode_putfh_maxsz + \
712 decode_getattr_maxsz)
713#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400714 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400716 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400718 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400720 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800723 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 encode_getattr_maxsz)
725#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400726 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800727 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 decode_getattr_maxsz)
729#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400730 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500732 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100733 encode_delegreturn_maxsz + \
734 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400736 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500737 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500738 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100739 decode_delegreturn_maxsz + \
740 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000741#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400742 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000743 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400744 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000745#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400746 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000747 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400748 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000749#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400750 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000751 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400752 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000753#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400754 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000755 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400756 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400757#define NFS4_enc_fs_locations_sz \
758 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400759 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400760 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400761 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400762 encode_fs_locations_maxsz + \
763 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400764#define NFS4_dec_fs_locations_sz \
765 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400766 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400767 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400768 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400769 decode_fs_locations_maxsz + \
770 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000771#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
772 encode_sequence_maxsz + \
773 encode_putfh_maxsz + \
774 encode_secinfo_maxsz)
775#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
776 decode_sequence_maxsz + \
777 decode_putfh_maxsz + \
778 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400779#define NFS4_enc_fsid_present_sz \
780 (compound_encode_hdr_maxsz + \
781 encode_sequence_maxsz + \
782 encode_putfh_maxsz + \
783 encode_getfh_maxsz + \
784 encode_renew_maxsz)
785#define NFS4_dec_fsid_present_sz \
786 (compound_decode_hdr_maxsz + \
787 decode_sequence_maxsz + \
788 decode_putfh_maxsz + \
789 decode_getfh_maxsz + \
790 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400791#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400792#define NFS4_enc_bind_conn_to_session_sz \
793 (compound_encode_hdr_maxsz + \
794 encode_bind_conn_to_session_maxsz)
795#define NFS4_dec_bind_conn_to_session_sz \
796 (compound_decode_hdr_maxsz + \
797 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400798#define NFS4_enc_exchange_id_sz \
799 (compound_encode_hdr_maxsz + \
800 encode_exchange_id_maxsz)
801#define NFS4_dec_exchange_id_sz \
802 (compound_decode_hdr_maxsz + \
803 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400804#define NFS4_enc_create_session_sz \
805 (compound_encode_hdr_maxsz + \
806 encode_create_session_maxsz)
807#define NFS4_dec_create_session_sz \
808 (compound_decode_hdr_maxsz + \
809 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400810#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
811 encode_destroy_session_maxsz)
812#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
813 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400814#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
815 encode_destroy_clientid_maxsz)
816#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
817 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400818#define NFS4_enc_sequence_sz \
819 (compound_decode_hdr_maxsz + \
820 encode_sequence_maxsz)
821#define NFS4_dec_sequence_sz \
822 (compound_decode_hdr_maxsz + \
823 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400824#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
825 encode_sequence_maxsz + \
826 encode_putrootfh_maxsz + \
827 encode_fsinfo_maxsz)
828#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
829 decode_sequence_maxsz + \
830 decode_putrootfh_maxsz + \
831 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500832#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
833 encode_sequence_maxsz + \
834 encode_reclaim_complete_maxsz)
835#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
836 decode_sequence_maxsz + \
837 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400838#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
839 encode_sequence_maxsz +\
840 encode_getdeviceinfo_maxsz)
841#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
842 decode_sequence_maxsz + \
843 decode_getdeviceinfo_maxsz)
844#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
845 encode_sequence_maxsz + \
846 encode_putfh_maxsz + \
847 encode_layoutget_maxsz)
848#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
849 decode_sequence_maxsz + \
850 decode_putfh_maxsz + \
851 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000852#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
853 encode_sequence_maxsz +\
854 encode_putfh_maxsz + \
855 encode_layoutcommit_maxsz + \
856 encode_getattr_maxsz)
857#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
858 decode_sequence_maxsz + \
859 decode_putfh_maxsz + \
860 decode_layoutcommit_maxsz + \
861 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300862#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
863 encode_sequence_maxsz + \
864 encode_putfh_maxsz + \
865 encode_layoutreturn_maxsz)
866#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
867 decode_sequence_maxsz + \
868 decode_putfh_maxsz + \
869 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400870#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
871 encode_sequence_maxsz + \
872 encode_putrootfh_maxsz +\
873 encode_secinfo_no_name_maxsz)
874#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
875 decode_sequence_maxsz + \
876 decode_putrootfh_maxsz + \
877 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400878#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
879 encode_sequence_maxsz + \
880 encode_test_stateid_maxsz)
881#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
882 decode_sequence_maxsz + \
883 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400884#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
885 encode_sequence_maxsz + \
886 encode_free_stateid_maxsz)
887#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
888 decode_sequence_maxsz + \
889 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500890
891const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
892 compound_encode_hdr_maxsz +
893 encode_sequence_maxsz +
894 encode_putfh_maxsz +
895 encode_getattr_maxsz) *
896 XDR_UNIT);
897
898const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
899 compound_decode_hdr_maxsz +
900 decode_sequence_maxsz +
901 decode_putfh_maxsz) *
902 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400903
904const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
905 compound_decode_hdr_maxsz +
906 decode_sequence_maxsz) *
907 XDR_UNIT);
908EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400909#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
Trond Myklebustbca79472009-03-11 14:10:26 -0400911static const umode_t nfs_type2fmt[] = {
912 [NF4BAD] = 0,
913 [NF4REG] = S_IFREG,
914 [NF4DIR] = S_IFDIR,
915 [NF4BLK] = S_IFBLK,
916 [NF4CHR] = S_IFCHR,
917 [NF4LNK] = S_IFLNK,
918 [NF4SOCK] = S_IFSOCK,
919 [NF4FIFO] = S_IFIFO,
920 [NF4ATTRDIR] = 0,
921 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922};
923
924struct compound_hdr {
925 int32_t status;
926 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500927 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 uint32_t taglen;
929 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400930 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400931 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932};
933
Benny Halevy13c65ce2009-08-14 17:19:25 +0300934static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
935{
936 __be32 *p = xdr_reserve_space(xdr, nbytes);
937 BUG_ON(!p);
938 return p;
939}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
Trond Myklebustcb17e552012-03-04 18:13:56 -0500941static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
942{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500943 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500944}
945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
947{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500948 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
Trond Myklebust4ade9822012-03-04 18:13:57 -0500951static void encode_uint32(struct xdr_stream *xdr, u32 n)
952{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500953 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500954}
955
Trond Myklebustff2eb682012-03-05 11:40:12 -0500956static void encode_uint64(struct xdr_stream *xdr, u64 n)
957{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500958 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500959}
960
Trond Myklebust37c88762018-03-20 17:03:08 -0400961static ssize_t xdr_encode_bitmap4(struct xdr_stream *xdr,
962 const __u32 *bitmap, size_t len)
963{
964 ssize_t ret;
965
966 /* Trim empty words */
967 while (len > 0 && bitmap[len-1] == 0)
968 len--;
969 ret = xdr_stream_encode_uint32_array(xdr, bitmap, len);
970 if (WARN_ON_ONCE(ret < 0))
971 return ret;
972 return len;
973}
974
975static size_t mask_bitmap4(const __u32 *bitmap, const __u32 *mask,
976 __u32 *res, size_t len)
977{
978 size_t i;
979 __u32 tmp;
980
981 while (len > 0 && (bitmap[len-1] == 0 || mask[len-1] == 0))
982 len--;
983 for (i = len; i-- > 0;) {
984 tmp = bitmap[i] & mask[i];
985 res[i] = tmp;
986 }
987 return len;
988}
989
Trond Myklebust4ade9822012-03-04 18:13:57 -0500990static void encode_nfs4_seqid(struct xdr_stream *xdr,
991 const struct nfs_seqid *seqid)
992{
Trond Myklebusta6796412015-01-23 19:04:44 -0500993 if (seqid != NULL)
994 encode_uint32(xdr, seqid->sequence->counter);
995 else
996 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500997}
998
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400999static void encode_compound_hdr(struct xdr_stream *xdr,
1000 struct rpc_rqst *req,
1001 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Al Viro8687b632006-10-19 23:28:48 -07001003 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -04001004 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -04001005
1006 /* initialize running count of expected bytes in reply.
1007 * NOTE: the replied tag SHOULD be the same is the one sent,
1008 * but this is not required as a MUST for the server to do so. */
1009 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Trond Myklebust7fc38842012-10-15 11:51:21 -04001011 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001012 encode_string(xdr, hdr->taglen, hdr->tag);
1013 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001014 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -05001015 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +03001016 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -05001017}
1018
Trond Myklebustab19b482012-03-04 18:13:57 -05001019static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
1020 uint32_t replen,
1021 struct compound_hdr *hdr)
1022{
1023 encode_uint32(xdr, op);
1024 hdr->nops++;
1025 hdr->replen += replen;
1026}
1027
Andy Adamsond0179312008-12-23 16:06:17 -05001028static void encode_nops(struct compound_hdr *hdr)
1029{
Trond Myklebust7fc38842012-10-15 11:51:21 -04001030 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -05001031 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001034static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1035{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05001036 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001037}
1038
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
1040{
Trond Myklebustcb17e552012-03-04 18:13:56 -05001041 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042}
1043
David Quigleyaa9c2662013-05-22 12:50:44 -04001044static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1045 const struct nfs4_label *label,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001046 const umode_t *umask,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001047 const struct nfs_server *server,
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001048 const uint32_t attrmask[])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049{
1050 char owner_name[IDMAP_NAMESZ];
1051 char owner_group[IDMAP_NAMESZ];
1052 int owner_namelen = 0;
1053 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001054 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001055 uint32_t len = 0;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001056 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 /*
1059 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 */
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001061 if ((iap->ia_valid & ATTR_SIZE) && (attrmask[0] & FATTR4_WORD0_SIZE)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001062 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001064 }
1065 if (iap->ia_valid & ATTR_MODE) {
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001066 if (umask && (attrmask[2] & FATTR4_WORD2_MODE_UMASK)) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001067 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1068 len += 8;
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001069 } else if (attrmask[1] & FATTR4_WORD1_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001070 bmval[1] |= FATTR4_WORD1_MODE;
1071 len += 4;
1072 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001073 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001074 if ((iap->ia_valid & ATTR_UID) && (attrmask[1] & FATTR4_WORD1_OWNER)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001075 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001077 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001078 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 /* XXX */
1080 strcpy(owner_name, "nobody");
1081 owner_namelen = sizeof("nobody") - 1;
1082 /* goto out; */
1083 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001084 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1086 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001087 if ((iap->ia_valid & ATTR_GID) &&
1088 (attrmask[1] & FATTR4_WORD1_OWNER_GROUP)) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001089 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001091 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001092 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 strcpy(owner_group, "nobody");
1094 owner_grouplen = sizeof("nobody") - 1;
1095 /* goto out; */
1096 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001097 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1099 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001100 if (attrmask[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1101 if (iap->ia_valid & ATTR_ATIME_SET) {
1102 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1103 len += 16;
1104 } else if (iap->ia_valid & ATTR_ATIME) {
1105 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1106 len += 4;
1107 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001109 if (attrmask[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1110 if (iap->ia_valid & ATTR_MTIME_SET) {
1111 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1112 len += 16;
1113 } else if (iap->ia_valid & ATTR_MTIME) {
1114 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1115 len += 4;
1116 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001118
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001119 if (label && (attrmask[2] & FATTR4_WORD2_SECURITY_LABEL)) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001120 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1121 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1122 }
1123
Trond Myklebust40a3426c2018-03-20 17:03:09 -04001124 xdr_encode_bitmap4(xdr, bmval, ARRAY_SIZE(bmval));
1125 xdr_stream_encode_opaque_inline(xdr, (void **)&p, len);
Trond Myklebustd7067b22013-07-17 17:09:01 -04001126
1127 if (bmval[0] & FATTR4_WORD0_SIZE)
1128 p = xdr_encode_hyper(p, iap->ia_size);
1129 if (bmval[1] & FATTR4_WORD1_MODE)
1130 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1131 if (bmval[1] & FATTR4_WORD1_OWNER)
1132 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1133 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1134 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1135 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1136 if (iap->ia_valid & ATTR_ATIME_SET) {
1137 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1138 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1139 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1140 } else
1141 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1142 }
1143 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1144 if (iap->ia_valid & ATTR_MTIME_SET) {
1145 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1146 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1147 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1148 } else
1149 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1150 }
1151 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001152 *p++ = cpu_to_be32(label->lfs);
1153 *p++ = cpu_to_be32(label->pi);
1154 *p++ = cpu_to_be32(label->len);
1155 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1156 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001157 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1158 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1159 *p++ = cpu_to_be32(*umask);
1160 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001165static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001167 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1168 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001171static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Trond Myklebustab19b482012-03-04 18:13:57 -05001173 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001174 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001175 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176}
1177
Fred Isaman0b7c0152012-04-20 14:47:39 -04001178static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Al Viro8687b632006-10-19 23:28:48 -07001180 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001181
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001182 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1183 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001184 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001185 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001188static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
Al Viro8687b632006-10-19 23:28:48 -07001190 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001191
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001192 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1193 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 switch (create->ftype) {
1196 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001197 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001198 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001199 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1200 create->u.symlink.len);
1201 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 break;
1203
1204 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001205 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001206 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001207 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 break;
1209
1210 default:
1211 break;
1212 }
1213
Benny Halevy811652b2009-08-14 17:19:34 +03001214 encode_string(xdr, create->name->len, create->name->name);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001215 encode_attrs(xdr, create->attrs, create->label, &create->umask,
1216 create->server, create->server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217}
1218
Trond Myklebust37c88762018-03-20 17:03:08 -04001219static void encode_getattr(struct xdr_stream *xdr,
1220 const __u32 *bitmap, const __u32 *mask, size_t len,
1221 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
Trond Myklebust37c88762018-03-20 17:03:08 -04001223 __u32 masked_bitmap[nfs4_fattr_bitmap_maxsz];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001225 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04001226 if (mask) {
1227 if (WARN_ON_ONCE(len > ARRAY_SIZE(masked_bitmap)))
1228 len = ARRAY_SIZE(masked_bitmap);
1229 len = mask_bitmap4(bitmap, mask, masked_bitmap, len);
1230 bitmap = masked_bitmap;
Fred Isamandae100c2011-07-30 20:52:37 -04001231 }
Trond Myklebust37c88762018-03-20 17:03:08 -04001232 xdr_encode_bitmap4(xdr, bitmap, len);
Fred Isamandae100c2011-07-30 20:52:37 -04001233}
1234
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001235static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236{
Trond Myklebust37c88762018-03-20 17:03:08 -04001237 encode_getattr(xdr, nfs4_fattr_bitmap, bitmask,
1238 ARRAY_SIZE(nfs4_fattr_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239}
1240
Andy Adamson88034c32012-05-23 05:02:34 -04001241static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001242 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001243 struct compound_hdr *hdr)
1244{
Trond Myklebust37c88762018-03-20 17:03:08 -04001245 encode_getattr(xdr, open_bitmap, bitmask, 3, hdr);
Andy Adamson88034c32012-05-23 05:02:34 -04001246}
1247
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001248static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Trond Myklebust37c88762018-03-20 17:03:08 -04001250 encode_getattr(xdr, nfs4_fsinfo_bitmap, bitmask,
1251 ARRAY_SIZE(nfs4_fsinfo_bitmap), hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252}
1253
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001254static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001255{
Trond Myklebust37c88762018-03-20 17:03:08 -04001256 encode_getattr(xdr, nfs4_fs_locations_bitmap, bitmask,
1257 ARRAY_SIZE(nfs4_fs_locations_bitmap), hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001258}
1259
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001260static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261{
Trond Myklebustab19b482012-03-04 18:13:57 -05001262 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263}
1264
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001265static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266{
Trond Myklebustab19b482012-03-04 18:13:57 -05001267 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001268 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269}
1270
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001271static inline int nfs4_lock_type(struct file_lock *fl, int block)
1272{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001273 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001274 return block ? NFS4_READW_LT : NFS4_READ_LT;
1275 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1276}
1277
1278static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1279{
1280 if (fl->fl_end == OFFSET_MAX)
1281 return ~(uint64_t)0;
1282 return fl->fl_end - fl->fl_start + 1;
1283}
1284
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001285static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1286{
1287 __be32 *p;
1288
Trond Myklebustd035c362010-12-21 10:45:27 -05001289 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001290 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001291 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001292 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001293 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001294 xdr_encode_hyper(p, lowner->id);
1295}
1296
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297/*
1298 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1299 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1300 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001301static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
Al Viro8687b632006-10-19 23:28:48 -07001303 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001305 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1306 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001307 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1308 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001309 p = xdr_encode_hyper(p, args->fl->fl_start);
1310 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001311 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001312 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001313 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001314 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001315 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001316 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
1318 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001319 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001320 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322}
1323
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001324static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325{
Al Viro8687b632006-10-19 23:28:48 -07001326 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001328 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1329 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001330 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001331 p = xdr_encode_hyper(p, args->fl->fl_start);
1332 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001333 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334}
1335
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001336static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
Al Viro8687b632006-10-19 23:28:48 -07001338 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001340 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1341 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001342 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001343 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001344 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001345 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001346 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347}
1348
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001349static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1350{
Trond Myklebustab19b482012-03-04 18:13:57 -05001351 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001352 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001353}
1354
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001355static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356{
Trond Myklebustab19b482012-03-04 18:13:57 -05001357 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001358 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359}
1360
Jeff Layton5b5faaf2017-06-29 06:34:52 -07001361static void encode_lookupp(struct xdr_stream *xdr, struct compound_hdr *hdr)
1362{
1363 encode_op_hdr(xdr, OP_LOOKUPP, decode_lookupp_maxsz, hdr);
1364}
1365
Trond Myklebust6ae37332015-01-30 14:21:14 -05001366static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367{
Al Viro8687b632006-10-19 23:28:48 -07001368 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Benny Halevy13c65ce2009-08-14 17:19:25 +03001370 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001371 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001372 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373}
1374
1375static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1376{
Al Viro8687b632006-10-19 23:28:48 -07001377 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 /*
1379 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1380 * owner 4 = 32
1381 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001382 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001383 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001384 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001385 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001386 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001387 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001388 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001389 *p++ = cpu_to_be32(arg->id.uniquifier);
1390 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391}
1392
1393static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1394{
Al Viro8687b632006-10-19 23:28:48 -07001395 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
Benny Halevy13c65ce2009-08-14 17:19:25 +03001397 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001398 switch(arg->createmode) {
1399 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001400 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001401 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1402 arg->server, arg->server->attr_bitmask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001403 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001404 case NFS4_CREATE_GUARDED:
1405 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001406 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1407 arg->server, arg->server->attr_bitmask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001408 break;
1409 case NFS4_CREATE_EXCLUSIVE:
1410 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1411 encode_nfs4_verifier(xdr, &arg->u.verifier);
1412 break;
1413 case NFS4_CREATE_EXCLUSIVE4_1:
1414 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1415 encode_nfs4_verifier(xdr, &arg->u.verifier);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001416 encode_attrs(xdr, arg->u.attrs, arg->label, &arg->umask,
1417 arg->server, arg->server->exclcreat_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 }
1419}
1420
1421static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1422{
Al Viro8687b632006-10-19 23:28:48 -07001423 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
Benny Halevy13c65ce2009-08-14 17:19:25 +03001425 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001427 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001428 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001429 break;
1430 default:
Benny Halevy34558512009-08-14 17:19:30 +03001431 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001432 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434}
1435
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001436static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
Al Viro8687b632006-10-19 23:28:48 -07001438 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
Benny Halevy13c65ce2009-08-14 17:19:25 +03001440 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001442 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001443 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001444 break;
1445 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001446 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001447 break;
1448 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001449 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001450 break;
1451 default:
1452 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454}
1455
1456static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1457{
Al Viro8687b632006-10-19 23:28:48 -07001458 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459
Benny Halevy13c65ce2009-08-14 17:19:25 +03001460 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001461 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 encode_string(xdr, name->len, name->name);
1463}
1464
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001465static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
Al Viro8687b632006-10-19 23:28:48 -07001467 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Benny Halevy13c65ce2009-08-14 17:19:25 +03001469 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001470 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 encode_delegation_type(xdr, type);
1472}
1473
1474static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1475{
Al Viro8687b632006-10-19 23:28:48 -07001476 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001478 p = reserve_space(xdr, 4);
1479 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1480 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 encode_string(xdr, name->len, name->name);
1482}
1483
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001484static inline void encode_claim_fh(struct xdr_stream *xdr)
1485{
1486 __be32 *p;
1487
1488 p = reserve_space(xdr, 4);
1489 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1490}
1491
1492static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1493{
1494 __be32 *p;
1495
1496 p = reserve_space(xdr, 4);
1497 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1498 encode_nfs4_stateid(xdr, stateid);
1499}
1500
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001501static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502{
Trond Myklebustab19b482012-03-04 18:13:57 -05001503 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 encode_openhdr(xdr, arg);
1505 encode_opentype(xdr, arg);
1506 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001507 case NFS4_OPEN_CLAIM_NULL:
1508 encode_claim_null(xdr, arg->name);
1509 break;
1510 case NFS4_OPEN_CLAIM_PREVIOUS:
1511 encode_claim_previous(xdr, arg->u.delegation_type);
1512 break;
1513 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1514 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1515 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001516 case NFS4_OPEN_CLAIM_FH:
1517 encode_claim_fh(xdr);
1518 break;
1519 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1520 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1521 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001522 default:
1523 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525}
1526
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001527static 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 -07001528{
Trond Myklebustab19b482012-03-04 18:13:57 -05001529 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001530 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001531 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532}
1533
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001534static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535{
Trond Myklebustab19b482012-03-04 18:13:57 -05001536 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001537 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001538 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001539 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540}
1541
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001542static void
Andy Adamsond0179312008-12-23 16:06:17 -05001543encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544{
Trond Myklebustab19b482012-03-04 18:13:57 -05001545 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001546 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547}
1548
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001549static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
Trond Myklebustab19b482012-03-04 18:13:57 -05001551 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552}
1553
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001554static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1555 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
Al Viro8687b632006-10-19 23:28:48 -07001557 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Trond Myklebustab19b482012-03-04 18:13:57 -05001559 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001560 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
Benny Halevy13c65ce2009-08-14 17:19:25 +03001562 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001563 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001564 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565}
1566
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001567static 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 -07001568{
David Quigleyaa9c2662013-05-22 12:50:44 -04001569 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001570 FATTR4_WORD0_RDATTR_ERROR,
1571 FATTR4_WORD1_MOUNTED_ON_FILEID,
1572 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001573 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001574 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001575 uint32_t attrlen = 0;
1576 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001578 if (readdir->plus) {
1579 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001580 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001581 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1582 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1583 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1584 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001585 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001586 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001587 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001588 /* Use mounted_on_fileid only if the server supports it */
1589 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1590 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001591 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1592 attrs[i] &= readdir->bitmask[i];
1593 if (attrs[i] != 0)
1594 attrlen = i+1;
1595 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001596
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001597 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001598 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001599 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001600 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001601 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001602 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001603 *p++ = cpu_to_be32(attrlen);
1604 for (i = 0; i < attrlen; i++)
1605 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001606 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001607
1608 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001609 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001610 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001611 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001612 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001613 attrs[1] & readdir->bitmask[1],
1614 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615}
1616
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001617static 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 -07001618{
Trond Myklebustab19b482012-03-04 18:13:57 -05001619 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001622static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623{
Trond Myklebustab19b482012-03-04 18:13:57 -05001624 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001625 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static 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 -07001629{
Trond Myklebustab19b482012-03-04 18:13:57 -05001630 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001631 encode_string(xdr, oldname->len, oldname->name);
1632 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633}
1634
Chuck Leverbb4dae52012-03-01 17:01:48 -05001635static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1636 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001638 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001639 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640}
1641
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001642static void
Andy Adamsond0179312008-12-23 16:06:17 -05001643encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001644{
Trond Myklebustab19b482012-03-04 18:13:57 -05001645 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001646}
1647
Chuck Lever9f06c712010-12-14 14:59:18 +00001648static void
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001649encode_setacl(struct xdr_stream *xdr, const struct nfs_setaclargs *arg,
1650 struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001651{
Al Viro8687b632006-10-19 23:28:48 -07001652 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001653
Trond Myklebustab19b482012-03-04 18:13:57 -05001654 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001655 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001656 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001657 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001658 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001659 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001660 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001661 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001662}
1663
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001664static void
Andy Adamsond0179312008-12-23 16:06:17 -05001665encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666{
Trond Myklebustab19b482012-03-04 18:13:57 -05001667 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668}
1669
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001670static 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 -07001671{
Trond Myklebustab19b482012-03-04 18:13:57 -05001672 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001673 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust28cf22d2017-05-06 12:19:11 -04001674 encode_attrs(xdr, arg->iap, arg->label, NULL, server,
1675 server->attr_bitmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676}
1677
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001678static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679{
Al Viro8687b632006-10-19 23:28:48 -07001680 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
Trond Myklebust70019512012-03-04 20:49:32 -05001682 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001683 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Jeff Layton3a6bb732015-06-09 19:43:57 -04001685 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1686 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001687 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001688 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1690 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001691 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001692 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693}
1694
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001695static 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 -07001696{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001697 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1698 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001699 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001700 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701}
1702
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001703static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1704 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705{
Al Viro8687b632006-10-19 23:28:48 -07001706 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Trond Myklebustab19b482012-03-04 18:13:57 -05001708 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001709 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Benny Halevy13c65ce2009-08-14 17:19:25 +03001711 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001712 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001713 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001714 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717}
1718
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001719static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720{
Trond Myklebustab19b482012-03-04 18:13:57 -05001721 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001722 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001724
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001725static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1726{
Trond Myklebustab19b482012-03-04 18:13:57 -05001727 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001728 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001729}
1730
Benny Halevy99fe60d2009-04-01 09:22:29 -04001731#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001732/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001733static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001734 const struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001735 struct compound_hdr *hdr)
1736{
1737 __be32 *p;
1738
1739 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1740 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001741 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001742 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001743 *p++ = cpu_to_be32(args->dir);
1744 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001745}
1746
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001747static void encode_op_map(struct xdr_stream *xdr, const struct nfs4_op_map *op_map)
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001748{
1749 unsigned int i;
1750 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1751 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1752 encode_uint32(xdr, op_map->u.words[i]);
1753}
1754
Benny Halevy99fe60d2009-04-01 09:22:29 -04001755static void encode_exchange_id(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001756 const struct nfs41_exchange_id_args *args,
Benny Halevy99fe60d2009-04-01 09:22:29 -04001757 struct compound_hdr *hdr)
1758{
1759 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001760 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001761 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001762
Trond Myklebust70019512012-03-04 20:49:32 -05001763 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Trond Myklebustfd405592017-08-01 16:02:47 -04001764 encode_nfs4_verifier(xdr, &args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001765
Jeff Layton3a6bb732015-06-09 19:43:57 -04001766 encode_string(xdr, strlen(args->client->cl_owner_id),
1767 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001768
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001769 encode_uint32(xdr, args->flags);
1770 encode_uint32(xdr, args->state_protect.how);
1771
1772 switch (args->state_protect.how) {
1773 case SP4_NONE:
1774 break;
1775 case SP4_MACH_CRED:
1776 encode_op_map(xdr, &args->state_protect.enforce);
1777 encode_op_map(xdr, &args->state_protect.allow);
1778 break;
1779 default:
1780 WARN_ON_ONCE(1);
1781 break;
1782 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001783
1784 if (send_implementation_id &&
1785 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1786 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001787 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001788 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1789 utsname()->sysname, utsname()->release,
1790 utsname()->version, utsname()->machine);
1791
1792 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001793 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001794
1795 encode_string(xdr,
1796 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1797 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1798 encode_string(xdr, len, impl_name);
1799 /* just send zeros for nii_date - the date is in nii_name */
1800 p = reserve_space(xdr, 12);
1801 p = xdr_encode_hyper(p, 0);
1802 *p = cpu_to_be32(0);
1803 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001804 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001805}
Andy Adamsonfc931582009-04-01 09:22:31 -04001806
1807static void encode_create_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001808 const struct nfs41_create_session_args *args,
Andy Adamsonfc931582009-04-01 09:22:31 -04001809 struct compound_hdr *hdr)
1810{
1811 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001812 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001813 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001814 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001815 u32 max_resp_sz_cached;
1816
1817 /*
1818 * Assumes OPEN is the biggest non-idempotent compound.
1819 * 2 is the verifier.
1820 */
J. Bruce Fields35c036e2017-09-20 12:42:13 -04001821 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE + 2)
1822 * XDR_UNIT + RPC_MAX_AUTH_SIZE;
Andy Adamsonfc931582009-04-01 09:22:31 -04001823
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001824 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001825 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001826 p = xdr_encode_hyper(p, args->clientid);
1827 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001828 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001829
Andy Adamsonfc931582009-04-01 09:22:31 -04001830 /* Fore Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001831 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001832 *p++ = cpu_to_be32(args->fc_attrs.max_rqst_sz); /* max req size */
1833 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001834 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001835 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1836 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1837 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001838
1839 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001840 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001841 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1842 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1843 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1844 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1845 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1846 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001847
Benny Halevye75bc1c2009-08-14 17:18:54 +03001848 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001849 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001850 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001851
1852 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001853 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001854 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001855 *p++ = cpu_to_be32(0); /* UID */
1856 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001857 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001858}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001859
1860static void encode_destroy_session(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001861 const struct nfs4_session *session,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001862 struct compound_hdr *hdr)
1863{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001864 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1865 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001866}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001867
Trond Myklebust66245532012-05-25 17:18:09 -04001868static void encode_destroy_clientid(struct xdr_stream *xdr,
1869 uint64_t clientid,
1870 struct compound_hdr *hdr)
1871{
1872 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1873 encode_uint64(xdr, clientid);
1874}
1875
Ricardo Labiaga180197532009-12-05 16:08:40 -05001876static void encode_reclaim_complete(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001877 const struct nfs41_reclaim_complete_args *args,
Ricardo Labiaga180197532009-12-05 16:08:40 -05001878 struct compound_hdr *hdr)
1879{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001880 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1881 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001882}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001883#endif /* CONFIG_NFS_V4_1 */
1884
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001885static void encode_sequence(struct xdr_stream *xdr,
1886 const struct nfs4_sequence_args *args,
1887 struct compound_hdr *hdr)
1888{
1889#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001890 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001891 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001892 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001893 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001894
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001895 tp = slot->table;
1896 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001897 if (!session)
1898 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001899
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001900 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001901
1902 /*
1903 * Sessionid + seqid + slotid + max slotid + cache_this
1904 */
1905 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1906 "max_slotid=%d cache_this=%d\n",
1907 __func__,
1908 ((u32 *)session->sess_id.data)[0],
1909 ((u32 *)session->sess_id.data)[1],
1910 ((u32 *)session->sess_id.data)[2],
1911 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001912 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001913 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001914 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001915 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001916 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001917 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001918 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001919 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001920#endif /* CONFIG_NFS_V4_1 */
1921}
1922
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001923#ifdef CONFIG_NFS_V4_1
1924static void
1925encode_getdeviceinfo(struct xdr_stream *xdr,
1926 const struct nfs4_getdeviceinfo_args *args,
1927 struct compound_hdr *hdr)
1928{
1929 __be32 *p;
1930
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001931 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001932 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001933 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1934 NFS4_DEVICEID4_SIZE);
1935 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001936 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001937
1938 p = reserve_space(xdr, 4 + 4);
1939 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001940 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001941}
1942
1943static void
1944encode_layoutget(struct xdr_stream *xdr,
1945 const struct nfs4_layoutget_args *args,
1946 struct compound_hdr *hdr)
1947{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001948 __be32 *p;
1949
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001950 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1951 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001952 *p++ = cpu_to_be32(0); /* Signal layout available */
1953 *p++ = cpu_to_be32(args->type);
1954 *p++ = cpu_to_be32(args->range.iomode);
1955 p = xdr_encode_hyper(p, args->range.offset);
1956 p = xdr_encode_hyper(p, args->range.length);
1957 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001958 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001959 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001960
1961 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1962 __func__,
1963 args->type,
1964 args->range.iomode,
1965 (unsigned long)args->range.offset,
1966 (unsigned long)args->range.length,
1967 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001968}
Andy Adamson863a3c62011-03-23 13:27:54 +00001969
1970static int
1971encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001972 struct inode *inode,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02001973 const struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001974 struct compound_hdr *hdr)
1975{
1976 __be32 *p;
1977
1978 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1979 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1980
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001981 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1982 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001983 /* Only whole file layouts */
1984 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001985 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001986 *p = cpu_to_be32(0); /* reclaim */
1987 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04001988 if (args->lastbytewritten != U64_MAX) {
1989 p = reserve_space(xdr, 20);
1990 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
1991 p = xdr_encode_hyper(p, args->lastbytewritten);
1992 } else {
1993 p = reserve_space(xdr, 12);
1994 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
1995 }
Andy Adamson863a3c62011-03-23 13:27:54 +00001996 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
1997 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03001998
Trond Myklebust73504742017-04-20 16:48:14 -04001999 encode_uint32(xdr, args->layoutupdate_len);
2000 if (args->layoutupdate_pages)
2001 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2002 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002003
Andy Adamson863a3c62011-03-23 13:27:54 +00002004 return 0;
2005}
Benny Halevycbe82602011-05-22 19:52:37 +03002006
2007static void
2008encode_layoutreturn(struct xdr_stream *xdr,
2009 const struct nfs4_layoutreturn_args *args,
2010 struct compound_hdr *hdr)
2011{
2012 __be32 *p;
2013
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002014 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2015 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002016 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2017 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002018 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002019 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002020 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002021 p = xdr_encode_hyper(p, args->range.offset);
2022 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002023 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002024 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002025 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002026 if (args->ld_private->ops && args->ld_private->ops->encode)
2027 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002028 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002029 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002030}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002031
2032static int
2033encode_secinfo_no_name(struct xdr_stream *xdr,
2034 const struct nfs41_secinfo_no_name_args *args,
2035 struct compound_hdr *hdr)
2036{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002037 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2038 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002039 return 0;
2040}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002041
2042static void encode_test_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002043 const struct nfs41_test_stateid_args *args,
Bryan Schumaker7d974792011-06-02 14:59:08 -04002044 struct compound_hdr *hdr)
2045{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002046 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2047 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002048 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002049}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002050
2051static void encode_free_stateid(struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002052 const struct nfs41_free_stateid_args *args,
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002053 struct compound_hdr *hdr)
2054{
Trond Myklebustab19b482012-03-04 18:13:57 -05002055 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002056 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002057}
Trond Myklebustcf805162016-11-15 14:56:07 -05002058#else
2059static inline void
2060encode_layoutreturn(struct xdr_stream *xdr,
2061 const struct nfs4_layoutreturn_args *args,
2062 struct compound_hdr *hdr)
2063{
2064}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002065#endif /* CONFIG_NFS_V4_1 */
2066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067/*
2068 * END OF "GENERIC" ENCODE ROUTINES.
2069 */
2070
Benny Halevy66cc0422009-04-01 09:22:10 -04002071static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2072{
2073#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002074 struct nfs4_session *session = args->sa_slot->table->session;
2075 if (session)
2076 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002077#endif /* CONFIG_NFS_V4_1 */
2078 return 0;
2079}
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081/*
2082 * Encode an ACCESS request
2083 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002084static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002085 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002087 const struct nfs4_accessargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002089 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Chuck Lever9f06c712010-12-14 14:59:18 +00002092 encode_compound_hdr(xdr, req, &hdr);
2093 encode_sequence(xdr, &args->seq_args, &hdr);
2094 encode_putfh(xdr, args->fh, &hdr);
2095 encode_access(xdr, args->access, &hdr);
2096 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002097 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098}
2099
2100/*
2101 * Encode LOOKUP request
2102 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002103static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002104 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002106 const struct nfs4_lookup_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002108 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Chuck Lever9f06c712010-12-14 14:59:18 +00002111 encode_compound_hdr(xdr, req, &hdr);
2112 encode_sequence(xdr, &args->seq_args, &hdr);
2113 encode_putfh(xdr, args->dir_fh, &hdr);
2114 encode_lookup(xdr, args->name, &hdr);
2115 encode_getfh(xdr, &hdr);
2116 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002117 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118}
2119
2120/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07002121 * Encode LOOKUPP request
2122 */
2123static void nfs4_xdr_enc_lookupp(struct rpc_rqst *req, struct xdr_stream *xdr,
2124 const void *data)
2125{
2126 const struct nfs4_lookupp_arg *args = data;
2127 struct compound_hdr hdr = {
2128 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2129 };
2130
2131 encode_compound_hdr(xdr, req, &hdr);
2132 encode_sequence(xdr, &args->seq_args, &hdr);
2133 encode_putfh(xdr, args->fh, &hdr);
2134 encode_lookupp(xdr, &hdr);
2135 encode_getfh(xdr, &hdr);
2136 encode_getfattr(xdr, args->bitmask, &hdr);
2137 encode_nops(&hdr);
2138}
2139
2140/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 * Encode LOOKUP_ROOT request
2142 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002143static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2144 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002145 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002147 const struct nfs4_lookup_root_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002149 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
Chuck Lever9f06c712010-12-14 14:59:18 +00002152 encode_compound_hdr(xdr, req, &hdr);
2153 encode_sequence(xdr, &args->seq_args, &hdr);
2154 encode_putrootfh(xdr, &hdr);
2155 encode_getfh(xdr, &hdr);
2156 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002157 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158}
2159
2160/*
2161 * Encode REMOVE request
2162 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002163static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002164 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002166 const struct nfs_removeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002168 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
Chuck Lever9f06c712010-12-14 14:59:18 +00002171 encode_compound_hdr(xdr, req, &hdr);
2172 encode_sequence(xdr, &args->seq_args, &hdr);
2173 encode_putfh(xdr, args->fh, &hdr);
2174 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002175 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
2178/*
2179 * Encode RENAME request
2180 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002181static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002182 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002184 const struct nfs_renameargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002186 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Chuck Lever9f06c712010-12-14 14:59:18 +00002189 encode_compound_hdr(xdr, req, &hdr);
2190 encode_sequence(xdr, &args->seq_args, &hdr);
2191 encode_putfh(xdr, args->old_dir, &hdr);
2192 encode_savefh(xdr, &hdr);
2193 encode_putfh(xdr, args->new_dir, &hdr);
2194 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002195 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196}
2197
2198/*
2199 * Encode LINK request
2200 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002201static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002202 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002204 const struct nfs4_link_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002206 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208
Chuck Lever9f06c712010-12-14 14:59:18 +00002209 encode_compound_hdr(xdr, req, &hdr);
2210 encode_sequence(xdr, &args->seq_args, &hdr);
2211 encode_putfh(xdr, args->fh, &hdr);
2212 encode_savefh(xdr, &hdr);
2213 encode_putfh(xdr, args->dir_fh, &hdr);
2214 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002215 encode_restorefh(xdr, &hdr);
2216 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002217 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218}
2219
2220/*
2221 * Encode CREATE request
2222 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002223static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002224 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002226 const struct nfs4_create_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002228 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
Chuck Lever9f06c712010-12-14 14:59:18 +00002231 encode_compound_hdr(xdr, req, &hdr);
2232 encode_sequence(xdr, &args->seq_args, &hdr);
2233 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002234 encode_create(xdr, args, &hdr);
2235 encode_getfh(xdr, &hdr);
2236 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002237 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238}
2239
2240/*
2241 * Encode SYMLINK request
2242 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002243static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002244 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002246 const struct nfs4_create_arg *args = data;
2247
Chuck Lever9f06c712010-12-14 14:59:18 +00002248 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249}
2250
2251/*
2252 * Encode GETATTR request
2253 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002254static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002255 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002257 const struct nfs4_getattr_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002259 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Chuck Lever9f06c712010-12-14 14:59:18 +00002262 encode_compound_hdr(xdr, req, &hdr);
2263 encode_sequence(xdr, &args->seq_args, &hdr);
2264 encode_putfh(xdr, args->fh, &hdr);
2265 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002266 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/*
2270 * Encode a CLOSE request
2271 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002272static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002273 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002275 const struct nfs_closeargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002276 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002277 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002278 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279
Chuck Lever9f06c712010-12-14 14:59:18 +00002280 encode_compound_hdr(xdr, req, &hdr);
2281 encode_sequence(xdr, &args->seq_args, &hdr);
2282 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002283 if (args->lr_args)
2284 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002285 if (args->bitmask != NULL)
2286 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002287 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002288 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
2291/*
2292 * Encode an OPEN request
2293 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002294static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002295 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002297 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002299 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Chuck Lever9f06c712010-12-14 14:59:18 +00002302 encode_compound_hdr(xdr, req, &hdr);
2303 encode_sequence(xdr, &args->seq_args, &hdr);
2304 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002305 encode_open(xdr, args, &hdr);
2306 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002307 if (args->access)
2308 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002309 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002310 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311}
2312
2313/*
2314 * Encode an OPEN_CONFIRM request
2315 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002316static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2317 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002318 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002320 const struct nfs_open_confirmargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002322 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Chuck Lever9f06c712010-12-14 14:59:18 +00002325 encode_compound_hdr(xdr, req, &hdr);
2326 encode_putfh(xdr, args->fh, &hdr);
2327 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002328 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329}
2330
2331/*
2332 * Encode an OPEN request with no attributes.
2333 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002334static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2335 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002336 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002338 const struct nfs_openargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002340 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Chuck Lever9f06c712010-12-14 14:59:18 +00002343 encode_compound_hdr(xdr, req, &hdr);
2344 encode_sequence(xdr, &args->seq_args, &hdr);
2345 encode_putfh(xdr, args->fh, &hdr);
2346 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002347 if (args->access)
2348 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002349 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002350 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351}
2352
2353/*
2354 * Encode an OPEN_DOWNGRADE request
2355 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002356static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2357 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002358 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002360 const struct nfs_closeargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002362 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Chuck Lever9f06c712010-12-14 14:59:18 +00002365 encode_compound_hdr(xdr, req, &hdr);
2366 encode_sequence(xdr, &args->seq_args, &hdr);
2367 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002368 if (args->lr_args)
2369 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002370 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002371 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372}
2373
2374/*
2375 * Encode a LOCK request
2376 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002377static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002378 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002380 const struct nfs_lock_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002382 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
Chuck Lever9f06c712010-12-14 14:59:18 +00002385 encode_compound_hdr(xdr, req, &hdr);
2386 encode_sequence(xdr, &args->seq_args, &hdr);
2387 encode_putfh(xdr, args->fh, &hdr);
2388 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002389 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
2392/*
2393 * Encode a LOCKT request
2394 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002395static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002396 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002398 const struct nfs_lockt_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002400 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
Chuck Lever9f06c712010-12-14 14:59:18 +00002403 encode_compound_hdr(xdr, req, &hdr);
2404 encode_sequence(xdr, &args->seq_args, &hdr);
2405 encode_putfh(xdr, args->fh, &hdr);
2406 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002407 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408}
2409
2410/*
2411 * Encode a LOCKU request
2412 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002413static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002414 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002416 const struct nfs_locku_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002418 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Chuck Lever9f06c712010-12-14 14:59:18 +00002421 encode_compound_hdr(xdr, req, &hdr);
2422 encode_sequence(xdr, &args->seq_args, &hdr);
2423 encode_putfh(xdr, args->fh, &hdr);
2424 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002425 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426}
2427
Chuck Lever9f06c712010-12-14 14:59:18 +00002428static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2429 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002430 const void *data)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002431{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002432 const struct nfs_release_lockowner_args *args = data;
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002433 struct compound_hdr hdr = {
2434 .minorversion = 0,
2435 };
2436
Chuck Lever9f06c712010-12-14 14:59:18 +00002437 encode_compound_hdr(xdr, req, &hdr);
2438 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002439 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002440}
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442/*
2443 * Encode a READLINK request
2444 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002445static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002446 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002448 const struct nfs4_readlink *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002450 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
Chuck Lever9f06c712010-12-14 14:59:18 +00002453 encode_compound_hdr(xdr, req, &hdr);
2454 encode_sequence(xdr, &args->seq_args, &hdr);
2455 encode_putfh(xdr, args->fh, &hdr);
2456 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002457
Benny Halevy28f56692009-04-01 09:22:09 -04002458 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002459 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002460 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461}
2462
2463/*
2464 * Encode a READDIR request
2465 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002466static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002467 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002469 const struct nfs4_readdir_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002471 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
Chuck Lever9f06c712010-12-14 14:59:18 +00002474 encode_compound_hdr(xdr, req, &hdr);
2475 encode_sequence(xdr, &args->seq_args, &hdr);
2476 encode_putfh(xdr, args->fh, &hdr);
2477 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002478
Benny Halevy28f56692009-04-01 09:22:09 -04002479 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002480 args->pgbase, args->count);
2481 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002482 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002483 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002484 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485}
2486
2487/*
2488 * Encode a READ request
2489 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002490static void nfs4_xdr_enc_read(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 nfs_pgio_args *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_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Benny Halevy28f56692009-04-01 09:22:09 -04002503 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002505 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002506 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507}
2508
2509/*
2510 * Encode an SETATTR request
2511 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002512static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002513 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002515 const struct nfs_setattrargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05002516 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002517 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002518 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
Chuck Lever9f06c712010-12-14 14:59:18 +00002520 encode_compound_hdr(xdr, req, &hdr);
2521 encode_sequence(xdr, &args->seq_args, &hdr);
2522 encode_putfh(xdr, args->fh, &hdr);
2523 encode_setattr(xdr, args, args->server, &hdr);
2524 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002525 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526}
2527
2528/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002529 * Encode a GETACL request
2530 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002531static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002532 const void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002533{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002534 const struct nfs_getaclargs *args = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002535 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002536 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002537 };
Trond Myklebust37c88762018-03-20 17:03:08 -04002538 const __u32 nfs4_acl_bitmap[1] = {
2539 [0] = FATTR4_WORD0_ACL,
2540 };
Benny Halevy28f56692009-04-01 09:22:09 -04002541 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002542
Chuck Lever9f06c712010-12-14 14:59:18 +00002543 encode_compound_hdr(xdr, req, &hdr);
2544 encode_sequence(xdr, &args->seq_args, &hdr);
2545 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002546 replen = hdr.replen + op_decode_hdr_maxsz;
Trond Myklebust37c88762018-03-20 17:03:08 -04002547 encode_getattr(xdr, nfs4_acl_bitmap, NULL,
2548 ARRAY_SIZE(nfs4_acl_bitmap), &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002549
Benny Halevy28f56692009-04-01 09:22:09 -04002550 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002551 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002552
Andy Adamsond0179312008-12-23 16:06:17 -05002553 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002554}
2555
2556/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 * Encode a WRITE request
2558 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002559static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002560 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002562 const struct nfs_pgio_args *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002564 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
Chuck Lever9f06c712010-12-14 14:59:18 +00002567 encode_compound_hdr(xdr, req, &hdr);
2568 encode_sequence(xdr, &args->seq_args, &hdr);
2569 encode_putfh(xdr, args->fh, &hdr);
2570 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002571 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002572 if (args->bitmask)
2573 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002574 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575}
2576
2577/*
2578 * a COMMIT request
2579 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002580static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002581 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002583 const struct nfs_commitargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002585 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587
Chuck Lever9f06c712010-12-14 14:59:18 +00002588 encode_compound_hdr(xdr, req, &hdr);
2589 encode_sequence(xdr, &args->seq_args, &hdr);
2590 encode_putfh(xdr, args->fh, &hdr);
2591 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002592 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593}
2594
2595/*
2596 * FSINFO request
2597 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002598static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002599 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002601 const struct nfs4_fsinfo_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002603 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
Chuck Lever9f06c712010-12-14 14:59:18 +00002606 encode_compound_hdr(xdr, req, &hdr);
2607 encode_sequence(xdr, &args->seq_args, &hdr);
2608 encode_putfh(xdr, args->fh, &hdr);
2609 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002610 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611}
2612
2613/*
2614 * a PATHCONF request
2615 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002616static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002617 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002619 const struct nfs4_pathconf_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002621 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623
Chuck Lever9f06c712010-12-14 14:59:18 +00002624 encode_compound_hdr(xdr, req, &hdr);
2625 encode_sequence(xdr, &args->seq_args, &hdr);
2626 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002627 encode_getattr(xdr, nfs4_pathconf_bitmap, args->bitmask,
2628 ARRAY_SIZE(nfs4_pathconf_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002629 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630}
2631
2632/*
2633 * a STATFS request
2634 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002635static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002636 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002638 const struct nfs4_statfs_arg *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002640 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
Chuck Lever9f06c712010-12-14 14:59:18 +00002643 encode_compound_hdr(xdr, req, &hdr);
2644 encode_sequence(xdr, &args->seq_args, &hdr);
2645 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002646 encode_getattr(xdr, nfs4_statfs_bitmap, args->bitmask,
2647 ARRAY_SIZE(nfs4_statfs_bitmap), &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002648 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649}
2650
2651/*
2652 * GETATTR_BITMAP request
2653 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002654static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2655 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_server_caps_arg *args = data;
Kinglong Mee8c612822015-08-26 21:12:58 +08002659 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002661 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Chuck Lever9f06c712010-12-14 14:59:18 +00002664 encode_compound_hdr(xdr, req, &hdr);
2665 encode_sequence(xdr, &args->seq_args, &hdr);
2666 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust37c88762018-03-20 17:03:08 -04002667 encode_getattr(xdr, bitmask, NULL, 3, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002668 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669}
2670
2671/*
2672 * a RENEW request
2673 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002674static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002675 const void *data)
2676
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002678 const struct nfs_client *clp = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002680 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 };
2682
Chuck Lever9f06c712010-12-14 14:59:18 +00002683 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002684 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002685 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686}
2687
2688/*
2689 * a SETCLIENTID request
2690 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002691static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2692 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002693 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002695 const struct nfs4_setclientid *sc = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002697 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 };
2699
Chuck Lever9f06c712010-12-14 14:59:18 +00002700 encode_compound_hdr(xdr, req, &hdr);
2701 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002702 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703}
2704
2705/*
2706 * a SETCLIENTID_CONFIRM request
2707 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002708static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2709 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002710 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002712 const struct nfs4_setclientid_res *arg = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002714 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716
Chuck Lever9f06c712010-12-14 14:59:18 +00002717 encode_compound_hdr(xdr, req, &hdr);
2718 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002719 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720}
2721
2722/*
2723 * DELEGRETURN request
2724 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002725static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2726 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002727 const void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002729 const struct nfs4_delegreturnargs *args = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002731 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733
Chuck Lever9f06c712010-12-14 14:59:18 +00002734 encode_compound_hdr(xdr, req, &hdr);
2735 encode_sequence(xdr, &args->seq_args, &hdr);
2736 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002737 if (args->lr_args)
2738 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002739 if (args->bitmask)
2740 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002741 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002742 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743}
2744
2745/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002746 * Encode FS_LOCATIONS request
2747 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002748static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2749 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002750 const void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002751{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002752 const struct nfs4_fs_locations_arg *args = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002753 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002754 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002755 };
Benny Halevy28f56692009-04-01 09:22:09 -04002756 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002757
Chuck Lever9f06c712010-12-14 14:59:18 +00002758 encode_compound_hdr(xdr, req, &hdr);
2759 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002760 if (args->migration) {
2761 encode_putfh(xdr, args->fh, &hdr);
2762 replen = hdr.replen;
2763 encode_fs_locations(xdr, args->bitmask, &hdr);
2764 if (args->renew)
2765 encode_renew(xdr, args->clientid, &hdr);
2766 } else {
2767 encode_putfh(xdr, args->dir_fh, &hdr);
2768 encode_lookup(xdr, args->name, &hdr);
2769 replen = hdr.replen;
2770 encode_fs_locations(xdr, args->bitmask, &hdr);
2771 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002772
Chuck Leverb03d7352013-10-17 14:12:50 -04002773 /* Set up reply kvec to capture returned fs_locations array. */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002774 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
2775 (struct page **)&args->page, 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002776 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002777}
2778
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002779/*
2780 * Encode SECINFO request
2781 */
2782static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2783 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002784 const void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002785{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002786 const struct nfs4_secinfo_arg *args = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002787 struct compound_hdr hdr = {
2788 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2789 };
2790
2791 encode_compound_hdr(xdr, req, &hdr);
2792 encode_sequence(xdr, &args->seq_args, &hdr);
2793 encode_putfh(xdr, args->dir_fh, &hdr);
2794 encode_secinfo(xdr, args->name, &hdr);
2795 encode_nops(&hdr);
2796}
2797
Chuck Lever44c99932013-10-17 14:13:30 -04002798/*
2799 * Encode FSID_PRESENT request
2800 */
2801static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2802 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002803 const void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04002804{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002805 const struct nfs4_fsid_present_arg *args = data;
Chuck Lever44c99932013-10-17 14:13:30 -04002806 struct compound_hdr hdr = {
2807 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2808 };
2809
2810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_sequence(xdr, &args->seq_args, &hdr);
2812 encode_putfh(xdr, args->fh, &hdr);
2813 encode_getfh(xdr, &hdr);
2814 if (args->renew)
2815 encode_renew(xdr, args->clientid, &hdr);
2816 encode_nops(&hdr);
2817}
2818
Benny Halevy99fe60d2009-04-01 09:22:29 -04002819#if defined(CONFIG_NFS_V4_1)
2820/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002821 * BIND_CONN_TO_SESSION request
2822 */
2823static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2824 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002825 const void *data)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002826{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002827 const struct nfs41_bind_conn_to_session_args *args = data;
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002828 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002829 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002830 };
2831
2832 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002833 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002834 encode_nops(&hdr);
2835}
2836
2837/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002838 * EXCHANGE_ID request
2839 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002840static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2841 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002842 const void *data)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002843{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002844 const struct nfs41_exchange_id_args *args = data;
Benny Halevy99fe60d2009-04-01 09:22:29 -04002845 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002846 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002847 };
2848
Chuck Lever9f06c712010-12-14 14:59:18 +00002849 encode_compound_hdr(xdr, req, &hdr);
2850 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002851 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002852}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002853
2854/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002855 * a CREATE_SESSION request
2856 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002857static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2858 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002859 const void *data)
Andy Adamsonfc931582009-04-01 09:22:31 -04002860{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002861 const struct nfs41_create_session_args *args = data;
Andy Adamsonfc931582009-04-01 09:22:31 -04002862 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002863 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002864 };
2865
Chuck Lever9f06c712010-12-14 14:59:18 +00002866 encode_compound_hdr(xdr, req, &hdr);
2867 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002868 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002869}
2870
2871/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002872 * a DESTROY_SESSION request
2873 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002874static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2875 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002876 const void *data)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002877{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002878 const struct nfs4_session *session = data;
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002879 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002880 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002881 };
2882
Chuck Lever9f06c712010-12-14 14:59:18 +00002883 encode_compound_hdr(xdr, req, &hdr);
2884 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002885 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002886}
2887
2888/*
Trond Myklebust66245532012-05-25 17:18:09 -04002889 * a DESTROY_CLIENTID request
2890 */
2891static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2892 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002893 const void *data)
Trond Myklebust66245532012-05-25 17:18:09 -04002894{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002895 const struct nfs_client *clp = data;
Trond Myklebust66245532012-05-25 17:18:09 -04002896 struct compound_hdr hdr = {
2897 .minorversion = clp->cl_mvops->minor_version,
2898 };
2899
2900 encode_compound_hdr(xdr, req, &hdr);
2901 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2902 encode_nops(&hdr);
2903}
2904
2905/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002906 * a SEQUENCE request
2907 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002908static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002909 const void *data)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002910{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002911 const struct nfs4_sequence_args *args = data;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002912 struct compound_hdr hdr = {
2913 .minorversion = nfs4_xdr_minorversion(args),
2914 };
2915
Chuck Lever9f06c712010-12-14 14:59:18 +00002916 encode_compound_hdr(xdr, req, &hdr);
2917 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002918 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002919}
2920
2921/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002922 * a GET_LEASE_TIME request
2923 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002924static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2925 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002926 const void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002927{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002928 const struct nfs4_get_lease_time_args *args = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04002929 struct compound_hdr hdr = {
2930 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2931 };
Fred Isamandae100c2011-07-30 20:52:37 -04002932 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002933
Chuck Lever9f06c712010-12-14 14:59:18 +00002934 encode_compound_hdr(xdr, req, &hdr);
2935 encode_sequence(xdr, &args->la_seq_args, &hdr);
2936 encode_putrootfh(xdr, &hdr);
2937 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002938 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002939}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002940
2941/*
2942 * a RECLAIM_COMPLETE request
2943 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002944static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2945 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002946 const void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002947{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002948 const struct nfs41_reclaim_complete_args *args = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05002949 struct compound_hdr hdr = {
2950 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2951 };
2952
Chuck Lever9f06c712010-12-14 14:59:18 +00002953 encode_compound_hdr(xdr, req, &hdr);
2954 encode_sequence(xdr, &args->seq_args, &hdr);
2955 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002956 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002957}
2958
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002959/*
2960 * Encode GETDEVICEINFO request
2961 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002962static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2963 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002964 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002965{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002966 const struct nfs4_getdeviceinfo_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002967 struct compound_hdr hdr = {
2968 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2969 };
2970
Chuck Lever9f06c712010-12-14 14:59:18 +00002971 encode_compound_hdr(xdr, req, &hdr);
2972 encode_sequence(xdr, &args->seq_args, &hdr);
2973 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002974
2975 /* set up reply kvec. Subtract notification bitmap max size (2)
2976 * so that notification bitmap is put in xdr_buf tail */
2977 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2978 args->pdev->pages, args->pdev->pgbase,
2979 args->pdev->pglen);
2980
2981 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002982}
2983
2984/*
2985 * Encode LAYOUTGET request
2986 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002987static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2988 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002989 const void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002990{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02002991 const struct nfs4_layoutget_args *args = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002992 struct compound_hdr hdr = {
2993 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2994 };
2995
Chuck Lever9f06c712010-12-14 14:59:18 +00002996 encode_compound_hdr(xdr, req, &hdr);
2997 encode_sequence(xdr, &args->seq_args, &hdr);
2998 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2999 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04003000
3001 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
3002 args->layout.pages, 0, args->layout.pglen);
3003
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003004 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04003005}
Andy Adamson863a3c62011-03-23 13:27:54 +00003006
3007/*
3008 * Encode LAYOUTCOMMIT request
3009 */
Benny Halevycbe82602011-05-22 19:52:37 +03003010static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
3011 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003012 const void *priv)
Andy Adamson863a3c62011-03-23 13:27:54 +00003013{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003014 const struct nfs4_layoutcommit_args *args = priv;
Benny Halevyac7db722011-05-22 19:53:48 +03003015 struct nfs4_layoutcommit_data *data =
3016 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00003017 struct compound_hdr hdr = {
3018 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3019 };
3020
3021 encode_compound_hdr(xdr, req, &hdr);
3022 encode_sequence(xdr, &args->seq_args, &hdr);
3023 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03003024 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003025 encode_getfattr(xdr, args->bitmask, &hdr);
3026 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03003027}
3028
3029/*
3030 * Encode LAYOUTRETURN request
3031 */
3032static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
3033 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003034 const void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03003035{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003036 const struct nfs4_layoutreturn_args *args = data;
Benny Halevycbe82602011-05-22 19:52:37 +03003037 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);
3044 encode_layoutreturn(xdr, args, &hdr);
3045 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00003046}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003047
3048/*
3049 * Encode SECINFO_NO_NAME request
3050 */
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003051static void nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003052 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003053 const void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003054{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003055 const struct nfs41_secinfo_no_name_args *args = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003056 struct compound_hdr hdr = {
3057 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3058 };
3059
3060 encode_compound_hdr(xdr, req, &hdr);
3061 encode_sequence(xdr, &args->seq_args, &hdr);
3062 encode_putrootfh(xdr, &hdr);
3063 encode_secinfo_no_name(xdr, args, &hdr);
3064 encode_nops(&hdr);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04003065}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003066
3067/*
3068 * Encode TEST_STATEID request
3069 */
3070static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3071 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003072 const void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04003073{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003074 const struct nfs41_test_stateid_args *args = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04003075 struct compound_hdr hdr = {
3076 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3077 };
3078
3079 encode_compound_hdr(xdr, req, &hdr);
3080 encode_sequence(xdr, &args->seq_args, &hdr);
3081 encode_test_stateid(xdr, args, &hdr);
3082 encode_nops(&hdr);
3083}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003084
3085/*
3086 * Encode FREE_STATEID request
3087 */
3088static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3089 struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003090 const void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003091{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02003092 const struct nfs41_free_stateid_args *args = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003093 struct compound_hdr hdr = {
3094 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3095 };
3096
3097 encode_compound_hdr(xdr, req, &hdr);
3098 encode_sequence(xdr, &args->seq_args, &hdr);
3099 encode_free_stateid(xdr, args, &hdr);
3100 encode_nops(&hdr);
3101}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003102#endif /* CONFIG_NFS_V4_1 */
3103
Benny Halevy686841b2009-08-14 17:19:48 +03003104static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3105{
3106 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3107 "Remaining buffer length is %tu words.\n",
3108 func, xdr->end - xdr->p);
3109}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
Trond Myklebust683b57b2006-06-09 09:34:22 -04003111static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003113 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3114 NFS4_OPAQUE_LIMIT);
3115 if (unlikely(ret < 0)) {
3116 if (ret == -EBADMSG)
3117 print_overflow_msg(__func__, xdr);
3118 return -EIO;
3119 }
3120 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 return 0;
3122}
3123
3124static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3125{
Al Viro8687b632006-10-19 23:28:48 -07003126 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127
Benny Halevyc0eae662009-08-14 17:20:14 +03003128 p = xdr_inline_decode(xdr, 8);
3129 if (unlikely(!p))
3130 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003131 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003132 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003133
Benny Halevyc0eae662009-08-14 17:20:14 +03003134 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3135 if (unlikely(!p))
3136 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 hdr->tag = (char *)p;
3138 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003139 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003140 if (unlikely(hdr->nops < 1))
3141 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003143out_overflow:
3144 print_overflow_msg(__func__, xdr);
3145 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146}
3147
Trond Myklebustc7848f62013-12-04 17:39:23 -05003148static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3149 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150{
Al Viro8687b632006-10-19 23:28:48 -07003151 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 uint32_t opnum;
3153 int32_t nfserr;
3154
Benny Halevyc0eae662009-08-14 17:20:14 +03003155 p = xdr_inline_decode(xdr, 8);
3156 if (unlikely(!p))
3157 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003158 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003159 if (unlikely(opnum != expected))
3160 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003161 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003162 if (nfserr == NFS_OK)
3163 *nfs_retval = 0;
3164 else
3165 *nfs_retval = nfs4_stat_to_errno(nfserr);
3166 return true;
3167out_bad_operation:
3168 dprintk("nfs: Server returned operation"
3169 " %d but we issued a request for %d\n",
3170 opnum, expected);
3171 *nfs_retval = -EREMOTEIO;
3172 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003173out_overflow:
3174 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003175 *nfs_retval = -EIO;
3176 return false;
3177}
3178
3179static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3180{
3181 int retval;
3182
3183 __decode_op_hdr(xdr, expected, &retval);
3184 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185}
3186
3187/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003188static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189{
Al Viro8687b632006-10-19 23:28:48 -07003190 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003191 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 char *str;
3193
Benny Halevyc0eae662009-08-14 17:20:14 +03003194 p = xdr_inline_decode(xdr, 12);
3195 if (likely(p))
3196 return decode_opaque_inline(xdr, &strlen, &str);
3197 print_overflow_msg(__func__, xdr);
3198 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199}
3200
Trond Myklebust37c88762018-03-20 17:03:08 -04003201static ssize_t
3202decode_bitmap4(struct xdr_stream *xdr, uint32_t *bitmap, size_t sz)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203{
Trond Myklebust37c88762018-03-20 17:03:08 -04003204 ssize_t ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205
Trond Myklebust37c88762018-03-20 17:03:08 -04003206 ret = xdr_stream_decode_uint32_array(xdr, bitmap, sz);
3207 if (likely(ret >= 0))
3208 return ret;
3209 if (ret == -EMSGSIZE)
3210 return sz;
Benny Halevyc0eae662009-08-14 17:20:14 +03003211 print_overflow_msg(__func__, xdr);
3212 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213}
3214
Trond Myklebust37c88762018-03-20 17:03:08 -04003215static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3216{
3217 ssize_t ret;
3218 ret = decode_bitmap4(xdr, bitmap, 3);
3219 return ret < 0 ? ret : 0;
3220}
3221
Trond Myklebust256e48b2012-06-21 11:18:13 -04003222static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223{
Al Viro8687b632006-10-19 23:28:48 -07003224 __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 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003230 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003232out_overflow:
3233 print_overflow_msg(__func__, xdr);
3234 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235}
3236
3237static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3238{
3239 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003240 int ret;
3241 ret = decode_attr_bitmap(xdr, bitmask);
3242 if (unlikely(ret < 0))
3243 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3245 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003246 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3247 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3248 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 return 0;
3250}
3251
3252static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3253{
Al Viro8687b632006-10-19 23:28:48 -07003254 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003255 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256
3257 *type = 0;
3258 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3259 return -EIO;
3260 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003261 p = xdr_inline_decode(xdr, 4);
3262 if (unlikely(!p))
3263 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003264 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003266 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 return -EIO;
3268 }
3269 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003270 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003272 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003273 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003274out_overflow:
3275 print_overflow_msg(__func__, xdr);
3276 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277}
3278
Chuck Lever264e6352012-03-01 17:02:05 -05003279static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3280 uint32_t *bitmap, uint32_t *type)
3281{
3282 __be32 *p;
3283
3284 *type = 0;
3285 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3286 return -EIO;
3287 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3288 p = xdr_inline_decode(xdr, 4);
3289 if (unlikely(!p))
3290 goto out_overflow;
3291 *type = be32_to_cpup(p);
3292 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3293 }
3294 dprintk("%s: expire type=0x%x\n", __func__, *type);
3295 return 0;
3296out_overflow:
3297 print_overflow_msg(__func__, xdr);
3298 return -EIO;
3299}
3300
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3302{
Al Viro8687b632006-10-19 23:28:48 -07003303 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003304 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
3306 *change = 0;
3307 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3308 return -EIO;
3309 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003310 p = xdr_inline_decode(xdr, 8);
3311 if (unlikely(!p))
3312 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003313 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003315 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003317 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003319 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003320out_overflow:
3321 print_overflow_msg(__func__, xdr);
3322 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323}
3324
3325static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3326{
Al Viro8687b632006-10-19 23:28:48 -07003327 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003328 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
3330 *size = 0;
3331 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3332 return -EIO;
3333 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003334 p = xdr_inline_decode(xdr, 8);
3335 if (unlikely(!p))
3336 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003337 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003339 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003341 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003342 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003343out_overflow:
3344 print_overflow_msg(__func__, xdr);
3345 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346}
3347
3348static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3349{
Al Viro8687b632006-10-19 23:28:48 -07003350 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
3352 *res = 0;
3353 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3354 return -EIO;
3355 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003356 p = xdr_inline_decode(xdr, 4);
3357 if (unlikely(!p))
3358 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003359 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3361 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003362 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003364out_overflow:
3365 print_overflow_msg(__func__, xdr);
3366 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367}
3368
3369static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3370{
Al Viro8687b632006-10-19 23:28:48 -07003371 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372
3373 *res = 0;
3374 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3375 return -EIO;
3376 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003377 p = xdr_inline_decode(xdr, 4);
3378 if (unlikely(!p))
3379 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003380 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3382 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003383 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003385out_overflow:
3386 print_overflow_msg(__func__, xdr);
3387 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388}
3389
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003390static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391{
Al Viro8687b632006-10-19 23:28:48 -07003392 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003393 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394
3395 fsid->major = 0;
3396 fsid->minor = 0;
3397 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3398 return -EIO;
3399 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003400 p = xdr_inline_decode(xdr, 16);
3401 if (unlikely(!p))
3402 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003403 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003404 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003406 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003408 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 (unsigned long long)fsid->major,
3410 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003411 return ret;
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
3417static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3418{
Al Viro8687b632006-10-19 23:28:48 -07003419 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
3421 *res = 60;
3422 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3423 return -EIO;
3424 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003425 p = xdr_inline_decode(xdr, 4);
3426 if (unlikely(!p))
3427 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003428 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3430 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003431 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003433out_overflow:
3434 print_overflow_msg(__func__, xdr);
3435 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436}
3437
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003438static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003439{
3440 __be32 *p;
3441
3442 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3443 return -EIO;
3444 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3445 p = xdr_inline_decode(xdr, 4);
3446 if (unlikely(!p))
3447 goto out_overflow;
3448 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003449 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003450 }
3451 return 0;
3452out_overflow:
3453 print_overflow_msg(__func__, xdr);
3454 return -EIO;
3455}
3456
Kinglong Mee8c612822015-08-26 21:12:58 +08003457static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3458 uint32_t *bitmap, uint32_t *bitmask)
3459{
3460 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3461 int ret;
3462 ret = decode_attr_bitmap(xdr, bitmask);
3463 if (unlikely(ret < 0))
3464 return ret;
3465 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3466 } else
3467 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3468 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3469 bitmask[0], bitmask[1], bitmask[2]);
3470 return 0;
3471}
3472
Bryan Schumakerae42c702010-10-21 16:33:17 -04003473static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3474{
3475 __be32 *p;
3476 int len;
3477
Trond Myklebust7ad07352010-10-23 15:34:20 -04003478 if (fh != NULL)
3479 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003480
3481 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3482 return -EIO;
3483 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3484 p = xdr_inline_decode(xdr, 4);
3485 if (unlikely(!p))
3486 goto out_overflow;
3487 len = be32_to_cpup(p);
3488 if (len > NFS4_FHSIZE)
3489 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003490 p = xdr_inline_decode(xdr, len);
3491 if (unlikely(!p))
3492 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003493 if (fh != NULL) {
3494 memcpy(fh->data, p, len);
3495 fh->size = len;
3496 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003497 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3498 }
3499 return 0;
3500out_overflow:
3501 print_overflow_msg(__func__, xdr);
3502 return -EIO;
3503}
3504
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3506{
Al Viro8687b632006-10-19 23:28:48 -07003507 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003509 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3511 return -EIO;
3512 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003513 p = xdr_inline_decode(xdr, 4);
3514 if (unlikely(!p))
3515 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003516 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3518 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003519 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003521out_overflow:
3522 print_overflow_msg(__func__, xdr);
3523 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524}
3525
3526static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3527{
Al Viro8687b632006-10-19 23:28:48 -07003528 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003529 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530
3531 *fileid = 0;
3532 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3533 return -EIO;
3534 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003535 p = xdr_inline_decode(xdr, 8);
3536 if (unlikely(!p))
3537 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003538 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003540 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003542 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003543 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003544out_overflow:
3545 print_overflow_msg(__func__, xdr);
3546 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547}
3548
Manoj Naik99baf622006-06-09 09:34:24 -04003549static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3550{
Al Viro8687b632006-10-19 23:28:48 -07003551 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003552 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003553
3554 *fileid = 0;
3555 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3556 return -EIO;
3557 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003558 p = xdr_inline_decode(xdr, 8);
3559 if (unlikely(!p))
3560 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003561 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003562 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003563 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003564 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003565 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003566 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003567out_overflow:
3568 print_overflow_msg(__func__, xdr);
3569 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003570}
3571
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3573{
Al Viro8687b632006-10-19 23:28:48 -07003574 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 int status = 0;
3576
3577 *res = 0;
3578 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3579 return -EIO;
3580 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003581 p = xdr_inline_decode(xdr, 8);
3582 if (unlikely(!p))
3583 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003584 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3586 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003587 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003589out_overflow:
3590 print_overflow_msg(__func__, xdr);
3591 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592}
3593
3594static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3595{
Al Viro8687b632006-10-19 23:28:48 -07003596 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597 int status = 0;
3598
3599 *res = 0;
3600 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3601 return -EIO;
3602 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003603 p = xdr_inline_decode(xdr, 8);
3604 if (unlikely(!p))
3605 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003606 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3608 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003609 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003611out_overflow:
3612 print_overflow_msg(__func__, xdr);
3613 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614}
3615
3616static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3617{
Al Viro8687b632006-10-19 23:28:48 -07003618 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003619 int status = 0;
3620
3621 *res = 0;
3622 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3623 return -EIO;
3624 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003625 p = xdr_inline_decode(xdr, 8);
3626 if (unlikely(!p))
3627 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003628 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3630 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003631 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003633out_overflow:
3634 print_overflow_msg(__func__, xdr);
3635 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636}
3637
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003638static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3639{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003640 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003641 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003642 int status = 0;
3643
Benny Halevyc0eae662009-08-14 17:20:14 +03003644 p = xdr_inline_decode(xdr, 4);
3645 if (unlikely(!p))
3646 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003647 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003648 if (n == 0)
3649 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003650 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003651 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3652 dprintk("cannot parse %d components in path\n", n);
3653 goto out_eio;
3654 }
3655 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003656 struct nfs4_string *component = &path->components[path->ncomponents];
3657 status = decode_opaque_inline(xdr, &component->len, &component->data);
3658 if (unlikely(status != 0))
3659 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003660 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003661 pr_cont("%s%.*s ",
3662 (path->ncomponents != n ? "/ " : ""),
3663 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003664 }
3665out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003666 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003667root_path:
3668/* a root pathname is sent as a zero component4 */
3669 path->ncomponents = 1;
3670 path->components[0].len=0;
3671 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003672 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003673 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003674out_eio:
3675 dprintk(" status %d", status);
3676 status = -EIO;
3677 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003678out_overflow:
3679 print_overflow_msg(__func__, xdr);
3680 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003681}
3682
3683static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003684{
3685 int n;
Al Viro8687b632006-10-19 23:28:48 -07003686 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003687 int status = -EIO;
3688
3689 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3690 goto out;
3691 status = 0;
3692 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3693 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003694 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003695 status = -EIO;
3696 /* Ignore borken servers that return unrequested attrs */
3697 if (unlikely(res == NULL))
3698 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003699 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003700 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003701 if (unlikely(status != 0))
3702 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003703 p = xdr_inline_decode(xdr, 4);
3704 if (unlikely(!p))
3705 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003706 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003707 if (n <= 0)
3708 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003709 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003710 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003711 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003712
Trond Myklebust809b4262013-03-27 11:54:45 -04003713 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3714 break;
3715 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003716 p = xdr_inline_decode(xdr, 4);
3717 if (unlikely(!p))
3718 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003719 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003720
Chuck Lever02a29762012-03-01 17:00:31 -05003721 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003722 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3723 struct nfs4_string *server;
3724
3725 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003726 unsigned int i;
3727 dprintk("%s: using first %u of %u servers "
3728 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003729 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003730 NFS4_FS_LOCATION_MAXSERVERS,
3731 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003732 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003733 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003734 char *data;
3735 status = decode_opaque_inline(xdr, &len, &data);
3736 if (unlikely(status != 0))
3737 goto out_eio;
3738 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003739 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003740 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003741 server = &loc->servers[loc->nservers];
3742 status = decode_opaque_inline(xdr, &server->len, &server->data);
3743 if (unlikely(status != 0))
3744 goto out_eio;
3745 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003746 }
3747 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003748 if (unlikely(status != 0))
3749 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003750 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003751 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003752 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003753out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003754 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003755 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003756out_overflow:
3757 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003758out_eio:
3759 status = -EIO;
3760 goto out;
3761}
3762
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3764{
Al Viro8687b632006-10-19 23:28:48 -07003765 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 int status = 0;
3767
3768 *res = 0;
3769 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3770 return -EIO;
3771 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003772 p = xdr_inline_decode(xdr, 8);
3773 if (unlikely(!p))
3774 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003775 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3777 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003778 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003780out_overflow:
3781 print_overflow_msg(__func__, xdr);
3782 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783}
3784
3785static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3786{
Al Viro8687b632006-10-19 23:28:48 -07003787 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788 int status = 0;
3789
3790 *maxlink = 1;
3791 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3792 return -EIO;
3793 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003794 p = xdr_inline_decode(xdr, 4);
3795 if (unlikely(!p))
3796 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003797 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3799 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003800 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003802out_overflow:
3803 print_overflow_msg(__func__, xdr);
3804 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805}
3806
3807static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3808{
Al Viro8687b632006-10-19 23:28:48 -07003809 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 int status = 0;
3811
3812 *maxname = 1024;
3813 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3814 return -EIO;
3815 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003816 p = xdr_inline_decode(xdr, 4);
3817 if (unlikely(!p))
3818 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003819 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3821 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003822 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003824out_overflow:
3825 print_overflow_msg(__func__, xdr);
3826 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827}
3828
3829static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3830{
Al Viro8687b632006-10-19 23:28:48 -07003831 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 int status = 0;
3833
3834 *res = 1024;
3835 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3836 return -EIO;
3837 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3838 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003839 p = xdr_inline_decode(xdr, 8);
3840 if (unlikely(!p))
3841 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003842 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843 if (maxread > 0x7FFFFFFF)
3844 maxread = 0x7FFFFFFF;
3845 *res = (uint32_t)maxread;
3846 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3847 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003848 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003850out_overflow:
3851 print_overflow_msg(__func__, xdr);
3852 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853}
3854
3855static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3856{
Al Viro8687b632006-10-19 23:28:48 -07003857 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858 int status = 0;
3859
3860 *res = 1024;
3861 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3862 return -EIO;
3863 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3864 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003865 p = xdr_inline_decode(xdr, 8);
3866 if (unlikely(!p))
3867 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003868 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869 if (maxwrite > 0x7FFFFFFF)
3870 maxwrite = 0x7FFFFFFF;
3871 *res = (uint32_t)maxwrite;
3872 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3873 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003874 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003875 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003876out_overflow:
3877 print_overflow_msg(__func__, xdr);
3878 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879}
3880
Trond Myklebustbca79472009-03-11 14:10:26 -04003881static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882{
Trond Myklebustbca79472009-03-11 14:10:26 -04003883 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003884 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003885 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003886
3887 *mode = 0;
3888 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3889 return -EIO;
3890 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003891 p = xdr_inline_decode(xdr, 4);
3892 if (unlikely(!p))
3893 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003894 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003895 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003897 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003899 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003900 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003901out_overflow:
3902 print_overflow_msg(__func__, xdr);
3903 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904}
3905
3906static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3907{
Al Viro8687b632006-10-19 23:28:48 -07003908 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003909 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910
3911 *nlink = 1;
3912 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3913 return -EIO;
3914 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003915 p = xdr_inline_decode(xdr, 4);
3916 if (unlikely(!p))
3917 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003918 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003920 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003922 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003923 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003924out_overflow:
3925 print_overflow_msg(__func__, xdr);
3926 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927}
3928
Trond Myklebust686a8162017-02-19 16:08:32 -05003929static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3930 struct nfs4_string *name, gfp_t gfp_flags)
3931{
3932 ssize_t ret;
3933
3934 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3935 XDR_MAX_NETOBJ, gfp_flags);
3936 name->len = 0;
3937 if (ret > 0)
3938 name->len = ret;
3939 return ret;
3940}
3941
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003942static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003943 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003944 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945{
Trond Myklebust686a8162017-02-19 16:08:32 -05003946 ssize_t len;
3947 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948
Eric W. Biedermane5782072013-02-01 14:22:02 -08003949 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3951 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003952 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3953 return 0;
3954 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3955
3956 if (owner_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003957 len = decode_nfs4_string(xdr, owner_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003958 if (len <= 0)
3959 goto out;
3960 dprintk("%s: name=%s\n", __func__, owner_name->data);
3961 return NFS_ATTR_FATTR_OWNER_NAME;
3962 } else {
3963 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3964 XDR_MAX_NETOBJ);
3965 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3966 goto out;
3967 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3968 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003970out:
3971 if (len != -EBADMSG)
3972 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003973 print_overflow_msg(__func__, xdr);
3974 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975}
3976
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003977static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003978 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003979 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980{
Trond Myklebust686a8162017-02-19 16:08:32 -05003981 ssize_t len;
3982 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003983
Eric W. Biedermane5782072013-02-01 14:22:02 -08003984 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3986 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003987 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3988 return 0;
3989 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3990
3991 if (group_name != NULL) {
Trond Myklebuste8d8aa42018-03-20 17:03:07 -04003992 len = decode_nfs4_string(xdr, group_name, GFP_NOIO);
Trond Myklebust686a8162017-02-19 16:08:32 -05003993 if (len <= 0)
3994 goto out;
3995 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08003996 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05003997 } else {
3998 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3999 XDR_MAX_NETOBJ);
4000 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
4001 goto out;
4002 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
4003 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004004 }
Trond Myklebust686a8162017-02-19 16:08:32 -05004005out:
4006 if (len != -EBADMSG)
4007 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004008 print_overflow_msg(__func__, xdr);
4009 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010}
4011
4012static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
4013{
Al Viro8687b632006-10-19 23:28:48 -07004014 uint32_t major = 0, minor = 0;
4015 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004016 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017
4018 *rdev = MKDEV(0,0);
4019 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
4020 return -EIO;
4021 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
4022 dev_t tmp;
4023
Benny Halevyc0eae662009-08-14 17:20:14 +03004024 p = xdr_inline_decode(xdr, 8);
4025 if (unlikely(!p))
4026 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004027 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004028 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 tmp = MKDEV(major, minor);
4030 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
4031 *rdev = tmp;
4032 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04004033 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004035 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04004036 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004037out_overflow:
4038 print_overflow_msg(__func__, xdr);
4039 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040}
4041
4042static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4043{
Al Viro8687b632006-10-19 23:28:48 -07004044 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045 int status = 0;
4046
4047 *res = 0;
4048 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
4049 return -EIO;
4050 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004051 p = xdr_inline_decode(xdr, 8);
4052 if (unlikely(!p))
4053 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004054 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
4056 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004057 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004059out_overflow:
4060 print_overflow_msg(__func__, xdr);
4061 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062}
4063
4064static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4065{
Al Viro8687b632006-10-19 23:28:48 -07004066 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 int status = 0;
4068
4069 *res = 0;
4070 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4071 return -EIO;
4072 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004073 p = xdr_inline_decode(xdr, 8);
4074 if (unlikely(!p))
4075 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004076 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4078 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004079 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004081out_overflow:
4082 print_overflow_msg(__func__, xdr);
4083 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084}
4085
4086static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4087{
Al Viro8687b632006-10-19 23:28:48 -07004088 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 int status = 0;
4090
4091 *res = 0;
4092 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4093 return -EIO;
4094 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004095 p = xdr_inline_decode(xdr, 8);
4096 if (unlikely(!p))
4097 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004098 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4100 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004101 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004103out_overflow:
4104 print_overflow_msg(__func__, xdr);
4105 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106}
4107
4108static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4109{
Al Viro8687b632006-10-19 23:28:48 -07004110 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004111 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112
4113 *used = 0;
4114 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4115 return -EIO;
4116 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004117 p = xdr_inline_decode(xdr, 8);
4118 if (unlikely(!p))
4119 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004120 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004122 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004124 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004126 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004127out_overflow:
4128 print_overflow_msg(__func__, xdr);
4129 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130}
4131
4132static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4133{
Al Viro8687b632006-10-19 23:28:48 -07004134 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 uint64_t sec;
4136 uint32_t nsec;
4137
Benny Halevyc0eae662009-08-14 17:20:14 +03004138 p = xdr_inline_decode(xdr, 12);
4139 if (unlikely(!p))
4140 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004141 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004142 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 time->tv_sec = (time_t)sec;
4144 time->tv_nsec = (long)nsec;
4145 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004146out_overflow:
4147 print_overflow_msg(__func__, xdr);
4148 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149}
4150
4151static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4152{
4153 int status = 0;
4154
4155 time->tv_sec = 0;
4156 time->tv_nsec = 0;
4157 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4158 return -EIO;
4159 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4160 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004161 if (status == 0)
4162 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4164 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004165 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 return status;
4167}
4168
4169static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4170{
4171 int status = 0;
4172
4173 time->tv_sec = 0;
4174 time->tv_nsec = 0;
4175 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4176 return -EIO;
4177 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4178 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004179 if (status == 0)
4180 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004181 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4182 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004183 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184 return status;
4185}
4186
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004187static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4188 struct timespec *time)
4189{
4190 int status = 0;
4191
4192 time->tv_sec = 0;
4193 time->tv_nsec = 0;
4194 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4195 return -EIO;
4196 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4197 status = decode_attr_time(xdr, time);
4198 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4199 }
4200 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4201 (long)time->tv_nsec);
4202 return status;
4203}
4204
David Quigleyaa9c2662013-05-22 12:50:44 -04004205static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4206 struct nfs4_label *label)
4207{
4208 uint32_t pi = 0;
4209 uint32_t lfs = 0;
4210 __u32 len;
4211 __be32 *p;
4212 int status = 0;
4213
4214 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4215 return -EIO;
4216 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4217 p = xdr_inline_decode(xdr, 4);
4218 if (unlikely(!p))
4219 goto out_overflow;
4220 lfs = be32_to_cpup(p++);
4221 p = xdr_inline_decode(xdr, 4);
4222 if (unlikely(!p))
4223 goto out_overflow;
4224 pi = be32_to_cpup(p++);
4225 p = xdr_inline_decode(xdr, 4);
4226 if (unlikely(!p))
4227 goto out_overflow;
4228 len = be32_to_cpup(p++);
4229 p = xdr_inline_decode(xdr, len);
4230 if (unlikely(!p))
4231 goto out_overflow;
4232 if (len < NFS4_MAXLABELLEN) {
4233 if (label) {
4234 memcpy(label->label, p, len);
4235 label->len = len;
4236 label->pi = pi;
4237 label->lfs = lfs;
4238 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4239 }
4240 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4241 } else
4242 printk(KERN_WARNING "%s: label too long (%u)!\n",
4243 __func__, len);
4244 }
4245 if (label && label->label)
4246 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4247 (char *)label->label, label->len, label->pi, label->lfs);
4248 return status;
4249
4250out_overflow:
4251 print_overflow_msg(__func__, xdr);
4252 return -EIO;
4253}
4254
Linus Torvalds1da177e2005-04-16 15:20:36 -07004255static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4256{
4257 int status = 0;
4258
4259 time->tv_sec = 0;
4260 time->tv_nsec = 0;
4261 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4262 return -EIO;
4263 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4264 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004265 if (status == 0)
4266 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004267 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4268 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004269 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 return status;
4271}
4272
Trond Myklebust256e48b2012-06-21 11:18:13 -04004273static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274{
4275 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004276 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004277
4278 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004279 dprintk("%s: server returned incorrect attribute length: "
4280 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004281 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282 attrwords << 2,
4283 (attrwords < nwords) ? '<' : '>',
4284 nwords << 2);
4285 return -EIO;
4286 }
4287 return 0;
4288}
4289
4290static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4291{
Al Viro8687b632006-10-19 23:28:48 -07004292 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293
Benny Halevyc0eae662009-08-14 17:20:14 +03004294 p = xdr_inline_decode(xdr, 20);
4295 if (unlikely(!p))
4296 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004297 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004298 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004299 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004301out_overflow:
4302 print_overflow_msg(__func__, xdr);
4303 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304}
4305
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004306static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307{
Al Viro8687b632006-10-19 23:28:48 -07004308 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 uint32_t supp, acc;
4310 int status;
4311
4312 status = decode_op_hdr(xdr, OP_ACCESS);
4313 if (status)
4314 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004315 p = xdr_inline_decode(xdr, 8);
4316 if (unlikely(!p))
4317 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004318 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004319 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004320 *supported = supp;
4321 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004323out_overflow:
4324 print_overflow_msg(__func__, xdr);
4325 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326}
4327
Benny Halevy07d30432009-08-14 17:19:52 +03004328static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004330 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4331 if (unlikely(ret < 0)) {
4332 print_overflow_msg(__func__, xdr);
4333 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004334 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004335 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004336}
4337
4338static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4339{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004340 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004341}
4342
Trond Myklebust93b717f2016-05-16 17:42:43 -04004343static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4344{
4345 stateid->type = NFS4_OPEN_STATEID_TYPE;
4346 return decode_stateid(xdr, stateid);
4347}
4348
4349static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4350{
4351 stateid->type = NFS4_LOCK_STATEID_TYPE;
4352 return decode_stateid(xdr, stateid);
4353}
4354
4355static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4356{
4357 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4358 return decode_stateid(xdr, stateid);
4359}
4360
Trond Myklebustfcd88432017-11-07 12:39:44 -05004361static int decode_invalid_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4362{
4363 nfs4_stateid dummy;
4364
4365 nfs4_stateid_copy(stateid, &invalid_stateid);
4366 return decode_stateid(xdr, &dummy);
4367}
4368
Linus Torvalds1da177e2005-04-16 15:20:36 -07004369static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 int status;
4372
4373 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004374 if (status != -EIO)
4375 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004376 if (!status)
Trond Myklebustfcd88432017-11-07 12:39:44 -05004377 status = decode_invalid_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004378 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379}
4380
Benny Halevydb942bb2009-08-14 17:19:56 +03004381static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4382{
Chuck Levercd937102012-03-02 17:14:31 -05004383 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004384}
4385
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004386static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4387{
4388 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4389}
4390
Fred Isaman0b7c0152012-04-20 14:47:39 -04004391static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 int status;
4394
4395 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004396 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004397 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004398 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399}
4400
4401static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4402{
Al Viro8687b632006-10-19 23:28:48 -07004403 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 uint32_t bmlen;
4405 int status;
4406
4407 status = decode_op_hdr(xdr, OP_CREATE);
4408 if (status)
4409 return status;
4410 if ((status = decode_change_info(xdr, cinfo)))
4411 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004412 p = xdr_inline_decode(xdr, 4);
4413 if (unlikely(!p))
4414 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004415 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004416 p = xdr_inline_decode(xdr, bmlen << 2);
4417 if (likely(p))
4418 return 0;
4419out_overflow:
4420 print_overflow_msg(__func__, xdr);
4421 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422}
4423
4424static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4425{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004426 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004427 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004428 int status;
4429
4430 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4431 goto xdr_error;
4432 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4433 goto xdr_error;
4434 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4435 goto xdr_error;
4436 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4437 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004438 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4439 &res->fh_expire_type)) != 0)
4440 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4442 goto xdr_error;
4443 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4444 goto xdr_error;
4445 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4446 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004447 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4448 res->exclcreat_bitmask)) != 0)
4449 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 status = verify_attr_len(xdr, savep, attrlen);
4451xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004452 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004453 return status;
4454}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004455
Linus Torvalds1da177e2005-04-16 15:20:36 -07004456static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4457{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004458 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004459 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004461
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4463 goto xdr_error;
4464 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4465 goto xdr_error;
4466 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4467 goto xdr_error;
4468
4469 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4470 goto xdr_error;
4471 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4472 goto xdr_error;
4473 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4474 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004475
4476 status = -EIO;
4477 if (unlikely(bitmap[0]))
4478 goto xdr_error;
4479
Linus Torvalds1da177e2005-04-16 15:20:36 -07004480 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4481 goto xdr_error;
4482 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4483 goto xdr_error;
4484 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4485 goto xdr_error;
4486
4487 status = verify_attr_len(xdr, savep, attrlen);
4488xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004489 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004490 return status;
4491}
4492
4493static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4494{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004495 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004496 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004498
Linus Torvalds1da177e2005-04-16 15:20:36 -07004499 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4500 goto xdr_error;
4501 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4502 goto xdr_error;
4503 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4504 goto xdr_error;
4505
4506 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4507 goto xdr_error;
4508 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4509 goto xdr_error;
4510
4511 status = verify_attr_len(xdr, savep, attrlen);
4512xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004513 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004514 return status;
4515}
4516
Andy Adamson88034c32012-05-23 05:02:34 -04004517static int decode_threshold_hint(struct xdr_stream *xdr,
4518 uint32_t *bitmap,
4519 uint64_t *res,
4520 uint32_t hint_bit)
4521{
4522 __be32 *p;
4523
4524 *res = 0;
4525 if (likely(bitmap[0] & hint_bit)) {
4526 p = xdr_inline_decode(xdr, 8);
4527 if (unlikely(!p))
4528 goto out_overflow;
4529 xdr_decode_hyper(p, res);
4530 }
4531 return 0;
4532out_overflow:
4533 print_overflow_msg(__func__, xdr);
4534 return -EIO;
4535}
4536
4537static int decode_first_threshold_item4(struct xdr_stream *xdr,
4538 struct nfs4_threshold *res)
4539{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004540 __be32 *p;
4541 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004542 uint32_t bitmap[3] = {0,}, attrlen;
4543 int status;
4544
4545 /* layout type */
4546 p = xdr_inline_decode(xdr, 4);
4547 if (unlikely(!p)) {
4548 print_overflow_msg(__func__, xdr);
4549 return -EIO;
4550 }
4551 res->l_type = be32_to_cpup(p);
4552
4553 /* thi_hintset bitmap */
4554 status = decode_attr_bitmap(xdr, bitmap);
4555 if (status < 0)
4556 goto xdr_error;
4557
4558 /* thi_hintlist length */
4559 status = decode_attr_length(xdr, &attrlen, &savep);
4560 if (status < 0)
4561 goto xdr_error;
4562 /* thi_hintlist */
4563 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4564 if (status < 0)
4565 goto xdr_error;
4566 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4567 if (status < 0)
4568 goto xdr_error;
4569 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4570 THRESHOLD_RD_IO);
4571 if (status < 0)
4572 goto xdr_error;
4573 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4574 THRESHOLD_WR_IO);
4575 if (status < 0)
4576 goto xdr_error;
4577
4578 status = verify_attr_len(xdr, savep, attrlen);
4579 res->bm = bitmap[0];
4580
4581 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4582 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4583 res->wr_io_sz);
4584xdr_error:
4585 dprintk("%s ret=%d!\n", __func__, status);
4586 return status;
4587}
4588
4589/*
4590 * Thresholds on pNFS direct I/O vrs MDS I/O
4591 */
4592static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4593 uint32_t *bitmap,
4594 struct nfs4_threshold *res)
4595{
4596 __be32 *p;
4597 int status = 0;
4598 uint32_t num;
4599
4600 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4601 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004602 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004603 /* Did the server return an unrequested attribute? */
4604 if (unlikely(res == NULL))
4605 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004606 p = xdr_inline_decode(xdr, 4);
4607 if (unlikely(!p))
4608 goto out_overflow;
4609 num = be32_to_cpup(p);
4610 if (num == 0)
4611 return 0;
4612 if (num > 1)
4613 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4614 "drivers per filesystem not supported\n",
4615 __func__);
4616
4617 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004618 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004619 }
4620 return status;
4621out_overflow:
4622 print_overflow_msg(__func__, xdr);
4623 return -EIO;
4624}
4625
Bryan Schumakerae42c702010-10-21 16:33:17 -04004626static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4627 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004628 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004629 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630{
Trond Myklebustbca79472009-03-11 14:10:26 -04004631 int status;
4632 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004633 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004634 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004636 status = decode_attr_type(xdr, bitmap, &type);
4637 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004638 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004639 fattr->mode = 0;
4640 if (status != 0) {
4641 fattr->mode |= nfs_type2fmt[type];
4642 fattr->valid |= status;
4643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004644
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004645 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4646 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004647 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004648 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004649
4650 status = decode_attr_size(xdr, bitmap, &fattr->size);
4651 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004652 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004653 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004654
4655 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4656 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004657 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004658 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004659
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004660 err = 0;
4661 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004662 if (status < 0)
4663 goto xdr_error;
4664
4665 status = decode_attr_filehandle(xdr, bitmap, fh);
4666 if (status < 0)
4667 goto xdr_error;
4668
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004669 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4670 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004671 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004672 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004673
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004674 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004675 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004676 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004677 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004678
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004679 status = -EIO;
4680 if (unlikely(bitmap[0]))
4681 goto xdr_error;
4682
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004683 status = decode_attr_mode(xdr, bitmap, &fmode);
4684 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004686 if (status != 0) {
4687 fattr->mode |= fmode;
4688 fattr->valid |= status;
4689 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004690
4691 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4692 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004694 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004695
Trond Myklebust6926afd2012-01-07 13:22:46 -05004696 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004697 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 Myklebust6926afd2012-01-07 13:22:46 -05004701 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004702 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004704 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004705
4706 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4707 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004708 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004709 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004710
4711 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4712 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004713 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004714 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004715
4716 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4717 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004719 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004720
4721 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4722 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004723 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004724 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004725
4726 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4727 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004729 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004730
Trond Myklebust28331a42011-04-27 13:47:52 -04004731 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004732 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004733 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004734 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004735
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004736 status = -EIO;
4737 if (unlikely(bitmap[1]))
4738 goto xdr_error;
4739
Andy Adamson88034c32012-05-23 05:02:34 -04004740 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4741 if (status < 0)
4742 goto xdr_error;
4743
David Quigleyaa9c2662013-05-22 12:50:44 -04004744 if (label) {
4745 status = decode_attr_security_label(xdr, bitmap, label);
4746 if (status < 0)
4747 goto xdr_error;
4748 fattr->valid |= status;
4749 }
4750
Bryan Schumakerae42c702010-10-21 16:33:17 -04004751xdr_error:
4752 dprintk("%s: xdr returned %d\n", __func__, -status);
4753 return status;
4754}
4755
4756static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004757 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004758 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004759{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004760 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004761 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004762 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004763 int status;
4764
4765 status = decode_op_hdr(xdr, OP_GETATTR);
4766 if (status < 0)
4767 goto xdr_error;
4768
4769 status = decode_attr_bitmap(xdr, bitmap);
4770 if (status < 0)
4771 goto xdr_error;
4772
4773 status = decode_attr_length(xdr, &attrlen, &savep);
4774 if (status < 0)
4775 goto xdr_error;
4776
David Quigleyaa9c2662013-05-22 12:50:44 -04004777 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4778 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004779 if (status < 0)
4780 goto xdr_error;
4781
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004782 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004783xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004784 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004785 return status;
4786}
4787
David Quigleyaa9c2662013-05-22 12:50:44 -04004788static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4789 struct nfs4_label *label, const struct nfs_server *server)
4790{
4791 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4792}
4793
Bryan Schumakerae42c702010-10-21 16:33:17 -04004794static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004795 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004796{
David Quigleyaa9c2662013-05-22 12:50:44 -04004797 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004798}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799
Andy Adamson504913f2010-10-20 00:17:57 -04004800/*
Jeff Layton3132e492016-08-10 15:58:24 -04004801 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004802 */
Jeff Layton3132e492016-08-10 15:58:24 -04004803static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004804 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004805{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004806 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004807 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004808
4809 p = xdr_inline_decode(xdr, 4);
4810 if (unlikely(!p))
4811 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004812 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004813
4814 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004815 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004816 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004817
4818 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004819 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004820 if (unlikely(!p))
4821 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004822
4823 /* If we get too many, then just cap it at the max */
4824 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4825 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4826 __func__, fsinfo->nlayouttypes);
4827 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4828 }
4829
4830 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4831 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004832 return 0;
4833out_overflow:
4834 print_overflow_msg(__func__, xdr);
4835 return -EIO;
4836}
4837
4838/*
4839 * The type of file system exported.
4840 * Note we must ensure that layouttype is set in any non-error case.
4841 */
4842static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004843 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004844{
4845 int status = 0;
4846
4847 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4848 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4849 return -EIO;
4850 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004851 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004852 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004853 }
Andy Adamson504913f2010-10-20 00:17:57 -04004854 return status;
4855}
4856
Fred Isamandae100c2011-07-30 20:52:37 -04004857/*
4858 * The prefered block size for layout directed io
4859 */
4860static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4861 uint32_t *res)
4862{
4863 __be32 *p;
4864
4865 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4866 *res = 0;
4867 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4868 p = xdr_inline_decode(xdr, 4);
4869 if (unlikely(!p)) {
4870 print_overflow_msg(__func__, xdr);
4871 return -EIO;
4872 }
4873 *res = be32_to_cpup(p);
4874 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4875 }
4876 return 0;
4877}
4878
Peng Tao2a92ee92015-09-26 02:24:37 +08004879/*
4880 * The granularity of a CLONE operation.
4881 */
4882static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4883 uint32_t *res)
4884{
4885 __be32 *p;
4886
4887 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4888 *res = 0;
4889 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4890 p = xdr_inline_decode(xdr, 4);
4891 if (unlikely(!p)) {
4892 print_overflow_msg(__func__, xdr);
4893 return -EIO;
4894 }
4895 *res = be32_to_cpup(p);
4896 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4897 }
4898 return 0;
4899}
4900
Linus Torvalds1da177e2005-04-16 15:20:36 -07004901static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4902{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004903 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004904 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004905 int status;
4906
4907 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4908 goto xdr_error;
4909 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4910 goto xdr_error;
4911 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4912 goto xdr_error;
4913
4914 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4915
4916 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4917 goto xdr_error;
4918 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4919 goto xdr_error;
4920 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4921 goto xdr_error;
4922 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4923 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4924 goto xdr_error;
4925 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004926
4927 status = -EIO;
4928 if (unlikely(bitmap[0]))
4929 goto xdr_error;
4930
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004931 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4932 if (status != 0)
4933 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004934 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004935 if (status != 0)
4936 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004937
4938 status = -EIO;
4939 if (unlikely(bitmap[1]))
4940 goto xdr_error;
4941
Fred Isamandae100c2011-07-30 20:52:37 -04004942 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4943 if (status)
4944 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004945 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4946 if (status)
4947 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004948
4949 status = verify_attr_len(xdr, savep, attrlen);
4950xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004951 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004952 return status;
4953}
4954
4955static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4956{
Al Viro8687b632006-10-19 23:28:48 -07004957 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004958 uint32_t len;
4959 int status;
4960
Trond Myklebust99367812007-07-17 21:52:41 -04004961 /* Zero handle first to allow comparisons */
4962 memset(fh, 0, sizeof(*fh));
4963
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 status = decode_op_hdr(xdr, OP_GETFH);
4965 if (status)
4966 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004967
Benny Halevyc0eae662009-08-14 17:20:14 +03004968 p = xdr_inline_decode(xdr, 4);
4969 if (unlikely(!p))
4970 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004971 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004972 if (len > NFS4_FHSIZE)
4973 return -EIO;
4974 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004975 p = xdr_inline_decode(xdr, len);
4976 if (unlikely(!p))
4977 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004978 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004980out_overflow:
4981 print_overflow_msg(__func__, xdr);
4982 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983}
4984
4985static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4986{
4987 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004988
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989 status = decode_op_hdr(xdr, OP_LINK);
4990 if (status)
4991 return status;
4992 return decode_change_info(xdr, cinfo);
4993}
4994
4995/*
4996 * We create the owner, so we know a proper owner.id length is 4.
4997 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004998static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005000 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07005001 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005002 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005003
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005004 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03005005 if (unlikely(!p))
5006 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005007 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03005008 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005009 type = be32_to_cpup(p++); /* 4 byte read */
5010 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005011 fl->fl_start = (loff_t)offset;
5012 fl->fl_end = fl->fl_start + (loff_t)length - 1;
5013 if (length == ~(uint64_t)0)
5014 fl->fl_end = OFFSET_MAX;
5015 fl->fl_type = F_WRLCK;
5016 if (type & 1)
5017 fl->fl_type = F_RDLCK;
5018 fl->fl_pid = 0;
5019 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04005020 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
5021 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
5022 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03005023 if (likely(p))
5024 return -NFS4ERR_DENIED;
5025out_overflow:
5026 print_overflow_msg(__func__, xdr);
5027 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005028}
5029
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005030static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005032 int status;
5033
5034 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005035 if (status == -EIO)
5036 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005037 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04005038 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005039 if (unlikely(status))
5040 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005041 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04005042 status = decode_lock_denied(xdr, NULL);
5043 if (res->open_seqid != NULL)
5044 nfs_increment_open_seqid(status, res->open_seqid);
5045 nfs_increment_lock_seqid(status, res->lock_seqid);
5046out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047 return status;
5048}
5049
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005050static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005051{
5052 int status;
5053 status = decode_op_hdr(xdr, OP_LOCKT);
5054 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005055 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005056 return status;
5057}
5058
Trond Myklebust911d1aa2006-01-03 09:55:16 +01005059static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005060{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005061 int status;
5062
5063 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005064 if (status != -EIO)
5065 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005066 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005067 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005068 return status;
5069}
5070
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005071static int decode_release_lockowner(struct xdr_stream *xdr)
5072{
5073 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5074}
5075
Linus Torvalds1da177e2005-04-16 15:20:36 -07005076static int decode_lookup(struct xdr_stream *xdr)
5077{
5078 return decode_op_hdr(xdr, OP_LOOKUP);
5079}
5080
Jeff Layton5b5faaf2017-06-29 06:34:52 -07005081static int decode_lookupp(struct xdr_stream *xdr)
5082{
5083 return decode_op_hdr(xdr, OP_LOOKUPP);
5084}
5085
Linus Torvalds1da177e2005-04-16 15:20:36 -07005086/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005087static int decode_space_limit(struct xdr_stream *xdr,
5088 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089{
Andy Adamson05d564f2008-12-23 16:06:15 -05005090 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005092 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005093
Benny Halevyc0eae662009-08-14 17:20:14 +03005094 p = xdr_inline_decode(xdr, 12);
5095 if (unlikely(!p))
5096 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005097 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005098 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005099 case NFS4_LIMIT_SIZE:
5100 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005101 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005102 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005103 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005104 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005105 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005106 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005107 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005108 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005109 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005110out_overflow:
5111 print_overflow_msg(__func__, xdr);
5112 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113}
5114
Trond Myklebust6ae37332015-01-30 14:21:14 -05005115static int decode_rw_delegation(struct xdr_stream *xdr,
5116 uint32_t delegation_type,
5117 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118{
Andy Adamson05d564f2008-12-23 16:06:15 -05005119 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005120 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005121
Trond Myklebust93b717f2016-05-16 17:42:43 -04005122 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005123 if (unlikely(status))
5124 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005125 p = xdr_inline_decode(xdr, 4);
5126 if (unlikely(!p))
5127 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005128 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005129
Linus Torvalds1da177e2005-04-16 15:20:36 -07005130 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005131 case NFS4_OPEN_DELEGATE_READ:
5132 res->delegation_type = FMODE_READ;
5133 break;
5134 case NFS4_OPEN_DELEGATE_WRITE:
5135 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005136 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 return -EIO;
5138 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005139 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005140out_overflow:
5141 print_overflow_msg(__func__, xdr);
5142 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005143}
5144
Trond Myklebust6ae37332015-01-30 14:21:14 -05005145static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5146{
5147 __be32 *p;
5148 uint32_t why_no_delegation;
5149
5150 p = xdr_inline_decode(xdr, 4);
5151 if (unlikely(!p))
5152 goto out_overflow;
5153 why_no_delegation = be32_to_cpup(p);
5154 switch (why_no_delegation) {
5155 case WND4_CONTENTION:
5156 case WND4_RESOURCE:
5157 xdr_inline_decode(xdr, 4);
5158 /* Ignore for now */
5159 }
5160 return 0;
5161out_overflow:
5162 print_overflow_msg(__func__, xdr);
5163 return -EIO;
5164}
5165
5166static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5167{
5168 __be32 *p;
5169 uint32_t delegation_type;
5170
5171 p = xdr_inline_decode(xdr, 4);
5172 if (unlikely(!p))
5173 goto out_overflow;
5174 delegation_type = be32_to_cpup(p);
5175 res->delegation_type = 0;
5176 switch (delegation_type) {
5177 case NFS4_OPEN_DELEGATE_NONE:
5178 return 0;
5179 case NFS4_OPEN_DELEGATE_READ:
5180 case NFS4_OPEN_DELEGATE_WRITE:
5181 return decode_rw_delegation(xdr, delegation_type, res);
5182 case NFS4_OPEN_DELEGATE_NONE_EXT:
5183 return decode_no_delegation(xdr, res);
5184 }
5185 return -EIO;
5186out_overflow:
5187 print_overflow_msg(__func__, xdr);
5188 return -EIO;
5189}
5190
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5192{
Andy Adamson05d564f2008-12-23 16:06:15 -05005193 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005194 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005195 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005196
Trond Myklebustc7848f62013-12-04 17:39:23 -05005197 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5198 return status;
5199 nfs_increment_open_seqid(status, res->seqid);
5200 if (status)
5201 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005202 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005203 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005204 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005205
Andy Adamson05d564f2008-12-23 16:06:15 -05005206 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207
Benny Halevyc0eae662009-08-14 17:20:14 +03005208 p = xdr_inline_decode(xdr, 8);
5209 if (unlikely(!p))
5210 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005211 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005212 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005213 if (bmlen > 10)
5214 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215
Benny Halevyc0eae662009-08-14 17:20:14 +03005216 p = xdr_inline_decode(xdr, bmlen << 2);
5217 if (unlikely(!p))
5218 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005219 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5220 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005221 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005222 for (; i < NFS4_BITMAP_SIZE; i++)
5223 res->attrset[i] = 0;
5224
Linus Torvalds1da177e2005-04-16 15:20:36 -07005225 return decode_delegation(xdr, res);
5226xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005227 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005228 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005229out_overflow:
5230 print_overflow_msg(__func__, xdr);
5231 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005232}
5233
5234static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5235{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 int status;
5237
Andy Adamson05d564f2008-12-23 16:06:15 -05005238 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005239 if (status != -EIO)
5240 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005241 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005242 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005243 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005244}
5245
5246static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5247{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248 int status;
5249
5250 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005251 if (status != -EIO)
5252 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005253 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005254 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005255 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005256}
5257
5258static int decode_putfh(struct xdr_stream *xdr)
5259{
5260 return decode_op_hdr(xdr, OP_PUTFH);
5261}
5262
5263static int decode_putrootfh(struct xdr_stream *xdr)
5264{
5265 return decode_op_hdr(xdr, OP_PUTROOTFH);
5266}
5267
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005268static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5269 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270{
Al Viro8687b632006-10-19 23:28:48 -07005271 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005272 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273 int status;
5274
5275 status = decode_op_hdr(xdr, OP_READ);
5276 if (status)
5277 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005278 p = xdr_inline_decode(xdr, 8);
5279 if (unlikely(!p))
5280 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005281 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005282 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005283 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005285 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 "count %u > recvd %u\n", count, recvd);
5287 count = recvd;
5288 eof = 0;
5289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 res->eof = eof;
5291 res->count = count;
5292 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005293out_overflow:
5294 print_overflow_msg(__func__, xdr);
5295 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296}
5297
5298static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5299{
Chuck Leverbcecff72007-10-26 13:32:03 -04005300 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005301 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302
5303 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005304 if (!status)
5305 status = decode_verifier(xdr, readdir->verifier.data);
5306 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005308 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005309 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005310 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005311 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312}
5313
5314static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5315{
5316 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005317 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005318 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 int status;
5320
5321 status = decode_op_hdr(xdr, OP_READLINK);
5322 if (status)
5323 return status;
5324
5325 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005326 p = xdr_inline_decode(xdr, 4);
5327 if (unlikely(!p))
5328 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005329 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005331 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 return -ENAMETOOLONG;
5333 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005334 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005336 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337 "count %u > recvd %u\n", len, recvd);
5338 return -EIO;
5339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005340 /*
5341 * The XDR encode routine has set things up so that
5342 * the link text will be copied directly into the
5343 * buffer. We just have to do overflow-checking,
5344 * and and null-terminate the text (the VFS expects
5345 * null-termination).
5346 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005347 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005349out_overflow:
5350 print_overflow_msg(__func__, xdr);
5351 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005352}
5353
5354static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5355{
5356 int status;
5357
5358 status = decode_op_hdr(xdr, OP_REMOVE);
5359 if (status)
5360 goto out;
5361 status = decode_change_info(xdr, cinfo);
5362out:
5363 return status;
5364}
5365
5366static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5367 struct nfs4_change_info *new_cinfo)
5368{
5369 int status;
5370
5371 status = decode_op_hdr(xdr, OP_RENAME);
5372 if (status)
5373 goto out;
5374 if ((status = decode_change_info(xdr, old_cinfo)))
5375 goto out;
5376 status = decode_change_info(xdr, new_cinfo);
5377out:
5378 return status;
5379}
5380
5381static int decode_renew(struct xdr_stream *xdr)
5382{
5383 return decode_op_hdr(xdr, OP_RENEW);
5384}
5385
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005386static int
5387decode_restorefh(struct xdr_stream *xdr)
5388{
5389 return decode_op_hdr(xdr, OP_RESTOREFH);
5390}
5391
J. Bruce Fields029d1052005-06-22 17:16:22 +00005392static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005393 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005394{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005395 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005396 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005397 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005398 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005399 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005400
Andy Adamsonbf118a32011-12-07 11:55:27 -05005401 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005402 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5403 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005404
Trond Myklebust519d3952012-08-14 17:30:10 -04005405 xdr_enter_page(xdr, xdr->buf->page_len);
5406
Trond Myklebustcff298c2012-08-14 17:14:17 -04005407 /* Calculate the offset of the page data */
5408 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005409
J. Bruce Fields029d1052005-06-22 17:16:22 +00005410 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5411 goto out;
5412 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5413 goto out;
5414
5415 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5416 return -EIO;
5417 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005418
Andy Adamsonbf118a32011-12-07 11:55:27 -05005419 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5420 * are stored with the acl data to handle the problem of
5421 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005422 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005423 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005424
5425 /* Check for receive buffer overflow */
5426 if (res->acl_len > (xdr->nwords << 2) ||
5427 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5428 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005429 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005430 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005431 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005432 } else
5433 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005434
5435out:
5436 return status;
5437}
5438
Linus Torvalds1da177e2005-04-16 15:20:36 -07005439static int
5440decode_savefh(struct xdr_stream *xdr)
5441{
5442 return decode_op_hdr(xdr, OP_SAVEFH);
5443}
5444
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005445static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005446{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447 int status;
5448
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449 status = decode_op_hdr(xdr, OP_SETATTR);
5450 if (status)
5451 return status;
Trond Myklebust37c88762018-03-20 17:03:08 -04005452 if (decode_bitmap4(xdr, NULL, 0) >= 0)
Benny Halevyc0eae662009-08-14 17:20:14 +03005453 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005454 print_overflow_msg(__func__, xdr);
5455 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456}
5457
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005458static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459{
Al Viro8687b632006-10-19 23:28:48 -07005460 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461 uint32_t opnum;
5462 int32_t nfserr;
5463
Benny Halevyc0eae662009-08-14 17:20:14 +03005464 p = xdr_inline_decode(xdr, 8);
5465 if (unlikely(!p))
5466 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005467 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005469 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005470 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471 return -EIO;
5472 }
Benny Halevycccddf42009-08-14 17:20:19 +03005473 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005474 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005475 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5476 if (unlikely(!p))
5477 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005478 p = xdr_decode_hyper(p, &res->clientid);
5479 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 } else if (nfserr == NFSERR_CLID_INUSE) {
5481 uint32_t len;
5482
5483 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005484 p = xdr_inline_decode(xdr, 4);
5485 if (unlikely(!p))
5486 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005487 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005488 p = xdr_inline_decode(xdr, len);
5489 if (unlikely(!p))
5490 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491
5492 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005493 p = xdr_inline_decode(xdr, 4);
5494 if (unlikely(!p))
5495 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005496 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005497 p = xdr_inline_decode(xdr, len);
5498 if (unlikely(!p))
5499 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005500 return -NFSERR_CLID_INUSE;
5501 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005502 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005503
5504 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005505out_overflow:
5506 print_overflow_msg(__func__, xdr);
5507 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005508}
5509
5510static int decode_setclientid_confirm(struct xdr_stream *xdr)
5511{
5512 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5513}
5514
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005515static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516{
Al Viro8687b632006-10-19 23:28:48 -07005517 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 int status;
5519
5520 status = decode_op_hdr(xdr, OP_WRITE);
5521 if (status)
5522 return status;
5523
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005524 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005525 if (unlikely(!p))
5526 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005527 res->count = be32_to_cpup(p++);
5528 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005529 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005530out_overflow:
5531 print_overflow_msg(__func__, xdr);
5532 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533}
5534
5535static int decode_delegreturn(struct xdr_stream *xdr)
5536{
5537 return decode_op_hdr(xdr, OP_DELEGRETURN);
5538}
5539
Chuck Leverfb15b262013-03-16 15:54:34 -04005540static int decode_secinfo_gss(struct xdr_stream *xdr,
5541 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005542{
Chuck Leverfb15b262013-03-16 15:54:34 -04005543 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005544 __be32 *p;
5545
5546 p = xdr_inline_decode(xdr, 4);
5547 if (unlikely(!p))
5548 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005549 oid_len = be32_to_cpup(p);
5550 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005551 goto out_err;
5552
Chuck Leverfb15b262013-03-16 15:54:34 -04005553 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005554 if (unlikely(!p))
5555 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005556 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5557 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005558
5559 p = xdr_inline_decode(xdr, 8);
5560 if (unlikely(!p))
5561 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005562 flavor->flavor_info.qop = be32_to_cpup(p++);
5563 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005564
5565 return 0;
5566
5567out_overflow:
5568 print_overflow_msg(__func__, xdr);
5569 return -EIO;
5570out_err:
5571 return -EINVAL;
5572}
5573
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005574static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005575{
Chuck Leverfb15b262013-03-16 15:54:34 -04005576 struct nfs4_secinfo4 *sec_flavor;
5577 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005578 int status;
5579 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005580
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005581 p = xdr_inline_decode(xdr, 4);
5582 if (unlikely(!p))
5583 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005584
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005585 res->flavors->num_flavors = 0;
5586 num_flavors = be32_to_cpup(p);
5587
5588 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005589 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005590 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005591 break;
5592
5593 p = xdr_inline_decode(xdr, 4);
5594 if (unlikely(!p))
5595 goto out_overflow;
5596 sec_flavor->flavor = be32_to_cpup(p);
5597
5598 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005599 status = decode_secinfo_gss(xdr, sec_flavor);
5600 if (status)
5601 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005602 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005603 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005604 }
5605
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005606 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005607out:
5608 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005609out_overflow:
5610 print_overflow_msg(__func__, xdr);
5611 return -EIO;
5612}
5613
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005614static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5615{
5616 int status = decode_op_hdr(xdr, OP_SECINFO);
5617 if (status)
5618 return status;
5619 return decode_secinfo_common(xdr, res);
5620}
5621
Benny Halevy99fe60d2009-04-01 09:22:29 -04005622#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005623static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5624{
5625 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5626 if (status)
5627 return status;
5628 return decode_secinfo_common(xdr, res);
5629}
5630
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005631static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5632{
5633 __be32 *p;
5634 uint32_t bitmap_words;
5635 unsigned int i;
5636
5637 p = xdr_inline_decode(xdr, 4);
Pan Bian4edabfd2017-04-23 14:49:41 +08005638 if (!p)
5639 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005640 bitmap_words = be32_to_cpup(p++);
5641 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5642 return -EIO;
5643 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5644 for (i = 0; i < bitmap_words; i++)
5645 op_map->u.words[i] = be32_to_cpup(p++);
5646
5647 return 0;
5648}
5649
Benny Halevy99fe60d2009-04-01 09:22:29 -04005650static int decode_exchange_id(struct xdr_stream *xdr,
5651 struct nfs41_exchange_id_res *res)
5652{
5653 __be32 *p;
5654 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005655 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005656 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005657 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005658
5659 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5660 if (status)
5661 return status;
5662
Benny Halevyc0eae662009-08-14 17:20:14 +03005663 p = xdr_inline_decode(xdr, 8);
5664 if (unlikely(!p))
5665 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005666 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005667 p = xdr_inline_decode(xdr, 12);
5668 if (unlikely(!p))
5669 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005670 res->seqid = be32_to_cpup(p++);
5671 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005672
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005673 res->state_protect.how = be32_to_cpup(p);
5674 switch (res->state_protect.how) {
5675 case SP4_NONE:
5676 break;
5677 case SP4_MACH_CRED:
5678 status = decode_op_map(xdr, &res->state_protect.enforce);
5679 if (status)
5680 return status;
5681 status = decode_op_map(xdr, &res->state_protect.allow);
5682 if (status)
5683 return status;
5684 break;
5685 default:
5686 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005687 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005688 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005689
Chuck Leveracdeb692012-05-21 22:46:16 -04005690 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005691 p = xdr_inline_decode(xdr, 8);
5692 if (unlikely(!p))
5693 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005694 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005695
Chuck Leveracdeb692012-05-21 22:46:16 -04005696 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005697 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5698 if (unlikely(status))
5699 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005700 memcpy(res->server_owner->major_id, dummy_str, dummy);
5701 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005702
Chuck Leveracdeb692012-05-21 22:46:16 -04005703 /* server_scope4 */
5704 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5705 if (unlikely(status))
5706 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005707 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5708 res->server_scope->server_scope_sz = dummy;
5709
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005710 /* Implementation Id */
5711 p = xdr_inline_decode(xdr, 4);
5712 if (unlikely(!p))
5713 goto out_overflow;
5714 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005715
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005716 if (impl_id_count) {
5717 /* nii_domain */
5718 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5719 if (unlikely(status))
5720 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005721 memcpy(res->impl_id->domain, dummy_str, dummy);
5722
5723 /* nii_name */
5724 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5725 if (unlikely(status))
5726 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005727 memcpy(res->impl_id->name, dummy_str, dummy);
5728
5729 /* nii_date */
5730 p = xdr_inline_decode(xdr, 12);
5731 if (unlikely(!p))
5732 goto out_overflow;
5733 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5734 res->impl_id->date.nseconds = be32_to_cpup(p);
5735
5736 /* if there's more than one entry, ignore the rest */
5737 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005738 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005739out_overflow:
5740 print_overflow_msg(__func__, xdr);
5741 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005742}
Andy Adamsonfc931582009-04-01 09:22:31 -04005743
5744static int decode_chan_attrs(struct xdr_stream *xdr,
5745 struct nfs4_channel_attrs *attrs)
5746{
5747 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005748 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005749
Benny Halevyc0eae662009-08-14 17:20:14 +03005750 p = xdr_inline_decode(xdr, 28);
5751 if (unlikely(!p))
5752 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005753 val = be32_to_cpup(p++); /* headerpadsz */
5754 if (val)
5755 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005756 attrs->max_rqst_sz = be32_to_cpup(p++);
5757 attrs->max_resp_sz = be32_to_cpup(p++);
5758 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5759 attrs->max_ops = be32_to_cpup(p++);
5760 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005761 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005762 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005763 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5764 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005765 return -EINVAL;
5766 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005767 if (nr_attrs == 1) {
5768 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5769 if (unlikely(!p))
5770 goto out_overflow;
5771 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005772 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005773out_overflow:
5774 print_overflow_msg(__func__, xdr);
5775 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005776}
5777
Benny Halevye78291e2009-08-14 17:20:00 +03005778static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5779{
5780 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005781}
5782
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005783static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5784 struct nfs41_bind_conn_to_session_res *res)
5785{
5786 __be32 *p;
5787 int status;
5788
5789 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5790 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005791 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005792 if (unlikely(status))
5793 return status;
5794
5795 /* dir flags, rdma mode bool */
5796 p = xdr_inline_decode(xdr, 8);
5797 if (unlikely(!p))
5798 goto out_overflow;
5799
5800 res->dir = be32_to_cpup(p++);
5801 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5802 return -EIO;
5803 if (be32_to_cpup(p) == 0)
5804 res->use_conn_in_rdma_mode = false;
5805 else
5806 res->use_conn_in_rdma_mode = true;
5807
5808 return 0;
5809out_overflow:
5810 print_overflow_msg(__func__, xdr);
5811 return -EIO;
5812}
5813
Andy Adamsonfc931582009-04-01 09:22:31 -04005814static int decode_create_session(struct xdr_stream *xdr,
5815 struct nfs41_create_session_res *res)
5816{
5817 __be32 *p;
5818 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005819
5820 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005821 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005822 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005823 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005824 return status;
5825
Andy Adamsonfc931582009-04-01 09:22:31 -04005826 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005827 p = xdr_inline_decode(xdr, 8);
5828 if (unlikely(!p))
5829 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005830 res->seqid = be32_to_cpup(p++);
5831 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005832
5833 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005834 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005835 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005836 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005837 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005838out_overflow:
5839 print_overflow_msg(__func__, xdr);
5840 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005841}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005842
5843static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5844{
5845 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5846}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005847
Trond Myklebust66245532012-05-25 17:18:09 -04005848static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5849{
5850 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5851}
5852
Ricardo Labiaga180197532009-12-05 16:08:40 -05005853static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5854{
5855 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5856}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005857#endif /* CONFIG_NFS_V4_1 */
5858
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005859static int decode_sequence(struct xdr_stream *xdr,
5860 struct nfs4_sequence_res *res,
5861 struct rpc_rqst *rqstp)
5862{
5863#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005864 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005865 struct nfs4_sessionid id;
5866 u32 dummy;
5867 int status;
5868 __be32 *p;
5869
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005870 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005871 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005872 if (!res->sr_slot->table->session)
5873 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005874
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005875 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005876 if (!status)
5877 status = decode_sessionid(xdr, &id);
5878 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005879 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005880
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005881 /*
5882 * If the server returns different values for sessionID, slotID or
5883 * sequence number, the server is looney tunes.
5884 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005885 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005886 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005887
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005888 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005889 NFS4_MAX_SESSIONID_LEN)) {
5890 dprintk("%s Invalid session id\n", __func__);
5891 goto out_err;
5892 }
Benny Halevye78291e2009-08-14 17:20:00 +03005893
Benny Halevyc0eae662009-08-14 17:20:14 +03005894 p = xdr_inline_decode(xdr, 20);
5895 if (unlikely(!p))
5896 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005897
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005898 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005899 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005900 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005901 dprintk("%s Invalid sequence number\n", __func__);
5902 goto out_err;
5903 }
5904 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005905 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005906 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005907 dprintk("%s Invalid slot id\n", __func__);
5908 goto out_err;
5909 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005910 /* highest slot id */
5911 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005912 /* target highest slot id */
5913 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005914 /* result flags */
5915 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005916 status = 0;
5917out_err:
5918 res->sr_status = status;
5919 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005920out_overflow:
5921 print_overflow_msg(__func__, xdr);
5922 status = -EIO;
5923 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005924#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005925 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005926#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005927}
5928
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005929#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005930static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5931{
5932 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5933 return decode_stateid(xdr, stateid);
5934}
5935
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005936static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005937 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005938{
Trond Myklebust4e590802015-03-09 14:01:25 -04005939 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005940 __be32 *p;
5941 uint32_t len, type;
5942 int status;
5943
5944 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5945 if (status) {
5946 if (status == -ETOOSMALL) {
5947 p = xdr_inline_decode(xdr, 4);
5948 if (unlikely(!p))
5949 goto out_overflow;
5950 pdev->mincount = be32_to_cpup(p);
5951 dprintk("%s: Min count too small. mincnt = %u\n",
5952 __func__, pdev->mincount);
5953 }
5954 return status;
5955 }
5956
5957 p = xdr_inline_decode(xdr, 8);
5958 if (unlikely(!p))
5959 goto out_overflow;
5960 type = be32_to_cpup(p++);
5961 if (type != pdev->layout_type) {
5962 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5963 __func__, pdev->layout_type, type);
5964 return -EINVAL;
5965 }
5966 /*
5967 * Get the length of the opaque device_addr4. xdr_read_pages places
5968 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5969 * and places the remaining xdr data in xdr_buf->tail
5970 */
5971 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005972 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5973 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005974
5975 /* Parse notification bitmap, verifying that it is zero. */
5976 p = xdr_inline_decode(xdr, 4);
5977 if (unlikely(!p))
5978 goto out_overflow;
5979 len = be32_to_cpup(p);
5980 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005981 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005982
5983 p = xdr_inline_decode(xdr, 4 * len);
5984 if (unlikely(!p))
5985 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005986
Trond Myklebust4e590802015-03-09 14:01:25 -04005987 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005988 for (i = 1; i < len; i++) {
5989 if (be32_to_cpup(p++)) {
5990 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005991 __func__);
5992 return -EIO;
5993 }
5994 }
5995 }
5996 return 0;
5997out_overflow:
5998 print_overflow_msg(__func__, xdr);
5999 return -EIO;
6000}
6001
6002static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
6003 struct nfs4_layoutget_res *res)
6004{
6005 __be32 *p;
6006 int status;
6007 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04006008 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006009
6010 status = decode_op_hdr(xdr, OP_LAYOUTGET);
6011 if (status)
6012 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006013 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006014 if (unlikely(!p))
6015 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006016 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04006017 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05006018 p = xdr_inline_decode(xdr, 4);
6019 if (unlikely(!p))
6020 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006021 layout_count = be32_to_cpup(p);
6022 if (!layout_count) {
6023 dprintk("%s: server responded with empty layout array\n",
6024 __func__);
6025 return -EINVAL;
6026 }
6027
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006028 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006029 if (unlikely(!p))
6030 goto out_overflow;
6031 p = xdr_decode_hyper(p, &res->range.offset);
6032 p = xdr_decode_hyper(p, &res->range.length);
6033 res->range.iomode = be32_to_cpup(p++);
6034 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006035 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006036
6037 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
6038 __func__,
6039 (unsigned long)res->range.offset,
6040 (unsigned long)res->range.length,
6041 res->range.iomode,
6042 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006043 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006044
Trond Myklebust64bd5772012-06-20 22:35:05 -04006045 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04006046 if (res->layoutp->len > recvd) {
6047 dprintk("NFS: server cheating in layoutget reply: "
6048 "layout len %u > recvd %u\n",
6049 res->layoutp->len, recvd);
6050 return -EINVAL;
6051 }
6052
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006053 if (layout_count > 1) {
6054 /* We only handle a length one array at the moment. Any
6055 * further entries are just ignored. Note that this means
6056 * the client may see a response that is less than the
6057 * minimum it requested.
6058 */
6059 dprintk("%s: server responded with %d layouts, dropping tail\n",
6060 __func__, layout_count);
6061 }
6062
6063 return 0;
6064out_overflow:
6065 print_overflow_msg(__func__, xdr);
6066 return -EIO;
6067}
Andy Adamson863a3c62011-03-23 13:27:54 +00006068
Benny Halevycbe82602011-05-22 19:52:37 +03006069static int decode_layoutreturn(struct xdr_stream *xdr,
6070 struct nfs4_layoutreturn_res *res)
6071{
6072 __be32 *p;
6073 int status;
6074
6075 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6076 if (status)
6077 return status;
6078 p = xdr_inline_decode(xdr, 4);
6079 if (unlikely(!p))
6080 goto out_overflow;
6081 res->lrs_present = be32_to_cpup(p);
6082 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006083 status = decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustfcd88432017-11-07 12:39:44 -05006084 else
6085 nfs4_stateid_copy(&res->stateid, &invalid_stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006086 return status;
6087out_overflow:
6088 print_overflow_msg(__func__, xdr);
6089 return -EIO;
6090}
6091
Andy Adamson863a3c62011-03-23 13:27:54 +00006092static int decode_layoutcommit(struct xdr_stream *xdr,
6093 struct rpc_rqst *req,
6094 struct nfs4_layoutcommit_res *res)
6095{
6096 __be32 *p;
6097 __u32 sizechanged;
6098 int status;
6099
6100 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006101 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006102 if (status)
6103 return status;
6104
6105 p = xdr_inline_decode(xdr, 4);
6106 if (unlikely(!p))
6107 goto out_overflow;
6108 sizechanged = be32_to_cpup(p);
6109
6110 if (sizechanged) {
6111 /* throw away new size */
6112 p = xdr_inline_decode(xdr, 8);
6113 if (unlikely(!p))
6114 goto out_overflow;
6115 }
6116 return 0;
6117out_overflow:
6118 print_overflow_msg(__func__, xdr);
6119 return -EIO;
6120}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006121
6122static int decode_test_stateid(struct xdr_stream *xdr,
6123 struct nfs41_test_stateid_res *res)
6124{
6125 __be32 *p;
6126 int status;
6127 int num_res;
6128
6129 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6130 if (status)
6131 return status;
6132
6133 p = xdr_inline_decode(xdr, 4);
6134 if (unlikely(!p))
6135 goto out_overflow;
6136 num_res = be32_to_cpup(p++);
6137 if (num_res != 1)
6138 goto out;
6139
6140 p = xdr_inline_decode(xdr, 4);
6141 if (unlikely(!p))
6142 goto out_overflow;
6143 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006144
6145 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006146out_overflow:
6147 print_overflow_msg(__func__, xdr);
6148out:
6149 return -EIO;
6150}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006151
6152static int decode_free_stateid(struct xdr_stream *xdr,
6153 struct nfs41_free_stateid_res *res)
6154{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006155 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006156 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006157}
Trond Myklebustcf805162016-11-15 14:56:07 -05006158#else
6159static inline
6160int decode_layoutreturn(struct xdr_stream *xdr,
6161 struct nfs4_layoutreturn_res *res)
6162{
6163 return 0;
6164}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006165#endif /* CONFIG_NFS_V4_1 */
6166
Linus Torvalds1da177e2005-04-16 15:20:36 -07006167/*
Benny Halevy49c25592008-12-23 16:06:16 -05006168 * END OF "GENERIC" DECODE ROUTINES.
6169 */
6170
6171/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172 * Decode OPEN_DOWNGRADE response
6173 */
Chuck Leverbf269552010-12-14 14:59:29 +00006174static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6175 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006176 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006177{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006178 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006179 struct compound_hdr hdr;
6180 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181
Chuck Leverbf269552010-12-14 14:59:29 +00006182 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006183 if (status)
6184 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006185 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006186 if (status)
6187 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006188 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006189 if (status)
6190 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006191 if (res->lr_res) {
6192 status = decode_layoutreturn(xdr, res->lr_res);
6193 res->lr_ret = status;
6194 if (status)
6195 goto out;
6196 }
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006199 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006200}
6201
6202/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 * Decode ACCESS response
6204 */
Chuck Leverbf269552010-12-14 14:59:29 +00006205static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006206 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006208 struct nfs4_accessres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006209 struct compound_hdr hdr;
6210 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006211
Chuck Leverbf269552010-12-14 14:59:29 +00006212 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006213 if (status)
6214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006215 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006216 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006218 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006219 if (status != 0)
6220 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006221 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006222 if (status != 0)
6223 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006224 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006225out:
6226 return status;
6227}
6228
6229/*
6230 * Decode LOOKUP response
6231 */
Chuck Leverbf269552010-12-14 14:59:29 +00006232static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006233 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006234{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006235 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006236 struct compound_hdr hdr;
6237 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006238
Chuck Leverbf269552010-12-14 14:59:29 +00006239 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006240 if (status)
6241 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006242 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006243 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006244 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006245 status = decode_putfh(xdr);
6246 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006247 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006248 status = decode_lookup(xdr);
6249 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006250 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006251 status = decode_getfh(xdr, res->fh);
6252 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006254 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006255out:
6256 return status;
6257}
6258
6259/*
Jeff Layton5b5faaf2017-06-29 06:34:52 -07006260 * Decode LOOKUPP response
6261 */
6262static int nfs4_xdr_dec_lookupp(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6263 void *data)
6264{
6265 struct nfs4_lookupp_res *res = data;
6266 struct compound_hdr hdr;
6267 int status;
6268
6269 status = decode_compound_hdr(xdr, &hdr);
6270 if (status)
6271 goto out;
6272 status = decode_sequence(xdr, &res->seq_res, rqstp);
6273 if (status)
6274 goto out;
6275 status = decode_putfh(xdr);
6276 if (status)
6277 goto out;
6278 status = decode_lookupp(xdr);
6279 if (status)
6280 goto out;
6281 status = decode_getfh(xdr, res->fh);
6282 if (status)
6283 goto out;
6284 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
6285out:
6286 return status;
6287}
6288
6289/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006290 * Decode LOOKUP_ROOT response
6291 */
Chuck Leverbf269552010-12-14 14:59:29 +00006292static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6293 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006294 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006296 struct nfs4_lookup_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006297 struct compound_hdr hdr;
6298 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006299
Chuck Leverbf269552010-12-14 14:59:29 +00006300 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006301 if (status)
6302 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006303 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006304 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006305 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006306 status = decode_putrootfh(xdr);
6307 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006308 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006309 status = decode_getfh(xdr, res->fh);
6310 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006311 status = decode_getfattr_label(xdr, res->fattr,
6312 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006313out:
6314 return status;
6315}
6316
6317/*
6318 * Decode REMOVE response
6319 */
Chuck Leverbf269552010-12-14 14:59:29 +00006320static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006321 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006323 struct nfs_removeres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006324 struct compound_hdr hdr;
6325 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006326
Chuck Leverbf269552010-12-14 14:59:29 +00006327 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006328 if (status)
6329 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006330 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006331 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006332 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006333 status = decode_putfh(xdr);
6334 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006335 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006336 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006337out:
6338 return status;
6339}
6340
6341/*
6342 * Decode RENAME response
6343 */
Chuck Leverbf269552010-12-14 14:59:29 +00006344static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006345 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006346{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006347 struct nfs_renameres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348 struct compound_hdr hdr;
6349 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006350
Chuck Leverbf269552010-12-14 14:59:29 +00006351 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006352 if (status)
6353 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006354 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006355 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006356 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006357 status = decode_putfh(xdr);
6358 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006360 status = decode_savefh(xdr);
6361 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006363 status = decode_putfh(xdr);
6364 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006365 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006366 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006367out:
6368 return status;
6369}
6370
6371/*
6372 * Decode LINK response
6373 */
Chuck Leverbf269552010-12-14 14:59:29 +00006374static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006375 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006376{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006377 struct nfs4_link_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006378 struct compound_hdr hdr;
6379 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006380
Chuck Leverbf269552010-12-14 14:59:29 +00006381 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006382 if (status)
6383 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006384 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006385 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006386 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006387 status = decode_putfh(xdr);
6388 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006389 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006390 status = decode_savefh(xdr);
6391 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006392 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_putfh(xdr);
6394 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_link(xdr, &res->cinfo);
6397 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006398 goto out;
6399 /*
6400 * Note order: OP_LINK leaves the directory as the current
6401 * filehandle.
6402 */
Chuck Leverbf269552010-12-14 14:59:29 +00006403 status = decode_restorefh(xdr);
6404 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006405 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006406 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006407out:
6408 return status;
6409}
6410
6411/*
6412 * Decode CREATE response
6413 */
Chuck Leverbf269552010-12-14 14:59:29 +00006414static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006415 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006416{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006417 struct nfs4_create_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006418 struct compound_hdr hdr;
6419 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006420
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006422 if (status)
6423 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006424 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006425 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_putfh(xdr);
6428 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006429 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006430 status = decode_create(xdr, &res->dir_cinfo);
6431 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006432 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006433 status = decode_getfh(xdr, res->fh);
6434 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006435 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006436 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437out:
6438 return status;
6439}
6440
6441/*
6442 * Decode SYMLINK response
6443 */
Chuck Leverbf269552010-12-14 14:59:29 +00006444static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006445 void *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006446{
Chuck Leverbf269552010-12-14 14:59:29 +00006447 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006448}
6449
6450/*
6451 * Decode GETATTR response
6452 */
Chuck Leverbf269552010-12-14 14:59:29 +00006453static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006454 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006455{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006456 struct nfs4_getattr_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006457 struct compound_hdr hdr;
6458 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006459
Chuck Leverbf269552010-12-14 14:59:29 +00006460 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006461 if (status)
6462 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006463 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006464 if (status)
6465 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006466 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006467 if (status)
6468 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006469 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006470out:
6471 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006472}
6473
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006474/*
6475 * Encode an SETACL request
6476 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006477static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006478 const void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006479{
Christoph Hellwigfcc85812017-05-08 10:01:49 +02006480 const struct nfs_setaclargs *args = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006481 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006482 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006483 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006484
Chuck Lever9f06c712010-12-14 14:59:18 +00006485 encode_compound_hdr(xdr, req, &hdr);
6486 encode_sequence(xdr, &args->seq_args, &hdr);
6487 encode_putfh(xdr, args->fh, &hdr);
6488 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006489 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006490}
Andy Adamson05d564f2008-12-23 16:06:15 -05006491
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006492/*
6493 * Decode SETACL response
6494 */
6495static int
Chuck Leverbf269552010-12-14 14:59:29 +00006496nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006497 void *data)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006498{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006499 struct nfs_setaclres *res = data;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006500 struct compound_hdr hdr;
6501 int status;
6502
Chuck Leverbf269552010-12-14 14:59:29 +00006503 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006504 if (status)
6505 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006506 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006507 if (status)
6508 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006509 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006510 if (status)
6511 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006512 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006513out:
6514 return status;
6515}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006516
6517/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006518 * Decode GETACL response
6519 */
6520static int
Chuck Leverbf269552010-12-14 14:59:29 +00006521nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006522 void *data)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006523{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006524 struct nfs_getaclres *res = data;
J. Bruce Fields029d1052005-06-22 17:16:22 +00006525 struct compound_hdr hdr;
6526 int status;
6527
Trond Myklebust331818f2012-02-03 18:30:53 -05006528 if (res->acl_scratch != NULL) {
6529 void *p = page_address(res->acl_scratch);
6530 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6531 }
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006533 if (status)
6534 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006535 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006536 if (status)
6537 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006538 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006539 if (status)
6540 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006541 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006542
6543out:
6544 return status;
6545}
6546
6547/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006548 * Decode CLOSE response
6549 */
Chuck Leverbf269552010-12-14 14:59:29 +00006550static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006551 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006552{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006553 struct nfs_closeres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006554 struct compound_hdr hdr;
6555 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006556
Chuck Leverbf269552010-12-14 14:59:29 +00006557 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006558 if (status)
6559 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006560 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006561 if (status)
6562 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006563 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006564 if (status)
6565 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006566 if (res->lr_res) {
6567 status = decode_layoutreturn(xdr, res->lr_res);
6568 res->lr_ret = status;
6569 if (status)
6570 goto out;
6571 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006572 if (res->fattr != NULL) {
6573 status = decode_getfattr(xdr, res->fattr, res->server);
6574 if (status != 0)
6575 goto out;
6576 }
Chuck Leverbf269552010-12-14 14:59:29 +00006577 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006578out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006579 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006580}
6581
6582/*
6583 * Decode OPEN response
6584 */
Chuck Leverbf269552010-12-14 14:59:29 +00006585static int nfs4_xdr_dec_open(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_openres *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);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006593 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;
Chuck Leverbf269552010-12-14 14:59:29 +00006601 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006602 if (status)
6603 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006604 status = decode_getfh(xdr, &res->fh);
6605 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006607 if (res->access_request)
6608 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006609 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006610out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006611 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006612}
6613
6614/*
6615 * Decode OPEN_CONFIRM response
6616 */
Chuck Leverbf269552010-12-14 14:59:29 +00006617static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6618 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006619 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006621 struct nfs_open_confirmres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006622 struct compound_hdr hdr;
6623 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006624
Chuck Leverbf269552010-12-14 14:59:29 +00006625 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006626 if (status)
6627 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006628 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006629 if (status)
6630 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006631 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006632out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006633 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634}
6635
6636/*
6637 * Decode OPEN response
6638 */
Chuck Leverbf269552010-12-14 14:59:29 +00006639static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6640 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006641 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006642{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006643 struct nfs_openres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006644 struct compound_hdr hdr;
6645 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006646
Chuck Leverbf269552010-12-14 14:59:29 +00006647 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006648 if (status)
6649 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006650 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006651 if (status)
6652 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006654 if (status)
6655 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006656 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006657 if (status)
6658 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006659 if (res->access_request)
6660 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006661 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006662out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006663 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006664}
6665
6666/*
6667 * Decode SETATTR response
6668 */
Chuck Leverbf269552010-12-14 14:59:29 +00006669static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6670 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006671 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006672{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006673 struct nfs_setattrres *res = data;
Andy Adamson05d564f2008-12-23 16:06:15 -05006674 struct compound_hdr hdr;
6675 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676
Chuck Leverbf269552010-12-14 14:59:29 +00006677 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006678 if (status)
6679 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006680 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006681 if (status)
6682 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006683 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006684 if (status)
6685 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006686 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006687 if (status)
6688 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006689 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006690out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006691 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006692}
6693
6694/*
6695 * Decode LOCK response
6696 */
Chuck Leverbf269552010-12-14 14:59:29 +00006697static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006698 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006700 struct nfs_lock_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006701 struct compound_hdr hdr;
6702 int status;
6703
Chuck Leverbf269552010-12-14 14:59:29 +00006704 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006705 if (status)
6706 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006707 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006708 if (status)
6709 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006710 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711 if (status)
6712 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006713 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006714out:
6715 return status;
6716}
6717
6718/*
6719 * Decode LOCKT response
6720 */
Chuck Leverbf269552010-12-14 14:59:29 +00006721static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006722 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006724 struct nfs_lockt_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006725 struct compound_hdr hdr;
6726 int status;
6727
Chuck Leverbf269552010-12-14 14:59:29 +00006728 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006729 if (status)
6730 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006731 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006732 if (status)
6733 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006734 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006735 if (status)
6736 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006737 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738out:
6739 return status;
6740}
6741
6742/*
6743 * Decode LOCKU response
6744 */
Chuck Leverbf269552010-12-14 14:59:29 +00006745static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006746 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006747{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006748 struct nfs_locku_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 struct compound_hdr hdr;
6750 int status;
6751
Chuck Leverbf269552010-12-14 14:59:29 +00006752 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 if (status)
6754 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006755 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006756 if (status)
6757 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006758 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006759 if (status)
6760 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006761 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006762out:
6763 return status;
6764}
6765
Chuck Leverbf269552010-12-14 14:59:29 +00006766static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6767 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006768{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006769 struct compound_hdr hdr;
6770 int status;
6771
Chuck Leverbf269552010-12-14 14:59:29 +00006772 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006773 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006774 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006775 return status;
6776}
6777
Linus Torvalds1da177e2005-04-16 15:20:36 -07006778/*
6779 * Decode READLINK response
6780 */
Chuck Leverbf269552010-12-14 14:59:29 +00006781static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6782 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006783 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006784{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006785 struct nfs4_readlink_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006786 struct compound_hdr hdr;
6787 int status;
6788
Chuck Leverbf269552010-12-14 14:59:29 +00006789 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006790 if (status)
6791 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006792 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006793 if (status)
6794 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006795 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 if (status)
6797 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006798 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006799out:
6800 return status;
6801}
6802
6803/*
6804 * Decode READDIR response
6805 */
Chuck Leverbf269552010-12-14 14:59:29 +00006806static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006807 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006808{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006809 struct nfs4_readdir_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810 struct compound_hdr hdr;
6811 int status;
6812
Chuck Leverbf269552010-12-14 14:59:29 +00006813 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006814 if (status)
6815 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006817 if (status)
6818 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006819 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006820 if (status)
6821 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006822 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006823out:
6824 return status;
6825}
6826
6827/*
6828 * Decode Read response
6829 */
Chuck Leverbf269552010-12-14 14:59:29 +00006830static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006831 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006832{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006833 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834 struct compound_hdr hdr;
6835 int status;
6836
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006838 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006839 if (status)
6840 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006841 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006842 if (status)
6843 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006844 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845 if (status)
6846 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006847 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006848 if (!status)
6849 status = res->count;
6850out:
6851 return status;
6852}
6853
6854/*
6855 * Decode WRITE response
6856 */
Chuck Leverbf269552010-12-14 14:59:29 +00006857static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006858 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006860 struct nfs_pgio_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006861 struct compound_hdr hdr;
6862 int status;
6863
Chuck Leverbf269552010-12-14 14:59:29 +00006864 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006865 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006866 if (status)
6867 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006868 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006869 if (status)
6870 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006871 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872 if (status)
6873 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006874 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006875 if (status)
6876 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006877 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006878 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 if (!status)
6880 status = res->count;
6881out:
6882 return status;
6883}
6884
6885/*
6886 * Decode COMMIT response
6887 */
Chuck Leverbf269552010-12-14 14:59:29 +00006888static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006889 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006890{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006891 struct nfs_commitres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006892 struct compound_hdr hdr;
6893 int status;
6894
Chuck Leverbf269552010-12-14 14:59:29 +00006895 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006896 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006897 if (status)
6898 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006899 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006900 if (status)
6901 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006902 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903 if (status)
6904 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006905 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006906out:
6907 return status;
6908}
6909
6910/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006911 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006912 */
Chuck Leverbf269552010-12-14 14:59:29 +00006913static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006914 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006915{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006916 struct nfs4_fsinfo_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006917 struct compound_hdr hdr;
6918 int status;
6919
Chuck Leverbf269552010-12-14 14:59:29 +00006920 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006921 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006922 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006923 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006924 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006925 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006926 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006927 return status;
6928}
6929
6930/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006931 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006932 */
Chuck Leverbf269552010-12-14 14:59:29 +00006933static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006934 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006935{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006936 struct nfs4_pathconf_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006937 struct compound_hdr hdr;
6938 int status;
6939
Chuck Leverbf269552010-12-14 14:59:29 +00006940 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006941 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006942 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006943 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006944 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006946 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006947 return status;
6948}
6949
6950/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006951 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006952 */
Chuck Leverbf269552010-12-14 14:59:29 +00006953static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006954 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006955{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006956 struct nfs4_statfs_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006957 struct compound_hdr hdr;
6958 int status;
6959
Chuck Leverbf269552010-12-14 14:59:29 +00006960 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006961 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006962 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006963 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006964 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006965 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006966 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006967 return status;
6968}
6969
6970/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006971 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006972 */
Chuck Leverbf269552010-12-14 14:59:29 +00006973static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6974 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02006975 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006976{
Christoph Hellwigfc016482017-05-08 15:09:02 +02006977 struct nfs4_server_caps_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006978 struct compound_hdr hdr;
6979 int status;
6980
Chuck Leverbf269552010-12-14 14:59:29 +00006981 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006982 if (status)
6983 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006984 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006985 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006986 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006987 status = decode_putfh(xdr);
6988 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006989 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006990 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006991out:
6992 return status;
6993}
6994
6995/*
6996 * Decode RENEW response
6997 */
Chuck Leverbf269552010-12-14 14:59:29 +00006998static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6999 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007000{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007001 struct compound_hdr hdr;
7002 int status;
7003
Chuck Leverbf269552010-12-14 14:59:29 +00007004 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007005 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007006 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007 return status;
7008}
7009
7010/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007011 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007012 */
Chuck Leverbf269552010-12-14 14:59:29 +00007013static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
7014 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007015 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007016{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007017 struct nfs4_setclientid_res *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007018 struct compound_hdr hdr;
7019 int status;
7020
Chuck Leverbf269552010-12-14 14:59:29 +00007021 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007022 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007023 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007024 return status;
7025}
7026
7027/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007028 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007029 */
Chuck Leverbf269552010-12-14 14:59:29 +00007030static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007031 struct xdr_stream *xdr,
7032 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007033{
Linus Torvalds1da177e2005-04-16 15:20:36 -07007034 struct compound_hdr hdr;
7035 int status;
7036
Chuck Leverbf269552010-12-14 14:59:29 +00007037 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007038 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007039 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040 return status;
7041}
7042
7043/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007044 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07007045 */
Chuck Leverbf269552010-12-14 14:59:29 +00007046static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
7047 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007048 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007049{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007050 struct nfs4_delegreturnres *res = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007051 struct compound_hdr hdr;
7052 int status;
7053
Chuck Leverbf269552010-12-14 14:59:29 +00007054 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007055 if (status)
7056 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007057 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007058 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01007059 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007060 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007061 if (status != 0)
7062 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05007063 if (res->lr_res) {
7064 status = decode_layoutreturn(xdr, res->lr_res);
7065 res->lr_ret = status;
7066 if (status)
7067 goto out;
7068 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05007069 if (res->fattr) {
7070 status = decode_getfattr(xdr, res->fattr, res->server);
7071 if (status != 0)
7072 goto out;
7073 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04007074 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01007075out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07007076 return status;
7077}
7078
Trond Myklebust683b57b2006-06-09 09:34:22 -04007079/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007080 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04007081 */
Chuck Leverbf269552010-12-14 14:59:29 +00007082static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
7083 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007084 void *data)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007085{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007086 struct nfs4_fs_locations_res *res = data;
Trond Myklebust683b57b2006-06-09 09:34:22 -04007087 struct compound_hdr hdr;
7088 int status;
7089
Chuck Leverbf269552010-12-14 14:59:29 +00007090 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007091 if (status)
7092 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007093 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04007094 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007095 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007096 status = decode_putfh(xdr);
7097 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04007098 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04007099 if (res->migration) {
7100 xdr_enter_page(xdr, PAGE_SIZE);
7101 status = decode_getfattr_generic(xdr,
7102 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05007103 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04007104 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04007105 if (status)
7106 goto out;
7107 if (res->renew)
7108 status = decode_renew(xdr);
7109 } else {
7110 status = decode_lookup(xdr);
7111 if (status)
7112 goto out;
7113 xdr_enter_page(xdr, PAGE_SIZE);
7114 status = decode_getfattr_generic(xdr,
7115 &res->fs_locations->fattr,
7116 NULL, res->fs_locations,
7117 NULL, res->fs_locations->server);
7118 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04007119out:
7120 return status;
7121}
7122
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007123/*
7124 * Decode SECINFO response
7125 */
7126static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
7127 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007128 void *data)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007129{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007130 struct nfs4_secinfo_res *res = data;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007131 struct compound_hdr hdr;
7132 int status;
7133
7134 status = decode_compound_hdr(xdr, &hdr);
7135 if (status)
7136 goto out;
7137 status = decode_sequence(xdr, &res->seq_res, rqstp);
7138 if (status)
7139 goto out;
7140 status = decode_putfh(xdr);
7141 if (status)
7142 goto out;
7143 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007144out:
7145 return status;
7146}
7147
Chuck Lever44c99932013-10-17 14:13:30 -04007148/*
7149 * Decode FSID_PRESENT response
7150 */
7151static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7152 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007153 void *data)
Chuck Lever44c99932013-10-17 14:13:30 -04007154{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007155 struct nfs4_fsid_present_res *res = data;
Chuck Lever44c99932013-10-17 14:13:30 -04007156 struct compound_hdr hdr;
7157 int status;
7158
7159 status = decode_compound_hdr(xdr, &hdr);
7160 if (status)
7161 goto out;
7162 status = decode_sequence(xdr, &res->seq_res, rqstp);
7163 if (status)
7164 goto out;
7165 status = decode_putfh(xdr);
7166 if (status)
7167 goto out;
7168 status = decode_getfh(xdr, res->fh);
7169 if (status)
7170 goto out;
7171 if (res->renew)
7172 status = decode_renew(xdr);
7173out:
7174 return status;
7175}
7176
Benny Halevy99fe60d2009-04-01 09:22:29 -04007177#if defined(CONFIG_NFS_V4_1)
7178/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007179 * Decode BIND_CONN_TO_SESSION response
7180 */
7181static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7182 struct xdr_stream *xdr,
7183 void *res)
7184{
7185 struct compound_hdr hdr;
7186 int status;
7187
7188 status = decode_compound_hdr(xdr, &hdr);
7189 if (!status)
7190 status = decode_bind_conn_to_session(xdr, res);
7191 return status;
7192}
7193
7194/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007195 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007196 */
Chuck Leverbf269552010-12-14 14:59:29 +00007197static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7198 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007199 void *res)
7200{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007201 struct compound_hdr hdr;
7202 int status;
7203
Chuck Leverbf269552010-12-14 14:59:29 +00007204 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007205 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007206 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007207 return status;
7208}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007209
7210/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007211 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007212 */
Chuck Leverbf269552010-12-14 14:59:29 +00007213static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7214 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007215 void *res)
Andy Adamsonfc931582009-04-01 09:22:31 -04007216{
Andy Adamsonfc931582009-04-01 09:22:31 -04007217 struct compound_hdr hdr;
7218 int status;
7219
Chuck Leverbf269552010-12-14 14:59:29 +00007220 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007221 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007222 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007223 return status;
7224}
7225
7226/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007227 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007228 */
Chuck Leverbf269552010-12-14 14:59:29 +00007229static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7230 struct xdr_stream *xdr,
7231 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007232{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007233 struct compound_hdr hdr;
7234 int status;
7235
Chuck Leverbf269552010-12-14 14:59:29 +00007236 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007237 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007238 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007239 return status;
7240}
7241
7242/*
Trond Myklebust66245532012-05-25 17:18:09 -04007243 * Decode DESTROY_CLIENTID response
7244 */
7245static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7246 struct xdr_stream *xdr,
7247 void *res)
7248{
7249 struct compound_hdr hdr;
7250 int status;
7251
7252 status = decode_compound_hdr(xdr, &hdr);
7253 if (!status)
7254 status = decode_destroy_clientid(xdr, res);
7255 return status;
7256}
7257
7258/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007259 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007260 */
Chuck Leverbf269552010-12-14 14:59:29 +00007261static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7262 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007263 void *res)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007264{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007265 struct compound_hdr hdr;
7266 int status;
7267
Chuck Leverbf269552010-12-14 14:59:29 +00007268 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007269 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007270 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007271 return status;
7272}
7273
7274/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007275 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007276 */
Chuck Leverbf269552010-12-14 14:59:29 +00007277static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7278 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007279 void *data)
Andy Adamson2050f0c2009-04-01 09:22:30 -04007280{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007281 struct nfs4_get_lease_time_res *res = data;
Andy Adamson2050f0c2009-04-01 09:22:30 -04007282 struct compound_hdr hdr;
7283 int status;
7284
Chuck Leverbf269552010-12-14 14:59:29 +00007285 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007286 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007287 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007288 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007289 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007290 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007291 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007292 return status;
7293}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007294
7295/*
7296 * Decode RECLAIM_COMPLETE response
7297 */
Chuck Leverbf269552010-12-14 14:59:29 +00007298static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7299 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007300 void *data)
Ricardo Labiaga180197532009-12-05 16:08:40 -05007301{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007302 struct nfs41_reclaim_complete_res *res = data;
Ricardo Labiaga180197532009-12-05 16:08:40 -05007303 struct compound_hdr hdr;
7304 int status;
7305
Chuck Leverbf269552010-12-14 14:59:29 +00007306 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007307 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007308 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007309 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307310 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007311 return status;
7312}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007313
7314/*
7315 * Decode GETDEVINFO response
7316 */
Chuck Leverbf269552010-12-14 14:59:29 +00007317static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7318 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007319 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007320{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007321 struct nfs4_getdeviceinfo_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007322 struct compound_hdr hdr;
7323 int status;
7324
Chuck Leverbf269552010-12-14 14:59:29 +00007325 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007326 if (status != 0)
7327 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007328 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007329 if (status != 0)
7330 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007331 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007332out:
7333 return status;
7334}
7335
7336/*
7337 * Decode LAYOUTGET response
7338 */
Chuck Leverbf269552010-12-14 14:59:29 +00007339static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7340 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007341 void *data)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007342{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007343 struct nfs4_layoutget_res *res = data;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007344 struct compound_hdr hdr;
7345 int status;
7346
Chuck Leverbf269552010-12-14 14:59:29 +00007347 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007348 if (status)
7349 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007350 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007351 if (status)
7352 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007353 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007354 if (status)
7355 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007356 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007357out:
7358 return status;
7359}
Andy Adamson863a3c62011-03-23 13:27:54 +00007360
7361/*
Benny Halevycbe82602011-05-22 19:52:37 +03007362 * Decode LAYOUTRETURN response
7363 */
7364static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7365 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007366 void *data)
Benny Halevycbe82602011-05-22 19:52:37 +03007367{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007368 struct nfs4_layoutreturn_res *res = data;
Benny Halevycbe82602011-05-22 19:52:37 +03007369 struct compound_hdr hdr;
7370 int status;
7371
7372 status = decode_compound_hdr(xdr, &hdr);
7373 if (status)
7374 goto out;
7375 status = decode_sequence(xdr, &res->seq_res, rqstp);
7376 if (status)
7377 goto out;
7378 status = decode_putfh(xdr);
7379 if (status)
7380 goto out;
7381 status = decode_layoutreturn(xdr, res);
7382out:
7383 return status;
7384}
7385
7386/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007387 * Decode LAYOUTCOMMIT response
7388 */
7389static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7390 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007391 void *data)
Andy Adamson863a3c62011-03-23 13:27:54 +00007392{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007393 struct nfs4_layoutcommit_res *res = data;
Andy Adamson863a3c62011-03-23 13:27:54 +00007394 struct compound_hdr hdr;
7395 int status;
7396
7397 status = decode_compound_hdr(xdr, &hdr);
7398 if (status)
7399 goto out;
7400 status = decode_sequence(xdr, &res->seq_res, rqstp);
7401 if (status)
7402 goto out;
7403 status = decode_putfh(xdr);
7404 if (status)
7405 goto out;
7406 status = decode_layoutcommit(xdr, rqstp, res);
7407 if (status)
7408 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007409 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007410out:
7411 return status;
7412}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007413
7414/*
7415 * Decode SECINFO_NO_NAME response
7416 */
7417static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7418 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007419 void *data)
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007420{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007421 struct nfs4_secinfo_res *res = data;
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007422 struct compound_hdr hdr;
7423 int status;
7424
7425 status = decode_compound_hdr(xdr, &hdr);
7426 if (status)
7427 goto out;
7428 status = decode_sequence(xdr, &res->seq_res, rqstp);
7429 if (status)
7430 goto out;
7431 status = decode_putrootfh(xdr);
7432 if (status)
7433 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007434 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007435out:
7436 return status;
7437}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007438
7439/*
7440 * Decode TEST_STATEID response
7441 */
7442static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7443 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007444 void *data)
Bryan Schumaker7d974792011-06-02 14:59:08 -04007445{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007446 struct nfs41_test_stateid_res *res = data;
Bryan Schumaker7d974792011-06-02 14:59:08 -04007447 struct compound_hdr hdr;
7448 int status;
7449
7450 status = decode_compound_hdr(xdr, &hdr);
7451 if (status)
7452 goto out;
7453 status = decode_sequence(xdr, &res->seq_res, rqstp);
7454 if (status)
7455 goto out;
7456 status = decode_test_stateid(xdr, res);
7457out:
7458 return status;
7459}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007460
7461/*
7462 * Decode FREE_STATEID response
7463 */
7464static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7465 struct xdr_stream *xdr,
Christoph Hellwigfc016482017-05-08 15:09:02 +02007466 void *data)
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007467{
Christoph Hellwigfc016482017-05-08 15:09:02 +02007468 struct nfs41_free_stateid_res *res = data;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007469 struct compound_hdr hdr;
7470 int status;
7471
7472 status = decode_compound_hdr(xdr, &hdr);
7473 if (status)
7474 goto out;
7475 status = decode_sequence(xdr, &res->seq_res, rqstp);
7476 if (status)
7477 goto out;
7478 status = decode_free_stateid(xdr, res);
7479out:
7480 return status;
7481}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007482#endif /* CONFIG_NFS_V4_1 */
7483
Chuck Lever573c4e12010-12-14 14:58:11 +00007484/**
7485 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7486 * the local page cache.
7487 * @xdr: XDR stream where entry resides
7488 * @entry: buffer to fill in with entry data
7489 * @plus: boolean indicating whether this should be a readdirplus entry
7490 *
7491 * Returns zero if successful, otherwise a negative errno value is
7492 * returned.
7493 *
7494 * This function is not invoked during READDIR reply decoding, but
7495 * rather whenever an application invokes the getdents(2) system call
7496 * on a directory already in our cache.
7497 */
7498int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
Benjamin Coddingtona7a3b1e2017-06-20 08:33:44 -04007499 bool plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007500{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007501 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007502 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007503 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007504 __be32 *p = xdr_inline_decode(xdr, 4);
7505 if (unlikely(!p))
7506 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007507 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007508 p = xdr_inline_decode(xdr, 4);
7509 if (unlikely(!p))
7510 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007511 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007512 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007513 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007514 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007515 }
7516
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007517 p = xdr_inline_decode(xdr, 12);
7518 if (unlikely(!p))
7519 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007520 entry->prev_cookie = entry->cookie;
7521 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007522 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007523
Trond Myklebust9af8c222010-10-24 11:52:55 -04007524 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007525 if (unlikely(!p))
7526 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007527 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007528
7529 /*
7530 * In case the server doesn't return an inode number,
7531 * we fake one here. (We don't use inode number 0,
7532 * since glibc seems to choke on it...)
7533 */
7534 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007535 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007536
Trond Myklebust9af8c222010-10-24 11:52:55 -04007537 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007538 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007539
Trond Myklebust256e48b2012-06-21 11:18:13 -04007540 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007541 goto out_overflow;
7542
Chuck Lever573c4e12010-12-14 14:58:11 +00007543 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007544 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007545 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007546 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7547 entry->ino = entry->fattr->mounted_on_fileid;
7548 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007549 entry->ino = entry->fattr->fileid;
7550
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007551 entry->d_type = DT_UNKNOWN;
7552 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7553 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7554
Chuck Lever573c4e12010-12-14 14:58:11 +00007555 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007556
7557out_overflow:
7558 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007559 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007560}
7561
7562/*
7563 * We need to translate between nfs status return values and
7564 * the local errno values which may not be the same.
7565 */
7566static struct {
7567 int stat;
7568 int errno;
7569} nfs_errtbl[] = {
7570 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007571 { NFS4ERR_PERM, -EPERM },
7572 { NFS4ERR_NOENT, -ENOENT },
7573 { NFS4ERR_IO, -errno_NFSERR_IO},
7574 { NFS4ERR_NXIO, -ENXIO },
7575 { NFS4ERR_ACCESS, -EACCES },
7576 { NFS4ERR_EXIST, -EEXIST },
7577 { NFS4ERR_XDEV, -EXDEV },
7578 { NFS4ERR_NOTDIR, -ENOTDIR },
7579 { NFS4ERR_ISDIR, -EISDIR },
7580 { NFS4ERR_INVAL, -EINVAL },
7581 { NFS4ERR_FBIG, -EFBIG },
7582 { NFS4ERR_NOSPC, -ENOSPC },
7583 { NFS4ERR_ROFS, -EROFS },
7584 { NFS4ERR_MLINK, -EMLINK },
7585 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7586 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7587 { NFS4ERR_DQUOT, -EDQUOT },
7588 { NFS4ERR_STALE, -ESTALE },
7589 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007590 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7591 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7592 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007593 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007594 { NFS4ERR_BADTYPE, -EBADTYPE },
7595 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007596 { NFS4ERR_SYMLINK, -ELOOP },
7597 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7598 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007599 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007600};
7601
7602/*
7603 * Convert an NFS error code to a local one.
7604 * This one is used jointly by NFSv2 and NFSv3.
7605 */
7606static int
David Howells0a8ea432006-08-22 20:06:08 -04007607nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007608{
7609 int i;
7610 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7611 if (nfs_errtbl[i].stat == stat)
7612 return nfs_errtbl[i].errno;
7613 }
7614 if (stat <= 10000 || stat > 10100) {
7615 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007616 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007617 }
7618 /* If we cannot translate the error, the recovery routines should
7619 * handle it.
7620 * Note: remaining NFSv4 error codes have values > 10000, so should
7621 * not conflict with native Linux error codes.
7622 */
Benny Halevy856dff32008-03-31 17:39:06 +03007623 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007624}
7625
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007626#ifdef CONFIG_NFS_V4_2
7627#include "nfs42xdr.c"
7628#endif /* CONFIG_NFS_V4_2 */
7629
Linus Torvalds1da177e2005-04-16 15:20:36 -07007630#define PROC(proc, argtype, restype) \
7631[NFSPROC4_CLNT_##proc] = { \
7632 .p_proc = NFSPROC4_COMPOUND, \
Christoph Hellwigfcc85812017-05-08 10:01:49 +02007633 .p_encode = nfs4_xdr_##argtype, \
Christoph Hellwigfc016482017-05-08 15:09:02 +02007634 .p_decode = nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007635 .p_arglen = NFS4_##argtype##_sz, \
7636 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007637 .p_statidx = NFSPROC4_CLNT_##proc, \
7638 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007639}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007640
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007641#define STUB(proc) \
7642[NFSPROC4_CLNT_##proc] = { \
7643 .p_name = #proc, \
7644}
7645
Trond Myklebust8634ef52018-01-06 09:53:49 -05007646#if defined(CONFIG_NFS_V4_1)
7647#define PROC41(proc, argtype, restype) \
7648 PROC(proc, argtype, restype)
7649#else
7650#define PROC41(proc, argtype, restype) \
7651 STUB(proc)
7652#endif
7653
7654#if defined(CONFIG_NFS_V4_2)
7655#define PROC42(proc, argtype, restype) \
7656 PROC(proc, argtype, restype)
7657#else
7658#define PROC42(proc, argtype, restype) \
7659 STUB(proc)
7660#endif
7661
Christoph Hellwig511e9362017-05-12 15:36:49 +02007662const struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007663 PROC(READ, enc_read, dec_read),
7664 PROC(WRITE, enc_write, dec_write),
7665 PROC(COMMIT, enc_commit, dec_commit),
7666 PROC(OPEN, enc_open, dec_open),
7667 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7668 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7669 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7670 PROC(CLOSE, enc_close, dec_close),
7671 PROC(SETATTR, enc_setattr, dec_setattr),
7672 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7673 PROC(RENEW, enc_renew, dec_renew),
7674 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7675 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7676 PROC(LOCK, enc_lock, dec_lock),
7677 PROC(LOCKT, enc_lockt, dec_lockt),
7678 PROC(LOCKU, enc_locku, dec_locku),
7679 PROC(ACCESS, enc_access, dec_access),
7680 PROC(GETATTR, enc_getattr, dec_getattr),
7681 PROC(LOOKUP, enc_lookup, dec_lookup),
7682 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7683 PROC(REMOVE, enc_remove, dec_remove),
7684 PROC(RENAME, enc_rename, dec_rename),
7685 PROC(LINK, enc_link, dec_link),
7686 PROC(SYMLINK, enc_symlink, dec_symlink),
7687 PROC(CREATE, enc_create, dec_create),
7688 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7689 PROC(STATFS, enc_statfs, dec_statfs),
7690 PROC(READLINK, enc_readlink, dec_readlink),
7691 PROC(READDIR, enc_readdir, dec_readdir),
7692 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7693 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7694 PROC(GETACL, enc_getacl, dec_getacl),
7695 PROC(SETACL, enc_setacl, dec_setacl),
7696 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7697 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007698 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007699 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007700 PROC41(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7701 PROC41(CREATE_SESSION, enc_create_session, dec_create_session),
7702 PROC41(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7703 PROC41(SEQUENCE, enc_sequence, dec_sequence),
7704 PROC41(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7705 PROC41(RECLAIM_COMPLETE,enc_reclaim_complete, dec_reclaim_complete),
7706 PROC41(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7707 PROC41(LAYOUTGET, enc_layoutget, dec_layoutget),
7708 PROC41(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
7709 PROC41(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
7710 PROC41(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
7711 PROC41(TEST_STATEID, enc_test_stateid, dec_test_stateid),
7712 PROC41(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007713 STUB(GETDEVICELIST),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007714 PROC41(BIND_CONN_TO_SESSION,
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007715 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust8634ef52018-01-06 09:53:49 -05007716 PROC41(DESTROY_CLIENTID,enc_destroy_clientid, dec_destroy_clientid),
7717 PROC42(SEEK, enc_seek, dec_seek),
7718 PROC42(ALLOCATE, enc_allocate, dec_allocate),
7719 PROC42(DEALLOCATE, enc_deallocate, dec_deallocate),
7720 PROC42(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
7721 PROC42(CLONE, enc_clone, dec_clone),
7722 PROC42(COPY, enc_copy, dec_copy),
7723 PROC(LOOKUPP, enc_lookupp, dec_lookupp),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007724};
7725
Christoph Hellwigc5518582017-05-08 23:27:10 +02007726static unsigned int nfs_version4_counts[ARRAY_SIZE(nfs4_procedures)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05007727const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007728 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007729 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Christoph Hellwigc5518582017-05-08 23:27:10 +02007730 .procs = nfs4_procedures,
7731 .counts = nfs_version4_counts,
Linus Torvalds1da177e2005-04-16 15:20:36 -07007732};
7733
7734/*
7735 * Local variables:
7736 * c-basic-offset: 8
7737 * End:
7738 */