blob: 125212588115c4db6c5556b7c8b45b0296139e92 [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)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400162#define encode_share_access_maxsz \
163 (2)
Alexandros Batsakis4882ef72009-12-05 13:30:21 -0500164#define encode_createmode_maxsz (1 + encode_attrs_maxsz + encode_verifier_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400165#define encode_opentype_maxsz (1 + encode_createmode_maxsz)
166#define encode_claim_null_maxsz (1 + nfs4_name_maxsz)
167#define encode_open_maxsz (op_encode_hdr_maxsz + \
168 2 + encode_share_access_maxsz + 2 + \
169 open_owner_id_maxsz + \
170 encode_opentype_maxsz + \
171 encode_claim_null_maxsz)
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500172#define decode_space_limit_maxsz (3)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400173#define decode_ace_maxsz (3 + nfs4_owner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400174#define decode_delegation_maxsz (1 + decode_stateid_maxsz + 1 + \
Trond Myklebust5a1f6d92017-02-19 16:08:29 -0500175 decode_space_limit_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400176 decode_ace_maxsz)
177#define decode_change_info_maxsz (5)
178#define decode_open_maxsz (op_decode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400179 decode_stateid_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400180 decode_change_info_maxsz + 1 + \
181 nfs4_fattr_bitmap_maxsz + \
182 decode_delegation_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400183#define encode_open_confirm_maxsz \
184 (op_encode_hdr_maxsz + \
185 encode_stateid_maxsz + 1)
186#define decode_open_confirm_maxsz \
187 (op_decode_hdr_maxsz + \
188 decode_stateid_maxsz)
189#define encode_open_downgrade_maxsz \
190 (op_encode_hdr_maxsz + \
191 encode_stateid_maxsz + 1 + \
192 encode_share_access_maxsz)
193#define decode_open_downgrade_maxsz \
194 (op_decode_hdr_maxsz + \
195 decode_stateid_maxsz)
196#define encode_close_maxsz (op_encode_hdr_maxsz + \
197 1 + encode_stateid_maxsz)
198#define decode_close_maxsz (op_decode_hdr_maxsz + \
199 decode_stateid_maxsz)
200#define encode_setattr_maxsz (op_encode_hdr_maxsz + \
201 encode_stateid_maxsz + \
202 encode_attrs_maxsz)
203#define decode_setattr_maxsz (op_decode_hdr_maxsz + \
204 nfs4_fattr_bitmap_maxsz)
205#define encode_read_maxsz (op_encode_hdr_maxsz + \
206 encode_stateid_maxsz + 3)
207#define decode_read_maxsz (op_decode_hdr_maxsz + 2)
208#define encode_readdir_maxsz (op_encode_hdr_maxsz + \
David Quigleyaa9c2662013-05-22 12:50:44 -0400209 2 + encode_verifier_maxsz + 5 + \
210 nfs4_label_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400211#define decode_readdir_maxsz (op_decode_hdr_maxsz + \
Chuck Levera7697f62014-03-12 12:51:17 -0400212 decode_verifier_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400213#define encode_readlink_maxsz (op_encode_hdr_maxsz)
214#define decode_readlink_maxsz (op_decode_hdr_maxsz + 1)
215#define encode_write_maxsz (op_encode_hdr_maxsz + \
216 encode_stateid_maxsz + 4)
217#define decode_write_maxsz (op_decode_hdr_maxsz + \
218 2 + decode_verifier_maxsz)
219#define encode_commit_maxsz (op_encode_hdr_maxsz + 3)
220#define decode_commit_maxsz (op_decode_hdr_maxsz + \
221 decode_verifier_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define encode_remove_maxsz (op_encode_hdr_maxsz + \
223 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400224#define decode_remove_maxsz (op_decode_hdr_maxsz + \
225 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226#define encode_rename_maxsz (op_encode_hdr_maxsz + \
227 2 * nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400228#define decode_rename_maxsz (op_decode_hdr_maxsz + \
229 decode_change_info_maxsz + \
230 decode_change_info_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231#define encode_link_maxsz (op_encode_hdr_maxsz + \
232 nfs4_name_maxsz)
Benny Halevy6ce18392009-04-01 09:22:06 -0400233#define decode_link_maxsz (op_decode_hdr_maxsz + decode_change_info_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400234#define encode_lockowner_maxsz (7)
Trond Myklebust9104a552007-07-17 21:52:42 -0400235#define encode_lock_maxsz (op_encode_hdr_maxsz + \
236 7 + \
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400237 1 + encode_stateid_maxsz + 1 + \
238 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400239#define decode_lock_denied_maxsz \
240 (8 + decode_lockowner_maxsz)
241#define decode_lock_maxsz (op_decode_hdr_maxsz + \
242 decode_lock_denied_maxsz)
Trond Myklebustdaccbde2010-06-25 18:11:43 -0400243#define encode_lockt_maxsz (op_encode_hdr_maxsz + 5 + \
244 encode_lockowner_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400245#define decode_lockt_maxsz (op_decode_hdr_maxsz + \
246 decode_lock_denied_maxsz)
247#define encode_locku_maxsz (op_encode_hdr_maxsz + 3 + \
248 encode_stateid_maxsz + \
249 4)
250#define decode_locku_maxsz (op_decode_hdr_maxsz + \
251 decode_stateid_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400252#define encode_release_lockowner_maxsz \
253 (op_encode_hdr_maxsz + \
254 encode_lockowner_maxsz)
255#define decode_release_lockowner_maxsz \
256 (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400257#define encode_access_maxsz (op_encode_hdr_maxsz + 1)
258#define decode_access_maxsz (op_decode_hdr_maxsz + 2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259#define encode_symlink_maxsz (op_encode_hdr_maxsz + \
260 1 + nfs4_name_maxsz + \
Chuck Lever94a6d752006-08-22 20:06:23 -0400261 1 + \
J. Bruce Fields96928202005-06-22 17:16:22 +0000262 nfs4_fattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263#define decode_symlink_maxsz (op_decode_hdr_maxsz + 8)
264#define encode_create_maxsz (op_encode_hdr_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400265 1 + 2 + nfs4_name_maxsz + \
266 encode_attrs_maxsz)
Trond Myklebust2cebf822007-07-02 13:57:28 -0400267#define decode_create_maxsz (op_decode_hdr_maxsz + \
268 decode_change_info_maxsz + \
269 nfs4_fattr_bitmap_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400270#define encode_statfs_maxsz (encode_getattr_maxsz)
271#define decode_statfs_maxsz (decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272#define encode_delegreturn_maxsz (op_encode_hdr_maxsz + 4)
273#define decode_delegreturn_maxsz (op_decode_hdr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400274#define encode_getacl_maxsz (encode_getattr_maxsz)
275#define decode_getacl_maxsz (op_decode_hdr_maxsz + \
276 nfs4_fattr_bitmap_maxsz + 1)
277#define encode_setacl_maxsz (op_encode_hdr_maxsz + \
278 encode_stateid_maxsz + 3)
279#define decode_setacl_maxsz (decode_setattr_maxsz)
Trond Myklebuste6889622007-07-02 13:58:30 -0400280#define encode_fs_locations_maxsz \
281 (encode_getattr_maxsz)
282#define decode_fs_locations_maxsz \
283 (0)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000284#define encode_secinfo_maxsz (op_encode_hdr_maxsz + nfs4_name_maxsz)
Bryan Schumaker1650add2011-06-02 15:07:35 -0400285#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 -0400286
287#if defined(CONFIG_NFS_V4_1)
Andy Adamsonfc931582009-04-01 09:22:31 -0400288#define NFS4_MAX_MACHINE_NAME_LEN (64)
Jim Reesd751f742012-11-16 18:12:06 -0500289#define IMPL_NAME_LIMIT (sizeof(utsname()->sysname) + sizeof(utsname()->release) + \
290 sizeof(utsname()->version) + sizeof(utsname()->machine) + 8)
Andy Adamsonfc931582009-04-01 09:22:31 -0400291
Benny Halevy99fe60d2009-04-01 09:22:29 -0400292#define encode_exchange_id_maxsz (op_encode_hdr_maxsz + \
293 encode_verifier_maxsz + \
294 1 /* co_ownerid.len */ + \
Jeff Laytonb8fb2f52015-06-09 19:43:58 -0400295 /* eia_clientowner */ \
296 1 + XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400297 1 /* flags */ + \
298 1 /* spa_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400299 /* max is SP4_MACH_CRED (for now) */ + \
300 1 + NFS4_OP_MAP_NUM_WORDS + \
301 1 + NFS4_OP_MAP_NUM_WORDS + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500302 1 /* implementation id array of size 1 */ + \
303 1 /* nii_domain */ + \
304 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
305 1 /* nii_name */ + \
Jim Reesd751f742012-11-16 18:12:06 -0500306 XDR_QUADLEN(IMPL_NAME_LIMIT) + \
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -0500307 3 /* nii_date */)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400308#define decode_exchange_id_maxsz (op_decode_hdr_maxsz + \
309 2 /* eir_clientid */ + \
310 1 /* eir_sequenceid */ + \
311 1 /* eir_flags */ + \
312 1 /* spr_how */ + \
Weston Andros Adamson2031cd12013-08-13 16:37:32 -0400313 /* max is SP4_MACH_CRED (for now) */ + \
314 1 + NFS4_OP_MAP_NUM_WORDS + \
315 1 + NFS4_OP_MAP_NUM_WORDS + \
Benny Halevy99fe60d2009-04-01 09:22:29 -0400316 2 /* eir_server_owner.so_minor_id */ + \
317 /* eir_server_owner.so_major_id<> */ \
318 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
319 /* eir_server_scope<> */ \
320 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 + \
321 1 /* eir_server_impl_id array length */ + \
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -0500322 1 /* nii_domain */ + \
323 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
324 1 /* nii_name */ + \
325 XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + \
326 3 /* nii_date */)
Andy Adamsonfc931582009-04-01 09:22:31 -0400327#define encode_channel_attrs_maxsz (6 + 1 /* ca_rdma_ird.len (0) */)
328#define decode_channel_attrs_maxsz (6 + \
329 1 /* ca_rdma_ird.len */ + \
330 1 /* ca_rdma_ird */)
331#define encode_create_session_maxsz (op_encode_hdr_maxsz + \
332 2 /* csa_clientid */ + \
333 1 /* csa_sequence */ + \
334 1 /* csa_flags */ + \
335 encode_channel_attrs_maxsz + \
336 encode_channel_attrs_maxsz + \
337 1 /* csa_cb_program */ + \
338 1 /* csa_sec_parms.len (1) */ + \
339 1 /* cb_secflavor (AUTH_SYS) */ + \
340 1 /* stamp */ + \
341 1 /* machinename.len */ + \
342 XDR_QUADLEN(NFS4_MAX_MACHINE_NAME_LEN) + \
343 1 /* uid */ + \
344 1 /* gid */ + \
345 1 /* gids.len (0) */)
346#define decode_create_session_maxsz (op_decode_hdr_maxsz + \
347 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
348 1 /* csr_sequence */ + \
349 1 /* csr_flags */ + \
350 decode_channel_attrs_maxsz + \
351 decode_channel_attrs_maxsz)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400352#define encode_bind_conn_to_session_maxsz (op_encode_hdr_maxsz + \
353 /* bctsa_sessid */ \
354 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
355 1 /* bctsa_dir */ + \
356 1 /* bctsa_use_conn_in_rdma_mode */)
357#define decode_bind_conn_to_session_maxsz (op_decode_hdr_maxsz + \
358 /* bctsr_sessid */ \
359 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + \
360 1 /* bctsr_dir */ + \
361 1 /* bctsr_use_conn_in_rdma_mode */)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400362#define encode_destroy_session_maxsz (op_encode_hdr_maxsz + 4)
363#define decode_destroy_session_maxsz (op_decode_hdr_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400364#define encode_destroy_clientid_maxsz (op_encode_hdr_maxsz + 2)
365#define decode_destroy_clientid_maxsz (op_decode_hdr_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400366#define encode_sequence_maxsz (op_encode_hdr_maxsz + \
367 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 4)
368#define decode_sequence_maxsz (op_decode_hdr_maxsz + \
369 XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500370#define encode_reclaim_complete_maxsz (op_encode_hdr_maxsz + 4)
371#define decode_reclaim_complete_maxsz (op_decode_hdr_maxsz + 4)
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700372#define encode_getdeviceinfo_maxsz (op_encode_hdr_maxsz + \
373 XDR_QUADLEN(NFS4_DEVICEID4_SIZE) + \
374 1 /* layout type */ + \
375 1 /* maxcount */ + \
376 1 /* bitmap size */ + \
377 1 /* notification bitmap length */ + \
378 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400379#define decode_getdeviceinfo_maxsz (op_decode_hdr_maxsz + \
380 1 /* layout type */ + \
381 1 /* opaque devaddr4 length */ + \
382 /* devaddr4 payload is read into page */ \
383 1 /* notification bitmap length */ + \
Christoph Hellwig84c9dee2014-09-10 17:37:28 -0700384 1 /* notification bitmap, word 0 */)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400385#define encode_layoutget_maxsz (op_encode_hdr_maxsz + 10 + \
386 encode_stateid_maxsz)
387#define decode_layoutget_maxsz (op_decode_hdr_maxsz + 8 + \
388 decode_stateid_maxsz + \
389 XDR_QUADLEN(PNFS_LAYOUT_MAXSIZE))
Andy Adamson863a3c62011-03-23 13:27:54 +0000390#define encode_layoutcommit_maxsz (op_encode_hdr_maxsz + \
391 2 /* offset */ + \
392 2 /* length */ + \
393 1 /* reclaim */ + \
394 encode_stateid_maxsz + \
395 1 /* new offset (true) */ + \
396 2 /* last byte written */ + \
397 1 /* nt_timechanged (false) */ + \
398 1 /* layoutupdate4 layout type */ + \
Christoph Hellwig5f919c92014-08-21 11:09:25 -0500399 1 /* layoutupdate4 opaqueue len */)
400 /* the actual content of layoutupdate4 should
401 be allocated by drivers and spliced in
402 using xdr_write_pages */
Andy Adamson863a3c62011-03-23 13:27:54 +0000403#define decode_layoutcommit_maxsz (op_decode_hdr_maxsz + 3)
Benny Halevycbe82602011-05-22 19:52:37 +0300404#define encode_layoutreturn_maxsz (8 + op_encode_hdr_maxsz + \
405 encode_stateid_maxsz + \
Trond Myklebust6669cb82015-08-27 20:43:20 -0400406 1 + \
407 XDR_QUADLEN(NFS4_OPAQUE_LIMIT))
Benny Halevycbe82602011-05-22 19:52:37 +0300408#define decode_layoutreturn_maxsz (op_decode_hdr_maxsz + \
409 1 + decode_stateid_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400410#define encode_secinfo_no_name_maxsz (op_encode_hdr_maxsz + 1)
411#define decode_secinfo_no_name_maxsz decode_secinfo_maxsz
Bryan Schumaker7d974792011-06-02 14:59:08 -0400412#define encode_test_stateid_maxsz (op_encode_hdr_maxsz + 2 + \
413 XDR_QUADLEN(NFS4_STATEID_SIZE))
414#define decode_test_stateid_maxsz (op_decode_hdr_maxsz + 2 + 1)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400415#define encode_free_stateid_maxsz (op_encode_hdr_maxsz + 1 + \
416 XDR_QUADLEN(NFS4_STATEID_SIZE))
Andy Adamson9f79fb42013-09-10 12:56:29 -0400417#define decode_free_stateid_maxsz (op_decode_hdr_maxsz)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400418#else /* CONFIG_NFS_V4_1 */
419#define encode_sequence_maxsz 0
420#define decode_sequence_maxsz 0
Trond Myklebustcf805162016-11-15 14:56:07 -0500421#define encode_layoutreturn_maxsz 0
422#define decode_layoutreturn_maxsz 0
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400423#endif /* CONFIG_NFS_V4_1 */
424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425#define NFS4_enc_compound_sz (1024) /* XXX: large enough? */
426#define NFS4_dec_compound_sz (1024) /* XXX: large enough? */
427#define NFS4_enc_read_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400428 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400430 encode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431#define NFS4_dec_read_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400432 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400434 decode_read_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435#define NFS4_enc_readlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400436 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400438 encode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#define NFS4_dec_readlink_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400440 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400442 decode_readlink_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443#define NFS4_enc_readdir_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400444 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400446 encode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#define NFS4_dec_readdir_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400448 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400450 decode_readdir_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451#define NFS4_enc_write_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400452 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400454 encode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400455 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#define NFS4_dec_write_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400457 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400459 decode_write_maxsz + \
Trond Myklebust4f9838c2005-10-27 22:12:44 -0400460 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461#define NFS4_enc_commit_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400462 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 encode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400464 encode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465#define NFS4_dec_commit_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400466 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 decode_putfh_maxsz + \
Trond Myklebust85827152012-04-29 10:44:42 -0400468 decode_commit_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469#define NFS4_enc_open_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400470 encode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400471 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400472 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400473 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400474 encode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400475 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476#define NFS4_dec_open_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400477 decode_sequence_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400478 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400479 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400480 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400481 decode_getfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400482 decode_getattr_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400483#define NFS4_enc_open_confirm_sz \
484 (compound_encode_hdr_maxsz + \
485 encode_putfh_maxsz + \
486 encode_open_confirm_maxsz)
487#define NFS4_dec_open_confirm_sz \
488 (compound_decode_hdr_maxsz + \
489 decode_putfh_maxsz + \
490 decode_open_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491#define NFS4_enc_open_noattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400492 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 encode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400494 encode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400495 encode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400496 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497#define NFS4_dec_open_noattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400498 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 decode_putfh_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400500 decode_open_maxsz + \
Weston Andros Adamson6168f622012-09-10 14:00:46 -0400501 decode_access_maxsz + \
Trond Myklebust2cebf822007-07-02 13:57:28 -0400502 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503#define NFS4_enc_open_downgrade_sz \
504 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400505 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400506 encode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500507 encode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400508 encode_open_downgrade_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509#define NFS4_dec_open_downgrade_sz \
510 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400511 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400512 decode_putfh_maxsz + \
Trond Myklebustb6808142016-11-20 13:34:16 -0500513 decode_layoutreturn_maxsz + \
Trond Myklebust3947b742016-10-27 18:27:02 -0400514 decode_open_downgrade_maxsz)
Trond Myklebust9104a552007-07-17 21:52:42 -0400515#define NFS4_enc_close_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400516 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400517 encode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500518 encode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400519 encode_close_maxsz + \
520 encode_getattr_maxsz)
521#define NFS4_dec_close_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400522 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400523 decode_putfh_maxsz + \
Trond Myklebustcf805162016-11-15 14:56:07 -0500524 decode_layoutreturn_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400525 decode_close_maxsz + \
526 decode_getattr_maxsz)
527#define NFS4_enc_setattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400528 encode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400529 encode_putfh_maxsz + \
530 encode_setattr_maxsz + \
531 encode_getattr_maxsz)
532#define NFS4_dec_setattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400533 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400534 decode_putfh_maxsz + \
535 decode_setattr_maxsz + \
536 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537#define NFS4_enc_fsinfo_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400538 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 encode_putfh_maxsz + \
540 encode_fsinfo_maxsz)
541#define NFS4_dec_fsinfo_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400542 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 decode_putfh_maxsz + \
544 decode_fsinfo_maxsz)
545#define NFS4_enc_renew_sz (compound_encode_hdr_maxsz + \
546 encode_renew_maxsz)
547#define NFS4_dec_renew_sz (compound_decode_hdr_maxsz + \
548 decode_renew_maxsz)
549#define NFS4_enc_setclientid_sz (compound_encode_hdr_maxsz + \
550 encode_setclientid_maxsz)
551#define NFS4_dec_setclientid_sz (compound_decode_hdr_maxsz + \
552 decode_setclientid_maxsz)
553#define NFS4_enc_setclientid_confirm_sz \
554 (compound_encode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400555 encode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556#define NFS4_dec_setclientid_confirm_sz \
557 (compound_decode_hdr_maxsz + \
Chuck Lever83ca7f52013-03-16 15:55:53 -0400558 decode_setclientid_confirm_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559#define NFS4_enc_lock_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400560 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400562 encode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#define NFS4_dec_lock_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400564 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400566 decode_lock_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define NFS4_enc_lockt_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400568 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400570 encode_lockt_maxsz)
571#define NFS4_dec_lockt_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400572 decode_sequence_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400573 decode_putfh_maxsz + \
574 decode_lockt_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575#define NFS4_enc_locku_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400576 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400578 encode_locku_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579#define NFS4_dec_locku_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400580 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400582 decode_locku_maxsz)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -0400583#define NFS4_enc_release_lockowner_sz \
584 (compound_encode_hdr_maxsz + \
585 encode_lockowner_maxsz)
586#define NFS4_dec_release_lockowner_sz \
587 (compound_decode_hdr_maxsz + \
588 decode_lockowner_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589#define NFS4_enc_access_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400590 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 encode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400592 encode_access_maxsz + \
593 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594#define NFS4_dec_access_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400595 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 decode_putfh_maxsz + \
Trond Myklebust76b32992007-08-10 17:45:11 -0400597 decode_access_maxsz + \
598 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#define NFS4_enc_getattr_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400600 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 encode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400602 encode_getattr_maxsz + \
603 encode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604#define NFS4_dec_getattr_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400605 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 decode_putfh_maxsz + \
Chuck Lever44c99932013-10-17 14:13:30 -0400607 decode_getattr_maxsz + \
608 decode_renew_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609#define NFS4_enc_lookup_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400610 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 encode_putfh_maxsz + \
612 encode_lookup_maxsz + \
613 encode_getattr_maxsz + \
614 encode_getfh_maxsz)
615#define NFS4_dec_lookup_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400616 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400618 decode_lookup_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 decode_getattr_maxsz + \
620 decode_getfh_maxsz)
621#define NFS4_enc_lookup_root_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400622 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 encode_putrootfh_maxsz + \
624 encode_getattr_maxsz + \
625 encode_getfh_maxsz)
626#define NFS4_dec_lookup_root_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400627 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 decode_putrootfh_maxsz + \
629 decode_getattr_maxsz + \
630 decode_getfh_maxsz)
631#define NFS4_enc_remove_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400632 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400634 encode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635#define NFS4_dec_remove_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400636 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400638 decode_remove_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#define NFS4_enc_rename_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400640 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 encode_putfh_maxsz + \
642 encode_savefh_maxsz + \
643 encode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400644 encode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645#define NFS4_dec_rename_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400646 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 decode_putfh_maxsz + \
648 decode_savefh_maxsz + \
649 decode_putfh_maxsz + \
Trond Myklebust778d2812012-04-27 13:48:19 -0400650 decode_rename_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651#define NFS4_enc_link_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400652 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 encode_putfh_maxsz + \
654 encode_savefh_maxsz + \
655 encode_putfh_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400656 encode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400657 encode_restorefh_maxsz + \
Trond Myklebusta9f69912012-04-27 13:48:17 -0400658 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659#define NFS4_dec_link_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 Myklebust91ba2ee2005-10-27 22:12:42 -0400664 decode_link_maxsz + \
Trond Myklebust91ba2ee2005-10-27 22:12:42 -0400665 decode_restorefh_maxsz + \
666 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667#define NFS4_enc_symlink_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400668 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 encode_putfh_maxsz + \
670 encode_symlink_maxsz + \
671 encode_getattr_maxsz + \
672 encode_getfh_maxsz)
673#define NFS4_dec_symlink_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_symlink_maxsz + \
677 decode_getattr_maxsz + \
678 decode_getfh_maxsz)
679#define NFS4_enc_create_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400680 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 encode_putfh_maxsz + \
682 encode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400683 encode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400684 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685#define NFS4_dec_create_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400686 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 decode_putfh_maxsz + \
688 decode_create_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400689 decode_getfh_maxsz + \
Trond Myklebust56ae19f2005-10-27 22:12:40 -0400690 decode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691#define NFS4_enc_pathconf_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400692 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 encode_putfh_maxsz + \
694 encode_getattr_maxsz)
695#define NFS4_dec_pathconf_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400696 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 decode_putfh_maxsz + \
698 decode_getattr_maxsz)
699#define NFS4_enc_statfs_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400700 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400702 encode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703#define NFS4_dec_statfs_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400704 decode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400706 decode_statfs_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707#define NFS4_enc_server_caps_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400708 encode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800709 encode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 encode_getattr_maxsz)
711#define NFS4_dec_server_caps_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400712 decode_sequence_maxsz + \
Trond Myklebustab91f262007-02-02 14:47:17 -0800713 decode_putfh_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 decode_getattr_maxsz)
715#define NFS4_enc_delegreturn_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400716 encode_sequence_maxsz + \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 encode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500718 encode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100719 encode_delegreturn_maxsz + \
720 encode_getattr_maxsz)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721#define NFS4_dec_delegreturn_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400722 decode_sequence_maxsz + \
Trond Myklebustd8434d4c2016-11-16 13:54:00 -0500723 decode_putfh_maxsz + \
Trond Myklebust586f1c32016-11-15 15:03:33 -0500724 decode_layoutreturn_maxsz + \
Trond Myklebustfa178f22006-01-03 09:55:38 +0100725 decode_delegreturn_maxsz + \
726 decode_getattr_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000727#define NFS4_enc_getacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400728 encode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000729 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400730 encode_getacl_maxsz)
J. Bruce Fields029d1052005-06-22 17:16:22 +0000731#define NFS4_dec_getacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400732 decode_sequence_maxsz + \
J. Bruce Fields029d1052005-06-22 17:16:22 +0000733 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400734 decode_getacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000735#define NFS4_enc_setacl_sz (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400736 encode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000737 encode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400738 encode_setacl_maxsz)
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000739#define NFS4_dec_setacl_sz (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400740 decode_sequence_maxsz + \
J. Bruce Fields23ec6962005-06-22 17:16:22 +0000741 decode_putfh_maxsz + \
Trond Myklebust9104a552007-07-17 21:52:42 -0400742 decode_setacl_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400743#define NFS4_enc_fs_locations_sz \
744 (compound_encode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400745 encode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400746 encode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400747 encode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400748 encode_fs_locations_maxsz + \
749 encode_renew_maxsz)
Trond Myklebust683b57b2006-06-09 09:34:22 -0400750#define NFS4_dec_fs_locations_sz \
751 (compound_decode_hdr_maxsz + \
Andy Adamson9b7b9fc2009-04-01 09:22:11 -0400752 decode_sequence_maxsz + \
Trond Myklebust683b57b2006-06-09 09:34:22 -0400753 decode_putfh_maxsz + \
Trond Myklebuste6889622007-07-02 13:58:30 -0400754 decode_lookup_maxsz + \
Chuck Leverb03d7352013-10-17 14:12:50 -0400755 decode_fs_locations_maxsz + \
756 decode_renew_maxsz)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +0000757#define NFS4_enc_secinfo_sz (compound_encode_hdr_maxsz + \
758 encode_sequence_maxsz + \
759 encode_putfh_maxsz + \
760 encode_secinfo_maxsz)
761#define NFS4_dec_secinfo_sz (compound_decode_hdr_maxsz + \
762 decode_sequence_maxsz + \
763 decode_putfh_maxsz + \
764 decode_secinfo_maxsz)
Chuck Lever44c99932013-10-17 14:13:30 -0400765#define NFS4_enc_fsid_present_sz \
766 (compound_encode_hdr_maxsz + \
767 encode_sequence_maxsz + \
768 encode_putfh_maxsz + \
769 encode_getfh_maxsz + \
770 encode_renew_maxsz)
771#define NFS4_dec_fsid_present_sz \
772 (compound_decode_hdr_maxsz + \
773 decode_sequence_maxsz + \
774 decode_putfh_maxsz + \
775 decode_getfh_maxsz + \
776 decode_renew_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400777#if defined(CONFIG_NFS_V4_1)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -0400778#define NFS4_enc_bind_conn_to_session_sz \
779 (compound_encode_hdr_maxsz + \
780 encode_bind_conn_to_session_maxsz)
781#define NFS4_dec_bind_conn_to_session_sz \
782 (compound_decode_hdr_maxsz + \
783 decode_bind_conn_to_session_maxsz)
Benny Halevy99fe60d2009-04-01 09:22:29 -0400784#define NFS4_enc_exchange_id_sz \
785 (compound_encode_hdr_maxsz + \
786 encode_exchange_id_maxsz)
787#define NFS4_dec_exchange_id_sz \
788 (compound_decode_hdr_maxsz + \
789 decode_exchange_id_maxsz)
Andy Adamsonfc931582009-04-01 09:22:31 -0400790#define NFS4_enc_create_session_sz \
791 (compound_encode_hdr_maxsz + \
792 encode_create_session_maxsz)
793#define NFS4_dec_create_session_sz \
794 (compound_decode_hdr_maxsz + \
795 decode_create_session_maxsz)
Andy Adamson0f3e66c2009-04-01 09:22:34 -0400796#define NFS4_enc_destroy_session_sz (compound_encode_hdr_maxsz + \
797 encode_destroy_session_maxsz)
798#define NFS4_dec_destroy_session_sz (compound_decode_hdr_maxsz + \
799 decode_destroy_session_maxsz)
Trond Myklebust66245532012-05-25 17:18:09 -0400800#define NFS4_enc_destroy_clientid_sz (compound_encode_hdr_maxsz + \
801 encode_destroy_clientid_maxsz)
802#define NFS4_dec_destroy_clientid_sz (compound_decode_hdr_maxsz + \
803 decode_destroy_clientid_maxsz)
Andy Adamsonfc01cea2009-04-01 09:22:36 -0400804#define NFS4_enc_sequence_sz \
805 (compound_decode_hdr_maxsz + \
806 encode_sequence_maxsz)
807#define NFS4_dec_sequence_sz \
808 (compound_decode_hdr_maxsz + \
809 decode_sequence_maxsz)
Andy Adamson2050f0c2009-04-01 09:22:30 -0400810#define NFS4_enc_get_lease_time_sz (compound_encode_hdr_maxsz + \
811 encode_sequence_maxsz + \
812 encode_putrootfh_maxsz + \
813 encode_fsinfo_maxsz)
814#define NFS4_dec_get_lease_time_sz (compound_decode_hdr_maxsz + \
815 decode_sequence_maxsz + \
816 decode_putrootfh_maxsz + \
817 decode_fsinfo_maxsz)
Ricardo Labiaga180197532009-12-05 16:08:40 -0500818#define NFS4_enc_reclaim_complete_sz (compound_encode_hdr_maxsz + \
819 encode_sequence_maxsz + \
820 encode_reclaim_complete_maxsz)
821#define NFS4_dec_reclaim_complete_sz (compound_decode_hdr_maxsz + \
822 decode_sequence_maxsz + \
823 decode_reclaim_complete_maxsz)
Andy Adamsonb1f69b72010-10-20 00:18:03 -0400824#define NFS4_enc_getdeviceinfo_sz (compound_encode_hdr_maxsz + \
825 encode_sequence_maxsz +\
826 encode_getdeviceinfo_maxsz)
827#define NFS4_dec_getdeviceinfo_sz (compound_decode_hdr_maxsz + \
828 decode_sequence_maxsz + \
829 decode_getdeviceinfo_maxsz)
830#define NFS4_enc_layoutget_sz (compound_encode_hdr_maxsz + \
831 encode_sequence_maxsz + \
832 encode_putfh_maxsz + \
833 encode_layoutget_maxsz)
834#define NFS4_dec_layoutget_sz (compound_decode_hdr_maxsz + \
835 decode_sequence_maxsz + \
836 decode_putfh_maxsz + \
837 decode_layoutget_maxsz)
Andy Adamson863a3c62011-03-23 13:27:54 +0000838#define NFS4_enc_layoutcommit_sz (compound_encode_hdr_maxsz + \
839 encode_sequence_maxsz +\
840 encode_putfh_maxsz + \
841 encode_layoutcommit_maxsz + \
842 encode_getattr_maxsz)
843#define NFS4_dec_layoutcommit_sz (compound_decode_hdr_maxsz + \
844 decode_sequence_maxsz + \
845 decode_putfh_maxsz + \
846 decode_layoutcommit_maxsz + \
847 decode_getattr_maxsz)
Benny Halevycbe82602011-05-22 19:52:37 +0300848#define NFS4_enc_layoutreturn_sz (compound_encode_hdr_maxsz + \
849 encode_sequence_maxsz + \
850 encode_putfh_maxsz + \
851 encode_layoutreturn_maxsz)
852#define NFS4_dec_layoutreturn_sz (compound_decode_hdr_maxsz + \
853 decode_sequence_maxsz + \
854 decode_putfh_maxsz + \
855 decode_layoutreturn_maxsz)
Bryan Schumakerfca78d62011-06-02 14:59:07 -0400856#define NFS4_enc_secinfo_no_name_sz (compound_encode_hdr_maxsz + \
857 encode_sequence_maxsz + \
858 encode_putrootfh_maxsz +\
859 encode_secinfo_no_name_maxsz)
860#define NFS4_dec_secinfo_no_name_sz (compound_decode_hdr_maxsz + \
861 decode_sequence_maxsz + \
862 decode_putrootfh_maxsz + \
863 decode_secinfo_no_name_maxsz)
Bryan Schumaker7d974792011-06-02 14:59:08 -0400864#define NFS4_enc_test_stateid_sz (compound_encode_hdr_maxsz + \
865 encode_sequence_maxsz + \
866 encode_test_stateid_maxsz)
867#define NFS4_dec_test_stateid_sz (compound_decode_hdr_maxsz + \
868 decode_sequence_maxsz + \
869 decode_test_stateid_maxsz)
Bryan Schumaker9aeda352011-06-02 14:59:09 -0400870#define NFS4_enc_free_stateid_sz (compound_encode_hdr_maxsz + \
871 encode_sequence_maxsz + \
872 encode_free_stateid_maxsz)
873#define NFS4_dec_free_stateid_sz (compound_decode_hdr_maxsz + \
874 decode_sequence_maxsz + \
875 decode_free_stateid_maxsz)
Alexandros Batsakis2449ea22009-12-05 13:36:55 -0500876
877const u32 nfs41_maxwrite_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
878 compound_encode_hdr_maxsz +
879 encode_sequence_maxsz +
880 encode_putfh_maxsz +
881 encode_getattr_maxsz) *
882 XDR_UNIT);
883
884const u32 nfs41_maxread_overhead = ((RPC_MAX_HEADER_WITH_AUTH +
885 compound_decode_hdr_maxsz +
886 decode_sequence_maxsz +
887 decode_putfh_maxsz) *
888 XDR_UNIT);
Andy Adamsonf1c097b2013-06-25 19:02:53 -0400889
890const u32 nfs41_maxgetdevinfo_overhead = ((RPC_MAX_REPHEADER_WITH_AUTH +
891 compound_decode_hdr_maxsz +
892 decode_sequence_maxsz) *
893 XDR_UNIT);
894EXPORT_SYMBOL_GPL(nfs41_maxgetdevinfo_overhead);
Benny Halevy99fe60d2009-04-01 09:22:29 -0400895#endif /* CONFIG_NFS_V4_1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Trond Myklebustbca79472009-03-11 14:10:26 -0400897static const umode_t nfs_type2fmt[] = {
898 [NF4BAD] = 0,
899 [NF4REG] = S_IFREG,
900 [NF4DIR] = S_IFDIR,
901 [NF4BLK] = S_IFBLK,
902 [NF4CHR] = S_IFCHR,
903 [NF4LNK] = S_IFLNK,
904 [NF4SOCK] = S_IFSOCK,
905 [NF4FIFO] = S_IFIFO,
906 [NF4ATTRDIR] = 0,
907 [NF4NAMEDATTR] = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908};
909
910struct compound_hdr {
911 int32_t status;
912 uint32_t nops;
Andy Adamsond0179312008-12-23 16:06:17 -0500913 __be32 * nops_p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 uint32_t taglen;
915 char * tag;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400916 uint32_t replen; /* expected reply words */
Benny Halevy66cc0422009-04-01 09:22:10 -0400917 u32 minorversion;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918};
919
Benny Halevy13c65ce2009-08-14 17:19:25 +0300920static __be32 *reserve_space(struct xdr_stream *xdr, size_t nbytes)
921{
922 __be32 *p = xdr_reserve_space(xdr, nbytes);
923 BUG_ON(!p);
924 return p;
925}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
Trond Myklebustcb17e552012-03-04 18:13:56 -0500927static void encode_opaque_fixed(struct xdr_stream *xdr, const void *buf, size_t len)
928{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500929 WARN_ON_ONCE(xdr_stream_encode_opaque_fixed(xdr, buf, len) < 0);
Trond Myklebustcb17e552012-03-04 18:13:56 -0500930}
931
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932static void encode_string(struct xdr_stream *xdr, unsigned int len, const char *str)
933{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500934 WARN_ON_ONCE(xdr_stream_encode_opaque(xdr, str, len) < 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}
936
Trond Myklebust4ade9822012-03-04 18:13:57 -0500937static void encode_uint32(struct xdr_stream *xdr, u32 n)
938{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500939 WARN_ON_ONCE(xdr_stream_encode_u32(xdr, n) < 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500940}
941
Trond Myklebustff2eb682012-03-05 11:40:12 -0500942static void encode_uint64(struct xdr_stream *xdr, u64 n)
943{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -0500944 WARN_ON_ONCE(xdr_stream_encode_u64(xdr, n) < 0);
Trond Myklebustff2eb682012-03-05 11:40:12 -0500945}
946
Trond Myklebust4ade9822012-03-04 18:13:57 -0500947static void encode_nfs4_seqid(struct xdr_stream *xdr,
948 const struct nfs_seqid *seqid)
949{
Trond Myklebusta6796412015-01-23 19:04:44 -0500950 if (seqid != NULL)
951 encode_uint32(xdr, seqid->sequence->counter);
952 else
953 encode_uint32(xdr, 0);
Trond Myklebust4ade9822012-03-04 18:13:57 -0500954}
955
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400956static void encode_compound_hdr(struct xdr_stream *xdr,
957 struct rpc_rqst *req,
958 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959{
Al Viro8687b632006-10-19 23:28:48 -0700960 __be32 *p;
Trond Myklebusta17c2152010-07-31 14:29:08 -0400961 struct rpc_auth *auth = req->rq_cred->cr_auth;
Benny Halevy0c4e8c12009-04-01 09:22:07 -0400962
963 /* initialize running count of expected bytes in reply.
964 * NOTE: the replied tag SHOULD be the same is the one sent,
965 * but this is not required as a MUST for the server to do so. */
966 hdr->replen = RPC_REPHDRSIZE + auth->au_rslack + 3 + hdr->taglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Trond Myklebust7fc38842012-10-15 11:51:21 -0400968 WARN_ON_ONCE(hdr->taglen > NFS4_MAXTAGLEN);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -0500969 encode_string(xdr, hdr->taglen, hdr->tag);
970 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +0300971 *p++ = cpu_to_be32(hdr->minorversion);
Andy Adamsond0179312008-12-23 16:06:17 -0500972 hdr->nops_p = p;
Benny Halevy34558512009-08-14 17:19:30 +0300973 *p = cpu_to_be32(hdr->nops);
Andy Adamsond0179312008-12-23 16:06:17 -0500974}
975
Trond Myklebustab19b482012-03-04 18:13:57 -0500976static void encode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 op,
977 uint32_t replen,
978 struct compound_hdr *hdr)
979{
980 encode_uint32(xdr, op);
981 hdr->nops++;
982 hdr->replen += replen;
983}
984
Andy Adamsond0179312008-12-23 16:06:17 -0500985static void encode_nops(struct compound_hdr *hdr)
986{
Trond Myklebust7fc38842012-10-15 11:51:21 -0400987 WARN_ON_ONCE(hdr->nops > NFS4_MAX_OPS);
Andy Adamsond0179312008-12-23 16:06:17 -0500988 *hdr->nops_p = htonl(hdr->nops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500991static void encode_nfs4_stateid(struct xdr_stream *xdr, const nfs4_stateid *stateid)
992{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -0500993 encode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -0500994}
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996static void encode_nfs4_verifier(struct xdr_stream *xdr, const nfs4_verifier *verf)
997{
Trond Myklebustcb17e552012-03-04 18:13:56 -0500998 encode_opaque_fixed(xdr, verf->data, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999}
1000
David Quigleyaa9c2662013-05-22 12:50:44 -04001001static void encode_attrs(struct xdr_stream *xdr, const struct iattr *iap,
1002 const struct nfs4_label *label,
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001003 const struct nfs_server *server,
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001004 bool excl_check, const umode_t *umask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005{
1006 char owner_name[IDMAP_NAMESZ];
1007 char owner_group[IDMAP_NAMESZ];
1008 int owner_namelen = 0;
1009 int owner_grouplen = 0;
Al Viro8687b632006-10-19 23:28:48 -07001010 __be32 *p;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001011 unsigned i;
1012 uint32_t len = 0;
1013 uint32_t bmval_len;
1014 uint32_t bmval[3] = { 0 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 /*
1017 * We reserve enough space to write the entire attribute buffer at once.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 */
Trond Myklebustd7067b22013-07-17 17:09:01 -04001019 if (iap->ia_valid & ATTR_SIZE) {
1020 bmval[0] |= FATTR4_WORD0_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 len += 8;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001022 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001023 if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK))
1024 umask = NULL;
Trond Myklebustd7067b22013-07-17 17:09:01 -04001025 if (iap->ia_valid & ATTR_MODE) {
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001026 if (umask) {
1027 bmval[2] |= FATTR4_WORD2_MODE_UMASK;
1028 len += 8;
1029 } else {
1030 bmval[1] |= FATTR4_WORD1_MODE;
1031 len += 4;
1032 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (iap->ia_valid & ATTR_UID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001035 owner_namelen = nfs_map_uid_to_name(server, iap->ia_uid, owner_name, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 if (owner_namelen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001037 dprintk("nfs: couldn't resolve uid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001038 from_kuid(&init_user_ns, iap->ia_uid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 /* XXX */
1040 strcpy(owner_name, "nobody");
1041 owner_namelen = sizeof("nobody") - 1;
1042 /* goto out; */
1043 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001044 bmval[1] |= FATTR4_WORD1_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 len += 4 + (XDR_QUADLEN(owner_namelen) << 2);
1046 }
1047 if (iap->ia_valid & ATTR_GID) {
Trond Myklebuste4fd72a2011-02-22 15:44:31 -08001048 owner_grouplen = nfs_map_gid_to_group(server, iap->ia_gid, owner_group, IDMAP_NAMESZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if (owner_grouplen < 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04001050 dprintk("nfs: couldn't resolve gid %d to string\n",
Eric W. Biedermane5782072013-02-01 14:22:02 -08001051 from_kgid(&init_user_ns, iap->ia_gid));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 strcpy(owner_group, "nobody");
1053 owner_grouplen = sizeof("nobody") - 1;
1054 /* goto out; */
1055 }
Trond Myklebustd7067b22013-07-17 17:09:01 -04001056 bmval[1] |= FATTR4_WORD1_OWNER_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 len += 4 + (XDR_QUADLEN(owner_grouplen) << 2);
1058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 if (iap->ia_valid & ATTR_ATIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001060 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1061 len += 16;
1062 } else if (iap->ia_valid & ATTR_ATIME) {
1063 bmval[1] |= FATTR4_WORD1_TIME_ACCESS_SET;
1064 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 }
1066 if (iap->ia_valid & ATTR_MTIME_SET) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001067 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1068 len += 16;
1069 } else if (iap->ia_valid & ATTR_MTIME) {
1070 bmval[1] |= FATTR4_WORD1_TIME_MODIFY_SET;
1071 len += 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 }
Kinglong Mee5334c5b2015-08-26 21:13:37 +08001073
1074 if (excl_check) {
1075 const u32 *excl_bmval = server->exclcreat_bitmask;
1076 bmval[0] &= excl_bmval[0];
1077 bmval[1] &= excl_bmval[1];
1078 bmval[2] &= excl_bmval[2];
1079
1080 if (!(excl_bmval[2] & FATTR4_WORD2_SECURITY_LABEL))
1081 label = NULL;
1082 }
1083
David Quigleyaa9c2662013-05-22 12:50:44 -04001084 if (label) {
Trond Myklebustd7067b22013-07-17 17:09:01 -04001085 len += 4 + 4 + 4 + (XDR_QUADLEN(label->len) << 2);
1086 bmval[2] |= FATTR4_WORD2_SECURITY_LABEL;
1087 }
1088
1089 if (bmval[2] != 0)
1090 bmval_len = 3;
1091 else if (bmval[1] != 0)
1092 bmval_len = 2;
1093 else
1094 bmval_len = 1;
1095
1096 p = reserve_space(xdr, 4 + (bmval_len << 2) + 4 + len);
1097
1098 *p++ = cpu_to_be32(bmval_len);
1099 for (i = 0; i < bmval_len; i++)
1100 *p++ = cpu_to_be32(bmval[i]);
1101 *p++ = cpu_to_be32(len);
1102
1103 if (bmval[0] & FATTR4_WORD0_SIZE)
1104 p = xdr_encode_hyper(p, iap->ia_size);
1105 if (bmval[1] & FATTR4_WORD1_MODE)
1106 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1107 if (bmval[1] & FATTR4_WORD1_OWNER)
1108 p = xdr_encode_opaque(p, owner_name, owner_namelen);
1109 if (bmval[1] & FATTR4_WORD1_OWNER_GROUP)
1110 p = xdr_encode_opaque(p, owner_group, owner_grouplen);
1111 if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
1112 if (iap->ia_valid & ATTR_ATIME_SET) {
1113 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1114 p = xdr_encode_hyper(p, (s64)iap->ia_atime.tv_sec);
1115 *p++ = cpu_to_be32(iap->ia_atime.tv_nsec);
1116 } else
1117 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1118 }
1119 if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
1120 if (iap->ia_valid & ATTR_MTIME_SET) {
1121 *p++ = cpu_to_be32(NFS4_SET_TO_CLIENT_TIME);
1122 p = xdr_encode_hyper(p, (s64)iap->ia_mtime.tv_sec);
1123 *p++ = cpu_to_be32(iap->ia_mtime.tv_nsec);
1124 } else
1125 *p++ = cpu_to_be32(NFS4_SET_TO_SERVER_TIME);
1126 }
1127 if (bmval[2] & FATTR4_WORD2_SECURITY_LABEL) {
David Quigleyaa9c2662013-05-22 12:50:44 -04001128 *p++ = cpu_to_be32(label->lfs);
1129 *p++ = cpu_to_be32(label->pi);
1130 *p++ = cpu_to_be32(label->len);
1131 p = xdr_encode_opaque_fixed(p, label->label, label->len);
1132 }
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001133 if (bmval[2] & FATTR4_WORD2_MODE_UMASK) {
1134 *p++ = cpu_to_be32(iap->ia_mode & S_IALLUGO);
1135 *p++ = cpu_to_be32(*umask);
1136 }
Andy Adamson6c0195a2008-12-23 16:06:15 -05001137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138/* out: */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001141static void encode_access(struct xdr_stream *xdr, u32 access, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001143 encode_op_hdr(xdr, OP_ACCESS, decode_access_maxsz, hdr);
1144 encode_uint32(xdr, access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145}
1146
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001147static void encode_close(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148{
Trond Myklebustab19b482012-03-04 18:13:57 -05001149 encode_op_hdr(xdr, OP_CLOSE, decode_close_maxsz, hdr);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001150 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001151 encode_nfs4_stateid(xdr, &arg->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152}
1153
Fred Isaman0b7c0152012-04-20 14:47:39 -04001154static void encode_commit(struct xdr_stream *xdr, const struct nfs_commitargs *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
Al Viro8687b632006-10-19 23:28:48 -07001156 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001157
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001158 encode_op_hdr(xdr, OP_COMMIT, decode_commit_maxsz, hdr);
1159 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001160 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001161 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162}
1163
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001164static void encode_create(struct xdr_stream *xdr, const struct nfs4_create_arg *create, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
Al Viro8687b632006-10-19 23:28:48 -07001166 __be32 *p;
Andy Adamson6c0195a2008-12-23 16:06:15 -05001167
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001168 encode_op_hdr(xdr, OP_CREATE, decode_create_maxsz, hdr);
1169 encode_uint32(xdr, create->ftype);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 switch (create->ftype) {
1172 case NF4LNK:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001173 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001174 *p = cpu_to_be32(create->u.symlink.len);
Chuck Lever2fcc2132015-08-03 13:04:26 -04001175 xdr_write_pages(xdr, create->u.symlink.pages, 0,
1176 create->u.symlink.len);
1177 xdr->buf->flags |= XDRBUF_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 break;
1179
1180 case NF4BLK: case NF4CHR:
Benny Halevy13c65ce2009-08-14 17:19:25 +03001181 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001182 *p++ = cpu_to_be32(create->u.device.specdata1);
Benny Halevy34558512009-08-14 17:19:30 +03001183 *p = cpu_to_be32(create->u.device.specdata2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 break;
1185
1186 default:
1187 break;
1188 }
1189
Benny Halevy811652b2009-08-14 17:19:34 +03001190 encode_string(xdr, create->name->len, create->name->name);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001191 encode_attrs(xdr, create->attrs, create->label, create->server, false,
1192 &create->umask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193}
1194
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001195static void encode_getattr_one(struct xdr_stream *xdr, uint32_t bitmap, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196{
Andy Adamson05d564f2008-12-23 16:06:15 -05001197 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001199 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1200 p = reserve_space(xdr, 8);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001201 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001202 *p = cpu_to_be32(bitmap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203}
1204
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001205static void encode_getattr_two(struct xdr_stream *xdr, uint32_t bm0, uint32_t bm1, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
Andy Adamson05d564f2008-12-23 16:06:15 -05001207 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001209 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
1210 p = reserve_space(xdr, 12);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001211 *p++ = cpu_to_be32(2);
1212 *p++ = cpu_to_be32(bm0);
Benny Halevy34558512009-08-14 17:19:30 +03001213 *p = cpu_to_be32(bm1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214}
1215
Fred Isamandae100c2011-07-30 20:52:37 -04001216static void
1217encode_getattr_three(struct xdr_stream *xdr,
1218 uint32_t bm0, uint32_t bm1, uint32_t bm2,
1219 struct compound_hdr *hdr)
1220{
1221 __be32 *p;
1222
Trond Myklebustab19b482012-03-04 18:13:57 -05001223 encode_op_hdr(xdr, OP_GETATTR, decode_getattr_maxsz, hdr);
Fred Isamandae100c2011-07-30 20:52:37 -04001224 if (bm2) {
1225 p = reserve_space(xdr, 16);
1226 *p++ = cpu_to_be32(3);
1227 *p++ = cpu_to_be32(bm0);
1228 *p++ = cpu_to_be32(bm1);
1229 *p = cpu_to_be32(bm2);
1230 } else if (bm1) {
1231 p = reserve_space(xdr, 12);
1232 *p++ = cpu_to_be32(2);
1233 *p++ = cpu_to_be32(bm0);
1234 *p = cpu_to_be32(bm1);
1235 } else {
1236 p = reserve_space(xdr, 8);
1237 *p++ = cpu_to_be32(1);
1238 *p = cpu_to_be32(bm0);
1239 }
Fred Isamandae100c2011-07-30 20:52:37 -04001240}
1241
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001242static void encode_getfattr(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
David Quigleya09df2c2013-05-22 12:50:41 -04001244 encode_getattr_three(xdr, bitmask[0] & nfs4_fattr_bitmap[0],
1245 bitmask[1] & nfs4_fattr_bitmap[1],
1246 bitmask[2] & nfs4_fattr_bitmap[2],
1247 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248}
1249
Andy Adamson88034c32012-05-23 05:02:34 -04001250static void encode_getfattr_open(struct xdr_stream *xdr, const u32 *bitmask,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001251 const u32 *open_bitmap,
Andy Adamson88034c32012-05-23 05:02:34 -04001252 struct compound_hdr *hdr)
1253{
1254 encode_getattr_three(xdr,
Trond Myklebust1549210f2012-06-05 09:16:47 -04001255 bitmask[0] & open_bitmap[0],
1256 bitmask[1] & open_bitmap[1],
1257 bitmask[2] & open_bitmap[2],
Andy Adamson88034c32012-05-23 05:02:34 -04001258 hdr);
1259}
1260
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001261static void encode_fsinfo(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262{
Fred Isamandae100c2011-07-30 20:52:37 -04001263 encode_getattr_three(xdr,
1264 bitmask[0] & nfs4_fsinfo_bitmap[0],
1265 bitmask[1] & nfs4_fsinfo_bitmap[1],
1266 bitmask[2] & nfs4_fsinfo_bitmap[2],
1267 hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268}
1269
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001270static void encode_fs_locations(struct xdr_stream *xdr, const u32* bitmask, struct compound_hdr *hdr)
Manoj Naik830b8e32006-06-09 09:34:25 -04001271{
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001272 encode_getattr_two(xdr, bitmask[0] & nfs4_fs_locations_bitmap[0],
1273 bitmask[1] & nfs4_fs_locations_bitmap[1], hdr);
Manoj Naik830b8e32006-06-09 09:34:25 -04001274}
1275
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001276static void encode_getfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
Trond Myklebustab19b482012-03-04 18:13:57 -05001278 encode_op_hdr(xdr, OP_GETFH, decode_getfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279}
1280
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001281static void encode_link(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282{
Trond Myklebustab19b482012-03-04 18:13:57 -05001283 encode_op_hdr(xdr, OP_LINK, decode_link_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001284 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285}
1286
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001287static inline int nfs4_lock_type(struct file_lock *fl, int block)
1288{
Jeff Laytonf44106e2012-07-23 15:49:56 -04001289 if (fl->fl_type == F_RDLCK)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001290 return block ? NFS4_READW_LT : NFS4_READ_LT;
1291 return block ? NFS4_WRITEW_LT : NFS4_WRITE_LT;
1292}
1293
1294static inline uint64_t nfs4_lock_length(struct file_lock *fl)
1295{
1296 if (fl->fl_end == OFFSET_MAX)
1297 return ~(uint64_t)0;
1298 return fl->fl_end - fl->fl_start + 1;
1299}
1300
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001301static void encode_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner)
1302{
1303 __be32 *p;
1304
Trond Myklebustd035c362010-12-21 10:45:27 -05001305 p = reserve_space(xdr, 32);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001306 p = xdr_encode_hyper(p, lowner->clientid);
Trond Myklebustd035c362010-12-21 10:45:27 -05001307 *p++ = cpu_to_be32(20);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001308 p = xdr_encode_opaque_fixed(p, "lock id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001309 *p++ = cpu_to_be32(lowner->s_dev);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001310 xdr_encode_hyper(p, lowner->id);
1311}
1312
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313/*
1314 * opcode,type,reclaim,offset,length,new_lock_owner = 32
1315 * open_seqid,open_stateid,lock_seqid,lock_owner.clientid, lock_owner.id = 40
1316 */
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001317static void encode_lock(struct xdr_stream *xdr, const struct nfs_lock_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318{
Al Viro8687b632006-10-19 23:28:48 -07001319 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001321 encode_op_hdr(xdr, OP_LOCK, decode_lock_maxsz, hdr);
1322 p = reserve_space(xdr, 28);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001323 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, args->block));
1324 *p++ = cpu_to_be32(args->reclaim);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001325 p = xdr_encode_hyper(p, args->fl->fl_start);
1326 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Benny Halevy34558512009-08-14 17:19:30 +03001327 *p = cpu_to_be32(args->new_lock_owner);
Trond Myklebust911d1aa2006-01-03 09:55:16 +01001328 if (args->new_lock_owner){
Trond Myklebust4ade9822012-03-04 18:13:57 -05001329 encode_nfs4_seqid(xdr, args->open_seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001330 encode_nfs4_stateid(xdr, &args->open_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001331 encode_nfs4_seqid(xdr, args->lock_seqid);
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001332 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 }
1334 else {
Trond Myklebust425c1d42015-01-24 14:57:53 -05001335 encode_nfs4_stateid(xdr, &args->lock_stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001336 encode_nfs4_seqid(xdr, args->lock_seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338}
1339
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001340static void encode_lockt(struct xdr_stream *xdr, const struct nfs_lockt_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341{
Al Viro8687b632006-10-19 23:28:48 -07001342 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001344 encode_op_hdr(xdr, OP_LOCKT, decode_lockt_maxsz, hdr);
1345 p = reserve_space(xdr, 20);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001346 *p++ = cpu_to_be32(nfs4_lock_type(args->fl, 0));
Benny Halevyb95be5a2009-08-14 17:19:01 +03001347 p = xdr_encode_hyper(p, args->fl->fl_start);
1348 p = xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Trond Myklebustdaccbde2010-06-25 18:11:43 -04001349 encode_lockowner(xdr, &args->lock_owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
1351
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001352static void encode_locku(struct xdr_stream *xdr, const struct nfs_locku_args *args, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
Al Viro8687b632006-10-19 23:28:48 -07001354 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001356 encode_op_hdr(xdr, OP_LOCKU, decode_locku_maxsz, hdr);
1357 encode_uint32(xdr, nfs4_lock_type(args->fl, 0));
Trond Myklebust4ade9822012-03-04 18:13:57 -05001358 encode_nfs4_seqid(xdr, args->seqid);
Trond Myklebust425c1d42015-01-24 14:57:53 -05001359 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001360 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001361 p = xdr_encode_hyper(p, args->fl->fl_start);
Benny Halevy34558512009-08-14 17:19:30 +03001362 xdr_encode_hyper(p, nfs4_lock_length(args->fl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363}
1364
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001365static void encode_release_lockowner(struct xdr_stream *xdr, const struct nfs_lowner *lowner, struct compound_hdr *hdr)
1366{
Trond Myklebustab19b482012-03-04 18:13:57 -05001367 encode_op_hdr(xdr, OP_RELEASE_LOCKOWNER, decode_release_lockowner_maxsz, hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001368 encode_lockowner(xdr, lowner);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04001369}
1370
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001371static void encode_lookup(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372{
Trond Myklebustab19b482012-03-04 18:13:57 -05001373 encode_op_hdr(xdr, OP_LOOKUP, decode_lookup_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001374 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375}
1376
Trond Myklebust6ae37332015-01-30 14:21:14 -05001377static void encode_share_access(struct xdr_stream *xdr, u32 share_access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378{
Al Viro8687b632006-10-19 23:28:48 -07001379 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Benny Halevy13c65ce2009-08-14 17:19:25 +03001381 p = reserve_space(xdr, 8);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001382 *p++ = cpu_to_be32(share_access);
Benny Halevy34558512009-08-14 17:19:30 +03001383 *p = cpu_to_be32(0); /* for linux, share_deny = 0 always */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384}
1385
1386static inline void encode_openhdr(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1387{
Al Viro8687b632006-10-19 23:28:48 -07001388 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 /*
1390 * opcode 4, seqid 4, share_access 4, share_deny 4, clientid 8, ownerlen 4,
1391 * owner 4 = 32
1392 */
Trond Myklebust4ade9822012-03-04 18:13:57 -05001393 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001394 encode_share_access(xdr, arg->share_access);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001395 p = reserve_space(xdr, 36);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001396 p = xdr_encode_hyper(p, arg->clientid);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001397 *p++ = cpu_to_be32(24);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001398 p = xdr_encode_opaque_fixed(p, "open id:", 8);
Trond Myklebustd035c362010-12-21 10:45:27 -05001399 *p++ = cpu_to_be32(arg->server->s_dev);
Trond Myklebust95b72eb2012-04-20 19:24:51 -04001400 *p++ = cpu_to_be32(arg->id.uniquifier);
1401 xdr_encode_hyper(p, arg->id.create_time);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402}
1403
1404static inline void encode_createmode(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1405{
Al Viro8687b632006-10-19 23:28:48 -07001406 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Benny Halevy13c65ce2009-08-14 17:19:25 +03001408 p = reserve_space(xdr, 4);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001409 switch(arg->createmode) {
1410 case NFS4_CREATE_UNCHECKED:
Benny Halevy34558512009-08-14 17:19:30 +03001411 *p = cpu_to_be32(NFS4_CREATE_UNCHECKED);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001412 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1413 &arg->umask);
Andy Adamson05d564f2008-12-23 16:06:15 -05001414 break;
Trond Myklebust549b19c2013-04-16 18:42:34 -04001415 case NFS4_CREATE_GUARDED:
1416 *p = cpu_to_be32(NFS4_CREATE_GUARDED);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001417 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, false,
1418 &arg->umask);
Trond Myklebust549b19c2013-04-16 18:42:34 -04001419 break;
1420 case NFS4_CREATE_EXCLUSIVE:
1421 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE);
1422 encode_nfs4_verifier(xdr, &arg->u.verifier);
1423 break;
1424 case NFS4_CREATE_EXCLUSIVE4_1:
1425 *p = cpu_to_be32(NFS4_CREATE_EXCLUSIVE4_1);
1426 encode_nfs4_verifier(xdr, &arg->u.verifier);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001427 encode_attrs(xdr, arg->u.attrs, arg->label, arg->server, true,
1428 &arg->umask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
1430}
1431
1432static void encode_opentype(struct xdr_stream *xdr, const struct nfs_openargs *arg)
1433{
Al Viro8687b632006-10-19 23:28:48 -07001434 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Benny Halevy13c65ce2009-08-14 17:19:25 +03001436 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 switch (arg->open_flags & O_CREAT) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001438 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001439 *p = cpu_to_be32(NFS4_OPEN_NOCREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001440 break;
1441 default:
Benny Halevy34558512009-08-14 17:19:30 +03001442 *p = cpu_to_be32(NFS4_OPEN_CREATE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001443 encode_createmode(xdr, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 }
1445}
1446
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001447static inline void encode_delegation_type(struct xdr_stream *xdr, fmode_t delegation_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448{
Al Viro8687b632006-10-19 23:28:48 -07001449 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
Benny Halevy13c65ce2009-08-14 17:19:25 +03001451 p = reserve_space(xdr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001453 case 0:
Benny Halevy34558512009-08-14 17:19:30 +03001454 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_NONE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001455 break;
1456 case FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001457 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_READ);
Andy Adamson05d564f2008-12-23 16:06:15 -05001458 break;
1459 case FMODE_WRITE|FMODE_READ:
Benny Halevy34558512009-08-14 17:19:30 +03001460 *p = cpu_to_be32(NFS4_OPEN_DELEGATE_WRITE);
Andy Adamson05d564f2008-12-23 16:06:15 -05001461 break;
1462 default:
1463 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 }
1465}
1466
1467static inline void encode_claim_null(struct xdr_stream *xdr, const struct qstr *name)
1468{
Al Viro8687b632006-10-19 23:28:48 -07001469 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
Benny Halevy13c65ce2009-08-14 17:19:25 +03001471 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001472 *p = cpu_to_be32(NFS4_OPEN_CLAIM_NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 encode_string(xdr, name->len, name->name);
1474}
1475
Trond Myklebustbd7bf9d2008-12-23 15:21:53 -05001476static inline void encode_claim_previous(struct xdr_stream *xdr, fmode_t type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
Al Viro8687b632006-10-19 23:28:48 -07001478 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Benny Halevy13c65ce2009-08-14 17:19:25 +03001480 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001481 *p = cpu_to_be32(NFS4_OPEN_CLAIM_PREVIOUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 encode_delegation_type(xdr, type);
1483}
1484
1485static inline void encode_claim_delegate_cur(struct xdr_stream *xdr, const struct qstr *name, const nfs4_stateid *stateid)
1486{
Al Viro8687b632006-10-19 23:28:48 -07001487 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001489 p = reserve_space(xdr, 4);
1490 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEGATE_CUR);
1491 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 encode_string(xdr, name->len, name->name);
1493}
1494
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001495static inline void encode_claim_fh(struct xdr_stream *xdr)
1496{
1497 __be32 *p;
1498
1499 p = reserve_space(xdr, 4);
1500 *p = cpu_to_be32(NFS4_OPEN_CLAIM_FH);
1501}
1502
1503static inline void encode_claim_delegate_cur_fh(struct xdr_stream *xdr, const nfs4_stateid *stateid)
1504{
1505 __be32 *p;
1506
1507 p = reserve_space(xdr, 4);
1508 *p = cpu_to_be32(NFS4_OPEN_CLAIM_DELEG_CUR_FH);
1509 encode_nfs4_stateid(xdr, stateid);
1510}
1511
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001512static void encode_open(struct xdr_stream *xdr, const struct nfs_openargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Trond Myklebustab19b482012-03-04 18:13:57 -05001514 encode_op_hdr(xdr, OP_OPEN, decode_open_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 encode_openhdr(xdr, arg);
1516 encode_opentype(xdr, arg);
1517 switch (arg->claim) {
Andy Adamson05d564f2008-12-23 16:06:15 -05001518 case NFS4_OPEN_CLAIM_NULL:
1519 encode_claim_null(xdr, arg->name);
1520 break;
1521 case NFS4_OPEN_CLAIM_PREVIOUS:
1522 encode_claim_previous(xdr, arg->u.delegation_type);
1523 break;
1524 case NFS4_OPEN_CLAIM_DELEGATE_CUR:
1525 encode_claim_delegate_cur(xdr, arg->name, &arg->u.delegation);
1526 break;
Trond Myklebustd9fc6612013-03-15 15:39:06 -04001527 case NFS4_OPEN_CLAIM_FH:
1528 encode_claim_fh(xdr);
1529 break;
1530 case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
1531 encode_claim_delegate_cur_fh(xdr, &arg->u.delegation);
1532 break;
Andy Adamson05d564f2008-12-23 16:06:15 -05001533 default:
1534 BUG();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536}
1537
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001538static 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 -07001539{
Trond Myklebustab19b482012-03-04 18:13:57 -05001540 encode_op_hdr(xdr, OP_OPEN_CONFIRM, decode_open_confirm_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001541 encode_nfs4_stateid(xdr, arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001542 encode_nfs4_seqid(xdr, arg->seqid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543}
1544
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001545static void encode_open_downgrade(struct xdr_stream *xdr, const struct nfs_closeargs *arg, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546{
Trond Myklebustab19b482012-03-04 18:13:57 -05001547 encode_op_hdr(xdr, OP_OPEN_DOWNGRADE, decode_open_downgrade_maxsz, hdr);
Trond Myklebust566fcec2015-01-23 15:32:46 -05001548 encode_nfs4_stateid(xdr, &arg->stateid);
Trond Myklebust4ade9822012-03-04 18:13:57 -05001549 encode_nfs4_seqid(xdr, arg->seqid);
Trond Myklebust6ae37332015-01-30 14:21:14 -05001550 encode_share_access(xdr, arg->share_access);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551}
1552
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001553static void
Andy Adamsond0179312008-12-23 16:06:17 -05001554encode_putfh(struct xdr_stream *xdr, const struct nfs_fh *fh, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555{
Trond Myklebustab19b482012-03-04 18:13:57 -05001556 encode_op_hdr(xdr, OP_PUTFH, decode_putfh_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001557 encode_string(xdr, fh->size, fh->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558}
1559
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001560static void encode_putrootfh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
Trond Myklebustab19b482012-03-04 18:13:57 -05001562 encode_op_hdr(xdr, OP_PUTROOTFH, decode_putrootfh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563}
1564
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001565static void encode_read(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1566 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
Al Viro8687b632006-10-19 23:28:48 -07001568 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
Trond Myklebustab19b482012-03-04 18:13:57 -05001570 encode_op_hdr(xdr, OP_READ, decode_read_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001571 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
Benny Halevy13c65ce2009-08-14 17:19:25 +03001573 p = reserve_space(xdr, 12);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001574 p = xdr_encode_hyper(p, args->offset);
Benny Halevy34558512009-08-14 17:19:30 +03001575 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576}
1577
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001578static 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 -07001579{
David Quigleyaa9c2662013-05-22 12:50:44 -04001580 uint32_t attrs[3] = {
Trond Myklebust28331a42011-04-27 13:47:52 -04001581 FATTR4_WORD0_RDATTR_ERROR,
1582 FATTR4_WORD1_MOUNTED_ON_FILEID,
1583 };
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001584 uint32_t dircount = readdir->count >> 1;
Chuck Levercd937102012-03-02 17:14:31 -05001585 __be32 *p, verf[2];
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001586 uint32_t attrlen = 0;
1587 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001589 if (readdir->plus) {
1590 attrs[0] |= FATTR4_WORD0_TYPE|FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE|
Trond Myklebust28331a42011-04-27 13:47:52 -04001591 FATTR4_WORD0_FSID|FATTR4_WORD0_FILEHANDLE|FATTR4_WORD0_FILEID;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001592 attrs[1] |= FATTR4_WORD1_MODE|FATTR4_WORD1_NUMLINKS|FATTR4_WORD1_OWNER|
1593 FATTR4_WORD1_OWNER_GROUP|FATTR4_WORD1_RAWDEV|
1594 FATTR4_WORD1_SPACE_USED|FATTR4_WORD1_TIME_ACCESS|
1595 FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001596 attrs[2] |= FATTR4_WORD2_SECURITY_LABEL;
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001597 dircount >>= 1;
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001598 }
Trond Myklebust28331a42011-04-27 13:47:52 -04001599 /* Use mounted_on_fileid only if the server supports it */
1600 if (!(readdir->bitmask[1] & FATTR4_WORD1_MOUNTED_ON_FILEID))
1601 attrs[0] |= FATTR4_WORD0_FILEID;
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001602 for (i = 0; i < ARRAY_SIZE(attrs); i++) {
1603 attrs[i] &= readdir->bitmask[i];
1604 if (attrs[i] != 0)
1605 attrlen = i+1;
1606 }
Bryan Schumaker82f2e542010-10-21 16:33:18 -04001607
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001608 encode_op_hdr(xdr, OP_READDIR, decode_readdir_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001609 encode_uint64(xdr, readdir->cookie);
Chuck Levercd937102012-03-02 17:14:31 -05001610 encode_nfs4_verifier(xdr, &readdir->verifier);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001611 p = reserve_space(xdr, 12 + (attrlen << 2));
Trond Myklebust6f7a35b2010-10-24 12:11:42 -04001612 *p++ = cpu_to_be32(dircount);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001613 *p++ = cpu_to_be32(readdir->count);
Trond Myklebustd204c5d2013-11-04 13:23:59 -05001614 *p++ = cpu_to_be32(attrlen);
1615 for (i = 0; i < attrlen; i++)
1616 *p++ = cpu_to_be32(attrs[i]);
Chuck Levercd937102012-03-02 17:14:31 -05001617 memcpy(verf, readdir->verifier.data, sizeof(verf));
David Quigleyaa9c2662013-05-22 12:50:44 -04001618
1619 dprintk("%s: cookie = %llu, verifier = %08x:%08x, bitmap = %08x:%08x:%08x\n",
Fred Isaman44109242008-04-02 15:21:15 +03001620 __func__,
Trond Myklebusteadf4592005-06-22 17:16:39 +00001621 (unsigned long long)readdir->cookie,
Chuck Levercd937102012-03-02 17:14:31 -05001622 verf[0], verf[1],
Trond Myklebusteadf4592005-06-22 17:16:39 +00001623 attrs[0] & readdir->bitmask[0],
David Quigleyaa9c2662013-05-22 12:50:44 -04001624 attrs[1] & readdir->bitmask[1],
1625 attrs[2] & readdir->bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626}
1627
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001628static 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 -07001629{
Trond Myklebustab19b482012-03-04 18:13:57 -05001630 encode_op_hdr(xdr, OP_READLINK, decode_readlink_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631}
1632
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001633static void encode_remove(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
Trond Myklebustab19b482012-03-04 18:13:57 -05001635 encode_op_hdr(xdr, OP_REMOVE, decode_remove_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001636 encode_string(xdr, name->len, name->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637}
1638
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001639static 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 -07001640{
Trond Myklebustab19b482012-03-04 18:13:57 -05001641 encode_op_hdr(xdr, OP_RENAME, decode_rename_maxsz, hdr);
Benny Halevy811652b2009-08-14 17:19:34 +03001642 encode_string(xdr, oldname->len, oldname->name);
1643 encode_string(xdr, newname->len, newname->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644}
1645
Chuck Leverbb4dae52012-03-01 17:01:48 -05001646static void encode_renew(struct xdr_stream *xdr, clientid4 clid,
1647 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001649 encode_op_hdr(xdr, OP_RENEW, decode_renew_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001650 encode_uint64(xdr, clid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651}
1652
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001653static void
Andy Adamsond0179312008-12-23 16:06:17 -05001654encode_restorefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001655{
Trond Myklebustab19b482012-03-04 18:13:57 -05001656 encode_op_hdr(xdr, OP_RESTOREFH, decode_restorefh_maxsz, hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04001657}
1658
Chuck Lever9f06c712010-12-14 14:59:18 +00001659static void
Andy Adamsond0179312008-12-23 16:06:17 -05001660encode_setacl(struct xdr_stream *xdr, struct nfs_setaclargs *arg, struct compound_hdr *hdr)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001661{
Al Viro8687b632006-10-19 23:28:48 -07001662 __be32 *p;
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001663
Trond Myklebustab19b482012-03-04 18:13:57 -05001664 encode_op_hdr(xdr, OP_SETATTR, decode_setacl_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001665 encode_nfs4_stateid(xdr, &zero_stateid);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001666 p = reserve_space(xdr, 2*4);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001667 *p++ = cpu_to_be32(1);
Benny Halevy34558512009-08-14 17:19:30 +03001668 *p = cpu_to_be32(FATTR4_WORD0_ACL);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001669 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001670 *p = cpu_to_be32(arg->acl_len);
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01001671 xdr_write_pages(xdr, arg->acl_pages, 0, arg->acl_len);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00001672}
1673
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001674static void
Andy Adamsond0179312008-12-23 16:06:17 -05001675encode_savefh(struct xdr_stream *xdr, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676{
Trond Myklebustab19b482012-03-04 18:13:57 -05001677 encode_op_hdr(xdr, OP_SAVEFH, decode_savefh_maxsz, hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678}
1679
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001680static 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 -07001681{
Trond Myklebustab19b482012-03-04 18:13:57 -05001682 encode_op_hdr(xdr, OP_SETATTR, decode_setattr_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001683 encode_nfs4_stateid(xdr, &arg->stateid);
Andreas Gruenbacherdff25dd2016-12-02 22:53:30 -05001684 encode_attrs(xdr, arg->iap, arg->label, server, false, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685}
1686
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001687static void encode_setclientid(struct xdr_stream *xdr, const struct nfs4_setclientid *setclientid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
Al Viro8687b632006-10-19 23:28:48 -07001689 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
Trond Myklebust70019512012-03-04 20:49:32 -05001691 encode_op_hdr(xdr, OP_SETCLIENTID, decode_setclientid_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001692 encode_nfs4_verifier(xdr, setclientid->sc_verifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Jeff Layton3a6bb732015-06-09 19:43:57 -04001694 encode_string(xdr, strlen(setclientid->sc_clnt->cl_owner_id),
1695 setclientid->sc_clnt->cl_owner_id);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001696 p = reserve_space(xdr, 4);
Benny Halevy34558512009-08-14 17:19:30 +03001697 *p = cpu_to_be32(setclientid->sc_prog);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 encode_string(xdr, setclientid->sc_netid_len, setclientid->sc_netid);
1699 encode_string(xdr, setclientid->sc_uaddr_len, setclientid->sc_uaddr);
Benny Halevy13c65ce2009-08-14 17:19:25 +03001700 p = reserve_space(xdr, 4);
Jeff Layton3a6bb732015-06-09 19:43:57 -04001701 *p = cpu_to_be32(setclientid->sc_clnt->cl_cb_ident);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702}
1703
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04001704static 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 -07001705{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001706 encode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM,
1707 decode_setclientid_confirm_maxsz, hdr);
Trond Myklebustff2eb682012-03-05 11:40:12 -05001708 encode_uint64(xdr, arg->clientid);
Chuck Levercd937102012-03-02 17:14:31 -05001709 encode_nfs4_verifier(xdr, &arg->confirm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710}
1711
Anna Schumaker3c6b8992014-05-06 09:12:24 -04001712static void encode_write(struct xdr_stream *xdr, const struct nfs_pgio_args *args,
1713 struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714{
Al Viro8687b632006-10-19 23:28:48 -07001715 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Trond Myklebustab19b482012-03-04 18:13:57 -05001717 encode_op_hdr(xdr, OP_WRITE, decode_write_maxsz, hdr);
Trond Myklebust9b206142013-03-17 15:52:00 -04001718 encode_nfs4_stateid(xdr, &args->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Benny Halevy13c65ce2009-08-14 17:19:25 +03001720 p = reserve_space(xdr, 16);
Benny Halevyb95be5a2009-08-14 17:19:01 +03001721 p = xdr_encode_hyper(p, args->offset);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001722 *p++ = cpu_to_be32(args->stable);
Benny Halevy34558512009-08-14 17:19:30 +03001723 *p = cpu_to_be32(args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 xdr_write_pages(xdr, args->pages, args->pgbase, args->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726}
1727
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05001728static void encode_delegreturn(struct xdr_stream *xdr, const nfs4_stateid *stateid, struct compound_hdr *hdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729{
Trond Myklebustab19b482012-03-04 18:13:57 -05001730 encode_op_hdr(xdr, OP_DELEGRETURN, decode_delegreturn_maxsz, hdr);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001731 encode_nfs4_stateid(xdr, stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001733
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001734static void encode_secinfo(struct xdr_stream *xdr, const struct qstr *name, struct compound_hdr *hdr)
1735{
Trond Myklebustab19b482012-03-04 18:13:57 -05001736 encode_op_hdr(xdr, OP_SECINFO, decode_secinfo_maxsz, hdr);
Trond Myklebust6fdfb0bc2012-03-04 18:13:57 -05001737 encode_string(xdr, name->len, name->name);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00001738}
1739
Benny Halevy99fe60d2009-04-01 09:22:29 -04001740#if defined(CONFIG_NFS_V4_1)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001741/* NFSv4.1 operations */
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001742static void encode_bind_conn_to_session(struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08001743 struct nfs41_bind_conn_to_session_args *args,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001744 struct compound_hdr *hdr)
1745{
1746 __be32 *p;
1747
1748 encode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION,
1749 decode_bind_conn_to_session_maxsz, hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001750 encode_opaque_fixed(xdr, args->sessionid.data, NFS4_MAX_SESSIONID_LEN);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001751 p = xdr_reserve_space(xdr, 8);
Trond Myklebust71a097c2015-02-18 09:27:18 -08001752 *p++ = cpu_to_be32(args->dir);
1753 *p = (args->use_conn_in_rdma_mode) ? cpu_to_be32(1) : cpu_to_be32(0);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04001754}
1755
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001756static void encode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
1757{
1758 unsigned int i;
1759 encode_uint32(xdr, NFS4_OP_MAP_NUM_WORDS);
1760 for (i = 0; i < NFS4_OP_MAP_NUM_WORDS; i++)
1761 encode_uint32(xdr, op_map->u.words[i]);
1762}
1763
Benny Halevy99fe60d2009-04-01 09:22:29 -04001764static void encode_exchange_id(struct xdr_stream *xdr,
1765 struct nfs41_exchange_id_args *args,
1766 struct compound_hdr *hdr)
1767{
1768 __be32 *p;
Jim Reesd751f742012-11-16 18:12:06 -05001769 char impl_name[IMPL_NAME_LIMIT];
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001770 int len = 0;
Benny Halevy99fe60d2009-04-01 09:22:29 -04001771
Trond Myklebust70019512012-03-04 20:49:32 -05001772 encode_op_hdr(xdr, OP_EXCHANGE_ID, decode_exchange_id_maxsz, hdr);
Chuck Levercd937102012-03-02 17:14:31 -05001773 encode_nfs4_verifier(xdr, args->verifier);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001774
Jeff Layton3a6bb732015-06-09 19:43:57 -04001775 encode_string(xdr, strlen(args->client->cl_owner_id),
1776 args->client->cl_owner_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04001777
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001778 encode_uint32(xdr, args->flags);
1779 encode_uint32(xdr, args->state_protect.how);
1780
1781 switch (args->state_protect.how) {
1782 case SP4_NONE:
1783 break;
1784 case SP4_MACH_CRED:
1785 encode_op_map(xdr, &args->state_protect.enforce);
1786 encode_op_map(xdr, &args->state_protect.allow);
1787 break;
1788 default:
1789 WARN_ON_ONCE(1);
1790 break;
1791 }
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001792
1793 if (send_implementation_id &&
1794 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) > 1 &&
1795 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN)
Jim Reesd751f742012-11-16 18:12:06 -05001796 <= sizeof(impl_name) + 1)
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001797 len = snprintf(impl_name, sizeof(impl_name), "%s %s %s %s",
1798 utsname()->sysname, utsname()->release,
1799 utsname()->version, utsname()->machine);
1800
1801 if (len > 0) {
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001802 encode_uint32(xdr, 1); /* implementation id array length=1 */
Weston Andros Adamsondb8ac8b2012-02-17 15:20:24 -05001803
1804 encode_string(xdr,
1805 sizeof(CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN) - 1,
1806 CONFIG_NFS_V4_1_IMPLEMENTATION_ID_DOMAIN);
1807 encode_string(xdr, len, impl_name);
1808 /* just send zeros for nii_date - the date is in nii_name */
1809 p = reserve_space(xdr, 12);
1810 p = xdr_encode_hyper(p, 0);
1811 *p = cpu_to_be32(0);
1812 } else
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04001813 encode_uint32(xdr, 0); /* implementation id array length=0 */
Benny Halevy99fe60d2009-04-01 09:22:29 -04001814}
Andy Adamsonfc931582009-04-01 09:22:31 -04001815
1816static void encode_create_session(struct xdr_stream *xdr,
1817 struct nfs41_create_session_args *args,
1818 struct compound_hdr *hdr)
1819{
1820 __be32 *p;
Andy Adamsonfc931582009-04-01 09:22:31 -04001821 struct nfs_client *clp = args->client;
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001822 struct rpc_clnt *clnt = clp->cl_rpcclient;
Chuck Leverf0920752012-05-21 22:45:41 -04001823 struct nfs_net *nn = net_generic(clp->cl_net, nfs_net_id);
Mike Sager8e0d46e2009-12-17 12:06:26 -05001824 u32 max_resp_sz_cached;
1825
1826 /*
1827 * Assumes OPEN is the biggest non-idempotent compound.
1828 * 2 is the verifier.
1829 */
1830 max_resp_sz_cached = (NFS4_dec_open_sz + RPC_REPHDRSIZE +
1831 RPC_MAX_AUTH_SIZE + 2) * XDR_UNIT;
Andy Adamsonfc931582009-04-01 09:22:31 -04001832
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001833 encode_op_hdr(xdr, OP_CREATE_SESSION, decode_create_session_maxsz, hdr);
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001834 p = reserve_space(xdr, 16 + 2*28 + 20 + clnt->cl_nodelen + 12);
Trond Myklebust79969dd2015-02-18 11:30:18 -08001835 p = xdr_encode_hyper(p, args->clientid);
1836 *p++ = cpu_to_be32(args->seqid); /*Sequence id */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001837 *p++ = cpu_to_be32(args->flags); /*flags */
Andy Adamsonfc931582009-04-01 09:22:31 -04001838
Andy Adamsonfc931582009-04-01 09:22:31 -04001839 /* Fore 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->fc_attrs.max_rqst_sz); /* max req size */
1842 *p++ = cpu_to_be32(args->fc_attrs.max_resp_sz); /* max resp size */
Mike Sager8e0d46e2009-12-17 12:06:26 -05001843 *p++ = cpu_to_be32(max_resp_sz_cached); /* Max resp sz cached */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001844 *p++ = cpu_to_be32(args->fc_attrs.max_ops); /* max operations */
1845 *p++ = cpu_to_be32(args->fc_attrs.max_reqs); /* max requests */
1846 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001847
1848 /* Back Channel */
Benny Halevyc9c30dd2011-06-11 17:08:39 -04001849 *p++ = cpu_to_be32(0); /* header padding size */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001850 *p++ = cpu_to_be32(args->bc_attrs.max_rqst_sz); /* max req size */
1851 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz); /* max resp size */
1852 *p++ = cpu_to_be32(args->bc_attrs.max_resp_sz_cached); /* Max resp sz cached */
1853 *p++ = cpu_to_be32(args->bc_attrs.max_ops); /* max operations */
1854 *p++ = cpu_to_be32(args->bc_attrs.max_reqs); /* max requests */
1855 *p++ = cpu_to_be32(0); /* rdmachannel_attrs */
Andy Adamsonfc931582009-04-01 09:22:31 -04001856
Benny Halevye75bc1c2009-08-14 17:18:54 +03001857 *p++ = cpu_to_be32(args->cb_program); /* cb_program */
Benny Halevye75bc1c2009-08-14 17:18:54 +03001858 *p++ = cpu_to_be32(1);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001859 *p++ = cpu_to_be32(RPC_AUTH_UNIX); /* auth_sys */
Andy Adamsonfc931582009-04-01 09:22:31 -04001860
1861 /* authsys_parms rfc1831 */
Deepa Dinamani2f86e092016-10-01 16:46:26 -07001862 *p++ = cpu_to_be32(ktime_to_ns(nn->boot_time)); /* stamp */
Trond Myklebust89f0ff32015-01-03 14:47:43 -05001863 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001864 *p++ = cpu_to_be32(0); /* UID */
1865 *p++ = cpu_to_be32(0); /* GID */
Benny Halevy34558512009-08-14 17:19:30 +03001866 *p = cpu_to_be32(0); /* No more gids */
Andy Adamsonfc931582009-04-01 09:22:31 -04001867}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001868
1869static void encode_destroy_session(struct xdr_stream *xdr,
1870 struct nfs4_session *session,
1871 struct compound_hdr *hdr)
1872{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001873 encode_op_hdr(xdr, OP_DESTROY_SESSION, decode_destroy_session_maxsz, hdr);
1874 encode_opaque_fixed(xdr, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04001875}
Ricardo Labiaga180197532009-12-05 16:08:40 -05001876
Trond Myklebust66245532012-05-25 17:18:09 -04001877static void encode_destroy_clientid(struct xdr_stream *xdr,
1878 uint64_t clientid,
1879 struct compound_hdr *hdr)
1880{
1881 encode_op_hdr(xdr, OP_DESTROY_CLIENTID, decode_destroy_clientid_maxsz, hdr);
1882 encode_uint64(xdr, clientid);
1883}
1884
Ricardo Labiaga180197532009-12-05 16:08:40 -05001885static void encode_reclaim_complete(struct xdr_stream *xdr,
1886 struct nfs41_reclaim_complete_args *args,
1887 struct compound_hdr *hdr)
1888{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001889 encode_op_hdr(xdr, OP_RECLAIM_COMPLETE, decode_reclaim_complete_maxsz, hdr);
1890 encode_uint32(xdr, args->one_fs);
Ricardo Labiaga180197532009-12-05 16:08:40 -05001891}
Benny Halevy99fe60d2009-04-01 09:22:29 -04001892#endif /* CONFIG_NFS_V4_1 */
1893
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001894static void encode_sequence(struct xdr_stream *xdr,
1895 const struct nfs4_sequence_args *args,
1896 struct compound_hdr *hdr)
1897{
1898#if defined(CONFIG_NFS_V4_1)
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001899 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001900 struct nfs4_slot_table *tp;
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001901 struct nfs4_slot *slot = args->sa_slot;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001902 __be32 *p;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001903
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001904 tp = slot->table;
1905 session = tp->session;
Chuck Lever3bd23842013-08-09 12:49:19 -04001906 if (!session)
1907 return;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001908
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001909 encode_op_hdr(xdr, OP_SEQUENCE, decode_sequence_maxsz, hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001910
1911 /*
1912 * Sessionid + seqid + slotid + max slotid + cache_this
1913 */
1914 dprintk("%s: sessionid=%u:%u:%u:%u seqid=%d slotid=%d "
1915 "max_slotid=%d cache_this=%d\n",
1916 __func__,
1917 ((u32 *)session->sess_id.data)[0],
1918 ((u32 *)session->sess_id.data)[1],
1919 ((u32 *)session->sess_id.data)[2],
1920 ((u32 *)session->sess_id.data)[3],
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001921 slot->seq_nr, slot->slot_nr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04001922 tp->highest_used_slotid, args->sa_cache_this);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001923 p = reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 16);
Benny Halevy93f0cf22009-08-14 17:19:06 +03001924 p = xdr_encode_opaque_fixed(p, session->sess_id.data, NFS4_MAX_SESSIONID_LEN);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001925 *p++ = cpu_to_be32(slot->seq_nr);
Trond Myklebust2b2fa712012-11-16 12:58:36 -05001926 *p++ = cpu_to_be32(slot->slot_nr);
Benny Halevye75bc1c2009-08-14 17:18:54 +03001927 *p++ = cpu_to_be32(tp->highest_used_slotid);
Benny Halevy34558512009-08-14 17:19:30 +03001928 *p = cpu_to_be32(args->sa_cache_this);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04001929#endif /* CONFIG_NFS_V4_1 */
1930}
1931
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001932#ifdef CONFIG_NFS_V4_1
1933static void
1934encode_getdeviceinfo(struct xdr_stream *xdr,
1935 const struct nfs4_getdeviceinfo_args *args,
1936 struct compound_hdr *hdr)
1937{
1938 __be32 *p;
1939
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001940 encode_op_hdr(xdr, OP_GETDEVICEINFO, decode_getdeviceinfo_maxsz, hdr);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001941 p = reserve_space(xdr, NFS4_DEVICEID4_SIZE + 4 + 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001942 p = xdr_encode_opaque_fixed(p, args->pdev->dev_id.data,
1943 NFS4_DEVICEID4_SIZE);
1944 *p++ = cpu_to_be32(args->pdev->layout_type);
Andy Adamsonf1c097b2013-06-25 19:02:53 -04001945 *p++ = cpu_to_be32(args->pdev->maxcount); /* gdia_maxcount */
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07001946
1947 p = reserve_space(xdr, 4 + 4);
1948 *p++ = cpu_to_be32(1); /* bitmap length */
Trond Myklebust4e590802015-03-09 14:01:25 -04001949 *p++ = cpu_to_be32(args->notify_types);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001950}
1951
1952static void
1953encode_layoutget(struct xdr_stream *xdr,
1954 const struct nfs4_layoutget_args *args,
1955 struct compound_hdr *hdr)
1956{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001957 __be32 *p;
1958
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001959 encode_op_hdr(xdr, OP_LAYOUTGET, decode_layoutget_maxsz, hdr);
1960 p = reserve_space(xdr, 36);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001961 *p++ = cpu_to_be32(0); /* Signal layout available */
1962 *p++ = cpu_to_be32(args->type);
1963 *p++ = cpu_to_be32(args->range.iomode);
1964 p = xdr_encode_hyper(p, args->range.offset);
1965 p = xdr_encode_hyper(p, args->range.length);
1966 p = xdr_encode_hyper(p, args->minlength);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001967 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001968 encode_uint32(xdr, args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001969
1970 dprintk("%s: 1st type:0x%x iomode:%d off:%lu len:%lu mc:%d\n",
1971 __func__,
1972 args->type,
1973 args->range.iomode,
1974 (unsigned long)args->range.offset,
1975 (unsigned long)args->range.length,
1976 args->maxcount);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04001977}
Andy Adamson863a3c62011-03-23 13:27:54 +00001978
1979static int
1980encode_layoutcommit(struct xdr_stream *xdr,
Benny Halevyac7db722011-05-22 19:53:48 +03001981 struct inode *inode,
Christoph Hellwig5f919c92014-08-21 11:09:25 -05001982 struct nfs4_layoutcommit_args *args,
Andy Adamson863a3c62011-03-23 13:27:54 +00001983 struct compound_hdr *hdr)
1984{
1985 __be32 *p;
1986
1987 dprintk("%s: lbw: %llu type: %d\n", __func__, args->lastbytewritten,
1988 NFS_SERVER(args->inode)->pnfs_curr_ld->id);
1989
Trond Myklebust475d4ba2012-03-05 11:27:16 -05001990 encode_op_hdr(xdr, OP_LAYOUTCOMMIT, decode_layoutcommit_maxsz, hdr);
1991 p = reserve_space(xdr, 20);
Andy Adamson863a3c62011-03-23 13:27:54 +00001992 /* Only whole file layouts */
1993 p = xdr_encode_hyper(p, 0); /* offset */
Peng Tao3557c6c2011-07-30 20:52:34 -04001994 p = xdr_encode_hyper(p, args->lastbytewritten + 1); /* length */
Trond Myklebustea9d23f2012-03-04 18:13:56 -05001995 *p = cpu_to_be32(0); /* reclaim */
1996 encode_nfs4_stateid(xdr, &args->stateid);
Trond Myklebust2e18d4d2016-06-26 18:54:58 -04001997 if (args->lastbytewritten != U64_MAX) {
1998 p = reserve_space(xdr, 20);
1999 *p++ = cpu_to_be32(1); /* newoffset = TRUE */
2000 p = xdr_encode_hyper(p, args->lastbytewritten);
2001 } else {
2002 p = reserve_space(xdr, 12);
2003 *p++ = cpu_to_be32(0); /* newoffset = FALSE */
2004 }
Andy Adamson863a3c62011-03-23 13:27:54 +00002005 *p++ = cpu_to_be32(0); /* Never send time_modify_changed */
2006 *p++ = cpu_to_be32(NFS_SERVER(args->inode)->pnfs_curr_ld->id);/* type */
Benny Halevyac7db722011-05-22 19:53:48 +03002007
Trond Myklebust73504742017-04-20 16:48:14 -04002008 encode_uint32(xdr, args->layoutupdate_len);
2009 if (args->layoutupdate_pages)
2010 xdr_write_pages(xdr, args->layoutupdate_pages, 0,
2011 args->layoutupdate_len);
Andy Adamson863a3c62011-03-23 13:27:54 +00002012
Andy Adamson863a3c62011-03-23 13:27:54 +00002013 return 0;
2014}
Benny Halevycbe82602011-05-22 19:52:37 +03002015
2016static void
2017encode_layoutreturn(struct xdr_stream *xdr,
2018 const struct nfs4_layoutreturn_args *args,
2019 struct compound_hdr *hdr)
2020{
2021 __be32 *p;
2022
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002023 encode_op_hdr(xdr, OP_LAYOUTRETURN, decode_layoutreturn_maxsz, hdr);
2024 p = reserve_space(xdr, 16);
Benny Halevycbe82602011-05-22 19:52:37 +03002025 *p++ = cpu_to_be32(0); /* reclaim. always 0 for now */
2026 *p++ = cpu_to_be32(args->layout_type);
Peng Tao15eb67c2014-11-17 09:30:36 +08002027 *p++ = cpu_to_be32(args->range.iomode);
Benny Halevycbe82602011-05-22 19:52:37 +03002028 *p = cpu_to_be32(RETURN_FILE);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002029 p = reserve_space(xdr, 16);
Peng Tao15eb67c2014-11-17 09:30:36 +08002030 p = xdr_encode_hyper(p, args->range.offset);
2031 p = xdr_encode_hyper(p, args->range.length);
Benny Halevycbe82602011-05-22 19:52:37 +03002032 spin_lock(&args->inode->i_lock);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002033 encode_nfs4_stateid(xdr, &args->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03002034 spin_unlock(&args->inode->i_lock);
Trond Myklebust4d796d72016-09-23 11:38:08 -04002035 if (args->ld_private->ops && args->ld_private->ops->encode)
2036 args->ld_private->ops->encode(xdr, args, args->ld_private);
Trond Myklebust94e5c572016-09-15 18:49:52 -04002037 else
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002038 encode_uint32(xdr, 0);
Benny Halevycbe82602011-05-22 19:52:37 +03002039}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002040
2041static int
2042encode_secinfo_no_name(struct xdr_stream *xdr,
2043 const struct nfs41_secinfo_no_name_args *args,
2044 struct compound_hdr *hdr)
2045{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002046 encode_op_hdr(xdr, OP_SECINFO_NO_NAME, decode_secinfo_no_name_maxsz, hdr);
2047 encode_uint32(xdr, args->style);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002048 return 0;
2049}
Bryan Schumaker7d974792011-06-02 14:59:08 -04002050
2051static void encode_test_stateid(struct xdr_stream *xdr,
2052 struct nfs41_test_stateid_args *args,
2053 struct compound_hdr *hdr)
2054{
Trond Myklebust475d4ba2012-03-05 11:27:16 -05002055 encode_op_hdr(xdr, OP_TEST_STATEID, decode_test_stateid_maxsz, hdr);
2056 encode_uint32(xdr, 1);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05002057 encode_nfs4_stateid(xdr, args->stateid);
Bryan Schumaker7d974792011-06-02 14:59:08 -04002058}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002059
2060static void encode_free_stateid(struct xdr_stream *xdr,
2061 struct nfs41_free_stateid_args *args,
2062 struct compound_hdr *hdr)
2063{
Trond Myklebustab19b482012-03-04 18:13:57 -05002064 encode_op_hdr(xdr, OP_FREE_STATEID, decode_free_stateid_maxsz, hdr);
Trond Myklebust7c1d5fa2013-05-03 14:40:01 -04002065 encode_nfs4_stateid(xdr, &args->stateid);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04002066}
Trond Myklebustcf805162016-11-15 14:56:07 -05002067#else
2068static inline void
2069encode_layoutreturn(struct xdr_stream *xdr,
2070 const struct nfs4_layoutreturn_args *args,
2071 struct compound_hdr *hdr)
2072{
2073}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002074#endif /* CONFIG_NFS_V4_1 */
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076/*
2077 * END OF "GENERIC" ENCODE ROUTINES.
2078 */
2079
Benny Halevy66cc0422009-04-01 09:22:10 -04002080static u32 nfs4_xdr_minorversion(const struct nfs4_sequence_args *args)
2081{
2082#if defined(CONFIG_NFS_V4_1)
Chuck Lever3bd23842013-08-09 12:49:19 -04002083 struct nfs4_session *session = args->sa_slot->table->session;
2084 if (session)
2085 return session->clp->cl_mvops->minor_version;
Benny Halevy66cc0422009-04-01 09:22:10 -04002086#endif /* CONFIG_NFS_V4_1 */
2087 return 0;
2088}
2089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090/*
2091 * Encode an ACCESS request
2092 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002093static void nfs4_xdr_enc_access(struct rpc_rqst *req, struct xdr_stream *xdr,
2094 const struct nfs4_accessargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002097 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Chuck Lever9f06c712010-12-14 14:59:18 +00002100 encode_compound_hdr(xdr, req, &hdr);
2101 encode_sequence(xdr, &args->seq_args, &hdr);
2102 encode_putfh(xdr, args->fh, &hdr);
2103 encode_access(xdr, args->access, &hdr);
2104 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002105 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
2108/*
2109 * Encode LOOKUP request
2110 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002111static void nfs4_xdr_enc_lookup(struct rpc_rqst *req, struct xdr_stream *xdr,
2112 const struct nfs4_lookup_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002115 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
Chuck Lever9f06c712010-12-14 14:59:18 +00002118 encode_compound_hdr(xdr, req, &hdr);
2119 encode_sequence(xdr, &args->seq_args, &hdr);
2120 encode_putfh(xdr, args->dir_fh, &hdr);
2121 encode_lookup(xdr, args->name, &hdr);
2122 encode_getfh(xdr, &hdr);
2123 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002124 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
2127/*
2128 * Encode LOOKUP_ROOT request
2129 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002130static void nfs4_xdr_enc_lookup_root(struct rpc_rqst *req,
2131 struct xdr_stream *xdr,
2132 const struct nfs4_lookup_root_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002135 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
Chuck Lever9f06c712010-12-14 14:59:18 +00002138 encode_compound_hdr(xdr, req, &hdr);
2139 encode_sequence(xdr, &args->seq_args, &hdr);
2140 encode_putrootfh(xdr, &hdr);
2141 encode_getfh(xdr, &hdr);
2142 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002143 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
2146/*
2147 * Encode REMOVE request
2148 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002149static void nfs4_xdr_enc_remove(struct rpc_rqst *req, struct xdr_stream *xdr,
2150 const struct nfs_removeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002153 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
Chuck Lever9f06c712010-12-14 14:59:18 +00002156 encode_compound_hdr(xdr, req, &hdr);
2157 encode_sequence(xdr, &args->seq_args, &hdr);
2158 encode_putfh(xdr, args->fh, &hdr);
2159 encode_remove(xdr, &args->name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002160 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161}
2162
2163/*
2164 * Encode RENAME request
2165 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002166static void nfs4_xdr_enc_rename(struct rpc_rqst *req, struct xdr_stream *xdr,
2167 const struct nfs_renameargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002170 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Chuck Lever9f06c712010-12-14 14:59:18 +00002173 encode_compound_hdr(xdr, req, &hdr);
2174 encode_sequence(xdr, &args->seq_args, &hdr);
2175 encode_putfh(xdr, args->old_dir, &hdr);
2176 encode_savefh(xdr, &hdr);
2177 encode_putfh(xdr, args->new_dir, &hdr);
2178 encode_rename(xdr, args->old_name, args->new_name, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002179 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180}
2181
2182/*
2183 * Encode LINK request
2184 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002185static void nfs4_xdr_enc_link(struct rpc_rqst *req, struct xdr_stream *xdr,
2186 const struct nfs4_link_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002189 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
Chuck Lever9f06c712010-12-14 14:59:18 +00002192 encode_compound_hdr(xdr, req, &hdr);
2193 encode_sequence(xdr, &args->seq_args, &hdr);
2194 encode_putfh(xdr, args->fh, &hdr);
2195 encode_savefh(xdr, &hdr);
2196 encode_putfh(xdr, args->dir_fh, &hdr);
2197 encode_link(xdr, args->name, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002198 encode_restorefh(xdr, &hdr);
2199 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002200 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/*
2204 * Encode CREATE request
2205 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002206static void nfs4_xdr_enc_create(struct rpc_rqst *req, struct xdr_stream *xdr,
2207 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002210 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Chuck Lever9f06c712010-12-14 14:59:18 +00002213 encode_compound_hdr(xdr, req, &hdr);
2214 encode_sequence(xdr, &args->seq_args, &hdr);
2215 encode_putfh(xdr, args->dir_fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002216 encode_create(xdr, args, &hdr);
2217 encode_getfh(xdr, &hdr);
2218 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002219 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220}
2221
2222/*
2223 * Encode SYMLINK request
2224 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002225static void nfs4_xdr_enc_symlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2226 const struct nfs4_create_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
Chuck Lever9f06c712010-12-14 14:59:18 +00002228 nfs4_xdr_enc_create(req, xdr, args);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229}
2230
2231/*
2232 * Encode GETATTR request
2233 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002234static void nfs4_xdr_enc_getattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2235 const struct nfs4_getattr_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002238 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Chuck Lever9f06c712010-12-14 14:59:18 +00002241 encode_compound_hdr(xdr, req, &hdr);
2242 encode_sequence(xdr, &args->seq_args, &hdr);
2243 encode_putfh(xdr, args->fh, &hdr);
2244 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002245 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246}
2247
2248/*
2249 * Encode a CLOSE request
2250 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002251static void nfs4_xdr_enc_close(struct rpc_rqst *req, struct xdr_stream *xdr,
2252 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253{
Andy Adamson05d564f2008-12-23 16:06:15 -05002254 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002255 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002256 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257
Chuck Lever9f06c712010-12-14 14:59:18 +00002258 encode_compound_hdr(xdr, req, &hdr);
2259 encode_sequence(xdr, &args->seq_args, &hdr);
2260 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustcf805162016-11-15 14:56:07 -05002261 if (args->lr_args)
2262 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust3ecefc92016-10-27 18:25:04 -04002263 if (args->bitmask != NULL)
2264 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebustd8d84982016-12-19 12:14:44 -05002265 encode_close(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002266 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267}
2268
2269/*
2270 * Encode an OPEN request
2271 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002272static void nfs4_xdr_enc_open(struct rpc_rqst *req, struct xdr_stream *xdr,
2273 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002276 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
Chuck Lever9f06c712010-12-14 14:59:18 +00002279 encode_compound_hdr(xdr, req, &hdr);
2280 encode_sequence(xdr, &args->seq_args, &hdr);
2281 encode_putfh(xdr, args->fh, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002282 encode_open(xdr, args, &hdr);
2283 encode_getfh(xdr, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002284 if (args->access)
2285 encode_access(xdr, args->access, &hdr);
Trond Myklebust1549210f2012-06-05 09:16:47 -04002286 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002287 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288}
2289
2290/*
2291 * Encode an OPEN_CONFIRM request
2292 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002293static void nfs4_xdr_enc_open_confirm(struct rpc_rqst *req,
2294 struct xdr_stream *xdr,
2295 struct nfs_open_confirmargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002298 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
Chuck Lever9f06c712010-12-14 14:59:18 +00002301 encode_compound_hdr(xdr, req, &hdr);
2302 encode_putfh(xdr, args->fh, &hdr);
2303 encode_open_confirm(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002304 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305}
2306
2307/*
2308 * Encode an OPEN request with no attributes.
2309 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002310static void nfs4_xdr_enc_open_noattr(struct rpc_rqst *req,
2311 struct xdr_stream *xdr,
2312 struct nfs_openargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002315 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Chuck Lever9f06c712010-12-14 14:59:18 +00002318 encode_compound_hdr(xdr, req, &hdr);
2319 encode_sequence(xdr, &args->seq_args, &hdr);
2320 encode_putfh(xdr, args->fh, &hdr);
2321 encode_open(xdr, args, &hdr);
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07002322 if (args->access)
2323 encode_access(xdr, args->access, &hdr);
Andy Adamsone23008e2012-10-02 21:07:32 -04002324 encode_getfattr_open(xdr, args->bitmask, args->open_bitmap, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002325 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326}
2327
2328/*
2329 * Encode an OPEN_DOWNGRADE request
2330 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002331static void nfs4_xdr_enc_open_downgrade(struct rpc_rqst *req,
2332 struct xdr_stream *xdr,
2333 struct nfs_closeargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002336 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Chuck Lever9f06c712010-12-14 14:59:18 +00002339 encode_compound_hdr(xdr, req, &hdr);
2340 encode_sequence(xdr, &args->seq_args, &hdr);
2341 encode_putfh(xdr, args->fh, &hdr);
Trond Myklebustb6808142016-11-20 13:34:16 -05002342 if (args->lr_args)
2343 encode_layoutreturn(xdr, args->lr_args, &hdr);
Chuck Lever9f06c712010-12-14 14:59:18 +00002344 encode_open_downgrade(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002345 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346}
2347
2348/*
2349 * Encode a LOCK request
2350 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002351static void nfs4_xdr_enc_lock(struct rpc_rqst *req, struct xdr_stream *xdr,
2352 struct nfs_lock_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002355 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Chuck Lever9f06c712010-12-14 14:59:18 +00002358 encode_compound_hdr(xdr, req, &hdr);
2359 encode_sequence(xdr, &args->seq_args, &hdr);
2360 encode_putfh(xdr, args->fh, &hdr);
2361 encode_lock(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002362 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363}
2364
2365/*
2366 * Encode a LOCKT request
2367 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002368static void nfs4_xdr_enc_lockt(struct rpc_rqst *req, struct xdr_stream *xdr,
2369 struct nfs_lockt_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002372 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374
Chuck Lever9f06c712010-12-14 14:59:18 +00002375 encode_compound_hdr(xdr, req, &hdr);
2376 encode_sequence(xdr, &args->seq_args, &hdr);
2377 encode_putfh(xdr, args->fh, &hdr);
2378 encode_lockt(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002379 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380}
2381
2382/*
2383 * Encode a LOCKU request
2384 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002385static void nfs4_xdr_enc_locku(struct rpc_rqst *req, struct xdr_stream *xdr,
2386 struct nfs_locku_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002389 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
Chuck Lever9f06c712010-12-14 14:59:18 +00002392 encode_compound_hdr(xdr, req, &hdr);
2393 encode_sequence(xdr, &args->seq_args, &hdr);
2394 encode_putfh(xdr, args->fh, &hdr);
2395 encode_locku(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002396 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397}
2398
Chuck Lever9f06c712010-12-14 14:59:18 +00002399static void nfs4_xdr_enc_release_lockowner(struct rpc_rqst *req,
2400 struct xdr_stream *xdr,
2401 struct nfs_release_lockowner_args *args)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002402{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002403 struct compound_hdr hdr = {
2404 .minorversion = 0,
2405 };
2406
Chuck Lever9f06c712010-12-14 14:59:18 +00002407 encode_compound_hdr(xdr, req, &hdr);
2408 encode_release_lockowner(xdr, &args->lock_owner, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002409 encode_nops(&hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04002410}
2411
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412/*
2413 * Encode a READLINK request
2414 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002415static void nfs4_xdr_enc_readlink(struct rpc_rqst *req, struct xdr_stream *xdr,
2416 const struct nfs4_readlink *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002419 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
Chuck Lever9f06c712010-12-14 14:59:18 +00002422 encode_compound_hdr(xdr, req, &hdr);
2423 encode_sequence(xdr, &args->seq_args, &hdr);
2424 encode_putfh(xdr, args->fh, &hdr);
2425 encode_readlink(xdr, args, req, &hdr);
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002426
Benny Halevy28f56692009-04-01 09:22:09 -04002427 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebuste3a535e2007-07-19 10:03:38 -04002428 args->pgbase, args->pglen);
Andy Adamsond0179312008-12-23 16:06:17 -05002429 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430}
2431
2432/*
2433 * Encode a READDIR request
2434 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002435static void nfs4_xdr_enc_readdir(struct rpc_rqst *req, struct xdr_stream *xdr,
2436 const struct nfs4_readdir_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002439 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Chuck Lever9f06c712010-12-14 14:59:18 +00002442 encode_compound_hdr(xdr, req, &hdr);
2443 encode_sequence(xdr, &args->seq_args, &hdr);
2444 encode_putfh(xdr, args->fh, &hdr);
2445 encode_readdir(xdr, args, req, &hdr);
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002446
Benny Halevy28f56692009-04-01 09:22:09 -04002447 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002448 args->pgbase, args->count);
2449 dprintk("%s: inlined page args = (%u, %p, %u, %u)\n",
Benny Halevy28f56692009-04-01 09:22:09 -04002450 __func__, hdr.replen << 2, args->pages,
Trond Myklebustd6ac02d2007-07-19 10:03:37 -04002451 args->pgbase, args->count);
Andy Adamsond0179312008-12-23 16:06:17 -05002452 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453}
2454
2455/*
2456 * Encode a READ request
2457 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002458static void nfs4_xdr_enc_read(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002459 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002462 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
Chuck Lever9f06c712010-12-14 14:59:18 +00002465 encode_compound_hdr(xdr, req, &hdr);
2466 encode_sequence(xdr, &args->seq_args, &hdr);
2467 encode_putfh(xdr, args->fh, &hdr);
2468 encode_read(xdr, args, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469
Benny Halevy28f56692009-04-01 09:22:09 -04002470 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 args->pages, args->pgbase, args->count);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002472 req->rq_rcv_buf.flags |= XDRBUF_READ;
Andy Adamsond0179312008-12-23 16:06:17 -05002473 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474}
2475
2476/*
2477 * Encode an SETATTR request
2478 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002479static void nfs4_xdr_enc_setattr(struct rpc_rqst *req, struct xdr_stream *xdr,
2480 struct nfs_setattrargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481{
Andy Adamson05d564f2008-12-23 16:06:15 -05002482 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002483 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05002484 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
Chuck Lever9f06c712010-12-14 14:59:18 +00002486 encode_compound_hdr(xdr, req, &hdr);
2487 encode_sequence(xdr, &args->seq_args, &hdr);
2488 encode_putfh(xdr, args->fh, &hdr);
2489 encode_setattr(xdr, args, args->server, &hdr);
2490 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002491 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492}
2493
2494/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00002495 * Encode a GETACL request
2496 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002497static void nfs4_xdr_enc_getacl(struct rpc_rqst *req, struct xdr_stream *xdr,
2498 struct nfs_getaclargs *args)
J. Bruce Fields029d1052005-06-22 17:16:22 +00002499{
J. Bruce Fields029d1052005-06-22 17:16:22 +00002500 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002501 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
J. Bruce Fields029d1052005-06-22 17:16:22 +00002502 };
Benny Halevy28f56692009-04-01 09:22:09 -04002503 uint32_t replen;
J. Bruce Fields029d1052005-06-22 17:16:22 +00002504
Chuck Lever9f06c712010-12-14 14:59:18 +00002505 encode_compound_hdr(xdr, req, &hdr);
2506 encode_sequence(xdr, &args->seq_args, &hdr);
2507 encode_putfh(xdr, args->fh, &hdr);
J. Bruce Fields6682c142017-02-23 14:53:39 -05002508 replen = hdr.replen + op_decode_hdr_maxsz;
Chuck Lever9f06c712010-12-14 14:59:18 +00002509 encode_getattr_two(xdr, FATTR4_WORD0_ACL, 0, &hdr);
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002510
Benny Halevy28f56692009-04-01 09:22:09 -04002511 xdr_inline_pages(&req->rq_rcv_buf, replen << 2,
Andreas Gruenbacher8fbcf232015-11-03 18:25:34 +01002512 args->acl_pages, 0, args->acl_len);
Andy Adamsonbf118a32011-12-07 11:55:27 -05002513
Andy Adamsond0179312008-12-23 16:06:17 -05002514 encode_nops(&hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00002515}
2516
2517/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 * Encode a WRITE request
2519 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002520static void nfs4_xdr_enc_write(struct rpc_rqst *req, struct xdr_stream *xdr,
Anna Schumaker3c6b8992014-05-06 09:12:24 -04002521 struct nfs_pgio_args *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002524 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
Chuck Lever9f06c712010-12-14 14:59:18 +00002527 encode_compound_hdr(xdr, req, &hdr);
2528 encode_sequence(xdr, &args->seq_args, &hdr);
2529 encode_putfh(xdr, args->fh, &hdr);
2530 encode_write(xdr, args, &hdr);
\"Talpey, Thomas\4f22ccc2007-09-10 13:44:58 -04002531 req->rq_snd_buf.flags |= XDRBUF_WRITE;
Fred Isaman7ffd1062011-03-03 15:13:46 +00002532 if (args->bitmask)
2533 encode_getfattr(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002534 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537/*
2538 * a COMMIT request
2539 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002540static void nfs4_xdr_enc_commit(struct rpc_rqst *req, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04002541 struct nfs_commitargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002544 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
Chuck Lever9f06c712010-12-14 14:59:18 +00002547 encode_compound_hdr(xdr, req, &hdr);
2548 encode_sequence(xdr, &args->seq_args, &hdr);
2549 encode_putfh(xdr, args->fh, &hdr);
2550 encode_commit(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002551 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552}
2553
2554/*
2555 * FSINFO request
2556 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002557static void nfs4_xdr_enc_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
2558 struct nfs4_fsinfo_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002561 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
Chuck Lever9f06c712010-12-14 14:59:18 +00002564 encode_compound_hdr(xdr, req, &hdr);
2565 encode_sequence(xdr, &args->seq_args, &hdr);
2566 encode_putfh(xdr, args->fh, &hdr);
2567 encode_fsinfo(xdr, args->bitmask, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002568 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569}
2570
2571/*
2572 * a PATHCONF request
2573 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002574static void nfs4_xdr_enc_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
2575 const struct nfs4_pathconf_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002578 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
Chuck Lever9f06c712010-12-14 14:59:18 +00002581 encode_compound_hdr(xdr, req, &hdr);
2582 encode_sequence(xdr, &args->seq_args, &hdr);
2583 encode_putfh(xdr, args->fh, &hdr);
2584 encode_getattr_one(xdr, args->bitmask[0] & nfs4_pathconf_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002585 &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002586 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587}
2588
2589/*
2590 * a STATFS request
2591 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002592static void nfs4_xdr_enc_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
2593 const struct nfs4_statfs_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002596 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
Chuck Lever9f06c712010-12-14 14:59:18 +00002599 encode_compound_hdr(xdr, req, &hdr);
2600 encode_sequence(xdr, &args->seq_args, &hdr);
2601 encode_putfh(xdr, args->fh, &hdr);
2602 encode_getattr_two(xdr, args->bitmask[0] & nfs4_statfs_bitmap[0],
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002603 args->bitmask[1] & nfs4_statfs_bitmap[1], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002604 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605}
2606
2607/*
2608 * GETATTR_BITMAP request
2609 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002610static void nfs4_xdr_enc_server_caps(struct rpc_rqst *req,
2611 struct xdr_stream *xdr,
2612 struct nfs4_server_caps_arg *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613{
Kinglong Mee8c612822015-08-26 21:12:58 +08002614 const u32 *bitmask = args->bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002616 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
Chuck Lever9f06c712010-12-14 14:59:18 +00002619 encode_compound_hdr(xdr, req, &hdr);
2620 encode_sequence(xdr, &args->seq_args, &hdr);
2621 encode_putfh(xdr, args->fhandle, &hdr);
Kinglong Mee8c612822015-08-26 21:12:58 +08002622 encode_getattr_three(xdr, bitmask[0], bitmask[1], bitmask[2], &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002623 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624}
2625
2626/*
2627 * a RENEW request
2628 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002629static void nfs4_xdr_enc_renew(struct rpc_rqst *req, struct xdr_stream *xdr,
2630 struct nfs_client *clp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002633 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 };
2635
Chuck Lever9f06c712010-12-14 14:59:18 +00002636 encode_compound_hdr(xdr, req, &hdr);
Chuck Leverbb4dae52012-03-01 17:01:48 -05002637 encode_renew(xdr, clp->cl_clientid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002638 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639}
2640
2641/*
2642 * a SETCLIENTID request
2643 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002644static void nfs4_xdr_enc_setclientid(struct rpc_rqst *req,
2645 struct xdr_stream *xdr,
2646 struct nfs4_setclientid *sc)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002649 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 };
2651
Chuck Lever9f06c712010-12-14 14:59:18 +00002652 encode_compound_hdr(xdr, req, &hdr);
2653 encode_setclientid(xdr, sc, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002654 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655}
2656
2657/*
2658 * a SETCLIENTID_CONFIRM request
2659 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002660static void nfs4_xdr_enc_setclientid_confirm(struct rpc_rqst *req,
2661 struct xdr_stream *xdr,
2662 struct nfs4_setclientid_res *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 struct compound_hdr hdr = {
Andy Adamsond0179312008-12-23 16:06:17 -05002665 .nops = 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
Chuck Lever9f06c712010-12-14 14:59:18 +00002668 encode_compound_hdr(xdr, req, &hdr);
2669 encode_setclientid_confirm(xdr, arg, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002670 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
2673/*
2674 * DELEGRETURN request
2675 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002676static void nfs4_xdr_enc_delegreturn(struct rpc_rqst *req,
2677 struct xdr_stream *xdr,
2678 const struct nfs4_delegreturnargs *args)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002681 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
Chuck Lever9f06c712010-12-14 14:59:18 +00002684 encode_compound_hdr(xdr, req, &hdr);
2685 encode_sequence(xdr, &args->seq_args, &hdr);
2686 encode_putfh(xdr, args->fhandle, &hdr);
Trond Myklebust586f1c32016-11-15 15:03:33 -05002687 if (args->lr_args)
2688 encode_layoutreturn(xdr, args->lr_args, &hdr);
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05002689 if (args->bitmask)
2690 encode_getfattr(xdr, args->bitmask, &hdr);
Trond Myklebuste144cbc2012-04-28 16:05:03 -04002691 encode_delegreturn(xdr, args->stateid, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05002692 encode_nops(&hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693}
2694
2695/*
Trond Myklebust683b57b2006-06-09 09:34:22 -04002696 * Encode FS_LOCATIONS request
2697 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002698static void nfs4_xdr_enc_fs_locations(struct rpc_rqst *req,
2699 struct xdr_stream *xdr,
2700 struct nfs4_fs_locations_arg *args)
Trond Myklebust683b57b2006-06-09 09:34:22 -04002701{
Trond Myklebust683b57b2006-06-09 09:34:22 -04002702 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04002703 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Trond Myklebust683b57b2006-06-09 09:34:22 -04002704 };
Benny Halevy28f56692009-04-01 09:22:09 -04002705 uint32_t replen;
Trond Myklebust683b57b2006-06-09 09:34:22 -04002706
Chuck Lever9f06c712010-12-14 14:59:18 +00002707 encode_compound_hdr(xdr, req, &hdr);
2708 encode_sequence(xdr, &args->seq_args, &hdr);
Chuck Leverb03d7352013-10-17 14:12:50 -04002709 if (args->migration) {
2710 encode_putfh(xdr, args->fh, &hdr);
2711 replen = hdr.replen;
2712 encode_fs_locations(xdr, args->bitmask, &hdr);
2713 if (args->renew)
2714 encode_renew(xdr, args->clientid, &hdr);
2715 } else {
2716 encode_putfh(xdr, args->dir_fh, &hdr);
2717 encode_lookup(xdr, args->name, &hdr);
2718 replen = hdr.replen;
2719 encode_fs_locations(xdr, args->bitmask, &hdr);
2720 }
Andy Adamsoncf8cdbe2008-12-23 16:06:18 -05002721
Chuck Leverb03d7352013-10-17 14:12:50 -04002722 /* Set up reply kvec to capture returned fs_locations array. */
Benny Halevy28f56692009-04-01 09:22:09 -04002723 xdr_inline_pages(&req->rq_rcv_buf, replen << 2, &args->page,
Trond Myklebust683b57b2006-06-09 09:34:22 -04002724 0, PAGE_SIZE);
Andy Adamsond0179312008-12-23 16:06:17 -05002725 encode_nops(&hdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04002726}
2727
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00002728/*
2729 * Encode SECINFO request
2730 */
2731static void nfs4_xdr_enc_secinfo(struct rpc_rqst *req,
2732 struct xdr_stream *xdr,
2733 struct nfs4_secinfo_arg *args)
2734{
2735 struct compound_hdr hdr = {
2736 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2737 };
2738
2739 encode_compound_hdr(xdr, req, &hdr);
2740 encode_sequence(xdr, &args->seq_args, &hdr);
2741 encode_putfh(xdr, args->dir_fh, &hdr);
2742 encode_secinfo(xdr, args->name, &hdr);
2743 encode_nops(&hdr);
2744}
2745
Chuck Lever44c99932013-10-17 14:13:30 -04002746/*
2747 * Encode FSID_PRESENT request
2748 */
2749static void nfs4_xdr_enc_fsid_present(struct rpc_rqst *req,
2750 struct xdr_stream *xdr,
2751 struct nfs4_fsid_present_arg *args)
2752{
2753 struct compound_hdr hdr = {
2754 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2755 };
2756
2757 encode_compound_hdr(xdr, req, &hdr);
2758 encode_sequence(xdr, &args->seq_args, &hdr);
2759 encode_putfh(xdr, args->fh, &hdr);
2760 encode_getfh(xdr, &hdr);
2761 if (args->renew)
2762 encode_renew(xdr, args->clientid, &hdr);
2763 encode_nops(&hdr);
2764}
2765
Benny Halevy99fe60d2009-04-01 09:22:29 -04002766#if defined(CONFIG_NFS_V4_1)
2767/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002768 * BIND_CONN_TO_SESSION request
2769 */
2770static void nfs4_xdr_enc_bind_conn_to_session(struct rpc_rqst *req,
2771 struct xdr_stream *xdr,
Trond Myklebust71a097c2015-02-18 09:27:18 -08002772 struct nfs41_bind_conn_to_session_args *args)
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002773{
2774 struct compound_hdr hdr = {
Trond Myklebust71a097c2015-02-18 09:27:18 -08002775 .minorversion = args->client->cl_mvops->minor_version,
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002776 };
2777
2778 encode_compound_hdr(xdr, req, &hdr);
Trond Myklebust71a097c2015-02-18 09:27:18 -08002779 encode_bind_conn_to_session(xdr, args, &hdr);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04002780 encode_nops(&hdr);
2781}
2782
2783/*
Benny Halevy99fe60d2009-04-01 09:22:29 -04002784 * EXCHANGE_ID request
2785 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002786static void nfs4_xdr_enc_exchange_id(struct rpc_rqst *req,
2787 struct xdr_stream *xdr,
2788 struct nfs41_exchange_id_args *args)
Benny Halevy99fe60d2009-04-01 09:22:29 -04002789{
Benny Halevy99fe60d2009-04-01 09:22:29 -04002790 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002791 .minorversion = args->client->cl_mvops->minor_version,
Benny Halevy99fe60d2009-04-01 09:22:29 -04002792 };
2793
Chuck Lever9f06c712010-12-14 14:59:18 +00002794 encode_compound_hdr(xdr, req, &hdr);
2795 encode_exchange_id(xdr, args, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002796 encode_nops(&hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04002797}
Andy Adamson2050f0c2009-04-01 09:22:30 -04002798
2799/*
Andy Adamsonfc931582009-04-01 09:22:31 -04002800 * a CREATE_SESSION request
2801 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002802static void nfs4_xdr_enc_create_session(struct rpc_rqst *req,
2803 struct xdr_stream *xdr,
2804 struct nfs41_create_session_args *args)
Andy Adamsonfc931582009-04-01 09:22:31 -04002805{
Andy Adamsonfc931582009-04-01 09:22:31 -04002806 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002807 .minorversion = args->client->cl_mvops->minor_version,
Andy Adamsonfc931582009-04-01 09:22:31 -04002808 };
2809
Chuck Lever9f06c712010-12-14 14:59:18 +00002810 encode_compound_hdr(xdr, req, &hdr);
2811 encode_create_session(xdr, args, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002812 encode_nops(&hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04002813}
2814
2815/*
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002816 * a DESTROY_SESSION request
2817 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002818static void nfs4_xdr_enc_destroy_session(struct rpc_rqst *req,
2819 struct xdr_stream *xdr,
2820 struct nfs4_session *session)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002821{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002822 struct compound_hdr hdr = {
Trond Myklebusta4432342010-06-16 09:52:27 -04002823 .minorversion = session->clp->cl_mvops->minor_version,
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002824 };
2825
Chuck Lever9f06c712010-12-14 14:59:18 +00002826 encode_compound_hdr(xdr, req, &hdr);
2827 encode_destroy_session(xdr, session, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002828 encode_nops(&hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04002829}
2830
2831/*
Trond Myklebust66245532012-05-25 17:18:09 -04002832 * a DESTROY_CLIENTID request
2833 */
2834static void nfs4_xdr_enc_destroy_clientid(struct rpc_rqst *req,
2835 struct xdr_stream *xdr,
2836 struct nfs_client *clp)
2837{
2838 struct compound_hdr hdr = {
2839 .minorversion = clp->cl_mvops->minor_version,
2840 };
2841
2842 encode_compound_hdr(xdr, req, &hdr);
2843 encode_destroy_clientid(xdr, clp->cl_clientid, &hdr);
2844 encode_nops(&hdr);
2845}
2846
2847/*
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002848 * a SEQUENCE request
2849 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002850static void nfs4_xdr_enc_sequence(struct rpc_rqst *req, struct xdr_stream *xdr,
2851 struct nfs4_sequence_args *args)
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002852{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002853 struct compound_hdr hdr = {
2854 .minorversion = nfs4_xdr_minorversion(args),
2855 };
2856
Chuck Lever9f06c712010-12-14 14:59:18 +00002857 encode_compound_hdr(xdr, req, &hdr);
2858 encode_sequence(xdr, args, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002859 encode_nops(&hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04002860}
2861
2862/*
Andy Adamson2050f0c2009-04-01 09:22:30 -04002863 * a GET_LEASE_TIME request
2864 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002865static void nfs4_xdr_enc_get_lease_time(struct rpc_rqst *req,
2866 struct xdr_stream *xdr,
2867 struct nfs4_get_lease_time_args *args)
Andy Adamson2050f0c2009-04-01 09:22:30 -04002868{
Andy Adamson2050f0c2009-04-01 09:22:30 -04002869 struct compound_hdr hdr = {
2870 .minorversion = nfs4_xdr_minorversion(&args->la_seq_args),
2871 };
Fred Isamandae100c2011-07-30 20:52:37 -04002872 const u32 lease_bitmap[3] = { FATTR4_WORD0_LEASE_TIME };
Andy Adamson2050f0c2009-04-01 09:22:30 -04002873
Chuck Lever9f06c712010-12-14 14:59:18 +00002874 encode_compound_hdr(xdr, req, &hdr);
2875 encode_sequence(xdr, &args->la_seq_args, &hdr);
2876 encode_putrootfh(xdr, &hdr);
2877 encode_fsinfo(xdr, lease_bitmap, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002878 encode_nops(&hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04002879}
Ricardo Labiaga180197532009-12-05 16:08:40 -05002880
2881/*
2882 * a RECLAIM_COMPLETE request
2883 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002884static void nfs4_xdr_enc_reclaim_complete(struct rpc_rqst *req,
2885 struct xdr_stream *xdr,
2886 struct nfs41_reclaim_complete_args *args)
Ricardo Labiaga180197532009-12-05 16:08:40 -05002887{
Ricardo Labiaga180197532009-12-05 16:08:40 -05002888 struct compound_hdr hdr = {
2889 .minorversion = nfs4_xdr_minorversion(&args->seq_args)
2890 };
2891
Chuck Lever9f06c712010-12-14 14:59:18 +00002892 encode_compound_hdr(xdr, req, &hdr);
2893 encode_sequence(xdr, &args->seq_args, &hdr);
2894 encode_reclaim_complete(xdr, args, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002895 encode_nops(&hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05002896}
2897
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002898/*
2899 * Encode GETDEVICEINFO request
2900 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002901static void nfs4_xdr_enc_getdeviceinfo(struct rpc_rqst *req,
2902 struct xdr_stream *xdr,
2903 struct nfs4_getdeviceinfo_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002904{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002905 struct compound_hdr hdr = {
2906 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2907 };
2908
Chuck Lever9f06c712010-12-14 14:59:18 +00002909 encode_compound_hdr(xdr, req, &hdr);
2910 encode_sequence(xdr, &args->seq_args, &hdr);
2911 encode_getdeviceinfo(xdr, args, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002912
2913 /* set up reply kvec. Subtract notification bitmap max size (2)
2914 * so that notification bitmap is put in xdr_buf tail */
2915 xdr_inline_pages(&req->rq_rcv_buf, (hdr.replen - 2) << 2,
2916 args->pdev->pages, args->pdev->pgbase,
2917 args->pdev->pglen);
2918
2919 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002920}
2921
2922/*
2923 * Encode LAYOUTGET request
2924 */
Chuck Lever9f06c712010-12-14 14:59:18 +00002925static void nfs4_xdr_enc_layoutget(struct rpc_rqst *req,
2926 struct xdr_stream *xdr,
2927 struct nfs4_layoutget_args *args)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002928{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002929 struct compound_hdr hdr = {
2930 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2931 };
2932
Chuck Lever9f06c712010-12-14 14:59:18 +00002933 encode_compound_hdr(xdr, req, &hdr);
2934 encode_sequence(xdr, &args->seq_args, &hdr);
2935 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2936 encode_layoutget(xdr, args, &hdr);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04002937
2938 xdr_inline_pages(&req->rq_rcv_buf, hdr.replen << 2,
2939 args->layout.pages, 0, args->layout.pglen);
2940
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002941 encode_nops(&hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04002942}
Andy Adamson863a3c62011-03-23 13:27:54 +00002943
2944/*
2945 * Encode LAYOUTCOMMIT request
2946 */
Benny Halevycbe82602011-05-22 19:52:37 +03002947static void nfs4_xdr_enc_layoutcommit(struct rpc_rqst *req,
2948 struct xdr_stream *xdr,
2949 struct nfs4_layoutcommit_args *args)
Andy Adamson863a3c62011-03-23 13:27:54 +00002950{
Benny Halevyac7db722011-05-22 19:53:48 +03002951 struct nfs4_layoutcommit_data *data =
2952 container_of(args, struct nfs4_layoutcommit_data, args);
Andy Adamson863a3c62011-03-23 13:27:54 +00002953 struct compound_hdr hdr = {
2954 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2955 };
2956
2957 encode_compound_hdr(xdr, req, &hdr);
2958 encode_sequence(xdr, &args->seq_args, &hdr);
2959 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
Benny Halevyac7db722011-05-22 19:53:48 +03002960 encode_layoutcommit(xdr, data->args.inode, args, &hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002961 encode_getfattr(xdr, args->bitmask, &hdr);
2962 encode_nops(&hdr);
Benny Halevycbe82602011-05-22 19:52:37 +03002963}
2964
2965/*
2966 * Encode LAYOUTRETURN request
2967 */
2968static void nfs4_xdr_enc_layoutreturn(struct rpc_rqst *req,
2969 struct xdr_stream *xdr,
2970 struct nfs4_layoutreturn_args *args)
2971{
2972 struct compound_hdr hdr = {
2973 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2974 };
2975
2976 encode_compound_hdr(xdr, req, &hdr);
2977 encode_sequence(xdr, &args->seq_args, &hdr);
2978 encode_putfh(xdr, NFS_FH(args->inode), &hdr);
2979 encode_layoutreturn(xdr, args, &hdr);
2980 encode_nops(&hdr);
Andy Adamson863a3c62011-03-23 13:27:54 +00002981}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04002982
2983/*
2984 * Encode SECINFO_NO_NAME request
2985 */
2986static int nfs4_xdr_enc_secinfo_no_name(struct rpc_rqst *req,
2987 struct xdr_stream *xdr,
2988 struct nfs41_secinfo_no_name_args *args)
2989{
2990 struct compound_hdr hdr = {
2991 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
2992 };
2993
2994 encode_compound_hdr(xdr, req, &hdr);
2995 encode_sequence(xdr, &args->seq_args, &hdr);
2996 encode_putrootfh(xdr, &hdr);
2997 encode_secinfo_no_name(xdr, args, &hdr);
2998 encode_nops(&hdr);
2999 return 0;
3000}
Bryan Schumaker7d974792011-06-02 14:59:08 -04003001
3002/*
3003 * Encode TEST_STATEID request
3004 */
3005static void nfs4_xdr_enc_test_stateid(struct rpc_rqst *req,
3006 struct xdr_stream *xdr,
3007 struct nfs41_test_stateid_args *args)
3008{
3009 struct compound_hdr hdr = {
3010 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3011 };
3012
3013 encode_compound_hdr(xdr, req, &hdr);
3014 encode_sequence(xdr, &args->seq_args, &hdr);
3015 encode_test_stateid(xdr, args, &hdr);
3016 encode_nops(&hdr);
3017}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04003018
3019/*
3020 * Encode FREE_STATEID request
3021 */
3022static void nfs4_xdr_enc_free_stateid(struct rpc_rqst *req,
3023 struct xdr_stream *xdr,
3024 struct nfs41_free_stateid_args *args)
3025{
3026 struct compound_hdr hdr = {
3027 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
3028 };
3029
3030 encode_compound_hdr(xdr, req, &hdr);
3031 encode_sequence(xdr, &args->seq_args, &hdr);
3032 encode_free_stateid(xdr, args, &hdr);
3033 encode_nops(&hdr);
3034}
Benny Halevy99fe60d2009-04-01 09:22:29 -04003035#endif /* CONFIG_NFS_V4_1 */
3036
Benny Halevy686841b2009-08-14 17:19:48 +03003037static void print_overflow_msg(const char *func, const struct xdr_stream *xdr)
3038{
3039 dprintk("nfs: %s: prematurely hit end of receive buffer. "
3040 "Remaining buffer length is %tu words.\n",
3041 func, xdr->end - xdr->p);
3042}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
Trond Myklebust683b57b2006-06-09 09:34:22 -04003044static int decode_opaque_inline(struct xdr_stream *xdr, unsigned int *len, char **string)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045{
Trond Myklebust6da59ce2017-02-19 16:08:27 -05003046 ssize_t ret = xdr_stream_decode_opaque_inline(xdr, (void **)string,
3047 NFS4_OPAQUE_LIMIT);
3048 if (unlikely(ret < 0)) {
3049 if (ret == -EBADMSG)
3050 print_overflow_msg(__func__, xdr);
3051 return -EIO;
3052 }
3053 *len = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 return 0;
3055}
3056
3057static int decode_compound_hdr(struct xdr_stream *xdr, struct compound_hdr *hdr)
3058{
Al Viro8687b632006-10-19 23:28:48 -07003059 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
Benny Halevyc0eae662009-08-14 17:20:14 +03003061 p = xdr_inline_decode(xdr, 8);
3062 if (unlikely(!p))
3063 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003064 hdr->status = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003065 hdr->taglen = be32_to_cpup(p);
Andy Adamson6c0195a2008-12-23 16:06:15 -05003066
Benny Halevyc0eae662009-08-14 17:20:14 +03003067 p = xdr_inline_decode(xdr, hdr->taglen + 4);
3068 if (unlikely(!p))
3069 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 hdr->tag = (char *)p;
3071 p += XDR_QUADLEN(hdr->taglen);
Benny Halevycccddf42009-08-14 17:20:19 +03003072 hdr->nops = be32_to_cpup(p);
Benny Halevyaadf6152008-12-23 16:06:13 -05003073 if (unlikely(hdr->nops < 1))
3074 return nfs4_stat_to_errno(hdr->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003076out_overflow:
3077 print_overflow_msg(__func__, xdr);
3078 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079}
3080
Trond Myklebustc7848f62013-12-04 17:39:23 -05003081static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
3082 int *nfs_retval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083{
Al Viro8687b632006-10-19 23:28:48 -07003084 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 uint32_t opnum;
3086 int32_t nfserr;
3087
Benny Halevyc0eae662009-08-14 17:20:14 +03003088 p = xdr_inline_decode(xdr, 8);
3089 if (unlikely(!p))
3090 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003091 opnum = be32_to_cpup(p++);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003092 if (unlikely(opnum != expected))
3093 goto out_bad_operation;
Benny Halevycccddf42009-08-14 17:20:19 +03003094 nfserr = be32_to_cpup(p);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003095 if (nfserr == NFS_OK)
3096 *nfs_retval = 0;
3097 else
3098 *nfs_retval = nfs4_stat_to_errno(nfserr);
3099 return true;
3100out_bad_operation:
3101 dprintk("nfs: Server returned operation"
3102 " %d but we issued a request for %d\n",
3103 opnum, expected);
3104 *nfs_retval = -EREMOTEIO;
3105 return false;
Benny Halevyc0eae662009-08-14 17:20:14 +03003106out_overflow:
3107 print_overflow_msg(__func__, xdr);
Trond Myklebustc7848f62013-12-04 17:39:23 -05003108 *nfs_retval = -EIO;
3109 return false;
3110}
3111
3112static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
3113{
3114 int retval;
3115
3116 __decode_op_hdr(xdr, expected, &retval);
3117 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118}
3119
3120/* Dummy routine */
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05003121static int decode_ace(struct xdr_stream *xdr, void *ace)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122{
Al Viro8687b632006-10-19 23:28:48 -07003123 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003124 unsigned int strlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 char *str;
3126
Benny Halevyc0eae662009-08-14 17:20:14 +03003127 p = xdr_inline_decode(xdr, 12);
3128 if (likely(p))
3129 return decode_opaque_inline(xdr, &strlen, &str);
3130 print_overflow_msg(__func__, xdr);
3131 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132}
3133
3134static int decode_attr_bitmap(struct xdr_stream *xdr, uint32_t *bitmap)
3135{
Al Viro8687b632006-10-19 23:28:48 -07003136 uint32_t bmlen;
3137 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
Benny Halevyc0eae662009-08-14 17:20:14 +03003139 p = xdr_inline_decode(xdr, 4);
3140 if (unlikely(!p))
3141 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003142 bmlen = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143
Fred Isamandae100c2011-07-30 20:52:37 -04003144 bitmap[0] = bitmap[1] = bitmap[2] = 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003145 p = xdr_inline_decode(xdr, (bmlen << 2));
3146 if (unlikely(!p))
3147 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 if (bmlen > 0) {
Benny Halevy6f723f72009-08-14 17:19:37 +03003149 bitmap[0] = be32_to_cpup(p++);
Fred Isamandae100c2011-07-30 20:52:37 -04003150 if (bmlen > 1) {
3151 bitmap[1] = be32_to_cpup(p++);
3152 if (bmlen > 2)
3153 bitmap[2] = be32_to_cpup(p);
3154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 }
3156 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003157out_overflow:
3158 print_overflow_msg(__func__, xdr);
3159 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160}
3161
Trond Myklebust256e48b2012-06-21 11:18:13 -04003162static int decode_attr_length(struct xdr_stream *xdr, uint32_t *attrlen, unsigned int *savep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163{
Al Viro8687b632006-10-19 23:28:48 -07003164 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
Benny Halevyc0eae662009-08-14 17:20:14 +03003166 p = xdr_inline_decode(xdr, 4);
3167 if (unlikely(!p))
3168 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003169 *attrlen = be32_to_cpup(p);
Trond Myklebust256e48b2012-06-21 11:18:13 -04003170 *savep = xdr_stream_pos(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003172out_overflow:
3173 print_overflow_msg(__func__, xdr);
3174 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175}
3176
3177static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *bitmask)
3178{
3179 if (likely(bitmap[0] & FATTR4_WORD0_SUPPORTED_ATTRS)) {
Roman Borisov3388bff2010-10-13 16:54:51 +04003180 int ret;
3181 ret = decode_attr_bitmap(xdr, bitmask);
3182 if (unlikely(ret < 0))
3183 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
3185 } else
Fred Isamandae100c2011-07-30 20:52:37 -04003186 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3187 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3188 bitmask[0], bitmask[1], bitmask[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 return 0;
3190}
3191
3192static int decode_attr_type(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *type)
3193{
Al Viro8687b632006-10-19 23:28:48 -07003194 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003195 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
3197 *type = 0;
3198 if (unlikely(bitmap[0] & (FATTR4_WORD0_TYPE - 1U)))
3199 return -EIO;
3200 if (likely(bitmap[0] & FATTR4_WORD0_TYPE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003201 p = xdr_inline_decode(xdr, 4);
3202 if (unlikely(!p))
3203 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003204 *type = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 if (*type < NF4REG || *type > NF4NAMEDATTR) {
Harvey Harrison3110ff82008-05-02 13:42:44 -07003206 dprintk("%s: bad type %d\n", __func__, *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 return -EIO;
3208 }
3209 bitmap[0] &= ~FATTR4_WORD0_TYPE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003210 ret = NFS_ATTR_FATTR_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 }
Trond Myklebustbca79472009-03-11 14:10:26 -04003212 dprintk("%s: type=0%o\n", __func__, nfs_type2fmt[*type]);
Trond Myklebust409924e2009-03-11 14:10:27 -04003213 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003214out_overflow:
3215 print_overflow_msg(__func__, xdr);
3216 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217}
3218
Chuck Lever264e6352012-03-01 17:02:05 -05003219static int decode_attr_fh_expire_type(struct xdr_stream *xdr,
3220 uint32_t *bitmap, uint32_t *type)
3221{
3222 __be32 *p;
3223
3224 *type = 0;
3225 if (unlikely(bitmap[0] & (FATTR4_WORD0_FH_EXPIRE_TYPE - 1U)))
3226 return -EIO;
3227 if (likely(bitmap[0] & FATTR4_WORD0_FH_EXPIRE_TYPE)) {
3228 p = xdr_inline_decode(xdr, 4);
3229 if (unlikely(!p))
3230 goto out_overflow;
3231 *type = be32_to_cpup(p);
3232 bitmap[0] &= ~FATTR4_WORD0_FH_EXPIRE_TYPE;
3233 }
3234 dprintk("%s: expire type=0x%x\n", __func__, *type);
3235 return 0;
3236out_overflow:
3237 print_overflow_msg(__func__, xdr);
3238 return -EIO;
3239}
3240
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241static int decode_attr_change(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *change)
3242{
Al Viro8687b632006-10-19 23:28:48 -07003243 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003244 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
3246 *change = 0;
3247 if (unlikely(bitmap[0] & (FATTR4_WORD0_CHANGE - 1U)))
3248 return -EIO;
3249 if (likely(bitmap[0] & FATTR4_WORD0_CHANGE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003250 p = xdr_inline_decode(xdr, 8);
3251 if (unlikely(!p))
3252 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003253 xdr_decode_hyper(p, change);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 bitmap[0] &= ~FATTR4_WORD0_CHANGE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003255 ret = NFS_ATTR_FATTR_CHANGE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003257 dprintk("%s: change attribute=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 (unsigned long long)*change);
Trond Myklebust409924e2009-03-11 14:10:27 -04003259 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003260out_overflow:
3261 print_overflow_msg(__func__, xdr);
3262 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263}
3264
3265static int decode_attr_size(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *size)
3266{
Al Viro8687b632006-10-19 23:28:48 -07003267 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003268 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269
3270 *size = 0;
3271 if (unlikely(bitmap[0] & (FATTR4_WORD0_SIZE - 1U)))
3272 return -EIO;
3273 if (likely(bitmap[0] & FATTR4_WORD0_SIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003274 p = xdr_inline_decode(xdr, 8);
3275 if (unlikely(!p))
3276 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003277 xdr_decode_hyper(p, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 bitmap[0] &= ~FATTR4_WORD0_SIZE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003279 ret = NFS_ATTR_FATTR_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003281 dprintk("%s: file size=%Lu\n", __func__, (unsigned long long)*size);
Trond Myklebust409924e2009-03-11 14:10:27 -04003282 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003283out_overflow:
3284 print_overflow_msg(__func__, xdr);
3285 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286}
3287
3288static int decode_attr_link_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3289{
Al Viro8687b632006-10-19 23:28:48 -07003290 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
3292 *res = 0;
3293 if (unlikely(bitmap[0] & (FATTR4_WORD0_LINK_SUPPORT - 1U)))
3294 return -EIO;
3295 if (likely(bitmap[0] & FATTR4_WORD0_LINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003296 p = xdr_inline_decode(xdr, 4);
3297 if (unlikely(!p))
3298 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003299 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 bitmap[0] &= ~FATTR4_WORD0_LINK_SUPPORT;
3301 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003302 dprintk("%s: link support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003304out_overflow:
3305 print_overflow_msg(__func__, xdr);
3306 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307}
3308
3309static int decode_attr_symlink_support(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3310{
Al Viro8687b632006-10-19 23:28:48 -07003311 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312
3313 *res = 0;
3314 if (unlikely(bitmap[0] & (FATTR4_WORD0_SYMLINK_SUPPORT - 1U)))
3315 return -EIO;
3316 if (likely(bitmap[0] & FATTR4_WORD0_SYMLINK_SUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003317 p = xdr_inline_decode(xdr, 4);
3318 if (unlikely(!p))
3319 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003320 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 bitmap[0] &= ~FATTR4_WORD0_SYMLINK_SUPPORT;
3322 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003323 dprintk("%s: symlink support=%s\n", __func__, *res == 0 ? "false" : "true");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003325out_overflow:
3326 print_overflow_msg(__func__, xdr);
3327 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328}
3329
Trond Myklebust8b4bdcf2006-06-09 09:34:19 -04003330static int decode_attr_fsid(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fsid *fsid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331{
Al Viro8687b632006-10-19 23:28:48 -07003332 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003333 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334
3335 fsid->major = 0;
3336 fsid->minor = 0;
3337 if (unlikely(bitmap[0] & (FATTR4_WORD0_FSID - 1U)))
3338 return -EIO;
3339 if (likely(bitmap[0] & FATTR4_WORD0_FSID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003340 p = xdr_inline_decode(xdr, 16);
3341 if (unlikely(!p))
3342 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03003343 p = xdr_decode_hyper(p, &fsid->major);
Benny Halevycccddf42009-08-14 17:20:19 +03003344 xdr_decode_hyper(p, &fsid->minor);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 bitmap[0] &= ~FATTR4_WORD0_FSID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003346 ret = NFS_ATTR_FATTR_FSID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003348 dprintk("%s: fsid=(0x%Lx/0x%Lx)\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 (unsigned long long)fsid->major,
3350 (unsigned long long)fsid->minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003351 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003352out_overflow:
3353 print_overflow_msg(__func__, xdr);
3354 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355}
3356
3357static int decode_attr_lease_time(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3358{
Al Viro8687b632006-10-19 23:28:48 -07003359 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
3361 *res = 60;
3362 if (unlikely(bitmap[0] & (FATTR4_WORD0_LEASE_TIME - 1U)))
3363 return -EIO;
3364 if (likely(bitmap[0] & FATTR4_WORD0_LEASE_TIME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003365 p = xdr_inline_decode(xdr, 4);
3366 if (unlikely(!p))
3367 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003368 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 bitmap[0] &= ~FATTR4_WORD0_LEASE_TIME;
3370 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003371 dprintk("%s: file size=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003373out_overflow:
3374 print_overflow_msg(__func__, xdr);
3375 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376}
3377
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003378static int decode_attr_error(struct xdr_stream *xdr, uint32_t *bitmap, int32_t *res)
Bryan Schumakerae42c702010-10-21 16:33:17 -04003379{
3380 __be32 *p;
3381
3382 if (unlikely(bitmap[0] & (FATTR4_WORD0_RDATTR_ERROR - 1U)))
3383 return -EIO;
3384 if (likely(bitmap[0] & FATTR4_WORD0_RDATTR_ERROR)) {
3385 p = xdr_inline_decode(xdr, 4);
3386 if (unlikely(!p))
3387 goto out_overflow;
3388 bitmap[0] &= ~FATTR4_WORD0_RDATTR_ERROR;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04003389 *res = -be32_to_cpup(p);
Bryan Schumakerae42c702010-10-21 16:33:17 -04003390 }
3391 return 0;
3392out_overflow:
3393 print_overflow_msg(__func__, xdr);
3394 return -EIO;
3395}
3396
Kinglong Mee8c612822015-08-26 21:12:58 +08003397static int decode_attr_exclcreat_supported(struct xdr_stream *xdr,
3398 uint32_t *bitmap, uint32_t *bitmask)
3399{
3400 if (likely(bitmap[2] & FATTR4_WORD2_SUPPATTR_EXCLCREAT)) {
3401 int ret;
3402 ret = decode_attr_bitmap(xdr, bitmask);
3403 if (unlikely(ret < 0))
3404 return ret;
3405 bitmap[2] &= ~FATTR4_WORD2_SUPPATTR_EXCLCREAT;
3406 } else
3407 bitmask[0] = bitmask[1] = bitmask[2] = 0;
3408 dprintk("%s: bitmask=%08x:%08x:%08x\n", __func__,
3409 bitmask[0], bitmask[1], bitmask[2]);
3410 return 0;
3411}
3412
Bryan Schumakerae42c702010-10-21 16:33:17 -04003413static int decode_attr_filehandle(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs_fh *fh)
3414{
3415 __be32 *p;
3416 int len;
3417
Trond Myklebust7ad07352010-10-23 15:34:20 -04003418 if (fh != NULL)
3419 memset(fh, 0, sizeof(*fh));
Bryan Schumakerae42c702010-10-21 16:33:17 -04003420
3421 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEHANDLE - 1U)))
3422 return -EIO;
3423 if (likely(bitmap[0] & FATTR4_WORD0_FILEHANDLE)) {
3424 p = xdr_inline_decode(xdr, 4);
3425 if (unlikely(!p))
3426 goto out_overflow;
3427 len = be32_to_cpup(p);
3428 if (len > NFS4_FHSIZE)
3429 return -EIO;
Bryan Schumakerae42c702010-10-21 16:33:17 -04003430 p = xdr_inline_decode(xdr, len);
3431 if (unlikely(!p))
3432 goto out_overflow;
Trond Myklebust7ad07352010-10-23 15:34:20 -04003433 if (fh != NULL) {
3434 memcpy(fh->data, p, len);
3435 fh->size = len;
3436 }
Bryan Schumakerae42c702010-10-21 16:33:17 -04003437 bitmap[0] &= ~FATTR4_WORD0_FILEHANDLE;
3438 }
3439 return 0;
3440out_overflow:
3441 print_overflow_msg(__func__, xdr);
3442 return -EIO;
3443}
3444
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445static int decode_attr_aclsupport(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3446{
Al Viro8687b632006-10-19 23:28:48 -07003447 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448
Malahal Nainenia1800ac2014-01-27 15:31:09 -06003449 *res = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACLSUPPORT - 1U)))
3451 return -EIO;
3452 if (likely(bitmap[0] & FATTR4_WORD0_ACLSUPPORT)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003453 p = xdr_inline_decode(xdr, 4);
3454 if (unlikely(!p))
3455 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003456 *res = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 bitmap[0] &= ~FATTR4_WORD0_ACLSUPPORT;
3458 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003459 dprintk("%s: ACLs supported=%u\n", __func__, (unsigned int)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003461out_overflow:
3462 print_overflow_msg(__func__, xdr);
3463 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464}
3465
3466static int decode_attr_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3467{
Al Viro8687b632006-10-19 23:28:48 -07003468 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003469 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
3471 *fileid = 0;
3472 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILEID - 1U)))
3473 return -EIO;
3474 if (likely(bitmap[0] & FATTR4_WORD0_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003475 p = xdr_inline_decode(xdr, 8);
3476 if (unlikely(!p))
3477 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003478 xdr_decode_hyper(p, fileid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 bitmap[0] &= ~FATTR4_WORD0_FILEID;
Trond Myklebust409924e2009-03-11 14:10:27 -04003480 ret = NFS_ATTR_FATTR_FILEID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003482 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003483 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003484out_overflow:
3485 print_overflow_msg(__func__, xdr);
3486 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003487}
3488
Manoj Naik99baf622006-06-09 09:34:24 -04003489static int decode_attr_mounted_on_fileid(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *fileid)
3490{
Al Viro8687b632006-10-19 23:28:48 -07003491 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003492 int ret = 0;
Manoj Naik99baf622006-06-09 09:34:24 -04003493
3494 *fileid = 0;
3495 if (unlikely(bitmap[1] & (FATTR4_WORD1_MOUNTED_ON_FILEID - 1U)))
3496 return -EIO;
3497 if (likely(bitmap[1] & FATTR4_WORD1_MOUNTED_ON_FILEID)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003498 p = xdr_inline_decode(xdr, 8);
3499 if (unlikely(!p))
3500 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003501 xdr_decode_hyper(p, fileid);
Manoj Naik99baf622006-06-09 09:34:24 -04003502 bitmap[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
Trond Myklebust28331a42011-04-27 13:47:52 -04003503 ret = NFS_ATTR_FATTR_MOUNTED_ON_FILEID;
Manoj Naik99baf622006-06-09 09:34:24 -04003504 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003505 dprintk("%s: fileid=%Lu\n", __func__, (unsigned long long)*fileid);
Trond Myklebust409924e2009-03-11 14:10:27 -04003506 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003507out_overflow:
3508 print_overflow_msg(__func__, xdr);
3509 return -EIO;
Manoj Naik99baf622006-06-09 09:34:24 -04003510}
3511
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512static int decode_attr_files_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3513{
Al Viro8687b632006-10-19 23:28:48 -07003514 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515 int status = 0;
3516
3517 *res = 0;
3518 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_AVAIL - 1U)))
3519 return -EIO;
3520 if (likely(bitmap[0] & FATTR4_WORD0_FILES_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003521 p = xdr_inline_decode(xdr, 8);
3522 if (unlikely(!p))
3523 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003524 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 bitmap[0] &= ~FATTR4_WORD0_FILES_AVAIL;
3526 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003527 dprintk("%s: files avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003529out_overflow:
3530 print_overflow_msg(__func__, xdr);
3531 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532}
3533
3534static int decode_attr_files_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3535{
Al Viro8687b632006-10-19 23:28:48 -07003536 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 int status = 0;
3538
3539 *res = 0;
3540 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_FREE - 1U)))
3541 return -EIO;
3542 if (likely(bitmap[0] & FATTR4_WORD0_FILES_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003543 p = xdr_inline_decode(xdr, 8);
3544 if (unlikely(!p))
3545 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003546 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 bitmap[0] &= ~FATTR4_WORD0_FILES_FREE;
3548 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003549 dprintk("%s: files free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003551out_overflow:
3552 print_overflow_msg(__func__, xdr);
3553 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554}
3555
3556static int decode_attr_files_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3557{
Al Viro8687b632006-10-19 23:28:48 -07003558 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 int status = 0;
3560
3561 *res = 0;
3562 if (unlikely(bitmap[0] & (FATTR4_WORD0_FILES_TOTAL - 1U)))
3563 return -EIO;
3564 if (likely(bitmap[0] & FATTR4_WORD0_FILES_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003565 p = xdr_inline_decode(xdr, 8);
3566 if (unlikely(!p))
3567 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003568 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 bitmap[0] &= ~FATTR4_WORD0_FILES_TOTAL;
3570 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003571 dprintk("%s: files total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003573out_overflow:
3574 print_overflow_msg(__func__, xdr);
3575 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576}
3577
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003578static int decode_pathname(struct xdr_stream *xdr, struct nfs4_pathname *path)
3579{
Chuck Lever464ad6b2007-10-26 13:32:08 -04003580 u32 n;
Al Viro8687b632006-10-19 23:28:48 -07003581 __be32 *p;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003582 int status = 0;
3583
Benny Halevyc0eae662009-08-14 17:20:14 +03003584 p = xdr_inline_decode(xdr, 4);
3585 if (unlikely(!p))
3586 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003587 n = be32_to_cpup(p);
Andy Adamson33a43f22006-06-09 09:34:30 -04003588 if (n == 0)
3589 goto root_path;
Chuck Lever02a29762012-03-01 17:00:31 -05003590 dprintk("pathname4: ");
Trond Myklebust809b4262013-03-27 11:54:45 -04003591 if (n > NFS4_PATHNAME_MAXCOMPONENTS) {
3592 dprintk("cannot parse %d components in path\n", n);
3593 goto out_eio;
3594 }
3595 for (path->ncomponents = 0; path->ncomponents < n; path->ncomponents++) {
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003596 struct nfs4_string *component = &path->components[path->ncomponents];
3597 status = decode_opaque_inline(xdr, &component->len, &component->data);
3598 if (unlikely(status != 0))
3599 goto out_eio;
Trond Myklebust95a13f72012-03-14 21:55:01 -04003600 ifdebug (XDR)
Chuck Lever02a29762012-03-01 17:00:31 -05003601 pr_cont("%s%.*s ",
3602 (path->ncomponents != n ? "/ " : ""),
3603 component->len, component->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003604 }
3605out:
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003606 return status;
Andy Adamson33a43f22006-06-09 09:34:30 -04003607root_path:
3608/* a root pathname is sent as a zero component4 */
3609 path->ncomponents = 1;
3610 path->components[0].len=0;
3611 path->components[0].data=NULL;
Chuck Lever02a29762012-03-01 17:00:31 -05003612 dprintk("pathname4: /\n");
Andy Adamson33a43f22006-06-09 09:34:30 -04003613 goto out;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003614out_eio:
3615 dprintk(" status %d", status);
3616 status = -EIO;
3617 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003618out_overflow:
3619 print_overflow_msg(__func__, xdr);
3620 return -EIO;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003621}
3622
3623static int decode_attr_fs_locations(struct xdr_stream *xdr, uint32_t *bitmap, struct nfs4_fs_locations *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04003624{
3625 int n;
Al Viro8687b632006-10-19 23:28:48 -07003626 __be32 *p;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003627 int status = -EIO;
3628
3629 if (unlikely(bitmap[0] & (FATTR4_WORD0_FS_LOCATIONS -1U)))
3630 goto out;
3631 status = 0;
3632 if (unlikely(!(bitmap[0] & FATTR4_WORD0_FS_LOCATIONS)))
3633 goto out;
Kinglong Meef54423a2015-11-18 10:39:26 +08003634 bitmap[0] &= ~FATTR4_WORD0_FS_LOCATIONS;
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05003635 status = -EIO;
3636 /* Ignore borken servers that return unrequested attrs */
3637 if (unlikely(res == NULL))
3638 goto out;
Chuck Lever02a29762012-03-01 17:00:31 -05003639 dprintk("%s: fsroot:\n", __func__);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003640 status = decode_pathname(xdr, &res->fs_path);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003641 if (unlikely(status != 0))
3642 goto out;
Benny Halevyc0eae662009-08-14 17:20:14 +03003643 p = xdr_inline_decode(xdr, 4);
3644 if (unlikely(!p))
3645 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003646 n = be32_to_cpup(p);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003647 if (n <= 0)
3648 goto out_eio;
Trond Myklebust809b4262013-03-27 11:54:45 -04003649 for (res->nlocations = 0; res->nlocations < n; res->nlocations++) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003650 u32 m;
Trond Myklebust809b4262013-03-27 11:54:45 -04003651 struct nfs4_fs_location *loc;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003652
Trond Myklebust809b4262013-03-27 11:54:45 -04003653 if (res->nlocations == NFS4_FS_LOCATIONS_MAXENTRIES)
3654 break;
3655 loc = &res->locations[res->nlocations];
Benny Halevyc0eae662009-08-14 17:20:14 +03003656 p = xdr_inline_decode(xdr, 4);
3657 if (unlikely(!p))
3658 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003659 m = be32_to_cpup(p);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003660
Chuck Lever02a29762012-03-01 17:00:31 -05003661 dprintk("%s: servers:\n", __func__);
Trond Myklebust809b4262013-03-27 11:54:45 -04003662 for (loc->nservers = 0; loc->nservers < m; loc->nservers++) {
3663 struct nfs4_string *server;
3664
3665 if (loc->nservers == NFS4_FS_LOCATION_MAXSERVERS) {
Chuck Lever464ad6b2007-10-26 13:32:08 -04003666 unsigned int i;
3667 dprintk("%s: using first %u of %u servers "
3668 "returned for location %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07003669 __func__,
Chuck Lever464ad6b2007-10-26 13:32:08 -04003670 NFS4_FS_LOCATION_MAXSERVERS,
3671 m, res->nlocations);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003672 for (i = loc->nservers; i < m; i++) {
Trond Myklebust2e42c3e2007-05-14 17:20:41 -04003673 unsigned int len;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003674 char *data;
3675 status = decode_opaque_inline(xdr, &len, &data);
3676 if (unlikely(status != 0))
3677 goto out_eio;
3678 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003679 break;
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003680 }
Trond Myklebust809b4262013-03-27 11:54:45 -04003681 server = &loc->servers[loc->nservers];
3682 status = decode_opaque_inline(xdr, &server->len, &server->data);
3683 if (unlikely(status != 0))
3684 goto out_eio;
3685 dprintk("%s ", server->data);
Manoj Naik7aaa0b32006-06-09 09:34:23 -04003686 }
3687 status = decode_pathname(xdr, &loc->rootpath);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003688 if (unlikely(status != 0))
3689 goto out_eio;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003690 }
Trond Myklebust409924e2009-03-11 14:10:27 -04003691 if (res->nlocations != 0)
Chuck Lever81934dd2012-03-01 17:01:57 -05003692 status = NFS_ATTR_FATTR_V4_LOCATIONS;
Trond Myklebust683b57b2006-06-09 09:34:22 -04003693out:
Harvey Harrison3110ff82008-05-02 13:42:44 -07003694 dprintk("%s: fs_locations done, error = %d\n", __func__, status);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003695 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003696out_overflow:
3697 print_overflow_msg(__func__, xdr);
Trond Myklebust683b57b2006-06-09 09:34:22 -04003698out_eio:
3699 status = -EIO;
3700 goto out;
3701}
3702
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703static int decode_attr_maxfilesize(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3704{
Al Viro8687b632006-10-19 23:28:48 -07003705 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 int status = 0;
3707
3708 *res = 0;
3709 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXFILESIZE - 1U)))
3710 return -EIO;
3711 if (likely(bitmap[0] & FATTR4_WORD0_MAXFILESIZE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003712 p = xdr_inline_decode(xdr, 8);
3713 if (unlikely(!p))
3714 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003715 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003716 bitmap[0] &= ~FATTR4_WORD0_MAXFILESIZE;
3717 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003718 dprintk("%s: maxfilesize=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003720out_overflow:
3721 print_overflow_msg(__func__, xdr);
3722 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723}
3724
3725static int decode_attr_maxlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxlink)
3726{
Al Viro8687b632006-10-19 23:28:48 -07003727 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728 int status = 0;
3729
3730 *maxlink = 1;
3731 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXLINK - 1U)))
3732 return -EIO;
3733 if (likely(bitmap[0] & FATTR4_WORD0_MAXLINK)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003734 p = xdr_inline_decode(xdr, 4);
3735 if (unlikely(!p))
3736 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003737 *maxlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 bitmap[0] &= ~FATTR4_WORD0_MAXLINK;
3739 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003740 dprintk("%s: maxlink=%u\n", __func__, *maxlink);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003742out_overflow:
3743 print_overflow_msg(__func__, xdr);
3744 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745}
3746
3747static int decode_attr_maxname(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *maxname)
3748{
Al Viro8687b632006-10-19 23:28:48 -07003749 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750 int status = 0;
3751
3752 *maxname = 1024;
3753 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXNAME - 1U)))
3754 return -EIO;
3755 if (likely(bitmap[0] & FATTR4_WORD0_MAXNAME)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003756 p = xdr_inline_decode(xdr, 4);
3757 if (unlikely(!p))
3758 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003759 *maxname = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003760 bitmap[0] &= ~FATTR4_WORD0_MAXNAME;
3761 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003762 dprintk("%s: maxname=%u\n", __func__, *maxname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003764out_overflow:
3765 print_overflow_msg(__func__, xdr);
3766 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767}
3768
3769static int decode_attr_maxread(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3770{
Al Viro8687b632006-10-19 23:28:48 -07003771 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 int status = 0;
3773
3774 *res = 1024;
3775 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXREAD - 1U)))
3776 return -EIO;
3777 if (likely(bitmap[0] & FATTR4_WORD0_MAXREAD)) {
3778 uint64_t maxread;
Benny Halevyc0eae662009-08-14 17:20:14 +03003779 p = xdr_inline_decode(xdr, 8);
3780 if (unlikely(!p))
3781 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003782 xdr_decode_hyper(p, &maxread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 if (maxread > 0x7FFFFFFF)
3784 maxread = 0x7FFFFFFF;
3785 *res = (uint32_t)maxread;
3786 bitmap[0] &= ~FATTR4_WORD0_MAXREAD;
3787 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003788 dprintk("%s: maxread=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003790out_overflow:
3791 print_overflow_msg(__func__, xdr);
3792 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003793}
3794
3795static int decode_attr_maxwrite(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *res)
3796{
Al Viro8687b632006-10-19 23:28:48 -07003797 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 int status = 0;
3799
3800 *res = 1024;
3801 if (unlikely(bitmap[0] & (FATTR4_WORD0_MAXWRITE - 1U)))
3802 return -EIO;
3803 if (likely(bitmap[0] & FATTR4_WORD0_MAXWRITE)) {
3804 uint64_t maxwrite;
Benny Halevyc0eae662009-08-14 17:20:14 +03003805 p = xdr_inline_decode(xdr, 8);
3806 if (unlikely(!p))
3807 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003808 xdr_decode_hyper(p, &maxwrite);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809 if (maxwrite > 0x7FFFFFFF)
3810 maxwrite = 0x7FFFFFFF;
3811 *res = (uint32_t)maxwrite;
3812 bitmap[0] &= ~FATTR4_WORD0_MAXWRITE;
3813 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003814 dprintk("%s: maxwrite=%lu\n", __func__, (unsigned long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003816out_overflow:
3817 print_overflow_msg(__func__, xdr);
3818 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819}
3820
Trond Myklebustbca79472009-03-11 14:10:26 -04003821static int decode_attr_mode(struct xdr_stream *xdr, uint32_t *bitmap, umode_t *mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822{
Trond Myklebustbca79472009-03-11 14:10:26 -04003823 uint32_t tmp;
Al Viro8687b632006-10-19 23:28:48 -07003824 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003825 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826
3827 *mode = 0;
3828 if (unlikely(bitmap[1] & (FATTR4_WORD1_MODE - 1U)))
3829 return -EIO;
3830 if (likely(bitmap[1] & FATTR4_WORD1_MODE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003831 p = xdr_inline_decode(xdr, 4);
3832 if (unlikely(!p))
3833 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003834 tmp = be32_to_cpup(p);
Trond Myklebustbca79472009-03-11 14:10:26 -04003835 *mode = tmp & ~S_IFMT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836 bitmap[1] &= ~FATTR4_WORD1_MODE;
Trond Myklebust409924e2009-03-11 14:10:27 -04003837 ret = NFS_ATTR_FATTR_MODE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003839 dprintk("%s: file mode=0%o\n", __func__, (unsigned int)*mode);
Trond Myklebust409924e2009-03-11 14:10:27 -04003840 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003841out_overflow:
3842 print_overflow_msg(__func__, xdr);
3843 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844}
3845
3846static int decode_attr_nlink(struct xdr_stream *xdr, uint32_t *bitmap, uint32_t *nlink)
3847{
Al Viro8687b632006-10-19 23:28:48 -07003848 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003849 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850
3851 *nlink = 1;
3852 if (unlikely(bitmap[1] & (FATTR4_WORD1_NUMLINKS - 1U)))
3853 return -EIO;
3854 if (likely(bitmap[1] & FATTR4_WORD1_NUMLINKS)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003855 p = xdr_inline_decode(xdr, 4);
3856 if (unlikely(!p))
3857 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003858 *nlink = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 bitmap[1] &= ~FATTR4_WORD1_NUMLINKS;
Trond Myklebust409924e2009-03-11 14:10:27 -04003860 ret = NFS_ATTR_FATTR_NLINK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003862 dprintk("%s: nlink=%u\n", __func__, (unsigned int)*nlink);
Trond Myklebust409924e2009-03-11 14:10:27 -04003863 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003864out_overflow:
3865 print_overflow_msg(__func__, xdr);
3866 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003867}
3868
Trond Myklebust686a8162017-02-19 16:08:32 -05003869static ssize_t decode_nfs4_string(struct xdr_stream *xdr,
3870 struct nfs4_string *name, gfp_t gfp_flags)
3871{
3872 ssize_t ret;
3873
3874 ret = xdr_stream_decode_string_dup(xdr, &name->data,
3875 XDR_MAX_NETOBJ, gfp_flags);
3876 name->len = 0;
3877 if (ret > 0)
3878 name->len = ret;
3879 return ret;
3880}
3881
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003882static int decode_attr_owner(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003883 const struct nfs_server *server, kuid_t *uid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003884 struct nfs4_string *owner_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885{
Trond Myklebust686a8162017-02-19 16:08:32 -05003886 ssize_t len;
3887 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888
Eric W. Biedermane5782072013-02-01 14:22:02 -08003889 *uid = make_kuid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER - 1U)))
3891 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003892 if (!(bitmap[1] & FATTR4_WORD1_OWNER))
3893 return 0;
3894 bitmap[1] &= ~FATTR4_WORD1_OWNER;
3895
3896 if (owner_name != NULL) {
3897 len = decode_nfs4_string(xdr, owner_name, GFP_NOWAIT);
3898 if (len <= 0)
3899 goto out;
3900 dprintk("%s: name=%s\n", __func__, owner_name->data);
3901 return NFS_ATTR_FATTR_OWNER_NAME;
3902 } else {
3903 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3904 XDR_MAX_NETOBJ);
3905 if (len <= 0 || nfs_map_name_to_uid(server, p, len, uid) != 0)
3906 goto out;
3907 dprintk("%s: uid=%d\n", __func__, (int)from_kuid(&init_user_ns, *uid));
3908 return NFS_ATTR_FATTR_OWNER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003910out:
3911 if (len != -EBADMSG)
3912 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003913 print_overflow_msg(__func__, xdr);
3914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003915}
3916
Trond Myklebust80e52ac2009-08-09 15:06:19 -04003917static int decode_attr_group(struct xdr_stream *xdr, uint32_t *bitmap,
Eric W. Biedermane5782072013-02-01 14:22:02 -08003918 const struct nfs_server *server, kgid_t *gid,
Trond Myklebust6926afd2012-01-07 13:22:46 -05003919 struct nfs4_string *group_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003920{
Trond Myklebust686a8162017-02-19 16:08:32 -05003921 ssize_t len;
3922 char *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923
Eric W. Biedermane5782072013-02-01 14:22:02 -08003924 *gid = make_kgid(&init_user_ns, -2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 if (unlikely(bitmap[1] & (FATTR4_WORD1_OWNER_GROUP - 1U)))
3926 return -EIO;
Trond Myklebust686a8162017-02-19 16:08:32 -05003927 if (!(bitmap[1] & FATTR4_WORD1_OWNER_GROUP))
3928 return 0;
3929 bitmap[1] &= ~FATTR4_WORD1_OWNER_GROUP;
3930
3931 if (group_name != NULL) {
3932 len = decode_nfs4_string(xdr, group_name, GFP_NOWAIT);
3933 if (len <= 0)
3934 goto out;
3935 dprintk("%s: name=%s\n", __func__, group_name->data);
Kinglong Mee6f1f6222017-03-06 17:49:42 +08003936 return NFS_ATTR_FATTR_GROUP_NAME;
Trond Myklebust686a8162017-02-19 16:08:32 -05003937 } else {
3938 len = xdr_stream_decode_opaque_inline(xdr, (void **)&p,
3939 XDR_MAX_NETOBJ);
3940 if (len <= 0 || nfs_map_group_to_gid(server, p, len, gid) != 0)
3941 goto out;
3942 dprintk("%s: gid=%d\n", __func__, (int)from_kgid(&init_user_ns, *gid));
3943 return NFS_ATTR_FATTR_GROUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 }
Trond Myklebust686a8162017-02-19 16:08:32 -05003945out:
3946 if (len != -EBADMSG)
3947 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03003948 print_overflow_msg(__func__, xdr);
3949 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003950}
3951
3952static int decode_attr_rdev(struct xdr_stream *xdr, uint32_t *bitmap, dev_t *rdev)
3953{
Al Viro8687b632006-10-19 23:28:48 -07003954 uint32_t major = 0, minor = 0;
3955 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04003956 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957
3958 *rdev = MKDEV(0,0);
3959 if (unlikely(bitmap[1] & (FATTR4_WORD1_RAWDEV - 1U)))
3960 return -EIO;
3961 if (likely(bitmap[1] & FATTR4_WORD1_RAWDEV)) {
3962 dev_t tmp;
3963
Benny Halevyc0eae662009-08-14 17:20:14 +03003964 p = xdr_inline_decode(xdr, 8);
3965 if (unlikely(!p))
3966 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03003967 major = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03003968 minor = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 tmp = MKDEV(major, minor);
3970 if (MAJOR(tmp) == major && MINOR(tmp) == minor)
3971 *rdev = tmp;
3972 bitmap[1] &= ~ FATTR4_WORD1_RAWDEV;
Trond Myklebust409924e2009-03-11 14:10:27 -04003973 ret = NFS_ATTR_FATTR_RDEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003975 dprintk("%s: rdev=(0x%x:0x%x)\n", __func__, major, minor);
Trond Myklebust409924e2009-03-11 14:10:27 -04003976 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03003977out_overflow:
3978 print_overflow_msg(__func__, xdr);
3979 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980}
3981
3982static int decode_attr_space_avail(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
3983{
Al Viro8687b632006-10-19 23:28:48 -07003984 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 int status = 0;
3986
3987 *res = 0;
3988 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_AVAIL - 1U)))
3989 return -EIO;
3990 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_AVAIL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03003991 p = xdr_inline_decode(xdr, 8);
3992 if (unlikely(!p))
3993 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03003994 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 bitmap[1] &= ~FATTR4_WORD1_SPACE_AVAIL;
3996 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07003997 dprintk("%s: space avail=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03003999out_overflow:
4000 print_overflow_msg(__func__, xdr);
4001 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002}
4003
4004static int decode_attr_space_free(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4005{
Al Viro8687b632006-10-19 23:28:48 -07004006 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 int status = 0;
4008
4009 *res = 0;
4010 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_FREE - 1U)))
4011 return -EIO;
4012 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_FREE)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004013 p = xdr_inline_decode(xdr, 8);
4014 if (unlikely(!p))
4015 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004016 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 bitmap[1] &= ~FATTR4_WORD1_SPACE_FREE;
4018 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004019 dprintk("%s: space free=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004021out_overflow:
4022 print_overflow_msg(__func__, xdr);
4023 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024}
4025
4026static int decode_attr_space_total(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *res)
4027{
Al Viro8687b632006-10-19 23:28:48 -07004028 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 int status = 0;
4030
4031 *res = 0;
4032 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_TOTAL - 1U)))
4033 return -EIO;
4034 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_TOTAL)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004035 p = xdr_inline_decode(xdr, 8);
4036 if (unlikely(!p))
4037 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004038 xdr_decode_hyper(p, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039 bitmap[1] &= ~FATTR4_WORD1_SPACE_TOTAL;
4040 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004041 dprintk("%s: space total=%Lu\n", __func__, (unsigned long long)*res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004043out_overflow:
4044 print_overflow_msg(__func__, xdr);
4045 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046}
4047
4048static int decode_attr_space_used(struct xdr_stream *xdr, uint32_t *bitmap, uint64_t *used)
4049{
Al Viro8687b632006-10-19 23:28:48 -07004050 __be32 *p;
Trond Myklebust409924e2009-03-11 14:10:27 -04004051 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052
4053 *used = 0;
4054 if (unlikely(bitmap[1] & (FATTR4_WORD1_SPACE_USED - 1U)))
4055 return -EIO;
4056 if (likely(bitmap[1] & FATTR4_WORD1_SPACE_USED)) {
Benny Halevyc0eae662009-08-14 17:20:14 +03004057 p = xdr_inline_decode(xdr, 8);
4058 if (unlikely(!p))
4059 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004060 xdr_decode_hyper(p, used);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061 bitmap[1] &= ~FATTR4_WORD1_SPACE_USED;
Trond Myklebust409924e2009-03-11 14:10:27 -04004062 ret = NFS_ATTR_FATTR_SPACE_USED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004064 dprintk("%s: space used=%Lu\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065 (unsigned long long)*used);
Trond Myklebust409924e2009-03-11 14:10:27 -04004066 return ret;
Benny Halevyc0eae662009-08-14 17:20:14 +03004067out_overflow:
4068 print_overflow_msg(__func__, xdr);
4069 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070}
4071
4072static int decode_attr_time(struct xdr_stream *xdr, struct timespec *time)
4073{
Al Viro8687b632006-10-19 23:28:48 -07004074 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 uint64_t sec;
4076 uint32_t nsec;
4077
Benny Halevyc0eae662009-08-14 17:20:14 +03004078 p = xdr_inline_decode(xdr, 12);
4079 if (unlikely(!p))
4080 goto out_overflow;
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004081 p = xdr_decode_hyper(p, &sec);
Benny Halevycccddf42009-08-14 17:20:19 +03004082 nsec = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 time->tv_sec = (time_t)sec;
4084 time->tv_nsec = (long)nsec;
4085 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004086out_overflow:
4087 print_overflow_msg(__func__, xdr);
4088 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089}
4090
4091static int decode_attr_time_access(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4092{
4093 int status = 0;
4094
4095 time->tv_sec = 0;
4096 time->tv_nsec = 0;
4097 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_ACCESS - 1U)))
4098 return -EIO;
4099 if (likely(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) {
4100 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004101 if (status == 0)
4102 status = NFS_ATTR_FATTR_ATIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 bitmap[1] &= ~FATTR4_WORD1_TIME_ACCESS;
4104 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004105 dprintk("%s: atime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 return status;
4107}
4108
4109static int decode_attr_time_metadata(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4110{
4111 int status = 0;
4112
4113 time->tv_sec = 0;
4114 time->tv_nsec = 0;
4115 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_METADATA - 1U)))
4116 return -EIO;
4117 if (likely(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) {
4118 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004119 if (status == 0)
4120 status = NFS_ATTR_FATTR_CTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 bitmap[1] &= ~FATTR4_WORD1_TIME_METADATA;
4122 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004123 dprintk("%s: ctime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 return status;
4125}
4126
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004127static int decode_attr_time_delta(struct xdr_stream *xdr, uint32_t *bitmap,
4128 struct timespec *time)
4129{
4130 int status = 0;
4131
4132 time->tv_sec = 0;
4133 time->tv_nsec = 0;
4134 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_DELTA - 1U)))
4135 return -EIO;
4136 if (likely(bitmap[1] & FATTR4_WORD1_TIME_DELTA)) {
4137 status = decode_attr_time(xdr, time);
4138 bitmap[1] &= ~FATTR4_WORD1_TIME_DELTA;
4139 }
4140 dprintk("%s: time_delta=%ld %ld\n", __func__, (long)time->tv_sec,
4141 (long)time->tv_nsec);
4142 return status;
4143}
4144
David Quigleyaa9c2662013-05-22 12:50:44 -04004145static int decode_attr_security_label(struct xdr_stream *xdr, uint32_t *bitmap,
4146 struct nfs4_label *label)
4147{
4148 uint32_t pi = 0;
4149 uint32_t lfs = 0;
4150 __u32 len;
4151 __be32 *p;
4152 int status = 0;
4153
4154 if (unlikely(bitmap[2] & (FATTR4_WORD2_SECURITY_LABEL - 1U)))
4155 return -EIO;
4156 if (likely(bitmap[2] & FATTR4_WORD2_SECURITY_LABEL)) {
4157 p = xdr_inline_decode(xdr, 4);
4158 if (unlikely(!p))
4159 goto out_overflow;
4160 lfs = be32_to_cpup(p++);
4161 p = xdr_inline_decode(xdr, 4);
4162 if (unlikely(!p))
4163 goto out_overflow;
4164 pi = be32_to_cpup(p++);
4165 p = xdr_inline_decode(xdr, 4);
4166 if (unlikely(!p))
4167 goto out_overflow;
4168 len = be32_to_cpup(p++);
4169 p = xdr_inline_decode(xdr, len);
4170 if (unlikely(!p))
4171 goto out_overflow;
4172 if (len < NFS4_MAXLABELLEN) {
4173 if (label) {
4174 memcpy(label->label, p, len);
4175 label->len = len;
4176 label->pi = pi;
4177 label->lfs = lfs;
4178 status = NFS_ATTR_FATTR_V4_SECURITY_LABEL;
4179 }
4180 bitmap[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
4181 } else
4182 printk(KERN_WARNING "%s: label too long (%u)!\n",
4183 __func__, len);
4184 }
4185 if (label && label->label)
4186 dprintk("%s: label=%s, len=%d, PI=%d, LFS=%d\n", __func__,
4187 (char *)label->label, label->len, label->pi, label->lfs);
4188 return status;
4189
4190out_overflow:
4191 print_overflow_msg(__func__, xdr);
4192 return -EIO;
4193}
4194
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195static int decode_attr_time_modify(struct xdr_stream *xdr, uint32_t *bitmap, struct timespec *time)
4196{
4197 int status = 0;
4198
4199 time->tv_sec = 0;
4200 time->tv_nsec = 0;
4201 if (unlikely(bitmap[1] & (FATTR4_WORD1_TIME_MODIFY - 1U)))
4202 return -EIO;
4203 if (likely(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) {
4204 status = decode_attr_time(xdr, time);
Trond Myklebust409924e2009-03-11 14:10:27 -04004205 if (status == 0)
4206 status = NFS_ATTR_FATTR_MTIME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 bitmap[1] &= ~FATTR4_WORD1_TIME_MODIFY;
4208 }
Harvey Harrison3110ff82008-05-02 13:42:44 -07004209 dprintk("%s: mtime=%ld\n", __func__, (long)time->tv_sec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 return status;
4211}
4212
Trond Myklebust256e48b2012-06-21 11:18:13 -04004213static int verify_attr_len(struct xdr_stream *xdr, unsigned int savep, uint32_t attrlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004214{
4215 unsigned int attrwords = XDR_QUADLEN(attrlen);
Trond Myklebust256e48b2012-06-21 11:18:13 -04004216 unsigned int nwords = (xdr_stream_pos(xdr) - savep) >> 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217
4218 if (unlikely(attrwords != nwords)) {
Chuck Leverfe82a182007-09-11 18:01:10 -04004219 dprintk("%s: server returned incorrect attribute length: "
4220 "%u %c %u\n",
Harvey Harrison3110ff82008-05-02 13:42:44 -07004221 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004222 attrwords << 2,
4223 (attrwords < nwords) ? '<' : '>',
4224 nwords << 2);
4225 return -EIO;
4226 }
4227 return 0;
4228}
4229
4230static int decode_change_info(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4231{
Al Viro8687b632006-10-19 23:28:48 -07004232 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004233
Benny Halevyc0eae662009-08-14 17:20:14 +03004234 p = xdr_inline_decode(xdr, 20);
4235 if (unlikely(!p))
4236 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004237 cinfo->atomic = be32_to_cpup(p++);
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004238 p = xdr_decode_hyper(p, &cinfo->before);
Benny Halevycccddf42009-08-14 17:20:19 +03004239 xdr_decode_hyper(p, &cinfo->after);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004241out_overflow:
4242 print_overflow_msg(__func__, xdr);
4243 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004244}
4245
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004246static int decode_access(struct xdr_stream *xdr, u32 *supported, u32 *access)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004247{
Al Viro8687b632006-10-19 23:28:48 -07004248 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004249 uint32_t supp, acc;
4250 int status;
4251
4252 status = decode_op_hdr(xdr, OP_ACCESS);
4253 if (status)
4254 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004255 p = xdr_inline_decode(xdr, 8);
4256 if (unlikely(!p))
4257 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03004258 supp = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03004259 acc = be32_to_cpup(p);
Weston Andros Adamson6168f622012-09-10 14:00:46 -04004260 *supported = supp;
4261 *access = acc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004262 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004263out_overflow:
4264 print_overflow_msg(__func__, xdr);
4265 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266}
4267
Benny Halevy07d30432009-08-14 17:19:52 +03004268static int decode_opaque_fixed(struct xdr_stream *xdr, void *buf, size_t len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269{
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004270 ssize_t ret = xdr_stream_decode_opaque_fixed(xdr, buf, len);
4271 if (unlikely(ret < 0)) {
4272 print_overflow_msg(__func__, xdr);
4273 return -EIO;
Benny Halevy07d30432009-08-14 17:19:52 +03004274 }
Trond Myklebustab6e9aa2017-02-19 16:08:26 -05004275 return 0;
Benny Halevy07d30432009-08-14 17:19:52 +03004276}
4277
4278static int decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4279{
Trond Myklebust2d2f24a2012-03-04 18:13:57 -05004280 return decode_opaque_fixed(xdr, stateid, NFS4_STATEID_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281}
4282
Trond Myklebust93b717f2016-05-16 17:42:43 -04004283static int decode_open_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4284{
4285 stateid->type = NFS4_OPEN_STATEID_TYPE;
4286 return decode_stateid(xdr, stateid);
4287}
4288
4289static int decode_lock_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4290{
4291 stateid->type = NFS4_LOCK_STATEID_TYPE;
4292 return decode_stateid(xdr, stateid);
4293}
4294
4295static int decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
4296{
4297 stateid->type = NFS4_DELEGATION_STATEID_TYPE;
4298 return decode_stateid(xdr, stateid);
4299}
4300
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
4302{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 int status;
4304
4305 status = decode_op_hdr(xdr, OP_CLOSE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004306 if (status != -EIO)
4307 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004308 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004309 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004310 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311}
4312
Benny Halevydb942bb2009-08-14 17:19:56 +03004313static int decode_verifier(struct xdr_stream *xdr, void *verifier)
4314{
Chuck Levercd937102012-03-02 17:14:31 -05004315 return decode_opaque_fixed(xdr, verifier, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316}
4317
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004318static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifier *verifier)
4319{
4320 return decode_opaque_fixed(xdr, verifier->data, NFS4_VERIFIER_SIZE);
4321}
4322
Fred Isaman0b7c0152012-04-20 14:47:39 -04004323static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325 int status;
4326
4327 status = decode_op_hdr(xdr, OP_COMMIT);
Benny Halevydb942bb2009-08-14 17:19:56 +03004328 if (!status)
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04004329 status = decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevydb942bb2009-08-14 17:19:56 +03004330 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331}
4332
4333static int decode_create(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4334{
Al Viro8687b632006-10-19 23:28:48 -07004335 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 uint32_t bmlen;
4337 int status;
4338
4339 status = decode_op_hdr(xdr, OP_CREATE);
4340 if (status)
4341 return status;
4342 if ((status = decode_change_info(xdr, cinfo)))
4343 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03004344 p = xdr_inline_decode(xdr, 4);
4345 if (unlikely(!p))
4346 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004347 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03004348 p = xdr_inline_decode(xdr, bmlen << 2);
4349 if (likely(p))
4350 return 0;
4351out_overflow:
4352 print_overflow_msg(__func__, xdr);
4353 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004354}
4355
4356static int decode_server_caps(struct xdr_stream *xdr, struct nfs4_server_caps_res *res)
4357{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004358 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004359 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 int status;
4361
4362 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4363 goto xdr_error;
4364 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4365 goto xdr_error;
4366 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4367 goto xdr_error;
4368 if ((status = decode_attr_supported(xdr, bitmap, res->attr_bitmask)) != 0)
4369 goto xdr_error;
Chuck Lever264e6352012-03-01 17:02:05 -05004370 if ((status = decode_attr_fh_expire_type(xdr, bitmap,
4371 &res->fh_expire_type)) != 0)
4372 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004373 if ((status = decode_attr_link_support(xdr, bitmap, &res->has_links)) != 0)
4374 goto xdr_error;
4375 if ((status = decode_attr_symlink_support(xdr, bitmap, &res->has_symlinks)) != 0)
4376 goto xdr_error;
4377 if ((status = decode_attr_aclsupport(xdr, bitmap, &res->acl_bitmask)) != 0)
4378 goto xdr_error;
Kinglong Mee8c612822015-08-26 21:12:58 +08004379 if ((status = decode_attr_exclcreat_supported(xdr, bitmap,
4380 res->exclcreat_bitmask)) != 0)
4381 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004382 status = verify_attr_len(xdr, savep, attrlen);
4383xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004384 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 return status;
4386}
Andy Adamson6c0195a2008-12-23 16:06:15 -05004387
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388static int decode_statfs(struct xdr_stream *xdr, struct nfs_fsstat *fsstat)
4389{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004390 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004391 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004393
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4395 goto xdr_error;
4396 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4397 goto xdr_error;
4398 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4399 goto xdr_error;
4400
4401 if ((status = decode_attr_files_avail(xdr, bitmap, &fsstat->afiles)) != 0)
4402 goto xdr_error;
4403 if ((status = decode_attr_files_free(xdr, bitmap, &fsstat->ffiles)) != 0)
4404 goto xdr_error;
4405 if ((status = decode_attr_files_total(xdr, bitmap, &fsstat->tfiles)) != 0)
4406 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004407
4408 status = -EIO;
4409 if (unlikely(bitmap[0]))
4410 goto xdr_error;
4411
Linus Torvalds1da177e2005-04-16 15:20:36 -07004412 if ((status = decode_attr_space_avail(xdr, bitmap, &fsstat->abytes)) != 0)
4413 goto xdr_error;
4414 if ((status = decode_attr_space_free(xdr, bitmap, &fsstat->fbytes)) != 0)
4415 goto xdr_error;
4416 if ((status = decode_attr_space_total(xdr, bitmap, &fsstat->tbytes)) != 0)
4417 goto xdr_error;
4418
4419 status = verify_attr_len(xdr, savep, attrlen);
4420xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004421 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004422 return status;
4423}
4424
4425static int decode_pathconf(struct xdr_stream *xdr, struct nfs_pathconf *pathconf)
4426{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004427 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004428 uint32_t attrlen, bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004429 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004430
Linus Torvalds1da177e2005-04-16 15:20:36 -07004431 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4432 goto xdr_error;
4433 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4434 goto xdr_error;
4435 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4436 goto xdr_error;
4437
4438 if ((status = decode_attr_maxlink(xdr, bitmap, &pathconf->max_link)) != 0)
4439 goto xdr_error;
4440 if ((status = decode_attr_maxname(xdr, bitmap, &pathconf->max_namelen)) != 0)
4441 goto xdr_error;
4442
4443 status = verify_attr_len(xdr, savep, attrlen);
4444xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004445 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 return status;
4447}
4448
Andy Adamson88034c32012-05-23 05:02:34 -04004449static int decode_threshold_hint(struct xdr_stream *xdr,
4450 uint32_t *bitmap,
4451 uint64_t *res,
4452 uint32_t hint_bit)
4453{
4454 __be32 *p;
4455
4456 *res = 0;
4457 if (likely(bitmap[0] & hint_bit)) {
4458 p = xdr_inline_decode(xdr, 8);
4459 if (unlikely(!p))
4460 goto out_overflow;
4461 xdr_decode_hyper(p, res);
4462 }
4463 return 0;
4464out_overflow:
4465 print_overflow_msg(__func__, xdr);
4466 return -EIO;
4467}
4468
4469static int decode_first_threshold_item4(struct xdr_stream *xdr,
4470 struct nfs4_threshold *res)
4471{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004472 __be32 *p;
4473 unsigned int savep;
Andy Adamson88034c32012-05-23 05:02:34 -04004474 uint32_t bitmap[3] = {0,}, attrlen;
4475 int status;
4476
4477 /* layout type */
4478 p = xdr_inline_decode(xdr, 4);
4479 if (unlikely(!p)) {
4480 print_overflow_msg(__func__, xdr);
4481 return -EIO;
4482 }
4483 res->l_type = be32_to_cpup(p);
4484
4485 /* thi_hintset bitmap */
4486 status = decode_attr_bitmap(xdr, bitmap);
4487 if (status < 0)
4488 goto xdr_error;
4489
4490 /* thi_hintlist length */
4491 status = decode_attr_length(xdr, &attrlen, &savep);
4492 if (status < 0)
4493 goto xdr_error;
4494 /* thi_hintlist */
4495 status = decode_threshold_hint(xdr, bitmap, &res->rd_sz, THRESHOLD_RD);
4496 if (status < 0)
4497 goto xdr_error;
4498 status = decode_threshold_hint(xdr, bitmap, &res->wr_sz, THRESHOLD_WR);
4499 if (status < 0)
4500 goto xdr_error;
4501 status = decode_threshold_hint(xdr, bitmap, &res->rd_io_sz,
4502 THRESHOLD_RD_IO);
4503 if (status < 0)
4504 goto xdr_error;
4505 status = decode_threshold_hint(xdr, bitmap, &res->wr_io_sz,
4506 THRESHOLD_WR_IO);
4507 if (status < 0)
4508 goto xdr_error;
4509
4510 status = verify_attr_len(xdr, savep, attrlen);
4511 res->bm = bitmap[0];
4512
4513 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
4514 __func__, res->bm, res->rd_sz, res->wr_sz, res->rd_io_sz,
4515 res->wr_io_sz);
4516xdr_error:
4517 dprintk("%s ret=%d!\n", __func__, status);
4518 return status;
4519}
4520
4521/*
4522 * Thresholds on pNFS direct I/O vrs MDS I/O
4523 */
4524static int decode_attr_mdsthreshold(struct xdr_stream *xdr,
4525 uint32_t *bitmap,
4526 struct nfs4_threshold *res)
4527{
4528 __be32 *p;
4529 int status = 0;
4530 uint32_t num;
4531
4532 if (unlikely(bitmap[2] & (FATTR4_WORD2_MDSTHRESHOLD - 1U)))
4533 return -EIO;
Trond Myklebust029c5342012-06-05 09:35:44 -04004534 if (bitmap[2] & FATTR4_WORD2_MDSTHRESHOLD) {
Trond Myklebust1549210f2012-06-05 09:16:47 -04004535 /* Did the server return an unrequested attribute? */
4536 if (unlikely(res == NULL))
4537 return -EREMOTEIO;
Andy Adamson88034c32012-05-23 05:02:34 -04004538 p = xdr_inline_decode(xdr, 4);
4539 if (unlikely(!p))
4540 goto out_overflow;
4541 num = be32_to_cpup(p);
4542 if (num == 0)
4543 return 0;
4544 if (num > 1)
4545 printk(KERN_INFO "%s: Warning: Multiple pNFS layout "
4546 "drivers per filesystem not supported\n",
4547 __func__);
4548
4549 status = decode_first_threshold_item4(xdr, res);
Trond Myklebust029c5342012-06-05 09:35:44 -04004550 bitmap[2] &= ~FATTR4_WORD2_MDSTHRESHOLD;
Andy Adamson88034c32012-05-23 05:02:34 -04004551 }
4552 return status;
4553out_overflow:
4554 print_overflow_msg(__func__, xdr);
4555 return -EIO;
4556}
4557
Bryan Schumakerae42c702010-10-21 16:33:17 -04004558static int decode_getfattr_attrs(struct xdr_stream *xdr, uint32_t *bitmap,
4559 struct nfs_fattr *fattr, struct nfs_fh *fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04004560 struct nfs4_fs_locations *fs_loc, struct nfs4_label *label,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004561 const struct nfs_server *server)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004562{
Trond Myklebustbca79472009-03-11 14:10:26 -04004563 int status;
4564 umode_t fmode = 0;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004565 uint32_t type;
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004566 int32_t err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004568 status = decode_attr_type(xdr, bitmap, &type);
4569 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004571 fattr->mode = 0;
4572 if (status != 0) {
4573 fattr->mode |= nfs_type2fmt[type];
4574 fattr->valid |= status;
4575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004576
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004577 status = decode_attr_change(xdr, bitmap, &fattr->change_attr);
4578 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004580 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004581
4582 status = decode_attr_size(xdr, bitmap, &fattr->size);
4583 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004584 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004585 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004586
4587 status = decode_attr_fsid(xdr, bitmap, &fattr->fsid);
4588 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004589 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004590 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004591
Trond Myklebustee7b75f2011-06-16 13:15:41 -04004592 err = 0;
4593 status = decode_attr_error(xdr, bitmap, &err);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004594 if (status < 0)
4595 goto xdr_error;
4596
4597 status = decode_attr_filehandle(xdr, bitmap, fh);
4598 if (status < 0)
4599 goto xdr_error;
4600
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004601 status = decode_attr_fileid(xdr, bitmap, &fattr->fileid);
4602 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004604 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004605
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004606 status = decode_attr_fs_locations(xdr, bitmap, fs_loc);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004607 if (status < 0)
Trond Myklebust683b57b2006-06-09 09:34:22 -04004608 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004609 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004610
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004611 status = -EIO;
4612 if (unlikely(bitmap[0]))
4613 goto xdr_error;
4614
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004615 status = decode_attr_mode(xdr, bitmap, &fmode);
4616 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004617 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004618 if (status != 0) {
4619 fattr->mode |= fmode;
4620 fattr->valid |= status;
4621 }
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004622
4623 status = decode_attr_nlink(xdr, bitmap, &fattr->nlink);
4624 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004625 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004626 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004627
Trond Myklebust6926afd2012-01-07 13:22:46 -05004628 status = decode_attr_owner(xdr, bitmap, server, &fattr->uid, fattr->owner_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004629 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004630 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004631 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004632
Trond Myklebust6926afd2012-01-07 13:22:46 -05004633 status = decode_attr_group(xdr, bitmap, server, &fattr->gid, fattr->group_name);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004634 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004635 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004636 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004637
4638 status = decode_attr_rdev(xdr, bitmap, &fattr->rdev);
4639 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004641 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004642
4643 status = decode_attr_space_used(xdr, bitmap, &fattr->du.nfs3.used);
4644 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004646 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004647
4648 status = decode_attr_time_access(xdr, bitmap, &fattr->atime);
4649 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004650 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004651 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004652
4653 status = decode_attr_time_metadata(xdr, bitmap, &fattr->ctime);
4654 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004655 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004656 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004657
4658 status = decode_attr_time_modify(xdr, bitmap, &fattr->mtime);
4659 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004660 goto xdr_error;
Trond Myklebust409924e2009-03-11 14:10:27 -04004661 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004662
Trond Myklebust28331a42011-04-27 13:47:52 -04004663 status = decode_attr_mounted_on_fileid(xdr, bitmap, &fattr->mounted_on_fileid);
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004664 if (status < 0)
Manoj Naik99baf622006-06-09 09:34:24 -04004665 goto xdr_error;
Trond Myklebust28331a42011-04-27 13:47:52 -04004666 fattr->valid |= status;
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004667
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004668 status = -EIO;
4669 if (unlikely(bitmap[1]))
4670 goto xdr_error;
4671
Andy Adamson88034c32012-05-23 05:02:34 -04004672 status = decode_attr_mdsthreshold(xdr, bitmap, fattr->mdsthreshold);
4673 if (status < 0)
4674 goto xdr_error;
4675
David Quigleyaa9c2662013-05-22 12:50:44 -04004676 if (label) {
4677 status = decode_attr_security_label(xdr, bitmap, label);
4678 if (status < 0)
4679 goto xdr_error;
4680 fattr->valid |= status;
4681 }
4682
Bryan Schumakerae42c702010-10-21 16:33:17 -04004683xdr_error:
4684 dprintk("%s: xdr returned %d\n", __func__, -status);
4685 return status;
4686}
4687
4688static int decode_getfattr_generic(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05004689 struct nfs_fh *fh, struct nfs4_fs_locations *fs_loc,
David Quigleyaa9c2662013-05-22 12:50:44 -04004690 struct nfs4_label *label, const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004691{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004692 unsigned int savep;
Bryan Schumakerae42c702010-10-21 16:33:17 -04004693 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04004694 bitmap[3] = {0};
Bryan Schumakerae42c702010-10-21 16:33:17 -04004695 int status;
4696
4697 status = decode_op_hdr(xdr, OP_GETATTR);
4698 if (status < 0)
4699 goto xdr_error;
4700
4701 status = decode_attr_bitmap(xdr, bitmap);
4702 if (status < 0)
4703 goto xdr_error;
4704
4705 status = decode_attr_length(xdr, &attrlen, &savep);
4706 if (status < 0)
4707 goto xdr_error;
4708
David Quigleyaa9c2662013-05-22 12:50:44 -04004709 status = decode_getfattr_attrs(xdr, bitmap, fattr, fh, fs_loc,
4710 label, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004711 if (status < 0)
4712 goto xdr_error;
4713
Trond Myklebustf26c7a72009-03-11 14:10:26 -04004714 status = verify_attr_len(xdr, savep, attrlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004715xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004716 dprintk("%s: xdr returned %d\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004717 return status;
4718}
4719
David Quigleyaa9c2662013-05-22 12:50:44 -04004720static int decode_getfattr_label(struct xdr_stream *xdr, struct nfs_fattr *fattr,
4721 struct nfs4_label *label, const struct nfs_server *server)
4722{
4723 return decode_getfattr_generic(xdr, fattr, NULL, NULL, label, server);
4724}
4725
Bryan Schumakerae42c702010-10-21 16:33:17 -04004726static int decode_getfattr(struct xdr_stream *xdr, struct nfs_fattr *fattr,
Trond Myklebust6926afd2012-01-07 13:22:46 -05004727 const struct nfs_server *server)
Bryan Schumakerae42c702010-10-21 16:33:17 -04004728{
David Quigleyaa9c2662013-05-22 12:50:44 -04004729 return decode_getfattr_generic(xdr, fattr, NULL, NULL, NULL, server);
Bryan Schumakerae42c702010-10-21 16:33:17 -04004730}
Linus Torvalds1da177e2005-04-16 15:20:36 -07004731
Andy Adamson504913f2010-10-20 00:17:57 -04004732/*
Jeff Layton3132e492016-08-10 15:58:24 -04004733 * Decode potentially multiple layout types.
Andy Adamson504913f2010-10-20 00:17:57 -04004734 */
Jeff Layton3132e492016-08-10 15:58:24 -04004735static int decode_pnfs_layout_types(struct xdr_stream *xdr,
Jeff Laytonca440c32016-09-15 14:40:49 -04004736 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004737{
Trond Myklebustb8a8a0d2013-08-20 21:08:56 -04004738 __be32 *p;
Jeff Laytonca440c32016-09-15 14:40:49 -04004739 uint32_t i;
Andy Adamson504913f2010-10-20 00:17:57 -04004740
4741 p = xdr_inline_decode(xdr, 4);
4742 if (unlikely(!p))
4743 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004744 fsinfo->nlayouttypes = be32_to_cpup(p);
Andy Adamson504913f2010-10-20 00:17:57 -04004745
4746 /* pNFS is not supported by the underlying file system */
Jeff Laytonca440c32016-09-15 14:40:49 -04004747 if (fsinfo->nlayouttypes == 0)
Andy Adamson504913f2010-10-20 00:17:57 -04004748 return 0;
Andy Adamson504913f2010-10-20 00:17:57 -04004749
4750 /* Decode and set first layout type, move xdr->p past unused types */
Jeff Laytonca440c32016-09-15 14:40:49 -04004751 p = xdr_inline_decode(xdr, fsinfo->nlayouttypes * 4);
Andy Adamson504913f2010-10-20 00:17:57 -04004752 if (unlikely(!p))
4753 goto out_overflow;
Jeff Laytonca440c32016-09-15 14:40:49 -04004754
4755 /* If we get too many, then just cap it at the max */
4756 if (fsinfo->nlayouttypes > NFS_MAX_LAYOUT_TYPES) {
4757 printk(KERN_INFO "NFS: %s: Warning: Too many (%u) pNFS layout types\n",
4758 __func__, fsinfo->nlayouttypes);
4759 fsinfo->nlayouttypes = NFS_MAX_LAYOUT_TYPES;
4760 }
4761
4762 for(i = 0; i < fsinfo->nlayouttypes; ++i)
4763 fsinfo->layouttype[i] = be32_to_cpup(p++);
Andy Adamson504913f2010-10-20 00:17:57 -04004764 return 0;
4765out_overflow:
4766 print_overflow_msg(__func__, xdr);
4767 return -EIO;
4768}
4769
4770/*
4771 * The type of file system exported.
4772 * Note we must ensure that layouttype is set in any non-error case.
4773 */
4774static int decode_attr_pnfstype(struct xdr_stream *xdr, uint32_t *bitmap,
Jeff Laytonca440c32016-09-15 14:40:49 -04004775 struct nfs_fsinfo *fsinfo)
Andy Adamson504913f2010-10-20 00:17:57 -04004776{
4777 int status = 0;
4778
4779 dprintk("%s: bitmap is %x\n", __func__, bitmap[1]);
4780 if (unlikely(bitmap[1] & (FATTR4_WORD1_FS_LAYOUT_TYPES - 1U)))
4781 return -EIO;
4782 if (bitmap[1] & FATTR4_WORD1_FS_LAYOUT_TYPES) {
Jeff Laytonca440c32016-09-15 14:40:49 -04004783 status = decode_pnfs_layout_types(xdr, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004784 bitmap[1] &= ~FATTR4_WORD1_FS_LAYOUT_TYPES;
Jeff Layton3132e492016-08-10 15:58:24 -04004785 }
Andy Adamson504913f2010-10-20 00:17:57 -04004786 return status;
4787}
4788
Fred Isamandae100c2011-07-30 20:52:37 -04004789/*
4790 * The prefered block size for layout directed io
4791 */
4792static int decode_attr_layout_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4793 uint32_t *res)
4794{
4795 __be32 *p;
4796
4797 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4798 *res = 0;
4799 if (bitmap[2] & FATTR4_WORD2_LAYOUT_BLKSIZE) {
4800 p = xdr_inline_decode(xdr, 4);
4801 if (unlikely(!p)) {
4802 print_overflow_msg(__func__, xdr);
4803 return -EIO;
4804 }
4805 *res = be32_to_cpup(p);
4806 bitmap[2] &= ~FATTR4_WORD2_LAYOUT_BLKSIZE;
4807 }
4808 return 0;
4809}
4810
Peng Tao2a92ee92015-09-26 02:24:37 +08004811/*
4812 * The granularity of a CLONE operation.
4813 */
4814static int decode_attr_clone_blksize(struct xdr_stream *xdr, uint32_t *bitmap,
4815 uint32_t *res)
4816{
4817 __be32 *p;
4818
4819 dprintk("%s: bitmap is %x\n", __func__, bitmap[2]);
4820 *res = 0;
4821 if (bitmap[2] & FATTR4_WORD2_CLONE_BLKSIZE) {
4822 p = xdr_inline_decode(xdr, 4);
4823 if (unlikely(!p)) {
4824 print_overflow_msg(__func__, xdr);
4825 return -EIO;
4826 }
4827 *res = be32_to_cpup(p);
4828 bitmap[2] &= ~FATTR4_WORD2_CLONE_BLKSIZE;
4829 }
4830 return 0;
4831}
4832
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833static int decode_fsinfo(struct xdr_stream *xdr, struct nfs_fsinfo *fsinfo)
4834{
Trond Myklebust256e48b2012-06-21 11:18:13 -04004835 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04004836 uint32_t attrlen, bitmap[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004837 int status;
4838
4839 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
4840 goto xdr_error;
4841 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
4842 goto xdr_error;
4843 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
4844 goto xdr_error;
4845
4846 fsinfo->rtmult = fsinfo->wtmult = 512; /* ??? */
4847
4848 if ((status = decode_attr_lease_time(xdr, bitmap, &fsinfo->lease_time)) != 0)
4849 goto xdr_error;
4850 if ((status = decode_attr_maxfilesize(xdr, bitmap, &fsinfo->maxfilesize)) != 0)
4851 goto xdr_error;
4852 if ((status = decode_attr_maxread(xdr, bitmap, &fsinfo->rtmax)) != 0)
4853 goto xdr_error;
4854 fsinfo->rtpref = fsinfo->dtpref = fsinfo->rtmax;
4855 if ((status = decode_attr_maxwrite(xdr, bitmap, &fsinfo->wtmax)) != 0)
4856 goto xdr_error;
4857 fsinfo->wtpref = fsinfo->wtmax;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004858
4859 status = -EIO;
4860 if (unlikely(bitmap[0]))
4861 goto xdr_error;
4862
Ricardo Labiaga55b6e772010-10-12 16:30:06 -07004863 status = decode_attr_time_delta(xdr, bitmap, &fsinfo->time_delta);
4864 if (status != 0)
4865 goto xdr_error;
Jeff Laytonca440c32016-09-15 14:40:49 -04004866 status = decode_attr_pnfstype(xdr, bitmap, fsinfo);
Andy Adamson504913f2010-10-20 00:17:57 -04004867 if (status != 0)
4868 goto xdr_error;
Andreas Gruenbacher1ca843a2015-11-03 18:25:33 +01004869
4870 status = -EIO;
4871 if (unlikely(bitmap[1]))
4872 goto xdr_error;
4873
Fred Isamandae100c2011-07-30 20:52:37 -04004874 status = decode_attr_layout_blksize(xdr, bitmap, &fsinfo->blksize);
4875 if (status)
4876 goto xdr_error;
Peng Tao2a92ee92015-09-26 02:24:37 +08004877 status = decode_attr_clone_blksize(xdr, bitmap, &fsinfo->clone_blksize);
4878 if (status)
4879 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004880
4881 status = verify_attr_len(xdr, savep, attrlen);
4882xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07004883 dprintk("%s: xdr returned %d!\n", __func__, -status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004884 return status;
4885}
4886
4887static int decode_getfh(struct xdr_stream *xdr, struct nfs_fh *fh)
4888{
Al Viro8687b632006-10-19 23:28:48 -07004889 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004890 uint32_t len;
4891 int status;
4892
Trond Myklebust99367812007-07-17 21:52:41 -04004893 /* Zero handle first to allow comparisons */
4894 memset(fh, 0, sizeof(*fh));
4895
Linus Torvalds1da177e2005-04-16 15:20:36 -07004896 status = decode_op_hdr(xdr, OP_GETFH);
4897 if (status)
4898 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004899
Benny Halevyc0eae662009-08-14 17:20:14 +03004900 p = xdr_inline_decode(xdr, 4);
4901 if (unlikely(!p))
4902 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03004903 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004904 if (len > NFS4_FHSIZE)
4905 return -EIO;
4906 fh->size = len;
Benny Halevyc0eae662009-08-14 17:20:14 +03004907 p = xdr_inline_decode(xdr, len);
4908 if (unlikely(!p))
4909 goto out_overflow;
Benny Halevy99398d02009-08-14 17:20:05 +03004910 memcpy(fh->data, p, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004911 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03004912out_overflow:
4913 print_overflow_msg(__func__, xdr);
4914 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004915}
4916
4917static int decode_link(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
4918{
4919 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05004920
Linus Torvalds1da177e2005-04-16 15:20:36 -07004921 status = decode_op_hdr(xdr, OP_LINK);
4922 if (status)
4923 return status;
4924 return decode_change_info(xdr, cinfo);
4925}
4926
4927/*
4928 * We create the owner, so we know a proper owner.id length is 4.
4929 */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004930static int decode_lock_denied (struct xdr_stream *xdr, struct file_lock *fl)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004931{
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004932 uint64_t offset, length, clientid;
Al Viro8687b632006-10-19 23:28:48 -07004933 __be32 *p;
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004934 uint32_t namelen, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004935
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004936 p = xdr_inline_decode(xdr, 32); /* read 32 bytes */
Benny Halevyc0eae662009-08-14 17:20:14 +03004937 if (unlikely(!p))
4938 goto out_overflow;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004939 p = xdr_decode_hyper(p, &offset); /* read 2 8-byte long words */
Benny Halevy3ceb4db2009-08-14 17:19:41 +03004940 p = xdr_decode_hyper(p, &length);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004941 type = be32_to_cpup(p++); /* 4 byte read */
4942 if (fl != NULL) { /* manipulate file lock */
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004943 fl->fl_start = (loff_t)offset;
4944 fl->fl_end = fl->fl_start + (loff_t)length - 1;
4945 if (length == ~(uint64_t)0)
4946 fl->fl_end = OFFSET_MAX;
4947 fl->fl_type = F_WRLCK;
4948 if (type & 1)
4949 fl->fl_type = F_RDLCK;
4950 fl->fl_pid = 0;
4951 }
Bryan Schumakerbabddc72010-10-20 15:44:29 -04004952 p = xdr_decode_hyper(p, &clientid); /* read 8 bytes */
4953 namelen = be32_to_cpup(p); /* read 4 bytes */ /* have read all 32 bytes now */
4954 p = xdr_inline_decode(xdr, namelen); /* variable size field */
Benny Halevyc0eae662009-08-14 17:20:14 +03004955 if (likely(p))
4956 return -NFS4ERR_DENIED;
4957out_overflow:
4958 print_overflow_msg(__func__, xdr);
4959 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960}
4961
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004962static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004963{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004964 int status;
4965
4966 status = decode_op_hdr(xdr, OP_LOCK);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004967 if (status == -EIO)
4968 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004969 if (status == 0) {
Trond Myklebust93b717f2016-05-16 17:42:43 -04004970 status = decode_lock_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03004971 if (unlikely(status))
4972 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973 } else if (status == -NFS4ERR_DENIED)
Trond Myklebustc1d51932008-04-07 13:20:54 -04004974 status = decode_lock_denied(xdr, NULL);
4975 if (res->open_seqid != NULL)
4976 nfs_increment_open_seqid(status, res->open_seqid);
4977 nfs_increment_lock_seqid(status, res->lock_seqid);
4978out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07004979 return status;
4980}
4981
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004982static int decode_lockt(struct xdr_stream *xdr, struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004983{
4984 int status;
4985 status = decode_op_hdr(xdr, OP_LOCKT);
4986 if (status == -NFS4ERR_DENIED)
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004987 return decode_lock_denied(xdr, res->denied);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004988 return status;
4989}
4990
Trond Myklebust911d1aa2006-01-03 09:55:16 +01004991static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004992{
Linus Torvalds1da177e2005-04-16 15:20:36 -07004993 int status;
4994
4995 status = decode_op_hdr(xdr, OP_LOCKU);
Trond Myklebustc1d51932008-04-07 13:20:54 -04004996 if (status != -EIO)
4997 nfs_increment_lock_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03004998 if (status == 0)
Trond Myklebust93b717f2016-05-16 17:42:43 -04004999 status = decode_lock_stateid(xdr, &res->stateid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005000 return status;
5001}
5002
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04005003static int decode_release_lockowner(struct xdr_stream *xdr)
5004{
5005 return decode_op_hdr(xdr, OP_RELEASE_LOCKOWNER);
5006}
5007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005008static int decode_lookup(struct xdr_stream *xdr)
5009{
5010 return decode_op_hdr(xdr, OP_LOOKUP);
5011}
5012
5013/* This is too sick! */
Trond Myklebust7d160a62015-09-05 19:06:57 -04005014static int decode_space_limit(struct xdr_stream *xdr,
5015 unsigned long *pagemod_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005016{
Andy Adamson05d564f2008-12-23 16:06:15 -05005017 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005018 uint32_t limit_type, nblocks, blocksize;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005019 u64 maxsize = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005020
Benny Halevyc0eae662009-08-14 17:20:14 +03005021 p = xdr_inline_decode(xdr, 12);
5022 if (unlikely(!p))
5023 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005024 limit_type = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005025 switch (limit_type) {
Trond Myklebust7d160a62015-09-05 19:06:57 -04005026 case NFS4_LIMIT_SIZE:
5027 xdr_decode_hyper(p, &maxsize);
Andy Adamson05d564f2008-12-23 16:06:15 -05005028 break;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005029 case NFS4_LIMIT_BLOCKS:
Benny Halevy6f723f72009-08-14 17:19:37 +03005030 nblocks = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005031 blocksize = be32_to_cpup(p);
Trond Myklebust7d160a62015-09-05 19:06:57 -04005032 maxsize = (uint64_t)nblocks * (uint64_t)blocksize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005033 }
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +03005034 maxsize >>= PAGE_SHIFT;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005035 *pagemod_limit = min_t(u64, maxsize, ULONG_MAX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005036 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005037out_overflow:
5038 print_overflow_msg(__func__, xdr);
5039 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005040}
5041
Trond Myklebust6ae37332015-01-30 14:21:14 -05005042static int decode_rw_delegation(struct xdr_stream *xdr,
5043 uint32_t delegation_type,
5044 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045{
Andy Adamson05d564f2008-12-23 16:06:15 -05005046 __be32 *p;
Benny Halevy07d30432009-08-14 17:19:52 +03005047 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048
Trond Myklebust93b717f2016-05-16 17:42:43 -04005049 status = decode_delegation_stateid(xdr, &res->delegation);
Benny Halevy07d30432009-08-14 17:19:52 +03005050 if (unlikely(status))
5051 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005052 p = xdr_inline_decode(xdr, 4);
5053 if (unlikely(!p))
5054 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005055 res->do_recall = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005056
Linus Torvalds1da177e2005-04-16 15:20:36 -07005057 switch (delegation_type) {
Andy Adamson05d564f2008-12-23 16:06:15 -05005058 case NFS4_OPEN_DELEGATE_READ:
5059 res->delegation_type = FMODE_READ;
5060 break;
5061 case NFS4_OPEN_DELEGATE_WRITE:
5062 res->delegation_type = FMODE_WRITE|FMODE_READ;
Trond Myklebust7d160a62015-09-05 19:06:57 -04005063 if (decode_space_limit(xdr, &res->pagemod_limit) < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005064 return -EIO;
5065 }
Trond Myklebust1bbe60f2017-02-19 16:08:30 -05005066 return decode_ace(xdr, NULL);
Benny Halevyc0eae662009-08-14 17:20:14 +03005067out_overflow:
5068 print_overflow_msg(__func__, xdr);
5069 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005070}
5071
Trond Myklebust6ae37332015-01-30 14:21:14 -05005072static int decode_no_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5073{
5074 __be32 *p;
5075 uint32_t why_no_delegation;
5076
5077 p = xdr_inline_decode(xdr, 4);
5078 if (unlikely(!p))
5079 goto out_overflow;
5080 why_no_delegation = be32_to_cpup(p);
5081 switch (why_no_delegation) {
5082 case WND4_CONTENTION:
5083 case WND4_RESOURCE:
5084 xdr_inline_decode(xdr, 4);
5085 /* Ignore for now */
5086 }
5087 return 0;
5088out_overflow:
5089 print_overflow_msg(__func__, xdr);
5090 return -EIO;
5091}
5092
5093static int decode_delegation(struct xdr_stream *xdr, struct nfs_openres *res)
5094{
5095 __be32 *p;
5096 uint32_t delegation_type;
5097
5098 p = xdr_inline_decode(xdr, 4);
5099 if (unlikely(!p))
5100 goto out_overflow;
5101 delegation_type = be32_to_cpup(p);
5102 res->delegation_type = 0;
5103 switch (delegation_type) {
5104 case NFS4_OPEN_DELEGATE_NONE:
5105 return 0;
5106 case NFS4_OPEN_DELEGATE_READ:
5107 case NFS4_OPEN_DELEGATE_WRITE:
5108 return decode_rw_delegation(xdr, delegation_type, res);
5109 case NFS4_OPEN_DELEGATE_NONE_EXT:
5110 return decode_no_delegation(xdr, res);
5111 }
5112 return -EIO;
5113out_overflow:
5114 print_overflow_msg(__func__, xdr);
5115 return -EIO;
5116}
5117
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
5119{
Andy Adamson05d564f2008-12-23 16:06:15 -05005120 __be32 *p;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005121 uint32_t savewords, bmlen, i;
Andy Adamson05d564f2008-12-23 16:06:15 -05005122 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005123
Trond Myklebustc7848f62013-12-04 17:39:23 -05005124 if (!__decode_op_hdr(xdr, OP_OPEN, &status))
5125 return status;
5126 nfs_increment_open_seqid(status, res->seqid);
5127 if (status)
5128 return status;
Trond Myklebust93b717f2016-05-16 17:42:43 -04005129 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005130 if (unlikely(status))
Andy Adamson05d564f2008-12-23 16:06:15 -05005131 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132
Andy Adamson05d564f2008-12-23 16:06:15 -05005133 decode_change_info(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134
Benny Halevyc0eae662009-08-14 17:20:14 +03005135 p = xdr_inline_decode(xdr, 8);
5136 if (unlikely(!p))
5137 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005138 res->rflags = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005139 bmlen = be32_to_cpup(p);
Andy Adamson05d564f2008-12-23 16:06:15 -05005140 if (bmlen > 10)
5141 goto xdr_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005142
Benny Halevyc0eae662009-08-14 17:20:14 +03005143 p = xdr_inline_decode(xdr, bmlen << 2);
5144 if (unlikely(!p))
5145 goto out_overflow;
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005146 savewords = min_t(uint32_t, bmlen, NFS4_BITMAP_SIZE);
5147 for (i = 0; i < savewords; ++i)
Benny Halevy6f723f72009-08-14 17:19:37 +03005148 res->attrset[i] = be32_to_cpup(p++);
Jeff Laytonaa53ed52007-06-05 14:49:03 -04005149 for (; i < NFS4_BITMAP_SIZE; i++)
5150 res->attrset[i] = 0;
5151
Linus Torvalds1da177e2005-04-16 15:20:36 -07005152 return decode_delegation(xdr, res);
5153xdr_error:
Harvey Harrison3110ff82008-05-02 13:42:44 -07005154 dprintk("%s: Bitmap too large! Length = %u\n", __func__, bmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 return -EIO;
Benny Halevyc0eae662009-08-14 17:20:14 +03005156out_overflow:
5157 print_overflow_msg(__func__, xdr);
5158 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159}
5160
5161static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmres *res)
5162{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 int status;
5164
Andy Adamson05d564f2008-12-23 16:06:15 -05005165 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005166 if (status != -EIO)
5167 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005168 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005169 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005170 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171}
5172
5173static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *res)
5174{
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 int status;
5176
5177 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
Trond Myklebustc1d51932008-04-07 13:20:54 -04005178 if (status != -EIO)
5179 nfs_increment_open_seqid(status, res->seqid);
Benny Halevy07d30432009-08-14 17:19:52 +03005180 if (!status)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005181 status = decode_open_stateid(xdr, &res->stateid);
Benny Halevy07d30432009-08-14 17:19:52 +03005182 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183}
5184
5185static int decode_putfh(struct xdr_stream *xdr)
5186{
5187 return decode_op_hdr(xdr, OP_PUTFH);
5188}
5189
5190static int decode_putrootfh(struct xdr_stream *xdr)
5191{
5192 return decode_op_hdr(xdr, OP_PUTROOTFH);
5193}
5194
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005195static int decode_read(struct xdr_stream *xdr, struct rpc_rqst *req,
5196 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197{
Al Viro8687b632006-10-19 23:28:48 -07005198 __be32 *p;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005199 uint32_t count, eof, recvd;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200 int status;
5201
5202 status = decode_op_hdr(xdr, OP_READ);
5203 if (status)
5204 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005205 p = xdr_inline_decode(xdr, 8);
5206 if (unlikely(!p))
5207 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005208 eof = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005209 count = be32_to_cpup(p);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005210 recvd = xdr_read_pages(xdr, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005211 if (count > recvd) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005212 dprintk("NFS: server cheating in read reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005213 "count %u > recvd %u\n", count, recvd);
5214 count = recvd;
5215 eof = 0;
5216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005217 res->eof = eof;
5218 res->count = count;
5219 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005220out_overflow:
5221 print_overflow_msg(__func__, xdr);
5222 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223}
5224
5225static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct nfs4_readdir_res *readdir)
5226{
Chuck Leverbcecff72007-10-26 13:32:03 -04005227 int status;
Chuck Levercd937102012-03-02 17:14:31 -05005228 __be32 verf[2];
Linus Torvalds1da177e2005-04-16 15:20:36 -07005229
5230 status = decode_op_hdr(xdr, OP_READDIR);
Benny Halevydb942bb2009-08-14 17:19:56 +03005231 if (!status)
5232 status = decode_verifier(xdr, readdir->verifier.data);
5233 if (unlikely(status))
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234 return status;
Chuck Levercd937102012-03-02 17:14:31 -05005235 memcpy(verf, readdir->verifier.data, sizeof(verf));
Fred Isaman44109242008-04-02 15:21:15 +03005236 dprintk("%s: verifier = %08x:%08x\n",
Chuck Levercd937102012-03-02 17:14:31 -05005237 __func__, verf[0], verf[1]);
Trond Myklebust64bd5772012-06-20 22:35:05 -04005238 return xdr_read_pages(xdr, xdr->buf->page_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005239}
5240
5241static int decode_readlink(struct xdr_stream *xdr, struct rpc_rqst *req)
5242{
5243 struct xdr_buf *rcvbuf = &req->rq_rcv_buf;
Chuck Leverbcecff72007-10-26 13:32:03 -04005244 u32 len, recvd;
Al Viro8687b632006-10-19 23:28:48 -07005245 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005246 int status;
5247
5248 status = decode_op_hdr(xdr, OP_READLINK);
5249 if (status)
5250 return status;
5251
5252 /* Convert length of symlink */
Benny Halevyc0eae662009-08-14 17:20:14 +03005253 p = xdr_inline_decode(xdr, 4);
5254 if (unlikely(!p))
5255 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005256 len = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005257 if (len >= rcvbuf->page_len || len <= 0) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005258 dprintk("nfs: server returned giant symlink!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005259 return -ENAMETOOLONG;
5260 }
Trond Myklebust64bd5772012-06-20 22:35:05 -04005261 recvd = xdr_read_pages(xdr, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 if (recvd < len) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005263 dprintk("NFS: server cheating in readlink reply: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 "count %u > recvd %u\n", len, recvd);
5265 return -EIO;
5266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005267 /*
5268 * The XDR encode routine has set things up so that
5269 * the link text will be copied directly into the
5270 * buffer. We just have to do overflow-checking,
5271 * and and null-terminate the text (the VFS expects
5272 * null-termination).
5273 */
Chuck Leverb4687da2010-09-21 16:55:48 -04005274 xdr_terminate_string(rcvbuf, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005275 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005276out_overflow:
5277 print_overflow_msg(__func__, xdr);
5278 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279}
5280
5281static int decode_remove(struct xdr_stream *xdr, struct nfs4_change_info *cinfo)
5282{
5283 int status;
5284
5285 status = decode_op_hdr(xdr, OP_REMOVE);
5286 if (status)
5287 goto out;
5288 status = decode_change_info(xdr, cinfo);
5289out:
5290 return status;
5291}
5292
5293static int decode_rename(struct xdr_stream *xdr, struct nfs4_change_info *old_cinfo,
5294 struct nfs4_change_info *new_cinfo)
5295{
5296 int status;
5297
5298 status = decode_op_hdr(xdr, OP_RENAME);
5299 if (status)
5300 goto out;
5301 if ((status = decode_change_info(xdr, old_cinfo)))
5302 goto out;
5303 status = decode_change_info(xdr, new_cinfo);
5304out:
5305 return status;
5306}
5307
5308static int decode_renew(struct xdr_stream *xdr)
5309{
5310 return decode_op_hdr(xdr, OP_RENEW);
5311}
5312
Trond Myklebust56ae19f2005-10-27 22:12:40 -04005313static int
5314decode_restorefh(struct xdr_stream *xdr)
5315{
5316 return decode_op_hdr(xdr, OP_RESTOREFH);
5317}
5318
J. Bruce Fields029d1052005-06-22 17:16:22 +00005319static int decode_getacl(struct xdr_stream *xdr, struct rpc_rqst *req,
Andy Adamsonbf118a32011-12-07 11:55:27 -05005320 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00005321{
Trond Myklebust256e48b2012-06-21 11:18:13 -04005322 unsigned int savep;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005323 uint32_t attrlen,
Fred Isamandae100c2011-07-30 20:52:37 -04005324 bitmap[3] = {0};
J. Bruce Fields029d1052005-06-22 17:16:22 +00005325 int status;
Trond Myklebustcff298c2012-08-14 17:14:17 -04005326 unsigned int pg_offset;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005327
Andy Adamsonbf118a32011-12-07 11:55:27 -05005328 res->acl_len = 0;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005329 if ((status = decode_op_hdr(xdr, OP_GETATTR)) != 0)
5330 goto out;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005331
Trond Myklebust519d3952012-08-14 17:30:10 -04005332 xdr_enter_page(xdr, xdr->buf->page_len);
5333
Trond Myklebustcff298c2012-08-14 17:14:17 -04005334 /* Calculate the offset of the page data */
5335 pg_offset = xdr->buf->head[0].iov_len;
Sachin Prabhu5a006892012-04-17 14:35:39 +01005336
J. Bruce Fields029d1052005-06-22 17:16:22 +00005337 if ((status = decode_attr_bitmap(xdr, bitmap)) != 0)
5338 goto out;
5339 if ((status = decode_attr_length(xdr, &attrlen, &savep)) != 0)
5340 goto out;
5341
5342 if (unlikely(bitmap[0] & (FATTR4_WORD0_ACL - 1U)))
5343 return -EIO;
5344 if (likely(bitmap[0] & FATTR4_WORD0_ACL)) {
J. Bruce Fields029d1052005-06-22 17:16:22 +00005345
Andy Adamsonbf118a32011-12-07 11:55:27 -05005346 /* The bitmap (xdr len + bitmaps) and the attr xdr len words
5347 * are stored with the acl data to handle the problem of
5348 * variable length bitmaps.*/
Trond Myklebustcff298c2012-08-14 17:14:17 -04005349 res->acl_data_offset = xdr_stream_pos(xdr) - pg_offset;
Trond Myklebust519d3952012-08-14 17:30:10 -04005350 res->acl_len = attrlen;
Trond Myklebust1f1ea6c2012-08-26 11:44:43 -07005351
5352 /* Check for receive buffer overflow */
5353 if (res->acl_len > (xdr->nwords << 2) ||
5354 res->acl_len + res->acl_data_offset > xdr->buf->page_len) {
5355 res->acl_flags |= NFS4_ACL_TRUNC;
Trond Myklebust519d3952012-08-14 17:30:10 -04005356 dprintk("NFS: acl reply: attrlen %u > page_len %u\n",
Trond Myklebustcff298c2012-08-14 17:14:17 -04005357 attrlen, xdr->nwords << 2);
J. Bruce Fields029d1052005-06-22 17:16:22 +00005358 }
J. Bruce Fields8c233cf2005-10-13 16:54:27 -04005359 } else
5360 status = -EOPNOTSUPP;
J. Bruce Fields029d1052005-06-22 17:16:22 +00005361
5362out:
5363 return status;
5364}
5365
Linus Torvalds1da177e2005-04-16 15:20:36 -07005366static int
5367decode_savefh(struct xdr_stream *xdr)
5368{
5369 return decode_op_hdr(xdr, OP_SAVEFH);
5370}
5371
Benny Halevy9e9ecc02009-04-01 09:22:00 -04005372static int decode_setattr(struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373{
Al Viro8687b632006-10-19 23:28:48 -07005374 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005375 uint32_t bmlen;
5376 int status;
5377
Linus Torvalds1da177e2005-04-16 15:20:36 -07005378 status = decode_op_hdr(xdr, OP_SETATTR);
5379 if (status)
5380 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005381 p = xdr_inline_decode(xdr, 4);
5382 if (unlikely(!p))
5383 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005384 bmlen = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005385 p = xdr_inline_decode(xdr, bmlen << 2);
5386 if (likely(p))
5387 return 0;
5388out_overflow:
5389 print_overflow_msg(__func__, xdr);
5390 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005391}
5392
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005393static int decode_setclientid(struct xdr_stream *xdr, struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394{
Al Viro8687b632006-10-19 23:28:48 -07005395 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396 uint32_t opnum;
5397 int32_t nfserr;
5398
Benny Halevyc0eae662009-08-14 17:20:14 +03005399 p = xdr_inline_decode(xdr, 8);
5400 if (unlikely(!p))
5401 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005402 opnum = be32_to_cpup(p++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403 if (opnum != OP_SETCLIENTID) {
Chuck Leverfe82a182007-09-11 18:01:10 -04005404 dprintk("nfs: decode_setclientid: Server returned operation"
Andy Adamson6c0195a2008-12-23 16:06:15 -05005405 " %d\n", opnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 return -EIO;
5407 }
Benny Halevycccddf42009-08-14 17:20:19 +03005408 nfserr = be32_to_cpup(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 if (nfserr == NFS_OK) {
Benny Halevyc0eae662009-08-14 17:20:14 +03005410 p = xdr_inline_decode(xdr, 8 + NFS4_VERIFIER_SIZE);
5411 if (unlikely(!p))
5412 goto out_overflow;
Trond Myklebustbb8b27e2010-04-16 16:43:06 -04005413 p = xdr_decode_hyper(p, &res->clientid);
5414 memcpy(res->confirm.data, p, NFS4_VERIFIER_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005415 } else if (nfserr == NFSERR_CLID_INUSE) {
5416 uint32_t len;
5417
5418 /* skip netid string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005419 p = xdr_inline_decode(xdr, 4);
5420 if (unlikely(!p))
5421 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005422 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005423 p = xdr_inline_decode(xdr, len);
5424 if (unlikely(!p))
5425 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005426
5427 /* skip uaddr string */
Benny Halevyc0eae662009-08-14 17:20:14 +03005428 p = xdr_inline_decode(xdr, 4);
5429 if (unlikely(!p))
5430 goto out_overflow;
Benny Halevycccddf42009-08-14 17:20:19 +03005431 len = be32_to_cpup(p);
Benny Halevyc0eae662009-08-14 17:20:14 +03005432 p = xdr_inline_decode(xdr, len);
5433 if (unlikely(!p))
5434 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435 return -NFSERR_CLID_INUSE;
5436 } else
Benny Halevy856dff32008-03-31 17:39:06 +03005437 return nfs4_stat_to_errno(nfserr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438
5439 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005440out_overflow:
5441 print_overflow_msg(__func__, xdr);
5442 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005443}
5444
5445static int decode_setclientid_confirm(struct xdr_stream *xdr)
5446{
5447 return decode_op_hdr(xdr, OP_SETCLIENTID_CONFIRM);
5448}
5449
Anna Schumaker9137bdf2014-05-06 09:12:25 -04005450static int decode_write(struct xdr_stream *xdr, struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451{
Al Viro8687b632006-10-19 23:28:48 -07005452 __be32 *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005453 int status;
5454
5455 status = decode_op_hdr(xdr, OP_WRITE);
5456 if (status)
5457 return status;
5458
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005459 p = xdr_inline_decode(xdr, 8);
Benny Halevyc0eae662009-08-14 17:20:14 +03005460 if (unlikely(!p))
5461 goto out_overflow;
Benny Halevy6f723f72009-08-14 17:19:37 +03005462 res->count = be32_to_cpup(p++);
5463 res->verf->committed = be32_to_cpup(p++);
Trond Myklebust2f2c63b2012-06-08 11:56:09 -04005464 return decode_write_verifier(xdr, &res->verf->verifier);
Benny Halevyc0eae662009-08-14 17:20:14 +03005465out_overflow:
5466 print_overflow_msg(__func__, xdr);
5467 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468}
5469
5470static int decode_delegreturn(struct xdr_stream *xdr)
5471{
5472 return decode_op_hdr(xdr, OP_DELEGRETURN);
5473}
5474
Chuck Leverfb15b262013-03-16 15:54:34 -04005475static int decode_secinfo_gss(struct xdr_stream *xdr,
5476 struct nfs4_secinfo4 *flavor)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005477{
Chuck Leverfb15b262013-03-16 15:54:34 -04005478 u32 oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005479 __be32 *p;
5480
5481 p = xdr_inline_decode(xdr, 4);
5482 if (unlikely(!p))
5483 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005484 oid_len = be32_to_cpup(p);
5485 if (oid_len > GSS_OID_MAX_LEN)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005486 goto out_err;
5487
Chuck Leverfb15b262013-03-16 15:54:34 -04005488 p = xdr_inline_decode(xdr, oid_len);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005489 if (unlikely(!p))
5490 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005491 memcpy(flavor->flavor_info.oid.data, p, oid_len);
5492 flavor->flavor_info.oid.len = oid_len;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005493
5494 p = xdr_inline_decode(xdr, 8);
5495 if (unlikely(!p))
5496 goto out_overflow;
Chuck Leverfb15b262013-03-16 15:54:34 -04005497 flavor->flavor_info.qop = be32_to_cpup(p++);
5498 flavor->flavor_info.service = be32_to_cpup(p);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005499
5500 return 0;
5501
5502out_overflow:
5503 print_overflow_msg(__func__, xdr);
5504 return -EIO;
5505out_err:
5506 return -EINVAL;
5507}
5508
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005509static int decode_secinfo_common(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005510{
Chuck Leverfb15b262013-03-16 15:54:34 -04005511 struct nfs4_secinfo4 *sec_flavor;
5512 unsigned int i, num_flavors;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005513 int status;
5514 __be32 *p;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005515
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005516 p = xdr_inline_decode(xdr, 4);
5517 if (unlikely(!p))
5518 goto out_overflow;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005519
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005520 res->flavors->num_flavors = 0;
5521 num_flavors = be32_to_cpup(p);
5522
5523 for (i = 0; i < num_flavors; i++) {
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005524 sec_flavor = &res->flavors->flavors[i];
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005525 if ((char *)&sec_flavor[1] - (char *)res->flavors > PAGE_SIZE)
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005526 break;
5527
5528 p = xdr_inline_decode(xdr, 4);
5529 if (unlikely(!p))
5530 goto out_overflow;
5531 sec_flavor->flavor = be32_to_cpup(p);
5532
5533 if (sec_flavor->flavor == RPC_AUTH_GSS) {
Bryan Schumaker613e9012011-04-27 15:28:44 -04005534 status = decode_secinfo_gss(xdr, sec_flavor);
5535 if (status)
5536 goto out;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005537 }
Bryan Schumakerc3dfc282011-04-13 14:31:31 -04005538 res->flavors->num_flavors++;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005539 }
5540
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005541 status = 0;
Bryan Schumaker613e9012011-04-27 15:28:44 -04005542out:
5543 return status;
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00005544out_overflow:
5545 print_overflow_msg(__func__, xdr);
5546 return -EIO;
5547}
5548
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005549static int decode_secinfo(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5550{
5551 int status = decode_op_hdr(xdr, OP_SECINFO);
5552 if (status)
5553 return status;
5554 return decode_secinfo_common(xdr, res);
5555}
5556
Benny Halevy99fe60d2009-04-01 09:22:29 -04005557#if defined(CONFIG_NFS_V4_1)
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04005558static int decode_secinfo_no_name(struct xdr_stream *xdr, struct nfs4_secinfo_res *res)
5559{
5560 int status = decode_op_hdr(xdr, OP_SECINFO_NO_NAME);
5561 if (status)
5562 return status;
5563 return decode_secinfo_common(xdr, res);
5564}
5565
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005566static int decode_op_map(struct xdr_stream *xdr, struct nfs4_op_map *op_map)
5567{
5568 __be32 *p;
5569 uint32_t bitmap_words;
5570 unsigned int i;
5571
5572 p = xdr_inline_decode(xdr, 4);
5573 bitmap_words = be32_to_cpup(p++);
5574 if (bitmap_words > NFS4_OP_MAP_NUM_WORDS)
5575 return -EIO;
5576 p = xdr_inline_decode(xdr, 4 * bitmap_words);
5577 for (i = 0; i < bitmap_words; i++)
5578 op_map->u.words[i] = be32_to_cpup(p++);
5579
5580 return 0;
5581}
5582
Benny Halevy99fe60d2009-04-01 09:22:29 -04005583static int decode_exchange_id(struct xdr_stream *xdr,
5584 struct nfs41_exchange_id_res *res)
5585{
5586 __be32 *p;
5587 uint32_t dummy;
Benny Halevy2460ba52009-08-14 17:20:10 +03005588 char *dummy_str;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005589 int status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005590 uint32_t impl_id_count;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005591
5592 status = decode_op_hdr(xdr, OP_EXCHANGE_ID);
5593 if (status)
5594 return status;
5595
Benny Halevyc0eae662009-08-14 17:20:14 +03005596 p = xdr_inline_decode(xdr, 8);
5597 if (unlikely(!p))
5598 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005599 xdr_decode_hyper(p, &res->clientid);
Benny Halevyc0eae662009-08-14 17:20:14 +03005600 p = xdr_inline_decode(xdr, 12);
5601 if (unlikely(!p))
5602 goto out_overflow;
Trond Myklebust32b01312012-05-26 13:41:04 -04005603 res->seqid = be32_to_cpup(p++);
5604 res->flags = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005605
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005606 res->state_protect.how = be32_to_cpup(p);
5607 switch (res->state_protect.how) {
5608 case SP4_NONE:
5609 break;
5610 case SP4_MACH_CRED:
5611 status = decode_op_map(xdr, &res->state_protect.enforce);
5612 if (status)
5613 return status;
5614 status = decode_op_map(xdr, &res->state_protect.allow);
5615 if (status)
5616 return status;
5617 break;
5618 default:
5619 WARN_ON_ONCE(1);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005620 return -EIO;
Weston Andros Adamson2031cd12013-08-13 16:37:32 -04005621 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005622
Chuck Leveracdeb692012-05-21 22:46:16 -04005623 /* server_owner4.so_minor_id */
Benny Halevyc0eae662009-08-14 17:20:14 +03005624 p = xdr_inline_decode(xdr, 8);
5625 if (unlikely(!p))
5626 goto out_overflow;
Chuck Leveracdeb692012-05-21 22:46:16 -04005627 p = xdr_decode_hyper(p, &res->server_owner->minor_id);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005628
Chuck Leveracdeb692012-05-21 22:46:16 -04005629 /* server_owner4.so_major_id */
Benny Halevy2460ba52009-08-14 17:20:10 +03005630 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5631 if (unlikely(status))
5632 return status;
Chuck Leveracdeb692012-05-21 22:46:16 -04005633 memcpy(res->server_owner->major_id, dummy_str, dummy);
5634 res->server_owner->major_id_sz = dummy;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005635
Chuck Leveracdeb692012-05-21 22:46:16 -04005636 /* server_scope4 */
5637 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5638 if (unlikely(status))
5639 return status;
Weston Andros Adamson78fe0f42011-05-31 19:05:47 -04005640 memcpy(res->server_scope->server_scope, dummy_str, dummy);
5641 res->server_scope->server_scope_sz = dummy;
5642
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005643 /* Implementation Id */
5644 p = xdr_inline_decode(xdr, 4);
5645 if (unlikely(!p))
5646 goto out_overflow;
5647 impl_id_count = be32_to_cpup(p++);
Benny Halevy99fe60d2009-04-01 09:22:29 -04005648
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005649 if (impl_id_count) {
5650 /* nii_domain */
5651 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5652 if (unlikely(status))
5653 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005654 memcpy(res->impl_id->domain, dummy_str, dummy);
5655
5656 /* nii_name */
5657 status = decode_opaque_inline(xdr, &dummy, &dummy_str);
5658 if (unlikely(status))
5659 return status;
Weston Andros Adamson7d2ed9a2012-02-17 15:20:26 -05005660 memcpy(res->impl_id->name, dummy_str, dummy);
5661
5662 /* nii_date */
5663 p = xdr_inline_decode(xdr, 12);
5664 if (unlikely(!p))
5665 goto out_overflow;
5666 p = xdr_decode_hyper(p, &res->impl_id->date.seconds);
5667 res->impl_id->date.nseconds = be32_to_cpup(p);
5668
5669 /* if there's more than one entry, ignore the rest */
5670 }
Benny Halevy99fe60d2009-04-01 09:22:29 -04005671 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005672out_overflow:
5673 print_overflow_msg(__func__, xdr);
5674 return -EIO;
Benny Halevy99fe60d2009-04-01 09:22:29 -04005675}
Andy Adamsonfc931582009-04-01 09:22:31 -04005676
5677static int decode_chan_attrs(struct xdr_stream *xdr,
5678 struct nfs4_channel_attrs *attrs)
5679{
5680 __be32 *p;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005681 u32 nr_attrs, val;
Andy Adamsonfc931582009-04-01 09:22:31 -04005682
Benny Halevyc0eae662009-08-14 17:20:14 +03005683 p = xdr_inline_decode(xdr, 28);
5684 if (unlikely(!p))
5685 goto out_overflow;
Benny Halevyc9c30dd2011-06-11 17:08:39 -04005686 val = be32_to_cpup(p++); /* headerpadsz */
5687 if (val)
5688 return -EINVAL; /* no support for header padding yet */
Benny Halevy6f723f72009-08-14 17:19:37 +03005689 attrs->max_rqst_sz = be32_to_cpup(p++);
5690 attrs->max_resp_sz = be32_to_cpup(p++);
5691 attrs->max_resp_sz_cached = be32_to_cpup(p++);
5692 attrs->max_ops = be32_to_cpup(p++);
5693 attrs->max_reqs = be32_to_cpup(p++);
Benny Halevycccddf42009-08-14 17:20:19 +03005694 nr_attrs = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005695 if (unlikely(nr_attrs > 1)) {
Weston Andros Adamsona0308892012-01-26 13:32:23 -05005696 printk(KERN_WARNING "NFS: %s: Invalid rdma channel attrs "
5697 "count %u\n", __func__, nr_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005698 return -EINVAL;
5699 }
Benny Halevyc0eae662009-08-14 17:20:14 +03005700 if (nr_attrs == 1) {
5701 p = xdr_inline_decode(xdr, 4); /* skip rdma_attrs */
5702 if (unlikely(!p))
5703 goto out_overflow;
5704 }
Andy Adamsonfc931582009-04-01 09:22:31 -04005705 return 0;
Benny Halevyc0eae662009-08-14 17:20:14 +03005706out_overflow:
5707 print_overflow_msg(__func__, xdr);
5708 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005709}
5710
Benny Halevye78291e2009-08-14 17:20:00 +03005711static int decode_sessionid(struct xdr_stream *xdr, struct nfs4_sessionid *sid)
5712{
5713 return decode_opaque_fixed(xdr, sid->data, NFS4_MAX_SESSIONID_LEN);
Andy Adamsonfc931582009-04-01 09:22:31 -04005714}
5715
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005716static int decode_bind_conn_to_session(struct xdr_stream *xdr,
5717 struct nfs41_bind_conn_to_session_res *res)
5718{
5719 __be32 *p;
5720 int status;
5721
5722 status = decode_op_hdr(xdr, OP_BIND_CONN_TO_SESSION);
5723 if (!status)
Trond Myklebust71a097c2015-02-18 09:27:18 -08005724 status = decode_sessionid(xdr, &res->sessionid);
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04005725 if (unlikely(status))
5726 return status;
5727
5728 /* dir flags, rdma mode bool */
5729 p = xdr_inline_decode(xdr, 8);
5730 if (unlikely(!p))
5731 goto out_overflow;
5732
5733 res->dir = be32_to_cpup(p++);
5734 if (res->dir == 0 || res->dir > NFS4_CDFS4_BOTH)
5735 return -EIO;
5736 if (be32_to_cpup(p) == 0)
5737 res->use_conn_in_rdma_mode = false;
5738 else
5739 res->use_conn_in_rdma_mode = true;
5740
5741 return 0;
5742out_overflow:
5743 print_overflow_msg(__func__, xdr);
5744 return -EIO;
5745}
5746
Andy Adamsonfc931582009-04-01 09:22:31 -04005747static int decode_create_session(struct xdr_stream *xdr,
5748 struct nfs41_create_session_res *res)
5749{
5750 __be32 *p;
5751 int status;
Andy Adamsonfc931582009-04-01 09:22:31 -04005752
5753 status = decode_op_hdr(xdr, OP_CREATE_SESSION);
Benny Halevye78291e2009-08-14 17:20:00 +03005754 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005755 status = decode_sessionid(xdr, &res->sessionid);
Benny Halevye78291e2009-08-14 17:20:00 +03005756 if (unlikely(status))
Andy Adamsonfc931582009-04-01 09:22:31 -04005757 return status;
5758
Andy Adamsonfc931582009-04-01 09:22:31 -04005759 /* seqid, flags */
Benny Halevyc0eae662009-08-14 17:20:14 +03005760 p = xdr_inline_decode(xdr, 8);
5761 if (unlikely(!p))
5762 goto out_overflow;
Trond Myklebust79969dd2015-02-18 11:30:18 -08005763 res->seqid = be32_to_cpup(p++);
5764 res->flags = be32_to_cpup(p);
Andy Adamsonfc931582009-04-01 09:22:31 -04005765
5766 /* Channel attributes */
Trond Myklebust79969dd2015-02-18 11:30:18 -08005767 status = decode_chan_attrs(xdr, &res->fc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005768 if (!status)
Trond Myklebust79969dd2015-02-18 11:30:18 -08005769 status = decode_chan_attrs(xdr, &res->bc_attrs);
Andy Adamsonfc931582009-04-01 09:22:31 -04005770 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005771out_overflow:
5772 print_overflow_msg(__func__, xdr);
5773 return -EIO;
Andy Adamsonfc931582009-04-01 09:22:31 -04005774}
Andy Adamson0f3e66c2009-04-01 09:22:34 -04005775
5776static int decode_destroy_session(struct xdr_stream *xdr, void *dummy)
5777{
5778 return decode_op_hdr(xdr, OP_DESTROY_SESSION);
5779}
Ricardo Labiaga180197532009-12-05 16:08:40 -05005780
Trond Myklebust66245532012-05-25 17:18:09 -04005781static int decode_destroy_clientid(struct xdr_stream *xdr, void *dummy)
5782{
5783 return decode_op_hdr(xdr, OP_DESTROY_CLIENTID);
5784}
5785
Ricardo Labiaga180197532009-12-05 16:08:40 -05005786static int decode_reclaim_complete(struct xdr_stream *xdr, void *dummy)
5787{
5788 return decode_op_hdr(xdr, OP_RECLAIM_COMPLETE);
5789}
Benny Halevy99fe60d2009-04-01 09:22:29 -04005790#endif /* CONFIG_NFS_V4_1 */
5791
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005792static int decode_sequence(struct xdr_stream *xdr,
5793 struct nfs4_sequence_res *res,
5794 struct rpc_rqst *rqstp)
5795{
5796#if defined(CONFIG_NFS_V4_1)
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005797 struct nfs4_session *session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005798 struct nfs4_sessionid id;
5799 u32 dummy;
5800 int status;
5801 __be32 *p;
5802
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005803 if (res->sr_slot == NULL)
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005804 return 0;
Chuck Lever3bd23842013-08-09 12:49:19 -04005805 if (!res->sr_slot->table->session)
5806 return 0;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005807
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005808 status = decode_op_hdr(xdr, OP_SEQUENCE);
Benny Halevye78291e2009-08-14 17:20:00 +03005809 if (!status)
5810 status = decode_sessionid(xdr, &id);
5811 if (unlikely(status))
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005812 goto out_err;
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005813
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005814 /*
5815 * If the server returns different values for sessionID, slotID or
5816 * sequence number, the server is looney tunes.
5817 */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05005818 status = -EREMOTEIO;
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005819 session = res->sr_slot->table->session;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005820
Trond Myklebuste3725ec2012-11-16 12:25:01 -05005821 if (memcmp(id.data, session->sess_id.data,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005822 NFS4_MAX_SESSIONID_LEN)) {
5823 dprintk("%s Invalid session id\n", __func__);
5824 goto out_err;
5825 }
Benny Halevye78291e2009-08-14 17:20:00 +03005826
Benny Halevyc0eae662009-08-14 17:20:14 +03005827 p = xdr_inline_decode(xdr, 20);
5828 if (unlikely(!p))
5829 goto out_overflow;
Benny Halevye78291e2009-08-14 17:20:00 +03005830
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005831 /* seqid */
Benny Halevy6f723f72009-08-14 17:19:37 +03005832 dummy = be32_to_cpup(p++);
Benny Halevydfb4f3092010-09-24 09:17:01 -04005833 if (dummy != res->sr_slot->seq_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005834 dprintk("%s Invalid sequence number\n", __func__);
5835 goto out_err;
5836 }
5837 /* slot id */
Benny Halevy6f723f72009-08-14 17:19:37 +03005838 dummy = be32_to_cpup(p++);
Trond Myklebustdf2fabf2012-11-16 12:45:06 -05005839 if (dummy != res->sr_slot->slot_nr) {
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005840 dprintk("%s Invalid slot id\n", __func__);
5841 goto out_err;
5842 }
Trond Myklebustda0507b2012-11-20 18:10:30 -05005843 /* highest slot id */
5844 res->sr_highest_slotid = be32_to_cpup(p++);
Trond Myklebust464ee9f2012-11-20 12:49:27 -05005845 /* target highest slot id */
5846 res->sr_target_highest_slotid = be32_to_cpup(p++);
Alexandros Batsakis0629e372009-12-05 13:46:14 -05005847 /* result flags */
5848 res->sr_status_flags = be32_to_cpup(p);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005849 status = 0;
5850out_err:
5851 res->sr_status = status;
5852 return status;
Benny Halevyc0eae662009-08-14 17:20:14 +03005853out_overflow:
5854 print_overflow_msg(__func__, xdr);
5855 status = -EIO;
5856 goto out_err;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005857#else /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005858 return 0;
Andy Adamsonfc01cea2009-04-01 09:22:36 -04005859#endif /* CONFIG_NFS_V4_1 */
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04005860}
5861
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005862#if defined(CONFIG_NFS_V4_1)
Trond Myklebust93b717f2016-05-16 17:42:43 -04005863static int decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid)
5864{
5865 stateid->type = NFS4_LAYOUT_STATEID_TYPE;
5866 return decode_stateid(xdr, stateid);
5867}
5868
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005869static int decode_getdeviceinfo(struct xdr_stream *xdr,
Trond Myklebust4e590802015-03-09 14:01:25 -04005870 struct nfs4_getdeviceinfo_res *res)
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005871{
Trond Myklebust4e590802015-03-09 14:01:25 -04005872 struct pnfs_device *pdev = res->pdev;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005873 __be32 *p;
5874 uint32_t len, type;
5875 int status;
5876
5877 status = decode_op_hdr(xdr, OP_GETDEVICEINFO);
5878 if (status) {
5879 if (status == -ETOOSMALL) {
5880 p = xdr_inline_decode(xdr, 4);
5881 if (unlikely(!p))
5882 goto out_overflow;
5883 pdev->mincount = be32_to_cpup(p);
5884 dprintk("%s: Min count too small. mincnt = %u\n",
5885 __func__, pdev->mincount);
5886 }
5887 return status;
5888 }
5889
5890 p = xdr_inline_decode(xdr, 8);
5891 if (unlikely(!p))
5892 goto out_overflow;
5893 type = be32_to_cpup(p++);
5894 if (type != pdev->layout_type) {
5895 dprintk("%s: layout mismatch req: %u pdev: %u\n",
5896 __func__, pdev->layout_type, type);
5897 return -EINVAL;
5898 }
5899 /*
5900 * Get the length of the opaque device_addr4. xdr_read_pages places
5901 * the opaque device_addr4 in the xdr_buf->pages (pnfs_device->pages)
5902 * and places the remaining xdr data in xdr_buf->tail
5903 */
5904 pdev->mincount = be32_to_cpup(p);
Trond Myklebust13fe4ba2012-08-01 14:21:12 -04005905 if (xdr_read_pages(xdr, pdev->mincount) != pdev->mincount)
5906 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005907
5908 /* Parse notification bitmap, verifying that it is zero. */
5909 p = xdr_inline_decode(xdr, 4);
5910 if (unlikely(!p))
5911 goto out_overflow;
5912 len = be32_to_cpup(p);
5913 if (len) {
Chuck Leveread00592010-12-14 14:58:21 +00005914 uint32_t i;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005915
5916 p = xdr_inline_decode(xdr, 4 * len);
5917 if (unlikely(!p))
5918 goto out_overflow;
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005919
Trond Myklebust4e590802015-03-09 14:01:25 -04005920 res->notification = be32_to_cpup(p++);
Christoph Hellwig84c9dee2014-09-10 17:37:28 -07005921 for (i = 1; i < len; i++) {
5922 if (be32_to_cpup(p++)) {
5923 dprintk("%s: unsupported notification\n",
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005924 __func__);
5925 return -EIO;
5926 }
5927 }
5928 }
5929 return 0;
5930out_overflow:
5931 print_overflow_msg(__func__, xdr);
5932 return -EIO;
5933}
5934
5935static int decode_layoutget(struct xdr_stream *xdr, struct rpc_rqst *req,
5936 struct nfs4_layoutget_res *res)
5937{
5938 __be32 *p;
5939 int status;
5940 u32 layout_count;
Trond Myklebust64bd5772012-06-20 22:35:05 -04005941 u32 recvd;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005942
5943 status = decode_op_hdr(xdr, OP_LAYOUTGET);
5944 if (status)
5945 return status;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005946 p = xdr_inline_decode(xdr, 4);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005947 if (unlikely(!p))
5948 goto out_overflow;
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005949 res->return_on_close = be32_to_cpup(p);
Trond Myklebust93b717f2016-05-16 17:42:43 -04005950 decode_layout_stateid(xdr, &res->stateid);
Trond Myklebustea9d23f2012-03-04 18:13:56 -05005951 p = xdr_inline_decode(xdr, 4);
5952 if (unlikely(!p))
5953 goto out_overflow;
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005954 layout_count = be32_to_cpup(p);
5955 if (!layout_count) {
5956 dprintk("%s: server responded with empty layout array\n",
5957 __func__);
5958 return -EINVAL;
5959 }
5960
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005961 p = xdr_inline_decode(xdr, 28);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005962 if (unlikely(!p))
5963 goto out_overflow;
5964 p = xdr_decode_hyper(p, &res->range.offset);
5965 p = xdr_decode_hyper(p, &res->range.length);
5966 res->range.iomode = be32_to_cpup(p++);
5967 res->type = be32_to_cpup(p++);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005968 res->layoutp->len = be32_to_cpup(p);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005969
5970 dprintk("%s roff:%lu rlen:%lu riomode:%d, lo_type:0x%x, lo.len:%d\n",
5971 __func__,
5972 (unsigned long)res->range.offset,
5973 (unsigned long)res->range.length,
5974 res->range.iomode,
5975 res->type,
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005976 res->layoutp->len);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005977
Trond Myklebust64bd5772012-06-20 22:35:05 -04005978 recvd = xdr_read_pages(xdr, res->layoutp->len);
Weston Andros Adamson35124a02011-03-24 16:48:21 -04005979 if (res->layoutp->len > recvd) {
5980 dprintk("NFS: server cheating in layoutget reply: "
5981 "layout len %u > recvd %u\n",
5982 res->layoutp->len, recvd);
5983 return -EINVAL;
5984 }
5985
Andy Adamsonb1f69b72010-10-20 00:18:03 -04005986 if (layout_count > 1) {
5987 /* We only handle a length one array at the moment. Any
5988 * further entries are just ignored. Note that this means
5989 * the client may see a response that is less than the
5990 * minimum it requested.
5991 */
5992 dprintk("%s: server responded with %d layouts, dropping tail\n",
5993 __func__, layout_count);
5994 }
5995
5996 return 0;
5997out_overflow:
5998 print_overflow_msg(__func__, xdr);
5999 return -EIO;
6000}
Andy Adamson863a3c62011-03-23 13:27:54 +00006001
Benny Halevycbe82602011-05-22 19:52:37 +03006002static int decode_layoutreturn(struct xdr_stream *xdr,
6003 struct nfs4_layoutreturn_res *res)
6004{
6005 __be32 *p;
6006 int status;
6007
6008 status = decode_op_hdr(xdr, OP_LAYOUTRETURN);
6009 if (status)
6010 return status;
6011 p = xdr_inline_decode(xdr, 4);
6012 if (unlikely(!p))
6013 goto out_overflow;
6014 res->lrs_present = be32_to_cpup(p);
6015 if (res->lrs_present)
Trond Myklebust93b717f2016-05-16 17:42:43 -04006016 status = decode_layout_stateid(xdr, &res->stateid);
Benny Halevycbe82602011-05-22 19:52:37 +03006017 return status;
6018out_overflow:
6019 print_overflow_msg(__func__, xdr);
6020 return -EIO;
6021}
6022
Andy Adamson863a3c62011-03-23 13:27:54 +00006023static int decode_layoutcommit(struct xdr_stream *xdr,
6024 struct rpc_rqst *req,
6025 struct nfs4_layoutcommit_res *res)
6026{
6027 __be32 *p;
6028 __u32 sizechanged;
6029 int status;
6030
6031 status = decode_op_hdr(xdr, OP_LAYOUTCOMMIT);
Andy Adamsondb29c082011-07-30 20:52:38 -04006032 res->status = status;
Andy Adamson863a3c62011-03-23 13:27:54 +00006033 if (status)
6034 return status;
6035
6036 p = xdr_inline_decode(xdr, 4);
6037 if (unlikely(!p))
6038 goto out_overflow;
6039 sizechanged = be32_to_cpup(p);
6040
6041 if (sizechanged) {
6042 /* throw away new size */
6043 p = xdr_inline_decode(xdr, 8);
6044 if (unlikely(!p))
6045 goto out_overflow;
6046 }
6047 return 0;
6048out_overflow:
6049 print_overflow_msg(__func__, xdr);
6050 return -EIO;
6051}
Bryan Schumaker7d974792011-06-02 14:59:08 -04006052
6053static int decode_test_stateid(struct xdr_stream *xdr,
6054 struct nfs41_test_stateid_res *res)
6055{
6056 __be32 *p;
6057 int status;
6058 int num_res;
6059
6060 status = decode_op_hdr(xdr, OP_TEST_STATEID);
6061 if (status)
6062 return status;
6063
6064 p = xdr_inline_decode(xdr, 4);
6065 if (unlikely(!p))
6066 goto out_overflow;
6067 num_res = be32_to_cpup(p++);
6068 if (num_res != 1)
6069 goto out;
6070
6071 p = xdr_inline_decode(xdr, 4);
6072 if (unlikely(!p))
6073 goto out_overflow;
6074 res->status = be32_to_cpup(p++);
Bryan Schumaker1cab0652012-01-31 10:39:29 -05006075
6076 return status;
Bryan Schumaker7d974792011-06-02 14:59:08 -04006077out_overflow:
6078 print_overflow_msg(__func__, xdr);
6079out:
6080 return -EIO;
6081}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006082
6083static int decode_free_stateid(struct xdr_stream *xdr,
6084 struct nfs41_free_stateid_res *res)
6085{
Andy Adamson9f79fb42013-09-10 12:56:29 -04006086 res->status = decode_op_hdr(xdr, OP_FREE_STATEID);
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006087 return res->status;
Bryan Schumaker9aeda352011-06-02 14:59:09 -04006088}
Trond Myklebustcf805162016-11-15 14:56:07 -05006089#else
6090static inline
6091int decode_layoutreturn(struct xdr_stream *xdr,
6092 struct nfs4_layoutreturn_res *res)
6093{
6094 return 0;
6095}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04006096#endif /* CONFIG_NFS_V4_1 */
6097
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098/*
Benny Halevy49c25592008-12-23 16:06:16 -05006099 * END OF "GENERIC" DECODE ROUTINES.
6100 */
6101
6102/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006103 * Decode OPEN_DOWNGRADE response
6104 */
Chuck Leverbf269552010-12-14 14:59:29 +00006105static int nfs4_xdr_dec_open_downgrade(struct rpc_rqst *rqstp,
6106 struct xdr_stream *xdr,
6107 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006108{
Andy Adamson05d564f2008-12-23 16:06:15 -05006109 struct compound_hdr hdr;
6110 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006111
Chuck Leverbf269552010-12-14 14:59:29 +00006112 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006113 if (status)
6114 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006115 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006116 if (status)
6117 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006118 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006119 if (status)
6120 goto out;
Trond Myklebustb6808142016-11-20 13:34:16 -05006121 if (res->lr_res) {
6122 status = decode_layoutreturn(xdr, res->lr_res);
6123 res->lr_ret = status;
6124 if (status)
6125 goto out;
6126 }
Chuck Leverbf269552010-12-14 14:59:29 +00006127 status = decode_open_downgrade(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006128out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006129 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006130}
6131
6132/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 * Decode ACCESS response
6134 */
Chuck Leverbf269552010-12-14 14:59:29 +00006135static int nfs4_xdr_dec_access(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6136 struct nfs4_accessres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006138 struct compound_hdr hdr;
6139 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006140
Chuck Leverbf269552010-12-14 14:59:29 +00006141 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006142 if (status)
6143 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006144 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006145 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006146 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006147 status = decode_putfh(xdr);
Trond Myklebust76b32992007-08-10 17:45:11 -04006148 if (status != 0)
6149 goto out;
Weston Andros Adamson6168f622012-09-10 14:00:46 -04006150 status = decode_access(xdr, &res->supported, &res->access);
Trond Myklebust76b32992007-08-10 17:45:11 -04006151 if (status != 0)
6152 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05006153 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006154out:
6155 return status;
6156}
6157
6158/*
6159 * Decode LOOKUP response
6160 */
Chuck Leverbf269552010-12-14 14:59:29 +00006161static int nfs4_xdr_dec_lookup(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6162 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006163{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006164 struct compound_hdr hdr;
6165 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006166
Chuck Leverbf269552010-12-14 14:59:29 +00006167 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006168 if (status)
6169 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006170 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006171 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006172 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006173 status = decode_putfh(xdr);
6174 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006175 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006176 status = decode_lookup(xdr);
6177 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006178 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006179 status = decode_getfh(xdr, res->fh);
6180 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006181 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006182 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183out:
6184 return status;
6185}
6186
6187/*
6188 * Decode LOOKUP_ROOT response
6189 */
Chuck Leverbf269552010-12-14 14:59:29 +00006190static int nfs4_xdr_dec_lookup_root(struct rpc_rqst *rqstp,
6191 struct xdr_stream *xdr,
6192 struct nfs4_lookup_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006193{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006194 struct compound_hdr hdr;
6195 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006196
Chuck Leverbf269552010-12-14 14:59:29 +00006197 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006198 if (status)
6199 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006200 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006201 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006202 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006203 status = decode_putrootfh(xdr);
6204 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006205 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006206 status = decode_getfh(xdr, res->fh);
6207 if (status == 0)
David Quigleyaa9c2662013-05-22 12:50:44 -04006208 status = decode_getfattr_label(xdr, res->fattr,
6209 res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210out:
6211 return status;
6212}
6213
6214/*
6215 * Decode REMOVE response
6216 */
Chuck Leverbf269552010-12-14 14:59:29 +00006217static int nfs4_xdr_dec_remove(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6218 struct nfs_removeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220 struct compound_hdr hdr;
6221 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006222
Chuck Leverbf269552010-12-14 14:59:29 +00006223 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006224 if (status)
6225 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006226 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006227 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006228 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006229 status = decode_putfh(xdr);
6230 if (status)
Trond Myklebust16e42952005-10-27 22:12:44 -04006231 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006232 status = decode_remove(xdr, &res->cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006233out:
6234 return status;
6235}
6236
6237/*
6238 * Decode RENAME response
6239 */
Chuck Leverbf269552010-12-14 14:59:29 +00006240static int nfs4_xdr_dec_rename(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6241 struct nfs_renameres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 struct compound_hdr hdr;
6244 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006245
Chuck Leverbf269552010-12-14 14:59:29 +00006246 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006247 if (status)
6248 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006249 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006250 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006252 status = decode_putfh(xdr);
6253 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006254 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006255 status = decode_savefh(xdr);
6256 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006258 status = decode_putfh(xdr);
6259 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006260 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006261 status = decode_rename(xdr, &res->old_cinfo, &res->new_cinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006262out:
6263 return status;
6264}
6265
6266/*
6267 * Decode LINK response
6268 */
Chuck Leverbf269552010-12-14 14:59:29 +00006269static int nfs4_xdr_dec_link(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6270 struct nfs4_link_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006272 struct compound_hdr hdr;
6273 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006274
Chuck Leverbf269552010-12-14 14:59:29 +00006275 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006276 if (status)
6277 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006278 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006279 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006280 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006281 status = decode_putfh(xdr);
6282 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006283 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006284 status = decode_savefh(xdr);
6285 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006286 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006287 status = decode_putfh(xdr);
6288 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006289 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006290 status = decode_link(xdr, &res->cinfo);
6291 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006292 goto out;
6293 /*
6294 * Note order: OP_LINK leaves the directory as the current
6295 * filehandle.
6296 */
Chuck Leverbf269552010-12-14 14:59:29 +00006297 status = decode_restorefh(xdr);
6298 if (status)
Trond Myklebust91ba2ee2005-10-27 22:12:42 -04006299 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006300 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006301out:
6302 return status;
6303}
6304
6305/*
6306 * Decode CREATE response
6307 */
Chuck Leverbf269552010-12-14 14:59:29 +00006308static int nfs4_xdr_dec_create(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6309 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006310{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006311 struct compound_hdr hdr;
6312 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006313
Chuck Leverbf269552010-12-14 14:59:29 +00006314 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006315 if (status)
6316 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006317 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006318 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006319 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006320 status = decode_putfh(xdr);
6321 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006322 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006323 status = decode_create(xdr, &res->dir_cinfo);
6324 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006325 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006326 status = decode_getfh(xdr, res->fh);
6327 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006328 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006329 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006330out:
6331 return status;
6332}
6333
6334/*
6335 * Decode SYMLINK response
6336 */
Chuck Leverbf269552010-12-14 14:59:29 +00006337static int nfs4_xdr_dec_symlink(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6338 struct nfs4_create_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006339{
Chuck Leverbf269552010-12-14 14:59:29 +00006340 return nfs4_xdr_dec_create(rqstp, xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006341}
6342
6343/*
6344 * Decode GETATTR response
6345 */
Chuck Leverbf269552010-12-14 14:59:29 +00006346static int nfs4_xdr_dec_getattr(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6347 struct nfs4_getattr_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006348{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006349 struct compound_hdr hdr;
6350 int status;
Andy Adamson6c0195a2008-12-23 16:06:15 -05006351
Chuck Leverbf269552010-12-14 14:59:29 +00006352 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006353 if (status)
6354 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006355 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006356 if (status)
6357 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006358 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006359 if (status)
6360 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006361 status = decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006362out:
6363 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006364}
6365
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006366/*
6367 * Encode an SETACL request
6368 */
Chuck Lever9f06c712010-12-14 14:59:18 +00006369static void nfs4_xdr_enc_setacl(struct rpc_rqst *req, struct xdr_stream *xdr,
6370 struct nfs_setaclargs *args)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006371{
Andy Adamson05d564f2008-12-23 16:06:15 -05006372 struct compound_hdr hdr = {
Benny Halevy66cc0422009-04-01 09:22:10 -04006373 .minorversion = nfs4_xdr_minorversion(&args->seq_args),
Andy Adamson05d564f2008-12-23 16:06:15 -05006374 };
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006375
Chuck Lever9f06c712010-12-14 14:59:18 +00006376 encode_compound_hdr(xdr, req, &hdr);
6377 encode_sequence(xdr, &args->seq_args, &hdr);
6378 encode_putfh(xdr, args->fh, &hdr);
6379 encode_setacl(xdr, args, &hdr);
Andy Adamsond0179312008-12-23 16:06:17 -05006380 encode_nops(&hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006381}
Andy Adamson05d564f2008-12-23 16:06:15 -05006382
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006383/*
6384 * Decode SETACL response
6385 */
6386static int
Chuck Leverbf269552010-12-14 14:59:29 +00006387nfs4_xdr_dec_setacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy73c403a2009-04-01 09:22:01 -04006388 struct nfs_setaclres *res)
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006389{
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006390 struct compound_hdr hdr;
6391 int status;
6392
Chuck Leverbf269552010-12-14 14:59:29 +00006393 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006394 if (status)
6395 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006396 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006397 if (status)
6398 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006399 status = decode_putfh(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006400 if (status)
6401 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006402 status = decode_setattr(xdr);
J. Bruce Fields23ec6962005-06-22 17:16:22 +00006403out:
6404 return status;
6405}
Linus Torvalds1da177e2005-04-16 15:20:36 -07006406
6407/*
J. Bruce Fields029d1052005-06-22 17:16:22 +00006408 * Decode GETACL response
6409 */
6410static int
Chuck Leverbf269552010-12-14 14:59:29 +00006411nfs4_xdr_dec_getacl(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Benny Halevy663c79b2009-04-01 09:21:59 -04006412 struct nfs_getaclres *res)
J. Bruce Fields029d1052005-06-22 17:16:22 +00006413{
J. Bruce Fields029d1052005-06-22 17:16:22 +00006414 struct compound_hdr hdr;
6415 int status;
6416
Trond Myklebust331818f2012-02-03 18:30:53 -05006417 if (res->acl_scratch != NULL) {
6418 void *p = page_address(res->acl_scratch);
6419 xdr_set_scratch_buffer(xdr, p, PAGE_SIZE);
6420 }
Chuck Leverbf269552010-12-14 14:59:29 +00006421 status = decode_compound_hdr(xdr, &hdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006422 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)
6426 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006427 status = decode_putfh(xdr);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006428 if (status)
6429 goto out;
Andy Adamsonbf118a32011-12-07 11:55:27 -05006430 status = decode_getacl(xdr, rqstp, res);
J. Bruce Fields029d1052005-06-22 17:16:22 +00006431
6432out:
6433 return status;
6434}
6435
6436/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006437 * Decode CLOSE response
6438 */
Chuck Leverbf269552010-12-14 14:59:29 +00006439static int nfs4_xdr_dec_close(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6440 struct nfs_closeres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006441{
Andy Adamson05d564f2008-12-23 16:06:15 -05006442 struct compound_hdr hdr;
6443 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006444
Chuck Leverbf269552010-12-14 14:59:29 +00006445 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006446 if (status)
6447 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006448 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006449 if (status)
6450 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006451 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006452 if (status)
6453 goto out;
Trond Myklebustcf805162016-11-15 14:56:07 -05006454 if (res->lr_res) {
6455 status = decode_layoutreturn(xdr, res->lr_res);
6456 res->lr_ret = status;
6457 if (status)
6458 goto out;
6459 }
Trond Myklebustd8d84982016-12-19 12:14:44 -05006460 if (res->fattr != NULL) {
6461 status = decode_getfattr(xdr, res->fattr, res->server);
6462 if (status != 0)
6463 goto out;
6464 }
Chuck Leverbf269552010-12-14 14:59:29 +00006465 status = decode_close(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006466out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006467 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006468}
6469
6470/*
6471 * Decode OPEN response
6472 */
Chuck Leverbf269552010-12-14 14:59:29 +00006473static int nfs4_xdr_dec_open(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6474 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006475{
Andy Adamson05d564f2008-12-23 16:06:15 -05006476 struct compound_hdr hdr;
6477 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006478
Chuck Leverbf269552010-12-14 14:59:29 +00006479 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebust56ae19f2005-10-27 22:12:40 -04006480 if (status)
6481 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006482 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006483 if (status)
6484 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006485 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006486 if (status)
6487 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006488 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006489 if (status)
6490 goto out;
Weston Andros Adamson01913b42012-09-06 15:54:27 -04006491 status = decode_getfh(xdr, &res->fh);
6492 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006493 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006494 if (res->access_request)
6495 decode_access(xdr, &res->access_supported, &res->access_result);
David Quigleyaa9c2662013-05-22 12:50:44 -04006496 decode_getfattr_label(xdr, res->f_attr, res->f_label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006497out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006498 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006499}
6500
6501/*
6502 * Decode OPEN_CONFIRM response
6503 */
Chuck Leverbf269552010-12-14 14:59:29 +00006504static int nfs4_xdr_dec_open_confirm(struct rpc_rqst *rqstp,
6505 struct xdr_stream *xdr,
6506 struct nfs_open_confirmres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006507{
Andy Adamson05d564f2008-12-23 16:06:15 -05006508 struct compound_hdr hdr;
6509 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006510
Chuck Leverbf269552010-12-14 14:59:29 +00006511 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006512 if (status)
6513 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006514 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006515 if (status)
6516 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006517 status = decode_open_confirm(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006518out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006519 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006520}
6521
6522/*
6523 * Decode OPEN response
6524 */
Chuck Leverbf269552010-12-14 14:59:29 +00006525static int nfs4_xdr_dec_open_noattr(struct rpc_rqst *rqstp,
6526 struct xdr_stream *xdr,
6527 struct nfs_openres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006528{
Andy Adamson05d564f2008-12-23 16:06:15 -05006529 struct compound_hdr hdr;
6530 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006531
Chuck Leverbf269552010-12-14 14:59:29 +00006532 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006533 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);
Andy Adamson05d564f2008-12-23 16:06:15 -05006539 if (status)
6540 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006541 status = decode_open(xdr, res);
Andy Adamson05d564f2008-12-23 16:06:15 -05006542 if (status)
6543 goto out;
Weston Andros Adamsonae2bb032012-10-02 14:49:52 -07006544 if (res->access_request)
6545 decode_access(xdr, &res->access_supported, &res->access_result);
Trond Myklebust6926afd2012-01-07 13:22:46 -05006546 decode_getfattr(xdr, res->f_attr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006547out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006548 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006549}
6550
6551/*
6552 * Decode SETATTR response
6553 */
Chuck Leverbf269552010-12-14 14:59:29 +00006554static int nfs4_xdr_dec_setattr(struct rpc_rqst *rqstp,
6555 struct xdr_stream *xdr,
6556 struct nfs_setattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006557{
Andy Adamson05d564f2008-12-23 16:06:15 -05006558 struct compound_hdr hdr;
6559 int status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006560
Chuck Leverbf269552010-12-14 14:59:29 +00006561 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006562 if (status)
6563 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006564 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006565 if (status)
6566 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006567 status = decode_putfh(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006568 if (status)
6569 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006570 status = decode_setattr(xdr);
Andy Adamson05d564f2008-12-23 16:06:15 -05006571 if (status)
6572 goto out;
David Quigleyaa9c2662013-05-22 12:50:44 -04006573 decode_getfattr_label(xdr, res->fattr, res->label, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006574out:
Andy Adamson05d564f2008-12-23 16:06:15 -05006575 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006576}
6577
6578/*
6579 * Decode LOCK response
6580 */
Chuck Leverbf269552010-12-14 14:59:29 +00006581static int nfs4_xdr_dec_lock(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6582 struct nfs_lock_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006583{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006584 struct compound_hdr hdr;
6585 int status;
6586
Chuck Leverbf269552010-12-14 14:59:29 +00006587 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006588 if (status)
6589 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006590 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006591 if (status)
6592 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006593 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006594 if (status)
6595 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006596 status = decode_lock(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006597out:
6598 return status;
6599}
6600
6601/*
6602 * Decode LOCKT response
6603 */
Chuck Leverbf269552010-12-14 14:59:29 +00006604static int nfs4_xdr_dec_lockt(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6605 struct nfs_lockt_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006606{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006607 struct compound_hdr hdr;
6608 int status;
6609
Chuck Leverbf269552010-12-14 14:59:29 +00006610 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006611 if (status)
6612 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006613 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006614 if (status)
6615 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006616 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006617 if (status)
6618 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006619 status = decode_lockt(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006620out:
6621 return status;
6622}
6623
6624/*
6625 * Decode LOCKU response
6626 */
Chuck Leverbf269552010-12-14 14:59:29 +00006627static int nfs4_xdr_dec_locku(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6628 struct nfs_locku_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006629{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006630 struct compound_hdr hdr;
6631 int status;
6632
Chuck Leverbf269552010-12-14 14:59:29 +00006633 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006634 if (status)
6635 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006636 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006637 if (status)
6638 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006639 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006640 if (status)
6641 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006642 status = decode_locku(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006643out:
6644 return status;
6645}
6646
Chuck Leverbf269552010-12-14 14:59:29 +00006647static int nfs4_xdr_dec_release_lockowner(struct rpc_rqst *rqstp,
6648 struct xdr_stream *xdr, void *dummy)
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006649{
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006650 struct compound_hdr hdr;
6651 int status;
6652
Chuck Leverbf269552010-12-14 14:59:29 +00006653 status = decode_compound_hdr(xdr, &hdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006654 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006655 status = decode_release_lockowner(xdr);
Trond Myklebustd3c7b7c2010-07-01 12:49:01 -04006656 return status;
6657}
6658
Linus Torvalds1da177e2005-04-16 15:20:36 -07006659/*
6660 * Decode READLINK response
6661 */
Chuck Leverbf269552010-12-14 14:59:29 +00006662static int nfs4_xdr_dec_readlink(struct rpc_rqst *rqstp,
6663 struct xdr_stream *xdr,
Benny Halevyf50c7002009-04-01 09:21:55 -04006664 struct nfs4_readlink_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006665{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006666 struct compound_hdr hdr;
6667 int status;
6668
Chuck Leverbf269552010-12-14 14:59:29 +00006669 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006670 if (status)
6671 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006672 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006673 if (status)
6674 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006675 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006676 if (status)
6677 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006678 status = decode_readlink(xdr, rqstp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006679out:
6680 return status;
6681}
6682
6683/*
6684 * Decode READDIR response
6685 */
Chuck Leverbf269552010-12-14 14:59:29 +00006686static int nfs4_xdr_dec_readdir(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6687 struct nfs4_readdir_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006688{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006689 struct compound_hdr hdr;
6690 int status;
6691
Chuck Leverbf269552010-12-14 14:59:29 +00006692 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693 if (status)
6694 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006695 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006696 if (status)
6697 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006698 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006699 if (status)
6700 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006701 status = decode_readdir(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006702out:
6703 return status;
6704}
6705
6706/*
6707 * Decode Read response
6708 */
Chuck Leverbf269552010-12-14 14:59:29 +00006709static int nfs4_xdr_dec_read(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006710 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006711{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006712 struct compound_hdr hdr;
6713 int status;
6714
Chuck Leverbf269552010-12-14 14:59:29 +00006715 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006716 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006717 if (status)
6718 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006719 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006720 if (status)
6721 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006722 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006723 if (status)
6724 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006725 status = decode_read(xdr, rqstp, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006726 if (!status)
6727 status = res->count;
6728out:
6729 return status;
6730}
6731
6732/*
6733 * Decode WRITE response
6734 */
Chuck Leverbf269552010-12-14 14:59:29 +00006735static int nfs4_xdr_dec_write(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Anna Schumaker9137bdf2014-05-06 09:12:25 -04006736 struct nfs_pgio_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006737{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006738 struct compound_hdr hdr;
6739 int status;
6740
Chuck Leverbf269552010-12-14 14:59:29 +00006741 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006742 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006743 if (status)
6744 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006745 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006746 if (status)
6747 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006748 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006749 if (status)
6750 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006751 status = decode_write(xdr, res);
Trond Myklebust4f9838c2005-10-27 22:12:44 -04006752 if (status)
6753 goto out;
Fred Isaman7ffd1062011-03-03 15:13:46 +00006754 if (res->fattr)
Trond Myklebust6926afd2012-01-07 13:22:46 -05006755 decode_getfattr(xdr, res->fattr, res->server);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006756 if (!status)
6757 status = res->count;
6758out:
6759 return status;
6760}
6761
6762/*
6763 * Decode COMMIT response
6764 */
Chuck Leverbf269552010-12-14 14:59:29 +00006765static int nfs4_xdr_dec_commit(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
Fred Isaman0b7c0152012-04-20 14:47:39 -04006766 struct nfs_commitres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006767{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006768 struct compound_hdr hdr;
6769 int status;
6770
Chuck Leverbf269552010-12-14 14:59:29 +00006771 status = decode_compound_hdr(xdr, &hdr);
Peng Taoaabff4d2014-08-27 10:47:14 +08006772 res->op_status = hdr.status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006773 if (status)
6774 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006775 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006776 if (status)
6777 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006778 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006779 if (status)
6780 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006781 status = decode_commit(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006782out:
6783 return status;
6784}
6785
6786/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006787 * Decode FSINFO response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006788 */
Chuck Leverbf269552010-12-14 14:59:29 +00006789static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy3dda5e42009-04-01 09:21:57 -04006790 struct nfs4_fsinfo_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006791{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006792 struct compound_hdr hdr;
6793 int status;
6794
Chuck Leverbf269552010-12-14 14:59:29 +00006795 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006797 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006798 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006799 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006800 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006801 status = decode_fsinfo(xdr, res->fsinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006802 return status;
6803}
6804
6805/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006806 * Decode PATHCONF response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006807 */
Chuck Leverbf269552010-12-14 14:59:29 +00006808static int nfs4_xdr_dec_pathconf(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevyd45b2982009-04-01 09:21:58 -04006809 struct nfs4_pathconf_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006810{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006811 struct compound_hdr hdr;
6812 int status;
6813
Chuck Leverbf269552010-12-14 14:59:29 +00006814 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006815 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006816 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006817 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006818 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006819 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006820 status = decode_pathconf(xdr, res->pathconf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006821 return status;
6822}
6823
6824/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006825 * Decode STATFS response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006826 */
Chuck Leverbf269552010-12-14 14:59:29 +00006827static int nfs4_xdr_dec_statfs(struct rpc_rqst *req, struct xdr_stream *xdr,
Benny Halevy24ad1482009-04-01 09:21:56 -04006828 struct nfs4_statfs_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006829{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830 struct compound_hdr hdr;
6831 int status;
6832
Chuck Leverbf269552010-12-14 14:59:29 +00006833 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006835 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006836 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006837 status = decode_putfh(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006838 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006839 status = decode_statfs(xdr, res->fsstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006840 return status;
6841}
6842
6843/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006844 * Decode GETATTR_BITMAP response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006845 */
Chuck Leverbf269552010-12-14 14:59:29 +00006846static int nfs4_xdr_dec_server_caps(struct rpc_rqst *req,
6847 struct xdr_stream *xdr,
6848 struct nfs4_server_caps_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006849{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006850 struct compound_hdr hdr;
6851 int status;
6852
Chuck Leverbf269552010-12-14 14:59:29 +00006853 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006854 if (status)
6855 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006856 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006857 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006858 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006859 status = decode_putfh(xdr);
6860 if (status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006861 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006862 status = decode_server_caps(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006863out:
6864 return status;
6865}
6866
6867/*
6868 * Decode RENEW response
6869 */
Chuck Leverbf269552010-12-14 14:59:29 +00006870static int nfs4_xdr_dec_renew(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
6871 void *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006872{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 struct compound_hdr hdr;
6874 int status;
6875
Chuck Leverbf269552010-12-14 14:59:29 +00006876 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006877 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006878 status = decode_renew(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006879 return status;
6880}
6881
6882/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006883 * Decode SETCLIENTID response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006884 */
Chuck Leverbf269552010-12-14 14:59:29 +00006885static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req,
6886 struct xdr_stream *xdr,
6887 struct nfs4_setclientid_res *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006888{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006889 struct compound_hdr hdr;
6890 int status;
6891
Chuck Leverbf269552010-12-14 14:59:29 +00006892 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006893 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006894 status = decode_setclientid(xdr, res);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895 return status;
6896}
6897
6898/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006899 * Decode SETCLIENTID_CONFIRM response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006900 */
Chuck Leverbf269552010-12-14 14:59:29 +00006901static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req,
Chuck Lever83ca7f52013-03-16 15:55:53 -04006902 struct xdr_stream *xdr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006903{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006904 struct compound_hdr hdr;
6905 int status;
6906
Chuck Leverbf269552010-12-14 14:59:29 +00006907 status = decode_compound_hdr(xdr, &hdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006908 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00006909 status = decode_setclientid_confirm(xdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 return status;
6911}
6912
6913/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006914 * Decode DELEGRETURN response
Linus Torvalds1da177e2005-04-16 15:20:36 -07006915 */
Chuck Leverbf269552010-12-14 14:59:29 +00006916static int nfs4_xdr_dec_delegreturn(struct rpc_rqst *rqstp,
6917 struct xdr_stream *xdr,
6918 struct nfs4_delegreturnres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006919{
Linus Torvalds1da177e2005-04-16 15:20:36 -07006920 struct compound_hdr hdr;
6921 int status;
6922
Chuck Leverbf269552010-12-14 14:59:29 +00006923 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006924 if (status)
6925 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006926 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006927 if (status)
Trond Myklebustfa178f22006-01-03 09:55:38 +01006928 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006929 status = decode_putfh(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006930 if (status != 0)
6931 goto out;
Trond Myklebust586f1c32016-11-15 15:03:33 -05006932 if (res->lr_res) {
6933 status = decode_layoutreturn(xdr, res->lr_res);
6934 res->lr_ret = status;
6935 if (status)
6936 goto out;
6937 }
Trond Myklebust8ac2b4222016-12-19 10:23:10 -05006938 if (res->fattr) {
6939 status = decode_getfattr(xdr, res->fattr, res->server);
6940 if (status != 0)
6941 goto out;
6942 }
Trond Myklebuste144cbc2012-04-28 16:05:03 -04006943 status = decode_delegreturn(xdr);
Trond Myklebustfa178f22006-01-03 09:55:38 +01006944out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 return status;
6946}
6947
Trond Myklebust683b57b2006-06-09 09:34:22 -04006948/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05006949 * Decode FS_LOCATIONS response
Trond Myklebust683b57b2006-06-09 09:34:22 -04006950 */
Chuck Leverbf269552010-12-14 14:59:29 +00006951static int nfs4_xdr_dec_fs_locations(struct rpc_rqst *req,
6952 struct xdr_stream *xdr,
Benny Halevy22958462009-04-01 09:22:02 -04006953 struct nfs4_fs_locations_res *res)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006954{
Trond Myklebust683b57b2006-06-09 09:34:22 -04006955 struct compound_hdr hdr;
6956 int status;
6957
Chuck Leverbf269552010-12-14 14:59:29 +00006958 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006959 if (status)
6960 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006961 status = decode_sequence(xdr, &res->seq_res, req);
Andy Adamson9b7b9fc2009-04-01 09:22:11 -04006962 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006963 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00006964 status = decode_putfh(xdr);
6965 if (status)
Trond Myklebust683b57b2006-06-09 09:34:22 -04006966 goto out;
Chuck Leverb03d7352013-10-17 14:12:50 -04006967 if (res->migration) {
6968 xdr_enter_page(xdr, PAGE_SIZE);
6969 status = decode_getfattr_generic(xdr,
6970 &res->fs_locations->fattr,
Trond Myklebust8b7e3f42012-01-30 15:43:56 -05006971 NULL, res->fs_locations,
David Quigleyaa9c2662013-05-22 12:50:44 -04006972 NULL, res->fs_locations->server);
Chuck Leverb03d7352013-10-17 14:12:50 -04006973 if (status)
6974 goto out;
6975 if (res->renew)
6976 status = decode_renew(xdr);
6977 } else {
6978 status = decode_lookup(xdr);
6979 if (status)
6980 goto out;
6981 xdr_enter_page(xdr, PAGE_SIZE);
6982 status = decode_getfattr_generic(xdr,
6983 &res->fs_locations->fattr,
6984 NULL, res->fs_locations,
6985 NULL, res->fs_locations->server);
6986 }
Trond Myklebust683b57b2006-06-09 09:34:22 -04006987out:
6988 return status;
6989}
6990
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00006991/*
6992 * Decode SECINFO response
6993 */
6994static int nfs4_xdr_dec_secinfo(struct rpc_rqst *rqstp,
6995 struct xdr_stream *xdr,
6996 struct nfs4_secinfo_res *res)
6997{
6998 struct compound_hdr hdr;
6999 int status;
7000
7001 status = decode_compound_hdr(xdr, &hdr);
7002 if (status)
7003 goto out;
7004 status = decode_sequence(xdr, &res->seq_res, rqstp);
7005 if (status)
7006 goto out;
7007 status = decode_putfh(xdr);
7008 if (status)
7009 goto out;
7010 status = decode_secinfo(xdr, res);
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007011out:
7012 return status;
7013}
7014
Chuck Lever44c99932013-10-17 14:13:30 -04007015/*
7016 * Decode FSID_PRESENT response
7017 */
7018static int nfs4_xdr_dec_fsid_present(struct rpc_rqst *rqstp,
7019 struct xdr_stream *xdr,
7020 struct nfs4_fsid_present_res *res)
7021{
7022 struct compound_hdr hdr;
7023 int status;
7024
7025 status = decode_compound_hdr(xdr, &hdr);
7026 if (status)
7027 goto out;
7028 status = decode_sequence(xdr, &res->seq_res, rqstp);
7029 if (status)
7030 goto out;
7031 status = decode_putfh(xdr);
7032 if (status)
7033 goto out;
7034 status = decode_getfh(xdr, res->fh);
7035 if (status)
7036 goto out;
7037 if (res->renew)
7038 status = decode_renew(xdr);
7039out:
7040 return status;
7041}
7042
Benny Halevy99fe60d2009-04-01 09:22:29 -04007043#if defined(CONFIG_NFS_V4_1)
7044/*
Weston Andros Adamson7c44f1ae2012-05-24 13:22:50 -04007045 * Decode BIND_CONN_TO_SESSION response
7046 */
7047static int nfs4_xdr_dec_bind_conn_to_session(struct rpc_rqst *rqstp,
7048 struct xdr_stream *xdr,
7049 void *res)
7050{
7051 struct compound_hdr hdr;
7052 int status;
7053
7054 status = decode_compound_hdr(xdr, &hdr);
7055 if (!status)
7056 status = decode_bind_conn_to_session(xdr, res);
7057 return status;
7058}
7059
7060/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007061 * Decode EXCHANGE_ID response
Benny Halevy99fe60d2009-04-01 09:22:29 -04007062 */
Chuck Leverbf269552010-12-14 14:59:29 +00007063static int nfs4_xdr_dec_exchange_id(struct rpc_rqst *rqstp,
7064 struct xdr_stream *xdr,
Benny Halevy99fe60d2009-04-01 09:22:29 -04007065 void *res)
7066{
Benny Halevy99fe60d2009-04-01 09:22:29 -04007067 struct compound_hdr hdr;
7068 int status;
7069
Chuck Leverbf269552010-12-14 14:59:29 +00007070 status = decode_compound_hdr(xdr, &hdr);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007071 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007072 status = decode_exchange_id(xdr, res);
Benny Halevy99fe60d2009-04-01 09:22:29 -04007073 return status;
7074}
Andy Adamson2050f0c2009-04-01 09:22:30 -04007075
7076/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007077 * Decode CREATE_SESSION response
Andy Adamsonfc931582009-04-01 09:22:31 -04007078 */
Chuck Leverbf269552010-12-14 14:59:29 +00007079static int nfs4_xdr_dec_create_session(struct rpc_rqst *rqstp,
7080 struct xdr_stream *xdr,
Andy Adamsonfc931582009-04-01 09:22:31 -04007081 struct nfs41_create_session_res *res)
7082{
Andy Adamsonfc931582009-04-01 09:22:31 -04007083 struct compound_hdr hdr;
7084 int status;
7085
Chuck Leverbf269552010-12-14 14:59:29 +00007086 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc931582009-04-01 09:22:31 -04007087 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007088 status = decode_create_session(xdr, res);
Andy Adamsonfc931582009-04-01 09:22:31 -04007089 return status;
7090}
7091
7092/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007093 * Decode DESTROY_SESSION response
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007094 */
Chuck Leverbf269552010-12-14 14:59:29 +00007095static int nfs4_xdr_dec_destroy_session(struct rpc_rqst *rqstp,
7096 struct xdr_stream *xdr,
7097 void *res)
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007098{
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007099 struct compound_hdr hdr;
7100 int status;
7101
Chuck Leverbf269552010-12-14 14:59:29 +00007102 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007103 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007104 status = decode_destroy_session(xdr, res);
Andy Adamson0f3e66c2009-04-01 09:22:34 -04007105 return status;
7106}
7107
7108/*
Trond Myklebust66245532012-05-25 17:18:09 -04007109 * Decode DESTROY_CLIENTID response
7110 */
7111static int nfs4_xdr_dec_destroy_clientid(struct rpc_rqst *rqstp,
7112 struct xdr_stream *xdr,
7113 void *res)
7114{
7115 struct compound_hdr hdr;
7116 int status;
7117
7118 status = decode_compound_hdr(xdr, &hdr);
7119 if (!status)
7120 status = decode_destroy_clientid(xdr, res);
7121 return status;
7122}
7123
7124/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007125 * Decode SEQUENCE response
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007126 */
Chuck Leverbf269552010-12-14 14:59:29 +00007127static int nfs4_xdr_dec_sequence(struct rpc_rqst *rqstp,
7128 struct xdr_stream *xdr,
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007129 struct nfs4_sequence_res *res)
7130{
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007131 struct compound_hdr hdr;
7132 int status;
7133
Chuck Leverbf269552010-12-14 14:59:29 +00007134 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007135 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007136 status = decode_sequence(xdr, res, rqstp);
Andy Adamsonfc01cea2009-04-01 09:22:36 -04007137 return status;
7138}
7139
7140/*
Ricardo Labiaga8b173212009-12-05 16:08:39 -05007141 * Decode GET_LEASE_TIME response
Andy Adamson2050f0c2009-04-01 09:22:30 -04007142 */
Chuck Leverbf269552010-12-14 14:59:29 +00007143static int nfs4_xdr_dec_get_lease_time(struct rpc_rqst *rqstp,
7144 struct xdr_stream *xdr,
Andy Adamson2050f0c2009-04-01 09:22:30 -04007145 struct nfs4_get_lease_time_res *res)
7146{
Andy Adamson2050f0c2009-04-01 09:22:30 -04007147 struct compound_hdr hdr;
7148 int status;
7149
Chuck Leverbf269552010-12-14 14:59:29 +00007150 status = decode_compound_hdr(xdr, &hdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007151 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007152 status = decode_sequence(xdr, &res->lr_seq_res, rqstp);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007153 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007154 status = decode_putrootfh(xdr);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007155 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007156 status = decode_fsinfo(xdr, res->lr_fsinfo);
Andy Adamson2050f0c2009-04-01 09:22:30 -04007157 return status;
7158}
Ricardo Labiaga180197532009-12-05 16:08:40 -05007159
7160/*
7161 * Decode RECLAIM_COMPLETE response
7162 */
Chuck Leverbf269552010-12-14 14:59:29 +00007163static int nfs4_xdr_dec_reclaim_complete(struct rpc_rqst *rqstp,
7164 struct xdr_stream *xdr,
Ricardo Labiaga180197532009-12-05 16:08:40 -05007165 struct nfs41_reclaim_complete_res *res)
7166{
Ricardo Labiaga180197532009-12-05 16:08:40 -05007167 struct compound_hdr hdr;
7168 int status;
7169
Chuck Leverbf269552010-12-14 14:59:29 +00007170 status = decode_compound_hdr(xdr, &hdr);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007171 if (!status)
Chuck Leverbf269552010-12-14 14:59:29 +00007172 status = decode_sequence(xdr, &res->seq_res, rqstp);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007173 if (!status)
Himangi Saraogi8ee2b782014-06-27 00:09:09 +05307174 status = decode_reclaim_complete(xdr, NULL);
Ricardo Labiaga180197532009-12-05 16:08:40 -05007175 return status;
7176}
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007177
7178/*
7179 * Decode GETDEVINFO response
7180 */
Chuck Leverbf269552010-12-14 14:59:29 +00007181static int nfs4_xdr_dec_getdeviceinfo(struct rpc_rqst *rqstp,
7182 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007183 struct nfs4_getdeviceinfo_res *res)
7184{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007185 struct compound_hdr hdr;
7186 int status;
7187
Chuck Leverbf269552010-12-14 14:59:29 +00007188 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007189 if (status != 0)
7190 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007191 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007192 if (status != 0)
7193 goto out;
Trond Myklebust4e590802015-03-09 14:01:25 -04007194 status = decode_getdeviceinfo(xdr, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007195out:
7196 return status;
7197}
7198
7199/*
7200 * Decode LAYOUTGET response
7201 */
Chuck Leverbf269552010-12-14 14:59:29 +00007202static int nfs4_xdr_dec_layoutget(struct rpc_rqst *rqstp,
7203 struct xdr_stream *xdr,
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007204 struct nfs4_layoutget_res *res)
7205{
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007206 struct compound_hdr hdr;
7207 int status;
7208
Chuck Leverbf269552010-12-14 14:59:29 +00007209 status = decode_compound_hdr(xdr, &hdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007210 if (status)
7211 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007212 status = decode_sequence(xdr, &res->seq_res, rqstp);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007213 if (status)
7214 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007215 status = decode_putfh(xdr);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007216 if (status)
7217 goto out;
Chuck Leverbf269552010-12-14 14:59:29 +00007218 status = decode_layoutget(xdr, rqstp, res);
Andy Adamsonb1f69b72010-10-20 00:18:03 -04007219out:
7220 return status;
7221}
Andy Adamson863a3c62011-03-23 13:27:54 +00007222
7223/*
Benny Halevycbe82602011-05-22 19:52:37 +03007224 * Decode LAYOUTRETURN response
7225 */
7226static int nfs4_xdr_dec_layoutreturn(struct rpc_rqst *rqstp,
7227 struct xdr_stream *xdr,
7228 struct nfs4_layoutreturn_res *res)
7229{
7230 struct compound_hdr hdr;
7231 int status;
7232
7233 status = decode_compound_hdr(xdr, &hdr);
7234 if (status)
7235 goto out;
7236 status = decode_sequence(xdr, &res->seq_res, rqstp);
7237 if (status)
7238 goto out;
7239 status = decode_putfh(xdr);
7240 if (status)
7241 goto out;
7242 status = decode_layoutreturn(xdr, res);
7243out:
7244 return status;
7245}
7246
7247/*
Andy Adamson863a3c62011-03-23 13:27:54 +00007248 * Decode LAYOUTCOMMIT response
7249 */
7250static int nfs4_xdr_dec_layoutcommit(struct rpc_rqst *rqstp,
7251 struct xdr_stream *xdr,
7252 struct nfs4_layoutcommit_res *res)
7253{
7254 struct compound_hdr hdr;
7255 int status;
7256
7257 status = decode_compound_hdr(xdr, &hdr);
7258 if (status)
7259 goto out;
7260 status = decode_sequence(xdr, &res->seq_res, rqstp);
7261 if (status)
7262 goto out;
7263 status = decode_putfh(xdr);
7264 if (status)
7265 goto out;
7266 status = decode_layoutcommit(xdr, rqstp, res);
7267 if (status)
7268 goto out;
Trond Myklebust6926afd2012-01-07 13:22:46 -05007269 decode_getfattr(xdr, res->fattr, res->server);
Andy Adamson863a3c62011-03-23 13:27:54 +00007270out:
7271 return status;
7272}
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007273
7274/*
7275 * Decode SECINFO_NO_NAME response
7276 */
7277static int nfs4_xdr_dec_secinfo_no_name(struct rpc_rqst *rqstp,
7278 struct xdr_stream *xdr,
7279 struct nfs4_secinfo_res *res)
7280{
7281 struct compound_hdr hdr;
7282 int status;
7283
7284 status = decode_compound_hdr(xdr, &hdr);
7285 if (status)
7286 goto out;
7287 status = decode_sequence(xdr, &res->seq_res, rqstp);
7288 if (status)
7289 goto out;
7290 status = decode_putrootfh(xdr);
7291 if (status)
7292 goto out;
Bryan Schumaker31e4dda2012-04-27 13:27:38 -04007293 status = decode_secinfo_no_name(xdr, res);
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007294out:
7295 return status;
7296}
Bryan Schumaker7d974792011-06-02 14:59:08 -04007297
7298/*
7299 * Decode TEST_STATEID response
7300 */
7301static int nfs4_xdr_dec_test_stateid(struct rpc_rqst *rqstp,
7302 struct xdr_stream *xdr,
7303 struct nfs41_test_stateid_res *res)
7304{
7305 struct compound_hdr hdr;
7306 int status;
7307
7308 status = decode_compound_hdr(xdr, &hdr);
7309 if (status)
7310 goto out;
7311 status = decode_sequence(xdr, &res->seq_res, rqstp);
7312 if (status)
7313 goto out;
7314 status = decode_test_stateid(xdr, res);
7315out:
7316 return status;
7317}
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007318
7319/*
7320 * Decode FREE_STATEID response
7321 */
7322static int nfs4_xdr_dec_free_stateid(struct rpc_rqst *rqstp,
7323 struct xdr_stream *xdr,
7324 struct nfs41_free_stateid_res *res)
7325{
7326 struct compound_hdr hdr;
7327 int status;
7328
7329 status = decode_compound_hdr(xdr, &hdr);
7330 if (status)
7331 goto out;
7332 status = decode_sequence(xdr, &res->seq_res, rqstp);
7333 if (status)
7334 goto out;
7335 status = decode_free_stateid(xdr, res);
7336out:
7337 return status;
7338}
Benny Halevy99fe60d2009-04-01 09:22:29 -04007339#endif /* CONFIG_NFS_V4_1 */
7340
Chuck Lever573c4e12010-12-14 14:58:11 +00007341/**
7342 * nfs4_decode_dirent - Decode a single NFSv4 directory entry stored in
7343 * the local page cache.
7344 * @xdr: XDR stream where entry resides
7345 * @entry: buffer to fill in with entry data
7346 * @plus: boolean indicating whether this should be a readdirplus entry
7347 *
7348 * Returns zero if successful, otherwise a negative errno value is
7349 * returned.
7350 *
7351 * This function is not invoked during READDIR reply decoding, but
7352 * rather whenever an application invokes the getdents(2) system call
7353 * on a directory already in our cache.
7354 */
7355int nfs4_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
7356 int plus)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007357{
Trond Myklebust256e48b2012-06-21 11:18:13 -04007358 unsigned int savep;
Fred Isamandae100c2011-07-30 20:52:37 -04007359 uint32_t bitmap[3] = {0};
Linus Torvalds1da177e2005-04-16 15:20:36 -07007360 uint32_t len;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007361 __be32 *p = xdr_inline_decode(xdr, 4);
7362 if (unlikely(!p))
7363 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007364 if (*p == xdr_zero) {
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007365 p = xdr_inline_decode(xdr, 4);
7366 if (unlikely(!p))
7367 goto out_overflow;
Chuck Leverc08e76d2011-01-28 12:40:55 -05007368 if (*p == xdr_zero)
Chuck Lever573c4e12010-12-14 14:58:11 +00007369 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007370 entry->eof = 1;
Chuck Lever573c4e12010-12-14 14:58:11 +00007371 return -EBADCOOKIE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007372 }
7373
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007374 p = xdr_inline_decode(xdr, 12);
7375 if (unlikely(!p))
7376 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007377 entry->prev_cookie = entry->cookie;
7378 p = xdr_decode_hyper(p, &entry->cookie);
Chuck Leverc08e76d2011-01-28 12:40:55 -05007379 entry->len = be32_to_cpup(p);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007380
Trond Myklebust9af8c222010-10-24 11:52:55 -04007381 p = xdr_inline_decode(xdr, entry->len);
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007382 if (unlikely(!p))
7383 goto out_overflow;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007384 entry->name = (const char *) p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007385
7386 /*
7387 * In case the server doesn't return an inode number,
7388 * we fake one here. (We don't use inode number 0,
7389 * since glibc seems to choke on it...)
7390 */
7391 entry->ino = 1;
Trond Myklebust4f082222010-10-24 13:14:02 -04007392 entry->fattr->valid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007393
Trond Myklebust9af8c222010-10-24 11:52:55 -04007394 if (decode_attr_bitmap(xdr, bitmap) < 0)
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007395 goto out_overflow;
Trond Myklebust9af8c222010-10-24 11:52:55 -04007396
Trond Myklebust256e48b2012-06-21 11:18:13 -04007397 if (decode_attr_length(xdr, &len, &savep) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007398 goto out_overflow;
7399
Chuck Lever573c4e12010-12-14 14:58:11 +00007400 if (decode_getfattr_attrs(xdr, bitmap, entry->fattr, entry->fh,
David Quigleyaa9c2662013-05-22 12:50:44 -04007401 NULL, entry->label, entry->server) < 0)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007402 goto out_overflow;
Trond Myklebust28331a42011-04-27 13:47:52 -04007403 if (entry->fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID)
7404 entry->ino = entry->fattr->mounted_on_fileid;
7405 else if (entry->fattr->valid & NFS_ATTR_FATTR_FILEID)
Trond Myklebust9af8c222010-10-24 11:52:55 -04007406 entry->ino = entry->fattr->fileid;
7407
Trond Myklebust0b26a0b2010-11-20 14:26:44 -05007408 entry->d_type = DT_UNKNOWN;
7409 if (entry->fattr->valid & NFS_ATTR_FATTR_TYPE)
7410 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
7411
Chuck Lever573c4e12010-12-14 14:58:11 +00007412 return 0;
Bryan Schumakerbabddc72010-10-20 15:44:29 -04007413
7414out_overflow:
7415 print_overflow_msg(__func__, xdr);
Chuck Lever573c4e12010-12-14 14:58:11 +00007416 return -EAGAIN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007417}
7418
7419/*
7420 * We need to translate between nfs status return values and
7421 * the local errno values which may not be the same.
7422 */
7423static struct {
7424 int stat;
7425 int errno;
7426} nfs_errtbl[] = {
7427 { NFS4_OK, 0 },
Benny Halevy856dff32008-03-31 17:39:06 +03007428 { NFS4ERR_PERM, -EPERM },
7429 { NFS4ERR_NOENT, -ENOENT },
7430 { NFS4ERR_IO, -errno_NFSERR_IO},
7431 { NFS4ERR_NXIO, -ENXIO },
7432 { NFS4ERR_ACCESS, -EACCES },
7433 { NFS4ERR_EXIST, -EEXIST },
7434 { NFS4ERR_XDEV, -EXDEV },
7435 { NFS4ERR_NOTDIR, -ENOTDIR },
7436 { NFS4ERR_ISDIR, -EISDIR },
7437 { NFS4ERR_INVAL, -EINVAL },
7438 { NFS4ERR_FBIG, -EFBIG },
7439 { NFS4ERR_NOSPC, -ENOSPC },
7440 { NFS4ERR_ROFS, -EROFS },
7441 { NFS4ERR_MLINK, -EMLINK },
7442 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
7443 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
7444 { NFS4ERR_DQUOT, -EDQUOT },
7445 { NFS4ERR_STALE, -ESTALE },
7446 { NFS4ERR_BADHANDLE, -EBADHANDLE },
Benny Halevy856dff32008-03-31 17:39:06 +03007447 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
7448 { NFS4ERR_NOTSUPP, -ENOTSUPP },
7449 { NFS4ERR_TOOSMALL, -ETOOSMALL },
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007450 { NFS4ERR_SERVERFAULT, -EREMOTEIO },
Benny Halevy856dff32008-03-31 17:39:06 +03007451 { NFS4ERR_BADTYPE, -EBADTYPE },
7452 { NFS4ERR_LOCKED, -EAGAIN },
Benny Halevy856dff32008-03-31 17:39:06 +03007453 { NFS4ERR_SYMLINK, -ELOOP },
7454 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
7455 { NFS4ERR_DEADLOCK, -EDEADLK },
Benny Halevy856dff32008-03-31 17:39:06 +03007456 { -1, -EIO }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007457};
7458
7459/*
7460 * Convert an NFS error code to a local one.
7461 * This one is used jointly by NFSv2 and NFSv3.
7462 */
7463static int
David Howells0a8ea432006-08-22 20:06:08 -04007464nfs4_stat_to_errno(int stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007465{
7466 int i;
7467 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
7468 if (nfs_errtbl[i].stat == stat)
7469 return nfs_errtbl[i].errno;
7470 }
7471 if (stat <= 10000 || stat > 10100) {
7472 /* The server is looney tunes. */
Trond Myklebustfdcb4572010-02-08 09:32:40 -05007473 return -EREMOTEIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007474 }
7475 /* If we cannot translate the error, the recovery routines should
7476 * handle it.
7477 * Note: remaining NFSv4 error codes have values > 10000, so should
7478 * not conflict with native Linux error codes.
7479 */
Benny Halevy856dff32008-03-31 17:39:06 +03007480 return -stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007481}
7482
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007483#ifdef CONFIG_NFS_V4_2
7484#include "nfs42xdr.c"
7485#endif /* CONFIG_NFS_V4_2 */
7486
Linus Torvalds1da177e2005-04-16 15:20:36 -07007487#define PROC(proc, argtype, restype) \
7488[NFSPROC4_CLNT_##proc] = { \
7489 .p_proc = NFSPROC4_COMPOUND, \
Chuck Lever9f06c712010-12-14 14:59:18 +00007490 .p_encode = (kxdreproc_t)nfs4_xdr_##argtype, \
Chuck Leverbf269552010-12-14 14:59:29 +00007491 .p_decode = (kxdrdproc_t)nfs4_xdr_##restype, \
Chuck Lever2bea90d2007-03-29 16:47:53 -04007492 .p_arglen = NFS4_##argtype##_sz, \
7493 .p_replen = NFS4_##restype##_sz, \
Chuck Levercc0175c2006-03-20 13:44:22 -05007494 .p_statidx = NFSPROC4_CLNT_##proc, \
7495 .p_name = #proc, \
Andy Adamson05d564f2008-12-23 16:06:15 -05007496}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007497
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007498#define STUB(proc) \
7499[NFSPROC4_CLNT_##proc] = { \
7500 .p_name = #proc, \
7501}
7502
Linus Torvalds1da177e2005-04-16 15:20:36 -07007503struct rpc_procinfo nfs4_procedures[] = {
Chuck Lever7d93bd712010-12-14 14:57:42 +00007504 PROC(READ, enc_read, dec_read),
7505 PROC(WRITE, enc_write, dec_write),
7506 PROC(COMMIT, enc_commit, dec_commit),
7507 PROC(OPEN, enc_open, dec_open),
7508 PROC(OPEN_CONFIRM, enc_open_confirm, dec_open_confirm),
7509 PROC(OPEN_NOATTR, enc_open_noattr, dec_open_noattr),
7510 PROC(OPEN_DOWNGRADE, enc_open_downgrade, dec_open_downgrade),
7511 PROC(CLOSE, enc_close, dec_close),
7512 PROC(SETATTR, enc_setattr, dec_setattr),
7513 PROC(FSINFO, enc_fsinfo, dec_fsinfo),
7514 PROC(RENEW, enc_renew, dec_renew),
7515 PROC(SETCLIENTID, enc_setclientid, dec_setclientid),
7516 PROC(SETCLIENTID_CONFIRM, enc_setclientid_confirm, dec_setclientid_confirm),
7517 PROC(LOCK, enc_lock, dec_lock),
7518 PROC(LOCKT, enc_lockt, dec_lockt),
7519 PROC(LOCKU, enc_locku, dec_locku),
7520 PROC(ACCESS, enc_access, dec_access),
7521 PROC(GETATTR, enc_getattr, dec_getattr),
7522 PROC(LOOKUP, enc_lookup, dec_lookup),
7523 PROC(LOOKUP_ROOT, enc_lookup_root, dec_lookup_root),
7524 PROC(REMOVE, enc_remove, dec_remove),
7525 PROC(RENAME, enc_rename, dec_rename),
7526 PROC(LINK, enc_link, dec_link),
7527 PROC(SYMLINK, enc_symlink, dec_symlink),
7528 PROC(CREATE, enc_create, dec_create),
7529 PROC(PATHCONF, enc_pathconf, dec_pathconf),
7530 PROC(STATFS, enc_statfs, dec_statfs),
7531 PROC(READLINK, enc_readlink, dec_readlink),
7532 PROC(READDIR, enc_readdir, dec_readdir),
7533 PROC(SERVER_CAPS, enc_server_caps, dec_server_caps),
7534 PROC(DELEGRETURN, enc_delegreturn, dec_delegreturn),
7535 PROC(GETACL, enc_getacl, dec_getacl),
7536 PROC(SETACL, enc_setacl, dec_setacl),
7537 PROC(FS_LOCATIONS, enc_fs_locations, dec_fs_locations),
7538 PROC(RELEASE_LOCKOWNER, enc_release_lockowner, dec_release_lockowner),
Bryan Schumaker5a5ea0d2011-03-24 17:12:29 +00007539 PROC(SECINFO, enc_secinfo, dec_secinfo),
Chuck Lever44c99932013-10-17 14:13:30 -04007540 PROC(FSID_PRESENT, enc_fsid_present, dec_fsid_present),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007541#if defined(CONFIG_NFS_V4_1)
Chuck Lever7d93bd712010-12-14 14:57:42 +00007542 PROC(EXCHANGE_ID, enc_exchange_id, dec_exchange_id),
7543 PROC(CREATE_SESSION, enc_create_session, dec_create_session),
7544 PROC(DESTROY_SESSION, enc_destroy_session, dec_destroy_session),
7545 PROC(SEQUENCE, enc_sequence, dec_sequence),
7546 PROC(GET_LEASE_TIME, enc_get_lease_time, dec_get_lease_time),
7547 PROC(RECLAIM_COMPLETE, enc_reclaim_complete, dec_reclaim_complete),
7548 PROC(GETDEVICEINFO, enc_getdeviceinfo, dec_getdeviceinfo),
7549 PROC(LAYOUTGET, enc_layoutget, dec_layoutget),
Andy Adamson863a3c62011-03-23 13:27:54 +00007550 PROC(LAYOUTCOMMIT, enc_layoutcommit, dec_layoutcommit),
Benny Halevycbe82602011-05-22 19:52:37 +03007551 PROC(LAYOUTRETURN, enc_layoutreturn, dec_layoutreturn),
Bryan Schumakerfca78d62011-06-02 14:59:07 -04007552 PROC(SECINFO_NO_NAME, enc_secinfo_no_name, dec_secinfo_no_name),
Bryan Schumaker7d974792011-06-02 14:59:08 -04007553 PROC(TEST_STATEID, enc_test_stateid, dec_test_stateid),
Bryan Schumaker9aeda352011-06-02 14:59:09 -04007554 PROC(FREE_STATEID, enc_free_stateid, dec_free_stateid),
Anna Schumaker7c61f0d2015-04-14 10:34:20 -04007555 STUB(GETDEVICELIST),
Trond Myklebustad24ecf2012-05-25 17:11:42 -04007556 PROC(BIND_CONN_TO_SESSION,
7557 enc_bind_conn_to_session, dec_bind_conn_to_session),
Trond Myklebust66245532012-05-25 17:18:09 -04007558 PROC(DESTROY_CLIENTID, enc_destroy_clientid, dec_destroy_clientid),
Benny Halevy99fe60d2009-04-01 09:22:29 -04007559#endif /* CONFIG_NFS_V4_1 */
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007560#ifdef CONFIG_NFS_V4_2
7561 PROC(SEEK, enc_seek, dec_seek),
Anna Schumakerf4ac1672014-11-25 13:18:15 -05007562 PROC(ALLOCATE, enc_allocate, dec_allocate),
Anna Schumaker624bd5b2014-11-25 13:18:16 -05007563 PROC(DEALLOCATE, enc_deallocate, dec_deallocate),
Trond Myklebustbe3a5d22015-06-23 19:51:55 +08007564 PROC(LAYOUTSTATS, enc_layoutstats, dec_layoutstats),
Peng Tao36022772015-09-26 02:24:34 +08007565 PROC(CLONE, enc_clone, dec_clone),
Anna Schumaker2e724482013-05-21 16:53:03 -04007566 PROC(COPY, enc_copy, dec_copy),
Anna Schumaker1c6dcbe2014-09-26 13:58:48 -04007567#endif /* CONFIG_NFS_V4_2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007568};
7569
Trond Myklebusta613fa12012-01-20 13:53:56 -05007570const struct rpc_version nfs_version4 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007571 .number = 4,
Tobias Klausere8c96f82006-03-24 03:15:34 -08007572 .nrprocs = ARRAY_SIZE(nfs4_procedures),
Linus Torvalds1da177e2005-04-16 15:20:36 -07007573 .procs = nfs4_procedures
7574};
7575
7576/*
7577 * Local variables:
7578 * c-basic-offset: 8
7579 * End:
7580 */